kiss_fft_mipsr1.h 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. /*Copyright (c) 2013, Xiph.Org Foundation and contributors.
  2. All rights reserved.
  3. Redistribution and use in source and binary forms, with or without
  4. modification, are permitted provided that the following conditions are met:
  5. * Redistributions of source code must retain the above copyright notice,
  6. this list of conditions and the following disclaimer.
  7. * Redistributions in binary form must reproduce the above copyright notice,
  8. this list of conditions and the following disclaimer in the
  9. documentation and/or other materials provided with the distribution.
  10. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  11. AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  12. IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  13. ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
  14. LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  15. CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  16. SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  17. INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  18. CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  19. ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  20. POSSIBILITY OF SUCH DAMAGE.*/
  21. #ifndef KISS_FFT_MIPSR1_H
  22. #define KISS_FFT_MIPSR1_H
  23. #if !defined(KISS_FFT_GUTS_H)
  24. #error "This file should only be included from _kiss_fft_guts.h"
  25. #endif
  26. #ifdef FIXED_POINT
  27. #define S_MUL_ADD(a, b, c, d) (S_MUL(a,b)+S_MUL(c,d))
  28. #define S_MUL_SUB(a, b, c, d) (S_MUL(a,b)-S_MUL(c,d))
  29. #undef S_MUL_ADD
  30. static inline int S_MUL_ADD(int a, int b, int c, int d) {
  31. int m;
  32. asm volatile("MULT $ac1, %0, %1" : : "r" ((int)a), "r" ((int)b));
  33. asm volatile("madd $ac1, %0, %1" : : "r" ((int)c), "r" ((int)d));
  34. asm volatile("EXTR.W %0,$ac1, %1" : "=r" (m): "i" (15));
  35. return m;
  36. }
  37. #undef S_MUL_SUB
  38. static inline int S_MUL_SUB(int a, int b, int c, int d) {
  39. int m;
  40. asm volatile("MULT $ac1, %0, %1" : : "r" ((int)a), "r" ((int)b));
  41. asm volatile("msub $ac1, %0, %1" : : "r" ((int)c), "r" ((int)d));
  42. asm volatile("EXTR.W %0,$ac1, %1" : "=r" (m): "i" (15));
  43. return m;
  44. }
  45. #undef C_MUL
  46. # define C_MUL(m,a,b) (m=C_MUL_fun(a,b))
  47. static inline kiss_fft_cpx C_MUL_fun(kiss_fft_cpx a, kiss_twiddle_cpx b) {
  48. kiss_fft_cpx m;
  49. asm volatile("MULT $ac1, %0, %1" : : "r" ((int)a.r), "r" ((int)b.r));
  50. asm volatile("msub $ac1, %0, %1" : : "r" ((int)a.i), "r" ((int)b.i));
  51. asm volatile("EXTR.W %0,$ac1, %1" : "=r" (m.r): "i" (15));
  52. asm volatile("MULT $ac1, %0, %1" : : "r" ((int)a.r), "r" ((int)b.i));
  53. asm volatile("madd $ac1, %0, %1" : : "r" ((int)a.i), "r" ((int)b.r));
  54. asm volatile("EXTR.W %0,$ac1, %1" : "=r" (m.i): "i" (15));
  55. return m;
  56. }
  57. #undef C_MULC
  58. # define C_MULC(m,a,b) (m=C_MULC_fun(a,b))
  59. static inline kiss_fft_cpx C_MULC_fun(kiss_fft_cpx a, kiss_twiddle_cpx b) {
  60. kiss_fft_cpx m;
  61. asm volatile("MULT $ac1, %0, %1" : : "r" ((int)a.r), "r" ((int)b.r));
  62. asm volatile("madd $ac1, %0, %1" : : "r" ((int)a.i), "r" ((int)b.i));
  63. asm volatile("EXTR.W %0,$ac1, %1" : "=r" (m.r): "i" (15));
  64. asm volatile("MULT $ac1, %0, %1" : : "r" ((int)a.i), "r" ((int)b.r));
  65. asm volatile("msub $ac1, %0, %1" : : "r" ((int)a.r), "r" ((int)b.i));
  66. asm volatile("EXTR.W %0,$ac1, %1" : "=r" (m.i): "i" (15));
  67. return m;
  68. }
  69. #endif /* FIXED_POINT */
  70. #define OVERRIDE_kf_bfly5
  71. static void kf_bfly5(
  72. kiss_fft_cpx * Fout,
  73. const size_t fstride,
  74. const kiss_fft_state *st,
  75. int m,
  76. int N,
  77. int mm
  78. )
  79. {
  80. kiss_fft_cpx *Fout0,*Fout1,*Fout2,*Fout3,*Fout4;
  81. int i, u;
  82. kiss_fft_cpx scratch[13];
  83. const kiss_twiddle_cpx *tw;
  84. kiss_twiddle_cpx ya,yb;
  85. kiss_fft_cpx * Fout_beg = Fout;
  86. #ifdef FIXED_POINT
  87. ya.r = 10126;
  88. ya.i = -31164;
  89. yb.r = -26510;
  90. yb.i = -19261;
  91. #else
  92. ya = st->twiddles[fstride*m];
  93. yb = st->twiddles[fstride*2*m];
  94. #endif
  95. tw=st->twiddles;
  96. for (i=0;i<N;i++)
  97. {
  98. Fout = Fout_beg + i*mm;
  99. Fout0=Fout;
  100. Fout1=Fout0+m;
  101. Fout2=Fout0+2*m;
  102. Fout3=Fout0+3*m;
  103. Fout4=Fout0+4*m;
  104. /* For non-custom modes, m is guaranteed to be a multiple of 4. */
  105. for ( u=0; u<m; ++u ) {
  106. scratch[0] = *Fout0;
  107. C_MUL(scratch[1] ,*Fout1, tw[u*fstride]);
  108. C_MUL(scratch[2] ,*Fout2, tw[2*u*fstride]);
  109. C_MUL(scratch[3] ,*Fout3, tw[3*u*fstride]);
  110. C_MUL(scratch[4] ,*Fout4, tw[4*u*fstride]);
  111. C_ADD( scratch[7],scratch[1],scratch[4]);
  112. C_SUB( scratch[10],scratch[1],scratch[4]);
  113. C_ADD( scratch[8],scratch[2],scratch[3]);
  114. C_SUB( scratch[9],scratch[2],scratch[3]);
  115. Fout0->r += scratch[7].r + scratch[8].r;
  116. Fout0->i += scratch[7].i + scratch[8].i;
  117. scratch[5].r = scratch[0].r + S_MUL_ADD(scratch[7].r,ya.r,scratch[8].r,yb.r);
  118. scratch[5].i = scratch[0].i + S_MUL_ADD(scratch[7].i,ya.r,scratch[8].i,yb.r);
  119. scratch[6].r = S_MUL_ADD(scratch[10].i,ya.i,scratch[9].i,yb.i);
  120. scratch[6].i = -S_MUL_ADD(scratch[10].r,ya.i,scratch[9].r,yb.i);
  121. C_SUB(*Fout1,scratch[5],scratch[6]);
  122. C_ADD(*Fout4,scratch[5],scratch[6]);
  123. scratch[11].r = scratch[0].r + S_MUL_ADD(scratch[7].r,yb.r,scratch[8].r,ya.r);
  124. scratch[11].i = scratch[0].i + S_MUL_ADD(scratch[7].i,yb.r,scratch[8].i,ya.r);
  125. scratch[12].r = S_MUL_SUB(scratch[9].i,ya.i,scratch[10].i,yb.i);
  126. scratch[12].i = S_MUL_SUB(scratch[10].r,yb.i,scratch[9].r,ya.i);
  127. C_ADD(*Fout2,scratch[11],scratch[12]);
  128. C_SUB(*Fout3,scratch[11],scratch[12]);
  129. ++Fout0;++Fout1;++Fout2;++Fout3;++Fout4;
  130. }
  131. }
  132. }
  133. #endif /* KISS_FFT_MIPSR1_H */