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.

109 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. DECLARE_ASM_CONST(16, int, ff_m1m1m1m1)[4] =
  25. { 1 << 31, 1 << 31, 1 << 31, 1 << 31 };
  26. void ff_fft_dispatch_sse(FFTComplex *z, int nbits);
  27. void ff_fft_dispatch_interleave_sse(FFTComplex *z, int nbits);
  28. void ff_fft_dispatch_interleave_avx(FFTComplex *z, int nbits);
  29. void ff_fft_calc_avx(FFTContext *s, FFTComplex *z)
  30. {
  31. ff_fft_dispatch_interleave_avx(z, s->nbits);
  32. }
  33. void ff_fft_calc_sse(FFTContext *s, FFTComplex *z)
  34. {
  35. int n = 1 << s->nbits;
  36. ff_fft_dispatch_interleave_sse(z, s->nbits);
  37. if(n <= 16) {
  38. x86_reg i = -8*n;
  39. __asm__ volatile(
  40. "1: \n"
  41. "movaps (%0,%1), %%xmm0 \n"
  42. "movaps %%xmm0, %%xmm1 \n"
  43. "unpcklps 16(%0,%1), %%xmm0 \n"
  44. "unpckhps 16(%0,%1), %%xmm1 \n"
  45. "movaps %%xmm0, (%0,%1) \n"
  46. "movaps %%xmm1, 16(%0,%1) \n"
  47. "add $32, %0 \n"
  48. "jl 1b \n"
  49. :"+r"(i)
  50. :"r"(z+n)
  51. :"memory"
  52. );
  53. }
  54. }
  55. void ff_fft_permute_sse(FFTContext *s, FFTComplex *z)
  56. {
  57. int n = 1 << s->nbits;
  58. int i;
  59. for(i=0; i<n; i+=2) {
  60. __asm__ volatile(
  61. "movaps %2, %%xmm0 \n"
  62. "movlps %%xmm0, %0 \n"
  63. "movhps %%xmm0, %1 \n"
  64. :"=m"(s->tmp_buf[s->revtab[i]]),
  65. "=m"(s->tmp_buf[s->revtab[i+1]])
  66. :"m"(z[i])
  67. );
  68. }
  69. memcpy(z, s->tmp_buf, n*sizeof(FFTComplex));
  70. }
  71. void ff_imdct_calc_sse(FFTContext *s, FFTSample *output, const FFTSample *input)
  72. {
  73. x86_reg j, k;
  74. long n = s->mdct_size;
  75. long n4 = n >> 2;
  76. s->imdct_half(s, output + n4, input);
  77. j = -n;
  78. k = n-16;
  79. __asm__ volatile(
  80. "movaps "MANGLE(ff_m1m1m1m1)", %%xmm7 \n"
  81. "1: \n"
  82. "movaps (%2,%1), %%xmm0 \n"
  83. "movaps (%3,%0), %%xmm1 \n"
  84. "shufps $0x1b, %%xmm0, %%xmm0 \n"
  85. "shufps $0x1b, %%xmm1, %%xmm1 \n"
  86. "xorps %%xmm7, %%xmm0 \n"
  87. "movaps %%xmm1, (%3,%1) \n"
  88. "movaps %%xmm0, (%2,%0) \n"
  89. "sub $16, %1 \n"
  90. "add $16, %0 \n"
  91. "jl 1b \n"
  92. :"+r"(j), "+r"(k)
  93. :"r"(output+n4), "r"(output+n4*3)
  94. XMM_CLOBBERS_ONLY("%xmm0", "%xmm1", "%xmm7")
  95. );
  96. }