float_dsp_init.c 6.3 KB

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