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.

165 lines
6.7KB

  1. /*
  2. * This file is part of FFmpeg.
  3. *
  4. * FFmpeg is free software; you can redistribute it and/or
  5. * modify it under the terms of the GNU Lesser General Public
  6. * License as published by the Free Software Foundation; either
  7. * version 2.1 of the License, or (at your option) any later version.
  8. *
  9. * FFmpeg is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12. * Lesser General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU Lesser General Public
  15. * License along with FFmpeg; if not, write to the Free Software
  16. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  17. */
  18. #include "config.h"
  19. #include "libavutil/attributes.h"
  20. #include "libavutil/cpu.h"
  21. #include "libavutil/float_dsp.h"
  22. #include "cpu.h"
  23. #include "asm.h"
  24. void ff_vector_fmul_sse(float *dst, const float *src0, const float *src1,
  25. int len);
  26. void ff_vector_fmul_avx(float *dst, const float *src0, const float *src1,
  27. int len);
  28. void ff_vector_fmac_scalar_sse(float *dst, const float *src, float mul,
  29. int len);
  30. void ff_vector_fmac_scalar_avx(float *dst, const float *src, float mul,
  31. int len);
  32. void ff_vector_fmac_scalar_fma3(float *dst, const float *src, float mul,
  33. int len);
  34. void ff_vector_fmul_scalar_sse(float *dst, const float *src, float mul,
  35. int len);
  36. void ff_vector_dmul_scalar_sse2(double *dst, const double *src,
  37. double mul, int len);
  38. void ff_vector_dmul_scalar_avx(double *dst, const double *src,
  39. double mul, int len);
  40. void ff_vector_fmul_add_sse(float *dst, const float *src0, const float *src1,
  41. const float *src2, int len);
  42. void ff_vector_fmul_add_avx(float *dst, const float *src0, const float *src1,
  43. const float *src2, int len);
  44. void ff_vector_fmul_add_fma3(float *dst, const float *src0, const float *src1,
  45. const float *src2, int len);
  46. void ff_vector_fmul_reverse_sse(float *dst, const float *src0,
  47. const float *src1, int len);
  48. void ff_vector_fmul_reverse_avx(float *dst, const float *src0,
  49. const float *src1, int len);
  50. float ff_scalarproduct_float_sse(const float *v1, const float *v2, int order);
  51. void ff_butterflies_float_sse(float *src0, float *src1, int len);
  52. #if HAVE_6REGS && HAVE_INLINE_ASM
  53. static void vector_fmul_window_3dnowext(float *dst, const float *src0,
  54. const float *src1, const float *win,
  55. int len)
  56. {
  57. x86_reg i = -len * 4;
  58. x86_reg j = len * 4 - 8;
  59. __asm__ volatile (
  60. "1: \n"
  61. "pswapd (%5, %1), %%mm1 \n"
  62. "movq (%5, %0), %%mm0 \n"
  63. "pswapd (%4, %1), %%mm5 \n"
  64. "movq (%3, %0), %%mm4 \n"
  65. "movq %%mm0, %%mm2 \n"
  66. "movq %%mm1, %%mm3 \n"
  67. "pfmul %%mm4, %%mm2 \n" // src0[len + i] * win[len + i]
  68. "pfmul %%mm5, %%mm3 \n" // src1[j] * win[len + j]
  69. "pfmul %%mm4, %%mm1 \n" // src0[len + i] * win[len + j]
  70. "pfmul %%mm5, %%mm0 \n" // src1[j] * win[len + i]
  71. "pfadd %%mm3, %%mm2 \n"
  72. "pfsub %%mm0, %%mm1 \n"
  73. "pswapd %%mm2, %%mm2 \n"
  74. "movq %%mm1, (%2, %0) \n"
  75. "movq %%mm2, (%2, %1) \n"
  76. "sub $8, %1 \n"
  77. "add $8, %0 \n"
  78. "jl 1b \n"
  79. "femms \n"
  80. : "+r"(i), "+r"(j)
  81. : "r"(dst + len), "r"(src0 + len), "r"(src1), "r"(win + len)
  82. );
  83. }
  84. static void vector_fmul_window_sse(float *dst, const float *src0,
  85. const float *src1, const float *win, int len)
  86. {
  87. x86_reg i = -len * 4;
  88. x86_reg j = len * 4 - 16;
  89. __asm__ volatile (
  90. "1: \n"
  91. "movaps (%5, %1), %%xmm1 \n"
  92. "movaps (%5, %0), %%xmm0 \n"
  93. "movaps (%4, %1), %%xmm5 \n"
  94. "movaps (%3, %0), %%xmm4 \n"
  95. "shufps $0x1b, %%xmm1, %%xmm1 \n"
  96. "shufps $0x1b, %%xmm5, %%xmm5 \n"
  97. "movaps %%xmm0, %%xmm2 \n"
  98. "movaps %%xmm1, %%xmm3 \n"
  99. "mulps %%xmm4, %%xmm2 \n" // src0[len + i] * win[len + i]
  100. "mulps %%xmm5, %%xmm3 \n" // src1[j] * win[len + j]
  101. "mulps %%xmm4, %%xmm1 \n" // src0[len + i] * win[len + j]
  102. "mulps %%xmm5, %%xmm0 \n" // src1[j] * win[len + i]
  103. "addps %%xmm3, %%xmm2 \n"
  104. "subps %%xmm0, %%xmm1 \n"
  105. "shufps $0x1b, %%xmm2, %%xmm2 \n"
  106. "movaps %%xmm1, (%2, %0) \n"
  107. "movaps %%xmm2, (%2, %1) \n"
  108. "sub $16, %1 \n"
  109. "add $16, %0 \n"
  110. "jl 1b \n"
  111. : "+r"(i), "+r"(j)
  112. : "r"(dst + len), "r"(src0 + len), "r"(src1), "r"(win + len)
  113. );
  114. }
  115. #endif /* HAVE_6REGS && HAVE_INLINE_ASM */
  116. av_cold void ff_float_dsp_init_x86(AVFloatDSPContext *fdsp)
  117. {
  118. int cpu_flags = av_get_cpu_flags();
  119. #if HAVE_6REGS && HAVE_INLINE_ASM
  120. if (INLINE_AMD3DNOWEXT(cpu_flags)) {
  121. fdsp->vector_fmul_window = vector_fmul_window_3dnowext;
  122. }
  123. if (INLINE_SSE(cpu_flags)) {
  124. fdsp->vector_fmul_window = vector_fmul_window_sse;
  125. }
  126. #endif
  127. if (EXTERNAL_SSE(cpu_flags)) {
  128. fdsp->vector_fmul = ff_vector_fmul_sse;
  129. fdsp->vector_fmac_scalar = ff_vector_fmac_scalar_sse;
  130. fdsp->vector_fmul_scalar = ff_vector_fmul_scalar_sse;
  131. fdsp->vector_fmul_add = ff_vector_fmul_add_sse;
  132. fdsp->vector_fmul_reverse = ff_vector_fmul_reverse_sse;
  133. fdsp->scalarproduct_float = ff_scalarproduct_float_sse;
  134. fdsp->butterflies_float = ff_butterflies_float_sse;
  135. }
  136. if (EXTERNAL_SSE2(cpu_flags)) {
  137. fdsp->vector_dmul_scalar = ff_vector_dmul_scalar_sse2;
  138. }
  139. if (EXTERNAL_AVX(cpu_flags)) {
  140. fdsp->vector_fmul = ff_vector_fmul_avx;
  141. fdsp->vector_fmac_scalar = ff_vector_fmac_scalar_avx;
  142. fdsp->vector_dmul_scalar = ff_vector_dmul_scalar_avx;
  143. fdsp->vector_fmul_add = ff_vector_fmul_add_avx;
  144. fdsp->vector_fmul_reverse = ff_vector_fmul_reverse_avx;
  145. }
  146. if (EXTERNAL_FMA3(cpu_flags)) {
  147. fdsp->vector_fmac_scalar = ff_vector_fmac_scalar_fma3;
  148. fdsp->vector_fmul_add = ff_vector_fmul_add_fma3;
  149. }
  150. }