2 * XVID MPEG-4 VIDEO CODEC
3 * - MMX and XMM forward discrete cosine transform -
5 * Copyright(C) 2001 Peter Ross <pross@xvid.org>
7 * Originally provided by Intel at AP-922
8 * http://developer.intel.com/vtune/cbts/strmsimd/922down.htm
9 * (See more app notes at http://developer.intel.com/vtune/cbts/strmsimd/appnotes.htm)
10 * but in a limited edition.
11 * New macro implements a column part for precise iDCT
12 * The routine precision now satisfies IEEE standard 1180-1990.
14 * Copyright(C) 2000-2001 Peter Gubanov <peter@elecard.net.ru>
15 * Rounding trick Copyright(C) 2000 Michel Lespinasse <walken@zoy.org>
17 * http://www.elecard.com/peter/idct.html
18 * http://www.linuxvideo.org/mpeg2dec/
20 * These examples contain code fragments for first stage iDCT 8x8
21 * (for rows) and first stage DCT 8x8 (for columns)
23 * conversion to gcc syntax by Michael Niedermayer
25 * This file is part of Libav.
27 * Libav is free software; you can redistribute it and/or
28 * modify it under the terms of the GNU Lesser General Public
29 * License as published by the Free Software Foundation; either
30 * version 2.1 of the License, or (at your option) any later version.
32 * Libav is distributed in the hope that it will be useful,
33 * but WITHOUT ANY WARRANTY; without even the implied warranty of
34 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
35 * Lesser General Public License for more details.
37 * You should have received a copy of the GNU Lesser General Public License
38 * along with Libav; if not, write to the Free Software Foundation,
39 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
45 #include "libavcodec/avcodec.h"
46 #include "libavutil/mem.h"
53 //-----------------------------------------------------------------------------
54 // Various memory constants (trigonometric values or rounding values)
55 //-----------------------------------------------------------------------------
58 DECLARE_ALIGNED(8, static const int16_t, tg_1_16)[4*4] = {
59 13036,13036,13036,13036, // tg * (2<<16) + 0.5
60 27146,27146,27146,27146, // tg * (2<<16) + 0.5
61 -21746,-21746,-21746,-21746, // tg * (2<<16) + 0.5
62 23170,23170,23170,23170}; // cos * (2<<15) + 0.5
64 DECLARE_ALIGNED(8, static const int32_t, rounder_0)[2*8] = {
74 //-----------------------------------------------------------------------------
76 // The first stage iDCT 8x8 - inverse DCTs of rows
78 //-----------------------------------------------------------------------------
79 // The 8-point inverse DCT direct algorithm
80 //-----------------------------------------------------------------------------
82 // static const short w[32] = {
83 // FIX(cos_4_16), FIX(cos_2_16), FIX(cos_4_16), FIX(cos_6_16),
84 // FIX(cos_4_16), FIX(cos_6_16), -FIX(cos_4_16), -FIX(cos_2_16),
85 // FIX(cos_4_16), -FIX(cos_6_16), -FIX(cos_4_16), FIX(cos_2_16),
86 // FIX(cos_4_16), -FIX(cos_2_16), FIX(cos_4_16), -FIX(cos_6_16),
87 // FIX(cos_1_16), FIX(cos_3_16), FIX(cos_5_16), FIX(cos_7_16),
88 // FIX(cos_3_16), -FIX(cos_7_16), -FIX(cos_1_16), -FIX(cos_5_16),
89 // FIX(cos_5_16), -FIX(cos_1_16), FIX(cos_7_16), FIX(cos_3_16),
90 // FIX(cos_7_16), -FIX(cos_5_16), FIX(cos_3_16), -FIX(cos_1_16) };
92 // #define DCT_8_INV_ROW(x, y)
94 // int a0, a1, a2, a3, b0, b1, b2, b3;
96 // a0 =x[0]*w[0]+x[2]*w[1]+x[4]*w[2]+x[6]*w[3];
97 // a1 =x[0]*w[4]+x[2]*w[5]+x[4]*w[6]+x[6]*w[7];
98 // a2 = x[0] * w[ 8] + x[2] * w[ 9] + x[4] * w[10] + x[6] * w[11];
99 // a3 = x[0] * w[12] + x[2] * w[13] + x[4] * w[14] + x[6] * w[15];
100 // b0 = x[1] * w[16] + x[3] * w[17] + x[5] * w[18] + x[7] * w[19];
101 // b1 = x[1] * w[20] + x[3] * w[21] + x[5] * w[22] + x[7] * w[23];
102 // b2 = x[1] * w[24] + x[3] * w[25] + x[5] * w[26] + x[7] * w[27];
103 // b3 = x[1] * w[28] + x[3] * w[29] + x[5] * w[30] + x[7] * w[31];
105 // y[0] = SHIFT_ROUND ( a0 + b0 );
106 // y[1] = SHIFT_ROUND ( a1 + b1 );
107 // y[2] = SHIFT_ROUND ( a2 + b2 );
108 // y[3] = SHIFT_ROUND ( a3 + b3 );
109 // y[4] = SHIFT_ROUND ( a3 - b3 );
110 // y[5] = SHIFT_ROUND ( a2 - b2 );
111 // y[6] = SHIFT_ROUND ( a1 - b1 );
112 // y[7] = SHIFT_ROUND ( a0 - b0 );
115 //-----------------------------------------------------------------------------
117 // In this implementation the outputs of the iDCT-1D are multiplied
118 // for rows 0,4 - by cos_4_16,
119 // for rows 1,7 - by cos_1_16,
120 // for rows 2,6 - by cos_2_16,
121 // for rows 3,5 - by cos_3_16
122 // and are shifted to the left for better accuracy
124 // For the constants used,
125 // FIX(float_const) = (short) (float_const * (1<<15) + 0.5)
127 //-----------------------------------------------------------------------------
129 //-----------------------------------------------------------------------------
130 // Tables for mmx processors
131 //-----------------------------------------------------------------------------
133 // Table for rows 0,4 - constants are multiplied by cos_4_16
134 DECLARE_ALIGNED(8, static const int16_t, tab_i_04_mmx)[32*4] = {
135 16384,16384,16384,-16384, // movq-> w06 w04 w02 w00
136 21407,8867,8867,-21407, // w07 w05 w03 w01
137 16384,-16384,16384,16384, // w14 w12 w10 w08
138 -8867,21407,-21407,-8867, // w15 w13 w11 w09
139 22725,12873,19266,-22725, // w22 w20 w18 w16
140 19266,4520,-4520,-12873, // w23 w21 w19 w17
141 12873,4520,4520,19266, // w30 w28 w26 w24
142 -22725,19266,-12873,-22725, // w31 w29 w27 w25
143 // Table for rows 1,7 - constants are multiplied by cos_1_16
144 22725,22725,22725,-22725, // movq-> w06 w04 w02 w00
145 29692,12299,12299,-29692, // w07 w05 w03 w01
146 22725,-22725,22725,22725, // w14 w12 w10 w08
147 -12299,29692,-29692,-12299, // w15 w13 w11 w09
148 31521,17855,26722,-31521, // w22 w20 w18 w16
149 26722,6270,-6270,-17855, // w23 w21 w19 w17
150 17855,6270,6270,26722, // w30 w28 w26 w24
151 -31521,26722,-17855,-31521, // w31 w29 w27 w25
152 // Table for rows 2,6 - constants are multiplied by cos_2_16
153 21407,21407,21407,-21407, // movq-> w06 w04 w02 w00
154 27969,11585,11585,-27969, // w07 w05 w03 w01
155 21407,-21407,21407,21407, // w14 w12 w10 w08
156 -11585,27969,-27969,-11585, // w15 w13 w11 w09
157 29692,16819,25172,-29692, // w22 w20 w18 w16
158 25172,5906,-5906,-16819, // w23 w21 w19 w17
159 16819,5906,5906,25172, // w30 w28 w26 w24
160 -29692,25172,-16819,-29692, // w31 w29 w27 w25
161 // Table for rows 3,5 - constants are multiplied by cos_3_16
162 19266,19266,19266,-19266, // movq-> w06 w04 w02 w00
163 25172,10426,10426,-25172, // w07 w05 w03 w01
164 19266,-19266,19266,19266, // w14 w12 w10 w08
165 -10426,25172,-25172,-10426, // w15 w13 w11 w09
166 26722,15137,22654,-26722, // w22 w20 w18 w16
167 22654,5315,-5315,-15137, // w23 w21 w19 w17
168 15137,5315,5315,22654, // w30 w28 w26 w24
169 -26722,22654,-15137,-26722, // w31 w29 w27 w25
171 //-----------------------------------------------------------------------------
172 // Tables for xmm processors
173 //-----------------------------------------------------------------------------
175 // %3 for rows 0,4 - constants are multiplied by cos_4_16
176 DECLARE_ALIGNED(8, static const int16_t, tab_i_04_xmm)[32*4] = {
177 16384,21407,16384,8867, // movq-> w05 w04 w01 w00
178 16384,8867,-16384,-21407, // w07 w06 w03 w02
179 16384,-8867,16384,-21407, // w13 w12 w09 w08
180 -16384,21407,16384,-8867, // w15 w14 w11 w10
181 22725,19266,19266,-4520, // w21 w20 w17 w16
182 12873,4520,-22725,-12873, // w23 w22 w19 w18
183 12873,-22725,4520,-12873, // w29 w28 w25 w24
184 4520,19266,19266,-22725, // w31 w30 w27 w26
185 // %3 for rows 1,7 - constants are multiplied by cos_1_16
186 22725,29692,22725,12299, // movq-> w05 w04 w01 w00
187 22725,12299,-22725,-29692, // w07 w06 w03 w02
188 22725,-12299,22725,-29692, // w13 w12 w09 w08
189 -22725,29692,22725,-12299, // w15 w14 w11 w10
190 31521,26722,26722,-6270, // w21 w20 w17 w16
191 17855,6270,-31521,-17855, // w23 w22 w19 w18
192 17855,-31521,6270,-17855, // w29 w28 w25 w24
193 6270,26722,26722,-31521, // w31 w30 w27 w26
194 // %3 for rows 2,6 - constants are multiplied by cos_2_16
195 21407,27969,21407,11585, // movq-> w05 w04 w01 w00
196 21407,11585,-21407,-27969, // w07 w06 w03 w02
197 21407,-11585,21407,-27969, // w13 w12 w09 w08
198 -21407,27969,21407,-11585, // w15 w14 w11 w10
199 29692,25172,25172,-5906, // w21 w20 w17 w16
200 16819,5906,-29692,-16819, // w23 w22 w19 w18
201 16819,-29692,5906,-16819, // w29 w28 w25 w24
202 5906,25172,25172,-29692, // w31 w30 w27 w26
203 // %3 for rows 3,5 - constants are multiplied by cos_3_16
204 19266,25172,19266,10426, // movq-> w05 w04 w01 w00
205 19266,10426,-19266,-25172, // w07 w06 w03 w02
206 19266,-10426,19266,-25172, // w13 w12 w09 w08
207 -19266,25172,19266,-10426, // w15 w14 w11 w10
208 26722,22654,22654,-5315, // w21 w20 w17 w16
209 15137,5315,-26722,-15137, // w23 w22 w19 w18
210 15137,-26722,5315,-15137, // w29 w28 w25 w24
211 5315,22654,22654,-26722, // w31 w30 w27 w26
213 //=============================================================================
214 // Helper macros for the code
215 //=============================================================================
217 //-----------------------------------------------------------------------------
218 // DCT_8_INV_ROW_MMX( INP, OUT, TABLE, ROUNDER
219 //-----------------------------------------------------------------------------
221 #define DCT_8_INV_ROW_MMX(A1,A2,A3,A4)\
222 "movq " #A1 ",%%mm0 \n\t"/* 0 ; x3 x2 x1 x0*/\
223 "movq 8+" #A1 ",%%mm1 \n\t"/* 1 ; x7 x6 x5 x4*/\
224 "movq %%mm0,%%mm2 \n\t"/* 2 ; x3 x2 x1 x0*/\
225 "movq " #A3 ",%%mm3 \n\t"/* 3 ; w06 w04 w02 w00*/\
226 "punpcklwd %%mm1,%%mm0 \n\t"/* x5 x1 x4 x0*/\
227 "movq %%mm0,%%mm5 \n\t"/* 5 ; x5 x1 x4 x0*/\
228 "punpckldq %%mm0,%%mm0 \n\t"/* x4 x0 x4 x0*/\
229 "movq 8+" #A3 ",%%mm4 \n\t"/* 4 ; w07 w05 w03 w01*/\
230 "punpckhwd %%mm1,%%mm2 \n\t"/* 1 ; x7 x3 x6 x2*/\
231 "pmaddwd %%mm0,%%mm3 \n\t"/* x4*w06+x0*w04 x4*w02+x0*w00*/\
232 "movq %%mm2,%%mm6 \n\t"/* 6 ; x7 x3 x6 x2*/\
233 "movq 32+" #A3 ",%%mm1 \n\t"/* 1 ; w22 w20 w18 w16*/\
234 "punpckldq %%mm2,%%mm2 \n\t"/* x6 x2 x6 x2*/\
235 "pmaddwd %%mm2,%%mm4 \n\t"/* x6*w07+x2*w05 x6*w03+x2*w01*/\
236 "punpckhdq %%mm5,%%mm5 \n\t"/* x5 x1 x5 x1*/\
237 "pmaddwd 16+" #A3 ",%%mm0 \n\t"/* x4*w14+x0*w12 x4*w10+x0*w08*/\
238 "punpckhdq %%mm6,%%mm6 \n\t"/* x7 x3 x7 x3*/\
239 "movq 40+" #A3 ",%%mm7 \n\t"/* 7 ; w23 w21 w19 w17*/\
240 "pmaddwd %%mm5,%%mm1 \n\t"/* x5*w22+x1*w20 x5*w18+x1*w16*/\
241 "paddd " #A4 ",%%mm3 \n\t"/* +%4*/\
242 "pmaddwd %%mm6,%%mm7 \n\t"/* x7*w23+x3*w21 x7*w19+x3*w17*/\
243 "pmaddwd 24+" #A3 ",%%mm2 \n\t"/* x6*w15+x2*w13 x6*w11+x2*w09*/\
244 "paddd %%mm4,%%mm3 \n\t"/* 4 ; a1=sum(even1) a0=sum(even0)*/\
245 "pmaddwd 48+" #A3 ",%%mm5 \n\t"/* x5*w30+x1*w28 x5*w26+x1*w24*/\
246 "movq %%mm3,%%mm4 \n\t"/* 4 ; a1 a0*/\
247 "pmaddwd 56+" #A3 ",%%mm6 \n\t"/* x7*w31+x3*w29 x7*w27+x3*w25*/\
248 "paddd %%mm7,%%mm1 \n\t"/* 7 ; b1=sum(odd1) b0=sum(odd0)*/\
249 "paddd " #A4 ",%%mm0 \n\t"/* +%4*/\
250 "psubd %%mm1,%%mm3 \n\t"/* a1-b1 a0-b0*/\
251 "psrad $11,%%mm3 \n\t"/* y6=a1-b1 y7=a0-b0*/\
252 "paddd %%mm4,%%mm1 \n\t"/* 4 ; a1+b1 a0+b0*/\
253 "paddd %%mm2,%%mm0 \n\t"/* 2 ; a3=sum(even3) a2=sum(even2)*/\
254 "psrad $11,%%mm1 \n\t"/* y1=a1+b1 y0=a0+b0*/\
255 "paddd %%mm6,%%mm5 \n\t"/* 6 ; b3=sum(odd3) b2=sum(odd2)*/\
256 "movq %%mm0,%%mm4 \n\t"/* 4 ; a3 a2*/\
257 "paddd %%mm5,%%mm0 \n\t"/* a3+b3 a2+b2*/\
258 "psubd %%mm5,%%mm4 \n\t"/* 5 ; a3-b3 a2-b2*/\
259 "psrad $11,%%mm0 \n\t"/* y3=a3+b3 y2=a2+b2*/\
260 "psrad $11,%%mm4 \n\t"/* y4=a3-b3 y5=a2-b2*/\
261 "packssdw %%mm0,%%mm1 \n\t"/* 0 ; y3 y2 y1 y0*/\
262 "packssdw %%mm3,%%mm4 \n\t"/* 3 ; y6 y7 y4 y5*/\
263 "movq %%mm4,%%mm7 \n\t"/* 7 ; y6 y7 y4 y5*/\
264 "psrld $16,%%mm4 \n\t"/* 0 y6 0 y4*/\
265 "pslld $16,%%mm7 \n\t"/* y7 0 y5 0*/\
266 "movq %%mm1," #A2 " \n\t"/* 1 ; save y3 y2 y1 y0*/\
267 "por %%mm4,%%mm7 \n\t"/* 4 ; y7 y6 y5 y4*/\
268 "movq %%mm7,8 +" #A2 "\n\t"/* 7 ; save y7 y6 y5 y4*/\
271 //-----------------------------------------------------------------------------
272 // DCT_8_INV_ROW_XMM( INP, OUT, TABLE, ROUNDER
273 //-----------------------------------------------------------------------------
275 #define DCT_8_INV_ROW_XMM(A1,A2,A3,A4)\
276 "movq " #A1 ",%%mm0 \n\t"/* 0 ; x3 x2 x1 x0*/\
277 "movq 8+" #A1 ",%%mm1 \n\t"/* 1 ; x7 x6 x5 x4*/\
278 "movq %%mm0,%%mm2 \n\t"/* 2 ; x3 x2 x1 x0*/\
279 "movq " #A3 ",%%mm3 \n\t"/* 3 ; w05 w04 w01 w00*/\
280 "pshufw $0x88,%%mm0,%%mm0 \n\t"/* x2 x0 x2 x0*/\
281 "movq 8+" #A3 ",%%mm4 \n\t"/* 4 ; w07 w06 w03 w02*/\
282 "movq %%mm1,%%mm5 \n\t"/* 5 ; x7 x6 x5 x4*/\
283 "pmaddwd %%mm0,%%mm3 \n\t"/* x2*w05+x0*w04 x2*w01+x0*w00*/\
284 "movq 32+" #A3 ",%%mm6 \n\t"/* 6 ; w21 w20 w17 w16*/\
285 "pshufw $0x88,%%mm1,%%mm1 \n\t"/* x6 x4 x6 x4*/\
286 "pmaddwd %%mm1,%%mm4 \n\t"/* x6*w07+x4*w06 x6*w03+x4*w02*/\
287 "movq 40+" #A3 ",%%mm7 \n\t"/* 7 ; w23 w22 w19 w18*/\
288 "pshufw $0xdd,%%mm2,%%mm2 \n\t"/* x3 x1 x3 x1*/\
289 "pmaddwd %%mm2,%%mm6 \n\t"/* x3*w21+x1*w20 x3*w17+x1*w16*/\
290 "pshufw $0xdd,%%mm5,%%mm5 \n\t"/* x7 x5 x7 x5*/\
291 "pmaddwd %%mm5,%%mm7 \n\t"/* x7*w23+x5*w22 x7*w19+x5*w18*/\
292 "paddd " #A4 ",%%mm3 \n\t"/* +%4*/\
293 "pmaddwd 16+" #A3 ",%%mm0 \n\t"/* x2*w13+x0*w12 x2*w09+x0*w08*/\
294 "paddd %%mm4,%%mm3 \n\t"/* 4 ; a1=sum(even1) a0=sum(even0)*/\
295 "pmaddwd 24+" #A3 ",%%mm1 \n\t"/* x6*w15+x4*w14 x6*w11+x4*w10*/\
296 "movq %%mm3,%%mm4 \n\t"/* 4 ; a1 a0*/\
297 "pmaddwd 48+" #A3 ",%%mm2 \n\t"/* x3*w29+x1*w28 x3*w25+x1*w24*/\
298 "paddd %%mm7,%%mm6 \n\t"/* 7 ; b1=sum(odd1) b0=sum(odd0)*/\
299 "pmaddwd 56+" #A3 ",%%mm5 \n\t"/* x7*w31+x5*w30 x7*w27+x5*w26*/\
300 "paddd %%mm6,%%mm3 \n\t"/* a1+b1 a0+b0*/\
301 "paddd " #A4 ",%%mm0 \n\t"/* +%4*/\
302 "psrad $11,%%mm3 \n\t"/* y1=a1+b1 y0=a0+b0*/\
303 "paddd %%mm1,%%mm0 \n\t"/* 1 ; a3=sum(even3) a2=sum(even2)*/\
304 "psubd %%mm6,%%mm4 \n\t"/* 6 ; a1-b1 a0-b0*/\
305 "movq %%mm0,%%mm7 \n\t"/* 7 ; a3 a2*/\
306 "paddd %%mm5,%%mm2 \n\t"/* 5 ; b3=sum(odd3) b2=sum(odd2)*/\
307 "paddd %%mm2,%%mm0 \n\t"/* a3+b3 a2+b2*/\
308 "psrad $11,%%mm4 \n\t"/* y6=a1-b1 y7=a0-b0*/\
309 "psubd %%mm2,%%mm7 \n\t"/* 2 ; a3-b3 a2-b2*/\
310 "psrad $11,%%mm0 \n\t"/* y3=a3+b3 y2=a2+b2*/\
311 "psrad $11,%%mm7 \n\t"/* y4=a3-b3 y5=a2-b2*/\
312 "packssdw %%mm0,%%mm3 \n\t"/* 0 ; y3 y2 y1 y0*/\
313 "packssdw %%mm4,%%mm7 \n\t"/* 4 ; y6 y7 y4 y5*/\
314 "movq %%mm3, " #A2 " \n\t"/* 3 ; save y3 y2 y1 y0*/\
315 "pshufw $0xb1,%%mm7,%%mm7 \n\t"/* y7 y6 y5 y4*/\
316 "movq %%mm7,8 +" #A2 "\n\t"/* 7 ; save y7 y6 y5 y4*/\
319 //-----------------------------------------------------------------------------
321 // The first stage DCT 8x8 - forward DCTs of columns
323 // The %2puts are multiplied
324 // for rows 0,4 - on cos_4_16,
325 // for rows 1,7 - on cos_1_16,
326 // for rows 2,6 - on cos_2_16,
327 // for rows 3,5 - on cos_3_16
328 // and are shifted to the left for rise of accuracy
330 //-----------------------------------------------------------------------------
332 // The 8-point scaled forward DCT algorithm (26a8m)
334 //-----------------------------------------------------------------------------
336 // #define DCT_8_FRW_COL(x, y)
338 // short t0, t1, t2, t3, t4, t5, t6, t7;
339 // short tp03, tm03, tp12, tm12, tp65, tm65;
340 // short tp465, tm465, tp765, tm765;
342 // t0 = LEFT_SHIFT ( x[0] + x[7] );
343 // t1 = LEFT_SHIFT ( x[1] + x[6] );
344 // t2 = LEFT_SHIFT ( x[2] + x[5] );
345 // t3 = LEFT_SHIFT ( x[3] + x[4] );
346 // t4 = LEFT_SHIFT ( x[3] - x[4] );
347 // t5 = LEFT_SHIFT ( x[2] - x[5] );
348 // t6 = LEFT_SHIFT ( x[1] - x[6] );
349 // t7 = LEFT_SHIFT ( x[0] - x[7] );
356 // y[0] = tp03 + tp12;
357 // y[4] = tp03 - tp12;
359 // y[2] = tm03 + tm12 * tg_2_16;
360 // y[6] = tm03 * tg_2_16 - tm12;
362 // tp65 =(t6 +t5 )*cos_4_16;
363 // tm65 =(t6 -t5 )*cos_4_16;
365 // tp765 = t7 + tp65;
366 // tm765 = t7 - tp65;
367 // tp465 = t4 + tm65;
368 // tm465 = t4 - tm65;
370 // y[1] = tp765 + tp465 * tg_1_16;
371 // y[7] = tp765 * tg_1_16 - tp465;
372 // y[5] = tm765 * tg_3_16 + tm465;
373 // y[3] = tm765 - tm465 * tg_3_16;
376 //-----------------------------------------------------------------------------
378 //-----------------------------------------------------------------------------
379 // DCT_8_INV_COL_4 INP,OUT
380 //-----------------------------------------------------------------------------
382 #define DCT_8_INV_COL(A1,A2)\
383 "movq 2*8(%3),%%mm0\n\t"\
384 "movq 16*3+" #A1 ",%%mm3\n\t"\
385 "movq %%mm0,%%mm1 \n\t"/* tg_3_16*/\
386 "movq 16*5+" #A1 ",%%mm5\n\t"\
387 "pmulhw %%mm3,%%mm0 \n\t"/* x3*(tg_3_16-1)*/\
388 "movq (%3),%%mm4\n\t"\
389 "pmulhw %%mm5,%%mm1 \n\t"/* x5*(tg_3_16-1)*/\
390 "movq 16*7+" #A1 ",%%mm7\n\t"\
391 "movq %%mm4,%%mm2 \n\t"/* tg_1_16*/\
392 "movq 16*1+" #A1 ",%%mm6\n\t"\
393 "pmulhw %%mm7,%%mm4 \n\t"/* x7*tg_1_16*/\
394 "paddsw %%mm3,%%mm0 \n\t"/* x3*tg_3_16*/\
395 "pmulhw %%mm6,%%mm2 \n\t"/* x1*tg_1_16*/\
396 "paddsw %%mm3,%%mm1 \n\t"/* x3+x5*(tg_3_16-1)*/\
397 "psubsw %%mm5,%%mm0 \n\t"/* x3*tg_3_16-x5 = tm35*/\
398 "movq 3*8(%3),%%mm3\n\t"\
399 "paddsw %%mm5,%%mm1 \n\t"/* x3+x5*tg_3_16 = tp35*/\
400 "paddsw %%mm6,%%mm4 \n\t"/* x1+tg_1_16*x7 = tp17*/\
401 "psubsw %%mm7,%%mm2 \n\t"/* x1*tg_1_16-x7 = tm17*/\
402 "movq %%mm4,%%mm5 \n\t"/* tp17*/\
403 "movq %%mm2,%%mm6 \n\t"/* tm17*/\
404 "paddsw %%mm1,%%mm5 \n\t"/* tp17+tp35 = b0*/\
405 "psubsw %%mm0,%%mm6 \n\t"/* tm17-tm35 = b3*/\
406 "psubsw %%mm1,%%mm4 \n\t"/* tp17-tp35 = t1*/\
407 "paddsw %%mm0,%%mm2 \n\t"/* tm17+tm35 = t2*/\
408 "movq 1*8(%3),%%mm7\n\t"\
409 "movq %%mm4,%%mm1 \n\t"/* t1*/\
410 "movq %%mm5,3*16 +" #A2 "\n\t"/* save b0*/\
411 "paddsw %%mm2,%%mm1 \n\t"/* t1+t2*/\
412 "movq %%mm6,5*16 +" #A2 "\n\t"/* save b3*/\
413 "psubsw %%mm2,%%mm4 \n\t"/* t1-t2*/\
414 "movq 2*16+" #A1 ",%%mm5\n\t"\
415 "movq %%mm7,%%mm0 \n\t"/* tg_2_16*/\
416 "movq 6*16+" #A1 ",%%mm6\n\t"\
417 "pmulhw %%mm5,%%mm0 \n\t"/* x2*tg_2_16*/\
418 "pmulhw %%mm6,%%mm7 \n\t"/* x6*tg_2_16*/\
419 "pmulhw %%mm3,%%mm1 \n\t"/* ocos_4_16*(t1+t2) = b1/2*/\
420 "movq 0*16+" #A1 ",%%mm2\n\t"\
421 "pmulhw %%mm3,%%mm4 \n\t"/* ocos_4_16*(t1-t2) = b2/2*/\
422 "psubsw %%mm6,%%mm0 \n\t"/* t2*tg_2_16-x6 = tm26*/\
423 "movq %%mm2,%%mm3 \n\t"/* x0*/\
424 "movq 4*16+" #A1 ",%%mm6\n\t"\
425 "paddsw %%mm5,%%mm7 \n\t"/* x2+x6*tg_2_16 = tp26*/\
426 "paddsw %%mm6,%%mm2 \n\t"/* x0+x4 = tp04*/\
427 "psubsw %%mm6,%%mm3 \n\t"/* x0-x4 = tm04*/\
428 "movq %%mm2,%%mm5 \n\t"/* tp04*/\
429 "movq %%mm3,%%mm6 \n\t"/* tm04*/\
430 "psubsw %%mm7,%%mm2 \n\t"/* tp04-tp26 = a3*/\
431 "paddsw %%mm0,%%mm3 \n\t"/* tm04+tm26 = a1*/\
432 "paddsw %%mm1,%%mm1 \n\t"/* b1*/\
433 "paddsw %%mm4,%%mm4 \n\t"/* b2*/\
434 "paddsw %%mm7,%%mm5 \n\t"/* tp04+tp26 = a0*/\
435 "psubsw %%mm0,%%mm6 \n\t"/* tm04-tm26 = a2*/\
436 "movq %%mm3,%%mm7 \n\t"/* a1*/\
437 "movq %%mm6,%%mm0 \n\t"/* a2*/\
438 "paddsw %%mm1,%%mm3 \n\t"/* a1+b1*/\
439 "paddsw %%mm4,%%mm6 \n\t"/* a2+b2*/\
440 "psraw $6,%%mm3 \n\t"/* dst1*/\
441 "psubsw %%mm1,%%mm7 \n\t"/* a1-b1*/\
442 "psraw $6,%%mm6 \n\t"/* dst2*/\
443 "psubsw %%mm4,%%mm0 \n\t"/* a2-b2*/\
444 "movq 3*16+" #A2 ",%%mm1 \n\t"/* load b0*/\
445 "psraw $6,%%mm7 \n\t"/* dst6*/\
446 "movq %%mm5,%%mm4 \n\t"/* a0*/\
447 "psraw $6,%%mm0 \n\t"/* dst5*/\
448 "movq %%mm3,1*16+" #A2 "\n\t"\
449 "paddsw %%mm1,%%mm5 \n\t"/* a0+b0*/\
450 "movq %%mm6,2*16+" #A2 "\n\t"\
451 "psubsw %%mm1,%%mm4 \n\t"/* a0-b0*/\
452 "movq 5*16+" #A2 ",%%mm3 \n\t"/* load b3*/\
453 "psraw $6,%%mm5 \n\t"/* dst0*/\
454 "movq %%mm2,%%mm6 \n\t"/* a3*/\
455 "psraw $6,%%mm4 \n\t"/* dst7*/\
456 "movq %%mm0,5*16+" #A2 "\n\t"\
457 "paddsw %%mm3,%%mm2 \n\t"/* a3+b3*/\
458 "movq %%mm7,6*16+" #A2 "\n\t"\
459 "psubsw %%mm3,%%mm6 \n\t"/* a3-b3*/\
460 "movq %%mm5,0*16+" #A2 "\n\t"\
461 "psraw $6,%%mm2 \n\t"/* dst3*/\
462 "movq %%mm4,7*16+" #A2 "\n\t"\
463 "psraw $6,%%mm6 \n\t"/* dst4*/\
464 "movq %%mm2,3*16+" #A2 "\n\t"\
465 "movq %%mm6,4*16+" #A2 "\n\t"
467 //=============================================================================
469 //=============================================================================
471 //-----------------------------------------------------------------------------
472 // void idct_mmx(uint16_t block[64]);
473 //-----------------------------------------------------------------------------
476 void ff_xvid_idct_mmx(short *block)
480 DCT_8_INV_ROW_MMX(0*16(%0), 0*16(%0), 64*0(%2), 8*0(%1))
481 DCT_8_INV_ROW_MMX(1*16(%0), 1*16(%0), 64*1(%2), 8*1(%1))
482 DCT_8_INV_ROW_MMX(2*16(%0), 2*16(%0), 64*2(%2), 8*2(%1))
483 DCT_8_INV_ROW_MMX(3*16(%0), 3*16(%0), 64*3(%2), 8*3(%1))
484 DCT_8_INV_ROW_MMX(4*16(%0), 4*16(%0), 64*0(%2), 8*4(%1))
485 DCT_8_INV_ROW_MMX(5*16(%0), 5*16(%0), 64*3(%2), 8*5(%1))
486 DCT_8_INV_ROW_MMX(6*16(%0), 6*16(%0), 64*2(%2), 8*6(%1))
487 DCT_8_INV_ROW_MMX(7*16(%0), 7*16(%0), 64*1(%2), 8*7(%1))
489 //# Process the columns (4 at a time)
490 DCT_8_INV_COL(0(%0), 0(%0))
491 DCT_8_INV_COL(8(%0), 8(%0))
492 :: "r"(block), "r"(rounder_0), "r"(tab_i_04_mmx), "r"(tg_1_16));
495 void ff_xvid_idct_mmx_put(uint8_t *dest, int line_size, int16_t *block)
497 ff_xvid_idct_mmx(block);
498 ff_put_pixels_clamped_mmx(block, dest, line_size);
501 void ff_xvid_idct_mmx_add(uint8_t *dest, int line_size, int16_t *block)
503 ff_xvid_idct_mmx(block);
504 ff_add_pixels_clamped_mmx(block, dest, line_size);
507 #endif /* HAVE_MMX_INLINE */
509 #if HAVE_MMXEXT_INLINE
511 //-----------------------------------------------------------------------------
512 // void idct_xmm(uint16_t block[64]);
513 //-----------------------------------------------------------------------------
516 void ff_xvid_idct_mmxext(short *block)
520 DCT_8_INV_ROW_XMM(0*16(%0), 0*16(%0), 64*0(%2), 8*0(%1))
521 DCT_8_INV_ROW_XMM(1*16(%0), 1*16(%0), 64*1(%2), 8*1(%1))
522 DCT_8_INV_ROW_XMM(2*16(%0), 2*16(%0), 64*2(%2), 8*2(%1))
523 DCT_8_INV_ROW_XMM(3*16(%0), 3*16(%0), 64*3(%2), 8*3(%1))
524 DCT_8_INV_ROW_XMM(4*16(%0), 4*16(%0), 64*0(%2), 8*4(%1))
525 DCT_8_INV_ROW_XMM(5*16(%0), 5*16(%0), 64*3(%2), 8*5(%1))
526 DCT_8_INV_ROW_XMM(6*16(%0), 6*16(%0), 64*2(%2), 8*6(%1))
527 DCT_8_INV_ROW_XMM(7*16(%0), 7*16(%0), 64*1(%2), 8*7(%1))
529 //# Process the columns (4 at a time)
530 DCT_8_INV_COL(0(%0), 0(%0))
531 DCT_8_INV_COL(8(%0), 8(%0))
532 :: "r"(block), "r"(rounder_0), "r"(tab_i_04_xmm), "r"(tg_1_16));
535 void ff_xvid_idct_mmxext_put(uint8_t *dest, int line_size, int16_t *block)
537 ff_xvid_idct_mmxext(block);
538 ff_put_pixels_clamped_mmx(block, dest, line_size);
541 void ff_xvid_idct_mmxext_add(uint8_t *dest, int line_size, int16_t *block)
543 ff_xvid_idct_mmxext(block);
544 ff_add_pixels_clamped_mmx(block, dest, line_size);
547 #endif /* HAVE_MMXEXT_INLINE */