fft_altivec.c 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  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 "libavcodec/dsputil.h"
  24. #include "dsputil_ppc.h"
  25. #include "util_altivec.h"
  26. /**
  27. * Do a complex FFT with the parameters defined in ff_fft_init(). The
  28. * input data must be permuted before with s->revtab table. No
  29. * 1.0/sqrt(n) normalization is done.
  30. * AltiVec-enabled
  31. * This code assumes that the 'z' pointer is 16 bytes-aligned
  32. * It also assumes all FFTComplex are 8 bytes-aligned pair of float
  33. * The code is exactly the same as the SSE version, except
  34. * that successive MUL + ADD/SUB have been merged into
  35. * fused multiply-add ('vec_madd' in altivec)
  36. */
  37. void ff_fft_calc_altivec(FFTContext *s, FFTComplex *z)
  38. {
  39. POWERPC_PERF_DECLARE(altivec_fft_num, s->nbits >= 6);
  40. register const vector float vczero = (const vector float)vec_splat_u32(0.);
  41. int ln = s->nbits;
  42. int j, np, np2;
  43. int nblocks, nloops;
  44. register FFTComplex *p, *q;
  45. FFTComplex *cptr, *cptr1;
  46. int k;
  47. POWERPC_PERF_START_COUNT(altivec_fft_num, s->nbits >= 6);
  48. np = 1 << ln;
  49. {
  50. vector float *r, a, b, a1, c1, c2;
  51. r = (vector float *)&z[0];
  52. c1 = vcii(p,p,n,n);
  53. if (s->inverse) {
  54. c2 = vcii(p,p,n,p);
  55. } else {
  56. c2 = vcii(p,p,p,n);
  57. }
  58. j = (np >> 2);
  59. do {
  60. a = vec_ld(0, r);
  61. a1 = vec_ld(sizeof(vector float), r);
  62. b = vec_perm(a,a,vcprmle(1,0,3,2));
  63. a = vec_madd(a,c1,b);
  64. /* do the pass 0 butterfly */
  65. b = vec_perm(a1,a1,vcprmle(1,0,3,2));
  66. b = vec_madd(a1,c1,b);
  67. /* do the pass 0 butterfly */
  68. /* multiply third by -i */
  69. b = vec_perm(b,b,vcprmle(2,3,1,0));
  70. /* do the pass 1 butterfly */
  71. vec_st(vec_madd(b,c2,a), 0, r);
  72. vec_st(vec_nmsub(b,c2,a), sizeof(vector float), r);
  73. r += 2;
  74. } while (--j != 0);
  75. }
  76. /* pass 2 .. ln-1 */
  77. nblocks = np >> 3;
  78. nloops = 1 << 2;
  79. np2 = np >> 1;
  80. cptr1 = s->exptab1;
  81. do {
  82. p = z;
  83. q = z + nloops;
  84. j = nblocks;
  85. do {
  86. cptr = cptr1;
  87. k = nloops >> 1;
  88. do {
  89. vector float a,b,c,t1;
  90. a = vec_ld(0, (float*)p);
  91. b = vec_ld(0, (float*)q);
  92. /* complex mul */
  93. c = vec_ld(0, (float*)cptr);
  94. /* cre*re cim*re */
  95. t1 = vec_madd(c, vec_perm(b,b,vcprmle(2,2,0,0)),vczero);
  96. c = vec_ld(sizeof(vector float), (float*)cptr);
  97. /* -cim*im cre*im */
  98. b = vec_madd(c, vec_perm(b,b,vcprmle(3,3,1,1)),t1);
  99. /* butterfly */
  100. vec_st(vec_add(a,b), 0, (float*)p);
  101. vec_st(vec_sub(a,b), 0, (float*)q);
  102. p += 2;
  103. q += 2;
  104. cptr += 4;
  105. } while (--k);
  106. p += nloops;
  107. q += nloops;
  108. } while (--j);
  109. cptr1 += nloops * 2;
  110. nblocks = nblocks >> 1;
  111. nloops = nloops << 1;
  112. } while (nblocks != 0);
  113. POWERPC_PERF_STOP_COUNT(altivec_fft_num, s->nbits >= 6);
  114. }