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.

234 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_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. extern void ff_conv_s16_to_fltp_6ch_sse2 (float *const *dst, int16_t *src,
  93. int len, int channels);
  94. extern void ff_conv_s16_to_fltp_6ch_ssse3(float *const *dst, int16_t *src,
  95. int len, int channels);
  96. extern void ff_conv_s16_to_fltp_6ch_sse4 (float *const *dst, int16_t *src,
  97. int len, int channels);
  98. extern void ff_conv_s16_to_fltp_6ch_avx (float *const *dst, int16_t *src,
  99. int len, int channels);
  100. extern void ff_conv_flt_to_s16p_2ch_sse2(int16_t *const *dst, float *src,
  101. int len, int channels);
  102. extern void ff_conv_flt_to_s16p_2ch_avx (int16_t *const *dst, float *src,
  103. int len, int channels);
  104. av_cold void ff_audio_convert_init_x86(AudioConvert *ac)
  105. {
  106. #if HAVE_YASM
  107. int mm_flags = av_get_cpu_flags();
  108. if (mm_flags & AV_CPU_FLAG_MMX && HAVE_MMX) {
  109. ff_audio_convert_set_func(ac, AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_S32,
  110. 0, 1, 8, "MMX", ff_conv_s32_to_s16_mmx);
  111. ff_audio_convert_set_func(ac, AV_SAMPLE_FMT_FLT, AV_SAMPLE_FMT_FLTP,
  112. 6, 1, 4, "MMX", ff_conv_fltp_to_flt_6ch_mmx);
  113. }
  114. if (mm_flags & AV_CPU_FLAG_SSE && HAVE_SSE) {
  115. ff_audio_convert_set_func(ac, AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_FLTP,
  116. 6, 1, 2, "SSE", ff_conv_fltp_to_s16_6ch_sse);
  117. ff_audio_convert_set_func(ac, AV_SAMPLE_FMT_FLT, AV_SAMPLE_FMT_FLTP,
  118. 2, 16, 8, "SSE", ff_conv_fltp_to_flt_2ch_sse);
  119. }
  120. if (mm_flags & AV_CPU_FLAG_SSE2 && HAVE_SSE) {
  121. if (!(mm_flags & AV_CPU_FLAG_SSE2SLOW)) {
  122. ff_audio_convert_set_func(ac, AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_S32,
  123. 0, 16, 16, "SSE2", ff_conv_s32_to_s16_sse2);
  124. ff_audio_convert_set_func(ac, AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_S16P,
  125. 6, 16, 8, "SSE2", ff_conv_s16p_to_s16_6ch_sse2);
  126. ff_audio_convert_set_func(ac, AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_FLTP,
  127. 6, 16, 4, "SSE2", ff_conv_fltp_to_s16_6ch_sse2);
  128. } else {
  129. ff_audio_convert_set_func(ac, AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_S16P,
  130. 6, 1, 4, "SSE2SLOW", ff_conv_s16p_to_s16_6ch_sse2slow);
  131. }
  132. ff_audio_convert_set_func(ac, AV_SAMPLE_FMT_S32, AV_SAMPLE_FMT_S16,
  133. 0, 16, 8, "SSE2", ff_conv_s16_to_s32_sse2);
  134. ff_audio_convert_set_func(ac, AV_SAMPLE_FMT_FLT, AV_SAMPLE_FMT_S16,
  135. 0, 16, 8, "SSE2", ff_conv_s16_to_flt_sse2);
  136. ff_audio_convert_set_func(ac, AV_SAMPLE_FMT_FLT, AV_SAMPLE_FMT_S32,
  137. 0, 16, 8, "SSE2", ff_conv_s32_to_flt_sse2);
  138. ff_audio_convert_set_func(ac, AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_FLT,
  139. 0, 16, 16, "SSE2", ff_conv_flt_to_s16_sse2);
  140. ff_audio_convert_set_func(ac, AV_SAMPLE_FMT_S32, AV_SAMPLE_FMT_FLT,
  141. 0, 16, 16, "SSE2", ff_conv_flt_to_s32_sse2);
  142. ff_audio_convert_set_func(ac, AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_S16P,
  143. 2, 16, 16, "SSE2", ff_conv_s16p_to_s16_2ch_sse2);
  144. ff_audio_convert_set_func(ac, AV_SAMPLE_FMT_FLT, AV_SAMPLE_FMT_S16P,
  145. 2, 16, 8, "SSE2", ff_conv_s16p_to_flt_2ch_sse2);
  146. ff_audio_convert_set_func(ac, AV_SAMPLE_FMT_FLT, AV_SAMPLE_FMT_S16P,
  147. 6, 16, 4, "SSE2", ff_conv_s16p_to_flt_6ch_sse2);
  148. ff_audio_convert_set_func(ac, AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_FLTP,
  149. 2, 16, 4, "SSE2", ff_conv_fltp_to_s16_2ch_sse2);
  150. ff_audio_convert_set_func(ac, AV_SAMPLE_FMT_S16P, AV_SAMPLE_FMT_S16,
  151. 2, 16, 8, "SSE2", ff_conv_s16_to_s16p_2ch_sse2);
  152. ff_audio_convert_set_func(ac, AV_SAMPLE_FMT_S16P, AV_SAMPLE_FMT_S16,
  153. 6, 16, 4, "SSE2", ff_conv_s16_to_s16p_6ch_sse2);
  154. ff_audio_convert_set_func(ac, AV_SAMPLE_FMT_FLTP, AV_SAMPLE_FMT_S16,
  155. 2, 16, 8, "SSE2", ff_conv_s16_to_fltp_2ch_sse2);
  156. ff_audio_convert_set_func(ac, AV_SAMPLE_FMT_FLTP, AV_SAMPLE_FMT_S16,
  157. 6, 16, 4, "SSE2", ff_conv_s16_to_fltp_6ch_sse2);
  158. ff_audio_convert_set_func(ac, AV_SAMPLE_FMT_S16P, AV_SAMPLE_FMT_FLT,
  159. 2, 16, 8, "SSE2", ff_conv_flt_to_s16p_2ch_sse2);
  160. }
  161. if (mm_flags & AV_CPU_FLAG_SSSE3 && HAVE_SSE) {
  162. ff_audio_convert_set_func(ac, AV_SAMPLE_FMT_FLT, AV_SAMPLE_FMT_S16P,
  163. 6, 16, 4, "SSSE3", ff_conv_s16p_to_flt_6ch_ssse3);
  164. ff_audio_convert_set_func(ac, AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_FLTP,
  165. 2, 16, 4, "SSSE3", ff_conv_fltp_to_s16_2ch_ssse3);
  166. ff_audio_convert_set_func(ac, AV_SAMPLE_FMT_S16P, AV_SAMPLE_FMT_S16,
  167. 2, 16, 8, "SSSE3", ff_conv_s16_to_s16p_2ch_ssse3);
  168. ff_audio_convert_set_func(ac, AV_SAMPLE_FMT_S16P, AV_SAMPLE_FMT_S16,
  169. 6, 16, 4, "SSSE3", ff_conv_s16_to_s16p_6ch_ssse3);
  170. ff_audio_convert_set_func(ac, AV_SAMPLE_FMT_FLTP, AV_SAMPLE_FMT_S16,
  171. 6, 16, 4, "SSSE3", ff_conv_s16_to_fltp_6ch_ssse3);
  172. }
  173. if (mm_flags & AV_CPU_FLAG_SSE4 && HAVE_SSE) {
  174. ff_audio_convert_set_func(ac, AV_SAMPLE_FMT_FLT, AV_SAMPLE_FMT_S16,
  175. 0, 16, 8, "SSE4", ff_conv_s16_to_flt_sse4);
  176. ff_audio_convert_set_func(ac, AV_SAMPLE_FMT_FLT, AV_SAMPLE_FMT_FLTP,
  177. 6, 16, 4, "SSE4", ff_conv_fltp_to_flt_6ch_sse4);
  178. }
  179. if (mm_flags & AV_CPU_FLAG_AVX && HAVE_AVX) {
  180. ff_audio_convert_set_func(ac, AV_SAMPLE_FMT_FLT, AV_SAMPLE_FMT_S32,
  181. 0, 32, 16, "AVX", ff_conv_s32_to_flt_avx);
  182. ff_audio_convert_set_func(ac, AV_SAMPLE_FMT_S32, AV_SAMPLE_FMT_FLT,
  183. 0, 32, 32, "AVX", ff_conv_flt_to_s32_avx);
  184. ff_audio_convert_set_func(ac, AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_S16P,
  185. 2, 16, 16, "AVX", ff_conv_s16p_to_s16_2ch_avx);
  186. ff_audio_convert_set_func(ac, AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_S16P,
  187. 6, 16, 8, "AVX", ff_conv_s16p_to_s16_6ch_avx);
  188. ff_audio_convert_set_func(ac, AV_SAMPLE_FMT_FLT, AV_SAMPLE_FMT_S16P,
  189. 2, 16, 8, "AVX", ff_conv_s16p_to_flt_2ch_avx);
  190. ff_audio_convert_set_func(ac, AV_SAMPLE_FMT_FLT, AV_SAMPLE_FMT_S16P,
  191. 6, 16, 4, "AVX", ff_conv_s16p_to_flt_6ch_avx);
  192. ff_audio_convert_set_func(ac, AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_FLTP,
  193. 6, 16, 4, "AVX", ff_conv_fltp_to_s16_6ch_avx);
  194. ff_audio_convert_set_func(ac, AV_SAMPLE_FMT_FLT, AV_SAMPLE_FMT_FLTP,
  195. 6, 16, 4, "AVX", ff_conv_fltp_to_flt_6ch_avx);
  196. ff_audio_convert_set_func(ac, AV_SAMPLE_FMT_S16P, AV_SAMPLE_FMT_S16,
  197. 2, 16, 8, "AVX", ff_conv_s16_to_s16p_2ch_avx);
  198. ff_audio_convert_set_func(ac, AV_SAMPLE_FMT_S16P, AV_SAMPLE_FMT_S16,
  199. 6, 16, 4, "AVX", ff_conv_s16_to_s16p_6ch_avx);
  200. ff_audio_convert_set_func(ac, AV_SAMPLE_FMT_FLTP, AV_SAMPLE_FMT_S16,
  201. 2, 16, 8, "AVX", ff_conv_s16_to_fltp_2ch_avx);
  202. ff_audio_convert_set_func(ac, AV_SAMPLE_FMT_FLTP, AV_SAMPLE_FMT_S16,
  203. 6, 16, 4, "AVX", ff_conv_s16_to_fltp_6ch_avx);
  204. ff_audio_convert_set_func(ac, AV_SAMPLE_FMT_S16P, AV_SAMPLE_FMT_FLT,
  205. 2, 16, 8, "AVX", ff_conv_flt_to_s16p_2ch_avx);
  206. }
  207. #endif
  208. }