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.

103 lines
2.9KB

  1. /*
  2. * FFT/MDCT transform with SSE optimizations
  3. * Copyright (c) 2008 Loren Merritt
  4. *
  5. * This file is part of FFmpeg.
  6. *
  7. * FFmpeg 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. * FFmpeg 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 FFmpeg; 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_ALIGNED(16, static const int, 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_calc_sse(FFTContext *s, FFTComplex *z)
  29. {
  30. int n = 1 << s->nbits;
  31. ff_fft_dispatch_interleave_sse(z, s->nbits);
  32. if(n <= 16) {
  33. x86_reg i = -8*n;
  34. __asm__ volatile(
  35. "1: \n"
  36. "movaps (%0,%1), %%xmm0 \n"
  37. "movaps %%xmm0, %%xmm1 \n"
  38. "unpcklps 16(%0,%1), %%xmm0 \n"
  39. "unpckhps 16(%0,%1), %%xmm1 \n"
  40. "movaps %%xmm0, (%0,%1) \n"
  41. "movaps %%xmm1, 16(%0,%1) \n"
  42. "add $32, %0 \n"
  43. "jl 1b \n"
  44. :"+r"(i)
  45. :"r"(z+n)
  46. :"memory"
  47. );
  48. }
  49. }
  50. void ff_fft_permute_sse(FFTContext *s, FFTComplex *z)
  51. {
  52. int n = 1 << s->nbits;
  53. int i;
  54. for(i=0; i<n; i+=2) {
  55. __asm__ volatile(
  56. "movaps %2, %%xmm0 \n"
  57. "movlps %%xmm0, %0 \n"
  58. "movhps %%xmm0, %1 \n"
  59. :"=m"(s->tmp_buf[s->revtab[i]]),
  60. "=m"(s->tmp_buf[s->revtab[i+1]])
  61. :"m"(z[i])
  62. );
  63. }
  64. memcpy(z, s->tmp_buf, n*sizeof(FFTComplex));
  65. }
  66. void ff_imdct_calc_sse(FFTContext *s, FFTSample *output, const FFTSample *input)
  67. {
  68. x86_reg j, k;
  69. long n = s->mdct_size;
  70. long n4 = n >> 2;
  71. ff_imdct_half_sse(s, output+n4, input);
  72. j = -n;
  73. k = n-16;
  74. __asm__ volatile(
  75. "movaps %4, %%xmm7 \n"
  76. "1: \n"
  77. "movaps (%2,%1), %%xmm0 \n"
  78. "movaps (%3,%0), %%xmm1 \n"
  79. "shufps $0x1b, %%xmm0, %%xmm0 \n"
  80. "shufps $0x1b, %%xmm1, %%xmm1 \n"
  81. "xorps %%xmm7, %%xmm0 \n"
  82. "movaps %%xmm1, (%3,%1) \n"
  83. "movaps %%xmm0, (%2,%0) \n"
  84. "sub $16, %1 \n"
  85. "add $16, %0 \n"
  86. "jl 1b \n"
  87. :"+r"(j), "+r"(k)
  88. :"r"(output+n4), "r"(output+n4*3),
  89. "m"(*m1m1m1m1)
  90. );
  91. }