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