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.

111 lines
3.1KB

  1. /*
  2. * FFT/MDCT transform with SSE optimizations
  3. * Copyright (c) 2008 Loren Merritt
  4. *
  5. * This file is part of Libav.
  6. *
  7. * Libav is free software; you can redistribute it and/or
  8. * modify it under the terms of the GNU Lesser General Public
  9. * License as published by the Free Software Foundation; either
  10. * version 2.1 of the License, or (at your option) any later version.
  11. *
  12. * Libav is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  15. * Lesser General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU Lesser General Public
  18. * License along with Libav; if not, write to the Free Software
  19. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  20. */
  21. #include "libavutil/x86_cpu.h"
  22. #include "libavcodec/dsputil.h"
  23. #include "fft.h"
  24. #include "config.h"
  25. DECLARE_ASM_CONST(16, unsigned int, ff_m1m1m1m1)[4] =
  26. { 1U << 31, 1U << 31, 1U << 31, 1U << 31 };
  27. void ff_fft_dispatch_sse(FFTComplex *z, int nbits);
  28. void ff_fft_dispatch_interleave_sse(FFTComplex *z, int nbits);
  29. void ff_fft_dispatch_interleave_avx(FFTComplex *z, int nbits);
  30. #if HAVE_AVX
  31. void ff_fft_calc_avx(FFTContext *s, FFTComplex *z)
  32. {
  33. ff_fft_dispatch_interleave_avx(z, s->nbits);
  34. }
  35. #endif
  36. void ff_fft_calc_sse(FFTContext *s, FFTComplex *z)
  37. {
  38. int n = 1 << s->nbits;
  39. ff_fft_dispatch_interleave_sse(z, s->nbits);
  40. if(n <= 16) {
  41. x86_reg i = -8*n;
  42. __asm__ volatile(
  43. "1: \n"
  44. "movaps (%0,%1), %%xmm0 \n"
  45. "movaps %%xmm0, %%xmm1 \n"
  46. "unpcklps 16(%0,%1), %%xmm0 \n"
  47. "unpckhps 16(%0,%1), %%xmm1 \n"
  48. "movaps %%xmm0, (%0,%1) \n"
  49. "movaps %%xmm1, 16(%0,%1) \n"
  50. "add $32, %0 \n"
  51. "jl 1b \n"
  52. :"+r"(i)
  53. :"r"(z+n)
  54. :"memory"
  55. );
  56. }
  57. }
  58. void ff_fft_permute_sse(FFTContext *s, FFTComplex *z)
  59. {
  60. int n = 1 << s->nbits;
  61. int i;
  62. for(i=0; i<n; i+=2) {
  63. __asm__ volatile(
  64. "movaps %2, %%xmm0 \n"
  65. "movlps %%xmm0, %0 \n"
  66. "movhps %%xmm0, %1 \n"
  67. :"=m"(s->tmp_buf[s->revtab[i]]),
  68. "=m"(s->tmp_buf[s->revtab[i+1]])
  69. :"m"(z[i])
  70. );
  71. }
  72. memcpy(z, s->tmp_buf, n*sizeof(FFTComplex));
  73. }
  74. void ff_imdct_calc_sse(FFTContext *s, FFTSample *output, const FFTSample *input)
  75. {
  76. x86_reg j, k;
  77. long n = s->mdct_size;
  78. long n4 = n >> 2;
  79. s->imdct_half(s, output + n4, input);
  80. j = -n;
  81. k = n-16;
  82. __asm__ volatile(
  83. "movaps "MANGLE(ff_m1m1m1m1)", %%xmm7 \n"
  84. "1: \n"
  85. "movaps (%2,%1), %%xmm0 \n"
  86. "movaps (%3,%0), %%xmm1 \n"
  87. "shufps $0x1b, %%xmm0, %%xmm0 \n"
  88. "shufps $0x1b, %%xmm1, %%xmm1 \n"
  89. "xorps %%xmm7, %%xmm0 \n"
  90. "movaps %%xmm1, (%3,%1) \n"
  91. "movaps %%xmm0, (%2,%0) \n"
  92. "sub $16, %1 \n"
  93. "add $16, %0 \n"
  94. "jl 1b \n"
  95. :"+r"(j), "+r"(k)
  96. :"r"(output+n4), "r"(output+n4*3)
  97. XMM_CLOBBERS_ONLY("%xmm0", "%xmm1", "%xmm7")
  98. );
  99. }