arch.h 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243
  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. #ifndef SPEEX_VERSION
  33. #define SPEEX_MAJOR_VERSION 1 /**< Major Speex version. */
  34. #define SPEEX_MINOR_VERSION 1 /**< Minor Speex version. */
  35. #define SPEEX_MICRO_VERSION 15 /**< Micro Speex version. */
  36. #define SPEEX_EXTRA_VERSION "" /**< Extra Speex version. */
  37. #define SPEEX_VERSION "speex-1.2beta3" /**< Speex version string. */
  38. #endif
  39. /* A couple test to catch stupid option combinations */
  40. #ifdef FIXED_POINT
  41. #ifdef FLOATING_POINT
  42. #error You cannot compile as floating point and fixed point at the same time
  43. #endif
  44. #ifdef USE_SSE
  45. #error SSE is only for floating-point
  46. #endif
  47. #if ((defined (ARM4_ASM)||defined (ARM4_ASM)) && defined(BFIN_ASM)) || (defined (ARM4_ASM)&&defined(ARM5E_ASM))
  48. #error Make up your mind. What CPU do you have?
  49. #endif
  50. #ifdef VORBIS_PSYCHO
  51. #error Vorbis-psy model currently not implemented in fixed-point
  52. #endif
  53. #else
  54. #ifndef FLOATING_POINT
  55. #error You now need to define either FIXED_POINT or FLOATING_POINT
  56. #endif
  57. #if defined (ARM4_ASM) || defined(ARM5E_ASM) || defined(BFIN_ASM)
  58. #error I suppose you can have a [ARM4/ARM5E/Blackfin] that has float instructions?
  59. #endif
  60. #ifdef FIXED_POINT_DEBUG
  61. #error "Don't you think enabling fixed-point is a good thing to do if you want to debug that?"
  62. #endif
  63. #endif
  64. #ifndef OUTSIDE_SPEEX
  65. #include "speex/speexdsp_types.h"
  66. #endif
  67. #define ABS(x) ((x) < 0 ? (-(x)) : (x)) /**< Absolute integer value. */
  68. #define ABS16(x) ((x) < 0 ? (-(x)) : (x)) /**< Absolute 16-bit value. */
  69. #define MIN16(a,b) ((a) < (b) ? (a) : (b)) /**< Maximum 16-bit value. */
  70. #define MAX16(a,b) ((a) > (b) ? (a) : (b)) /**< Maximum 16-bit value. */
  71. #define ABS32(x) ((x) < 0 ? (-(x)) : (x)) /**< Absolute 32-bit value. */
  72. #define MIN32(a,b) ((a) < (b) ? (a) : (b)) /**< Maximum 32-bit value. */
  73. #define MAX32(a,b) ((a) > (b) ? (a) : (b)) /**< Maximum 32-bit value. */
  74. #ifdef FIXED_POINT
  75. typedef spx_int16_t spx_word16_t;
  76. typedef spx_int32_t spx_word32_t;
  77. typedef spx_word32_t spx_mem_t;
  78. typedef spx_word16_t spx_coef_t;
  79. typedef spx_word16_t spx_lsp_t;
  80. typedef spx_word32_t spx_sig_t;
  81. #define Q15ONE 32767
  82. #define LPC_SCALING 8192
  83. #define SIG_SCALING 16384
  84. #define LSP_SCALING 8192.
  85. #define GAMMA_SCALING 32768.
  86. #define GAIN_SCALING 64
  87. #define GAIN_SCALING_1 0.015625
  88. #define LPC_SHIFT 13
  89. #define LSP_SHIFT 13
  90. #define SIG_SHIFT 14
  91. #define GAIN_SHIFT 6
  92. #define WORD2INT(x) ((x) < -32767 ? -32768 : ((x) > 32766 ? 32767 : (x)))
  93. #define VERY_SMALL 0
  94. #define VERY_LARGE32 ((spx_word32_t)2147483647)
  95. #define VERY_LARGE16 ((spx_word16_t)32767)
  96. #define Q15_ONE ((spx_word16_t)32767)
  97. #ifdef FIXED_DEBUG
  98. #include "fixed_debug.h"
  99. #else
  100. #include "fixed_generic.h"
  101. #ifdef ARM5E_ASM
  102. #include "fixed_arm5e.h"
  103. #elif defined (ARM4_ASM)
  104. #include "fixed_arm4.h"
  105. #elif defined (BFIN_ASM)
  106. #include "fixed_bfin.h"
  107. #endif
  108. #endif
  109. #else
  110. typedef float spx_mem_t;
  111. typedef float spx_coef_t;
  112. typedef float spx_lsp_t;
  113. typedef float spx_sig_t;
  114. typedef float spx_word16_t;
  115. typedef float spx_word32_t;
  116. #define Q15ONE 1.0f
  117. #define LPC_SCALING 1.f
  118. #define SIG_SCALING 1.f
  119. #define LSP_SCALING 1.f
  120. #define GAMMA_SCALING 1.f
  121. #define GAIN_SCALING 1.f
  122. #define GAIN_SCALING_1 1.f
  123. #define VERY_SMALL 1e-15f
  124. #define VERY_LARGE32 1e15f
  125. #define VERY_LARGE16 1e15f
  126. #define Q15_ONE ((spx_word16_t)1.f)
  127. #define QCONST16(x,bits) (x)
  128. #define QCONST32(x,bits) (x)
  129. #define NEG16(x) (-(x))
  130. #define NEG32(x) (-(x))
  131. #define EXTRACT16(x) (x)
  132. #define EXTEND32(x) (x)
  133. #define SHR16(a,shift) (a)
  134. #define SHL16(a,shift) (a)
  135. #define SHR32(a,shift) (a)
  136. #define SHL32(a,shift) (a)
  137. #define PSHR16(a,shift) (a)
  138. #define PSHR32(a,shift) (a)
  139. #define VSHR32(a,shift) (a)
  140. #define SATURATE16(x,a) (x)
  141. #define SATURATE32(x,a) (x)
  142. #define SATURATE32PSHR(x,shift,a) (x)
  143. #define PSHR(a,shift) (a)
  144. #define SHR(a,shift) (a)
  145. #define SHL(a,shift) (a)
  146. #define SATURATE(x,a) (x)
  147. #define ADD16(a,b) ((a)+(b))
  148. #define SUB16(a,b) ((a)-(b))
  149. #define ADD32(a,b) ((a)+(b))
  150. #define SUB32(a,b) ((a)-(b))
  151. #define MULT16_16_16(a,b) ((a)*(b))
  152. #define MULT16_16(a,b) ((spx_word32_t)(a)*(spx_word32_t)(b))
  153. #define MAC16_16(c,a,b) ((c)+(spx_word32_t)(a)*(spx_word32_t)(b))
  154. #define MULT16_32_Q11(a,b) ((a)*(b))
  155. #define MULT16_32_Q13(a,b) ((a)*(b))
  156. #define MULT16_32_Q14(a,b) ((a)*(b))
  157. #define MULT16_32_Q15(a,b) ((a)*(b))
  158. #define MULT16_32_P15(a,b) ((a)*(b))
  159. #define MAC16_32_Q11(c,a,b) ((c)+(a)*(b))
  160. #define MAC16_32_Q15(c,a,b) ((c)+(a)*(b))
  161. #define MAC16_16_Q11(c,a,b) ((c)+(a)*(b))
  162. #define MAC16_16_Q13(c,a,b) ((c)+(a)*(b))
  163. #define MAC16_16_P13(c,a,b) ((c)+(a)*(b))
  164. #define MULT16_16_Q11_32(a,b) ((a)*(b))
  165. #define MULT16_16_Q13(a,b) ((a)*(b))
  166. #define MULT16_16_Q14(a,b) ((a)*(b))
  167. #define MULT16_16_Q15(a,b) ((a)*(b))
  168. #define MULT16_16_P15(a,b) ((a)*(b))
  169. #define MULT16_16_P13(a,b) ((a)*(b))
  170. #define MULT16_16_P14(a,b) ((a)*(b))
  171. #define DIV32_16(a,b) (((spx_word32_t)(a))/(spx_word16_t)(b))
  172. #define PDIV32_16(a,b) (((spx_word32_t)(a))/(spx_word16_t)(b))
  173. #define DIV32(a,b) (((spx_word32_t)(a))/(spx_word32_t)(b))
  174. #define PDIV32(a,b) (((spx_word32_t)(a))/(spx_word32_t)(b))
  175. #define WORD2INT(x) ((x) < -32767.5f ? -32768 : \
  176. ((x) > 32766.5f ? 32767 : (spx_int16_t)floor(.5 + (x))))
  177. #endif
  178. #if defined (CONFIG_TI_C54X) || defined (CONFIG_TI_C55X)
  179. /* 2 on TI C5x DSP */
  180. #define BYTES_PER_CHAR 2
  181. #define BITS_PER_CHAR 16
  182. #define LOG2_BITS_PER_CHAR 4
  183. #else
  184. #define BYTES_PER_CHAR 1
  185. #define BITS_PER_CHAR 8
  186. #define LOG2_BITS_PER_CHAR 3
  187. #endif
  188. #ifdef FIXED_DEBUG
  189. extern long long spx_mips;
  190. #endif
  191. #endif