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.

171 lines
4.6KB

  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_altivec.h"
  26. /*
  27. those three macros are from libavcodec/fft.c
  28. and are required for the reference C code
  29. */
  30. /* butter fly op */
  31. #define BF(pre, pim, qre, qim, pre1, pim1, qre1, qim1) \
  32. {\
  33. FFTSample ax, ay, bx, by;\
  34. bx=pre1;\
  35. by=pim1;\
  36. ax=qre1;\
  37. ay=qim1;\
  38. pre = (bx + ax);\
  39. pim = (by + ay);\
  40. qre = (bx - ax);\
  41. qim = (by - ay);\
  42. }
  43. #define MUL16(a,b) ((a) * (b))
  44. #define CMUL(pre, pim, are, aim, bre, bim) \
  45. {\
  46. pre = (MUL16(are, bre) - MUL16(aim, bim));\
  47. pim = (MUL16(are, bim) + MUL16(bre, aim));\
  48. }
  49. /**
  50. * Do a complex FFT with the parameters defined in ff_fft_init(). The
  51. * input data must be permuted before with s->revtab table. No
  52. * 1.0/sqrt(n) normalization is done.
  53. * AltiVec-enabled
  54. * This code assumes that the 'z' pointer is 16 bytes-aligned
  55. * It also assumes all FFTComplex are 8 bytes-aligned pair of float
  56. * The code is exactly the same as the SSE version, except
  57. * that successive MUL + ADD/SUB have been merged into
  58. * fused multiply-add ('vec_madd' in altivec)
  59. */
  60. void ff_fft_calc_altivec(FFTContext *s, FFTComplex *z)
  61. {
  62. POWERPC_PERF_DECLARE(altivec_fft_num, s->nbits >= 6);
  63. #ifdef CONFIG_DARWIN
  64. register const vector float vczero = (const vector float)(0.);
  65. #else
  66. register const vector float vczero = (const vector float){0.,0.,0.,0.};
  67. #endif
  68. int ln = s->nbits;
  69. int j, np, np2;
  70. int nblocks, nloops;
  71. register FFTComplex *p, *q;
  72. FFTComplex *cptr, *cptr1;
  73. int k;
  74. POWERPC_PERF_START_COUNT(altivec_fft_num, s->nbits >= 6);
  75. np = 1 << ln;
  76. {
  77. vector float *r, a, b, a1, c1, c2;
  78. r = (vector float *)&z[0];
  79. c1 = vcii(p,p,n,n);
  80. if (s->inverse)
  81. {
  82. c2 = vcii(p,p,n,p);
  83. }
  84. else
  85. {
  86. c2 = vcii(p,p,p,n);
  87. }
  88. j = (np >> 2);
  89. do {
  90. a = vec_ld(0, r);
  91. a1 = vec_ld(sizeof(vector float), r);
  92. b = vec_perm(a,a,vcprmle(1,0,3,2));
  93. a = vec_madd(a,c1,b);
  94. /* do the pass 0 butterfly */
  95. b = vec_perm(a1,a1,vcprmle(1,0,3,2));
  96. b = vec_madd(a1,c1,b);
  97. /* do the pass 0 butterfly */
  98. /* multiply third by -i */
  99. b = vec_perm(b,b,vcprmle(2,3,1,0));
  100. /* do the pass 1 butterfly */
  101. vec_st(vec_madd(b,c2,a), 0, r);
  102. vec_st(vec_nmsub(b,c2,a), sizeof(vector float), r);
  103. r += 2;
  104. } while (--j != 0);
  105. }
  106. /* pass 2 .. ln-1 */
  107. nblocks = np >> 3;
  108. nloops = 1 << 2;
  109. np2 = np >> 1;
  110. cptr1 = s->exptab1;
  111. do {
  112. p = z;
  113. q = z + nloops;
  114. j = nblocks;
  115. do {
  116. cptr = cptr1;
  117. k = nloops >> 1;
  118. do {
  119. vector float a,b,c,t1;
  120. a = vec_ld(0, (float*)p);
  121. b = vec_ld(0, (float*)q);
  122. /* complex mul */
  123. c = vec_ld(0, (float*)cptr);
  124. /* cre*re cim*re */
  125. t1 = vec_madd(c, vec_perm(b,b,vcprmle(2,2,0,0)),vczero);
  126. c = vec_ld(sizeof(vector float), (float*)cptr);
  127. /* -cim*im cre*im */
  128. b = vec_madd(c, vec_perm(b,b,vcprmle(3,3,1,1)),t1);
  129. /* butterfly */
  130. vec_st(vec_add(a,b), 0, (float*)p);
  131. vec_st(vec_sub(a,b), 0, (float*)q);
  132. p += 2;
  133. q += 2;
  134. cptr += 4;
  135. } while (--k);
  136. p += nloops;
  137. q += nloops;
  138. } while (--j);
  139. cptr1 += nloops * 2;
  140. nblocks = nblocks >> 1;
  141. nloops = nloops << 1;
  142. } while (nblocks != 0);
  143. POWERPC_PERF_STOP_COUNT(altivec_fft_num, s->nbits >= 6);
  144. }