1
|
1 /*
|
|
2 * idct_mmx.c
|
|
3 * Copyright (C) 1999-2000 Aaron Holtzman <aholtzma@ess.engr.uvic.ca>
|
|
4 *
|
|
5 * This file is part of mpeg2dec, a free MPEG-2 video stream decoder.
|
|
6 *
|
|
7 * mpeg2dec is free software; you can redistribute it and/or modify
|
|
8 * it under the terms of the GNU General Public License as published by
|
|
9 * the Free Software Foundation; either version 2 of the License, or
|
|
10 * (at your option) any later version.
|
|
11 *
|
|
12 * mpeg2dec is distributed in the hope that it will be useful,
|
|
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
15 * GNU General Public License for more details.
|
|
16 *
|
|
17 * You should have received a copy of the GNU General Public License
|
|
18 * along with this program; if not, write to the Free Software
|
|
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
20 */
|
|
21
|
|
22 #include "config.h"
|
|
23
|
|
24 #ifdef ARCH_X86
|
|
25
|
|
26 #include <inttypes.h>
|
|
27
|
|
28 #include "mpeg2_internal.h"
|
|
29 #include "attributes.h"
|
|
30 #include "mmx.h"
|
|
31
|
|
32 #define ROW_SHIFT 11
|
|
33 #define COL_SHIFT 6
|
|
34
|
|
35 #define round(bias) ((int)(((bias)+0.5) * (1<<ROW_SHIFT)))
|
|
36 #define rounder(bias) {round (bias), round (bias)}
|
|
37
|
|
38
|
|
39 #if 0
|
|
40 // C row IDCT - its just here to document the MMXEXT and MMX versions
|
|
41 static inline void idct_row (int16_t * row, int offset,
|
|
42 int16_t * table, int32_t * rounder)
|
|
43 {
|
|
44 int C1, C2, C3, C4, C5, C6, C7;
|
|
45 int a0, a1, a2, a3, b0, b1, b2, b3;
|
|
46
|
|
47 row += offset;
|
|
48
|
|
49 C1 = table[1];
|
|
50 C2 = table[2];
|
|
51 C3 = table[3];
|
|
52 C4 = table[4];
|
|
53 C5 = table[5];
|
|
54 C6 = table[6];
|
|
55 C7 = table[7];
|
|
56
|
|
57 a0 = C4*row[0] + C2*row[2] + C4*row[4] + C6*row[6] + *rounder;
|
|
58 a1 = C4*row[0] + C6*row[2] - C4*row[4] - C2*row[6] + *rounder;
|
|
59 a2 = C4*row[0] - C6*row[2] - C4*row[4] + C2*row[6] + *rounder;
|
|
60 a3 = C4*row[0] - C2*row[2] + C4*row[4] - C6*row[6] + *rounder;
|
|
61
|
|
62 b0 = C1*row[1] + C3*row[3] + C5*row[5] + C7*row[7];
|
|
63 b1 = C3*row[1] - C7*row[3] - C1*row[5] - C5*row[7];
|
|
64 b2 = C5*row[1] - C1*row[3] + C7*row[5] + C3*row[7];
|
|
65 b3 = C7*row[1] - C5*row[3] + C3*row[5] - C1*row[7];
|
|
66
|
|
67 row[0] = (a0 + b0) >> ROW_SHIFT;
|
|
68 row[1] = (a1 + b1) >> ROW_SHIFT;
|
|
69 row[2] = (a2 + b2) >> ROW_SHIFT;
|
|
70 row[3] = (a3 + b3) >> ROW_SHIFT;
|
|
71 row[4] = (a3 - b3) >> ROW_SHIFT;
|
|
72 row[5] = (a2 - b2) >> ROW_SHIFT;
|
|
73 row[6] = (a1 - b1) >> ROW_SHIFT;
|
|
74 row[7] = (a0 - b0) >> ROW_SHIFT;
|
|
75 }
|
|
76 #endif
|
|
77
|
|
78
|
|
79 // MMXEXT row IDCT
|
|
80
|
|
81 #define mmxext_table(c1,c2,c3,c4,c5,c6,c7) { c4, c2, -c4, -c2, \
|
|
82 c4, c6, c4, c6, \
|
|
83 c1, c3, -c1, -c5, \
|
|
84 c5, c7, c3, -c7, \
|
|
85 c4, -c6, c4, -c6, \
|
|
86 -c4, c2, c4, -c2, \
|
|
87 c5, -c1, c3, -c1, \
|
|
88 c7, c3, c7, -c5 }
|
|
89
|
|
90 static inline void mmxext_row_head (int16_t * row, int offset, int16_t * table)
|
|
91 {
|
|
92 movq_m2r (*(row+offset), mm2); // mm2 = x6 x4 x2 x0
|
|
93
|
|
94 movq_m2r (*(row+offset+4), mm5); // mm5 = x7 x5 x3 x1
|
|
95 movq_r2r (mm2, mm0); // mm0 = x6 x4 x2 x0
|
|
96
|
|
97 movq_m2r (*table, mm3); // mm3 = -C2 -C4 C2 C4
|
|
98 movq_r2r (mm5, mm6); // mm6 = x7 x5 x3 x1
|
|
99
|
|
100 movq_m2r (*(table+4), mm4); // mm4 = C6 C4 C6 C4
|
|
101 pmaddwd_r2r (mm0, mm3); // mm3 = -C4*x4-C2*x6 C4*x0+C2*x2
|
|
102
|
|
103 pshufw_r2r (mm2, mm2, 0x4e); // mm2 = x2 x0 x6 x4
|
|
104 }
|
|
105
|
|
106 static inline void mmxext_row (int16_t * table, int32_t * rounder)
|
|
107 {
|
|
108 movq_m2r (*(table+8), mm1); // mm1 = -C5 -C1 C3 C1
|
|
109 pmaddwd_r2r (mm2, mm4); // mm4 = C4*x0+C6*x2 C4*x4+C6*x6
|
|
110
|
|
111 pmaddwd_m2r (*(table+16), mm0); // mm0 = C4*x4-C6*x6 C4*x0-C6*x2
|
|
112 pshufw_r2r (mm6, mm6, 0x4e); // mm6 = x3 x1 x7 x5
|
|
113
|
|
114 movq_m2r (*(table+12), mm7); // mm7 = -C7 C3 C7 C5
|
|
115 pmaddwd_r2r (mm5, mm1); // mm1 = -C1*x5-C5*x7 C1*x1+C3*x3
|
|
116
|
|
117 paddd_m2r (*rounder, mm3); // mm3 += rounder
|
|
118 pmaddwd_r2r (mm6, mm7); // mm7 = C3*x1-C7*x3 C5*x5+C7*x7
|
|
119
|
|
120 pmaddwd_m2r (*(table+20), mm2); // mm2 = C4*x0-C2*x2 -C4*x4+C2*x6
|
|
121 paddd_r2r (mm4, mm3); // mm3 = a1 a0 + rounder
|
|
122
|
|
123 pmaddwd_m2r (*(table+24), mm5); // mm5 = C3*x5-C1*x7 C5*x1-C1*x3
|
|
124 movq_r2r (mm3, mm4); // mm4 = a1 a0 + rounder
|
|
125
|
|
126 pmaddwd_m2r (*(table+28), mm6); // mm6 = C7*x1-C5*x3 C7*x5+C3*x7
|
|
127 paddd_r2r (mm7, mm1); // mm1 = b1 b0
|
|
128
|
|
129 paddd_m2r (*rounder, mm0); // mm0 += rounder
|
|
130 psubd_r2r (mm1, mm3); // mm3 = a1-b1 a0-b0 + rounder
|
|
131
|
|
132 psrad_i2r (ROW_SHIFT, mm3); // mm3 = y6 y7
|
|
133 paddd_r2r (mm4, mm1); // mm1 = a1+b1 a0+b0 + rounder
|
|
134
|
|
135 paddd_r2r (mm2, mm0); // mm0 = a3 a2 + rounder
|
|
136 psrad_i2r (ROW_SHIFT, mm1); // mm1 = y1 y0
|
|
137
|
|
138 paddd_r2r (mm6, mm5); // mm5 = b3 b2
|
|
139 movq_r2r (mm0, mm4); // mm4 = a3 a2 + rounder
|
|
140
|
|
141 paddd_r2r (mm5, mm0); // mm0 = a3+b3 a2+b2 + rounder
|
|
142 psubd_r2r (mm5, mm4); // mm4 = a3-b3 a2-b2 + rounder
|
|
143 }
|
|
144
|
|
145 static inline void mmxext_row_tail (int16_t * row, int store)
|
|
146 {
|
|
147 psrad_i2r (ROW_SHIFT, mm0); // mm0 = y3 y2
|
|
148
|
|
149 psrad_i2r (ROW_SHIFT, mm4); // mm4 = y4 y5
|
|
150
|
|
151 packssdw_r2r (mm0, mm1); // mm1 = y3 y2 y1 y0
|
|
152
|
|
153 packssdw_r2r (mm3, mm4); // mm4 = y6 y7 y4 y5
|
|
154
|
|
155 movq_r2m (mm1, *(row+store)); // save y3 y2 y1 y0
|
|
156 pshufw_r2r (mm4, mm4, 0xb1); // mm4 = y7 y6 y5 y4
|
|
157
|
|
158 // slot
|
|
159
|
|
160 movq_r2m (mm4, *(row+store+4)); // save y7 y6 y5 y4
|
|
161 }
|
|
162
|
|
163 static inline void mmxext_row_mid (int16_t * row, int store,
|
|
164 int offset, int16_t * table)
|
|
165 {
|
|
166 movq_m2r (*(row+offset), mm2); // mm2 = x6 x4 x2 x0
|
|
167 psrad_i2r (ROW_SHIFT, mm0); // mm0 = y3 y2
|
|
168
|
|
169 movq_m2r (*(row+offset+4), mm5); // mm5 = x7 x5 x3 x1
|
|
170 psrad_i2r (ROW_SHIFT, mm4); // mm4 = y4 y5
|
|
171
|
|
172 packssdw_r2r (mm0, mm1); // mm1 = y3 y2 y1 y0
|
|
173 movq_r2r (mm5, mm6); // mm6 = x7 x5 x3 x1
|
|
174
|
|
175 packssdw_r2r (mm3, mm4); // mm4 = y6 y7 y4 y5
|
|
176 movq_r2r (mm2, mm0); // mm0 = x6 x4 x2 x0
|
|
177
|
|
178 movq_r2m (mm1, *(row+store)); // save y3 y2 y1 y0
|
|
179 pshufw_r2r (mm4, mm4, 0xb1); // mm4 = y7 y6 y5 y4
|
|
180
|
|
181 movq_m2r (*table, mm3); // mm3 = -C2 -C4 C2 C4
|
|
182 movq_r2m (mm4, *(row+store+4)); // save y7 y6 y5 y4
|
|
183
|
|
184 pmaddwd_r2r (mm0, mm3); // mm3 = -C4*x4-C2*x6 C4*x0+C2*x2
|
|
185
|
|
186 movq_m2r (*(table+4), mm4); // mm4 = C6 C4 C6 C4
|
|
187 pshufw_r2r (mm2, mm2, 0x4e); // mm2 = x2 x0 x6 x4
|
|
188 }
|
|
189
|
|
190
|
|
191 // MMX row IDCT
|
|
192
|
|
193 #define mmx_table(c1,c2,c3,c4,c5,c6,c7) { c4, c2, c4, c6, \
|
|
194 c4, c6, -c4, -c2, \
|
|
195 c1, c3, c3, -c7, \
|
|
196 c5, c7, -c1, -c5, \
|
|
197 c4, -c6, c4, -c2, \
|
|
198 -c4, c2, c4, -c6, \
|
|
199 c5, -c1, c7, -c5, \
|
|
200 c7, c3, c3, -c1 }
|
|
201
|
|
202 static inline void mmx_row_head (int16_t * row, int offset, int16_t * table)
|
|
203 {
|
|
204 movq_m2r (*(row+offset), mm2); // mm2 = x6 x4 x2 x0
|
|
205
|
|
206 movq_m2r (*(row+offset+4), mm5); // mm5 = x7 x5 x3 x1
|
|
207 movq_r2r (mm2, mm0); // mm0 = x6 x4 x2 x0
|
|
208
|
|
209 movq_m2r (*table, mm3); // mm3 = C6 C4 C2 C4
|
|
210 movq_r2r (mm5, mm6); // mm6 = x7 x5 x3 x1
|
|
211
|
|
212 punpckldq_r2r (mm0, mm0); // mm0 = x2 x0 x2 x0
|
|
213
|
|
214 movq_m2r (*(table+4), mm4); // mm4 = -C2 -C4 C6 C4
|
|
215 pmaddwd_r2r (mm0, mm3); // mm3 = C4*x0+C6*x2 C4*x0+C2*x2
|
|
216
|
|
217 movq_m2r (*(table+8), mm1); // mm1 = -C7 C3 C3 C1
|
|
218 punpckhdq_r2r (mm2, mm2); // mm2 = x6 x4 x6 x4
|
|
219 }
|
|
220
|
|
221 static inline void mmx_row (int16_t * table, int32_t * rounder)
|
|
222 {
|
|
223 pmaddwd_r2r (mm2, mm4); // mm4 = -C4*x4-C2*x6 C4*x4+C6*x6
|
|
224 punpckldq_r2r (mm5, mm5); // mm5 = x3 x1 x3 x1
|
|
225
|
|
226 pmaddwd_m2r (*(table+16), mm0); // mm0 = C4*x0-C2*x2 C4*x0-C6*x2
|
|
227 punpckhdq_r2r (mm6, mm6); // mm6 = x7 x5 x7 x5
|
|
228
|
|
229 movq_m2r (*(table+12), mm7); // mm7 = -C5 -C1 C7 C5
|
|
230 pmaddwd_r2r (mm5, mm1); // mm1 = C3*x1-C7*x3 C1*x1+C3*x3
|
|
231
|
|
232 paddd_m2r (*rounder, mm3); // mm3 += rounder
|
|
233 pmaddwd_r2r (mm6, mm7); // mm7 = -C1*x5-C5*x7 C5*x5+C7*x7
|
|
234
|
|
235 pmaddwd_m2r (*(table+20), mm2); // mm2 = C4*x4-C6*x6 -C4*x4+C2*x6
|
|
236 paddd_r2r (mm4, mm3); // mm3 = a1 a0 + rounder
|
|
237
|
|
238 pmaddwd_m2r (*(table+24), mm5); // mm5 = C7*x1-C5*x3 C5*x1-C1*x3
|
|
239 movq_r2r (mm3, mm4); // mm4 = a1 a0 + rounder
|
|
240
|
|
241 pmaddwd_m2r (*(table+28), mm6); // mm6 = C3*x5-C1*x7 C7*x5+C3*x7
|
|
242 paddd_r2r (mm7, mm1); // mm1 = b1 b0
|
|
243
|
|
244 paddd_m2r (*rounder, mm0); // mm0 += rounder
|
|
245 psubd_r2r (mm1, mm3); // mm3 = a1-b1 a0-b0 + rounder
|
|
246
|
|
247 psrad_i2r (ROW_SHIFT, mm3); // mm3 = y6 y7
|
|
248 paddd_r2r (mm4, mm1); // mm1 = a1+b1 a0+b0 + rounder
|
|
249
|
|
250 paddd_r2r (mm2, mm0); // mm0 = a3 a2 + rounder
|
|
251 psrad_i2r (ROW_SHIFT, mm1); // mm1 = y1 y0
|
|
252
|
|
253 paddd_r2r (mm6, mm5); // mm5 = b3 b2
|
|
254 movq_r2r (mm0, mm7); // mm7 = a3 a2 + rounder
|
|
255
|
|
256 paddd_r2r (mm5, mm0); // mm0 = a3+b3 a2+b2 + rounder
|
|
257 psubd_r2r (mm5, mm7); // mm7 = a3-b3 a2-b2 + rounder
|
|
258 }
|
|
259
|
|
260 static inline void mmx_row_tail (int16_t * row, int store)
|
|
261 {
|
|
262 psrad_i2r (ROW_SHIFT, mm0); // mm0 = y3 y2
|
|
263
|
|
264 psrad_i2r (ROW_SHIFT, mm7); // mm7 = y4 y5
|
|
265
|
|
266 packssdw_r2r (mm0, mm1); // mm1 = y3 y2 y1 y0
|
|
267
|
|
268 packssdw_r2r (mm3, mm7); // mm7 = y6 y7 y4 y5
|
|
269
|
|
270 movq_r2m (mm1, *(row+store)); // save y3 y2 y1 y0
|
|
271 movq_r2r (mm7, mm4); // mm4 = y6 y7 y4 y5
|
|
272
|
|
273 pslld_i2r (16, mm7); // mm7 = y7 0 y5 0
|
|
274
|
|
275 psrld_i2r (16, mm4); // mm4 = 0 y6 0 y4
|
|
276
|
|
277 por_r2r (mm4, mm7); // mm7 = y7 y6 y5 y4
|
|
278
|
|
279 // slot
|
|
280
|
|
281 movq_r2m (mm7, *(row+store+4)); // save y7 y6 y5 y4
|
|
282 }
|
|
283
|
|
284 static inline void mmx_row_mid (int16_t * row, int store,
|
|
285 int offset, int16_t * table)
|
|
286 {
|
|
287 movq_m2r (*(row+offset), mm2); // mm2 = x6 x4 x2 x0
|
|
288 psrad_i2r (ROW_SHIFT, mm0); // mm0 = y3 y2
|
|
289
|
|
290 movq_m2r (*(row+offset+4), mm5); // mm5 = x7 x5 x3 x1
|
|
291 psrad_i2r (ROW_SHIFT, mm7); // mm7 = y4 y5
|
|
292
|
|
293 packssdw_r2r (mm0, mm1); // mm1 = y3 y2 y1 y0
|
|
294 movq_r2r (mm5, mm6); // mm6 = x7 x5 x3 x1
|
|
295
|
|
296 packssdw_r2r (mm3, mm7); // mm7 = y6 y7 y4 y5
|
|
297 movq_r2r (mm2, mm0); // mm0 = x6 x4 x2 x0
|
|
298
|
|
299 movq_r2m (mm1, *(row+store)); // save y3 y2 y1 y0
|
|
300 movq_r2r (mm7, mm1); // mm1 = y6 y7 y4 y5
|
|
301
|
|
302 punpckldq_r2r (mm0, mm0); // mm0 = x2 x0 x2 x0
|
|
303 psrld_i2r (16, mm7); // mm7 = 0 y6 0 y4
|
|
304
|
|
305 movq_m2r (*table, mm3); // mm3 = C6 C4 C2 C4
|
|
306 pslld_i2r (16, mm1); // mm1 = y7 0 y5 0
|
|
307
|
|
308 movq_m2r (*(table+4), mm4); // mm4 = -C2 -C4 C6 C4
|
|
309 por_r2r (mm1, mm7); // mm7 = y7 y6 y5 y4
|
|
310
|
|
311 movq_m2r (*(table+8), mm1); // mm1 = -C7 C3 C3 C1
|
|
312 punpckhdq_r2r (mm2, mm2); // mm2 = x6 x4 x6 x4
|
|
313
|
|
314 movq_r2m (mm7, *(row+store+4)); // save y7 y6 y5 y4
|
|
315 pmaddwd_r2r (mm0, mm3); // mm3 = C4*x0+C6*x2 C4*x0+C2*x2
|
|
316 }
|
|
317
|
|
318
|
|
319 #if 0
|
|
320 // C column IDCT - its just here to document the MMXEXT and MMX versions
|
|
321 static inline void idct_col (int16_t * col, int offset)
|
|
322 {
|
|
323 // multiplication - as implemented on mmx
|
|
324 #define F(c,x) (((c) * (x)) >> 16)
|
|
325
|
|
326 // saturation - it helps us handle torture test cases
|
|
327 #define S(x) (((x)>32767) ? 32767 : ((x)<-32768) ? -32768 : (x))
|
|
328
|
|
329 int16_t x0, x1, x2, x3, x4, x5, x6, x7;
|
|
330 int16_t y0, y1, y2, y3, y4, y5, y6, y7;
|
|
331 int16_t a0, a1, a2, a3, b0, b1, b2, b3;
|
|
332 int16_t u04, v04, u26, v26, u17, v17, u35, v35, u12, v12;
|
|
333
|
|
334 col += offset;
|
|
335
|
|
336 x0 = col[0*8];
|
|
337 x1 = col[1*8];
|
|
338 x2 = col[2*8];
|
|
339 x3 = col[3*8];
|
|
340 x4 = col[4*8];
|
|
341 x5 = col[5*8];
|
|
342 x6 = col[6*8];
|
|
343 x7 = col[7*8];
|
|
344
|
|
345 u04 = S (x0 + x4);
|
|
346 v04 = S (x0 - x4);
|
|
347 u26 = S (F (T2, x6) + x2); // -0.5
|
|
348 v26 = S (F (T2, x2) - x6); // -0.5
|
|
349
|
|
350 a0 = S (u04 + u26);
|
|
351 a1 = S (v04 + v26);
|
|
352 a2 = S (v04 - v26);
|
|
353 a3 = S (u04 - u26);
|
|
354
|
|
355 u17 = S (F (T1, x7) + x1); // -0.5
|
|
356 v17 = S (F (T1, x1) - x7); // -0.5
|
|
357 u35 = S (F (T3, x5) + x3); // -0.5
|
|
358 v35 = S (F (T3, x3) - x5); // -0.5
|
|
359
|
|
360 b0 = S (u17 + u35);
|
|
361 b3 = S (v17 - v35);
|
|
362 u12 = S (u17 - u35);
|
|
363 v12 = S (v17 + v35);
|
|
364 u12 = S (2 * F (C4, u12)); // -0.5
|
|
365 v12 = S (2 * F (C4, v12)); // -0.5
|
|
366 b1 = S (u12 + v12);
|
|
367 b2 = S (u12 - v12);
|
|
368
|
|
369 y0 = S (a0 + b0) >> COL_SHIFT;
|
|
370 y1 = S (a1 + b1) >> COL_SHIFT;
|
|
371 y2 = S (a2 + b2) >> COL_SHIFT;
|
|
372 y3 = S (a3 + b3) >> COL_SHIFT;
|
|
373
|
|
374 y4 = S (a3 - b3) >> COL_SHIFT;
|
|
375 y5 = S (a2 - b2) >> COL_SHIFT;
|
|
376 y6 = S (a1 - b1) >> COL_SHIFT;
|
|
377 y7 = S (a0 - b0) >> COL_SHIFT;
|
|
378
|
|
379 col[0*8] = y0;
|
|
380 col[1*8] = y1;
|
|
381 col[2*8] = y2;
|
|
382 col[3*8] = y3;
|
|
383 col[4*8] = y4;
|
|
384 col[5*8] = y5;
|
|
385 col[6*8] = y6;
|
|
386 col[7*8] = y7;
|
|
387 }
|
|
388 #endif
|
|
389
|
|
390
|
|
391 // MMX column IDCT
|
|
392 static inline void idct_col (int16_t * col, int offset)
|
|
393 {
|
|
394 #define T1 13036
|
|
395 #define T2 27146
|
|
396 #define T3 43790
|
|
397 #define C4 23170
|
|
398
|
|
399 static short _T1[] ATTR_ALIGN(8) = {T1,T1,T1,T1};
|
|
400 static short _T2[] ATTR_ALIGN(8) = {T2,T2,T2,T2};
|
|
401 static short _T3[] ATTR_ALIGN(8) = {T3,T3,T3,T3};
|
|
402 static short _C4[] ATTR_ALIGN(8) = {C4,C4,C4,C4};
|
|
403 static mmx_t scratch0, scratch1;
|
|
404
|
|
405 /* column code adapted from peter gubanov */
|
|
406 /* http://www.elecard.com/peter/idct.shtml */
|
|
407
|
|
408 movq_m2r (*_T1, mm0); // mm0 = T1
|
|
409
|
|
410 movq_m2r (*(col+offset+1*8), mm1); // mm1 = x1
|
|
411 movq_r2r (mm0, mm2); // mm2 = T1
|
|
412
|
|
413 movq_m2r (*(col+offset+7*8), mm4); // mm4 = x7
|
|
414 pmulhw_r2r (mm1, mm0); // mm0 = T1*x1
|
|
415
|
|
416 movq_m2r (*_T3, mm5); // mm5 = T3
|
|
417 pmulhw_r2r (mm4, mm2); // mm2 = T1*x7
|
|
418
|
|
419 movq_m2r (*(col+offset+5*8), mm6); // mm6 = x5
|
|
420 movq_r2r (mm5, mm7); // mm7 = T3-1
|
|
421
|
|
422 movq_m2r (*(col+offset+3*8), mm3); // mm3 = x3
|
|
423 psubsw_r2r (mm4, mm0); // mm0 = v17
|
|
424
|
|
425 movq_m2r (*_T2, mm4); // mm4 = T2
|
|
426 pmulhw_r2r (mm3, mm5); // mm5 = (T3-1)*x3
|
|
427
|
|
428 paddsw_r2r (mm2, mm1); // mm1 = u17
|
|
429 pmulhw_r2r (mm6, mm7); // mm7 = (T3-1)*x5
|
|
430
|
|
431 // slot
|
|
432
|
|
433 movq_r2r (mm4, mm2); // mm2 = T2
|
|
434 paddsw_r2r (mm3, mm5); // mm5 = T3*x3
|
|
435
|
|
436 pmulhw_m2r (*(col+offset+2*8), mm4);// mm4 = T2*x2
|
|
437 paddsw_r2r (mm6, mm7); // mm7 = T3*x5
|
|
438
|
|
439 psubsw_r2r (mm6, mm5); // mm5 = v35
|
|
440 paddsw_r2r (mm3, mm7); // mm7 = u35
|
|
441
|
|
442 movq_m2r (*(col+offset+6*8), mm3); // mm3 = x6
|
|
443 movq_r2r (mm0, mm6); // mm6 = v17
|
|
444
|
|
445 pmulhw_r2r (mm3, mm2); // mm2 = T2*x6
|
|
446 psubsw_r2r (mm5, mm0); // mm0 = b3
|
|
447
|
|
448 psubsw_r2r (mm3, mm4); // mm4 = v26
|
|
449 paddsw_r2r (mm6, mm5); // mm5 = v12
|
|
450
|
|
451 movq_r2m (mm0, scratch0); // save b3
|
|
452 movq_r2r (mm1, mm6); // mm6 = u17
|
|
453
|
|
454 paddsw_m2r (*(col+offset+2*8), mm2);// mm2 = u26
|
|
455 paddsw_r2r (mm7, mm6); // mm6 = b0
|
|
456
|
|
457 psubsw_r2r (mm7, mm1); // mm1 = u12
|
|
458 movq_r2r (mm1, mm7); // mm7 = u12
|
|
459
|
|
460 movq_m2r (*(col+offset+0*8), mm3); // mm3 = x0
|
|
461 paddsw_r2r (mm5, mm1); // mm1 = u12+v12
|
|
462
|
|
463 movq_m2r (*_C4, mm0); // mm0 = C4/2
|
|
464 psubsw_r2r (mm5, mm7); // mm7 = u12-v12
|
|
465
|
|
466 movq_r2m (mm6, scratch1); // save b0
|
|
467 pmulhw_r2r (mm0, mm1); // mm1 = b1/2
|
|
468
|
|
469 movq_r2r (mm4, mm6); // mm6 = v26
|
|
470 pmulhw_r2r (mm0, mm7); // mm7 = b2/2
|
|
471
|
|
472 movq_m2r (*(col+offset+4*8), mm5); // mm5 = x4
|
|
473 movq_r2r (mm3, mm0); // mm0 = x0
|
|
474
|
|
475 psubsw_r2r (mm5, mm3); // mm3 = v04
|
|
476 paddsw_r2r (mm5, mm0); // mm0 = u04
|
|
477
|
|
478 paddsw_r2r (mm3, mm4); // mm4 = a1
|
|
479 movq_r2r (mm0, mm5); // mm5 = u04
|
|
480
|
|
481 psubsw_r2r (mm6, mm3); // mm3 = a2
|
|
482 paddsw_r2r (mm2, mm5); // mm5 = a0
|
|
483
|
|
484 paddsw_r2r (mm1, mm1); // mm1 = b1
|
|
485 psubsw_r2r (mm2, mm0); // mm0 = a3
|
|
486
|
|
487 paddsw_r2r (mm7, mm7); // mm7 = b2
|
|
488 movq_r2r (mm3, mm2); // mm2 = a2
|
|
489
|
|
490 movq_r2r (mm4, mm6); // mm6 = a1
|
|
491 paddsw_r2r (mm7, mm3); // mm3 = a2+b2
|
|
492
|
|
493 psraw_i2r (COL_SHIFT, mm3); // mm3 = y2
|
|
494 paddsw_r2r (mm1, mm4); // mm4 = a1+b1
|
|
495
|
|
496 psraw_i2r (COL_SHIFT, mm4); // mm4 = y1
|
|
497 psubsw_r2r (mm1, mm6); // mm6 = a1-b1
|
|
498
|
|
499 movq_m2r (scratch1, mm1); // mm1 = b0
|
|
500 psubsw_r2r (mm7, mm2); // mm2 = a2-b2
|
|
501
|
|
502 psraw_i2r (COL_SHIFT, mm6); // mm6 = y6
|
|
503 movq_r2r (mm5, mm7); // mm7 = a0
|
|
504
|
|
505 movq_r2m (mm4, *(col+offset+1*8)); // save y1
|
|
506 psraw_i2r (COL_SHIFT, mm2); // mm2 = y5
|
|
507
|
|
508 movq_r2m (mm3, *(col+offset+2*8)); // save y2
|
|
509 paddsw_r2r (mm1, mm5); // mm5 = a0+b0
|
|
510
|
|
511 movq_m2r (scratch0, mm4); // mm4 = b3
|
|
512 psubsw_r2r (mm1, mm7); // mm7 = a0-b0
|
|
513
|
|
514 psraw_i2r (COL_SHIFT, mm5); // mm5 = y0
|
|
515 movq_r2r (mm0, mm3); // mm3 = a3
|
|
516
|
|
517 movq_r2m (mm2, *(col+offset+5*8)); // save y5
|
|
518 psubsw_r2r (mm4, mm3); // mm3 = a3-b3
|
|
519
|
|
520 psraw_i2r (COL_SHIFT, mm7); // mm7 = y7
|
|
521 paddsw_r2r (mm0, mm4); // mm4 = a3+b3
|
|
522
|
|
523 movq_r2m (mm5, *(col+offset+0*8)); // save y0
|
|
524 psraw_i2r (COL_SHIFT, mm3); // mm3 = y4
|
|
525
|
|
526 movq_r2m (mm6, *(col+offset+6*8)); // save y6
|
|
527 psraw_i2r (COL_SHIFT, mm4); // mm4 = y3
|
|
528
|
|
529 movq_r2m (mm7, *(col+offset+7*8)); // save y7
|
|
530
|
|
531 movq_r2m (mm3, *(col+offset+4*8)); // save y4
|
|
532
|
|
533 movq_r2m (mm4, *(col+offset+3*8)); // save y3
|
|
534 }
|
|
535
|
|
536
|
|
537 static int32_t rounder0[] ATTR_ALIGN(8) =
|
|
538 rounder ((1 << (COL_SHIFT - 1)) - 0.5);
|
|
539 static int32_t rounder4[] ATTR_ALIGN(8) = rounder (0);
|
|
540 static int32_t rounder1[] ATTR_ALIGN(8) =
|
|
541 rounder (1.25683487303); // C1*(C1/C4+C1+C7)/2
|
|
542 static int32_t rounder7[] ATTR_ALIGN(8) =
|
|
543 rounder (-0.25); // C1*(C7/C4+C7-C1)/2
|
|
544 static int32_t rounder2[] ATTR_ALIGN(8) =
|
|
545 rounder (0.60355339059); // C2 * (C6+C2)/2
|
|
546 static int32_t rounder6[] ATTR_ALIGN(8) =
|
|
547 rounder (-0.25); // C2 * (C6-C2)/2
|
|
548 static int32_t rounder3[] ATTR_ALIGN(8) =
|
|
549 rounder (0.087788325588); // C3*(-C3/C4+C3+C5)/2
|
|
550 static int32_t rounder5[] ATTR_ALIGN(8) =
|
|
551 rounder (-0.441341716183); // C3*(-C5/C4+C5-C3)/2
|
|
552
|
|
553
|
|
554 #define declare_idct(idct,table,idct_row_head,idct_row,idct_row_tail,idct_row_mid) \
|
|
555 static inline void idct (int16_t * block) \
|
|
556 { \
|
|
557 static int16_t table04[] ATTR_ALIGN(16) = \
|
|
558 table (22725, 21407, 19266, 16384, 12873, 8867, 4520); \
|
|
559 static int16_t table17[] ATTR_ALIGN(16) = \
|
|
560 table (31521, 29692, 26722, 22725, 17855, 12299, 6270); \
|
|
561 static int16_t table26[] ATTR_ALIGN(16) = \
|
|
562 table (29692, 27969, 25172, 21407, 16819, 11585, 5906); \
|
|
563 static int16_t table35[] ATTR_ALIGN(16) = \
|
|
564 table (26722, 25172, 22654, 19266, 15137, 10426, 5315); \
|
|
565 \
|
|
566 idct_row_head (block, 0*8, table04); \
|
|
567 idct_row (table04, rounder0); \
|
|
568 idct_row_mid (block, 0*8, 4*8, table04); \
|
|
569 idct_row (table04, rounder4); \
|
|
570 idct_row_mid (block, 4*8, 1*8, table17); \
|
|
571 idct_row (table17, rounder1); \
|
|
572 idct_row_mid (block, 1*8, 7*8, table17); \
|
|
573 idct_row (table17, rounder7); \
|
|
574 idct_row_mid (block, 7*8, 2*8, table26); \
|
|
575 idct_row (table26, rounder2); \
|
|
576 idct_row_mid (block, 2*8, 6*8, table26); \
|
|
577 idct_row (table26, rounder6); \
|
|
578 idct_row_mid (block, 6*8, 3*8, table35); \
|
|
579 idct_row (table35, rounder3); \
|
|
580 idct_row_mid (block, 3*8, 5*8, table35); \
|
|
581 idct_row (table35, rounder5); \
|
|
582 idct_row_tail (block, 5*8); \
|
|
583 \
|
|
584 idct_col (block, 0); \
|
|
585 idct_col (block, 4); \
|
|
586 }
|
|
587
|
|
588
|
|
589 #define COPY_MMX(offset,r0,r1,r2) \
|
|
590 do { \
|
|
591 movq_m2r (*(block+offset), r0); \
|
|
592 dest += stride; \
|
|
593 movq_m2r (*(block+offset+4), r1); \
|
|
594 movq_r2m (r2, *dest); \
|
|
595 packuswb_r2r (r1, r0); \
|
|
596 } while (0)
|
|
597
|
|
598 static void block_copy (int16_t * block, uint8_t * dest, int stride)
|
|
599 {
|
|
600 movq_m2r (*(block+0*8), mm0);
|
|
601 movq_m2r (*(block+0*8+4), mm1);
|
|
602 movq_m2r (*(block+1*8), mm2);
|
|
603 packuswb_r2r (mm1, mm0);
|
|
604 movq_m2r (*(block+1*8+4), mm3);
|
|
605 movq_r2m (mm0, *dest);
|
|
606 packuswb_r2r (mm3, mm2);
|
|
607 COPY_MMX (2*8, mm0, mm1, mm2);
|
|
608 COPY_MMX (3*8, mm2, mm3, mm0);
|
|
609 COPY_MMX (4*8, mm0, mm1, mm2);
|
|
610 COPY_MMX (5*8, mm2, mm3, mm0);
|
|
611 COPY_MMX (6*8, mm0, mm1, mm2);
|
|
612 COPY_MMX (7*8, mm2, mm3, mm0);
|
|
613 movq_r2m (mm2, *(dest+stride));
|
|
614 }
|
|
615
|
|
616
|
|
617 #define ADD_MMX(offset,r1,r2,r3,r4) \
|
|
618 do { \
|
|
619 movq_m2r (*(dest+2*stride), r1); \
|
|
620 packuswb_r2r (r4, r3); \
|
|
621 movq_r2r (r1, r2); \
|
|
622 dest += stride; \
|
|
623 movq_r2m (r3, *dest); \
|
|
624 punpcklbw_r2r (mm0, r1); \
|
|
625 paddsw_m2r (*(block+offset), r1); \
|
|
626 punpckhbw_r2r (mm0, r2); \
|
|
627 paddsw_m2r (*(block+offset+4), r2); \
|
|
628 } while (0)
|
|
629
|
|
630 static void block_add (int16_t * block, uint8_t * dest, int stride)
|
|
631 {
|
|
632 movq_m2r (*dest, mm1);
|
|
633 pxor_r2r (mm0, mm0);
|
|
634 movq_m2r (*(dest+stride), mm3);
|
|
635 movq_r2r (mm1, mm2);
|
|
636 punpcklbw_r2r (mm0, mm1);
|
|
637 movq_r2r (mm3, mm4);
|
|
638 paddsw_m2r (*(block+0*8), mm1);
|
|
639 punpckhbw_r2r (mm0, mm2);
|
|
640 paddsw_m2r (*(block+0*8+4), mm2);
|
|
641 punpcklbw_r2r (mm0, mm3);
|
|
642 paddsw_m2r (*(block+1*8), mm3);
|
|
643 packuswb_r2r (mm2, mm1);
|
|
644 punpckhbw_r2r (mm0, mm4);
|
|
645 movq_r2m (mm1, *dest);
|
|
646 paddsw_m2r (*(block+1*8+4), mm4);
|
|
647 ADD_MMX (2*8, mm1, mm2, mm3, mm4);
|
|
648 ADD_MMX (3*8, mm3, mm4, mm1, mm2);
|
|
649 ADD_MMX (4*8, mm1, mm2, mm3, mm4);
|
|
650 ADD_MMX (5*8, mm3, mm4, mm1, mm2);
|
|
651 ADD_MMX (6*8, mm1, mm2, mm3, mm4);
|
|
652 ADD_MMX (7*8, mm3, mm4, mm1, mm2);
|
|
653 packuswb_r2r (mm4, mm3);
|
|
654 movq_r2m (mm3, *(dest+stride));
|
|
655 }
|
|
656
|
|
657
|
|
658 declare_idct (mmxext_idct, mmxext_table,
|
|
659 mmxext_row_head, mmxext_row, mmxext_row_tail, mmxext_row_mid)
|
|
660
|
|
661 void idct_block_copy_mmxext (int16_t * block, uint8_t * dest, int stride)
|
|
662 {
|
|
663 mmxext_idct (block);
|
|
664 block_copy (block, dest, stride);
|
|
665 }
|
|
666
|
|
667 void idct_block_add_mmxext (int16_t * block, uint8_t * dest, int stride)
|
|
668 {
|
|
669 mmxext_idct (block);
|
|
670 block_add (block, dest, stride);
|
|
671 }
|
|
672
|
|
673
|
|
674 declare_idct (mmx_idct, mmx_table,
|
|
675 mmx_row_head, mmx_row, mmx_row_tail, mmx_row_mid)
|
|
676
|
|
677 void idct_block_copy_mmx (int16_t * block, uint8_t * dest, int stride)
|
|
678 {
|
|
679 mmx_idct (block);
|
|
680 block_copy (block, dest, stride);
|
|
681 }
|
|
682
|
|
683 void idct_block_add_mmx (int16_t * block, uint8_t * dest, int stride)
|
|
684 {
|
|
685 mmx_idct (block);
|
|
686 block_add (block, dest, stride);
|
|
687 }
|
|
688
|
|
689
|
|
690 void idct_mmx_init (void)
|
|
691 {
|
|
692 extern uint8_t scan_norm[64];
|
|
693 extern uint8_t scan_alt[64];
|
|
694 int i, j;
|
|
695
|
|
696 // the mmx/mmxext idct uses a reordered input, so we patch scan tables
|
|
697
|
|
698 for (i = 0; i < 64; i++) {
|
|
699 j = scan_norm[i];
|
|
700 scan_norm[i] = (j & 0x38) | ((j & 6) >> 1) | ((j & 1) << 2);
|
|
701 j = scan_alt[i];
|
|
702 scan_alt[i] = (j & 0x38) | ((j & 6) >> 1) | ((j & 1) << 2);
|
|
703 }
|
|
704 }
|
|
705
|
|
706 #endif
|