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.

124 lines
4.2KB

  1. /*
  2. * FFT/MDCT transform with 3DNow! optimizations
  3. * Copyright (c) 2006 Zuxy MENG Jie, Loren Merritt
  4. * Based on fft_sse.c copyright (c) 2002 Fabrice Bellard.
  5. *
  6. * This library is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU Lesser General Public
  8. * License as published by the Free Software Foundation; either
  9. * version 2 of the License, or (at your option) any later version.
  10. *
  11. * This library is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. * Lesser General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU Lesser General Public
  17. * License along with this library; if not, write to the Free Software
  18. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  19. */
  20. #include "../dsputil.h"
  21. static const int p1m1[2] __attribute__((aligned(8))) =
  22. { 0, 1 << 31 };
  23. static const int m1p1[2] __attribute__((aligned(8))) =
  24. { 1 << 31, 0 };
  25. void ff_fft_calc_3dn(FFTContext *s, FFTComplex *z)
  26. {
  27. int ln = s->nbits;
  28. long i, j;
  29. long nblocks, nloops;
  30. FFTComplex *p, *cptr;
  31. asm volatile(
  32. /* FEMMS is not a must here but recommended by AMD */
  33. "femms \n\t"
  34. "movq %0, %%mm7 \n\t"
  35. ::"m"(*(s->inverse ? m1p1 : p1m1))
  36. );
  37. i = 8 << ln;
  38. asm volatile(
  39. "1: \n\t"
  40. "sub $32, %0 \n\t"
  41. "movq (%0,%1), %%mm0 \n\t"
  42. "movq 16(%0,%1), %%mm1 \n\t"
  43. "movq 8(%0,%1), %%mm2 \n\t"
  44. "movq 24(%0,%1), %%mm3 \n\t"
  45. "movq %%mm0, %%mm4 \n\t"
  46. "movq %%mm1, %%mm5 \n\t"
  47. "pfadd %%mm2, %%mm0 \n\t"
  48. "pfadd %%mm3, %%mm1 \n\t"
  49. "pfsub %%mm2, %%mm4 \n\t"
  50. "pfsub %%mm3, %%mm5 \n\t"
  51. "movq %%mm0, %%mm2 \n\t"
  52. "punpckldq %%mm5, %%mm6 \n\t"
  53. "punpckhdq %%mm6, %%mm5 \n\t"
  54. "movq %%mm4, %%mm3 \n\t"
  55. "pxor %%mm7, %%mm5 \n\t"
  56. "pfadd %%mm1, %%mm0 \n\t"
  57. "pfadd %%mm5, %%mm4 \n\t"
  58. "pfsub %%mm1, %%mm2 \n\t"
  59. "pfsub %%mm5, %%mm3 \n\t"
  60. "movq %%mm0, (%0,%1) \n\t"
  61. "movq %%mm4, 8(%0,%1) \n\t"
  62. "movq %%mm2, 16(%0,%1) \n\t"
  63. "movq %%mm3, 24(%0,%1) \n\t"
  64. "jg 1b \n\t"
  65. :"+r"(i)
  66. :"r"(z)
  67. );
  68. /* pass 2 .. ln-1 */
  69. nblocks = 1 << (ln-3);
  70. nloops = 1 << 2;
  71. cptr = s->exptab1;
  72. do {
  73. p = z;
  74. j = nblocks;
  75. do {
  76. i = nloops*8;
  77. asm volatile(
  78. "1: \n\t"
  79. "sub $16, %0 \n\t"
  80. "movq (%1,%0), %%mm0 \n\t"
  81. "movq 8(%1,%0), %%mm1 \n\t"
  82. "movq (%2,%0), %%mm2 \n\t"
  83. "movq 8(%2,%0), %%mm3 \n\t"
  84. "movq %%mm2, %%mm4 \n\t"
  85. "movq %%mm3, %%mm5 \n\t"
  86. "punpckldq %%mm2, %%mm2 \n\t"
  87. "punpckldq %%mm3, %%mm3 \n\t"
  88. "punpckhdq %%mm4, %%mm4 \n\t"
  89. "punpckhdq %%mm5, %%mm5 \n\t"
  90. "pfmul (%3,%0,2), %%mm2 \n\t" // cre*re cim*re
  91. "pfmul 8(%3,%0,2), %%mm3 \n\t"
  92. "pfmul 16(%3,%0,2), %%mm4 \n\t" // -cim*im cre*im
  93. "pfmul 24(%3,%0,2), %%mm5 \n\t"
  94. "pfadd %%mm2, %%mm4 \n\t" // cre*re-cim*im cim*re+cre*im
  95. "pfadd %%mm3, %%mm5 \n\t"
  96. "movq %%mm0, %%mm2 \n\t"
  97. "movq %%mm1, %%mm3 \n\t"
  98. "pfadd %%mm4, %%mm0 \n\t"
  99. "pfadd %%mm5, %%mm1 \n\t"
  100. "pfsub %%mm4, %%mm2 \n\t"
  101. "pfsub %%mm5, %%mm3 \n\t"
  102. "movq %%mm0, (%1,%0) \n\t"
  103. "movq %%mm1, 8(%1,%0) \n\t"
  104. "movq %%mm2, (%2,%0) \n\t"
  105. "movq %%mm3, 8(%2,%0) \n\t"
  106. "jg 1b \n\t"
  107. :"+r"(i)
  108. :"r"(p), "r"(p + nloops), "r"(cptr)
  109. );
  110. p += nloops*2;
  111. } while (--j);
  112. cptr += nloops*2;
  113. nblocks >>= 1;
  114. nloops <<= 1;
  115. } while (nblocks != 0);
  116. asm volatile("femms");
  117. }