arch.h 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237
  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 2 /**< Minor Speex version. */
  35. #define SPEEX_MICRO_VERSION 1 /**< Micro Speex version. */
  36. #define SPEEX_EXTRA_VERSION "" /**< Extra Speex version. */
  37. #define SPEEX_VERSION "speex-1.2.1" /**< 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. #include "speex/speex_types.h"
  65. #define ABS(x) ((x) < 0 ? (-(x)) : (x)) /**< Absolute integer value. */
  66. #define ABS16(x) ((x) < 0 ? (-(x)) : (x)) /**< Absolute 16-bit value. */
  67. #define MIN16(a,b) ((a) < (b) ? (a) : (b)) /**< Maximum 16-bit value. */
  68. #define MAX16(a,b) ((a) > (b) ? (a) : (b)) /**< Maximum 16-bit value. */
  69. #define ABS32(x) ((x) < 0 ? (-(x)) : (x)) /**< Absolute 32-bit value. */
  70. #define MIN32(a,b) ((a) < (b) ? (a) : (b)) /**< Maximum 32-bit value. */
  71. #define MAX32(a,b) ((a) > (b) ? (a) : (b)) /**< Maximum 32-bit value. */
  72. #ifdef FIXED_POINT
  73. typedef spx_int16_t spx_word16_t;
  74. typedef spx_int32_t spx_word32_t;
  75. typedef spx_word32_t spx_mem_t;
  76. typedef spx_word16_t spx_coef_t;
  77. typedef spx_word16_t spx_lsp_t;
  78. typedef spx_word32_t spx_sig_t;
  79. #define Q15ONE 32767
  80. #define LPC_SCALING 8192
  81. #define SIG_SCALING 16384
  82. #define LSP_SCALING 8192.
  83. #define GAMMA_SCALING 32768.
  84. #define GAIN_SCALING 64
  85. #define GAIN_SCALING_1 0.015625
  86. #define LPC_SHIFT 13
  87. #define LSP_SHIFT 13
  88. #define SIG_SHIFT 14
  89. #define GAIN_SHIFT 6
  90. #define VERY_SMALL 0
  91. #define VERY_LARGE32 ((spx_word32_t)2147483647)
  92. #define VERY_LARGE16 ((spx_word16_t)32767)
  93. #define Q15_ONE ((spx_word16_t)32767)
  94. #ifdef FIXED_DEBUG
  95. #include "fixed_debug.h"
  96. #else
  97. #include "fixed_generic.h"
  98. #ifdef ARM5E_ASM
  99. #include "fixed_arm5e.h"
  100. #elif defined (ARM4_ASM)
  101. #include "fixed_arm4.h"
  102. #elif defined (BFIN_ASM)
  103. #include "fixed_bfin.h"
  104. #endif
  105. #endif
  106. #else
  107. typedef float spx_mem_t;
  108. typedef float spx_coef_t;
  109. typedef float spx_lsp_t;
  110. typedef float spx_sig_t;
  111. typedef float spx_word16_t;
  112. typedef float spx_word32_t;
  113. #define Q15ONE 1.0f
  114. #define LPC_SCALING 1.f
  115. #define SIG_SCALING 1.f
  116. #define LSP_SCALING 1.f
  117. #define GAMMA_SCALING 1.f
  118. #define GAIN_SCALING 1.f
  119. #define GAIN_SCALING_1 1.f
  120. #define VERY_SMALL 1e-15f
  121. #define VERY_LARGE32 1e15f
  122. #define VERY_LARGE16 1e15f
  123. #define Q15_ONE ((spx_word16_t)1.f)
  124. #define QCONST16(x,bits) (x)
  125. #define QCONST32(x,bits) (x)
  126. #define NEG16(x) (-(x))
  127. #define NEG32(x) (-(x))
  128. #define EXTRACT16(x) (x)
  129. #define EXTEND32(x) (x)
  130. #define SHR16(a,shift) (a)
  131. #define SHL16(a,shift) (a)
  132. #define SHR32(a,shift) (a)
  133. #define SHL32(a,shift) (a)
  134. #define PSHR16(a,shift) (a)
  135. #define PSHR32(a,shift) (a)
  136. #define VSHR32(a,shift) (a)
  137. #define SATURATE16(x,a) (x)
  138. #define SATURATE32(x,a) (x)
  139. #define PSHR(a,shift) (a)
  140. #define SHR(a,shift) (a)
  141. #define SHL(a,shift) (a)
  142. #define SATURATE(x,a) (x)
  143. #define ADD16(a,b) ((a)+(b))
  144. #define SUB16(a,b) ((a)-(b))
  145. #define ADD32(a,b) ((a)+(b))
  146. #define SUB32(a,b) ((a)-(b))
  147. #define MULT16_16_16(a,b) ((a)*(b))
  148. #define MULT16_16(a,b) ((spx_word32_t)(a)*(spx_word32_t)(b))
  149. #define MAC16_16(c,a,b) ((c)+(spx_word32_t)(a)*(spx_word32_t)(b))
  150. #define MULT16_32_Q11(a,b) ((a)*(b))
  151. #define MULT16_32_Q13(a,b) ((a)*(b))
  152. #define MULT16_32_Q14(a,b) ((a)*(b))
  153. #define MULT16_32_Q15(a,b) ((a)*(b))
  154. #define MULT16_32_P15(a,b) ((a)*(b))
  155. #define MAC16_32_Q11(c,a,b) ((c)+(a)*(b))
  156. #define MAC16_32_Q15(c,a,b) ((c)+(a)*(b))
  157. #define MAC16_16_Q11(c,a,b) ((c)+(a)*(b))
  158. #define MAC16_16_Q13(c,a,b) ((c)+(a)*(b))
  159. #define MAC16_16_P13(c,a,b) ((c)+(a)*(b))
  160. #define MULT16_16_Q11_32(a,b) ((a)*(b))
  161. #define MULT16_16_Q13(a,b) ((a)*(b))
  162. #define MULT16_16_Q14(a,b) ((a)*(b))
  163. #define MULT16_16_Q15(a,b) ((a)*(b))
  164. #define MULT16_16_P15(a,b) ((a)*(b))
  165. #define MULT16_16_P13(a,b) ((a)*(b))
  166. #define MULT16_16_P14(a,b) ((a)*(b))
  167. #define DIV32_16(a,b) (((spx_word32_t)(a))/(spx_word16_t)(b))
  168. #define PDIV32_16(a,b) (((spx_word32_t)(a))/(spx_word16_t)(b))
  169. #define DIV32(a,b) (((spx_word32_t)(a))/(spx_word32_t)(b))
  170. #define PDIV32(a,b) (((spx_word32_t)(a))/(spx_word32_t)(b))
  171. #endif
  172. #if defined (CONFIG_TI_C54X) || defined (CONFIG_TI_C55X)
  173. /* 2 on TI C5x DSP */
  174. #define BYTES_PER_CHAR 2
  175. #define BITS_PER_CHAR 16
  176. #define LOG2_BITS_PER_CHAR 4
  177. #else
  178. #define BYTES_PER_CHAR 1
  179. #define BITS_PER_CHAR 8
  180. #define LOG2_BITS_PER_CHAR 3
  181. #endif
  182. #ifdef FIXED_DEBUG
  183. extern long long spx_mips;
  184. #endif
  185. #endif