main_sse.h 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248
  1. /* Copyright (c) 2014, Cisco Systems, INC
  2. Written by XiangMingZhu WeiZhou MinPeng YanWang
  3. Redistribution and use in source and binary forms, with or without
  4. modification, are permitted provided that the following conditions
  5. are met:
  6. - Redistributions of source code must retain the above copyright
  7. notice, this list of conditions and the following disclaimer.
  8. - Redistributions in binary form must reproduce the above copyright
  9. notice, this list of conditions and the following disclaimer in the
  10. documentation and/or other materials provided with the distribution.
  11. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  12. ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  13. LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  14. A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
  15. OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  16. EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  17. PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  18. PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  19. LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  20. NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  21. SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  22. */
  23. #ifndef MAIN_SSE_H
  24. #define MAIN_SSE_H
  25. #ifdef HAVE_CONFIG_H
  26. #include "config.h"
  27. #endif
  28. # if defined(OPUS_X86_MAY_HAVE_SSE4_1)
  29. #if 0 /* FIXME: SSE disabled until silk_VQ_WMat_EC_sse4_1() gets updated. */
  30. # define OVERRIDE_silk_VQ_WMat_EC
  31. void silk_VQ_WMat_EC_sse4_1(
  32. opus_int8 *ind, /* O index of best codebook vector */
  33. opus_int32 *rate_dist_Q14, /* O best weighted quant error + mu * rate */
  34. opus_int *gain_Q7, /* O sum of absolute LTP coefficients */
  35. const opus_int16 *in_Q14, /* I input vector to be quantized */
  36. const opus_int32 *W_Q18, /* I weighting matrix */
  37. const opus_int8 *cb_Q7, /* I codebook */
  38. const opus_uint8 *cb_gain_Q7, /* I codebook effective gain */
  39. const opus_uint8 *cl_Q5, /* I code length for each codebook vector */
  40. const opus_int mu_Q9, /* I tradeoff betw. weighted error and rate */
  41. const opus_int32 max_gain_Q7, /* I maximum sum of absolute LTP coefficients */
  42. opus_int L /* I number of vectors in codebook */
  43. );
  44. #if defined OPUS_X86_PRESUME_SSE4_1
  45. #define silk_VQ_WMat_EC(ind, rate_dist_Q14, gain_Q7, in_Q14, W_Q18, cb_Q7, cb_gain_Q7, cl_Q5, \
  46. mu_Q9, max_gain_Q7, L, arch) \
  47. ((void)(arch),silk_VQ_WMat_EC_sse4_1(ind, rate_dist_Q14, gain_Q7, in_Q14, W_Q18, cb_Q7, cb_gain_Q7, cl_Q5, \
  48. mu_Q9, max_gain_Q7, L))
  49. #else
  50. extern void (*const SILK_VQ_WMAT_EC_IMPL[OPUS_ARCHMASK + 1])(
  51. opus_int8 *ind, /* O index of best codebook vector */
  52. opus_int32 *rate_dist_Q14, /* O best weighted quant error + mu * rate */
  53. opus_int *gain_Q7, /* O sum of absolute LTP coefficients */
  54. const opus_int16 *in_Q14, /* I input vector to be quantized */
  55. const opus_int32 *W_Q18, /* I weighting matrix */
  56. const opus_int8 *cb_Q7, /* I codebook */
  57. const opus_uint8 *cb_gain_Q7, /* I codebook effective gain */
  58. const opus_uint8 *cl_Q5, /* I code length for each codebook vector */
  59. const opus_int mu_Q9, /* I tradeoff betw. weighted error and rate */
  60. const opus_int32 max_gain_Q7, /* I maximum sum of absolute LTP coefficients */
  61. opus_int L /* I number of vectors in codebook */
  62. );
  63. # define silk_VQ_WMat_EC(ind, rate_dist_Q14, gain_Q7, in_Q14, W_Q18, cb_Q7, cb_gain_Q7, cl_Q5, \
  64. mu_Q9, max_gain_Q7, L, arch) \
  65. ((*SILK_VQ_WMAT_EC_IMPL[(arch) & OPUS_ARCHMASK])(ind, rate_dist_Q14, gain_Q7, in_Q14, W_Q18, cb_Q7, cb_gain_Q7, cl_Q5, \
  66. mu_Q9, max_gain_Q7, L))
  67. #endif
  68. #endif
  69. #if 0 /* FIXME: SSE disabled until the NSQ code gets updated. */
  70. # define OVERRIDE_silk_NSQ
  71. void silk_NSQ_sse4_1(
  72. const silk_encoder_state *psEncC, /* I Encoder State */
  73. silk_nsq_state *NSQ, /* I/O NSQ state */
  74. SideInfoIndices *psIndices, /* I/O Quantization Indices */
  75. const opus_int32 x_Q3[], /* I Prefiltered input signal */
  76. opus_int8 pulses[], /* O Quantized pulse signal */
  77. const opus_int16 PredCoef_Q12[ 2 * MAX_LPC_ORDER ], /* I Short term prediction coefs */
  78. const opus_int16 LTPCoef_Q14[ LTP_ORDER * MAX_NB_SUBFR ], /* I Long term prediction coefs */
  79. const opus_int16 AR2_Q13[ MAX_NB_SUBFR * MAX_SHAPE_LPC_ORDER ], /* I Noise shaping coefs */
  80. const opus_int HarmShapeGain_Q14[ MAX_NB_SUBFR ], /* I Long term shaping coefs */
  81. const opus_int Tilt_Q14[ MAX_NB_SUBFR ], /* I Spectral tilt */
  82. const opus_int32 LF_shp_Q14[ MAX_NB_SUBFR ], /* I Low frequency shaping coefs */
  83. const opus_int32 Gains_Q16[ MAX_NB_SUBFR ], /* I Quantization step sizes */
  84. const opus_int pitchL[ MAX_NB_SUBFR ], /* I Pitch lags */
  85. const opus_int Lambda_Q10, /* I Rate/distortion tradeoff */
  86. const opus_int LTP_scale_Q14 /* I LTP state scaling */
  87. );
  88. #if defined OPUS_X86_PRESUME_SSE4_1
  89. #define silk_NSQ(psEncC, NSQ, psIndices, x_Q3, pulses, PredCoef_Q12, LTPCoef_Q14, AR2_Q13, \
  90. HarmShapeGain_Q14, Tilt_Q14, LF_shp_Q14, Gains_Q16, pitchL, Lambda_Q10, LTP_scale_Q14, arch) \
  91. ((void)(arch),silk_NSQ_sse4_1(psEncC, NSQ, psIndices, x_Q3, pulses, PredCoef_Q12, LTPCoef_Q14, AR2_Q13, \
  92. HarmShapeGain_Q14, Tilt_Q14, LF_shp_Q14, Gains_Q16, pitchL, Lambda_Q10, LTP_scale_Q14))
  93. #else
  94. extern void (*const SILK_NSQ_IMPL[OPUS_ARCHMASK + 1])(
  95. const silk_encoder_state *psEncC, /* I Encoder State */
  96. silk_nsq_state *NSQ, /* I/O NSQ state */
  97. SideInfoIndices *psIndices, /* I/O Quantization Indices */
  98. const opus_int32 x_Q3[], /* I Prefiltered input signal */
  99. opus_int8 pulses[], /* O Quantized pulse signal */
  100. const opus_int16 PredCoef_Q12[ 2 * MAX_LPC_ORDER ], /* I Short term prediction coefs */
  101. const opus_int16 LTPCoef_Q14[ LTP_ORDER * MAX_NB_SUBFR ], /* I Long term prediction coefs */
  102. const opus_int16 AR2_Q13[ MAX_NB_SUBFR * MAX_SHAPE_LPC_ORDER ], /* I Noise shaping coefs */
  103. const opus_int HarmShapeGain_Q14[ MAX_NB_SUBFR ], /* I Long term shaping coefs */
  104. const opus_int Tilt_Q14[ MAX_NB_SUBFR ], /* I Spectral tilt */
  105. const opus_int32 LF_shp_Q14[ MAX_NB_SUBFR ], /* I Low frequency shaping coefs */
  106. const opus_int32 Gains_Q16[ MAX_NB_SUBFR ], /* I Quantization step sizes */
  107. const opus_int pitchL[ MAX_NB_SUBFR ], /* I Pitch lags */
  108. const opus_int Lambda_Q10, /* I Rate/distortion tradeoff */
  109. const opus_int LTP_scale_Q14 /* I LTP state scaling */
  110. );
  111. # define silk_NSQ(psEncC, NSQ, psIndices, x_Q3, pulses, PredCoef_Q12, LTPCoef_Q14, AR2_Q13, \
  112. HarmShapeGain_Q14, Tilt_Q14, LF_shp_Q14, Gains_Q16, pitchL, Lambda_Q10, LTP_scale_Q14, arch) \
  113. ((*SILK_NSQ_IMPL[(arch) & OPUS_ARCHMASK])(psEncC, NSQ, psIndices, x_Q3, pulses, PredCoef_Q12, LTPCoef_Q14, AR2_Q13, \
  114. HarmShapeGain_Q14, Tilt_Q14, LF_shp_Q14, Gains_Q16, pitchL, Lambda_Q10, LTP_scale_Q14))
  115. #endif
  116. # define OVERRIDE_silk_NSQ_del_dec
  117. void silk_NSQ_del_dec_sse4_1(
  118. const silk_encoder_state *psEncC, /* I Encoder State */
  119. silk_nsq_state *NSQ, /* I/O NSQ state */
  120. SideInfoIndices *psIndices, /* I/O Quantization Indices */
  121. const opus_int32 x_Q3[], /* I Prefiltered input signal */
  122. opus_int8 pulses[], /* O Quantized pulse signal */
  123. const opus_int16 PredCoef_Q12[ 2 * MAX_LPC_ORDER ], /* I Short term prediction coefs */
  124. const opus_int16 LTPCoef_Q14[ LTP_ORDER * MAX_NB_SUBFR ], /* I Long term prediction coefs */
  125. const opus_int16 AR2_Q13[ MAX_NB_SUBFR * MAX_SHAPE_LPC_ORDER ], /* I Noise shaping coefs */
  126. const opus_int HarmShapeGain_Q14[ MAX_NB_SUBFR ], /* I Long term shaping coefs */
  127. const opus_int Tilt_Q14[ MAX_NB_SUBFR ], /* I Spectral tilt */
  128. const opus_int32 LF_shp_Q14[ MAX_NB_SUBFR ], /* I Low frequency shaping coefs */
  129. const opus_int32 Gains_Q16[ MAX_NB_SUBFR ], /* I Quantization step sizes */
  130. const opus_int pitchL[ MAX_NB_SUBFR ], /* I Pitch lags */
  131. const opus_int Lambda_Q10, /* I Rate/distortion tradeoff */
  132. const opus_int LTP_scale_Q14 /* I LTP state scaling */
  133. );
  134. #if defined OPUS_X86_PRESUME_SSE4_1
  135. #define silk_NSQ_del_dec(psEncC, NSQ, psIndices, x_Q3, pulses, PredCoef_Q12, LTPCoef_Q14, AR2_Q13, \
  136. HarmShapeGain_Q14, Tilt_Q14, LF_shp_Q14, Gains_Q16, pitchL, Lambda_Q10, LTP_scale_Q14, arch) \
  137. ((void)(arch),silk_NSQ_del_dec_sse4_1(psEncC, NSQ, psIndices, x_Q3, pulses, PredCoef_Q12, LTPCoef_Q14, AR2_Q13, \
  138. HarmShapeGain_Q14, Tilt_Q14, LF_shp_Q14, Gains_Q16, pitchL, Lambda_Q10, LTP_scale_Q14))
  139. #else
  140. extern void (*const SILK_NSQ_DEL_DEC_IMPL[OPUS_ARCHMASK + 1])(
  141. const silk_encoder_state *psEncC, /* I Encoder State */
  142. silk_nsq_state *NSQ, /* I/O NSQ state */
  143. SideInfoIndices *psIndices, /* I/O Quantization Indices */
  144. const opus_int32 x_Q3[], /* I Prefiltered input signal */
  145. opus_int8 pulses[], /* O Quantized pulse signal */
  146. const opus_int16 PredCoef_Q12[ 2 * MAX_LPC_ORDER ], /* I Short term prediction coefs */
  147. const opus_int16 LTPCoef_Q14[ LTP_ORDER * MAX_NB_SUBFR ], /* I Long term prediction coefs */
  148. const opus_int16 AR2_Q13[ MAX_NB_SUBFR * MAX_SHAPE_LPC_ORDER ], /* I Noise shaping coefs */
  149. const opus_int HarmShapeGain_Q14[ MAX_NB_SUBFR ], /* I Long term shaping coefs */
  150. const opus_int Tilt_Q14[ MAX_NB_SUBFR ], /* I Spectral tilt */
  151. const opus_int32 LF_shp_Q14[ MAX_NB_SUBFR ], /* I Low frequency shaping coefs */
  152. const opus_int32 Gains_Q16[ MAX_NB_SUBFR ], /* I Quantization step sizes */
  153. const opus_int pitchL[ MAX_NB_SUBFR ], /* I Pitch lags */
  154. const opus_int Lambda_Q10, /* I Rate/distortion tradeoff */
  155. const opus_int LTP_scale_Q14 /* I LTP state scaling */
  156. );
  157. # define silk_NSQ_del_dec(psEncC, NSQ, psIndices, x_Q3, pulses, PredCoef_Q12, LTPCoef_Q14, AR2_Q13, \
  158. HarmShapeGain_Q14, Tilt_Q14, LF_shp_Q14, Gains_Q16, pitchL, Lambda_Q10, LTP_scale_Q14, arch) \
  159. ((*SILK_NSQ_DEL_DEC_IMPL[(arch) & OPUS_ARCHMASK])(psEncC, NSQ, psIndices, x_Q3, pulses, PredCoef_Q12, LTPCoef_Q14, AR2_Q13, \
  160. HarmShapeGain_Q14, Tilt_Q14, LF_shp_Q14, Gains_Q16, pitchL, Lambda_Q10, LTP_scale_Q14))
  161. #endif
  162. #endif
  163. void silk_noise_shape_quantizer(
  164. silk_nsq_state *NSQ, /* I/O NSQ state */
  165. opus_int signalType, /* I Signal type */
  166. const opus_int32 x_sc_Q10[], /* I */
  167. opus_int8 pulses[], /* O */
  168. opus_int16 xq[], /* O */
  169. opus_int32 sLTP_Q15[], /* I/O LTP state */
  170. const opus_int16 a_Q12[], /* I Short term prediction coefs */
  171. const opus_int16 b_Q14[], /* I Long term prediction coefs */
  172. const opus_int16 AR_shp_Q13[], /* I Noise shaping AR coefs */
  173. opus_int lag, /* I Pitch lag */
  174. opus_int32 HarmShapeFIRPacked_Q14, /* I */
  175. opus_int Tilt_Q14, /* I Spectral tilt */
  176. opus_int32 LF_shp_Q14, /* I */
  177. opus_int32 Gain_Q16, /* I */
  178. opus_int Lambda_Q10, /* I */
  179. opus_int offset_Q10, /* I */
  180. opus_int length, /* I Input length */
  181. opus_int shapingLPCOrder, /* I Noise shaping AR filter order */
  182. opus_int predictLPCOrder, /* I Prediction filter order */
  183. int arch /* I Architecture */
  184. );
  185. /**************************/
  186. /* Noise level estimation */
  187. /**************************/
  188. void silk_VAD_GetNoiseLevels(
  189. const opus_int32 pX[ VAD_N_BANDS ], /* I subband energies */
  190. silk_VAD_state *psSilk_VAD /* I/O Pointer to Silk VAD state */
  191. );
  192. # define OVERRIDE_silk_VAD_GetSA_Q8
  193. opus_int silk_VAD_GetSA_Q8_sse4_1(
  194. silk_encoder_state *psEnC,
  195. const opus_int16 pIn[]
  196. );
  197. #if defined(OPUS_X86_PRESUME_SSE4_1)
  198. #define silk_VAD_GetSA_Q8(psEnC, pIn, arch) ((void)(arch),silk_VAD_GetSA_Q8_sse4_1(psEnC, pIn))
  199. #else
  200. # define silk_VAD_GetSA_Q8(psEnC, pIn, arch) \
  201. ((*SILK_VAD_GETSA_Q8_IMPL[(arch) & OPUS_ARCHMASK])(psEnC, pIn))
  202. extern opus_int (*const SILK_VAD_GETSA_Q8_IMPL[OPUS_ARCHMASK + 1])(
  203. silk_encoder_state *psEnC,
  204. const opus_int16 pIn[]);
  205. #endif
  206. # endif
  207. #endif