Statistics
| Branch: | Revision:

ffmpeg / libavcodec / ps2 / idct_mmi.c @ b550bfaa

History | View | Annotate | Download (13.4 KB)

1
/*
2
 * Originally provided by Intel at Application Note AP-922.
3
 *
4
 * Column code adapted from Peter Gubanov.
5
 * Copyright (c) 2000-2001 Peter Gubanov <peter@elecard.net.ru>
6
 * http://www.elecard.com/peter/idct.shtml
7
 * rounding trick copyright (c) 2000 Michel Lespinasse <walken@zoy.org>
8
 *
9
 * MMI port and (c) 2002 by Leon van Stuivenberg
10
 *
11
 * This file is part of FFmpeg.
12
 *
13
 * FFmpeg is free software; you can redistribute it and/or
14
 * modify it under the terms of the GNU Lesser General Public
15
 * License as published by the Free Software Foundation; either
16
 * version 2.1 of the License, or (at your option) any later version.
17
 *
18
 * FFmpeg is distributed in the hope that it will be useful,
19
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
21
 * Lesser General Public License for more details.
22
 *
23
 * You should have received a copy of the GNU Lesser General Public
24
 * License along with FFmpeg; if not, write to the Free Software
25
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
26
 *
27
*/
28

    
29
#include "common.h"
30
#include "dsputil.h"
31
#include "mmi.h"
32

    
33
#define BITS_INV_ACC    5       // 4 or 5 for IEEE
34
#define SHIFT_INV_ROW   (16 - BITS_INV_ACC)
35
#define SHIFT_INV_COL   (1 + BITS_INV_ACC)
36

    
37
#define TG1             6518
38
#define TG2             13573
39
#define TG3             21895
40
#define CS4             23170
41

    
42
#define ROUNDER_0       0
43
#define ROUNDER_1       16
44

    
45
#define TAB_i_04        (32+0)
46
#define TAB_i_17        (32+64)
47
#define TAB_i_26        (32+128)
48
#define TAB_i_35        (32+192)
49

    
50
#define TG_1_16         (32+256+0)
51
#define TG_2_16         (32+256+16)
52
#define TG_3_16         (32+256+32)
53
#define COS_4_16        (32+256+48)
54

    
55
#define CLIPMAX         (32+256+64+0)
56

    
57
static short consttable[] align16 = {
58
/* rounder 0*/  // assume SHIFT_INV_ROW == 11
59
 0x3ff, 1, 0x3ff, 1, 0x3ff, 1, 0x3ff, 1,
60
/* rounder 1*/
61
 0x3ff, 0, 0x3ff, 0, 0x3ff, 0, 0x3ff, 0,
62
/* row 0/4*/
63
 16384,  21407, -16384, -21407,  22725,  19266, -22725, -12873,
64
  8867,  16384,   8867,  16384,   4520,  12873,  -4520,  19266,
65
 16384,  -8867,  16384,  -8867,  12873, -22725,  19266, -22725,
66
 21407, -16384, -21407,  16384,  19266,   4520, -12873,   4520,
67
/* row 1/7*/
68
 22725,  29692, -22725, -29692,  31521,  26722, -31521, -17855,
69
 12299,  22725,  12299,  22725,   6270,  17855,  -6270,  26722,
70
 22725, -12299,  22725, -12299,  17855, -31521,  26722, -31521,
71
 29692, -22725, -29692,  22725,  26722,   6270, -17855,   6270,
72
/* row 2/6*/
73
 21407,  27969, -21407, -27969,  29692,  25172, -29692, -16819,
74
 11585,  21407,  11585,  21407,   5906,  16819,  -5906,  25172,
75
 21407, -11585,  21407, -11585,  16819, -29692,  25172, -29692,
76
 27969, -21407, -27969,  21407,  25172,   5906, -16819,   5906,
77
/*row 3/5*/
78
 19266,  25172, -19266, -25172,  26722,  22654, -26722, -15137,
79
 10426,  19266,  10426,  19266,   5315,  15137,  -5315,  22654,
80
 19266, -10426,  19266, -10426,  15137, -26722,  22654, -26722,
81
 25172, -19266, -25172,  19266,  22654,   5315, -15137,   5315,
82
/*column constants*/
83
 TG1, TG1, TG1, TG1, TG1, TG1, TG1, TG1,
84
 TG2, TG2, TG2, TG2, TG2, TG2, TG2, TG2,
85
 TG3, TG3, TG3, TG3, TG3, TG3, TG3, TG3,
86
 CS4, CS4, CS4, CS4, CS4, CS4, CS4, CS4,
87
/* clamp */
88
 255, 255, 255, 255, 255, 255, 255, 255
89
};
90

    
91

    
92
#define DCT_8_INV_ROW1(blk, rowoff, taboff, rnd, outreg) { \
93
        lq(blk, rowoff, $16);   /* r16 = x7  x5  x3  x1  x6  x4  x2  x0 */ \
94
        /*slot*/ \
95
        lq($24, 0+taboff, $17); /* r17 = w */ \
96
        /*delay slot $16*/ \
97
        lq($24, 16+taboff, $18);/* r18 = w */ \
98
        prevh($16, $2);         /* r2  = x1  x3  x5  x7  x0  x2  x4  x6 */ \
99
        lq($24, 32+taboff, $19);/* r19 = w */ \
100
        phmadh($17, $16, $17);  /* r17 = b1"b0'a1"a0' */ \
101
        lq($24, 48+taboff, $20);/* r20 = w */ \
102
        phmadh($18, $2, $18);   /* r18 = b1'b0"a1'a0" */ \
103
        phmadh($19, $16, $19);  /* r19 = b3"b2'a3"a2' */ \
104
        phmadh($20, $2, $20);   /* r20 = b3'b2"a3'a2" */ \
105
        paddw($17, $18, $17);   /* r17 = (b1)(b0)(a1)(a0) */ \
106
        paddw($19, $20, $19);   /* r19 = (b3)(b2)(a3)(a2) */ \
107
        pcpyld($19, $17, $18);  /* r18 = (a3)(a2)(a1)(a0) */ \
108
        pcpyud($17, $19, $20);  /* r20 = (b3)(b2)(b1)(b0) */ \
109
        paddw($18, rnd, $18);   /* r18 = (a3)(a2)(a1)(a0) */\
110
        paddw($18, $20, $17);   /* r17 = ()()()(a0+b0) */ \
111
        psubw($18, $20, $20);   /* r20 = ()()()(a0-b0) */ \
112
        psraw($17, SHIFT_INV_ROW, $17); /* r17 = (y3 y2 y1 y0) */ \
113
        psraw($20, SHIFT_INV_ROW, $20); /* r20 = (y4 y5 y6 y7) */ \
114
        ppach($20, $17, outreg);/* out = y4 y5 y6 y7 y3 y2 y1 y0  Note order */ \
115
\
116
        prevh(outreg, $2);        \
117
        pcpyud($2, $2, $2);        \
118
        pcpyld($2, outreg, outreg);        \
119
}
120

    
121

    
122
#define DCT_8_INV_COL8() \
123
\
124
        lq($24, TG_3_16, $2);   /* r2  = tn3 */         \
125
\
126
        pmulth($11, $2, $17);   /* r17 = x3 * tn3 (6420) */ \
127
        psraw($17, 15, $17);    \
128
        pmfhl_uw($3);           /* r3  = 7531 */        \
129
        psraw($3, 15, $3);      \
130
        pinteh($3, $17, $17);   /* r17 = x3 * tn3 */    \
131
        psubh($17, $13, $17);   /* r17 = tm35 */        \
132
\
133
        pmulth($13, $2, $18);   /* r18 = x5 * tn3 (6420) */ \
134
        psraw($18, 15, $18);    \
135
        pmfhl_uw($3);           /* r3  = 7531 */        \
136
        psraw($3, 15, $3);      \
137
        pinteh($3, $18, $18);   /* r18 = x5 * tn3 */    \
138
        paddh($18, $11, $18);   /* r18 = tp35 */        \
139
\
140
        lq($24, TG_1_16, $2);   /* r2  = tn1 */         \
141
\
142
        pmulth($15, $2, $19);   /* r19 = x7 * tn1 (6420) */ \
143
        psraw($19, 15, $19);    \
144
        pmfhl_uw($3);           /* r3  = 7531 */        \
145
        psraw($3, 15, $3);      \
146
        pinteh($3, $19, $19);   /* r19 = x7 * tn1 */    \
147
        paddh($19, $9, $19);    /* r19 = tp17 */        \
148
\
149
        pmulth($9, $2, $20);    /* r20 = x1 * tn1 (6420) */ \
150
        psraw($20, 15, $20);    \
151
        pmfhl_uw($3);           /* r3  = 7531 */        \
152
        psraw($3, 15, $3);      \
153
        pinteh($3, $20, $20);   /* r20 = x1 * tn1 */    \
154
        psubh($20, $15, $20);   /* r20 = tm17 */        \
155
\
156
        psubh($19, $18, $3);    /* r3  = t1 */          \
157
        paddh($20, $17, $16);   /* r16 = t2 */          \
158
        psubh($20, $17, $23);   /* r23 = b3 */          \
159
        paddh($19, $18, $20);   /* r20 = b0 */          \
160
\
161
        lq($24, COS_4_16, $2);  /* r2  = cs4 */         \
162
\
163
        paddh($3, $16, $21);    /* r21 = t1+t2 */       \
164
        psubh($3, $16, $22);    /* r22 = t1-t2 */       \
165
\
166
        pmulth($21, $2, $21);   /* r21 = cs4 * (t1+t2) 6420 */ \
167
        psraw($21, 15, $21);    \
168
        pmfhl_uw($3);           /* r3  = 7531 */        \
169
        psraw($3, 15, $3);      \
170
        pinteh($3, $21, $21);   /* r21 = b1 */          \
171
\
172
        pmulth($22, $2, $22);   /* r22 = cs4 * (t1-t2) 6420 */ \
173
        psraw($22, 15, $22);    \
174
        pmfhl_uw($3);           /* r3  = 7531 */        \
175
        psraw($3, 15, $3);      \
176
        pinteh($3, $22, $22);   /* r22 = b2 */          \
177
\
178
        lq($24, TG_2_16, $2);   /* r2  = tn2 */         \
179
\
180
        pmulth($10, $2, $17);   /* r17 = x2 * tn2 (6420) */ \
181
        psraw($17, 15, $17);    \
182
        pmfhl_uw($3);           /* r3  = 7531 */        \
183
        psraw($3, 15, $3);      \
184
        pinteh($3, $17, $17);   /* r17 = x3 * tn3 */    \
185
        psubh($17, $14, $17);   /* r17 = tm26 */        \
186
\
187
        pmulth($14, $2, $18);   /* r18 = x6 * tn2 (6420) */ \
188
        psraw($18, 15, $18);    \
189
        pmfhl_uw($3);           /* r3  = 7531 */        \
190
        psraw($3, 15, $3);      \
191
        pinteh($3, $18, $18);   /* r18 = x6 * tn2 */    \
192
        paddh($18, $10, $18);   /* r18 = tp26 */        \
193
\
194
        paddh($8, $12, $2);     /* r2  = tp04 */        \
195
        psubh($8, $12, $3);     /* r3  = tm04 */        \
196
\
197
        paddh($2, $18, $16);    /* r16 = a0 */          \
198
        psubh($2, $18, $19);    /* r19 = a3 */          \
199
        psubh($3, $17, $18);    /* r18 = a2 */          \
200
        paddh($3, $17, $17);    /* r17 = a1 */
201

    
202

    
203
#define DCT_8_INV_COL8_STORE(blk) \
204
\
205
        paddh($16, $20, $2);    /* y0  a0+b0 */ \
206
        psubh($16, $20, $16);   /* y7  a0-b0 */ \
207
        psrah($2, SHIFT_INV_COL, $2);           \
208
        psrah($16, SHIFT_INV_COL, $16);         \
209
        sq($2, 0, blk);                         \
210
        sq($16, 112, blk);                      \
211
\
212
        paddh($17, $21, $3);    /* y1  a1+b1 */ \
213
        psubh($17, $21, $17);   /* y6  a1-b1 */ \
214
        psrah($3, SHIFT_INV_COL, $3);           \
215
        psrah($17, SHIFT_INV_COL, $17);         \
216
        sq($3, 16, blk);                        \
217
        sq($17, 96, blk);                       \
218
\
219
        paddh($18, $22, $2);    /* y2  a2+b2 */ \
220
        psubh($18, $22, $18);   /* y5  a2-b2 */ \
221
        psrah($2, SHIFT_INV_COL, $2);           \
222
        psrah($18, SHIFT_INV_COL, $18);         \
223
        sq($2, 32, blk);                        \
224
        sq($18, 80, blk);                       \
225
\
226
        paddh($19, $23, $3);    /* y3  a3+b3 */ \
227
        psubh($19, $23, $19);   /* y4  a3-b3 */ \
228
        psrah($3, SHIFT_INV_COL, $3);           \
229
        psrah($19, SHIFT_INV_COL, $19);         \
230
        sq($3, 48, blk);                        \
231
        sq($19, 64, blk);
232

    
233

    
234

    
235
#define DCT_8_INV_COL8_PMS() \
236
        paddh($16, $20, $2);    /* y0  a0+b0 */ \
237
        psubh($16, $20, $20);   /* y7  a0-b0 */ \
238
        psrah($2, SHIFT_INV_COL, $16);          \
239
        psrah($20, SHIFT_INV_COL, $20);         \
240
\
241
        paddh($17, $21, $3);    /* y1  a1+b1 */ \
242
        psubh($17, $21, $21);   /* y6  a1-b1 */ \
243
        psrah($3, SHIFT_INV_COL, $17);          \
244
        psrah($21, SHIFT_INV_COL, $21);         \
245
\
246
        paddh($18, $22, $2);    /* y2  a2+b2 */ \
247
        psubh($18, $22, $22);   /* y5  a2-b2 */ \
248
        psrah($2, SHIFT_INV_COL, $18);          \
249
        psrah($22, SHIFT_INV_COL, $22);         \
250
\
251
        paddh($19, $23, $3);    /* y3  a3+b3 */ \
252
        psubh($19, $23, $23);   /* y4  a3-b3 */ \
253
        psrah($3, SHIFT_INV_COL, $19);          \
254
        psrah($23, SHIFT_INV_COL, $23);
255

    
256
#define PUT(rs)                 \
257
        pminh(rs, $11, $2);     \
258
        pmaxh($2, $0, $2);      \
259
        ppacb($0, $2, $2);      \
260
        sd3(2, 0, 4);           \
261
        __asm__ __volatile__ ("add $4, $5, $4");
262

    
263
#define DCT_8_INV_COL8_PUT() \
264
        PUT($16);        \
265
        PUT($17);        \
266
        PUT($18);        \
267
        PUT($19);        \
268
        PUT($23);        \
269
        PUT($22);        \
270
        PUT($21);        \
271
        PUT($20);
272

    
273
#define ADD(rs)          \
274
        ld3(4, 0, 2);        \
275
        pextlb($0, $2, $2);  \
276
        paddh($2, rs, $2);   \
277
        pminh($2, $11, $2);  \
278
        pmaxh($2, $0, $2);   \
279
        ppacb($0, $2, $2);   \
280
        sd3(2, 0, 4); \
281
        __asm__ __volatile__ ("add $4, $5, $4");
282

    
283
/*fixme: schedule*/
284
#define DCT_8_INV_COL8_ADD() \
285
        ADD($16);        \
286
        ADD($17);        \
287
        ADD($18);        \
288
        ADD($19);        \
289
        ADD($23);        \
290
        ADD($22);        \
291
        ADD($21);        \
292
        ADD($20);
293

    
294

    
295
void ff_mmi_idct(int16_t * block)
296
{
297
        /* $4 = block */
298
        __asm__ __volatile__("la $24, %0"::"m"(consttable[0]));
299
        lq($24, ROUNDER_0, $8);
300
        lq($24, ROUNDER_1, $7);
301
        DCT_8_INV_ROW1($4, 0, TAB_i_04, $8, $8);
302
        DCT_8_INV_ROW1($4, 16, TAB_i_17, $7, $9);
303
        DCT_8_INV_ROW1($4, 32, TAB_i_26, $7, $10);
304
        DCT_8_INV_ROW1($4, 48, TAB_i_35, $7, $11);
305
        DCT_8_INV_ROW1($4, 64, TAB_i_04, $7, $12);
306
        DCT_8_INV_ROW1($4, 80, TAB_i_35, $7, $13);
307
        DCT_8_INV_ROW1($4, 96, TAB_i_26, $7, $14);
308
        DCT_8_INV_ROW1($4, 112, TAB_i_17, $7, $15);
309
        DCT_8_INV_COL8();
310
        DCT_8_INV_COL8_STORE($4);
311

    
312
        //let savedtemp regs be saved
313
        __asm__ __volatile__(" ":::"$16", "$17", "$18", "$19", "$20", "$21", "$22", "$23");
314
}
315

    
316

    
317
void ff_mmi_idct_put(uint8_t *dest, int line_size, DCTELEM *block)
318
{
319
        /* $4 = dest, $5 = line_size, $6 = block */
320
        __asm__ __volatile__("la $24, %0"::"m"(consttable[0]));
321
        lq($24, ROUNDER_0, $8);
322
        lq($24, ROUNDER_1, $7);
323
        DCT_8_INV_ROW1($6, 0, TAB_i_04, $8, $8);
324
        DCT_8_INV_ROW1($6, 16, TAB_i_17, $7, $9);
325
        DCT_8_INV_ROW1($6, 32, TAB_i_26, $7, $10);
326
        DCT_8_INV_ROW1($6, 48, TAB_i_35, $7, $11);
327
        DCT_8_INV_ROW1($6, 64, TAB_i_04, $7, $12);
328
        DCT_8_INV_ROW1($6, 80, TAB_i_35, $7, $13);
329
        DCT_8_INV_ROW1($6, 96, TAB_i_26, $7, $14);
330
        DCT_8_INV_ROW1($6, 112, TAB_i_17, $7, $15);
331
        DCT_8_INV_COL8();
332
        lq($24, CLIPMAX, $11);
333
        DCT_8_INV_COL8_PMS();
334
        DCT_8_INV_COL8_PUT();
335

    
336
        //let savedtemp regs be saved
337
        __asm__ __volatile__(" ":::"$16", "$17", "$18", "$19", "$20", "$21", "$22", "$23");
338
}
339

    
340

    
341
void ff_mmi_idct_add(uint8_t *dest, int line_size, DCTELEM *block)
342
{
343
        /* $4 = dest, $5 = line_size, $6 = block */
344
        __asm__ __volatile__("la $24, %0"::"m"(consttable[0]));
345
        lq($24, ROUNDER_0, $8);
346
        lq($24, ROUNDER_1, $7);
347
        DCT_8_INV_ROW1($6, 0, TAB_i_04, $8, $8);
348
        DCT_8_INV_ROW1($6, 16, TAB_i_17, $7, $9);
349
        DCT_8_INV_ROW1($6, 32, TAB_i_26, $7, $10);
350
        DCT_8_INV_ROW1($6, 48, TAB_i_35, $7, $11);
351
        DCT_8_INV_ROW1($6, 64, TAB_i_04, $7, $12);
352
        DCT_8_INV_ROW1($6, 80, TAB_i_35, $7, $13);
353
        DCT_8_INV_ROW1($6, 96, TAB_i_26, $7, $14);
354
        DCT_8_INV_ROW1($6, 112, TAB_i_17, $7, $15);
355
        DCT_8_INV_COL8();
356
        lq($24, CLIPMAX, $11);
357
        DCT_8_INV_COL8_PMS();
358
        DCT_8_INV_COL8_ADD();
359

    
360
        //let savedtemp regs be saved
361
        __asm__ __volatile__(" ":::"$16", "$17", "$18", "$19", "$20", "$21", "$22", "$23");
362
}
363