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.

150 lines
6.1KB

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