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.

265 lines
16KB

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