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.

513 lines
26KB

  1. /*
  2. * Copyright (c) 2012
  3. * MIPS Technologies, Inc., California.
  4. *
  5. * Redistribution and use in source and binary forms, with or without
  6. * modification, are permitted provided that the following conditions
  7. * are met:
  8. * 1. Redistributions of source code must retain the above copyright
  9. * notice, this list of conditions and the following disclaimer.
  10. * 2. Redistributions in binary form must reproduce the above copyright
  11. * notice, this list of conditions and the following disclaimer in the
  12. * documentation and/or other materials provided with the distribution.
  13. * 3. Neither the name of the MIPS Technologies, Inc., nor the names of its
  14. * contributors may be used to endorse or promote products derived from
  15. * this software without specific prior written permission.
  16. *
  17. * THIS SOFTWARE IS PROVIDED BY THE MIPS TECHNOLOGIES, INC. ``AS IS'' AND
  18. * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  19. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  20. * ARE DISCLAIMED. IN NO EVENT SHALL THE MIPS TECHNOLOGIES, INC. BE LIABLE
  21. * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  22. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  23. * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  24. * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  25. * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  26. * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  27. * SUCH DAMAGE.
  28. *
  29. * Author: Stanislav Ocovaj (socovaj@mips.com)
  30. * Author: Zoran Lukic (zoranl@mips.com)
  31. *
  32. * Optimized MDCT/IMDCT and FFT transforms
  33. *
  34. * This file is part of FFmpeg.
  35. *
  36. * FFmpeg is free software; you can redistribute it and/or
  37. * modify it under the terms of the GNU Lesser General Public
  38. * License as published by the Free Software Foundation; either
  39. * version 2.1 of the License, or (at your option) any later version.
  40. *
  41. * FFmpeg is distributed in the hope that it will be useful,
  42. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  43. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  44. * Lesser General Public License for more details.
  45. *
  46. * You should have received a copy of the GNU Lesser General Public
  47. * License along with FFmpeg; if not, write to the Free Software
  48. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  49. */
  50. #include "config.h"
  51. #include "libavcodec/fft.h"
  52. #include "libavcodec/fft_table.h"
  53. /**
  54. * FFT transform
  55. */
  56. #if HAVE_INLINE_ASM
  57. static void ff_fft_calc_mips(FFTContext *s, FFTComplex *z)
  58. {
  59. int nbits, i, n, num_transforms, offset, step;
  60. int n4, n2, n34;
  61. FFTSample tmp1, tmp2, tmp3, tmp4, tmp5, tmp6, tmp7, tmp8;
  62. FFTComplex *tmpz;
  63. float w_re, w_im;
  64. float *w_re_ptr, *w_im_ptr;
  65. const int fft_size = (1 << s->nbits);
  66. float pom, pom1, pom2, pom3;
  67. float temp, temp1, temp3, temp4;
  68. FFTComplex * tmpz_n2, * tmpz_n34, * tmpz_n4;
  69. FFTComplex * tmpz_n2_i, * tmpz_n34_i, * tmpz_n4_i, * tmpz_i;
  70. num_transforms = (0x2aab >> (16 - s->nbits)) | 1;
  71. for (n=0; n<num_transforms; n++) {
  72. offset = ff_fft_offsets_lut[n] << 2;
  73. tmpz = z + offset;
  74. tmp1 = tmpz[0].re + tmpz[1].re;
  75. tmp5 = tmpz[2].re + tmpz[3].re;
  76. tmp2 = tmpz[0].im + tmpz[1].im;
  77. tmp6 = tmpz[2].im + tmpz[3].im;
  78. tmp3 = tmpz[0].re - tmpz[1].re;
  79. tmp8 = tmpz[2].im - tmpz[3].im;
  80. tmp4 = tmpz[0].im - tmpz[1].im;
  81. tmp7 = tmpz[2].re - tmpz[3].re;
  82. tmpz[0].re = tmp1 + tmp5;
  83. tmpz[2].re = tmp1 - tmp5;
  84. tmpz[0].im = tmp2 + tmp6;
  85. tmpz[2].im = tmp2 - tmp6;
  86. tmpz[1].re = tmp3 + tmp8;
  87. tmpz[3].re = tmp3 - tmp8;
  88. tmpz[1].im = tmp4 - tmp7;
  89. tmpz[3].im = tmp4 + tmp7;
  90. }
  91. if (fft_size < 8)
  92. return;
  93. num_transforms = (num_transforms >> 1) | 1;
  94. for (n=0; n<num_transforms; n++) {
  95. offset = ff_fft_offsets_lut[n] << 3;
  96. tmpz = z + offset;
  97. __asm__ volatile (
  98. "lwc1 %[tmp1], 32(%[tmpz]) \n\t"
  99. "lwc1 %[pom], 40(%[tmpz]) \n\t"
  100. "lwc1 %[tmp3], 48(%[tmpz]) \n\t"
  101. "lwc1 %[pom1], 56(%[tmpz]) \n\t"
  102. "lwc1 %[tmp2], 36(%[tmpz]) \n\t"
  103. "lwc1 %[pom2], 44(%[tmpz]) \n\t"
  104. "lwc1 %[pom3], 60(%[tmpz]) \n\t"
  105. "lwc1 %[tmp4], 52(%[tmpz]) \n\t"
  106. "add.s %[tmp1], %[tmp1], %[pom] \n\t" // tmp1 = tmpz[4].re + tmpz[5].re;
  107. "add.s %[tmp3], %[tmp3], %[pom1] \n\t" // tmp3 = tmpz[6].re + tmpz[7].re;
  108. "add.s %[tmp2], %[tmp2], %[pom2] \n\t" // tmp2 = tmpz[4].im + tmpz[5].im;
  109. "lwc1 %[pom], 40(%[tmpz]) \n\t"
  110. "add.s %[tmp4], %[tmp4], %[pom3] \n\t" // tmp4 = tmpz[6].im + tmpz[7].im;
  111. "add.s %[tmp5], %[tmp1], %[tmp3] \n\t" // tmp5 = tmp1 + tmp3;
  112. "sub.s %[tmp7], %[tmp1], %[tmp3] \n\t" // tmp7 = tmp1 - tmp3;
  113. "lwc1 %[tmp1], 32(%[tmpz]) \n\t"
  114. "lwc1 %[pom1], 44(%[tmpz]) \n\t"
  115. "add.s %[tmp6], %[tmp2], %[tmp4] \n\t" // tmp6 = tmp2 + tmp4;
  116. "sub.s %[tmp8], %[tmp2], %[tmp4] \n\t" // tmp8 = tmp2 - tmp4;
  117. "lwc1 %[tmp2], 36(%[tmpz]) \n\t"
  118. "lwc1 %[pom2], 56(%[tmpz]) \n\t"
  119. "lwc1 %[pom3], 60(%[tmpz]) \n\t"
  120. "lwc1 %[tmp3], 48(%[tmpz]) \n\t"
  121. "lwc1 %[tmp4], 52(%[tmpz]) \n\t"
  122. "sub.s %[tmp1], %[tmp1], %[pom] \n\t" // tmp1 = tmpz[4].re - tmpz[5].re;
  123. "lwc1 %[pom], 0(%[tmpz]) \n\t"
  124. "sub.s %[tmp2], %[tmp2], %[pom1] \n\t" // tmp2 = tmpz[4].im - tmpz[5].im;
  125. "sub.s %[tmp3], %[tmp3], %[pom2] \n\t" // tmp3 = tmpz[6].re - tmpz[7].re;
  126. "lwc1 %[pom2], 4(%[tmpz]) \n\t"
  127. "sub.s %[pom1], %[pom], %[tmp5] \n\t"
  128. "sub.s %[tmp4], %[tmp4], %[pom3] \n\t" // tmp4 = tmpz[6].im - tmpz[7].im;
  129. "add.s %[pom3], %[pom], %[tmp5] \n\t"
  130. "sub.s %[pom], %[pom2], %[tmp6] \n\t"
  131. "add.s %[pom2], %[pom2], %[tmp6] \n\t"
  132. "swc1 %[pom1], 32(%[tmpz]) \n\t" // tmpz[4].re = tmpz[0].re - tmp5;
  133. "swc1 %[pom3], 0(%[tmpz]) \n\t" // tmpz[0].re = tmpz[0].re + tmp5;
  134. "swc1 %[pom], 36(%[tmpz]) \n\t" // tmpz[4].im = tmpz[0].im - tmp6;
  135. "swc1 %[pom2], 4(%[tmpz]) \n\t" // tmpz[0].im = tmpz[0].im + tmp6;
  136. "lwc1 %[pom1], 16(%[tmpz]) \n\t"
  137. "lwc1 %[pom3], 20(%[tmpz]) \n\t"
  138. "li.s %[pom], 0.7071067812 \n\t" // float pom = 0.7071067812f;
  139. "add.s %[temp1],%[tmp1], %[tmp2] \n\t"
  140. "sub.s %[temp], %[pom1], %[tmp8] \n\t"
  141. "add.s %[pom2], %[pom3], %[tmp7] \n\t"
  142. "sub.s %[temp3],%[tmp3], %[tmp4] \n\t"
  143. "sub.s %[temp4],%[tmp2], %[tmp1] \n\t"
  144. "swc1 %[temp], 48(%[tmpz]) \n\t" // tmpz[6].re = tmpz[2].re - tmp8;
  145. "swc1 %[pom2], 52(%[tmpz]) \n\t" // tmpz[6].im = tmpz[2].im + tmp7;
  146. "add.s %[pom1], %[pom1], %[tmp8] \n\t"
  147. "sub.s %[pom3], %[pom3], %[tmp7] \n\t"
  148. "add.s %[tmp3], %[tmp3], %[tmp4] \n\t"
  149. "mul.s %[tmp5], %[pom], %[temp1] \n\t" // tmp5 = pom * (tmp1 + tmp2);
  150. "mul.s %[tmp7], %[pom], %[temp3] \n\t" // tmp7 = pom * (tmp3 - tmp4);
  151. "mul.s %[tmp6], %[pom], %[temp4] \n\t" // tmp6 = pom * (tmp2 - tmp1);
  152. "mul.s %[tmp8], %[pom], %[tmp3] \n\t" // tmp8 = pom * (tmp3 + tmp4);
  153. "swc1 %[pom1], 16(%[tmpz]) \n\t" // tmpz[2].re = tmpz[2].re + tmp8;
  154. "swc1 %[pom3], 20(%[tmpz]) \n\t" // tmpz[2].im = tmpz[2].im - tmp7;
  155. "add.s %[tmp1], %[tmp5], %[tmp7] \n\t" // tmp1 = tmp5 + tmp7;
  156. "sub.s %[tmp3], %[tmp5], %[tmp7] \n\t" // tmp3 = tmp5 - tmp7;
  157. "add.s %[tmp2], %[tmp6], %[tmp8] \n\t" // tmp2 = tmp6 + tmp8;
  158. "sub.s %[tmp4], %[tmp6], %[tmp8] \n\t" // tmp4 = tmp6 - tmp8;
  159. "lwc1 %[temp], 8(%[tmpz]) \n\t"
  160. "lwc1 %[temp1],12(%[tmpz]) \n\t"
  161. "lwc1 %[pom], 24(%[tmpz]) \n\t"
  162. "lwc1 %[pom2], 28(%[tmpz]) \n\t"
  163. "sub.s %[temp4],%[temp], %[tmp1] \n\t"
  164. "sub.s %[temp3],%[temp1], %[tmp2] \n\t"
  165. "add.s %[temp], %[temp], %[tmp1] \n\t"
  166. "add.s %[temp1],%[temp1], %[tmp2] \n\t"
  167. "sub.s %[pom1], %[pom], %[tmp4] \n\t"
  168. "add.s %[pom3], %[pom2], %[tmp3] \n\t"
  169. "add.s %[pom], %[pom], %[tmp4] \n\t"
  170. "sub.s %[pom2], %[pom2], %[tmp3] \n\t"
  171. "swc1 %[temp4],40(%[tmpz]) \n\t" // tmpz[5].re = tmpz[1].re - tmp1;
  172. "swc1 %[temp3],44(%[tmpz]) \n\t" // tmpz[5].im = tmpz[1].im - tmp2;
  173. "swc1 %[temp], 8(%[tmpz]) \n\t" // tmpz[1].re = tmpz[1].re + tmp1;
  174. "swc1 %[temp1],12(%[tmpz]) \n\t" // tmpz[1].im = tmpz[1].im + tmp2;
  175. "swc1 %[pom1], 56(%[tmpz]) \n\t" // tmpz[7].re = tmpz[3].re - tmp4;
  176. "swc1 %[pom3], 60(%[tmpz]) \n\t" // tmpz[7].im = tmpz[3].im + tmp3;
  177. "swc1 %[pom], 24(%[tmpz]) \n\t" // tmpz[3].re = tmpz[3].re + tmp4;
  178. "swc1 %[pom2], 28(%[tmpz]) \n\t" // tmpz[3].im = tmpz[3].im - tmp3;
  179. : [tmp1]"=&f"(tmp1), [pom]"=&f"(pom), [pom1]"=&f"(pom1), [pom2]"=&f"(pom2),
  180. [tmp3]"=&f"(tmp3), [tmp2]"=&f"(tmp2), [tmp4]"=&f"(tmp4), [tmp5]"=&f"(tmp5), [tmp7]"=&f"(tmp7),
  181. [tmp6]"=&f"(tmp6), [tmp8]"=&f"(tmp8), [pom3]"=&f"(pom3),[temp]"=&f"(temp), [temp1]"=&f"(temp1),
  182. [temp3]"=&f"(temp3), [temp4]"=&f"(temp4)
  183. : [tmpz]"r"(tmpz)
  184. : "memory"
  185. );
  186. }
  187. step = 1 << (MAX_LOG2_NFFT - 4);
  188. n4 = 4;
  189. for (nbits=4; nbits<=s->nbits; nbits++) {
  190. num_transforms = (num_transforms >> 1) | 1;
  191. n2 = 2 * n4;
  192. n34 = 3 * n4;
  193. for (n=0; n<num_transforms; n++) {
  194. offset = ff_fft_offsets_lut[n] << nbits;
  195. tmpz = z + offset;
  196. tmpz_n2 = tmpz + n2;
  197. tmpz_n4 = tmpz + n4;
  198. tmpz_n34 = tmpz + n34;
  199. __asm__ volatile (
  200. "lwc1 %[pom1], 0(%[tmpz_n2]) \n\t"
  201. "lwc1 %[pom], 0(%[tmpz_n34]) \n\t"
  202. "lwc1 %[pom2], 4(%[tmpz_n2]) \n\t"
  203. "lwc1 %[pom3], 4(%[tmpz_n34]) \n\t"
  204. "lwc1 %[temp1],0(%[tmpz]) \n\t"
  205. "lwc1 %[temp3],4(%[tmpz]) \n\t"
  206. "add.s %[tmp5], %[pom1], %[pom] \n\t" // tmp5 = tmpz[ n2].re + tmpz[n34].re;
  207. "sub.s %[tmp1], %[pom1], %[pom] \n\t" // tmp1 = tmpz[ n2].re - tmpz[n34].re;
  208. "add.s %[tmp6], %[pom2], %[pom3] \n\t" // tmp6 = tmpz[ n2].im + tmpz[n34].im;
  209. "sub.s %[tmp2], %[pom2], %[pom3] \n\t" // tmp2 = tmpz[ n2].im - tmpz[n34].im;
  210. "sub.s %[temp], %[temp1], %[tmp5] \n\t"
  211. "add.s %[temp1],%[temp1], %[tmp5] \n\t"
  212. "sub.s %[temp4],%[temp3], %[tmp6] \n\t"
  213. "add.s %[temp3],%[temp3], %[tmp6] \n\t"
  214. "swc1 %[temp], 0(%[tmpz_n2]) \n\t" // tmpz[ n2].re = tmpz[ 0].re - tmp5;
  215. "swc1 %[temp1],0(%[tmpz]) \n\t" // tmpz[ 0].re = tmpz[ 0].re + tmp5;
  216. "lwc1 %[pom1], 0(%[tmpz_n4]) \n\t"
  217. "swc1 %[temp4],4(%[tmpz_n2]) \n\t" // tmpz[ n2].im = tmpz[ 0].im - tmp6;
  218. "lwc1 %[temp], 4(%[tmpz_n4]) \n\t"
  219. "swc1 %[temp3],4(%[tmpz]) \n\t" // tmpz[ 0].im = tmpz[ 0].im + tmp6;
  220. "sub.s %[pom], %[pom1], %[tmp2] \n\t"
  221. "add.s %[pom1], %[pom1], %[tmp2] \n\t"
  222. "add.s %[temp1],%[temp], %[tmp1] \n\t"
  223. "sub.s %[temp], %[temp], %[tmp1] \n\t"
  224. "swc1 %[pom], 0(%[tmpz_n34]) \n\t" // tmpz[n34].re = tmpz[n4].re - tmp2;
  225. "swc1 %[pom1], 0(%[tmpz_n4]) \n\t" // tmpz[ n4].re = tmpz[n4].re + tmp2;
  226. "swc1 %[temp1],4(%[tmpz_n34]) \n\t" // tmpz[n34].im = tmpz[n4].im + tmp1;
  227. "swc1 %[temp], 4(%[tmpz_n4]) \n\t" // tmpz[ n4].im = tmpz[n4].im - tmp1;
  228. : [tmp5]"=&f"(tmp5),
  229. [tmp1]"=&f"(tmp1), [pom]"=&f"(pom), [pom1]"=&f"(pom1), [pom2]"=&f"(pom2),
  230. [tmp2]"=&f"(tmp2), [tmp6]"=&f"(tmp6), [pom3]"=&f"(pom3),
  231. [temp]"=&f"(temp), [temp1]"=&f"(temp1), [temp3]"=&f"(temp3), [temp4]"=&f"(temp4)
  232. : [tmpz]"r"(tmpz), [tmpz_n2]"r"(tmpz_n2), [tmpz_n34]"r"(tmpz_n34), [tmpz_n4]"r"(tmpz_n4)
  233. : "memory"
  234. );
  235. w_re_ptr = (float*)(ff_cos_65536 + step);
  236. w_im_ptr = (float*)(ff_cos_65536 + MAX_FFT_SIZE/4 - step);
  237. for (i=1; i<n4; i++) {
  238. w_re = w_re_ptr[0];
  239. w_im = w_im_ptr[0];
  240. tmpz_n2_i = tmpz_n2 + i;
  241. tmpz_n4_i = tmpz_n4 + i;
  242. tmpz_n34_i= tmpz_n34 + i;
  243. tmpz_i = tmpz + i;
  244. __asm__ volatile (
  245. "lwc1 %[temp], 0(%[tmpz_n2_i]) \n\t"
  246. "lwc1 %[temp1], 4(%[tmpz_n2_i]) \n\t"
  247. "lwc1 %[pom], 0(%[tmpz_n34_i]) \n\t"
  248. "lwc1 %[pom1], 4(%[tmpz_n34_i]) \n\t"
  249. "mul.s %[temp3], %[w_im], %[temp] \n\t"
  250. "mul.s %[temp4], %[w_im], %[temp1] \n\t"
  251. "mul.s %[pom2], %[w_im], %[pom1] \n\t"
  252. "mul.s %[pom3], %[w_im], %[pom] \n\t"
  253. "msub.s %[tmp2], %[temp3], %[w_re], %[temp1] \n\t" // tmp2 = w_re * tmpz[ n2+i].im - w_im * tmpz[ n2+i].re;
  254. "madd.s %[tmp1], %[temp4], %[w_re], %[temp] \n\t" // tmp1 = w_re * tmpz[ n2+i].re + w_im * tmpz[ n2+i].im;
  255. "msub.s %[tmp3], %[pom2], %[w_re], %[pom] \n\t" // tmp3 = w_re * tmpz[n34+i].re - w_im * tmpz[n34+i].im;
  256. "madd.s %[tmp4], %[pom3], %[w_re], %[pom1] \n\t" // tmp4 = w_re * tmpz[n34+i].im + w_im * tmpz[n34+i].re;
  257. "lwc1 %[temp], 0(%[tmpz_i]) \n\t"
  258. "lwc1 %[pom], 4(%[tmpz_i]) \n\t"
  259. "add.s %[tmp5], %[tmp1], %[tmp3] \n\t" // tmp5 = tmp1 + tmp3;
  260. "sub.s %[tmp1], %[tmp1], %[tmp3] \n\t" // tmp1 = tmp1 - tmp3;
  261. "add.s %[tmp6], %[tmp2], %[tmp4] \n\t" // tmp6 = tmp2 + tmp4;
  262. "sub.s %[tmp2], %[tmp2], %[tmp4] \n\t" // tmp2 = tmp2 - tmp4;
  263. "sub.s %[temp1], %[temp], %[tmp5] \n\t"
  264. "add.s %[temp], %[temp], %[tmp5] \n\t"
  265. "sub.s %[pom1], %[pom], %[tmp6] \n\t"
  266. "add.s %[pom], %[pom], %[tmp6] \n\t"
  267. "lwc1 %[temp3], 0(%[tmpz_n4_i]) \n\t"
  268. "lwc1 %[pom2], 4(%[tmpz_n4_i]) \n\t"
  269. "swc1 %[temp1], 0(%[tmpz_n2_i]) \n\t" // tmpz[ n2+i].re = tmpz[ i].re - tmp5;
  270. "swc1 %[temp], 0(%[tmpz_i]) \n\t" // tmpz[ i].re = tmpz[ i].re + tmp5;
  271. "swc1 %[pom1], 4(%[tmpz_n2_i]) \n\t" // tmpz[ n2+i].im = tmpz[ i].im - tmp6;
  272. "swc1 %[pom] , 4(%[tmpz_i]) \n\t" // tmpz[ i].im = tmpz[ i].im + tmp6;
  273. "sub.s %[temp4], %[temp3], %[tmp2] \n\t"
  274. "add.s %[pom3], %[pom2], %[tmp1] \n\t"
  275. "add.s %[temp3], %[temp3], %[tmp2] \n\t"
  276. "sub.s %[pom2], %[pom2], %[tmp1] \n\t"
  277. "swc1 %[temp4], 0(%[tmpz_n34_i]) \n\t" // tmpz[n34+i].re = tmpz[n4+i].re - tmp2;
  278. "swc1 %[pom3], 4(%[tmpz_n34_i]) \n\t" // tmpz[n34+i].im = tmpz[n4+i].im + tmp1;
  279. "swc1 %[temp3], 0(%[tmpz_n4_i]) \n\t" // tmpz[ n4+i].re = tmpz[n4+i].re + tmp2;
  280. "swc1 %[pom2], 4(%[tmpz_n4_i]) \n\t" // tmpz[ n4+i].im = tmpz[n4+i].im - tmp1;
  281. : [tmp1]"=&f"(tmp1), [tmp2]"=&f" (tmp2), [temp]"=&f"(temp), [tmp3]"=&f"(tmp3),
  282. [tmp4]"=&f"(tmp4), [tmp5]"=&f"(tmp5), [tmp6]"=&f"(tmp6),
  283. [temp1]"=&f"(temp1), [temp3]"=&f"(temp3), [temp4]"=&f"(temp4),
  284. [pom]"=&f"(pom), [pom1]"=&f"(pom1), [pom2]"=&f"(pom2), [pom3]"=&f"(pom3)
  285. : [w_re]"f"(w_re), [w_im]"f"(w_im),
  286. [tmpz_i]"r"(tmpz_i),[tmpz_n2_i]"r"(tmpz_n2_i),
  287. [tmpz_n34_i]"r"(tmpz_n34_i), [tmpz_n4_i]"r"(tmpz_n4_i)
  288. : "memory"
  289. );
  290. w_re_ptr += step;
  291. w_im_ptr -= step;
  292. }
  293. }
  294. step >>= 1;
  295. n4 <<= 1;
  296. }
  297. }
  298. /**
  299. * MDCT/IMDCT transforms.
  300. */
  301. static void ff_imdct_half_mips(FFTContext *s, FFTSample *output, const FFTSample *input)
  302. {
  303. int k, n8, n4, n2, n, j;
  304. const uint16_t *revtab = s->revtab;
  305. const FFTSample *tcos = s->tcos;
  306. const FFTSample *tsin = s->tsin;
  307. const FFTSample *in1, *in2, *in3, *in4;
  308. FFTComplex *z = (FFTComplex *)output;
  309. int j1;
  310. const float *tcos1, *tsin1, *tcos2, *tsin2;
  311. float temp1, temp2, temp3, temp4, temp5, temp6, temp7, temp8,
  312. temp9, temp10, temp11, temp12, temp13, temp14, temp15, temp16;
  313. FFTComplex *z1, *z2;
  314. n = 1 << s->mdct_bits;
  315. n2 = n >> 1;
  316. n4 = n >> 2;
  317. n8 = n >> 3;
  318. /* pre rotation */
  319. in1 = input;
  320. in2 = input + n2 - 1;
  321. in3 = input + 2;
  322. in4 = input + n2 - 3;
  323. tcos1 = tcos;
  324. tsin1 = tsin;
  325. /* n4 = 64 or 128 */
  326. for(k = 0; k < n4; k += 2) {
  327. j = revtab[k ];
  328. j1 = revtab[k + 1];
  329. __asm__ volatile (
  330. "lwc1 %[temp1], 0(%[in2]) \t\n"
  331. "lwc1 %[temp2], 0(%[tcos1]) \t\n"
  332. "lwc1 %[temp3], 0(%[tsin1]) \t\n"
  333. "lwc1 %[temp4], 0(%[in1]) \t\n"
  334. "lwc1 %[temp5], 0(%[in4]) \t\n"
  335. "mul.s %[temp9], %[temp1], %[temp2] \t\n"
  336. "mul.s %[temp10], %[temp1], %[temp3] \t\n"
  337. "lwc1 %[temp6], 4(%[tcos1]) \t\n"
  338. "lwc1 %[temp7], 4(%[tsin1]) \t\n"
  339. "nmsub.s %[temp9], %[temp9], %[temp4], %[temp3] \t\n"
  340. "madd.s %[temp10], %[temp10], %[temp4], %[temp2] \t\n"
  341. "mul.s %[temp11], %[temp5], %[temp6] \t\n"
  342. "mul.s %[temp12], %[temp5], %[temp7] \t\n"
  343. "lwc1 %[temp8], 0(%[in3]) \t\n"
  344. "addiu %[tcos1], %[tcos1], 8 \t\n"
  345. "addiu %[tsin1], %[tsin1], 8 \t\n"
  346. "addiu %[in1], %[in1], 16 \t\n"
  347. "nmsub.s %[temp11], %[temp11], %[temp8], %[temp7] \t\n"
  348. "madd.s %[temp12], %[temp12], %[temp8], %[temp6] \t\n"
  349. "addiu %[in2], %[in2], -16 \t\n"
  350. "addiu %[in3], %[in3], 16 \t\n"
  351. "addiu %[in4], %[in4], -16 \t\n"
  352. : [temp1]"=&f"(temp1), [temp2]"=&f"(temp2),
  353. [temp3]"=&f"(temp3), [temp4]"=&f"(temp4),
  354. [temp5]"=&f"(temp5), [temp6]"=&f"(temp6),
  355. [temp7]"=&f"(temp7), [temp8]"=&f"(temp8),
  356. [temp9]"=&f"(temp9), [temp10]"=&f"(temp10),
  357. [temp11]"=&f"(temp11), [temp12]"=&f"(temp12),
  358. [tsin1]"+r"(tsin1), [tcos1]"+r"(tcos1),
  359. [in1]"+r"(in1), [in2]"+r"(in2),
  360. [in3]"+r"(in3), [in4]"+r"(in4)
  361. :
  362. : "memory"
  363. );
  364. z[j ].re = temp9;
  365. z[j ].im = temp10;
  366. z[j1].re = temp11;
  367. z[j1].im = temp12;
  368. }
  369. s->fft_calc(s, z);
  370. /* post rotation + reordering */
  371. /* n8 = 32 or 64 */
  372. for(k = 0; k < n8; k += 2) {
  373. tcos1 = &tcos[n8 - k - 2];
  374. tsin1 = &tsin[n8 - k - 2];
  375. tcos2 = &tcos[n8 + k];
  376. tsin2 = &tsin[n8 + k];
  377. z1 = &z[n8 - k - 2];
  378. z2 = &z[n8 + k ];
  379. __asm__ volatile (
  380. "lwc1 %[temp1], 12(%[z1]) \t\n"
  381. "lwc1 %[temp2], 4(%[tsin1]) \t\n"
  382. "lwc1 %[temp3], 4(%[tcos1]) \t\n"
  383. "lwc1 %[temp4], 8(%[z1]) \t\n"
  384. "lwc1 %[temp5], 4(%[z1]) \t\n"
  385. "mul.s %[temp9], %[temp1], %[temp2] \t\n"
  386. "mul.s %[temp10], %[temp1], %[temp3] \t\n"
  387. "lwc1 %[temp6], 0(%[tsin1]) \t\n"
  388. "lwc1 %[temp7], 0(%[tcos1]) \t\n"
  389. "nmsub.s %[temp9], %[temp9], %[temp4], %[temp3] \t\n"
  390. "madd.s %[temp10], %[temp10], %[temp4], %[temp2] \t\n"
  391. "mul.s %[temp11], %[temp5], %[temp6] \t\n"
  392. "mul.s %[temp12], %[temp5], %[temp7] \t\n"
  393. "lwc1 %[temp8], 0(%[z1]) \t\n"
  394. "lwc1 %[temp1], 4(%[z2]) \t\n"
  395. "lwc1 %[temp2], 0(%[tsin2]) \t\n"
  396. "lwc1 %[temp3], 0(%[tcos2]) \t\n"
  397. "nmsub.s %[temp11], %[temp11], %[temp8], %[temp7] \t\n"
  398. "madd.s %[temp12], %[temp12], %[temp8], %[temp6] \t\n"
  399. "mul.s %[temp13], %[temp1], %[temp2] \t\n"
  400. "mul.s %[temp14], %[temp1], %[temp3] \t\n"
  401. "lwc1 %[temp4], 0(%[z2]) \t\n"
  402. "lwc1 %[temp5], 12(%[z2]) \t\n"
  403. "lwc1 %[temp6], 4(%[tsin2]) \t\n"
  404. "lwc1 %[temp7], 4(%[tcos2]) \t\n"
  405. "nmsub.s %[temp13], %[temp13], %[temp4], %[temp3] \t\n"
  406. "madd.s %[temp14], %[temp14], %[temp4], %[temp2] \t\n"
  407. "mul.s %[temp15], %[temp5], %[temp6] \t\n"
  408. "mul.s %[temp16], %[temp5], %[temp7] \t\n"
  409. "lwc1 %[temp8], 8(%[z2]) \t\n"
  410. "nmsub.s %[temp15], %[temp15], %[temp8], %[temp7] \t\n"
  411. "madd.s %[temp16], %[temp16], %[temp8], %[temp6] \t\n"
  412. : [temp1]"=&f"(temp1), [temp2]"=&f"(temp2),
  413. [temp3]"=&f"(temp3), [temp4]"=&f"(temp4),
  414. [temp5]"=&f"(temp5), [temp6]"=&f"(temp6),
  415. [temp7]"=&f"(temp7), [temp8]"=&f"(temp8),
  416. [temp9]"=&f"(temp9), [temp10]"=&f"(temp10),
  417. [temp11]"=&f"(temp11), [temp12]"=&f"(temp12),
  418. [temp13]"=&f"(temp13), [temp14]"=&f"(temp14),
  419. [temp15]"=&f"(temp15), [temp16]"=&f"(temp16)
  420. : [z1]"r"(z1), [z2]"r"(z2),
  421. [tsin1]"r"(tsin1), [tcos1]"r"(tcos1),
  422. [tsin2]"r"(tsin2), [tcos2]"r"(tcos2)
  423. : "memory"
  424. );
  425. z1[1].re = temp9;
  426. z1[1].im = temp14;
  427. z2[0].re = temp13;
  428. z2[0].im = temp10;
  429. z1[0].re = temp11;
  430. z1[0].im = temp16;
  431. z2[1].re = temp15;
  432. z2[1].im = temp12;
  433. }
  434. }
  435. /**
  436. * Compute inverse MDCT of size N = 2^nbits
  437. * @param output N samples
  438. * @param input N/2 samples
  439. */
  440. static void ff_imdct_calc_mips(FFTContext *s, FFTSample *output, const FFTSample *input)
  441. {
  442. int k;
  443. int n = 1 << s->mdct_bits;
  444. int n2 = n >> 1;
  445. int n4 = n >> 2;
  446. ff_imdct_half_mips(s, output+n4, input);
  447. for(k = 0; k < n4; k+=4) {
  448. output[k] = -output[n2-k-1];
  449. output[k+1] = -output[n2-k-2];
  450. output[k+2] = -output[n2-k-3];
  451. output[k+3] = -output[n2-k-4];
  452. output[n-k-1] = output[n2+k];
  453. output[n-k-2] = output[n2+k+1];
  454. output[n-k-3] = output[n2+k+2];
  455. output[n-k-4] = output[n2+k+3];
  456. }
  457. }
  458. #endif /* HAVE_INLINE_ASM */
  459. av_cold void ff_fft_init_mips(FFTContext *s)
  460. {
  461. int n=0;
  462. ff_fft_lut_init(ff_fft_offsets_lut, 0, 1 << 16, &n);
  463. ff_init_ff_cos_tabs(16);
  464. #if HAVE_INLINE_ASM
  465. s->fft_calc = ff_fft_calc_mips;
  466. #if CONFIG_MDCT
  467. s->imdct_calc = ff_imdct_calc_mips;
  468. s->imdct_half = ff_imdct_half_mips;
  469. #endif
  470. #endif
  471. }