FFmpeg
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
xvid_idct_mmi.c
Go to the documentation of this file.
1 /*
2  * Loongson SIMD optimized xvid idct
3  *
4  * Copyright (c) 2015 Loongson Technology Corporation Limited
5  * Copyright (c) 2015 Zhou Xiaoyong <zhouxiaoyong@loongson.cn>
6  *
7  * This file is part of FFmpeg.
8  *
9  * FFmpeg is free software; you can redistribute it and/or
10  * modify it under the terms of the GNU Lesser General Public
11  * License as published by the Free Software Foundation; either
12  * version 2.1 of the License, or (at your option) any later version.
13  *
14  * FFmpeg is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17  * Lesser General Public License for more details.
18  *
19  * You should have received a copy of the GNU Lesser General Public
20  * License along with FFmpeg; if not, write to the Free Software
21  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
22  */
23 
24 #include "idctdsp_mips.h"
25 #include "xvididct_mips.h"
26 
27 #define BITS_INV_ACC 5 // 4 or 5 for IEEE
28 #define SHIFT_INV_ROW (16 - BITS_INV_ACC) //11
29 #define SHIFT_INV_COL (1 + BITS_INV_ACC) //6
30 #define RND_INV_ROW (1024 * (6 - BITS_INV_ACC))
31 #define RND_INV_COL (16 * (BITS_INV_ACC - 3))
32 #define RND_INV_CORR (RND_INV_COL - 1)
33 
34 #define BITS_FRW_ACC 3 // 2 or 3 for accuracy
35 #define SHIFT_FRW_COL BITS_FRW_ACC
36 #define SHIFT_FRW_ROW (BITS_FRW_ACC + 17)
37 #define RND_FRW_ROW (262144*(BITS_FRW_ACC - 1))
38 
39 DECLARE_ALIGNED(8, static const int16_t, tg_1_16)[4*4] = {
40  13036, 13036, 13036, 13036, // tg * (2<<16) + 0.5
41  27146, 27146, 27146, 27146, // tg * (2<<16) + 0.5
42  -21746,-21746,-21746,-21746, // tg * (2<<16) + 0.5
43  23170, 23170, 23170, 23170 // cos * (2<<15) + 0.5
44 };
45 
46 DECLARE_ALIGNED(8, static const int32_t, rounder_0)[2*8] = {
47  65536,65536,
48  3597, 3597,
49  2260, 2260,
50  1203, 1203,
51  0, 0,
52  120, 120,
53  512, 512,
54  512, 512
55 };
56 
57 DECLARE_ALIGNED(8, static const int16_t, tab_i_04_mmi)[32*4] = {
58  16384, 21407, 16384, 8867, // w05 w04 w01 w00
59  16384, 8867,-16384,-21407, // w07 w06 w03 w02
60  16384, -8867, 16384,-21407, // w13 w12 w09 w08
61  -16384, 21407, 16384, -8867, // w15 w14 w11 w10
62  22725, 19266, 19266, -4520, // w21 w20 w17 w16
63  12873, 4520,-22725,-12873, // w23 w22 w19 w18
64  12873,-22725, 4520,-12873, // w29 w28 w25 w24
65  4520, 19266, 19266,-22725, // w31 w30 w27 w26
66 
67  22725, 29692, 22725, 12299, // w05 w04 w01 w00
68  22725, 12299,-22725,-29692, // w07 w06 w03 w02
69  22725,-12299, 22725,-29692, // w13 w12 w09 w08
70  -22725, 29692, 22725,-12299, // w15 w14 w11 w10
71  31521, 26722, 26722, -6270, // w21 w20 w17 w16
72  17855, 6270,-31521,-17855, // w23 w22 w19 w18
73  17855,-31521, 6270,-17855, // w29 w28 w25 w24
74  6270, 26722, 26722,-31521, // w31 w30 w27 w26
75 
76  21407, 27969, 21407, 11585, // w05 w04 w01 w00
77  21407, 11585,-21407,-27969, // w07 w06 w03 w02
78  21407,-11585, 21407,-27969, // w13 w12 w09 w08
79  -21407, 27969, 21407,-11585, // w15 w14 w11 w10
80  29692, 25172, 25172, -5906, // w21 w20 w17 w16
81  16819, 5906,-29692,-16819, // w23 w22 w19 w18
82  16819,-29692, 5906,-16819, // w29 w28 w25 w24
83  5906, 25172, 25172,-29692, // w31 w30 w27 w26
84 
85  19266, 25172, 19266, 10426, // w05 w04 w01 w00
86  19266, 10426,-19266,-25172, // w07 w06 w03 w02
87  19266,-10426, 19266,-25172, // w13 w12 w09 w08
88  -19266, 25172, 19266,-10426, // w15 w14 w11 w10
89  26722, 22654, 22654, -5315, // w21 w20 w17 w16
90  15137, 5315,-26722,-15137, // w23 w22 w19 w18
91  15137,-26722, 5315,-15137, // w29 w28 w25 w24
92  5315, 22654, 22654,-26722, // w31 w30 w27 w26
93 };
94 
95 #define DCT_8_INV_ROW_MMI(A1,A2,A3,A4) \
96  "dli $10, 0x88 \n\t" \
97  "ldc1 $f4, "#A1" \n\t" /* 0; x3 x2 x1 x0 */\
98  "dmtc1 $10, $f16 \n\t" \
99  "ldc1 $f10, 8+"#A1" \n\t" /* 1; x7 x6 x5 x4 */\
100  "ldc1 $f6, "#A3" \n\t" /* 3; w05 w04 w01 w00 */\
101  "pshufh $f0, $f4, $f16 \n\t" /* x2 x0 x2 x0 */\
102  "ldc1 $f8, 8+"#A3" \n\t" /* 4; w07 w06 w03 w02 */\
103  "ldc1 $f12, 32+"#A3" \n\t" /* 6; w21 w20 w17 w16 */\
104  "pmaddhw $f6, $f6, $f0 \n\t" /* x2*w05+x0*w04 x2*w01+x0*w00 */\
105  "dli $10, 0xdd \n\t" \
106  "pshufh $f2, $f10, $f16 \n\t" /* x6 x4 x6 x4 */\
107  "dmtc1 $10, $f16 \n\t" \
108  "pmaddhw $f8, $f8, $f2 \n\t" /* x6*w07+x4*w06 x6*w03+x4*w02 */\
109  "ldc1 $f14, 40+"#A3" \n\t" /* 7; w23 w22 w19 w18 */\
110  "pshufh $f4, $f4, $f16 \n\t" /* x3 x1 x3 x1 */\
111  "pmaddhw $f12, $f12, $f4 \n\t" /* x3*w21+x1*w20 x3*w17+x1*w16 */\
112  "pshufh $f10, $f10, $f16 \n\t" /* x7 x5 x7 x5 */\
113  "ldc1 $f18, "#A4" \n\t" \
114  "pmaddhw $f14, $f14, $f10 \n\t" /* x7*w23+x5*w22 x7*w19+x5*w18 */\
115  "paddw $f6, $f6, $f18 \n\t" /* +%4 */\
116  "ldc1 $f16, 16+"#A3" \n\t" \
117  "pmaddhw $f0, $f0, $f16 \n\t" /* x2*w13+x0*w12 x2*w09+x0*w08 */\
118  "ldc1 $f16, 24+"#A3" \n\t" \
119  "paddw $f6, $f6, $f8 \n\t" /* 4; a1=sum(even1) a0=sum(even0) */\
120  "pmaddhw $f2, $f2, $f16 \n\t" /* x6*w15+x4*w14 x6*w11+x4*w10 */\
121  "ldc1 $f16, 48+"#A3" \n\t" \
122  "pmaddhw $f4, $f4, $f16 \n\t" /* x3*w29+x1*w28 x3*w25+x1*w24 */\
123  "ldc1 $f16, 56+"#A3" \n\t" \
124  "paddw $f12, $f12, $f14 \n\t" /* 7; b1=sum(odd1) b0=sum(odd0) */\
125  "dli $10, 11 \n\t" \
126  "pmaddhw $f10, $f10, $f16 \n\t" /* x7*w31+x5*w30 x7*w27+x5*w26 */\
127  "dmtc1 $10, $f16 \n\t" \
128  "psubw $f8, $f6, $f12 \n\t" /* 6; a1-b1 a0-b0 */\
129  "paddw $f6, $f6, $f12 \n\t" /* a1+b1 a0+b0 */\
130  "paddw $f0, $f0, $f18 \n\t" /* +%4 */\
131  "psraw $f6, $f6, $f16 \n\t" /* y1=a1+b1 y0=a0+b0 */\
132  "paddw $f0, $f0, $f2 \n\t" /* 1; a3=sum(even3) a2=sum(even2) */\
133  "paddw $f4, $f4, $f10 \n\t" /* 5; b3=sum(odd3) b2=sum(odd2) */\
134  "psraw $f8, $f8, $f16 \n\t" /* y6=a1-b1 y7=a0-b0 */\
135  "psubw $f14, $f0, $f4 \n\t" /* 2; a3-b3 a2-b2 */\
136  "paddw $f0, $f0, $f4 \n\t" /* a3+b3 a2+b2 */\
137  "psraw $f0, $f0, $f16 \n\t" /* y3=a3+b3 y2=a2+b2 */\
138  "psraw $f14, $f14, $f16 \n\t" /* y4=a3-b3 y5=a2-b2 */\
139  "dli $10, 0xb1 \n\t" \
140  "packsswh $f6, $f6, $f0 \n\t" /* 0; y3 y2 y1 y0 */\
141  "dmtc1 $10, $f16 \n\t" \
142  "packsswh $f14, $f14, $f8 \n\t" /* 4; y6 y7 y4 y5 */\
143  "sdc1 $f6, "#A2" \n\t" /* 3; save y3 y2 y1 y0 */\
144  "pshufh $f14, $f14, $f16 \n\t" /* y7 y6 y5 y4 */\
145  "sdc1 $f14, 8+"#A2" \n\t" /* 7; save y7 y6 y5 y4 */\
146 
147 
148 #define DCT_8_INV_COL(A1,A2) \
149  "ldc1 $f2, 2*8(%3) \n\t" \
150  "ldc1 $f6, 16*3+"#A1" \n\t" \
151  "ldc1 $f10, 16*5+"#A1" \n\t" \
152  "pmulhh $f0, $f2, $f6 \n\t" /* x3*(tg_3_16-1) */\
153  "ldc1 $f4, 0(%3) \n\t" \
154  "pmulhh $f2, $f2, $f10 \n\t" /* x5*(tg_3_16-1) */\
155  "ldc1 $f14, 16*7+"#A1" \n\t" \
156  "ldc1 $f12, 16*1+"#A1" \n\t" \
157  "pmulhh $f8, $f4, $f14 \n\t" /* x7*tg_1_16 */\
158  "paddsh $f0, $f0, $f6 \n\t" /* x3*tg_3_16 */\
159  "pmulhh $f4, $f4, $f12 \n\t" /* x1*tg_1_16 */\
160  "paddsh $f2, $f2, $f6 \n\t" /* x3+x5*(tg_3_16-1) */\
161  "psubsh $f0, $f0, $f10 \n\t" /* x3*tg_3_16-x5 = tm35 */\
162  "ldc1 $f6, 3*8(%3) \n\t" \
163  "paddsh $f2, $f2, $f10 \n\t" /* x3+x5*tg_3_16 = tp35 */\
164  "paddsh $f8, $f8, $f12 \n\t" /* x1+tg_1_16*x7 = tp17 */\
165  "psubsh $f4, $f4, $f14 \n\t" /* x1*tg_1_16-x7 = tm17 */\
166  "paddsh $f10, $f8, $f2 \n\t" /* tp17+tp35 = b0 */\
167  "psubsh $f12, $f4, $f0 \n\t" /* tm17-tm35 = b3 */\
168  "psubsh $f8, $f8, $f2 \n\t" /* tp17-tp35 = t1 */\
169  "paddsh $f4, $f4, $f0 \n\t" /* tm17+tm35 = t2 */\
170  "ldc1 $f14, 1*8(%3) \n\t" \
171  "sdc1 $f10, 3*16+"#A2" \n\t" /* save b0 */\
172  "paddsh $f2, $f8, $f4 \n\t" /* t1+t2 */\
173  "sdc1 $f12, 5*16+"#A2" \n\t" /* save b3 */\
174  "psubsh $f8, $f8, $f4 \n\t" /* t1-t2 */\
175  "ldc1 $f10, 2*16+"#A1" \n\t" \
176  "ldc1 $f12, 6*16+"#A1" \n\t" \
177  "pmulhh $f0, $f14, $f10 \n\t" /* x2*tg_2_16 */\
178  "pmulhh $f14, $f14, $f12 \n\t" /* x6*tg_2_16 */\
179  "pmulhh $f2, $f2, $f6 \n\t" /* ocos_4_16*(t1+t2) = b1/2 */\
180  "ldc1 $f4, 0*16+"#A1" \n\t" \
181  "pmulhh $f8, $f8, $f6 \n\t" /* ocos_4_16*(t1-t2) = b2/2 */\
182  "psubsh $f0, $f0, $f12 \n\t" /* t2*tg_2_16-x6 = tm26 */\
183  "ldc1 $f12, 4*16+"#A1" \n\t" \
184  "paddsh $f14, $f14, $f10 \n\t" /* x2+x6*tg_2_16 = tp26 */\
185  "psubsh $f6, $f4, $f12 \n\t" /* x0-x4 = tm04 */\
186  "paddsh $f4, $f4, $f12 \n\t" /* x0+x4 = tp04 */\
187  "paddsh $f10, $f4, $f14 \n\t" /* tp04+tp26 = a0 */\
188  "psubsh $f12, $f6, $f0 \n\t" /* tm04-tm26 = a2 */\
189  "psubsh $f4, $f4, $f14 \n\t" /* tp04-tp26 = a3 */\
190  "paddsh $f6, $f6, $f0 \n\t" /* tm04+tm26 = a1 */\
191  "paddsh $f2, $f2, $f2 \n\t" /* b1 */\
192  "paddsh $f8, $f8, $f8 \n\t" /* b2 */\
193  "psubsh $f14, $f6, $f2 \n\t" /* a1-b1 */\
194  "dli $10, 6 \n\t" \
195  "paddsh $f6, $f6, $f2 \n\t" /* a1+b1 */\
196  "dmtc1 $10, $f16 \n\t" \
197  "psubsh $f0, $f12, $f8 \n\t" /* a2-b2 */\
198  "paddsh $f12, $f12, $f8 \n\t" /* a2+b2 */\
199  "psrah $f6, $f6, $f16 \n\t" /* dst1 */\
200  "psrah $f12, $f12, $f16 \n\t" /* dst2 */\
201  "ldc1 $f2, 3*16+"#A2" \n\t" /* load b0 */\
202  "psrah $f14, $f14, $f16 \n\t" /* dst6 */\
203  "psrah $f0, $f0, $f16 \n\t" /* dst5 */\
204  "sdc1 $f6, 1*16+"#A2" \n\t" \
205  "psubsh $f8, $f10, $f2 \n\t" /* a0-b0 */\
206  "paddsh $f10, $f10, $f2 \n\t" /* a0+b0 */\
207  "sdc1 $f12, 2*16+"#A2" \n\t" \
208  "ldc1 $f6, 5*16+"#A2" \n\t" /* load b3 */\
209  "psrah $f10, $f10, $f16 \n\t" /* dst0 */\
210  "psrah $f8, $f8, $f16 \n\t" /* dst7 */\
211  "sdc1 $f0, 5*16+"#A2" \n\t" \
212  "psubsh $f12, $f4, $f6 \n\t" /* a3-b3 */\
213  "paddsh $f4, $f4, $f6 \n\t" /* a3+b3 */\
214  "sdc1 $f14, 6*16+"#A2" \n\t" \
215  "sdc1 $f10, 0*16+"#A2" \n\t" \
216  "psrah $f4, $f4, $f16 \n\t" /* dst3 */\
217  "sdc1 $f8, 7*16+"#A2" \n\t" \
218  "psrah $f12, $f12, $f16 \n\t" /* dst4 */\
219  "sdc1 $f4, 3*16+"#A2" \n\t" \
220  "sdc1 $f12, 4*16+"#A2" \n\t" \
221 
222 
223 void ff_xvid_idct_mmi(int16_t *block)
224 {
225  __asm__ volatile (
226  //# Process each row
227  DCT_8_INV_ROW_MMI(0*16(%0), 0*16(%0), 64*0(%2), 8*0(%1))
228  DCT_8_INV_ROW_MMI(1*16(%0), 1*16(%0), 64*1(%2), 8*1(%1))
229  DCT_8_INV_ROW_MMI(2*16(%0), 2*16(%0), 64*2(%2), 8*2(%1))
230  DCT_8_INV_ROW_MMI(3*16(%0), 3*16(%0), 64*3(%2), 8*3(%1))
231  DCT_8_INV_ROW_MMI(4*16(%0), 4*16(%0), 64*0(%2), 8*4(%1))
232  DCT_8_INV_ROW_MMI(5*16(%0), 5*16(%0), 64*3(%2), 8*5(%1))
233  DCT_8_INV_ROW_MMI(6*16(%0), 6*16(%0), 64*2(%2), 8*6(%1))
234  DCT_8_INV_ROW_MMI(7*16(%0), 7*16(%0), 64*1(%2), 8*7(%1))
235  //# Process the columns (4 at a time)
236  DCT_8_INV_COL(0(%0), 0(%0))
237  DCT_8_INV_COL(8(%0), 8(%0))
238  ::"r"(block),"r"(rounder_0),"r"(tab_i_04_mmi),"r"(tg_1_16)
239  : "$10"
240  );
241 }
242 
243 void ff_xvid_idct_put_mmi(uint8_t *dest, int32_t line_size, int16_t *block)
244 {
245  ff_xvid_idct_mmi(block);
246  ff_put_pixels_clamped_mmi(block, dest, line_size);
247 }
248 
249 void ff_xvid_idct_add_mmi(uint8_t *dest, int32_t line_size, int16_t *block)
250 {
251  ff_xvid_idct_mmi(block);
252  ff_add_pixels_clamped_mmi(block, dest, line_size);
253 }
static const int32_t rounder_0[2 *8]
Definition: xvid_idct_mmi.c:46
void ff_xvid_idct_add_mmi(uint8_t *dest, int32_t line_size, int16_t *block)
void ff_xvid_idct_put_mmi(uint8_t *dest, int32_t line_size, int16_t *block)
static const int16_t tab_i_04_mmi[32 *4]
Definition: xvid_idct_mmi.c:57
static int16_t block[64]
Definition: dct.c:115
void ff_add_pixels_clamped_mmi(const int16_t *block, uint8_t *av_restrict pixels, ptrdiff_t line_size)
Definition: idctdsp_mmi.c:150
uint8_t
#define DECLARE_ALIGNED(n, t, v)
Declare a variable that is aligned in memory.
Definition: mem.h:112
static const int16_t tg_1_16[4 *4]
Definition: xvid_idct_mmi.c:39
void ff_put_pixels_clamped_mmi(const int16_t *block, uint8_t *av_restrict pixels, ptrdiff_t line_size)
Definition: idctdsp_mmi.c:28
int32_t
#define DCT_8_INV_COL(A1, A2)
void ff_xvid_idct_mmi(int16_t *block)
#define DCT_8_INV_ROW_MMI(A1, A2, A3, A4)
Definition: xvid_idct_mmi.c:95