2 * Loongson SIMD optimized simple idct
4 * Copyright (c) 2015 Loongson Technology Corporation Limited
5 * Copyright (c) 2015 Zhou Xiaoyong <zhouxiaoyong@loongson.cn>
6 * Zhang Shuangshuang <zhangshuangshuang@ict.ac.cn>
8 * This file is part of FFmpeg.
10 * FFmpeg is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU Lesser General Public
12 * License as published by the Free Software Foundation; either
13 * version 2.1 of the License, or (at your option) any later version.
15 * FFmpeg is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 * Lesser General Public License for more details.
20 * You should have received a copy of the GNU Lesser General Public
21 * License along with FFmpeg; if not, write to the Free Software
22 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
25 #include "idctdsp_mips.h"
26 #include "constants.h"
27 #include "libavutil/mips/asmdefs.h"
28 #include "libavutil/mips/mmiutils.h"
30 #define W1 22725 //cos(i*M_PI/16)*sqrt(2)*(1<<14) + 0.5
31 #define W2 21407 //cos(i*M_PI/16)*sqrt(2)*(1<<14) + 0.5
32 #define W3 19266 //cos(i*M_PI/16)*sqrt(2)*(1<<14) + 0.5
33 #define W4 16383 //cos(i*M_PI/16)*sqrt(2)*(1<<14) + 0.5
34 #define W5 12873 //cos(i*M_PI/16)*sqrt(2)*(1<<14) + 0.5
35 #define W6 8867 //cos(i*M_PI/16)*sqrt(2)*(1<<14) + 0.5
36 #define W7 4520 //cos(i*M_PI/16)*sqrt(2)*(1<<14) + 0.5
42 DECLARE_ALIGNED(8, const int16_t, W_arr)[46] = {
51 1024, 0, 1024, 0, //ff_p32_1024 = 0x0000040000000400ULL
52 0, -1, -1, -1, //mask = 0xffffffffffff0000ULL
53 32, 32, 32, 32 //ff_p16_32 = 0x0020002000200020ULL
56 void ff_simple_idct_8_mmi(int16_t *block)
61 #define IDCT_ROW_COND_DC(src1, src2) \
62 "dmfc1 $11, "#src1" \n\t" \
63 "dmfc1 $12, "#src2" \n\t" \
64 "and $11, $11, $9 \n\t" \
65 "or $10, $11, $12 \n\t" \
68 "punpcklhw $f30, "#src1", "#src2" \n\t" \
69 "punpckhhw $f31, "#src1", "#src2" \n\t" \
70 /* s6, s4, s2, s0 */ \
71 "punpcklhw "#src1", $f30, $f31 \n\t" \
72 /* s7, s5, s3, s1 */ \
73 "punpckhhw "#src2", $f30, $f31 \n\t" \
75 "pmaddhw $f30, "#src1", $f18 \n\t" \
76 "pmaddhw $f31, "#src2", $f19 \n\t" \
77 "paddw $f28, $f30, $f31 \n\t" \
78 "psubw $f29, $f30, $f31 \n\t" \
79 "punpcklwd $f30, $f28, $f29 \n\t" \
80 "punpckhwd $f31, $f28, $f29 \n\t" \
81 "paddw $f26, $f30, $f31 \n\t" \
82 "paddw $f26, $f26, $f16 \n\t" \
83 /* $f26: src[7], src[0] */ \
84 "psraw $f26, $f26, $f17 \n\t" \
86 "pmaddhw $f30, "#src1", $f20 \n\t" \
87 "pmaddhw $f31, "#src2", $f21 \n\t" \
88 "paddw $f28, $f30, $f31 \n\t" \
89 "psubw $f29, $f30, $f31 \n\t" \
90 "punpcklwd $f30, $f28, $f29 \n\t" \
91 "punpckhwd $f31, $f28, $f29 \n\t" \
92 "paddw $f27, $f30, $f31 \n\t" \
93 "paddw $f27, $f27, $f16 \n\t" \
94 /* $f27: src[6], src[1] */ \
95 "psraw $f27, $f27, $f17 \n\t" \
97 "pmaddhw $f30, "#src1", $f22 \n\t" \
98 "pmaddhw $f31, "#src2", $f23 \n\t" \
99 "paddw $f28, $f30, $f31 \n\t" \
100 "psubw $f29, $f30, $f31 \n\t" \
101 "punpcklwd $f30, $f28, $f29 \n\t" \
102 "punpckhwd $f31, $f28, $f29 \n\t" \
103 "paddw $f28, $f30, $f31 \n\t" \
104 "paddw $f28, $f28, $f16 \n\t" \
105 /* $f28: src[5], src[2] */ \
106 "psraw $f28, $f28, $f17 \n\t" \
108 "pmaddhw $f30, "#src1", $f24 \n\t" \
109 "pmaddhw $f31, "#src2", $f25 \n\t" \
110 "paddw "#src1", $f30, $f31 \n\t" \
111 "psubw "#src2", $f30, $f31 \n\t" \
112 "punpcklwd $f30, "#src1", "#src2" \n\t" \
113 "punpckhwd $f31, "#src1", "#src2" \n\t" \
114 "paddw $f29, $f30, $f31 \n\t" \
115 "paddw $f29, $f29, $f16 \n\t" \
116 /* $f29: src[4], src[3] */ \
117 "psraw $f29, $f29, $f17 \n\t" \
119 "punpcklhw "#src1", $f26, $f27 \n\t" \
120 "punpckhhw $f30, $f27, $f26 \n\t" \
121 "punpcklhw $f31, $f28, $f29 \n\t" \
122 "punpckhhw "#src2", $f29, $f28 \n\t" \
123 /* src[3], src[2], src[1], src[0] */ \
124 "punpcklwd "#src1", "#src1", $f31 \n\t" \
125 /* src[7], src[6], src[5], src[4] */ \
126 "punpcklwd "#src2", "#src2", $f30 \n\t" \
131 "dmtc1 $10, $f30 \n\t" \
132 "psllh $f28, "#src1", $f30 \n\t" \
133 "dmtc1 $9, $f31 \n\t" \
134 "punpcklhw $f29, $f28, $f28 \n\t" \
135 "and $f29, $f29, $f31 \n\t" \
136 "paddw $f28, $f28, $f29 \n\t" \
137 "punpcklwd "#src1", $f28, $f28 \n\t" \
138 "punpcklwd "#src2", $f28, $f28 \n\t" \
141 /* idctRowCondDC row0~8 */
144 "gslqc1 $f19, $f18, 0x00(%[w_arr]) \n\t"
145 "gslqc1 $f21, $f20, 0x10(%[w_arr]) \n\t"
146 "gslqc1 $f23, $f22, 0x20(%[w_arr]) \n\t"
147 "gslqc1 $f25, $f24, 0x30(%[w_arr]) \n\t"
148 "gslqc1 $f17, $f16, 0x40(%[w_arr]) \n\t"
149 /* load source in block */
150 "gslqc1 $f1, $f0, 0x00(%[block]) \n\t"
151 "gslqc1 $f3, $f2, 0x10(%[block]) \n\t"
152 "gslqc1 $f5, $f4, 0x20(%[block]) \n\t"
153 "gslqc1 $f7, $f6, 0x30(%[block]) \n\t"
154 "gslqc1 $f9, $f8, 0x40(%[block]) \n\t"
155 "gslqc1 $f11, $f10, 0x50(%[block]) \n\t"
156 "gslqc1 $f13, $f12, 0x60(%[block]) \n\t"
157 "gslqc1 $f15, $f14, 0x70(%[block]) \n\t"
159 /* $9: mask ; $f17: ROW_SHIFT */
160 "dmfc1 $9, $f17 \n\t"
162 "mtc1 $10, $f17 \n\t"
163 IDCT_ROW_COND_DC($f0,$f1)
164 IDCT_ROW_COND_DC($f2,$f3)
165 IDCT_ROW_COND_DC($f4,$f5)
166 IDCT_ROW_COND_DC($f6,$f7)
167 IDCT_ROW_COND_DC($f8,$f9)
168 IDCT_ROW_COND_DC($f10,$f11)
169 IDCT_ROW_COND_DC($f12,$f13)
170 IDCT_ROW_COND_DC($f14,$f15)
172 #define IDCT_COL_CASE1(src, out1, out2) \
173 "pmaddhw $f26, "#src", $f18 \n\t" \
174 "pmaddhw $f27, "#src", $f20 \n\t" \
175 "pmaddhw $f28, "#src", $f22 \n\t" \
176 "pmaddhw $f29, "#src", $f24 \n\t" \
178 "punpcklwd $f30, $f26, $f26 \n\t" \
179 "punpckhwd $f31, $f26, $f26 \n\t" \
180 /* $f26: src[0], src[56] */ \
181 "paddw $f26, $f30, $f31 \n\t" \
182 "punpcklwd $f30, $f27, $f27 \n\t" \
183 "punpckhwd $f31, $f27, $f27 \n\t" \
184 /* $f27: src[8], src[48] */ \
185 "paddw $f27, $f30, $f31 \n\t" \
186 "punpcklwd $f30, $f28, $f28 \n\t" \
187 "punpckhwd $f31, $f28, $f28 \n\t" \
188 /* $f28: src[16], src[40] */ \
189 "paddw $f28, $f30, $f31 \n\t" \
190 "punpcklwd $f30, $f29, $f29 \n\t" \
191 "punpckhwd $f31, $f29, $f29 \n\t" \
192 /* $f29: src[24], src[32] */ \
193 "paddw $f29, $f30, $f31 \n\t" \
195 /* out1: src[24], src[16], src[8], src[0] */ \
196 /* out2: src[56], src[48], src[40], src[32] */ \
197 "punpcklhw $f30, $f26, $f27 \n\t" \
198 "punpcklhw $f31, $f28, $f29 \n\t" \
199 "punpckhwd "#out1", $f30, $f31 \n\t" \
200 "psrah "#out1", "#out1", $f16 \n\t" \
201 "punpcklhw $f30, $f27, $f26 \n\t" \
202 "punpcklhw $f31, $f29, $f28 \n\t" \
203 "punpckhwd "#out2", $f31, $f30 \n\t" \
204 "psrah "#out2", "#out2", $f16 \n\t"
206 #define IDCT_COL_CASE2(src1, src2, out1, out2) \
207 "pmaddhw $f28, "#src1", $f18 \n\t" \
208 "pmaddhw $f29, "#src2", $f19 \n\t" \
209 "paddw $f30, $f28, $f29 \n\t" \
210 "psubw $f31, $f28, $f29 \n\t" \
211 "punpcklwd $f28, $f30, $f31 \n\t" \
212 "punpckhwd $f29, $f30, $f31 \n\t" \
213 "pmaddhw $f30, "#src1", $f20 \n\t" \
214 "pmaddhw $f31, "#src2", $f21 \n\t" \
215 /* $f26: src[0], src[56] */ \
216 "paddw $f26, $f28, $f29 \n\t" \
217 "paddw $f28, $f30, $f31 \n\t" \
218 "psubw $f29, $f30, $f31 \n\t" \
219 "punpcklwd $f30, $f28, $f29 \n\t" \
220 "punpckhwd $f31, $f28, $f29 \n\t" \
221 "pmaddhw $f28, "#src1", $f22 \n\t" \
222 "pmaddhw $f29, "#src2", $f23 \n\t" \
223 /* $f27: src[8], src[48] */ \
224 "paddw $f27, $f30, $f31 \n\t" \
225 "paddw $f30, $f28, $f29 \n\t" \
226 "psubw $f31, $f28, $f29 \n\t" \
227 "punpcklwd $f28, $f30, $f31 \n\t" \
228 "punpckhwd $f29, $f30, $f31 \n\t" \
229 "pmaddhw $f30, "#src1", $f24 \n\t" \
230 "pmaddhw $f31, "#src2", $f25 \n\t" \
231 /* $f28: src[16], src[40] */ \
232 "paddw $f28, $f28, $f29 \n\t" \
233 "paddw "#out1", $f30, $f31 \n\t" \
234 "psubw "#out2", $f30, $f31 \n\t" \
235 "punpcklwd $f30, "#out1", "#out2" \n\t" \
236 "punpckhwd $f31, "#out1", "#out2" \n\t" \
237 /* $f29: src[24], src[32] */ \
238 "paddw $f29, $f30, $f31 \n\t" \
240 /* out1: src[24], src[16], src[8], src[0] */ \
241 /* out2: src[56], src[48], src[40], src[32] */ \
242 "punpcklhw "#out1", $f26, $f27 \n\t" \
243 "punpckhhw "#out2", $f27, $f26 \n\t" \
244 "punpcklhw $f30, $f28, $f29 \n\t" \
245 "punpckhhw $f31, $f29, $f28 \n\t" \
246 "punpckhwd "#out1", "#out1", $f30 \n\t" \
247 "punpckhwd "#out2", $f31, "#out2" \n\t" \
248 "psrah "#out1", "#out1", $f16 \n\t" \
249 "psrah "#out2", "#out2", $f16 \n\t"
252 /* idctSparseCol col0~3 */
254 /* $f17: ff_p16_32; $f16: COL_SHIFT-16 */
255 "gsldlc1 $f17, 0x57(%[w_arr]) \n\t"
256 "gsldrc1 $f17, 0x50(%[w_arr]) \n\t"
258 "dmtc1 $10, $f16 \n\t"
259 "paddh $f0, $f0, $f17 \n\t"
260 /* Transpose row[0,2,4,6] */
261 "punpcklhw $f26, $f0, $f4 \n\t"
262 "punpckhhw $f27, $f0, $f4 \n\t"
263 "punpcklhw $f28, $f8, $f12 \n\t"
264 "punpckhhw $f29, $f8, $f12 \n\t"
265 "punpcklwd $f0, $f26, $f28 \n\t"
266 "punpckhwd $f4, $f26, $f28 \n\t"
267 "punpcklwd $f8, $f27, $f29 \n\t"
268 "punpckhwd $f12, $f27, $f29 \n\t"
270 "or $f26, $f2, $f6 \n\t"
271 "or $f26, $f26, $f10 \n\t"
272 "or $f26, $f26, $f14 \n\t"
273 "dmfc1 $10, $f26 \n\t"
275 /* case1: In this case, row[1,3,5,7] are all zero */
276 /* col0: $f0: col[24,16,8,0]; $f2: col[56,48,40,32] */
277 IDCT_COL_CASE1($f0, $f0, $f2)
278 /* col1: $f4: col[25,17,9,1]; $f6: col[57,49,41,33] */
279 IDCT_COL_CASE1($f4, $f4, $f6)
280 /* col2: $f8: col[26,18,10,2]; $f10: col[58,50,42,34] */
281 IDCT_COL_CASE1($f8, $f8, $f10)
282 /* col3: $f12: col[27,19,11,3]; $f14: col[59,51,43,35] */
283 IDCT_COL_CASE1($f12, $f12, $f14)
287 /* case2: row[1,3,5,7] are not all zero */
289 "punpcklhw $f26, $f2, $f6 \n\t"
290 "punpckhhw $f27, $f2, $f6 \n\t"
291 "punpcklhw $f28, $f10, $f14 \n\t"
292 "punpckhhw $f29, $f10, $f14 \n\t"
293 "punpcklwd $f2, $f26, $f28 \n\t"
294 "punpckhwd $f6, $f26, $f28 \n\t"
295 "punpcklwd $f10, $f27, $f29 \n\t"
296 "punpckhwd $f14, $f27, $f29 \n\t"
298 /* col0: $f0: col[24,16,8,0]; $f2: col[56,48,40,32] */
299 IDCT_COL_CASE2($f0, $f2, $f0, $f2)
300 /* col1: $f4: col[25,17,9,1]; $f6: col[57,49,41,33] */
301 IDCT_COL_CASE2($f4, $f6, $f4, $f6)
302 /* col2: $f8: col[26,18,10,2]; $f10: col[58,50,42,34] */
303 IDCT_COL_CASE2($f8, $f10, $f8, $f10)
304 /* col3: $f12: col[27,19,11,3]; $f14: col[59,51,43,35] */
305 IDCT_COL_CASE2($f12, $f14, $f12, $f14)
309 "punpcklhw $f26, $f0, $f4 \n\t"
310 "punpckhhw $f27, $f0, $f4 \n\t"
311 "punpcklhw $f28, $f8, $f12 \n\t"
312 "punpckhhw $f29, $f8, $f12 \n\t"
313 "punpcklwd $f0, $f26, $f28 \n\t"
314 "punpckhwd $f4, $f26, $f28 \n\t"
315 "punpcklwd $f8, $f27, $f29 \n\t"
316 "punpckhwd $f12, $f27, $f29 \n\t"
318 "punpcklhw $f26, $f2, $f6 \n\t"
319 "punpckhhw $f27, $f2, $f6 \n\t"
320 "punpcklhw $f28, $f10, $f14 \n\t"
321 "punpckhhw $f29, $f10, $f14 \n\t"
322 "punpcklwd $f2, $f26, $f28 \n\t"
323 "punpckhwd $f6, $f26, $f28 \n\t"
324 "punpcklwd $f10, $f27, $f29 \n\t"
325 "punpckhwd $f14, $f27, $f29 \n\t"
327 /* idctSparseCol col4~7 */
329 "paddh $f1, $f1, $f17 \n\t"
331 "punpcklhw $f26, $f1, $f5 \n\t"
332 "punpckhhw $f27, $f1, $f5 \n\t"
333 "punpcklhw $f28, $f9, $f13 \n\t"
334 "punpckhhw $f29, $f9, $f13 \n\t"
335 "punpcklwd $f1, $f26, $f28 \n\t"
336 "punpckhwd $f5, $f26, $f28 \n\t"
337 "punpcklwd $f9, $f27, $f29 \n\t"
338 "punpckhwd $f13, $f27, $f29 \n\t"
340 "or $f26, $f3, $f7 \n\t"
341 "or $f26, $f26, $f11 \n\t"
342 "or $f26, $f26, $f15 \n\t"
343 "dmfc1 $10, $f26 \n\t"
345 /* case1: In this case, row[1,3,5,7] are all zero */
346 /* col4: $f1: col[24,16,8,0]; $f3: col[56,48,40,32] */
347 IDCT_COL_CASE1($f1, $f1, $f3)
348 /* col5: $f5: col[25,17,9,1]; $f7: col[57,49,41,33] */
349 IDCT_COL_CASE1($f5, $f5, $f7)
350 /* col6: $f9: col[26,18,10,2]; $f11: col[58,50,42,34] */
351 IDCT_COL_CASE1($f9, $f9, $f11)
352 /* col7: $f13: col[27,19,11,3]; $f15: col[59,51,43,35] */
353 IDCT_COL_CASE1($f13, $f13, $f15)
357 /* case2: row[1,3,5,7] are not all zero */
359 "punpcklhw $f26, $f3, $f7 \n\t"
360 "punpckhhw $f27, $f3, $f7 \n\t"
361 "punpcklhw $f28, $f11, $f15 \n\t"
362 "punpckhhw $f29, $f11, $f15 \n\t"
363 "punpcklwd $f3, $f26, $f28 \n\t"
364 "punpckhwd $f7, $f26, $f28 \n\t"
365 "punpcklwd $f11, $f27, $f29 \n\t"
366 "punpckhwd $f15, $f27, $f29 \n\t"
368 /* col4: $f1: col[24,16,8,0]; $f3: col[56,48,40,32] */
369 IDCT_COL_CASE2($f1, $f3, $f1, $f3)
370 /* col5: $f5: col[25,17,9,1]; $f7: col[57,49,41,33] */
371 IDCT_COL_CASE2($f5, $f7, $f5, $f7)
372 /* col6: $f9: col[26,18,10,2]; $f11: col[58,50,42,34] */
373 IDCT_COL_CASE2($f9, $f11, $f9, $f11)
374 /* col7: $f13: col[27,19,11,3]; $f15: col[59,51,43,35] */
375 IDCT_COL_CASE2($f13, $f15, $f13, $f15)
379 "punpcklhw $f26, $f1, $f5 \n\t"
380 "punpckhhw $f27, $f1, $f5 \n\t"
381 "punpcklhw $f28, $f9, $f13 \n\t"
382 "punpckhhw $f29, $f9, $f13 \n\t"
383 "punpcklwd $f1, $f26, $f28 \n\t"
384 "punpckhwd $f5, $f26, $f28 \n\t"
385 "punpcklwd $f9, $f27, $f29 \n\t"
386 "punpckhwd $f13, $f27, $f29 \n\t"
388 "punpcklhw $f26, $f3, $f7 \n\t"
389 "punpckhhw $f27, $f3, $f7 \n\t"
390 "punpcklhw $f28, $f11, $f15 \n\t"
391 "punpckhhw $f29, $f11, $f15 \n\t"
392 "punpcklwd $f3, $f26, $f28 \n\t"
393 "punpckhwd $f7, $f26, $f28 \n\t"
394 "punpcklwd $f11, $f27, $f29 \n\t"
395 "punpckhwd $f15, $f27, $f29 \n\t"
397 "gssqc1 $f1, $f0, 0x00(%[block]) \n\t"
398 "gssqc1 $f5, $f4, 0x10(%[block]) \n\t"
399 "gssqc1 $f9, $f8, 0x20(%[block]) \n\t"
400 "gssqc1 $f13, $f12, 0x30(%[block]) \n\t"
401 "gssqc1 $f3, $f2, 0x40(%[block]) \n\t"
402 "gssqc1 $f7, $f6, 0x50(%[block]) \n\t"
403 "gssqc1 $f11, $f10, 0x60(%[block]) \n\t"
404 "gssqc1 $f15, $f14, 0x70(%[block]) \n\t"
406 : [block]"+&r"(block)
414 void ff_simple_idct_put_8_mmi(uint8_t *dest, ptrdiff_t line_size, int16_t *block)
416 ff_simple_idct_8_mmi(block);
417 ff_put_pixels_clamped_mmi(block, dest, line_size);
419 void ff_simple_idct_add_8_mmi(uint8_t *dest, ptrdiff_t line_size, int16_t *block)
421 ff_simple_idct_8_mmi(block);
422 ff_add_pixels_clamped_mmi(block, dest, line_size);