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.

210 lines
12KB

  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_convert.h"
  23. /* flat conversions */
  24. extern void ff_conv_s16_to_s32_sse2(int16_t *dst, const int32_t *src, int len);
  25. extern void ff_conv_s16_to_flt_sse2(float *dst, const int16_t *src, int len);
  26. extern void ff_conv_s16_to_flt_sse4(float *dst, const int16_t *src, int len);
  27. extern void ff_conv_s32_to_s16_mmx (int16_t *dst, const int32_t *src, int len);
  28. extern void ff_conv_s32_to_s16_sse2(int16_t *dst, const int32_t *src, int len);
  29. extern void ff_conv_s32_to_flt_sse2(float *dst, const int32_t *src, int len);
  30. extern void ff_conv_s32_to_flt_avx (float *dst, const int32_t *src, int len);
  31. extern void ff_conv_flt_to_s16_sse2(int16_t *dst, const float *src, int len);
  32. extern void ff_conv_flt_to_s32_sse2(int32_t *dst, const float *src, int len);
  33. extern void ff_conv_flt_to_s32_avx (int32_t *dst, const float *src, int len);
  34. /* interleave conversions */
  35. extern void ff_conv_s16p_to_s16_2ch_sse2(int16_t *dst, int16_t *const *src,
  36. int len, int channels);
  37. extern void ff_conv_s16p_to_s16_2ch_avx (int16_t *dst, int16_t *const *src,
  38. int len, int channels);
  39. extern void ff_conv_s16p_to_s16_6ch_sse2(int16_t *dst, int16_t *const *src,
  40. int len, int channels);
  41. extern void ff_conv_s16p_to_s16_6ch_sse2slow(int16_t *dst, int16_t *const *src,
  42. int len, int channels);
  43. extern void ff_conv_s16p_to_s16_6ch_avx (int16_t *dst, int16_t *const *src,
  44. int len, int channels);
  45. extern void ff_conv_s16p_to_flt_2ch_sse2(float *dst, int16_t *const *src,
  46. int len, int channels);
  47. extern void ff_conv_s16p_to_flt_2ch_avx (float *dst, int16_t *const *src,
  48. int len, int channels);
  49. extern void ff_conv_s16p_to_flt_6ch_sse2 (float *dst, int16_t *const *src,
  50. int len, int channels);
  51. extern void ff_conv_s16p_to_flt_6ch_ssse3(float *dst, int16_t *const *src,
  52. int len, int channels);
  53. extern void ff_conv_s16p_to_flt_6ch_avx (float *dst, int16_t *const *src,
  54. int len, int channels);
  55. extern void ff_conv_fltp_to_s16_2ch_sse2 (int16_t *dst, float *const *src,
  56. int len, int channels);
  57. extern void ff_conv_fltp_to_s16_2ch_ssse3(int16_t *dst, float *const *src,
  58. int len, int channels);
  59. extern void ff_conv_fltp_to_s16_6ch_sse (int16_t *dst, float *const *src,
  60. int len, int channels);
  61. extern void ff_conv_fltp_to_s16_6ch_sse2(int16_t *dst, float *const *src,
  62. int len, int channels);
  63. extern void ff_conv_fltp_to_s16_6ch_avx (int16_t *dst, float *const *src,
  64. int len, int channels);
  65. extern void ff_conv_fltp_to_flt_2ch_sse(float *dst, float *const *src, int len,
  66. int channels);
  67. extern void ff_conv_fltp_to_flt_2ch_avx(float *dst, float *const *src, int len,
  68. int channels);
  69. extern void ff_conv_fltp_to_flt_6ch_mmx (float *dst, float *const *src, int len,
  70. int channels);
  71. extern void ff_conv_fltp_to_flt_6ch_sse4(float *dst, float *const *src, int len,
  72. int channels);
  73. extern void ff_conv_fltp_to_flt_6ch_avx (float *dst, float *const *src, int len,
  74. int channels);
  75. /* deinterleave conversions */
  76. extern void ff_conv_s16_to_s16p_2ch_sse2(int16_t *const *dst, int16_t *src,
  77. int len, int channels);
  78. extern void ff_conv_s16_to_s16p_2ch_ssse3(int16_t *const *dst, int16_t *src,
  79. int len, int channels);
  80. extern void ff_conv_s16_to_s16p_2ch_avx (int16_t *const *dst, int16_t *src,
  81. int len, int channels);
  82. extern void ff_conv_s16_to_s16p_6ch_sse2 (int16_t *const *dst, int16_t *src,
  83. int len, int channels);
  84. extern void ff_conv_s16_to_s16p_6ch_ssse3(int16_t *const *dst, int16_t *src,
  85. int len, int channels);
  86. extern void ff_conv_s16_to_s16p_6ch_avx (int16_t *const *dst, int16_t *src,
  87. int len, int channels);
  88. extern void ff_conv_s16_to_fltp_2ch_sse2(float *const *dst, int16_t *src,
  89. int len, int channels);
  90. extern void ff_conv_s16_to_fltp_2ch_avx (float *const *dst, int16_t *src,
  91. int len, int channels);
  92. av_cold void ff_audio_convert_init_x86(AudioConvert *ac)
  93. {
  94. #if HAVE_YASM
  95. int mm_flags = av_get_cpu_flags();
  96. if (mm_flags & AV_CPU_FLAG_MMX && HAVE_MMX) {
  97. ff_audio_convert_set_func(ac, AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_S32,
  98. 0, 1, 8, "MMX", ff_conv_s32_to_s16_mmx);
  99. ff_audio_convert_set_func(ac, AV_SAMPLE_FMT_FLT, AV_SAMPLE_FMT_FLTP,
  100. 6, 1, 4, "MMX", ff_conv_fltp_to_flt_6ch_mmx);
  101. }
  102. if (mm_flags & AV_CPU_FLAG_SSE && HAVE_SSE) {
  103. ff_audio_convert_set_func(ac, AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_FLTP,
  104. 6, 1, 2, "SSE", ff_conv_fltp_to_s16_6ch_sse);
  105. ff_audio_convert_set_func(ac, AV_SAMPLE_FMT_FLT, AV_SAMPLE_FMT_FLTP,
  106. 2, 16, 8, "SSE", ff_conv_fltp_to_flt_2ch_sse);
  107. }
  108. if (mm_flags & AV_CPU_FLAG_SSE2 && HAVE_SSE) {
  109. if (!(mm_flags & AV_CPU_FLAG_SSE2SLOW)) {
  110. ff_audio_convert_set_func(ac, AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_S32,
  111. 0, 16, 16, "SSE2", ff_conv_s32_to_s16_sse2);
  112. ff_audio_convert_set_func(ac, AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_S16P,
  113. 6, 16, 8, "SSE2", ff_conv_s16p_to_s16_6ch_sse2);
  114. ff_audio_convert_set_func(ac, AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_FLTP,
  115. 6, 16, 4, "SSE2", ff_conv_fltp_to_s16_6ch_sse2);
  116. } else {
  117. ff_audio_convert_set_func(ac, AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_S16P,
  118. 6, 1, 4, "SSE2SLOW", ff_conv_s16p_to_s16_6ch_sse2slow);
  119. }
  120. ff_audio_convert_set_func(ac, AV_SAMPLE_FMT_S32, AV_SAMPLE_FMT_S16,
  121. 0, 16, 8, "SSE2", ff_conv_s16_to_s32_sse2);
  122. ff_audio_convert_set_func(ac, AV_SAMPLE_FMT_FLT, AV_SAMPLE_FMT_S16,
  123. 0, 16, 8, "SSE2", ff_conv_s16_to_flt_sse2);
  124. ff_audio_convert_set_func(ac, AV_SAMPLE_FMT_FLT, AV_SAMPLE_FMT_S32,
  125. 0, 16, 8, "SSE2", ff_conv_s32_to_flt_sse2);
  126. ff_audio_convert_set_func(ac, AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_FLT,
  127. 0, 16, 16, "SSE2", ff_conv_flt_to_s16_sse2);
  128. ff_audio_convert_set_func(ac, AV_SAMPLE_FMT_S32, AV_SAMPLE_FMT_FLT,
  129. 0, 16, 16, "SSE2", ff_conv_flt_to_s32_sse2);
  130. ff_audio_convert_set_func(ac, AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_S16P,
  131. 2, 16, 16, "SSE2", ff_conv_s16p_to_s16_2ch_sse2);
  132. ff_audio_convert_set_func(ac, AV_SAMPLE_FMT_FLT, AV_SAMPLE_FMT_S16P,
  133. 2, 16, 8, "SSE2", ff_conv_s16p_to_flt_2ch_sse2);
  134. ff_audio_convert_set_func(ac, AV_SAMPLE_FMT_FLT, AV_SAMPLE_FMT_S16P,
  135. 6, 16, 4, "SSE2", ff_conv_s16p_to_flt_6ch_sse2);
  136. ff_audio_convert_set_func(ac, AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_FLTP,
  137. 2, 16, 4, "SSE2", ff_conv_fltp_to_s16_2ch_sse2);
  138. ff_audio_convert_set_func(ac, AV_SAMPLE_FMT_S16P, AV_SAMPLE_FMT_S16,
  139. 2, 16, 8, "SSE2", ff_conv_s16_to_s16p_2ch_sse2);
  140. ff_audio_convert_set_func(ac, AV_SAMPLE_FMT_S16P, AV_SAMPLE_FMT_S16,
  141. 6, 16, 4, "SSE2", ff_conv_s16_to_s16p_6ch_sse2);
  142. ff_audio_convert_set_func(ac, AV_SAMPLE_FMT_FLTP, AV_SAMPLE_FMT_S16,
  143. 2, 16, 8, "SSE2", ff_conv_s16_to_fltp_2ch_sse2);
  144. }
  145. if (mm_flags & AV_CPU_FLAG_SSSE3 && HAVE_SSE) {
  146. ff_audio_convert_set_func(ac, AV_SAMPLE_FMT_FLT, AV_SAMPLE_FMT_S16P,
  147. 6, 16, 4, "SSSE3", ff_conv_s16p_to_flt_6ch_ssse3);
  148. ff_audio_convert_set_func(ac, AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_FLTP,
  149. 2, 16, 4, "SSSE3", ff_conv_fltp_to_s16_2ch_ssse3);
  150. ff_audio_convert_set_func(ac, AV_SAMPLE_FMT_S16P, AV_SAMPLE_FMT_S16,
  151. 2, 16, 8, "SSSE3", ff_conv_s16_to_s16p_2ch_ssse3);
  152. ff_audio_convert_set_func(ac, AV_SAMPLE_FMT_S16P, AV_SAMPLE_FMT_S16,
  153. 6, 16, 4, "SSSE3", ff_conv_s16_to_s16p_6ch_ssse3);
  154. }
  155. if (mm_flags & AV_CPU_FLAG_SSE4 && HAVE_SSE) {
  156. ff_audio_convert_set_func(ac, AV_SAMPLE_FMT_FLT, AV_SAMPLE_FMT_S16,
  157. 0, 16, 8, "SSE4", ff_conv_s16_to_flt_sse4);
  158. ff_audio_convert_set_func(ac, AV_SAMPLE_FMT_FLT, AV_SAMPLE_FMT_FLTP,
  159. 6, 16, 4, "SSE4", ff_conv_fltp_to_flt_6ch_sse4);
  160. }
  161. if (mm_flags & AV_CPU_FLAG_AVX && HAVE_AVX) {
  162. ff_audio_convert_set_func(ac, AV_SAMPLE_FMT_FLT, AV_SAMPLE_FMT_S32,
  163. 0, 32, 16, "AVX", ff_conv_s32_to_flt_avx);
  164. ff_audio_convert_set_func(ac, AV_SAMPLE_FMT_S32, AV_SAMPLE_FMT_FLT,
  165. 0, 32, 32, "AVX", ff_conv_flt_to_s32_avx);
  166. ff_audio_convert_set_func(ac, AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_S16P,
  167. 2, 16, 16, "AVX", ff_conv_s16p_to_s16_2ch_avx);
  168. ff_audio_convert_set_func(ac, AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_S16P,
  169. 6, 16, 8, "AVX", ff_conv_s16p_to_s16_6ch_avx);
  170. ff_audio_convert_set_func(ac, AV_SAMPLE_FMT_FLT, AV_SAMPLE_FMT_S16P,
  171. 2, 16, 8, "AVX", ff_conv_s16p_to_flt_2ch_avx);
  172. ff_audio_convert_set_func(ac, AV_SAMPLE_FMT_FLT, AV_SAMPLE_FMT_S16P,
  173. 6, 16, 4, "AVX", ff_conv_s16p_to_flt_6ch_avx);
  174. ff_audio_convert_set_func(ac, AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_FLTP,
  175. 6, 16, 4, "AVX", ff_conv_fltp_to_s16_6ch_avx);
  176. ff_audio_convert_set_func(ac, AV_SAMPLE_FMT_FLT, AV_SAMPLE_FMT_FLTP,
  177. 6, 16, 4, "AVX", ff_conv_fltp_to_flt_6ch_avx);
  178. ff_audio_convert_set_func(ac, AV_SAMPLE_FMT_S16P, AV_SAMPLE_FMT_S16,
  179. 2, 16, 8, "AVX", ff_conv_s16_to_s16p_2ch_avx);
  180. ff_audio_convert_set_func(ac, AV_SAMPLE_FMT_S16P, AV_SAMPLE_FMT_S16,
  181. 6, 16, 4, "AVX", ff_conv_s16_to_s16p_6ch_avx);
  182. ff_audio_convert_set_func(ac, AV_SAMPLE_FMT_FLTP, AV_SAMPLE_FMT_S16,
  183. 2, 16, 8, "AVX", ff_conv_s16_to_fltp_2ch_avx);
  184. }
  185. #endif
  186. }