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.

138 lines
3.9KB

  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/fft.h"
  24. #include "util_altivec.h"
  25. #include "dsputil_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. static void ff_fft_calc_altivec(FFTContext *s, FFTComplex *z)
  38. {
  39. register const vector float vczero = (const vector float)vec_splat_u32(0.);
  40. int ln = s->nbits;
  41. int j, np, np2;
  42. int nblocks, nloops;
  43. register FFTComplex *p, *q;
  44. FFTComplex *cptr, *cptr1;
  45. int k;
  46. np = 1 << ln;
  47. {
  48. vector float *r, a, b, a1, c1, c2;
  49. r = (vector float *)&z[0];
  50. c1 = vcii(p,p,n,n);
  51. if (s->inverse) {
  52. c2 = vcii(p,p,n,p);
  53. } else {
  54. c2 = vcii(p,p,p,n);
  55. }
  56. j = (np >> 2);
  57. do {
  58. a = vec_ld(0, r);
  59. a1 = vec_ld(sizeof(vector float), r);
  60. b = vec_perm(a,a,vcprmle(1,0,3,2));
  61. a = vec_madd(a,c1,b);
  62. /* do the pass 0 butterfly */
  63. b = vec_perm(a1,a1,vcprmle(1,0,3,2));
  64. b = vec_madd(a1,c1,b);
  65. /* do the pass 0 butterfly */
  66. /* multiply third by -i */
  67. b = vec_perm(b,b,vcprmle(2,3,1,0));
  68. /* do the pass 1 butterfly */
  69. vec_st(vec_madd(b,c2,a), 0, r);
  70. vec_st(vec_nmsub(b,c2,a), sizeof(vector float), r);
  71. r += 2;
  72. } while (--j != 0);
  73. }
  74. /* pass 2 .. ln-1 */
  75. nblocks = np >> 3;
  76. nloops = 1 << 2;
  77. np2 = np >> 1;
  78. cptr1 = s->exptab1;
  79. do {
  80. p = z;
  81. q = z + nloops;
  82. j = nblocks;
  83. do {
  84. cptr = cptr1;
  85. k = nloops >> 1;
  86. do {
  87. vector float a,b,c,t1;
  88. a = vec_ld(0, (float*)p);
  89. b = vec_ld(0, (float*)q);
  90. /* complex mul */
  91. c = vec_ld(0, (float*)cptr);
  92. /* cre*re cim*re */
  93. t1 = vec_madd(c, vec_perm(b,b,vcprmle(2,2,0,0)),vczero);
  94. c = vec_ld(sizeof(vector float), (float*)cptr);
  95. /* -cim*im cre*im */
  96. b = vec_madd(c, vec_perm(b,b,vcprmle(3,3,1,1)),t1);
  97. /* butterfly */
  98. vec_st(vec_add(a,b), 0, (float*)p);
  99. vec_st(vec_sub(a,b), 0, (float*)q);
  100. p += 2;
  101. q += 2;
  102. cptr += 4;
  103. } while (--k);
  104. p += nloops;
  105. q += nloops;
  106. } while (--j);
  107. cptr1 += nloops * 2;
  108. nblocks = nblocks >> 1;
  109. nloops = nloops << 1;
  110. } while (nblocks != 0);
  111. }
  112. av_cold void ff_fft_init_altivec(FFTContext *s)
  113. {
  114. s->fft_calc = ff_fft_calc_altivec;
  115. s->split_radix = 0;
  116. }