arch.h 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241
  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. #define FIXED_POINT
  40. /* A couple test to catch stupid option combinations */
  41. #ifdef FIXED_POINT
  42. #ifdef FLOATING_POINT
  43. #error You cannot compile as floating point and fixed point at the same time
  44. #endif
  45. #ifdef _USE_SSE
  46. #error SSE is only for floating-point
  47. #endif
  48. #if ((defined (ARM4_ASM)||defined (ARM4_ASM)) && defined(BFIN_ASM)) || (defined (ARM4_ASM)&&defined(ARM5E_ASM))
  49. #error Make up your mind. What CPU do you have?
  50. #endif
  51. #ifdef VORBIS_PSYCHO
  52. #error Vorbis-psy model currently not implemented in fixed-point
  53. #endif
  54. #else
  55. #ifndef FLOATING_POINT
  56. #error You now need to define either FIXED_POINT or FLOATING_POINT
  57. #endif
  58. #if defined (ARM4_ASM) || defined(ARM5E_ASM) || defined(BFIN_ASM)
  59. #error I suppose you can have a [ARM4/ARM5E/Blackfin] that has float instructions?
  60. #endif
  61. #ifdef FIXED_POINT_DEBUG
  62. #error "Don't you think enabling fixed-point is a good thing to do if you want to debug that?"
  63. #endif
  64. #endif
  65. #ifndef OUTSIDE_SPEEX
  66. #include "speex/speex_types.h"
  67. #endif
  68. #define ABS(x) ((x) < 0 ? (-(x)) : (x)) /**< Absolute integer value. */
  69. #define ABS16(x) ((x) < 0 ? (-(x)) : (x)) /**< Absolute 16-bit value. */
  70. #define MIN16(a,b) ((a) < (b) ? (a) : (b)) /**< Maximum 16-bit value. */
  71. #define MAX16(a,b) ((a) > (b) ? (a) : (b)) /**< Maximum 16-bit value. */
  72. #define ABS32(x) ((x) < 0 ? (-(x)) : (x)) /**< Absolute 32-bit value. */
  73. #define MIN32(a,b) ((a) < (b) ? (a) : (b)) /**< Maximum 32-bit value. */
  74. #define MAX32(a,b) ((a) > (b) ? (a) : (b)) /**< Maximum 32-bit value. */
  75. #ifdef FIXED_POINT
  76. typedef spx_int16_t spx_word16_t;
  77. typedef spx_int32_t spx_word32_t;
  78. typedef spx_word32_t spx_mem_t;
  79. typedef spx_word16_t spx_coef_t;
  80. typedef spx_word16_t spx_lsp_t;
  81. typedef spx_word32_t spx_sig_t;
  82. #define Q15ONE 32767
  83. #define LPC_SCALING 8192
  84. #define SIG_SCALING 16384
  85. #define LSP_SCALING 8192.
  86. #define GAMMA_SCALING 32768.
  87. #define GAIN_SCALING 64
  88. #define GAIN_SCALING_1 0.015625
  89. #define LPC_SHIFT 13
  90. #define LSP_SHIFT 13
  91. #define SIG_SHIFT 14
  92. #define GAIN_SHIFT 6
  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 PSHR(a,shift) (a)
  143. #define SHR(a,shift) (a)
  144. #define SHL(a,shift) (a)
  145. #define SATURATE(x,a) (x)
  146. #define ADD16(a,b) ((a)+(b))
  147. #define SUB16(a,b) ((a)-(b))
  148. #define ADD32(a,b) ((a)+(b))
  149. #define SUB32(a,b) ((a)-(b))
  150. #define MULT16_16_16(a,b) ((a)*(b))
  151. #define MULT16_16(a,b) ((spx_word32_t)(a)*(spx_word32_t)(b))
  152. #define MAC16_16(c,a,b) ((c)+(spx_word32_t)(a)*(spx_word32_t)(b))
  153. #define MULT16_32_Q11(a,b) ((a)*(b))
  154. #define MULT16_32_Q13(a,b) ((a)*(b))
  155. #define MULT16_32_Q14(a,b) ((a)*(b))
  156. #define MULT16_32_Q15(a,b) ((a)*(b))
  157. #define MULT16_32_P15(a,b) ((a)*(b))
  158. #define MAC16_32_Q11(c,a,b) ((c)+(a)*(b))
  159. #define MAC16_32_Q15(c,a,b) ((c)+(a)*(b))
  160. #define MAC16_16_Q11(c,a,b) ((c)+(a)*(b))
  161. #define MAC16_16_Q13(c,a,b) ((c)+(a)*(b))
  162. #define MAC16_16_P13(c,a,b) ((c)+(a)*(b))
  163. #define MULT16_16_Q11_32(a,b) ((a)*(b))
  164. #define MULT16_16_Q13(a,b) ((a)*(b))
  165. #define MULT16_16_Q14(a,b) ((a)*(b))
  166. #define MULT16_16_Q15(a,b) ((a)*(b))
  167. #define MULT16_16_P15(a,b) ((a)*(b))
  168. #define MULT16_16_P13(a,b) ((a)*(b))
  169. #define MULT16_16_P14(a,b) ((a)*(b))
  170. #define DIV32_16(a,b) (((spx_word32_t)(a))/(spx_word16_t)(b))
  171. #define PDIV32_16(a,b) (((spx_word32_t)(a))/(spx_word16_t)(b))
  172. #define DIV32(a,b) (((spx_word32_t)(a))/(spx_word32_t)(b))
  173. #define PDIV32(a,b) (((spx_word32_t)(a))/(spx_word32_t)(b))
  174. #endif
  175. #if defined (CONFIG_TI_C54X) || defined (CONFIG_TI_C55X)
  176. /* 2 on TI C5x DSP */
  177. #define BYTES_PER_CHAR 2
  178. #define BITS_PER_CHAR 16
  179. #define LOG2_BITS_PER_CHAR 4
  180. #else
  181. #define BYTES_PER_CHAR 1
  182. #define BITS_PER_CHAR 8
  183. #define LOG2_BITS_PER_CHAR 3
  184. #endif
  185. #ifdef FIXED_DEBUG
  186. extern long long spx_mips;
  187. #endif
  188. #endif