arch.h 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220
  1. /* Copyright (C) 2003 Jean-Marc Valin */
  2. /**
  3. @file arch.h
  4. @brief Various architecture definitions Speex
  5. */
  6. /*
  7. Redistribution and use in source and binary forms, with or without
  8. modification, are permitted provided that the following conditions
  9. are met:
  10. - Redistributions of source code must retain the above copyright
  11. notice, this list of conditions and the following disclaimer.
  12. - Redistributions in binary form must reproduce the above copyright
  13. notice, this list of conditions and the following disclaimer in the
  14. documentation and/or other materials provided with the distribution.
  15. - Neither the name of the Xiph.org Foundation nor the names of its
  16. contributors may be used to endorse or promote products derived from
  17. this software without specific prior written permission.
  18. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  19. ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  20. LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  21. A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR
  22. CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  23. EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  24. PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  25. PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  26. LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  27. NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  28. SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  29. */
  30. #ifndef ARCH_H
  31. #define ARCH_H
  32. /* A couple test to catch stupid option combinations */
  33. #ifdef FIXED_POINT
  34. #if ((defined (ARM4_ASM)||defined (ARM4_ASM)) && defined(BFIN_ASM)) || (defined (ARM4_ASM)&&defined(ARM5E_ASM))
  35. #error Make up your mind. What CPU do you have?
  36. #endif
  37. #else
  38. #if defined (ARM4_ASM) || defined(ARM5E_ASM) || defined(BFIN_ASM)
  39. #error I suppose you can have a [ARM4/ARM5E/Blackfin] that has float instructions?
  40. #endif
  41. #endif
  42. #ifndef OUTSIDE_SPEEX
  43. #include "speex/speexdsp_types.h"
  44. #endif
  45. #define ABS(x) ((x) < 0 ? (-(x)) : (x)) /**< Absolute integer value. */
  46. #define ABS16(x) ((x) < 0 ? (-(x)) : (x)) /**< Absolute 16-bit value. */
  47. #define MIN16(a,b) ((a) < (b) ? (a) : (b)) /**< Maximum 16-bit value. */
  48. #define MAX16(a,b) ((a) > (b) ? (a) : (b)) /**< Maximum 16-bit value. */
  49. #define ABS32(x) ((x) < 0 ? (-(x)) : (x)) /**< Absolute 32-bit value. */
  50. #define MIN32(a,b) ((a) < (b) ? (a) : (b)) /**< Maximum 32-bit value. */
  51. #define MAX32(a,b) ((a) > (b) ? (a) : (b)) /**< Maximum 32-bit value. */
  52. #ifdef FIXED_POINT
  53. typedef spx_int16_t spx_word16_t;
  54. typedef spx_int32_t spx_word32_t;
  55. typedef spx_word32_t spx_mem_t;
  56. typedef spx_word16_t spx_coef_t;
  57. typedef spx_word16_t spx_lsp_t;
  58. typedef spx_word32_t spx_sig_t;
  59. #define Q15ONE 32767
  60. #define LPC_SCALING 8192
  61. #define SIG_SCALING 16384
  62. #define LSP_SCALING 8192.
  63. #define GAMMA_SCALING 32768.
  64. #define GAIN_SCALING 64
  65. #define GAIN_SCALING_1 0.015625
  66. #define LPC_SHIFT 13
  67. #define LSP_SHIFT 13
  68. #define SIG_SHIFT 14
  69. #define GAIN_SHIFT 6
  70. #define WORD2INT(x) ((x) < -32767 ? -32768 : ((x) > 32766 ? 32767 : (x)))
  71. #define VERY_SMALL 0
  72. #define VERY_LARGE32 ((spx_word32_t)2147483647)
  73. #define VERY_LARGE16 ((spx_word16_t)32767)
  74. #define Q15_ONE ((spx_word16_t)32767)
  75. #ifdef FIXED_DEBUG
  76. #include "fixed_debug.h"
  77. #else
  78. #include "fixed_generic.h"
  79. #ifdef ARM5E_ASM
  80. #include "fixed_arm5e.h"
  81. #elif defined (ARM4_ASM)
  82. #include "fixed_arm4.h"
  83. #elif defined (BFIN_ASM)
  84. #include "fixed_bfin.h"
  85. #endif
  86. #endif
  87. #else
  88. typedef float spx_mem_t;
  89. typedef float spx_coef_t;
  90. typedef float spx_lsp_t;
  91. typedef float spx_sig_t;
  92. typedef float spx_word16_t;
  93. typedef float spx_word32_t;
  94. #define Q15ONE 1.0f
  95. #define LPC_SCALING 1.f
  96. #define SIG_SCALING 1.f
  97. #define LSP_SCALING 1.f
  98. #define GAMMA_SCALING 1.f
  99. #define GAIN_SCALING 1.f
  100. #define GAIN_SCALING_1 1.f
  101. #define VERY_SMALL 1e-15f
  102. #define VERY_LARGE32 1e15f
  103. #define VERY_LARGE16 1e15f
  104. #define Q15_ONE ((spx_word16_t)1.f)
  105. #define QCONST16(x,bits) (x)
  106. #define QCONST32(x,bits) (x)
  107. #define NEG16(x) (-(x))
  108. #define NEG32(x) (-(x))
  109. #define EXTRACT16(x) (x)
  110. #define EXTEND32(x) (x)
  111. #define SHR16(a,shift) (a)
  112. #define SHL16(a,shift) (a)
  113. #define SHR32(a,shift) (a)
  114. #define SHL32(a,shift) (a)
  115. #define PSHR16(a,shift) (a)
  116. #define PSHR32(a,shift) (a)
  117. #define VSHR32(a,shift) (a)
  118. #define SATURATE16(x,a) (x)
  119. #define SATURATE32(x,a) (x)
  120. #define SATURATE32PSHR(x,shift,a) (x)
  121. #define PSHR(a,shift) (a)
  122. #define SHR(a,shift) (a)
  123. #define SHL(a,shift) (a)
  124. #define SATURATE(x,a) (x)
  125. #define ADD16(a,b) ((a)+(b))
  126. #define SUB16(a,b) ((a)-(b))
  127. #define ADD32(a,b) ((a)+(b))
  128. #define SUB32(a,b) ((a)-(b))
  129. #define MULT16_16_16(a,b) ((a)*(b))
  130. #define MULT16_16(a,b) ((spx_word32_t)(a)*(spx_word32_t)(b))
  131. #define MAC16_16(c,a,b) ((c)+(spx_word32_t)(a)*(spx_word32_t)(b))
  132. #define MULT16_32_Q11(a,b) ((a)*(b))
  133. #define MULT16_32_Q13(a,b) ((a)*(b))
  134. #define MULT16_32_Q14(a,b) ((a)*(b))
  135. #define MULT16_32_Q15(a,b) ((a)*(b))
  136. #define MULT16_32_P15(a,b) ((a)*(b))
  137. #define MAC16_32_Q11(c,a,b) ((c)+(a)*(b))
  138. #define MAC16_32_Q15(c,a,b) ((c)+(a)*(b))
  139. #define MAC16_16_Q11(c,a,b) ((c)+(a)*(b))
  140. #define MAC16_16_Q13(c,a,b) ((c)+(a)*(b))
  141. #define MAC16_16_P13(c,a,b) ((c)+(a)*(b))
  142. #define MULT16_16_Q11_32(a,b) ((a)*(b))
  143. #define MULT16_16_Q13(a,b) ((a)*(b))
  144. #define MULT16_16_Q14(a,b) ((a)*(b))
  145. #define MULT16_16_Q15(a,b) ((a)*(b))
  146. #define MULT16_16_P15(a,b) ((a)*(b))
  147. #define MULT16_16_P13(a,b) ((a)*(b))
  148. #define MULT16_16_P14(a,b) ((a)*(b))
  149. #define DIV32_16(a,b) (((spx_word32_t)(a))/(spx_word16_t)(b))
  150. #define PDIV32_16(a,b) (((spx_word32_t)(a))/(spx_word16_t)(b))
  151. #define DIV32(a,b) (((spx_word32_t)(a))/(spx_word32_t)(b))
  152. #define PDIV32(a,b) (((spx_word32_t)(a))/(spx_word32_t)(b))
  153. #define WORD2INT(x) ((x) < -32767.5f ? -32768 : \
  154. ((x) > 32766.5f ? 32767 : (spx_int16_t)floor(.5 + (x))))
  155. #endif
  156. #if defined (CONFIG_TI_C54X) || defined (CONFIG_TI_C55X)
  157. /* 2 on TI C5x DSP */
  158. #define BYTES_PER_CHAR 2
  159. #define BITS_PER_CHAR 16
  160. #define LOG2_BITS_PER_CHAR 4
  161. #else
  162. #define BYTES_PER_CHAR 1
  163. #define BITS_PER_CHAR 8
  164. #define LOG2_BITS_PER_CHAR 3
  165. #endif
  166. #ifdef FIXED_DEBUG
  167. extern long long spx_mips;
  168. #endif
  169. #endif