Mercurial > libavcodec.hg
comparison i386/idct_mmx_xvid.c @ 2868:666064f710d4 libavcodec
xvids mmx&mmx2 idcts
needed to decode xvid without some minor artefacts
under #ifdef CONFIG_GPL of course
author | michael |
---|---|
date | Sat, 10 Sep 2005 17:01:30 +0000 |
parents | |
children | f7f8a1c2a077 |
comparison
equal
deleted
inserted
replaced
2867:7c7edddaa835 | 2868:666064f710d4 |
---|---|
1 ///**************************************************************************** | |
2 // * | |
3 // * XVID MPEG-4 VIDEO CODEC | |
4 // * - MMX and XMM forward discrete cosine transform - | |
5 // * | |
6 // * Copyright(C) 2001 Peter Ross <pross@xvid.org> | |
7 // * | |
8 // * This program is free software; you can redistribute it and/or modify it | |
9 // * under the terms of the GNU General Public License as published by | |
10 // * the Free Software Foundation; either version 2 of the License, or | |
11 // * (at your option) any later version. | |
12 // * | |
13 // * This program is distributed in the hope that it will be useful, | |
14 // * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
15 // * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
16 // * GNU General Public License for more details. | |
17 // * | |
18 // * You should have received a copy of the GNU General Public License | |
19 // * along with this program; if not, write to the Free Software | |
20 // * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
21 // * | |
22 // * $Id$ | |
23 // * | |
24 // ***************************************************************************/ | |
25 | |
26 // **************************************************************************** | |
27 // | |
28 // Originally provided by Intel at AP-922 | |
29 // http://developer.intel.com/vtune/cbts/strmsimd/922down.htm | |
30 // (See more app notes at http://developer.intel.com/vtune/cbts/strmsimd/appnotes.htm) | |
31 // but in a limited edition. | |
32 // New macro implements a column part for precise iDCT | |
33 // The routine precision now satisfies IEEE standard 1180-1990. | |
34 // | |
35 // Copyright(C) 2000-2001 Peter Gubanov <peter@elecard.net.ru> | |
36 // Rounding trick Copyright(C) 2000 Michel Lespinasse <walken@zoy.org> | |
37 // | |
38 // http://www.elecard.com/peter/idct.html | |
39 // http://www.linuxvideo.org/mpeg2dec/ | |
40 // | |
41 // ***************************************************************************/ | |
42 // | |
43 // These examples contain code fragments for first stage iDCT 8x8 | |
44 // (for rows) and first stage DCT 8x8 (for columns) | |
45 // | |
46 | |
47 // conversion to gcc syntax by michael niedermayer | |
48 | |
49 | |
50 #include <inttypes.h> | |
51 #include "../avcodec.h" | |
52 | |
53 //============================================================================= | |
54 // Macros and other preprocessor constants | |
55 //============================================================================= | |
56 | |
57 #define BITS_INV_ACC 5 // 4 or 5 for IEEE | |
58 #define SHIFT_INV_ROW (16 - BITS_INV_ACC) //11 | |
59 #define SHIFT_INV_COL (1 + BITS_INV_ACC) //6 | |
60 #define RND_INV_ROW (1024 * (6 - BITS_INV_ACC)) | |
61 #define RND_INV_COL (16 * (BITS_INV_ACC - 3)) | |
62 #define RND_INV_CORR (RND_INV_COL - 1) | |
63 | |
64 #define BITS_FRW_ACC 3 // 2 or 3 for accuracy | |
65 #define SHIFT_FRW_COL BITS_FRW_ACC | |
66 #define SHIFT_FRW_ROW (BITS_FRW_ACC + 17) | |
67 #define RND_FRW_ROW (262144*(BITS_FRW_ACC - 1)) | |
68 | |
69 | |
70 //----------------------------------------------------------------------------- | |
71 // Various memory constants (trigonometric values or rounding values) | |
72 //----------------------------------------------------------------------------- | |
73 | |
74 | |
75 static const int16_t one_corr[4] attribute_used __attribute__ ((aligned(8))) = { | |
76 1,1,1,1}; | |
77 static const int32_t round_inv_row[2] attribute_used __attribute__ ((aligned(8))) = { | |
78 RND_INV_ROW, RND_INV_ROW}; | |
79 static const int16_t round_inv_col[4] attribute_used __attribute__ ((aligned(8))) = { | |
80 RND_INV_COL, RND_INV_COL, RND_INV_COL, RND_INV_COL}; | |
81 static const int16_t round_inv_corr[4] attribute_used __attribute__ ((aligned(8))) = { | |
82 RND_INV_CORR, RND_INV_CORR, RND_INV_CORR, RND_INV_CORR}; | |
83 static const int32_t round_frw_row[2] attribute_used __attribute__ ((aligned(8))) = { | |
84 RND_FRW_ROW, RND_FRW_ROW}; | |
85 static const int16_t tg_1_16[4] attribute_used __attribute__ ((aligned(8))) = { | |
86 13036,13036,13036,13036}; // tg * (2<<16) + 0.5 | |
87 static const int16_t tg_2_16[4] attribute_used __attribute__ ((aligned(8))) = { | |
88 27146,27146,27146,27146}; // tg * (2<<16) + 0.5 | |
89 static const int16_t tg_3_16[4] attribute_used __attribute__ ((aligned(8))) = { | |
90 -21746,-21746,-21746,-21746}; // tg * (2<<16) + 0.5 | |
91 static const int16_t cos_4_16[4] attribute_used __attribute__ ((aligned(8))) = { | |
92 -19195,-19195,-19195,-19195}; // cos * (2<<16) + 0.5 | |
93 static const int16_t ocos_4_16[4] attribute_used __attribute__ ((aligned(8))) = { | |
94 23170,23170,23170,23170}; // cos * (2<<15) + 0.5 | |
95 static const int16_t otg_3_16[4] attribute_used __attribute__ ((aligned(8))) = { | |
96 21895,21895,21895,21895}; // tg * (2<<16) + 0.5 | |
97 | |
98 static const int32_t rounder_0[2*8] attribute_used __attribute__ ((aligned(8))) = { | |
99 65536,65536, | |
100 3597,3597, | |
101 2260,2260, | |
102 1203,1203, | |
103 0,0, | |
104 120,120, | |
105 512,512, | |
106 512,512}; | |
107 | |
108 //----------------------------------------------------------------------------- | |
109 // | |
110 // The first stage iDCT 8x8 - inverse DCTs of rows | |
111 // | |
112 //----------------------------------------------------------------------------- | |
113 // The 8-point inverse DCT direct algorithm | |
114 //----------------------------------------------------------------------------- | |
115 // | |
116 // static const short w[32] = { | |
117 // FIX(cos_4_16), FIX(cos_2_16), FIX(cos_4_16), FIX(cos_6_16), | |
118 // FIX(cos_4_16), FIX(cos_6_16), -FIX(cos_4_16), -FIX(cos_2_16), | |
119 // FIX(cos_4_16), -FIX(cos_6_16), -FIX(cos_4_16), FIX(cos_2_16), | |
120 // FIX(cos_4_16), -FIX(cos_2_16), FIX(cos_4_16), -FIX(cos_6_16), | |
121 // FIX(cos_1_16), FIX(cos_3_16), FIX(cos_5_16), FIX(cos_7_16), | |
122 // FIX(cos_3_16), -FIX(cos_7_16), -FIX(cos_1_16), -FIX(cos_5_16), | |
123 // FIX(cos_5_16), -FIX(cos_1_16), FIX(cos_7_16), FIX(cos_3_16), | |
124 // FIX(cos_7_16), -FIX(cos_5_16), FIX(cos_3_16), -FIX(cos_1_16) }; | |
125 // | |
126 // #define DCT_8_INV_ROW(x, y) | |
127 // { | |
128 // int a0, a1, a2, a3, b0, b1, b2, b3; | |
129 // | |
130 // a0 =x[0]*w[0]+x[2]*w[1]+x[4]*w[2]+x[6]*w[3]; | |
131 // a1 =x[0]*w[4]+x[2]*w[5]+x[4]*w[6]+x[6]*w[7]; | |
132 // a2 = x[0] * w[ 8] + x[2] * w[ 9] + x[4] * w[10] + x[6] * w[11]; | |
133 // a3 = x[0] * w[12] + x[2] * w[13] + x[4] * w[14] + x[6] * w[15]; | |
134 // b0 = x[1] * w[16] + x[3] * w[17] + x[5] * w[18] + x[7] * w[19]; | |
135 // b1 = x[1] * w[20] + x[3] * w[21] + x[5] * w[22] + x[7] * w[23]; | |
136 // b2 = x[1] * w[24] + x[3] * w[25] + x[5] * w[26] + x[7] * w[27]; | |
137 // b3 = x[1] * w[28] + x[3] * w[29] + x[5] * w[30] + x[7] * w[31]; | |
138 // | |
139 // y[0] = SHIFT_ROUND ( a0 + b0 ); | |
140 // y[1] = SHIFT_ROUND ( a1 + b1 ); | |
141 // y[2] = SHIFT_ROUND ( a2 + b2 ); | |
142 // y[3] = SHIFT_ROUND ( a3 + b3 ); | |
143 // y[4] = SHIFT_ROUND ( a3 - b3 ); | |
144 // y[5] = SHIFT_ROUND ( a2 - b2 ); | |
145 // y[6] = SHIFT_ROUND ( a1 - b1 ); | |
146 // y[7] = SHIFT_ROUND ( a0 - b0 ); | |
147 // } | |
148 // | |
149 //----------------------------------------------------------------------------- | |
150 // | |
151 // In this implementation the outputs of the iDCT-1D are multiplied | |
152 // for rows 0,4 - by cos_4_16, | |
153 // for rows 1,7 - by cos_1_16, | |
154 // for rows 2,6 - by cos_2_16, | |
155 // for rows 3,5 - by cos_3_16 | |
156 // and are shifted to the left for better accuracy | |
157 // | |
158 // For the constants used, | |
159 // FIX(float_const) = (short) (float_const * (1<<15) + 0.5) | |
160 // | |
161 //----------------------------------------------------------------------------- | |
162 | |
163 //----------------------------------------------------------------------------- | |
164 // Tables for mmx processors | |
165 //----------------------------------------------------------------------------- | |
166 | |
167 // Table for rows 0,4 - constants are multiplied by cos_4_16 | |
168 static const int16_t tab_i_04_mmx[32*4] attribute_used __attribute__ ((aligned(8))) = { | |
169 16384,16384,16384,-16384, // movq-> w06 w04 w02 w00 | |
170 21407,8867,8867,-21407, // w07 w05 w03 w01 | |
171 16384,-16384,16384,16384, // w14 w12 w10 w08 | |
172 -8867,21407,-21407,-8867, // w15 w13 w11 w09 | |
173 22725,12873,19266,-22725, // w22 w20 w18 w16 | |
174 19266,4520,-4520,-12873, // w23 w21 w19 w17 | |
175 12873,4520,4520,19266, // w30 w28 w26 w24 | |
176 -22725,19266,-12873,-22725, // w31 w29 w27 w25 | |
177 // Table for rows 1,7 - constants are multiplied by cos_1_16 | |
178 22725,22725,22725,-22725, // movq-> w06 w04 w02 w00 | |
179 29692,12299,12299,-29692, // w07 w05 w03 w01 | |
180 22725,-22725,22725,22725, // w14 w12 w10 w08 | |
181 -12299,29692,-29692,-12299, // w15 w13 w11 w09 | |
182 31521,17855,26722,-31521, // w22 w20 w18 w16 | |
183 26722,6270,-6270,-17855, // w23 w21 w19 w17 | |
184 17855,6270,6270,26722, // w30 w28 w26 w24 | |
185 -31521,26722,-17855,-31521, // w31 w29 w27 w25 | |
186 // Table for rows 2,6 - constants are multiplied by cos_2_16 | |
187 21407,21407,21407,-21407, // movq-> w06 w04 w02 w00 | |
188 27969,11585,11585,-27969, // w07 w05 w03 w01 | |
189 21407,-21407,21407,21407, // w14 w12 w10 w08 | |
190 -11585,27969,-27969,-11585, // w15 w13 w11 w09 | |
191 29692,16819,25172,-29692, // w22 w20 w18 w16 | |
192 25172,5906,-5906,-16819, // w23 w21 w19 w17 | |
193 16819,5906,5906,25172, // w30 w28 w26 w24 | |
194 -29692,25172,-16819,-29692, // w31 w29 w27 w25 | |
195 // Table for rows 3,5 - constants are multiplied by cos_3_16 | |
196 19266,19266,19266,-19266, // movq-> w06 w04 w02 w00 | |
197 25172,10426,10426,-25172, // w07 w05 w03 w01 | |
198 19266,-19266,19266,19266, // w14 w12 w10 w08 | |
199 -10426,25172,-25172,-10426, // w15 w13 w11 w09 | |
200 26722,15137,22654,-26722, // w22 w20 w18 w16 | |
201 22654,5315,-5315,-15137, // w23 w21 w19 w17 | |
202 15137,5315,5315,22654, // w30 w28 w26 w24 | |
203 -26722,22654,-15137,-26722, // w31 w29 w27 w25 | |
204 }; | |
205 //----------------------------------------------------------------------------- | |
206 // Tables for xmm processors | |
207 //----------------------------------------------------------------------------- | |
208 | |
209 // %3 for rows 0,4 - constants are multiplied by cos_4_16 | |
210 static const int16_t tab_i_04_xmm[32*4] attribute_used __attribute__ ((aligned(8))) = { | |
211 16384,21407,16384,8867, // movq-> w05 w04 w01 w00 | |
212 16384,8867,-16384,-21407, // w07 w06 w03 w02 | |
213 16384,-8867,16384,-21407, // w13 w12 w09 w08 | |
214 -16384,21407,16384,-8867, // w15 w14 w11 w10 | |
215 22725,19266,19266,-4520, // w21 w20 w17 w16 | |
216 12873,4520,-22725,-12873, // w23 w22 w19 w18 | |
217 12873,-22725,4520,-12873, // w29 w28 w25 w24 | |
218 4520,19266,19266,-22725, // w31 w30 w27 w26 | |
219 // %3 for rows 1,7 - constants are multiplied by cos_1_16 | |
220 22725,29692,22725,12299, // movq-> w05 w04 w01 w00 | |
221 22725,12299,-22725,-29692, // w07 w06 w03 w02 | |
222 22725,-12299,22725,-29692, // w13 w12 w09 w08 | |
223 -22725,29692,22725,-12299, // w15 w14 w11 w10 | |
224 31521,26722,26722,-6270, // w21 w20 w17 w16 | |
225 17855,6270,-31521,-17855, // w23 w22 w19 w18 | |
226 17855,-31521,6270,-17855, // w29 w28 w25 w24 | |
227 6270,26722,26722,-31521, // w31 w30 w27 w26 | |
228 // %3 for rows 2,6 - constants are multiplied by cos_2_16 | |
229 21407,27969,21407,11585, // movq-> w05 w04 w01 w00 | |
230 21407,11585,-21407,-27969, // w07 w06 w03 w02 | |
231 21407,-11585,21407,-27969, // w13 w12 w09 w08 | |
232 -21407,27969,21407,-11585, // w15 w14 w11 w10 | |
233 29692,25172,25172,-5906, // w21 w20 w17 w16 | |
234 16819,5906,-29692,-16819, // w23 w22 w19 w18 | |
235 16819,-29692,5906,-16819, // w29 w28 w25 w24 | |
236 5906,25172,25172,-29692, // w31 w30 w27 w26 | |
237 // %3 for rows 3,5 - constants are multiplied by cos_3_16 | |
238 19266,25172,19266,10426, // movq-> w05 w04 w01 w00 | |
239 19266,10426,-19266,-25172, // w07 w06 w03 w02 | |
240 19266,-10426,19266,-25172, // w13 w12 w09 w08 | |
241 -19266,25172,19266,-10426, // w15 w14 w11 w10 | |
242 26722,22654,22654,-5315, // w21 w20 w17 w16 | |
243 15137,5315,-26722,-15137, // w23 w22 w19 w18 | |
244 15137,-26722,5315,-15137, // w29 w28 w25 w24 | |
245 5315,22654,22654,-26722, // w31 w30 w27 w26 | |
246 }; | |
247 //============================================================================= | |
248 // Helper macros for the code | |
249 //============================================================================= | |
250 | |
251 //----------------------------------------------------------------------------- | |
252 // DCT_8_INV_ROW_MMX( INP, OUT, TABLE, ROUNDER | |
253 //----------------------------------------------------------------------------- | |
254 | |
255 #define DCT_8_INV_ROW_MMX(A1,A2,A3,A4)\ | |
256 "movq " #A1 ",%%mm0 \n\t"/* 0 ; x3 x2 x1 x0*/\ | |
257 "movq 8+" #A1 ",%%mm1 \n\t"/* 1 ; x7 x6 x5 x4*/\ | |
258 "movq %%mm0,%%mm2 \n\t"/* 2 ; x3 x2 x1 x0*/\ | |
259 "movq " #A3 ",%%mm3 \n\t"/* 3 ; w06 w04 w02 w00*/\ | |
260 "punpcklwd %%mm1,%%mm0 \n\t"/* x5 x1 x4 x0*/\ | |
261 "movq %%mm0,%%mm5 \n\t"/* 5 ; x5 x1 x4 x0*/\ | |
262 "punpckldq %%mm0,%%mm0 \n\t"/* x4 x0 x4 x0*/\ | |
263 "movq 8+" #A3 ",%%mm4 \n\t"/* 4 ; w07 w05 w03 w01*/\ | |
264 "punpckhwd %%mm1,%%mm2 \n\t"/* 1 ; x7 x3 x6 x2*/\ | |
265 "pmaddwd %%mm0,%%mm3 \n\t"/* x4*w06+x0*w04 x4*w02+x0*w00*/\ | |
266 "movq %%mm2,%%mm6 \n\t"/* 6 ; x7 x3 x6 x2*/\ | |
267 "movq 32+" #A3 ",%%mm1 \n\t"/* 1 ; w22 w20 w18 w16*/\ | |
268 "punpckldq %%mm2,%%mm2 \n\t"/* x6 x2 x6 x2*/\ | |
269 "pmaddwd %%mm2,%%mm4 \n\t"/* x6*w07+x2*w05 x6*w03+x2*w01*/\ | |
270 "punpckhdq %%mm5,%%mm5 \n\t"/* x5 x1 x5 x1*/\ | |
271 "pmaddwd 16+" #A3 ",%%mm0 \n\t"/* x4*w14+x0*w12 x4*w10+x0*w08*/\ | |
272 "punpckhdq %%mm6,%%mm6 \n\t"/* x7 x3 x7 x3*/\ | |
273 "movq 40+" #A3 ",%%mm7 \n\t"/* 7 ; w23 w21 w19 w17*/\ | |
274 "pmaddwd %%mm5,%%mm1 \n\t"/* x5*w22+x1*w20 x5*w18+x1*w16*/\ | |
275 "paddd " #A4 ",%%mm3 \n\t"/* +%4*/\ | |
276 "pmaddwd %%mm6,%%mm7 \n\t"/* x7*w23+x3*w21 x7*w19+x3*w17*/\ | |
277 "pmaddwd 24+" #A3 ",%%mm2 \n\t"/* x6*w15+x2*w13 x6*w11+x2*w09*/\ | |
278 "paddd %%mm4,%%mm3 \n\t"/* 4 ; a1=sum(even1) a0=sum(even0)*/\ | |
279 "pmaddwd 48+" #A3 ",%%mm5 \n\t"/* x5*w30+x1*w28 x5*w26+x1*w24*/\ | |
280 "movq %%mm3,%%mm4 \n\t"/* 4 ; a1 a0*/\ | |
281 "pmaddwd 56+" #A3 ",%%mm6 \n\t"/* x7*w31+x3*w29 x7*w27+x3*w25*/\ | |
282 "paddd %%mm7,%%mm1 \n\t"/* 7 ; b1=sum(odd1) b0=sum(odd0)*/\ | |
283 "paddd " #A4 ",%%mm0 \n\t"/* +%4*/\ | |
284 "psubd %%mm1,%%mm3 \n\t"/* a1-b1 a0-b0*/\ | |
285 "psrad $11,%%mm3 \n\t"/* y6=a1-b1 y7=a0-b0*/\ | |
286 "paddd %%mm4,%%mm1 \n\t"/* 4 ; a1+b1 a0+b0*/\ | |
287 "paddd %%mm2,%%mm0 \n\t"/* 2 ; a3=sum(even3) a2=sum(even2)*/\ | |
288 "psrad $11,%%mm1 \n\t"/* y1=a1+b1 y0=a0+b0*/\ | |
289 "paddd %%mm6,%%mm5 \n\t"/* 6 ; b3=sum(odd3) b2=sum(odd2)*/\ | |
290 "movq %%mm0,%%mm4 \n\t"/* 4 ; a3 a2*/\ | |
291 "paddd %%mm5,%%mm0 \n\t"/* a3+b3 a2+b2*/\ | |
292 "psubd %%mm5,%%mm4 \n\t"/* 5 ; a3-b3 a2-b2*/\ | |
293 "psrad $11,%%mm0 \n\t"/* y3=a3+b3 y2=a2+b2*/\ | |
294 "psrad $11,%%mm4 \n\t"/* y4=a3-b3 y5=a2-b2*/\ | |
295 "packssdw %%mm0,%%mm1 \n\t"/* 0 ; y3 y2 y1 y0*/\ | |
296 "packssdw %%mm3,%%mm4 \n\t"/* 3 ; y6 y7 y4 y5*/\ | |
297 "movq %%mm4,%%mm7 \n\t"/* 7 ; y6 y7 y4 y5*/\ | |
298 "psrld $16,%%mm4 \n\t"/* 0 y6 0 y4*/\ | |
299 "pslld $16,%%mm7 \n\t"/* y7 0 y5 0*/\ | |
300 "movq %%mm1," #A2 " \n\t"/* 1 ; save y3 y2 y1 y0*/\ | |
301 "por %%mm4,%%mm7 \n\t"/* 4 ; y7 y6 y5 y4*/\ | |
302 "movq %%mm7,8 +" #A2 "\n\t"/* 7 ; save y7 y6 y5 y4*/\ | |
303 | |
304 | |
305 //----------------------------------------------------------------------------- | |
306 // DCT_8_INV_ROW_XMM( INP, OUT, TABLE, ROUNDER | |
307 //----------------------------------------------------------------------------- | |
308 | |
309 #define DCT_8_INV_ROW_XMM(A1,A2,A3,A4)\ | |
310 "movq " #A1 ",%%mm0 \n\t"/* 0 ; x3 x2 x1 x0*/\ | |
311 "movq 8+" #A1 ",%%mm1 \n\t"/* 1 ; x7 x6 x5 x4*/\ | |
312 "movq %%mm0,%%mm2 \n\t"/* 2 ; x3 x2 x1 x0*/\ | |
313 "movq " #A3 ",%%mm3 \n\t"/* 3 ; w05 w04 w01 w00*/\ | |
314 "pshufw $0b10001000,%%mm0,%%mm0 \n\t"/* x2 x0 x2 x0*/\ | |
315 "movq 8+" #A3 ",%%mm4 \n\t"/* 4 ; w07 w06 w03 w02*/\ | |
316 "movq %%mm1,%%mm5 \n\t"/* 5 ; x7 x6 x5 x4*/\ | |
317 "pmaddwd %%mm0,%%mm3 \n\t"/* x2*w05+x0*w04 x2*w01+x0*w00*/\ | |
318 "movq 32+" #A3 ",%%mm6 \n\t"/* 6 ; w21 w20 w17 w16*/\ | |
319 "pshufw $0b10001000,%%mm1,%%mm1 \n\t"/* x6 x4 x6 x4*/\ | |
320 "pmaddwd %%mm1,%%mm4 \n\t"/* x6*w07+x4*w06 x6*w03+x4*w02*/\ | |
321 "movq 40+" #A3 ",%%mm7 \n\t"/* 7 ; w23 w22 w19 w18*/\ | |
322 "pshufw $0b11011101,%%mm2,%%mm2 \n\t"/* x3 x1 x3 x1*/\ | |
323 "pmaddwd %%mm2,%%mm6 \n\t"/* x3*w21+x1*w20 x3*w17+x1*w16*/\ | |
324 "pshufw $0b11011101,%%mm5,%%mm5 \n\t"/* x7 x5 x7 x5*/\ | |
325 "pmaddwd %%mm5,%%mm7 \n\t"/* x7*w23+x5*w22 x7*w19+x5*w18*/\ | |
326 "paddd " #A4 ",%%mm3 \n\t"/* +%4*/\ | |
327 "pmaddwd 16+" #A3 ",%%mm0 \n\t"/* x2*w13+x0*w12 x2*w09+x0*w08*/\ | |
328 "paddd %%mm4,%%mm3 \n\t"/* 4 ; a1=sum(even1) a0=sum(even0)*/\ | |
329 "pmaddwd 24+" #A3 ",%%mm1 \n\t"/* x6*w15+x4*w14 x6*w11+x4*w10*/\ | |
330 "movq %%mm3,%%mm4 \n\t"/* 4 ; a1 a0*/\ | |
331 "pmaddwd 48+" #A3 ",%%mm2 \n\t"/* x3*w29+x1*w28 x3*w25+x1*w24*/\ | |
332 "paddd %%mm7,%%mm6 \n\t"/* 7 ; b1=sum(odd1) b0=sum(odd0)*/\ | |
333 "pmaddwd 56+" #A3 ",%%mm5 \n\t"/* x7*w31+x5*w30 x7*w27+x5*w26*/\ | |
334 "paddd %%mm6,%%mm3 \n\t"/* a1+b1 a0+b0*/\ | |
335 "paddd " #A4 ",%%mm0 \n\t"/* +%4*/\ | |
336 "psrad $11,%%mm3 \n\t"/* y1=a1+b1 y0=a0+b0*/\ | |
337 "paddd %%mm1,%%mm0 \n\t"/* 1 ; a3=sum(even3) a2=sum(even2)*/\ | |
338 "psubd %%mm6,%%mm4 \n\t"/* 6 ; a1-b1 a0-b0*/\ | |
339 "movq %%mm0,%%mm7 \n\t"/* 7 ; a3 a2*/\ | |
340 "paddd %%mm5,%%mm2 \n\t"/* 5 ; b3=sum(odd3) b2=sum(odd2)*/\ | |
341 "paddd %%mm2,%%mm0 \n\t"/* a3+b3 a2+b2*/\ | |
342 "psrad $11,%%mm4 \n\t"/* y6=a1-b1 y7=a0-b0*/\ | |
343 "psubd %%mm2,%%mm7 \n\t"/* 2 ; a3-b3 a2-b2*/\ | |
344 "psrad $11,%%mm0 \n\t"/* y3=a3+b3 y2=a2+b2*/\ | |
345 "psrad $11,%%mm7 \n\t"/* y4=a3-b3 y5=a2-b2*/\ | |
346 "packssdw %%mm0,%%mm3 \n\t"/* 0 ; y3 y2 y1 y0*/\ | |
347 "packssdw %%mm4,%%mm7 \n\t"/* 4 ; y6 y7 y4 y5*/\ | |
348 "movq %%mm3, " #A2 " \n\t"/* 3 ; save y3 y2 y1 y0*/\ | |
349 "pshufw $0b10110001,%%mm7,%%mm7 \n\t"/* y7 y6 y5 y4*/\ | |
350 "movq %%mm7,8 +" #A2 "\n\t"/* 7 ; save y7 y6 y5 y4*/\ | |
351 | |
352 | |
353 //----------------------------------------------------------------------------- | |
354 // | |
355 // The first stage DCT 8x8 - forward DCTs of columns | |
356 // | |
357 // The %2puts are multiplied | |
358 // for rows 0,4 - on cos_4_16, | |
359 // for rows 1,7 - on cos_1_16, | |
360 // for rows 2,6 - on cos_2_16, | |
361 // for rows 3,5 - on cos_3_16 | |
362 // and are shifted to the left for rise of accuracy | |
363 // | |
364 //----------------------------------------------------------------------------- | |
365 // | |
366 // The 8-point scaled forward DCT algorithm (26a8m) | |
367 // | |
368 //----------------------------------------------------------------------------- | |
369 // | |
370 // #define DCT_8_FRW_COL(x, y) | |
371 //{ | |
372 // short t0, t1, t2, t3, t4, t5, t6, t7; | |
373 // short tp03, tm03, tp12, tm12, tp65, tm65; | |
374 // short tp465, tm465, tp765, tm765; | |
375 // | |
376 // t0 = LEFT_SHIFT ( x[0] + x[7] ); | |
377 // t1 = LEFT_SHIFT ( x[1] + x[6] ); | |
378 // t2 = LEFT_SHIFT ( x[2] + x[5] ); | |
379 // t3 = LEFT_SHIFT ( x[3] + x[4] ); | |
380 // t4 = LEFT_SHIFT ( x[3] - x[4] ); | |
381 // t5 = LEFT_SHIFT ( x[2] - x[5] ); | |
382 // t6 = LEFT_SHIFT ( x[1] - x[6] ); | |
383 // t7 = LEFT_SHIFT ( x[0] - x[7] ); | |
384 // | |
385 // tp03 = t0 + t3; | |
386 // tm03 = t0 - t3; | |
387 // tp12 = t1 + t2; | |
388 // tm12 = t1 - t2; | |
389 // | |
390 // y[0] = tp03 + tp12; | |
391 // y[4] = tp03 - tp12; | |
392 // | |
393 // y[2] = tm03 + tm12 * tg_2_16; | |
394 // y[6] = tm03 * tg_2_16 - tm12; | |
395 // | |
396 // tp65 =(t6 +t5 )*cos_4_16; | |
397 // tm65 =(t6 -t5 )*cos_4_16; | |
398 // | |
399 // tp765 = t7 + tp65; | |
400 // tm765 = t7 - tp65; | |
401 // tp465 = t4 + tm65; | |
402 // tm465 = t4 - tm65; | |
403 // | |
404 // y[1] = tp765 + tp465 * tg_1_16; | |
405 // y[7] = tp765 * tg_1_16 - tp465; | |
406 // y[5] = tm765 * tg_3_16 + tm465; | |
407 // y[3] = tm765 - tm465 * tg_3_16; | |
408 //} | |
409 // | |
410 //----------------------------------------------------------------------------- | |
411 | |
412 //----------------------------------------------------------------------------- | |
413 // DCT_8_INV_COL_4 INP,OUT | |
414 //----------------------------------------------------------------------------- | |
415 | |
416 #define DCT_8_INV_COL(A1,A2)\ | |
417 "movq tg_3_16,%%mm0\n\t"\ | |
418 "movq 16*3+" #A1 ",%%mm3\n\t"\ | |
419 "movq %%mm0,%%mm1 \n\t"/* tg_3_16*/\ | |
420 "movq 16*5+" #A1 ",%%mm5\n\t"\ | |
421 "pmulhw %%mm3,%%mm0 \n\t"/* x3*(tg_3_16-1)*/\ | |
422 "movq tg_1_16,%%mm4\n\t"\ | |
423 "pmulhw %%mm5,%%mm1 \n\t"/* x5*(tg_3_16-1)*/\ | |
424 "movq 16*7+" #A1 ",%%mm7\n\t"\ | |
425 "movq %%mm4,%%mm2 \n\t"/* tg_1_16*/\ | |
426 "movq 16*1+" #A1 ",%%mm6\n\t"\ | |
427 "pmulhw %%mm7,%%mm4 \n\t"/* x7*tg_1_16*/\ | |
428 "paddsw %%mm3,%%mm0 \n\t"/* x3*tg_3_16*/\ | |
429 "pmulhw %%mm6,%%mm2 \n\t"/* x1*tg_1_16*/\ | |
430 "paddsw %%mm3,%%mm1 \n\t"/* x3+x5*(tg_3_16-1)*/\ | |
431 "psubsw %%mm5,%%mm0 \n\t"/* x3*tg_3_16-x5 = tm35*/\ | |
432 "movq ocos_4_16,%%mm3\n\t"\ | |
433 "paddsw %%mm5,%%mm1 \n\t"/* x3+x5*tg_3_16 = tp35*/\ | |
434 "paddsw %%mm6,%%mm4 \n\t"/* x1+tg_1_16*x7 = tp17*/\ | |
435 "psubsw %%mm7,%%mm2 \n\t"/* x1*tg_1_16-x7 = tm17*/\ | |
436 "movq %%mm4,%%mm5 \n\t"/* tp17*/\ | |
437 "movq %%mm2,%%mm6 \n\t"/* tm17*/\ | |
438 "paddsw %%mm1,%%mm5 \n\t"/* tp17+tp35 = b0*/\ | |
439 "psubsw %%mm0,%%mm6 \n\t"/* tm17-tm35 = b3*/\ | |
440 "psubsw %%mm1,%%mm4 \n\t"/* tp17-tp35 = t1*/\ | |
441 "paddsw %%mm0,%%mm2 \n\t"/* tm17+tm35 = t2*/\ | |
442 "movq tg_2_16,%%mm7\n\t"\ | |
443 "movq %%mm4,%%mm1 \n\t"/* t1*/\ | |
444 "movq %%mm5,3*16 +" #A2 "\n\t"/* save b0*/\ | |
445 "paddsw %%mm2,%%mm1 \n\t"/* t1+t2*/\ | |
446 "movq %%mm6,5*16 +" #A2 "\n\t"/* save b3*/\ | |
447 "psubsw %%mm2,%%mm4 \n\t"/* t1-t2*/\ | |
448 "movq 2*16+" #A1 ",%%mm5\n\t"\ | |
449 "movq %%mm7,%%mm0 \n\t"/* tg_2_16*/\ | |
450 "movq 6*16+" #A1 ",%%mm6\n\t"\ | |
451 "pmulhw %%mm5,%%mm0 \n\t"/* x2*tg_2_16*/\ | |
452 "pmulhw %%mm6,%%mm7 \n\t"/* x6*tg_2_16*/\ | |
453 "pmulhw %%mm3,%%mm1 \n\t"/* ocos_4_16*(t1+t2) = b1/2*/\ | |
454 "movq 0*16+" #A1 ",%%mm2\n\t"\ | |
455 "pmulhw %%mm3,%%mm4 \n\t"/* ocos_4_16*(t1-t2) = b2/2*/\ | |
456 "psubsw %%mm6,%%mm0 \n\t"/* t2*tg_2_16-x6 = tm26*/\ | |
457 "movq %%mm2,%%mm3 \n\t"/* x0*/\ | |
458 "movq 4*16+" #A1 ",%%mm6\n\t"\ | |
459 "paddsw %%mm5,%%mm7 \n\t"/* x2+x6*tg_2_16 = tp26*/\ | |
460 "paddsw %%mm6,%%mm2 \n\t"/* x0+x4 = tp04*/\ | |
461 "psubsw %%mm6,%%mm3 \n\t"/* x0-x4 = tm04*/\ | |
462 "movq %%mm2,%%mm5 \n\t"/* tp04*/\ | |
463 "movq %%mm3,%%mm6 \n\t"/* tm04*/\ | |
464 "psubsw %%mm7,%%mm2 \n\t"/* tp04-tp26 = a3*/\ | |
465 "paddsw %%mm0,%%mm3 \n\t"/* tm04+tm26 = a1*/\ | |
466 "paddsw %%mm1,%%mm1 \n\t"/* b1*/\ | |
467 "paddsw %%mm4,%%mm4 \n\t"/* b2*/\ | |
468 "paddsw %%mm7,%%mm5 \n\t"/* tp04+tp26 = a0*/\ | |
469 "psubsw %%mm0,%%mm6 \n\t"/* tm04-tm26 = a2*/\ | |
470 "movq %%mm3,%%mm7 \n\t"/* a1*/\ | |
471 "movq %%mm6,%%mm0 \n\t"/* a2*/\ | |
472 "paddsw %%mm1,%%mm3 \n\t"/* a1+b1*/\ | |
473 "paddsw %%mm4,%%mm6 \n\t"/* a2+b2*/\ | |
474 "psraw $6,%%mm3 \n\t"/* dst1*/\ | |
475 "psubsw %%mm1,%%mm7 \n\t"/* a1-b1*/\ | |
476 "psraw $6,%%mm6 \n\t"/* dst2*/\ | |
477 "psubsw %%mm4,%%mm0 \n\t"/* a2-b2*/\ | |
478 "movq 3*16+" #A2 ",%%mm1 \n\t"/* load b0*/\ | |
479 "psraw $6,%%mm7 \n\t"/* dst6*/\ | |
480 "movq %%mm5,%%mm4 \n\t"/* a0*/\ | |
481 "psraw $6,%%mm0 \n\t"/* dst5*/\ | |
482 "movq %%mm3,1*16+" #A2 "\n\t"\ | |
483 "paddsw %%mm1,%%mm5 \n\t"/* a0+b0*/\ | |
484 "movq %%mm6,2*16+" #A2 "\n\t"\ | |
485 "psubsw %%mm1,%%mm4 \n\t"/* a0-b0*/\ | |
486 "movq 5*16+" #A2 ",%%mm3 \n\t"/* load b3*/\ | |
487 "psraw $6,%%mm5 \n\t"/* dst0*/\ | |
488 "movq %%mm2,%%mm6 \n\t"/* a3*/\ | |
489 "psraw $6,%%mm4 \n\t"/* dst7*/\ | |
490 "movq %%mm0,5*16+" #A2 "\n\t"\ | |
491 "paddsw %%mm3,%%mm2 \n\t"/* a3+b3*/\ | |
492 "movq %%mm7,6*16+" #A2 "\n\t"\ | |
493 "psubsw %%mm3,%%mm6 \n\t"/* a3-b3*/\ | |
494 "movq %%mm5,0*16+" #A2 "\n\t"\ | |
495 "psraw $6,%%mm2 \n\t"/* dst3*/\ | |
496 "movq %%mm4,7*16+" #A2 "\n\t"\ | |
497 "psraw $6,%%mm6 \n\t"/* dst4*/\ | |
498 "movq %%mm2,3*16+" #A2 "\n\t"\ | |
499 "movq %%mm6,4*16+" #A2 "\n\t" | |
500 | |
501 //============================================================================= | |
502 // Code | |
503 //============================================================================= | |
504 | |
505 //----------------------------------------------------------------------------- | |
506 // void idct_mmx(uint16_t block[64]); | |
507 //----------------------------------------------------------------------------- | |
508 | |
509 | |
510 void ff_idct_xvid_mmx(short *block){ | |
511 asm volatile( | |
512 //# Process each row | |
513 DCT_8_INV_ROW_MMX(0*16(%0), 0*16(%0), 64*0(%2), 8*0(%1)) | |
514 DCT_8_INV_ROW_MMX(1*16(%0), 1*16(%0), 64*1(%2), 8*1(%1)) | |
515 DCT_8_INV_ROW_MMX(2*16(%0), 2*16(%0), 64*2(%2), 8*2(%1)) | |
516 DCT_8_INV_ROW_MMX(3*16(%0), 3*16(%0), 64*3(%2), 8*3(%1)) | |
517 DCT_8_INV_ROW_MMX(4*16(%0), 4*16(%0), 64*0(%2), 8*4(%1)) | |
518 DCT_8_INV_ROW_MMX(5*16(%0), 5*16(%0), 64*3(%2), 8*5(%1)) | |
519 DCT_8_INV_ROW_MMX(6*16(%0), 6*16(%0), 64*2(%2), 8*6(%1)) | |
520 DCT_8_INV_ROW_MMX(7*16(%0), 7*16(%0), 64*1(%2), 8*7(%1)) | |
521 | |
522 //# Process the columns (4 at a time) | |
523 DCT_8_INV_COL(0(%0), 0(%0)) | |
524 DCT_8_INV_COL(8(%0), 8(%0)) | |
525 :: "r"(block), "r"(rounder_0), "r"(tab_i_04_mmx)); | |
526 } | |
527 | |
528 //----------------------------------------------------------------------------- | |
529 // void idct_xmm(uint16_t block[64]); | |
530 //----------------------------------------------------------------------------- | |
531 | |
532 | |
533 void ff_idct_xvid_mmx2(short *block){ | |
534 asm volatile( | |
535 //# Process each row | |
536 DCT_8_INV_ROW_XMM(0*16(%0), 0*16(%0), 64*0(%2), 8*0(%1)) | |
537 DCT_8_INV_ROW_XMM(1*16(%0), 1*16(%0), 64*1(%2), 8*1(%1)) | |
538 DCT_8_INV_ROW_XMM(2*16(%0), 2*16(%0), 64*2(%2), 8*2(%1)) | |
539 DCT_8_INV_ROW_XMM(3*16(%0), 3*16(%0), 64*3(%2), 8*3(%1)) | |
540 DCT_8_INV_ROW_XMM(4*16(%0), 4*16(%0), 64*0(%2), 8*4(%1)) | |
541 DCT_8_INV_ROW_XMM(5*16(%0), 5*16(%0), 64*3(%2), 8*5(%1)) | |
542 DCT_8_INV_ROW_XMM(6*16(%0), 6*16(%0), 64*2(%2), 8*6(%1)) | |
543 DCT_8_INV_ROW_XMM(7*16(%0), 7*16(%0), 64*1(%2), 8*7(%1)) | |
544 | |
545 //# Process the columns (4 at a time) | |
546 DCT_8_INV_COL(0(%0), 0(%0)) | |
547 DCT_8_INV_COL(8(%0), 8(%0)) | |
548 :: "r"(block), "r"(rounder_0), "r"(tab_i_04_xmm)); | |
549 } | |
550 |