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.

517 lines
27KB

  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. #include "libavutil/mips/asmdefs.h"
  54. /**
  55. * FFT transform
  56. */
  57. #if HAVE_INLINE_ASM
  58. static void ff_fft_calc_mips(FFTContext *s, FFTComplex *z)
  59. {
  60. int nbits, i, n, num_transforms, offset, step;
  61. int n4, n2, n34;
  62. FFTSample tmp1, tmp2, tmp3, tmp4, tmp5, tmp6, tmp7, tmp8;
  63. FFTComplex *tmpz;
  64. float w_re, w_im;
  65. float *w_re_ptr, *w_im_ptr;
  66. const int fft_size = (1 << s->nbits);
  67. float pom, pom1, pom2, pom3;
  68. float temp, temp1, temp3, temp4;
  69. FFTComplex * tmpz_n2, * tmpz_n34, * tmpz_n4;
  70. FFTComplex * tmpz_n2_i, * tmpz_n34_i, * tmpz_n4_i, * tmpz_i;
  71. num_transforms = (0x2aab >> (16 - s->nbits)) | 1;
  72. for (n=0; n<num_transforms; n++) {
  73. offset = ff_fft_offsets_lut[n] << 2;
  74. tmpz = z + offset;
  75. tmp1 = tmpz[0].re + tmpz[1].re;
  76. tmp5 = tmpz[2].re + tmpz[3].re;
  77. tmp2 = tmpz[0].im + tmpz[1].im;
  78. tmp6 = tmpz[2].im + tmpz[3].im;
  79. tmp3 = tmpz[0].re - tmpz[1].re;
  80. tmp8 = tmpz[2].im - tmpz[3].im;
  81. tmp4 = tmpz[0].im - tmpz[1].im;
  82. tmp7 = tmpz[2].re - tmpz[3].re;
  83. tmpz[0].re = tmp1 + tmp5;
  84. tmpz[2].re = tmp1 - tmp5;
  85. tmpz[0].im = tmp2 + tmp6;
  86. tmpz[2].im = tmp2 - tmp6;
  87. tmpz[1].re = tmp3 + tmp8;
  88. tmpz[3].re = tmp3 - tmp8;
  89. tmpz[1].im = tmp4 - tmp7;
  90. tmpz[3].im = tmp4 + tmp7;
  91. }
  92. if (fft_size < 8)
  93. return;
  94. num_transforms = (num_transforms >> 1) | 1;
  95. for (n=0; n<num_transforms; n++) {
  96. offset = ff_fft_offsets_lut[n] << 3;
  97. tmpz = z + offset;
  98. __asm__ volatile (
  99. "lwc1 %[tmp1], 32(%[tmpz]) \n\t"
  100. "lwc1 %[pom], 40(%[tmpz]) \n\t"
  101. "lwc1 %[tmp3], 48(%[tmpz]) \n\t"
  102. "lwc1 %[pom1], 56(%[tmpz]) \n\t"
  103. "lwc1 %[tmp2], 36(%[tmpz]) \n\t"
  104. "lwc1 %[pom2], 44(%[tmpz]) \n\t"
  105. "lwc1 %[pom3], 60(%[tmpz]) \n\t"
  106. "lwc1 %[tmp4], 52(%[tmpz]) \n\t"
  107. "add.s %[tmp1], %[tmp1], %[pom] \n\t" // tmp1 = tmpz[4].re + tmpz[5].re;
  108. "add.s %[tmp3], %[tmp3], %[pom1] \n\t" // tmp3 = tmpz[6].re + tmpz[7].re;
  109. "add.s %[tmp2], %[tmp2], %[pom2] \n\t" // tmp2 = tmpz[4].im + tmpz[5].im;
  110. "lwc1 %[pom], 40(%[tmpz]) \n\t"
  111. "add.s %[tmp4], %[tmp4], %[pom3] \n\t" // tmp4 = tmpz[6].im + tmpz[7].im;
  112. "add.s %[tmp5], %[tmp1], %[tmp3] \n\t" // tmp5 = tmp1 + tmp3;
  113. "sub.s %[tmp7], %[tmp1], %[tmp3] \n\t" // tmp7 = tmp1 - tmp3;
  114. "lwc1 %[tmp1], 32(%[tmpz]) \n\t"
  115. "lwc1 %[pom1], 44(%[tmpz]) \n\t"
  116. "add.s %[tmp6], %[tmp2], %[tmp4] \n\t" // tmp6 = tmp2 + tmp4;
  117. "sub.s %[tmp8], %[tmp2], %[tmp4] \n\t" // tmp8 = tmp2 - tmp4;
  118. "lwc1 %[tmp2], 36(%[tmpz]) \n\t"
  119. "lwc1 %[pom2], 56(%[tmpz]) \n\t"
  120. "lwc1 %[pom3], 60(%[tmpz]) \n\t"
  121. "lwc1 %[tmp3], 48(%[tmpz]) \n\t"
  122. "lwc1 %[tmp4], 52(%[tmpz]) \n\t"
  123. "sub.s %[tmp1], %[tmp1], %[pom] \n\t" // tmp1 = tmpz[4].re - tmpz[5].re;
  124. "lwc1 %[pom], 0(%[tmpz]) \n\t"
  125. "sub.s %[tmp2], %[tmp2], %[pom1] \n\t" // tmp2 = tmpz[4].im - tmpz[5].im;
  126. "sub.s %[tmp3], %[tmp3], %[pom2] \n\t" // tmp3 = tmpz[6].re - tmpz[7].re;
  127. "lwc1 %[pom2], 4(%[tmpz]) \n\t"
  128. "sub.s %[pom1], %[pom], %[tmp5] \n\t"
  129. "sub.s %[tmp4], %[tmp4], %[pom3] \n\t" // tmp4 = tmpz[6].im - tmpz[7].im;
  130. "add.s %[pom3], %[pom], %[tmp5] \n\t"
  131. "sub.s %[pom], %[pom2], %[tmp6] \n\t"
  132. "add.s %[pom2], %[pom2], %[tmp6] \n\t"
  133. "swc1 %[pom1], 32(%[tmpz]) \n\t" // tmpz[4].re = tmpz[0].re - tmp5;
  134. "swc1 %[pom3], 0(%[tmpz]) \n\t" // tmpz[0].re = tmpz[0].re + tmp5;
  135. "swc1 %[pom], 36(%[tmpz]) \n\t" // tmpz[4].im = tmpz[0].im - tmp6;
  136. "swc1 %[pom2], 4(%[tmpz]) \n\t" // tmpz[0].im = tmpz[0].im + tmp6;
  137. "lwc1 %[pom1], 16(%[tmpz]) \n\t"
  138. "lwc1 %[pom3], 20(%[tmpz]) \n\t"
  139. "li.s %[pom], 0.7071067812 \n\t" // float pom = 0.7071067812f;
  140. "add.s %[temp1],%[tmp1], %[tmp2] \n\t"
  141. "sub.s %[temp], %[pom1], %[tmp8] \n\t"
  142. "add.s %[pom2], %[pom3], %[tmp7] \n\t"
  143. "sub.s %[temp3],%[tmp3], %[tmp4] \n\t"
  144. "sub.s %[temp4],%[tmp2], %[tmp1] \n\t"
  145. "swc1 %[temp], 48(%[tmpz]) \n\t" // tmpz[6].re = tmpz[2].re - tmp8;
  146. "swc1 %[pom2], 52(%[tmpz]) \n\t" // tmpz[6].im = tmpz[2].im + tmp7;
  147. "add.s %[pom1], %[pom1], %[tmp8] \n\t"
  148. "sub.s %[pom3], %[pom3], %[tmp7] \n\t"
  149. "add.s %[tmp3], %[tmp3], %[tmp4] \n\t"
  150. "mul.s %[tmp5], %[pom], %[temp1] \n\t" // tmp5 = pom * (tmp1 + tmp2);
  151. "mul.s %[tmp7], %[pom], %[temp3] \n\t" // tmp7 = pom * (tmp3 - tmp4);
  152. "mul.s %[tmp6], %[pom], %[temp4] \n\t" // tmp6 = pom * (tmp2 - tmp1);
  153. "mul.s %[tmp8], %[pom], %[tmp3] \n\t" // tmp8 = pom * (tmp3 + tmp4);
  154. "swc1 %[pom1], 16(%[tmpz]) \n\t" // tmpz[2].re = tmpz[2].re + tmp8;
  155. "swc1 %[pom3], 20(%[tmpz]) \n\t" // tmpz[2].im = tmpz[2].im - tmp7;
  156. "add.s %[tmp1], %[tmp5], %[tmp7] \n\t" // tmp1 = tmp5 + tmp7;
  157. "sub.s %[tmp3], %[tmp5], %[tmp7] \n\t" // tmp3 = tmp5 - tmp7;
  158. "add.s %[tmp2], %[tmp6], %[tmp8] \n\t" // tmp2 = tmp6 + tmp8;
  159. "sub.s %[tmp4], %[tmp6], %[tmp8] \n\t" // tmp4 = tmp6 - tmp8;
  160. "lwc1 %[temp], 8(%[tmpz]) \n\t"
  161. "lwc1 %[temp1],12(%[tmpz]) \n\t"
  162. "lwc1 %[pom], 24(%[tmpz]) \n\t"
  163. "lwc1 %[pom2], 28(%[tmpz]) \n\t"
  164. "sub.s %[temp4],%[temp], %[tmp1] \n\t"
  165. "sub.s %[temp3],%[temp1], %[tmp2] \n\t"
  166. "add.s %[temp], %[temp], %[tmp1] \n\t"
  167. "add.s %[temp1],%[temp1], %[tmp2] \n\t"
  168. "sub.s %[pom1], %[pom], %[tmp4] \n\t"
  169. "add.s %[pom3], %[pom2], %[tmp3] \n\t"
  170. "add.s %[pom], %[pom], %[tmp4] \n\t"
  171. "sub.s %[pom2], %[pom2], %[tmp3] \n\t"
  172. "swc1 %[temp4],40(%[tmpz]) \n\t" // tmpz[5].re = tmpz[1].re - tmp1;
  173. "swc1 %[temp3],44(%[tmpz]) \n\t" // tmpz[5].im = tmpz[1].im - tmp2;
  174. "swc1 %[temp], 8(%[tmpz]) \n\t" // tmpz[1].re = tmpz[1].re + tmp1;
  175. "swc1 %[temp1],12(%[tmpz]) \n\t" // tmpz[1].im = tmpz[1].im + tmp2;
  176. "swc1 %[pom1], 56(%[tmpz]) \n\t" // tmpz[7].re = tmpz[3].re - tmp4;
  177. "swc1 %[pom3], 60(%[tmpz]) \n\t" // tmpz[7].im = tmpz[3].im + tmp3;
  178. "swc1 %[pom], 24(%[tmpz]) \n\t" // tmpz[3].re = tmpz[3].re + tmp4;
  179. "swc1 %[pom2], 28(%[tmpz]) \n\t" // tmpz[3].im = tmpz[3].im - tmp3;
  180. : [tmp1]"=&f"(tmp1), [pom]"=&f"(pom), [pom1]"=&f"(pom1), [pom2]"=&f"(pom2),
  181. [tmp3]"=&f"(tmp3), [tmp2]"=&f"(tmp2), [tmp4]"=&f"(tmp4), [tmp5]"=&f"(tmp5), [tmp7]"=&f"(tmp7),
  182. [tmp6]"=&f"(tmp6), [tmp8]"=&f"(tmp8), [pom3]"=&f"(pom3),[temp]"=&f"(temp), [temp1]"=&f"(temp1),
  183. [temp3]"=&f"(temp3), [temp4]"=&f"(temp4)
  184. : [tmpz]"r"(tmpz)
  185. : "memory"
  186. );
  187. }
  188. step = 1 << (MAX_LOG2_NFFT - 4);
  189. n4 = 4;
  190. for (nbits=4; nbits<=s->nbits; nbits++) {
  191. num_transforms = (num_transforms >> 1) | 1;
  192. n2 = 2 * n4;
  193. n34 = 3 * n4;
  194. for (n=0; n<num_transforms; n++) {
  195. offset = ff_fft_offsets_lut[n] << nbits;
  196. tmpz = z + offset;
  197. tmpz_n2 = tmpz + n2;
  198. tmpz_n4 = tmpz + n4;
  199. tmpz_n34 = tmpz + n34;
  200. __asm__ volatile (
  201. "lwc1 %[pom1], 0(%[tmpz_n2]) \n\t"
  202. "lwc1 %[pom], 0(%[tmpz_n34]) \n\t"
  203. "lwc1 %[pom2], 4(%[tmpz_n2]) \n\t"
  204. "lwc1 %[pom3], 4(%[tmpz_n34]) \n\t"
  205. "lwc1 %[temp1],0(%[tmpz]) \n\t"
  206. "lwc1 %[temp3],4(%[tmpz]) \n\t"
  207. "add.s %[tmp5], %[pom1], %[pom] \n\t" // tmp5 = tmpz[ n2].re + tmpz[n34].re;
  208. "sub.s %[tmp1], %[pom1], %[pom] \n\t" // tmp1 = tmpz[ n2].re - tmpz[n34].re;
  209. "add.s %[tmp6], %[pom2], %[pom3] \n\t" // tmp6 = tmpz[ n2].im + tmpz[n34].im;
  210. "sub.s %[tmp2], %[pom2], %[pom3] \n\t" // tmp2 = tmpz[ n2].im - tmpz[n34].im;
  211. "sub.s %[temp], %[temp1], %[tmp5] \n\t"
  212. "add.s %[temp1],%[temp1], %[tmp5] \n\t"
  213. "sub.s %[temp4],%[temp3], %[tmp6] \n\t"
  214. "add.s %[temp3],%[temp3], %[tmp6] \n\t"
  215. "swc1 %[temp], 0(%[tmpz_n2]) \n\t" // tmpz[ n2].re = tmpz[ 0].re - tmp5;
  216. "swc1 %[temp1],0(%[tmpz]) \n\t" // tmpz[ 0].re = tmpz[ 0].re + tmp5;
  217. "lwc1 %[pom1], 0(%[tmpz_n4]) \n\t"
  218. "swc1 %[temp4],4(%[tmpz_n2]) \n\t" // tmpz[ n2].im = tmpz[ 0].im - tmp6;
  219. "lwc1 %[temp], 4(%[tmpz_n4]) \n\t"
  220. "swc1 %[temp3],4(%[tmpz]) \n\t" // tmpz[ 0].im = tmpz[ 0].im + tmp6;
  221. "sub.s %[pom], %[pom1], %[tmp2] \n\t"
  222. "add.s %[pom1], %[pom1], %[tmp2] \n\t"
  223. "add.s %[temp1],%[temp], %[tmp1] \n\t"
  224. "sub.s %[temp], %[temp], %[tmp1] \n\t"
  225. "swc1 %[pom], 0(%[tmpz_n34]) \n\t" // tmpz[n34].re = tmpz[n4].re - tmp2;
  226. "swc1 %[pom1], 0(%[tmpz_n4]) \n\t" // tmpz[ n4].re = tmpz[n4].re + tmp2;
  227. "swc1 %[temp1],4(%[tmpz_n34]) \n\t" // tmpz[n34].im = tmpz[n4].im + tmp1;
  228. "swc1 %[temp], 4(%[tmpz_n4]) \n\t" // tmpz[ n4].im = tmpz[n4].im - tmp1;
  229. : [tmp5]"=&f"(tmp5),
  230. [tmp1]"=&f"(tmp1), [pom]"=&f"(pom), [pom1]"=&f"(pom1), [pom2]"=&f"(pom2),
  231. [tmp2]"=&f"(tmp2), [tmp6]"=&f"(tmp6), [pom3]"=&f"(pom3),
  232. [temp]"=&f"(temp), [temp1]"=&f"(temp1), [temp3]"=&f"(temp3), [temp4]"=&f"(temp4)
  233. : [tmpz]"r"(tmpz), [tmpz_n2]"r"(tmpz_n2), [tmpz_n34]"r"(tmpz_n34), [tmpz_n4]"r"(tmpz_n4)
  234. : "memory"
  235. );
  236. w_re_ptr = (float*)(ff_cos_65536 + step);
  237. w_im_ptr = (float*)(ff_cos_65536 + MAX_FFT_SIZE/4 - step);
  238. for (i=1; i<n4; i++) {
  239. w_re = w_re_ptr[0];
  240. w_im = w_im_ptr[0];
  241. tmpz_n2_i = tmpz_n2 + i;
  242. tmpz_n4_i = tmpz_n4 + i;
  243. tmpz_n34_i= tmpz_n34 + i;
  244. tmpz_i = tmpz + i;
  245. __asm__ volatile (
  246. "lwc1 %[temp], 0(%[tmpz_n2_i]) \n\t"
  247. "lwc1 %[temp1], 4(%[tmpz_n2_i]) \n\t"
  248. "lwc1 %[pom], 0(%[tmpz_n34_i]) \n\t"
  249. "lwc1 %[pom1], 4(%[tmpz_n34_i]) \n\t"
  250. "mul.s %[temp3], %[w_im], %[temp] \n\t"
  251. "mul.s %[temp4], %[w_im], %[temp1] \n\t"
  252. "mul.s %[pom2], %[w_im], %[pom1] \n\t"
  253. "mul.s %[pom3], %[w_im], %[pom] \n\t"
  254. "msub.s %[tmp2], %[temp3], %[w_re], %[temp1] \n\t" // tmp2 = w_re * tmpz[ n2+i].im - w_im * tmpz[ n2+i].re;
  255. "madd.s %[tmp1], %[temp4], %[w_re], %[temp] \n\t" // tmp1 = w_re * tmpz[ n2+i].re + w_im * tmpz[ n2+i].im;
  256. "msub.s %[tmp3], %[pom2], %[w_re], %[pom] \n\t" // tmp3 = w_re * tmpz[n34+i].re - w_im * tmpz[n34+i].im;
  257. "madd.s %[tmp4], %[pom3], %[w_re], %[pom1] \n\t" // tmp4 = w_re * tmpz[n34+i].im + w_im * tmpz[n34+i].re;
  258. "lwc1 %[temp], 0(%[tmpz_i]) \n\t"
  259. "lwc1 %[pom], 4(%[tmpz_i]) \n\t"
  260. "add.s %[tmp5], %[tmp1], %[tmp3] \n\t" // tmp5 = tmp1 + tmp3;
  261. "sub.s %[tmp1], %[tmp1], %[tmp3] \n\t" // tmp1 = tmp1 - tmp3;
  262. "add.s %[tmp6], %[tmp2], %[tmp4] \n\t" // tmp6 = tmp2 + tmp4;
  263. "sub.s %[tmp2], %[tmp2], %[tmp4] \n\t" // tmp2 = tmp2 - tmp4;
  264. "sub.s %[temp1], %[temp], %[tmp5] \n\t"
  265. "add.s %[temp], %[temp], %[tmp5] \n\t"
  266. "sub.s %[pom1], %[pom], %[tmp6] \n\t"
  267. "add.s %[pom], %[pom], %[tmp6] \n\t"
  268. "lwc1 %[temp3], 0(%[tmpz_n4_i]) \n\t"
  269. "lwc1 %[pom2], 4(%[tmpz_n4_i]) \n\t"
  270. "swc1 %[temp1], 0(%[tmpz_n2_i]) \n\t" // tmpz[ n2+i].re = tmpz[ i].re - tmp5;
  271. "swc1 %[temp], 0(%[tmpz_i]) \n\t" // tmpz[ i].re = tmpz[ i].re + tmp5;
  272. "swc1 %[pom1], 4(%[tmpz_n2_i]) \n\t" // tmpz[ n2+i].im = tmpz[ i].im - tmp6;
  273. "swc1 %[pom] , 4(%[tmpz_i]) \n\t" // tmpz[ i].im = tmpz[ i].im + tmp6;
  274. "sub.s %[temp4], %[temp3], %[tmp2] \n\t"
  275. "add.s %[pom3], %[pom2], %[tmp1] \n\t"
  276. "add.s %[temp3], %[temp3], %[tmp2] \n\t"
  277. "sub.s %[pom2], %[pom2], %[tmp1] \n\t"
  278. "swc1 %[temp4], 0(%[tmpz_n34_i]) \n\t" // tmpz[n34+i].re = tmpz[n4+i].re - tmp2;
  279. "swc1 %[pom3], 4(%[tmpz_n34_i]) \n\t" // tmpz[n34+i].im = tmpz[n4+i].im + tmp1;
  280. "swc1 %[temp3], 0(%[tmpz_n4_i]) \n\t" // tmpz[ n4+i].re = tmpz[n4+i].re + tmp2;
  281. "swc1 %[pom2], 4(%[tmpz_n4_i]) \n\t" // tmpz[ n4+i].im = tmpz[n4+i].im - tmp1;
  282. : [tmp1]"=&f"(tmp1), [tmp2]"=&f" (tmp2), [temp]"=&f"(temp), [tmp3]"=&f"(tmp3),
  283. [tmp4]"=&f"(tmp4), [tmp5]"=&f"(tmp5), [tmp6]"=&f"(tmp6),
  284. [temp1]"=&f"(temp1), [temp3]"=&f"(temp3), [temp4]"=&f"(temp4),
  285. [pom]"=&f"(pom), [pom1]"=&f"(pom1), [pom2]"=&f"(pom2), [pom3]"=&f"(pom3)
  286. : [w_re]"f"(w_re), [w_im]"f"(w_im),
  287. [tmpz_i]"r"(tmpz_i),[tmpz_n2_i]"r"(tmpz_n2_i),
  288. [tmpz_n34_i]"r"(tmpz_n34_i), [tmpz_n4_i]"r"(tmpz_n4_i)
  289. : "memory"
  290. );
  291. w_re_ptr += step;
  292. w_im_ptr -= step;
  293. }
  294. }
  295. step >>= 1;
  296. n4 <<= 1;
  297. }
  298. }
  299. /**
  300. * MDCT/IMDCT transforms.
  301. */
  302. static void ff_imdct_half_mips(FFTContext *s, FFTSample *output, const FFTSample *input)
  303. {
  304. int k, n8, n4, n2, n, j;
  305. const uint16_t *revtab = s->revtab;
  306. const FFTSample *tcos = s->tcos;
  307. const FFTSample *tsin = s->tsin;
  308. const FFTSample *in1, *in2, *in3, *in4;
  309. FFTComplex *z = (FFTComplex *)output;
  310. int j1;
  311. const float *tcos1, *tsin1, *tcos2, *tsin2;
  312. float temp1, temp2, temp3, temp4, temp5, temp6, temp7, temp8,
  313. temp9, temp10, temp11, temp12, temp13, temp14, temp15, temp16;
  314. FFTComplex *z1, *z2;
  315. n = 1 << s->mdct_bits;
  316. n2 = n >> 1;
  317. n4 = n >> 2;
  318. n8 = n >> 3;
  319. /* pre rotation */
  320. in1 = input;
  321. in2 = input + n2 - 1;
  322. in3 = input + 2;
  323. in4 = input + n2 - 3;
  324. tcos1 = tcos;
  325. tsin1 = tsin;
  326. /* n4 = 64 or 128 */
  327. for(k = 0; k < n4; k += 2) {
  328. j = revtab[k ];
  329. j1 = revtab[k + 1];
  330. __asm__ volatile (
  331. "lwc1 %[temp1], 0(%[in2]) \t\n"
  332. "lwc1 %[temp2], 0(%[tcos1]) \t\n"
  333. "lwc1 %[temp3], 0(%[tsin1]) \t\n"
  334. "lwc1 %[temp4], 0(%[in1]) \t\n"
  335. "lwc1 %[temp5], 0(%[in4]) \t\n"
  336. "mul.s %[temp9], %[temp1], %[temp2] \t\n"
  337. "mul.s %[temp10], %[temp1], %[temp3] \t\n"
  338. "lwc1 %[temp6], 4(%[tcos1]) \t\n"
  339. "lwc1 %[temp7], 4(%[tsin1]) \t\n"
  340. "nmsub.s %[temp9], %[temp9], %[temp4], %[temp3] \t\n"
  341. "madd.s %[temp10], %[temp10], %[temp4], %[temp2] \t\n"
  342. "mul.s %[temp11], %[temp5], %[temp6] \t\n"
  343. "mul.s %[temp12], %[temp5], %[temp7] \t\n"
  344. "lwc1 %[temp8], 0(%[in3]) \t\n"
  345. PTR_ADDIU " %[tcos1], %[tcos1], 8 \t\n"
  346. PTR_ADDIU " %[tsin1], %[tsin1], 8 \t\n"
  347. PTR_ADDIU " %[in1], %[in1], 16 \t\n"
  348. "nmsub.s %[temp11], %[temp11], %[temp8], %[temp7] \t\n"
  349. "madd.s %[temp12], %[temp12], %[temp8], %[temp6] \t\n"
  350. PTR_ADDIU " %[in2], %[in2], -16 \t\n"
  351. PTR_ADDIU " %[in3], %[in3], 16 \t\n"
  352. PTR_ADDIU " %[in4], %[in4], -16 \t\n"
  353. : [temp1]"=&f"(temp1), [temp2]"=&f"(temp2),
  354. [temp3]"=&f"(temp3), [temp4]"=&f"(temp4),
  355. [temp5]"=&f"(temp5), [temp6]"=&f"(temp6),
  356. [temp7]"=&f"(temp7), [temp8]"=&f"(temp8),
  357. [temp9]"=&f"(temp9), [temp10]"=&f"(temp10),
  358. [temp11]"=&f"(temp11), [temp12]"=&f"(temp12),
  359. [tsin1]"+r"(tsin1), [tcos1]"+r"(tcos1),
  360. [in1]"+r"(in1), [in2]"+r"(in2),
  361. [in3]"+r"(in3), [in4]"+r"(in4)
  362. :
  363. : "memory"
  364. );
  365. z[j ].re = temp9;
  366. z[j ].im = temp10;
  367. z[j1].re = temp11;
  368. z[j1].im = temp12;
  369. }
  370. s->fft_calc(s, z);
  371. /* post rotation + reordering */
  372. /* n8 = 32 or 64 */
  373. for(k = 0; k < n8; k += 2) {
  374. tcos1 = &tcos[n8 - k - 2];
  375. tsin1 = &tsin[n8 - k - 2];
  376. tcos2 = &tcos[n8 + k];
  377. tsin2 = &tsin[n8 + k];
  378. z1 = &z[n8 - k - 2];
  379. z2 = &z[n8 + k ];
  380. __asm__ volatile (
  381. "lwc1 %[temp1], 12(%[z1]) \t\n"
  382. "lwc1 %[temp2], 4(%[tsin1]) \t\n"
  383. "lwc1 %[temp3], 4(%[tcos1]) \t\n"
  384. "lwc1 %[temp4], 8(%[z1]) \t\n"
  385. "lwc1 %[temp5], 4(%[z1]) \t\n"
  386. "mul.s %[temp9], %[temp1], %[temp2] \t\n"
  387. "mul.s %[temp10], %[temp1], %[temp3] \t\n"
  388. "lwc1 %[temp6], 0(%[tsin1]) \t\n"
  389. "lwc1 %[temp7], 0(%[tcos1]) \t\n"
  390. "nmsub.s %[temp9], %[temp9], %[temp4], %[temp3] \t\n"
  391. "madd.s %[temp10], %[temp10], %[temp4], %[temp2] \t\n"
  392. "mul.s %[temp11], %[temp5], %[temp6] \t\n"
  393. "mul.s %[temp12], %[temp5], %[temp7] \t\n"
  394. "lwc1 %[temp8], 0(%[z1]) \t\n"
  395. "lwc1 %[temp1], 4(%[z2]) \t\n"
  396. "lwc1 %[temp2], 0(%[tsin2]) \t\n"
  397. "lwc1 %[temp3], 0(%[tcos2]) \t\n"
  398. "nmsub.s %[temp11], %[temp11], %[temp8], %[temp7] \t\n"
  399. "madd.s %[temp12], %[temp12], %[temp8], %[temp6] \t\n"
  400. "mul.s %[temp13], %[temp1], %[temp2] \t\n"
  401. "mul.s %[temp14], %[temp1], %[temp3] \t\n"
  402. "lwc1 %[temp4], 0(%[z2]) \t\n"
  403. "lwc1 %[temp5], 12(%[z2]) \t\n"
  404. "lwc1 %[temp6], 4(%[tsin2]) \t\n"
  405. "lwc1 %[temp7], 4(%[tcos2]) \t\n"
  406. "nmsub.s %[temp13], %[temp13], %[temp4], %[temp3] \t\n"
  407. "madd.s %[temp14], %[temp14], %[temp4], %[temp2] \t\n"
  408. "mul.s %[temp15], %[temp5], %[temp6] \t\n"
  409. "mul.s %[temp16], %[temp5], %[temp7] \t\n"
  410. "lwc1 %[temp8], 8(%[z2]) \t\n"
  411. "nmsub.s %[temp15], %[temp15], %[temp8], %[temp7] \t\n"
  412. "madd.s %[temp16], %[temp16], %[temp8], %[temp6] \t\n"
  413. : [temp1]"=&f"(temp1), [temp2]"=&f"(temp2),
  414. [temp3]"=&f"(temp3), [temp4]"=&f"(temp4),
  415. [temp5]"=&f"(temp5), [temp6]"=&f"(temp6),
  416. [temp7]"=&f"(temp7), [temp8]"=&f"(temp8),
  417. [temp9]"=&f"(temp9), [temp10]"=&f"(temp10),
  418. [temp11]"=&f"(temp11), [temp12]"=&f"(temp12),
  419. [temp13]"=&f"(temp13), [temp14]"=&f"(temp14),
  420. [temp15]"=&f"(temp15), [temp16]"=&f"(temp16)
  421. : [z1]"r"(z1), [z2]"r"(z2),
  422. [tsin1]"r"(tsin1), [tcos1]"r"(tcos1),
  423. [tsin2]"r"(tsin2), [tcos2]"r"(tcos2)
  424. : "memory"
  425. );
  426. z1[1].re = temp9;
  427. z1[1].im = temp14;
  428. z2[0].re = temp13;
  429. z2[0].im = temp10;
  430. z1[0].re = temp11;
  431. z1[0].im = temp16;
  432. z2[1].re = temp15;
  433. z2[1].im = temp12;
  434. }
  435. }
  436. /**
  437. * Compute inverse MDCT of size N = 2^nbits
  438. * @param output N samples
  439. * @param input N/2 samples
  440. */
  441. static void ff_imdct_calc_mips(FFTContext *s, FFTSample *output, const FFTSample *input)
  442. {
  443. int k;
  444. int n = 1 << s->mdct_bits;
  445. int n2 = n >> 1;
  446. int n4 = n >> 2;
  447. ff_imdct_half_mips(s, output+n4, input);
  448. for(k = 0; k < n4; k+=4) {
  449. output[k] = -output[n2-k-1];
  450. output[k+1] = -output[n2-k-2];
  451. output[k+2] = -output[n2-k-3];
  452. output[k+3] = -output[n2-k-4];
  453. output[n-k-1] = output[n2+k];
  454. output[n-k-2] = output[n2+k+1];
  455. output[n-k-3] = output[n2+k+2];
  456. output[n-k-4] = output[n2+k+3];
  457. }
  458. }
  459. #endif /* HAVE_INLINE_ASM */
  460. av_cold void ff_fft_init_mips(FFTContext *s)
  461. {
  462. int n=0;
  463. if (s->nbits > 16)
  464. return;
  465. ff_fft_lut_init(ff_fft_offsets_lut, 0, 1 << 17, &n);
  466. ff_init_ff_cos_tabs(16);
  467. #if HAVE_INLINE_ASM
  468. s->fft_calc = ff_fft_calc_mips;
  469. #if CONFIG_MDCT
  470. s->imdct_calc = ff_imdct_calc_mips;
  471. s->imdct_half = ff_imdct_half_mips;
  472. #endif
  473. #endif
  474. }