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.

167 lines
4.5KB

  1. /*
  2. * FFT/IFFT transforms
  3. * AltiVec-enabled
  4. * Copyright (c) 2003 Romain Dolbeau <romain@dolbeau.org>
  5. * Based on code Copyright (c) 2002 Fabrice Bellard.
  6. *
  7. * This file is part of FFmpeg.
  8. *
  9. * FFmpeg is free software; you can redistribute it and/or
  10. * modify it under the terms of the GNU Lesser General Public
  11. * License as published by the Free Software Foundation; either
  12. * version 2.1 of the License, or (at your option) any later version.
  13. *
  14. * FFmpeg is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  17. * Lesser General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU Lesser General Public
  20. * License along with FFmpeg; if not, write to the Free Software
  21. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  22. */
  23. #include "dsputil.h"
  24. #include "gcc_fixes.h"
  25. #include "dsputil_ppc.h"
  26. #include "util_altivec.h"
  27. /*
  28. those three macros are from libavcodec/fft.c
  29. and are required for the reference C code
  30. */
  31. /* butter fly op */
  32. #define BF(pre, pim, qre, qim, pre1, pim1, qre1, qim1) \
  33. {\
  34. FFTSample ax, ay, bx, by;\
  35. bx=pre1;\
  36. by=pim1;\
  37. ax=qre1;\
  38. ay=qim1;\
  39. pre = (bx + ax);\
  40. pim = (by + ay);\
  41. qre = (bx - ax);\
  42. qim = (by - ay);\
  43. }
  44. #define MUL16(a,b) ((a) * (b))
  45. #define CMUL(pre, pim, are, aim, bre, bim) \
  46. {\
  47. pre = (MUL16(are, bre) - MUL16(aim, bim));\
  48. pim = (MUL16(are, bim) + MUL16(bre, aim));\
  49. }
  50. /**
  51. * Do a complex FFT with the parameters defined in ff_fft_init(). The
  52. * input data must be permuted before with s->revtab table. No
  53. * 1.0/sqrt(n) normalization is done.
  54. * AltiVec-enabled
  55. * This code assumes that the 'z' pointer is 16 bytes-aligned
  56. * It also assumes all FFTComplex are 8 bytes-aligned pair of float
  57. * The code is exactly the same as the SSE version, except
  58. * that successive MUL + ADD/SUB have been merged into
  59. * fused multiply-add ('vec_madd' in altivec)
  60. */
  61. void ff_fft_calc_altivec(FFTContext *s, FFTComplex *z)
  62. {
  63. POWERPC_PERF_DECLARE(altivec_fft_num, s->nbits >= 6);
  64. register const vector float vczero = (const vector float)vec_splat_u32(0.);
  65. int ln = s->nbits;
  66. int j, np, np2;
  67. int nblocks, nloops;
  68. register FFTComplex *p, *q;
  69. FFTComplex *cptr, *cptr1;
  70. int k;
  71. POWERPC_PERF_START_COUNT(altivec_fft_num, s->nbits >= 6);
  72. np = 1 << ln;
  73. {
  74. vector float *r, a, b, a1, c1, c2;
  75. r = (vector float *)&z[0];
  76. c1 = vcii(p,p,n,n);
  77. if (s->inverse)
  78. {
  79. c2 = vcii(p,p,n,p);
  80. }
  81. else
  82. {
  83. c2 = vcii(p,p,p,n);
  84. }
  85. j = (np >> 2);
  86. do {
  87. a = vec_ld(0, r);
  88. a1 = vec_ld(sizeof(vector float), r);
  89. b = vec_perm(a,a,vcprmle(1,0,3,2));
  90. a = vec_madd(a,c1,b);
  91. /* do the pass 0 butterfly */
  92. b = vec_perm(a1,a1,vcprmle(1,0,3,2));
  93. b = vec_madd(a1,c1,b);
  94. /* do the pass 0 butterfly */
  95. /* multiply third by -i */
  96. b = vec_perm(b,b,vcprmle(2,3,1,0));
  97. /* do the pass 1 butterfly */
  98. vec_st(vec_madd(b,c2,a), 0, r);
  99. vec_st(vec_nmsub(b,c2,a), sizeof(vector float), r);
  100. r += 2;
  101. } while (--j != 0);
  102. }
  103. /* pass 2 .. ln-1 */
  104. nblocks = np >> 3;
  105. nloops = 1 << 2;
  106. np2 = np >> 1;
  107. cptr1 = s->exptab1;
  108. do {
  109. p = z;
  110. q = z + nloops;
  111. j = nblocks;
  112. do {
  113. cptr = cptr1;
  114. k = nloops >> 1;
  115. do {
  116. vector float a,b,c,t1;
  117. a = vec_ld(0, (float*)p);
  118. b = vec_ld(0, (float*)q);
  119. /* complex mul */
  120. c = vec_ld(0, (float*)cptr);
  121. /* cre*re cim*re */
  122. t1 = vec_madd(c, vec_perm(b,b,vcprmle(2,2,0,0)),vczero);
  123. c = vec_ld(sizeof(vector float), (float*)cptr);
  124. /* -cim*im cre*im */
  125. b = vec_madd(c, vec_perm(b,b,vcprmle(3,3,1,1)),t1);
  126. /* butterfly */
  127. vec_st(vec_add(a,b), 0, (float*)p);
  128. vec_st(vec_sub(a,b), 0, (float*)q);
  129. p += 2;
  130. q += 2;
  131. cptr += 4;
  132. } while (--k);
  133. p += nloops;
  134. q += nloops;
  135. } while (--j);
  136. cptr1 += nloops * 2;
  137. nblocks = nblocks >> 1;
  138. nloops = nloops << 1;
  139. } while (nblocks != 0);
  140. POWERPC_PERF_STOP_COUNT(altivec_fft_num, s->nbits >= 6);
  141. }