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.

188 lines
10KB

  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. av_cold void ff_audio_convert_init_x86(AudioConvert *ac)
  83. {
  84. #if HAVE_YASM
  85. int mm_flags = av_get_cpu_flags();
  86. if (mm_flags & AV_CPU_FLAG_MMX && HAVE_MMX) {
  87. ff_audio_convert_set_func(ac, AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_S32,
  88. 0, 1, 8, "MMX", ff_conv_s32_to_s16_mmx);
  89. ff_audio_convert_set_func(ac, AV_SAMPLE_FMT_FLT, AV_SAMPLE_FMT_FLTP,
  90. 6, 1, 4, "MMX", ff_conv_fltp_to_flt_6ch_mmx);
  91. }
  92. if (mm_flags & AV_CPU_FLAG_SSE && HAVE_SSE) {
  93. ff_audio_convert_set_func(ac, AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_FLTP,
  94. 6, 1, 2, "SSE", ff_conv_fltp_to_s16_6ch_sse);
  95. ff_audio_convert_set_func(ac, AV_SAMPLE_FMT_FLT, AV_SAMPLE_FMT_FLTP,
  96. 2, 16, 8, "SSE", ff_conv_fltp_to_flt_2ch_sse);
  97. }
  98. if (mm_flags & AV_CPU_FLAG_SSE2 && HAVE_SSE) {
  99. if (!(mm_flags & AV_CPU_FLAG_SSE2SLOW)) {
  100. ff_audio_convert_set_func(ac, AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_S32,
  101. 0, 16, 16, "SSE2", ff_conv_s32_to_s16_sse2);
  102. ff_audio_convert_set_func(ac, AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_S16P,
  103. 6, 16, 8, "SSE2", ff_conv_s16p_to_s16_6ch_sse2);
  104. ff_audio_convert_set_func(ac, AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_FLTP,
  105. 6, 16, 4, "SSE2", ff_conv_fltp_to_s16_6ch_sse2);
  106. } else {
  107. ff_audio_convert_set_func(ac, AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_S16P,
  108. 6, 1, 4, "SSE2SLOW", ff_conv_s16p_to_s16_6ch_sse2slow);
  109. }
  110. ff_audio_convert_set_func(ac, AV_SAMPLE_FMT_S32, AV_SAMPLE_FMT_S16,
  111. 0, 16, 8, "SSE2", ff_conv_s16_to_s32_sse2);
  112. ff_audio_convert_set_func(ac, AV_SAMPLE_FMT_FLT, AV_SAMPLE_FMT_S16,
  113. 0, 16, 8, "SSE2", ff_conv_s16_to_flt_sse2);
  114. ff_audio_convert_set_func(ac, AV_SAMPLE_FMT_FLT, AV_SAMPLE_FMT_S32,
  115. 0, 16, 8, "SSE2", ff_conv_s32_to_flt_sse2);
  116. ff_audio_convert_set_func(ac, AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_FLT,
  117. 0, 16, 16, "SSE2", ff_conv_flt_to_s16_sse2);
  118. ff_audio_convert_set_func(ac, AV_SAMPLE_FMT_S32, AV_SAMPLE_FMT_FLT,
  119. 0, 16, 16, "SSE2", ff_conv_flt_to_s32_sse2);
  120. ff_audio_convert_set_func(ac, AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_S16P,
  121. 2, 16, 16, "SSE2", ff_conv_s16p_to_s16_2ch_sse2);
  122. ff_audio_convert_set_func(ac, AV_SAMPLE_FMT_FLT, AV_SAMPLE_FMT_S16P,
  123. 2, 16, 8, "SSE2", ff_conv_s16p_to_flt_2ch_sse2);
  124. ff_audio_convert_set_func(ac, AV_SAMPLE_FMT_FLT, AV_SAMPLE_FMT_S16P,
  125. 6, 16, 4, "SSE2", ff_conv_s16p_to_flt_6ch_sse2);
  126. ff_audio_convert_set_func(ac, AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_FLTP,
  127. 2, 16, 4, "SSE2", ff_conv_fltp_to_s16_2ch_sse2);
  128. ff_audio_convert_set_func(ac, AV_SAMPLE_FMT_S16P, AV_SAMPLE_FMT_S16,
  129. 2, 16, 8, "SSE2", ff_conv_s16_to_s16p_2ch_sse2);
  130. }
  131. if (mm_flags & AV_CPU_FLAG_SSSE3 && HAVE_SSE) {
  132. ff_audio_convert_set_func(ac, AV_SAMPLE_FMT_FLT, AV_SAMPLE_FMT_S16P,
  133. 6, 16, 4, "SSSE3", ff_conv_s16p_to_flt_6ch_ssse3);
  134. ff_audio_convert_set_func(ac, AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_FLTP,
  135. 2, 16, 4, "SSSE3", ff_conv_fltp_to_s16_2ch_ssse3);
  136. ff_audio_convert_set_func(ac, AV_SAMPLE_FMT_S16P, AV_SAMPLE_FMT_S16,
  137. 2, 16, 8, "SSSE3", ff_conv_s16_to_s16p_2ch_ssse3);
  138. }
  139. if (mm_flags & AV_CPU_FLAG_SSE4 && HAVE_SSE) {
  140. ff_audio_convert_set_func(ac, AV_SAMPLE_FMT_FLT, AV_SAMPLE_FMT_S16,
  141. 0, 16, 8, "SSE4", ff_conv_s16_to_flt_sse4);
  142. ff_audio_convert_set_func(ac, AV_SAMPLE_FMT_FLT, AV_SAMPLE_FMT_FLTP,
  143. 6, 16, 4, "SSE4", ff_conv_fltp_to_flt_6ch_sse4);
  144. }
  145. if (mm_flags & AV_CPU_FLAG_AVX && HAVE_AVX) {
  146. ff_audio_convert_set_func(ac, AV_SAMPLE_FMT_FLT, AV_SAMPLE_FMT_S32,
  147. 0, 32, 16, "AVX", ff_conv_s32_to_flt_avx);
  148. ff_audio_convert_set_func(ac, AV_SAMPLE_FMT_S32, AV_SAMPLE_FMT_FLT,
  149. 0, 32, 32, "AVX", ff_conv_flt_to_s32_avx);
  150. ff_audio_convert_set_func(ac, AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_S16P,
  151. 2, 16, 16, "AVX", ff_conv_s16p_to_s16_2ch_avx);
  152. ff_audio_convert_set_func(ac, AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_S16P,
  153. 6, 16, 8, "AVX", ff_conv_s16p_to_s16_6ch_avx);
  154. ff_audio_convert_set_func(ac, AV_SAMPLE_FMT_FLT, AV_SAMPLE_FMT_S16P,
  155. 2, 16, 8, "AVX", ff_conv_s16p_to_flt_2ch_avx);
  156. ff_audio_convert_set_func(ac, AV_SAMPLE_FMT_FLT, AV_SAMPLE_FMT_S16P,
  157. 6, 16, 4, "AVX", ff_conv_s16p_to_flt_6ch_avx);
  158. ff_audio_convert_set_func(ac, AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_FLTP,
  159. 6, 16, 4, "AVX", ff_conv_fltp_to_s16_6ch_avx);
  160. ff_audio_convert_set_func(ac, AV_SAMPLE_FMT_FLT, AV_SAMPLE_FMT_FLTP,
  161. 6, 16, 4, "AVX", ff_conv_fltp_to_flt_6ch_avx);
  162. ff_audio_convert_set_func(ac, AV_SAMPLE_FMT_S16P, AV_SAMPLE_FMT_S16,
  163. 2, 16, 8, "AVX", ff_conv_s16_to_s16p_2ch_avx);
  164. }
  165. #endif
  166. }