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.

129 lines
4.3KB

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