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.

211 lines
6.9KB

  1. /*
  2. * FFT/MDCT transform with Extended 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 "../dsputil.h"
  23. static const int p1m1[2] __attribute__((aligned(8))) =
  24. { 0, 1 << 31 };
  25. static const int m1p1[2] __attribute__((aligned(8))) =
  26. { 1 << 31, 0 };
  27. void ff_fft_calc_3dn2(FFTContext *s, FFTComplex *z)
  28. {
  29. int ln = s->nbits;
  30. long i, j;
  31. long nblocks, nloops;
  32. FFTComplex *p, *cptr;
  33. asm volatile(
  34. /* FEMMS is not a must here but recommended by AMD */
  35. "femms \n\t"
  36. "movq %0, %%mm7 \n\t"
  37. ::"m"(*(s->inverse ? m1p1 : p1m1))
  38. );
  39. i = 8 << ln;
  40. asm volatile(
  41. "1: \n\t"
  42. "sub $32, %0 \n\t"
  43. "movq (%0,%1), %%mm0 \n\t"
  44. "movq 16(%0,%1), %%mm1 \n\t"
  45. "movq 8(%0,%1), %%mm2 \n\t"
  46. "movq 24(%0,%1), %%mm3 \n\t"
  47. "movq %%mm0, %%mm4 \n\t"
  48. "movq %%mm1, %%mm5 \n\t"
  49. "pfadd %%mm2, %%mm0 \n\t"
  50. "pfadd %%mm3, %%mm1 \n\t"
  51. "pfsub %%mm2, %%mm4 \n\t"
  52. "pfsub %%mm3, %%mm5 \n\t"
  53. "movq %%mm0, %%mm2 \n\t"
  54. "pswapd %%mm5, %%mm5 \n\t"
  55. "movq %%mm4, %%mm3 \n\t"
  56. "pxor %%mm7, %%mm5 \n\t"
  57. "pfadd %%mm1, %%mm0 \n\t"
  58. "pfadd %%mm5, %%mm4 \n\t"
  59. "pfsub %%mm1, %%mm2 \n\t"
  60. "pfsub %%mm5, %%mm3 \n\t"
  61. "movq %%mm0, (%0,%1) \n\t"
  62. "movq %%mm4, 8(%0,%1) \n\t"
  63. "movq %%mm2, 16(%0,%1) \n\t"
  64. "movq %%mm3, 24(%0,%1) \n\t"
  65. "jg 1b \n\t"
  66. :"+r"(i)
  67. :"r"(z)
  68. );
  69. /* pass 2 .. ln-1 */
  70. nblocks = 1 << (ln-3);
  71. nloops = 1 << 2;
  72. cptr = s->exptab1;
  73. do {
  74. p = z;
  75. j = nblocks;
  76. do {
  77. i = nloops*8;
  78. asm volatile(
  79. "1: \n\t"
  80. "sub $16, %0 \n\t"
  81. "movq (%1,%0), %%mm0 \n\t"
  82. "movq 8(%1,%0), %%mm1 \n\t"
  83. "movq (%2,%0), %%mm2 \n\t"
  84. "movq 8(%2,%0), %%mm3 \n\t"
  85. "movq (%3,%0,2), %%mm4 \n\t"
  86. "movq 8(%3,%0,2), %%mm5 \n\t"
  87. "pswapd %%mm4, %%mm6 \n\t" // no need for cptr[2] & cptr[3]
  88. "pswapd %%mm5, %%mm7 \n\t"
  89. "pfmul %%mm2, %%mm4 \n\t" // cre*re cim*im
  90. "pfmul %%mm3, %%mm5 \n\t"
  91. "pfmul %%mm2, %%mm6 \n\t" // cim*re cre*im
  92. "pfmul %%mm3, %%mm7 \n\t"
  93. "pfpnacc %%mm6, %%mm4 \n\t" // cre*re-cim*im cim*re+cre*im
  94. "pfpnacc %%mm7, %%mm5 \n\t"
  95. "movq %%mm0, %%mm2 \n\t"
  96. "movq %%mm1, %%mm3 \n\t"
  97. "pfadd %%mm4, %%mm0 \n\t"
  98. "pfadd %%mm5, %%mm1 \n\t"
  99. "pfsub %%mm4, %%mm2 \n\t"
  100. "pfsub %%mm5, %%mm3 \n\t"
  101. "movq %%mm0, (%1,%0) \n\t"
  102. "movq %%mm1, 8(%1,%0) \n\t"
  103. "movq %%mm2, (%2,%0) \n\t"
  104. "movq %%mm3, 8(%2,%0) \n\t"
  105. "jg 1b \n\t"
  106. :"+r"(i)
  107. :"r"(p), "r"(p + nloops), "r"(cptr)
  108. );
  109. p += nloops*2;
  110. } while (--j);
  111. cptr += nloops*2;
  112. nblocks >>= 1;
  113. nloops <<= 1;
  114. } while (nblocks != 0);
  115. asm volatile("femms");
  116. }
  117. void ff_imdct_calc_3dn2(MDCTContext *s, FFTSample *output,
  118. const FFTSample *input, FFTSample *tmp)
  119. {
  120. long k, n8, n4, n2, n;
  121. const uint16_t *revtab = s->fft.revtab;
  122. const FFTSample *tcos = s->tcos;
  123. const FFTSample *tsin = s->tsin;
  124. const FFTSample *in1, *in2;
  125. FFTComplex *z = (FFTComplex *)tmp;
  126. n = 1 << s->nbits;
  127. n2 = n >> 1;
  128. n4 = n >> 2;
  129. n8 = n >> 3;
  130. /* pre rotation */
  131. in1 = input;
  132. in2 = input + n2 - 1;
  133. for(k = 0; k < n4; k++) {
  134. // FIXME a single block is faster, but gcc 2.95 and 3.4.x on 32bit can't compile it
  135. asm volatile(
  136. "movd %0, %%mm0 \n\t"
  137. "movd %2, %%mm1 \n\t"
  138. "punpckldq %1, %%mm0 \n\t"
  139. "punpckldq %3, %%mm1 \n\t"
  140. "movq %%mm0, %%mm2 \n\t"
  141. "pfmul %%mm1, %%mm0 \n\t"
  142. "pswapd %%mm1, %%mm1 \n\t"
  143. "pfmul %%mm1, %%mm2 \n\t"
  144. "pfpnacc %%mm2, %%mm0 \n\t"
  145. ::"m"(in2[-2*k]), "m"(in1[2*k]),
  146. "m"(tcos[k]), "m"(tsin[k])
  147. );
  148. asm volatile(
  149. "movq %%mm0, %0 \n\t"
  150. :"=m"(z[revtab[k]])
  151. );
  152. }
  153. ff_fft_calc(&s->fft, z);
  154. /* post rotation + reordering */
  155. for(k = 0; k < n4; k++) {
  156. asm volatile(
  157. "movq %0, %%mm0 \n\t"
  158. "movd %1, %%mm1 \n\t"
  159. "punpckldq %2, %%mm1 \n\t"
  160. "movq %%mm0, %%mm2 \n\t"
  161. "pfmul %%mm1, %%mm0 \n\t"
  162. "pswapd %%mm1, %%mm1 \n\t"
  163. "pfmul %%mm1, %%mm2 \n\t"
  164. "pfpnacc %%mm2, %%mm0 \n\t"
  165. "movq %%mm0, %0 \n\t"
  166. :"+m"(z[k])
  167. :"m"(tcos[k]), "m"(tsin[k])
  168. );
  169. }
  170. k = n-8;
  171. asm volatile("movd %0, %%mm7" ::"r"(1<<31));
  172. asm volatile(
  173. "1: \n\t"
  174. "movq (%4,%0), %%mm0 \n\t" // z[n8+k]
  175. "neg %0 \n\t"
  176. "pswapd -8(%4,%0), %%mm1 \n\t" // z[n8-1-k]
  177. "movq %%mm0, %%mm2 \n\t"
  178. "pxor %%mm7, %%mm2 \n\t"
  179. "punpckldq %%mm1, %%mm2 \n\t"
  180. "pswapd %%mm2, %%mm3 \n\t"
  181. "punpckhdq %%mm1, %%mm0 \n\t"
  182. "pswapd %%mm0, %%mm4 \n\t"
  183. "pxor %%mm7, %%mm0 \n\t"
  184. "pxor %%mm7, %%mm4 \n\t"
  185. "movq %%mm3, -8(%3,%0) \n\t" // output[n-2-2*k] = { z[n8-1-k].im, -z[n8+k].re }
  186. "movq %%mm4, -8(%2,%0) \n\t" // output[n2-2-2*k]= { -z[n8-1-k].re, z[n8+k].im }
  187. "neg %0 \n\t"
  188. "movq %%mm0, (%1,%0) \n\t" // output[2*k] = { -z[n8+k].im, z[n8-1-k].re }
  189. "movq %%mm2, (%2,%0) \n\t" // output[n2+2*k] = { -z[n8+k].re, z[n8-1-k].im }
  190. "sub $8, %0 \n\t"
  191. "jge 1b \n\t"
  192. :"+r"(k)
  193. :"r"(output), "r"(output+n2), "r"(output+n), "r"(z+n8)
  194. :"memory"
  195. );
  196. asm volatile("femms");
  197. }