9857
|
1 /*
|
|
2 * idct_alpha.c
|
12932
|
3 * Copyright (C) 2002-2003 Falk Hueffner <falk@debian.org>
|
|
4 * Copyright (C) 2000-2003 Michel Lespinasse <walken@zoy.org>
|
9857
|
5 * Copyright (C) 1999-2000 Aaron Holtzman <aholtzma@ess.engr.uvic.ca>
|
|
6 *
|
|
7 * This file is part of mpeg2dec, a free MPEG-2 video stream decoder.
|
|
8 * See http://libmpeg2.sourceforge.net/ for updates.
|
|
9 *
|
|
10 * mpeg2dec is free software; you can redistribute it and/or modify
|
|
11 * it under the terms of the GNU General Public License as published by
|
|
12 * the Free Software Foundation; either version 2 of the License, or
|
|
13 * (at your option) any later version.
|
|
14 *
|
|
15 * mpeg2dec 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
|
|
18 * GNU General Public License for more details.
|
|
19 *
|
|
20 * You should have received a copy of the GNU General Public License
|
|
21 * along with this program; if not, write to the Free Software
|
|
22 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
23 */
|
|
24
|
|
25 #include "config.h"
|
|
26
|
|
27 #ifdef ARCH_ALPHA
|
|
28
|
|
29 #include <stdlib.h>
|
|
30 #include <inttypes.h>
|
|
31
|
12932
|
32 #include "mpeg2.h"
|
|
33 #include "attributes.h"
|
|
34 #include "mpeg2_internal.h"
|
9857
|
35 #include "alpha_asm.h"
|
|
36
|
12932
|
37 #define W1 2841 /* 2048 * sqrt (2) * cos (1 * pi / 16) */
|
|
38 #define W2 2676 /* 2048 * sqrt (2) * cos (2 * pi / 16) */
|
|
39 #define W3 2408 /* 2048 * sqrt (2) * cos (3 * pi / 16) */
|
|
40 #define W5 1609 /* 2048 * sqrt (2) * cos (5 * pi / 16) */
|
|
41 #define W6 1108 /* 2048 * sqrt (2) * cos (6 * pi / 16) */
|
|
42 #define W7 565 /* 2048 * sqrt (2) * cos (7 * pi / 16) */
|
9857
|
43
|
12932
|
44 extern uint8_t mpeg2_clip[3840 * 2 + 256];
|
|
45 #define CLIP(i) ((mpeg2_clip + 3840)[i])
|
9857
|
46
|
|
47 #if 0
|
|
48 #define BUTTERFLY(t0,t1,W0,W1,d0,d1) \
|
|
49 do { \
|
12932
|
50 t0 = W0 * d0 + W1 * d1; \
|
|
51 t1 = W0 * d1 - W1 * d0; \
|
9857
|
52 } while (0)
|
|
53 #else
|
|
54 #define BUTTERFLY(t0,t1,W0,W1,d0,d1) \
|
|
55 do { \
|
|
56 int_fast32_t tmp = W0 * (d0 + d1); \
|
|
57 t0 = tmp + (W1 - W0) * d1; \
|
|
58 t1 = tmp - (W1 + W0) * d0; \
|
|
59 } while (0)
|
|
60 #endif
|
|
61
|
10392
|
62 static inline void idct_row (int16_t * const block)
|
9857
|
63 {
|
|
64 uint64_t l, r;
|
|
65 int_fast32_t d0, d1, d2, d3;
|
|
66 int_fast32_t a0, a1, a2, a3, b0, b1, b2, b3;
|
|
67 int_fast32_t t0, t1, t2, t3;
|
|
68
|
|
69 l = ldq (block);
|
|
70 r = ldq (block + 4);
|
|
71
|
|
72 /* shortcut */
|
|
73 if (likely (!((l & ~0xffffUL) | r))) {
|
12932
|
74 uint64_t tmp = (uint16_t) (l >> 1);
|
9857
|
75 tmp |= tmp << 16;
|
|
76 tmp |= tmp << 32;
|
|
77 ((int32_t *)block)[0] = tmp;
|
|
78 ((int32_t *)block)[1] = tmp;
|
|
79 ((int32_t *)block)[2] = tmp;
|
|
80 ((int32_t *)block)[3] = tmp;
|
|
81 return;
|
|
82 }
|
|
83
|
12932
|
84 d0 = (sextw (l) << 11) + 2048;
|
9857
|
85 d1 = sextw (extwl (l, 2));
|
|
86 d2 = sextw (extwl (l, 4)) << 11;
|
|
87 d3 = sextw (extwl (l, 6));
|
|
88 t0 = d0 + d2;
|
|
89 t1 = d0 - d2;
|
|
90 BUTTERFLY (t2, t3, W6, W2, d3, d1);
|
|
91 a0 = t0 + t2;
|
|
92 a1 = t1 + t3;
|
|
93 a2 = t1 - t3;
|
|
94 a3 = t0 - t2;
|
|
95
|
|
96 d0 = sextw (r);
|
|
97 d1 = sextw (extwl (r, 2));
|
|
98 d2 = sextw (extwl (r, 4));
|
|
99 d3 = sextw (extwl (r, 6));
|
|
100 BUTTERFLY (t0, t1, W7, W1, d3, d0);
|
|
101 BUTTERFLY (t2, t3, W3, W5, d1, d2);
|
|
102 b0 = t0 + t2;
|
|
103 b3 = t1 + t3;
|
|
104 t0 -= t2;
|
|
105 t1 -= t3;
|
12932
|
106 b1 = ((t0 + t1) >> 8) * 181;
|
|
107 b2 = ((t0 - t1) >> 8) * 181;
|
9857
|
108
|
12932
|
109 block[0] = (a0 + b0) >> 12;
|
|
110 block[1] = (a1 + b1) >> 12;
|
|
111 block[2] = (a2 + b2) >> 12;
|
|
112 block[3] = (a3 + b3) >> 12;
|
|
113 block[4] = (a3 - b3) >> 12;
|
|
114 block[5] = (a2 - b2) >> 12;
|
|
115 block[6] = (a1 - b1) >> 12;
|
|
116 block[7] = (a0 - b0) >> 12;
|
9857
|
117 }
|
|
118
|
10392
|
119 static inline void idct_col (int16_t * const block)
|
9857
|
120 {
|
|
121 int_fast32_t d0, d1, d2, d3;
|
|
122 int_fast32_t a0, a1, a2, a3, b0, b1, b2, b3;
|
|
123 int_fast32_t t0, t1, t2, t3;
|
|
124
|
|
125 d0 = (block[8*0] << 11) + 65536;
|
|
126 d1 = block[8*1];
|
|
127 d2 = block[8*2] << 11;
|
|
128 d3 = block[8*3];
|
|
129 t0 = d0 + d2;
|
|
130 t1 = d0 - d2;
|
|
131 BUTTERFLY (t2, t3, W6, W2, d3, d1);
|
|
132 a0 = t0 + t2;
|
|
133 a1 = t1 + t3;
|
|
134 a2 = t1 - t3;
|
|
135 a3 = t0 - t2;
|
|
136
|
|
137 d0 = block[8*4];
|
|
138 d1 = block[8*5];
|
|
139 d2 = block[8*6];
|
|
140 d3 = block[8*7];
|
|
141 BUTTERFLY (t0, t1, W7, W1, d3, d0);
|
|
142 BUTTERFLY (t2, t3, W3, W5, d1, d2);
|
|
143 b0 = t0 + t2;
|
|
144 b3 = t1 + t3;
|
12932
|
145 t0 -= t2;
|
|
146 t1 -= t3;
|
|
147 b1 = ((t0 + t1) >> 8) * 181;
|
|
148 b2 = ((t0 - t1) >> 8) * 181;
|
9857
|
149
|
|
150 block[8*0] = (a0 + b0) >> 17;
|
|
151 block[8*1] = (a1 + b1) >> 17;
|
|
152 block[8*2] = (a2 + b2) >> 17;
|
|
153 block[8*3] = (a3 + b3) >> 17;
|
|
154 block[8*4] = (a3 - b3) >> 17;
|
|
155 block[8*5] = (a2 - b2) >> 17;
|
|
156 block[8*6] = (a1 - b1) >> 17;
|
|
157 block[8*7] = (a0 - b0) >> 17;
|
|
158 }
|
|
159
|
10488
|
160 #ifdef CAN_COMPILE_ALPHA_MVI
|
9857
|
161 void mpeg2_idct_copy_mvi (int16_t * block, uint8_t * dest, const int stride)
|
|
162 {
|
|
163 uint64_t clampmask;
|
|
164 int i;
|
|
165
|
|
166 for (i = 0; i < 8; i++)
|
|
167 idct_row (block + 8 * i);
|
|
168
|
|
169 for (i = 0; i < 8; i++)
|
|
170 idct_col (block + i);
|
|
171
|
|
172 clampmask = zap (-1, 0xaa); /* 0x00ff00ff00ff00ff */
|
|
173 do {
|
|
174 uint64_t shorts0, shorts1;
|
|
175
|
|
176 shorts0 = ldq (block);
|
|
177 shorts0 = maxsw4 (shorts0, 0);
|
|
178 shorts0 = minsw4 (shorts0, clampmask);
|
|
179 stl (pkwb (shorts0), dest);
|
|
180
|
|
181 shorts1 = ldq (block + 4);
|
|
182 shorts1 = maxsw4 (shorts1, 0);
|
|
183 shorts1 = minsw4 (shorts1, clampmask);
|
|
184 stl (pkwb (shorts1), dest + 4);
|
|
185
|
|
186 stq (0, block);
|
|
187 stq (0, block + 4);
|
|
188
|
|
189 dest += stride;
|
|
190 block += 8;
|
|
191 } while (--i);
|
|
192 }
|
|
193
|
|
194 void mpeg2_idct_add_mvi (const int last, int16_t * block,
|
|
195 uint8_t * dest, const int stride)
|
|
196 {
|
|
197 uint64_t clampmask;
|
|
198 uint64_t signmask;
|
|
199 int i;
|
|
200
|
12932
|
201 if (last != 129 || (block[0] & (7 << 4)) == (4 << 4)) {
|
9857
|
202 for (i = 0; i < 8; i++)
|
|
203 idct_row (block + 8 * i);
|
|
204 for (i = 0; i < 8; i++)
|
|
205 idct_col (block + i);
|
|
206 clampmask = zap (-1, 0xaa); /* 0x00ff00ff00ff00ff */
|
|
207 signmask = zap (-1, 0x33);
|
|
208 signmask ^= signmask >> 1; /* 0x8000800080008000 */
|
|
209
|
|
210 do {
|
|
211 uint64_t shorts0, pix0, signs0;
|
|
212 uint64_t shorts1, pix1, signs1;
|
|
213
|
|
214 shorts0 = ldq (block);
|
|
215 shorts1 = ldq (block + 4);
|
|
216
|
|
217 pix0 = unpkbw (ldl (dest));
|
|
218 /* signed subword add (MMX paddw). */
|
|
219 signs0 = shorts0 & signmask;
|
|
220 shorts0 &= ~signmask;
|
|
221 shorts0 += pix0;
|
|
222 shorts0 ^= signs0;
|
|
223 /* clamp. */
|
|
224 shorts0 = maxsw4 (shorts0, 0);
|
|
225 shorts0 = minsw4 (shorts0, clampmask);
|
|
226
|
|
227 /* next 4. */
|
|
228 pix1 = unpkbw (ldl (dest + 4));
|
|
229 signs1 = shorts1 & signmask;
|
|
230 shorts1 &= ~signmask;
|
|
231 shorts1 += pix1;
|
|
232 shorts1 ^= signs1;
|
|
233 shorts1 = maxsw4 (shorts1, 0);
|
|
234 shorts1 = minsw4 (shorts1, clampmask);
|
|
235
|
|
236 stl (pkwb (shorts0), dest);
|
|
237 stl (pkwb (shorts1), dest + 4);
|
|
238 stq (0, block);
|
|
239 stq (0, block + 4);
|
|
240
|
|
241 dest += stride;
|
|
242 block += 8;
|
|
243 } while (--i);
|
|
244 } else {
|
|
245 int DC;
|
|
246 uint64_t p0, p1, p2, p3, p4, p5, p6, p7;
|
|
247 uint64_t DCs;
|
|
248
|
12932
|
249 DC = (block[0] + 64) >> 7;
|
9857
|
250 block[0] = block[63] = 0;
|
|
251
|
|
252 p0 = ldq (dest + 0 * stride);
|
|
253 p1 = ldq (dest + 1 * stride);
|
|
254 p2 = ldq (dest + 2 * stride);
|
|
255 p3 = ldq (dest + 3 * stride);
|
|
256 p4 = ldq (dest + 4 * stride);
|
|
257 p5 = ldq (dest + 5 * stride);
|
|
258 p6 = ldq (dest + 6 * stride);
|
|
259 p7 = ldq (dest + 7 * stride);
|
|
260
|
|
261 if (DC > 0) {
|
|
262 DCs = BYTE_VEC (likely (DC <= 255) ? DC : 255);
|
|
263 p0 += minub8 (DCs, ~p0);
|
|
264 p1 += minub8 (DCs, ~p1);
|
|
265 p2 += minub8 (DCs, ~p2);
|
|
266 p3 += minub8 (DCs, ~p3);
|
|
267 p4 += minub8 (DCs, ~p4);
|
|
268 p5 += minub8 (DCs, ~p5);
|
|
269 p6 += minub8 (DCs, ~p6);
|
|
270 p7 += minub8 (DCs, ~p7);
|
|
271 } else {
|
|
272 DCs = BYTE_VEC (likely (-DC <= 255) ? -DC : 255);
|
|
273 p0 -= minub8 (DCs, p0);
|
|
274 p1 -= minub8 (DCs, p1);
|
|
275 p2 -= minub8 (DCs, p2);
|
|
276 p3 -= minub8 (DCs, p3);
|
|
277 p4 -= minub8 (DCs, p4);
|
|
278 p5 -= minub8 (DCs, p5);
|
|
279 p6 -= minub8 (DCs, p6);
|
|
280 p7 -= minub8 (DCs, p7);
|
|
281 }
|
|
282
|
|
283 stq (p0, dest + 0 * stride);
|
|
284 stq (p1, dest + 1 * stride);
|
|
285 stq (p2, dest + 2 * stride);
|
|
286 stq (p3, dest + 3 * stride);
|
|
287 stq (p4, dest + 4 * stride);
|
|
288 stq (p5, dest + 5 * stride);
|
|
289 stq (p6, dest + 6 * stride);
|
|
290 stq (p7, dest + 7 * stride);
|
|
291 }
|
|
292 }
|
10488
|
293 #endif
|
9857
|
294
|
|
295 void mpeg2_idct_copy_alpha (int16_t * block, uint8_t * dest, const int stride)
|
|
296 {
|
|
297 int i;
|
|
298
|
|
299 for (i = 0; i < 8; i++)
|
|
300 idct_row (block + 8 * i);
|
|
301 for (i = 0; i < 8; i++)
|
|
302 idct_col (block + i);
|
|
303 do {
|
|
304 dest[0] = CLIP (block[0]);
|
|
305 dest[1] = CLIP (block[1]);
|
|
306 dest[2] = CLIP (block[2]);
|
|
307 dest[3] = CLIP (block[3]);
|
|
308 dest[4] = CLIP (block[4]);
|
|
309 dest[5] = CLIP (block[5]);
|
|
310 dest[6] = CLIP (block[6]);
|
|
311 dest[7] = CLIP (block[7]);
|
|
312
|
|
313 stq(0, block);
|
|
314 stq(0, block + 4);
|
|
315
|
|
316 dest += stride;
|
|
317 block += 8;
|
|
318 } while (--i);
|
|
319 }
|
|
320
|
|
321 void mpeg2_idct_add_alpha (const int last, int16_t * block,
|
|
322 uint8_t * dest, const int stride)
|
|
323 {
|
|
324 int i;
|
|
325
|
12932
|
326 if (last != 129 || (block[0] & (7 << 4)) == (4 << 4)) {
|
9857
|
327 for (i = 0; i < 8; i++)
|
|
328 idct_row (block + 8 * i);
|
|
329 for (i = 0; i < 8; i++)
|
|
330 idct_col (block + i);
|
|
331 do {
|
|
332 dest[0] = CLIP (block[0] + dest[0]);
|
|
333 dest[1] = CLIP (block[1] + dest[1]);
|
|
334 dest[2] = CLIP (block[2] + dest[2]);
|
|
335 dest[3] = CLIP (block[3] + dest[3]);
|
|
336 dest[4] = CLIP (block[4] + dest[4]);
|
|
337 dest[5] = CLIP (block[5] + dest[5]);
|
|
338 dest[6] = CLIP (block[6] + dest[6]);
|
|
339 dest[7] = CLIP (block[7] + dest[7]);
|
|
340
|
|
341 stq(0, block);
|
|
342 stq(0, block + 4);
|
|
343
|
|
344 dest += stride;
|
|
345 block += 8;
|
|
346 } while (--i);
|
|
347 } else {
|
|
348 int DC;
|
|
349
|
12932
|
350 DC = (block[0] + 64) >> 7;
|
9857
|
351 block[0] = block[63] = 0;
|
|
352 i = 8;
|
|
353 do {
|
|
354 dest[0] = CLIP (DC + dest[0]);
|
|
355 dest[1] = CLIP (DC + dest[1]);
|
|
356 dest[2] = CLIP (DC + dest[2]);
|
|
357 dest[3] = CLIP (DC + dest[3]);
|
|
358 dest[4] = CLIP (DC + dest[4]);
|
|
359 dest[5] = CLIP (DC + dest[5]);
|
|
360 dest[6] = CLIP (DC + dest[6]);
|
|
361 dest[7] = CLIP (DC + dest[7]);
|
|
362 dest += stride;
|
|
363 } while (--i);
|
|
364 }
|
|
365 }
|
|
366
|
12932
|
367 void mpeg2_idct_alpha_init (void)
|
9857
|
368 {
|
|
369 extern uint8_t mpeg2_scan_norm[64];
|
|
370 extern uint8_t mpeg2_scan_alt[64];
|
|
371 int i, j;
|
|
372
|
|
373 for (i = 0; i < 64; i++) {
|
|
374 j = mpeg2_scan_norm[i];
|
|
375 mpeg2_scan_norm[i] = ((j & 0x36) >> 1) | ((j & 0x09) << 2);
|
|
376 j = mpeg2_scan_alt[i];
|
|
377 mpeg2_scan_alt[i] = ((j & 0x36) >> 1) | ((j & 0x09) << 2);
|
|
378 }
|
|
379 }
|
|
380
|
|
381 #endif /* ARCH_ALPHA */
|