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.

136 lines
5.4KB

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