You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

215 lines
13KB

  1. /*
  2. * Copyright (c) 2012 Justin Ruggles <justin.ruggles@gmail.com>
  3. *
  4. * This file is part of Libav.
  5. *
  6. * Libav is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU Lesser General Public
  8. * License as published by the Free Software Foundation; either
  9. * version 2.1 of the License, or (at your option) any later version.
  10. *
  11. * Libav is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. * Lesser General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU Lesser General Public
  17. * License along with Libav; if not, write to the Free Software
  18. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  19. */
  20. #include "config.h"
  21. #include "libavutil/cpu.h"
  22. #include "libavresample/audio_mix.h"
  23. extern void ff_mix_2_to_1_fltp_flt_sse(float **src, float **matrix, int len,
  24. int out_ch, int in_ch);
  25. extern void ff_mix_2_to_1_fltp_flt_avx(float **src, float **matrix, int len,
  26. int out_ch, int in_ch);
  27. extern void ff_mix_2_to_1_s16p_flt_sse2(int16_t **src, float **matrix, int len,
  28. int out_ch, int in_ch);
  29. extern void ff_mix_2_to_1_s16p_flt_sse4(int16_t **src, float **matrix, int len,
  30. int out_ch, int in_ch);
  31. extern void ff_mix_2_to_1_s16p_q8_sse2(int16_t **src, int16_t **matrix,
  32. int len, int out_ch, int in_ch);
  33. extern void ff_mix_1_to_2_fltp_flt_sse(float **src, float **matrix, int len,
  34. int out_ch, int in_ch);
  35. extern void ff_mix_1_to_2_fltp_flt_avx(float **src, float **matrix, int len,
  36. int out_ch, int in_ch);
  37. extern void ff_mix_1_to_2_s16p_flt_sse2(int16_t **src, float **matrix, int len,
  38. int out_ch, int in_ch);
  39. extern void ff_mix_1_to_2_s16p_flt_sse4(int16_t **src, float **matrix, int len,
  40. int out_ch, int in_ch);
  41. extern void ff_mix_1_to_2_s16p_flt_avx (int16_t **src, float **matrix, int len,
  42. int out_ch, int in_ch);
  43. #define DEFINE_MIX_3_8_TO_1_2(chan) \
  44. extern void ff_mix_ ## chan ## _to_1_fltp_flt_sse(float **src, \
  45. float **matrix, int len, \
  46. int out_ch, int in_ch); \
  47. extern void ff_mix_ ## chan ## _to_2_fltp_flt_sse(float **src, \
  48. float **matrix, int len, \
  49. int out_ch, int in_ch); \
  50. \
  51. extern void ff_mix_ ## chan ## _to_1_s16p_flt_sse2(int16_t **src, \
  52. float **matrix, int len, \
  53. int out_ch, int in_ch); \
  54. extern void ff_mix_ ## chan ## _to_2_s16p_flt_sse2(int16_t **src, \
  55. float **matrix, int len, \
  56. int out_ch, int in_ch); \
  57. \
  58. extern void ff_mix_ ## chan ## _to_1_s16p_flt_sse4(int16_t **src, \
  59. float **matrix, int len, \
  60. int out_ch, int in_ch); \
  61. extern void ff_mix_ ## chan ## _to_2_s16p_flt_sse4(int16_t **src, \
  62. float **matrix, int len, \
  63. int out_ch, int in_ch); \
  64. \
  65. extern void ff_mix_ ## chan ## _to_1_fltp_flt_avx(float **src, \
  66. float **matrix, int len, \
  67. int out_ch, int in_ch); \
  68. extern void ff_mix_ ## chan ## _to_2_fltp_flt_avx(float **src, \
  69. float **matrix, int len, \
  70. int out_ch, int in_ch); \
  71. \
  72. extern void ff_mix_ ## chan ## _to_1_s16p_flt_avx(int16_t **src, \
  73. float **matrix, int len, \
  74. int out_ch, int in_ch); \
  75. extern void ff_mix_ ## chan ## _to_2_s16p_flt_avx(int16_t **src, \
  76. float **matrix, int len, \
  77. int out_ch, int in_ch); \
  78. \
  79. extern void ff_mix_ ## chan ## _to_1_fltp_flt_fma4(float **src, \
  80. float **matrix, int len, \
  81. int out_ch, int in_ch); \
  82. extern void ff_mix_ ## chan ## _to_2_fltp_flt_fma4(float **src, \
  83. float **matrix, int len, \
  84. int out_ch, int in_ch); \
  85. \
  86. extern void ff_mix_ ## chan ## _to_1_s16p_flt_fma4(int16_t **src, \
  87. float **matrix, int len, \
  88. int out_ch, int in_ch); \
  89. extern void ff_mix_ ## chan ## _to_2_s16p_flt_fma4(int16_t **src, \
  90. float **matrix, int len, \
  91. int out_ch, int in_ch);
  92. DEFINE_MIX_3_8_TO_1_2(3)
  93. DEFINE_MIX_3_8_TO_1_2(4)
  94. DEFINE_MIX_3_8_TO_1_2(5)
  95. DEFINE_MIX_3_8_TO_1_2(6)
  96. DEFINE_MIX_3_8_TO_1_2(7)
  97. DEFINE_MIX_3_8_TO_1_2(8)
  98. #define SET_MIX_3_8_TO_1_2(chan) \
  99. if (mm_flags & AV_CPU_FLAG_SSE && HAVE_SSE) { \
  100. ff_audio_mix_set_func(am, AV_SAMPLE_FMT_FLTP, AV_MIX_COEFF_TYPE_FLT,\
  101. chan, 1, 16, 4, "SSE", \
  102. ff_mix_ ## chan ## _to_1_fltp_flt_sse); \
  103. ff_audio_mix_set_func(am, AV_SAMPLE_FMT_FLTP, AV_MIX_COEFF_TYPE_FLT,\
  104. chan, 2, 16, 4, "SSE", \
  105. ff_mix_## chan ##_to_2_fltp_flt_sse); \
  106. } \
  107. if (mm_flags & AV_CPU_FLAG_SSE2 && HAVE_SSE) { \
  108. ff_audio_mix_set_func(am, AV_SAMPLE_FMT_S16P, AV_MIX_COEFF_TYPE_FLT,\
  109. chan, 1, 16, 8, "SSE2", \
  110. ff_mix_ ## chan ## _to_1_s16p_flt_sse2); \
  111. ff_audio_mix_set_func(am, AV_SAMPLE_FMT_S16P, AV_MIX_COEFF_TYPE_FLT,\
  112. chan, 2, 16, 8, "SSE2", \
  113. ff_mix_ ## chan ## _to_2_s16p_flt_sse2); \
  114. } \
  115. if (mm_flags & AV_CPU_FLAG_SSE4 && HAVE_SSE) { \
  116. ff_audio_mix_set_func(am, AV_SAMPLE_FMT_S16P, AV_MIX_COEFF_TYPE_FLT,\
  117. chan, 1, 16, 8, "SSE4", \
  118. ff_mix_ ## chan ## _to_1_s16p_flt_sse4); \
  119. ff_audio_mix_set_func(am, AV_SAMPLE_FMT_S16P, AV_MIX_COEFF_TYPE_FLT,\
  120. chan, 2, 16, 8, "SSE4", \
  121. ff_mix_ ## chan ## _to_2_s16p_flt_sse4); \
  122. } \
  123. if (mm_flags & AV_CPU_FLAG_AVX && HAVE_AVX) { \
  124. int ptr_align = 32; \
  125. int smp_align = 8; \
  126. if (ARCH_X86_32 || chan >= 6) { \
  127. ptr_align = 16; \
  128. smp_align = 4; \
  129. } \
  130. ff_audio_mix_set_func(am, AV_SAMPLE_FMT_FLTP, AV_MIX_COEFF_TYPE_FLT,\
  131. chan, 1, ptr_align, smp_align, "AVX", \
  132. ff_mix_ ## chan ## _to_1_fltp_flt_avx); \
  133. ff_audio_mix_set_func(am, AV_SAMPLE_FMT_FLTP, AV_MIX_COEFF_TYPE_FLT,\
  134. chan, 2, ptr_align, smp_align, "AVX", \
  135. ff_mix_ ## chan ## _to_2_fltp_flt_avx); \
  136. ff_audio_mix_set_func(am, AV_SAMPLE_FMT_S16P, AV_MIX_COEFF_TYPE_FLT,\
  137. chan, 1, 16, 8, "AVX", \
  138. ff_mix_ ## chan ## _to_1_s16p_flt_avx); \
  139. ff_audio_mix_set_func(am, AV_SAMPLE_FMT_S16P, AV_MIX_COEFF_TYPE_FLT,\
  140. chan, 2, 16, 8, "AVX", \
  141. ff_mix_ ## chan ## _to_2_s16p_flt_avx); \
  142. } \
  143. if (mm_flags & AV_CPU_FLAG_FMA4 && HAVE_FMA4) { \
  144. int ptr_align = 32; \
  145. int smp_align = 8; \
  146. if (ARCH_X86_32 || chan >= 6) { \
  147. ptr_align = 16; \
  148. smp_align = 4; \
  149. } \
  150. ff_audio_mix_set_func(am, AV_SAMPLE_FMT_FLTP, AV_MIX_COEFF_TYPE_FLT,\
  151. chan, 1, ptr_align, smp_align, "FMA4", \
  152. ff_mix_ ## chan ## _to_1_fltp_flt_fma4); \
  153. ff_audio_mix_set_func(am, AV_SAMPLE_FMT_FLTP, AV_MIX_COEFF_TYPE_FLT,\
  154. chan, 2, ptr_align, smp_align, "FMA4", \
  155. ff_mix_ ## chan ## _to_2_fltp_flt_fma4); \
  156. ff_audio_mix_set_func(am, AV_SAMPLE_FMT_S16P, AV_MIX_COEFF_TYPE_FLT,\
  157. chan, 1, 16, 8, "FMA4", \
  158. ff_mix_ ## chan ## _to_1_s16p_flt_fma4); \
  159. ff_audio_mix_set_func(am, AV_SAMPLE_FMT_S16P, AV_MIX_COEFF_TYPE_FLT,\
  160. chan, 2, 16, 8, "FMA4", \
  161. ff_mix_ ## chan ## _to_2_s16p_flt_fma4); \
  162. }
  163. av_cold void ff_audio_mix_init_x86(AudioMix *am)
  164. {
  165. #if HAVE_YASM
  166. int mm_flags = av_get_cpu_flags();
  167. if (mm_flags & AV_CPU_FLAG_SSE && HAVE_SSE) {
  168. ff_audio_mix_set_func(am, AV_SAMPLE_FMT_FLTP, AV_MIX_COEFF_TYPE_FLT,
  169. 2, 1, 16, 8, "SSE", ff_mix_2_to_1_fltp_flt_sse);
  170. ff_audio_mix_set_func(am, AV_SAMPLE_FMT_FLTP, AV_MIX_COEFF_TYPE_FLT,
  171. 1, 2, 16, 4, "SSE", ff_mix_1_to_2_fltp_flt_sse);
  172. }
  173. if (mm_flags & AV_CPU_FLAG_SSE2 && HAVE_SSE) {
  174. ff_audio_mix_set_func(am, AV_SAMPLE_FMT_S16P, AV_MIX_COEFF_TYPE_FLT,
  175. 2, 1, 16, 8, "SSE2", ff_mix_2_to_1_s16p_flt_sse2);
  176. ff_audio_mix_set_func(am, AV_SAMPLE_FMT_S16P, AV_MIX_COEFF_TYPE_Q8,
  177. 2, 1, 16, 8, "SSE2", ff_mix_2_to_1_s16p_q8_sse2);
  178. ff_audio_mix_set_func(am, AV_SAMPLE_FMT_S16P, AV_MIX_COEFF_TYPE_FLT,
  179. 1, 2, 16, 8, "SSE2", ff_mix_1_to_2_s16p_flt_sse2);
  180. }
  181. if (mm_flags & AV_CPU_FLAG_SSE4 && HAVE_SSE) {
  182. ff_audio_mix_set_func(am, AV_SAMPLE_FMT_S16P, AV_MIX_COEFF_TYPE_FLT,
  183. 2, 1, 16, 8, "SSE4", ff_mix_2_to_1_s16p_flt_sse4);
  184. ff_audio_mix_set_func(am, AV_SAMPLE_FMT_S16P, AV_MIX_COEFF_TYPE_FLT,
  185. 1, 2, 16, 8, "SSE4", ff_mix_1_to_2_s16p_flt_sse4);
  186. }
  187. if (mm_flags & AV_CPU_FLAG_AVX && HAVE_AVX) {
  188. ff_audio_mix_set_func(am, AV_SAMPLE_FMT_FLTP, AV_MIX_COEFF_TYPE_FLT,
  189. 2, 1, 32, 16, "AVX", ff_mix_2_to_1_fltp_flt_avx);
  190. ff_audio_mix_set_func(am, AV_SAMPLE_FMT_FLTP, AV_MIX_COEFF_TYPE_FLT,
  191. 1, 2, 32, 8, "AVX", ff_mix_1_to_2_fltp_flt_avx);
  192. ff_audio_mix_set_func(am, AV_SAMPLE_FMT_S16P, AV_MIX_COEFF_TYPE_FLT,
  193. 1, 2, 16, 8, "AVX", ff_mix_1_to_2_s16p_flt_avx);
  194. }
  195. SET_MIX_3_8_TO_1_2(3)
  196. SET_MIX_3_8_TO_1_2(4)
  197. SET_MIX_3_8_TO_1_2(5)
  198. SET_MIX_3_8_TO_1_2(6)
  199. SET_MIX_3_8_TO_1_2(7)
  200. SET_MIX_3_8_TO_1_2(8)
  201. #endif
  202. }