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.

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