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.

156 lines
6.3KB

  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/cpu.h"
  20. #include "libavutil/float_dsp.h"
  21. #include "cpu.h"
  22. #include "asm.h"
  23. void ff_vector_fmul_sse(float *dst, const float *src0, const float *src1,
  24. int len);
  25. void ff_vector_fmul_avx(float *dst, const float *src0, const float *src1,
  26. int len);
  27. void ff_vector_fmac_scalar_sse(float *dst, const float *src, float mul,
  28. int len);
  29. void ff_vector_fmac_scalar_avx(float *dst, const float *src, float mul,
  30. int len);
  31. void ff_vector_fmul_scalar_sse(float *dst, const float *src, float mul,
  32. int len);
  33. void ff_vector_dmul_scalar_sse2(double *dst, const double *src,
  34. double mul, int len);
  35. void ff_vector_dmul_scalar_avx(double *dst, const double *src,
  36. double mul, int len);
  37. void ff_vector_fmul_add_sse(float *dst, const float *src0, const float *src1,
  38. const float *src2, int len);
  39. void ff_vector_fmul_add_avx(float *dst, const float *src0, const float *src1,
  40. const float *src2, int len);
  41. void ff_vector_fmul_reverse_sse(float *dst, const float *src0,
  42. const float *src1, int len);
  43. void ff_vector_fmul_reverse_avx(float *dst, const float *src0,
  44. const float *src1, int len);
  45. float ff_scalarproduct_float_sse(const float *v1, const float *v2, int order);
  46. void ff_butterflies_float_sse(float *src0, float *src1, int len);
  47. #if HAVE_6REGS && HAVE_INLINE_ASM
  48. static void vector_fmul_window_3dnowext(float *dst, const float *src0,
  49. const float *src1, const float *win,
  50. int len)
  51. {
  52. x86_reg i = -len * 4;
  53. x86_reg j = len * 4 - 8;
  54. __asm__ volatile (
  55. "1: \n"
  56. "pswapd (%5, %1), %%mm1 \n"
  57. "movq (%5, %0), %%mm0 \n"
  58. "pswapd (%4, %1), %%mm5 \n"
  59. "movq (%3, %0), %%mm4 \n"
  60. "movq %%mm0, %%mm2 \n"
  61. "movq %%mm1, %%mm3 \n"
  62. "pfmul %%mm4, %%mm2 \n" // src0[len + i] * win[len + i]
  63. "pfmul %%mm5, %%mm3 \n" // src1[j] * win[len + j]
  64. "pfmul %%mm4, %%mm1 \n" // src0[len + i] * win[len + j]
  65. "pfmul %%mm5, %%mm0 \n" // src1[j] * win[len + i]
  66. "pfadd %%mm3, %%mm2 \n"
  67. "pfsub %%mm0, %%mm1 \n"
  68. "pswapd %%mm2, %%mm2 \n"
  69. "movq %%mm1, (%2, %0) \n"
  70. "movq %%mm2, (%2, %1) \n"
  71. "sub $8, %1 \n"
  72. "add $8, %0 \n"
  73. "jl 1b \n"
  74. "femms \n"
  75. : "+r"(i), "+r"(j)
  76. : "r"(dst + len), "r"(src0 + len), "r"(src1), "r"(win + len)
  77. );
  78. }
  79. static void vector_fmul_window_sse(float *dst, const float *src0,
  80. const float *src1, const float *win, int len)
  81. {
  82. x86_reg i = -len * 4;
  83. x86_reg j = len * 4 - 16;
  84. __asm__ volatile (
  85. "1: \n"
  86. "movaps (%5, %1), %%xmm1 \n"
  87. "movaps (%5, %0), %%xmm0 \n"
  88. "movaps (%4, %1), %%xmm5 \n"
  89. "movaps (%3, %0), %%xmm4 \n"
  90. "shufps $0x1b, %%xmm1, %%xmm1 \n"
  91. "shufps $0x1b, %%xmm5, %%xmm5 \n"
  92. "movaps %%xmm0, %%xmm2 \n"
  93. "movaps %%xmm1, %%xmm3 \n"
  94. "mulps %%xmm4, %%xmm2 \n" // src0[len + i] * win[len + i]
  95. "mulps %%xmm5, %%xmm3 \n" // src1[j] * win[len + j]
  96. "mulps %%xmm4, %%xmm1 \n" // src0[len + i] * win[len + j]
  97. "mulps %%xmm5, %%xmm0 \n" // src1[j] * win[len + i]
  98. "addps %%xmm3, %%xmm2 \n"
  99. "subps %%xmm0, %%xmm1 \n"
  100. "shufps $0x1b, %%xmm2, %%xmm2 \n"
  101. "movaps %%xmm1, (%2, %0) \n"
  102. "movaps %%xmm2, (%2, %1) \n"
  103. "sub $16, %1 \n"
  104. "add $16, %0 \n"
  105. "jl 1b \n"
  106. : "+r"(i), "+r"(j)
  107. : "r"(dst + len), "r"(src0 + len), "r"(src1), "r"(win + len)
  108. );
  109. }
  110. #endif /* HAVE_6REGS && HAVE_INLINE_ASM */
  111. void ff_float_dsp_init_x86(AVFloatDSPContext *fdsp)
  112. {
  113. int mm_flags = av_get_cpu_flags();
  114. #if HAVE_6REGS && HAVE_INLINE_ASM
  115. if (INLINE_AMD3DNOWEXT(mm_flags)) {
  116. fdsp->vector_fmul_window = vector_fmul_window_3dnowext;
  117. }
  118. if (INLINE_SSE(mm_flags)) {
  119. fdsp->vector_fmul_window = vector_fmul_window_sse;
  120. }
  121. #endif
  122. if (EXTERNAL_SSE(mm_flags)) {
  123. fdsp->vector_fmul = ff_vector_fmul_sse;
  124. fdsp->vector_fmac_scalar = ff_vector_fmac_scalar_sse;
  125. fdsp->vector_fmul_scalar = ff_vector_fmul_scalar_sse;
  126. fdsp->vector_fmul_add = ff_vector_fmul_add_sse;
  127. fdsp->vector_fmul_reverse = ff_vector_fmul_reverse_sse;
  128. fdsp->scalarproduct_float = ff_scalarproduct_float_sse;
  129. fdsp->butterflies_float = ff_butterflies_float_sse;
  130. }
  131. if (EXTERNAL_SSE2(mm_flags)) {
  132. fdsp->vector_dmul_scalar = ff_vector_dmul_scalar_sse2;
  133. }
  134. if (EXTERNAL_AVX(mm_flags)) {
  135. fdsp->vector_fmul = ff_vector_fmul_avx;
  136. fdsp->vector_fmac_scalar = ff_vector_fmac_scalar_avx;
  137. fdsp->vector_dmul_scalar = ff_vector_dmul_scalar_avx;
  138. fdsp->vector_fmul_add = ff_vector_fmul_add_avx;
  139. fdsp->vector_fmul_reverse = ff_vector_fmul_reverse_avx;
  140. }
  141. }