]> git.sesse.net Git - ffmpeg/blob - libavcodec/mips/vc1dsp_mmi.c
lavu: move LOCAL_ALIGNED from internal.h to mem_internal.h
[ffmpeg] / libavcodec / mips / vc1dsp_mmi.c
1 /*
2  * VC-1 and WMV3 - DSP functions Loongson MMI-optimized
3  *
4  * Copyright (c) 2016 Zhou Xiaoyong <zhouxiaoyong@loongson.cn>
5  *
6  * This file is part of FFmpeg.
7  *
8  * FFmpeg is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU Lesser General Public
10  * License as published by the Free Software Foundation; either
11  * version 2.1 of the License, or (at your option) any later version.
12  *
13  * FFmpeg is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16  * Lesser General Public License for more details.
17  *
18  * You should have received a copy of the GNU Lesser General Public
19  * License along with FFmpeg; if not, write to the Free Software
20  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21  */
22
23 #include "libavutil/avassert.h"
24 #include "libavcodec/vc1dsp.h"
25 #include "constants.h"
26 #include "vc1dsp_mips.h"
27 #include "hpeldsp_mips.h"
28 #include "libavutil/mem_internal.h"
29 #include "libavutil/mips/mmiutils.h"
30
31 #define VC1_INV_TRANCS_8_TYPE1(o1, o2, r1, r2, r3, r4, c0)                  \
32         "li         %[tmp0],    "#r1"                                 \n\t" \
33         "mtc1       %[tmp0],    %[ftmp13]                             \n\t" \
34         "punpcklwd  %[ftmp13],  %[ftmp13],  %[ftmp13]                 \n\t" \
35         "li         %[tmp0],    "#r2"                                 \n\t" \
36         "mtc1       %[tmp0],    %[ftmp14]                             \n\t" \
37         "punpcklwd  %[ftmp14],  %[ftmp14],  %[ftmp14]                 \n\t" \
38         "pmaddhw    %[ftmp1],   %[ftmp5],   %[ftmp13]                 \n\t" \
39         "pmaddhw    %[ftmp2],   %[ftmp7],   %[ftmp14]                 \n\t" \
40         "paddw      %[ftmp1],   %[ftmp1],   %[ftmp2]                  \n\t" \
41         "pmaddhw    %[ftmp2],   %[ftmp6],   %[ftmp13]                 \n\t" \
42         "pmaddhw    %[ftmp3],   %[ftmp8],   %[ftmp14]                 \n\t" \
43         "paddw      %[ftmp2],   %[ftmp2],   %[ftmp3]                  \n\t" \
44                                                                             \
45         "li         %[tmp0],    "#r3"                                 \n\t" \
46         "mtc1       %[tmp0],    %[ftmp13]                             \n\t" \
47         "punpcklwd  %[ftmp13],  %[ftmp13],  %[ftmp13]                 \n\t" \
48         "li         %[tmp0],    "#r4"                                 \n\t" \
49         "mtc1       %[tmp0],    %[ftmp14]                             \n\t" \
50         "punpcklwd  %[ftmp14],  %[ftmp14],  %[ftmp14]                 \n\t" \
51         "pmaddhw    %[ftmp3],   %[ftmp9],   %[ftmp13]                 \n\t" \
52         "pmaddhw    %[ftmp4],   %[ftmp11],  %[ftmp14]                 \n\t" \
53         "paddw      %[ftmp3],   %[ftmp3],   %[ftmp4]                  \n\t" \
54         "pmaddhw    %[ftmp4],   %[ftmp10],  %[ftmp13]                 \n\t" \
55         "pmaddhw    %[ftmp13],  %[ftmp12],  %[ftmp14]                 \n\t" \
56         "paddw      %[ftmp4],   %[ftmp4],   %[ftmp13]                 \n\t" \
57                                                                             \
58         "paddw      %[ftmp1],   %[ftmp1],   "#c0"                     \n\t" \
59         "paddw      %[ftmp2],   %[ftmp2],   "#c0"                     \n\t" \
60         "paddw      %[ftmp13],  %[ftmp1],   %[ftmp3]                  \n\t" \
61         "psubw      %[ftmp14],  %[ftmp1],   %[ftmp3]                  \n\t" \
62         "paddw      %[ftmp1],   %[ftmp2],   %[ftmp4]                  \n\t" \
63         "psubw      %[ftmp3],   %[ftmp2],   %[ftmp4]                  \n\t" \
64         "psraw      %[ftmp13],  %[ftmp13],  %[ftmp0]                  \n\t" \
65         "psraw      %[ftmp1],   %[ftmp1],   %[ftmp0]                  \n\t" \
66         "psraw      %[ftmp14],  %[ftmp14],  %[ftmp0]                  \n\t" \
67         "psraw      %[ftmp3],   %[ftmp3],   %[ftmp0]                  \n\t" \
68         "punpcklhw  %[ftmp2],   %[ftmp13],  %[ftmp1]                  \n\t" \
69         "punpckhhw  %[ftmp4],   %[ftmp13],  %[ftmp1]                  \n\t" \
70         "punpcklhw  "#o1",      %[ftmp2],   %[ftmp4]                  \n\t" \
71         "punpcklhw  %[ftmp2],   %[ftmp14],  %[ftmp3]                  \n\t" \
72         "punpckhhw  %[ftmp4],   %[ftmp14],  %[ftmp3]                  \n\t" \
73         "punpcklhw  "#o2",      %[ftmp2],   %[ftmp4]                  \n\t"
74
75 #define VC1_INV_TRANCS_8_TYPE2(o1, o2, r1, r2, r3, r4, c0, c1)              \
76         "li         %[tmp0],    "#r1"                                 \n\t" \
77         "mtc1       %[tmp0],    %[ftmp13]                             \n\t" \
78         "punpcklwd  %[ftmp13],  %[ftmp13],  %[ftmp13]                 \n\t" \
79         "li         %[tmp0],    "#r2"                                 \n\t" \
80         "mtc1       %[tmp0],    %[ftmp14]                             \n\t" \
81         "punpcklwd  %[ftmp14],  %[ftmp14],  %[ftmp14]                 \n\t" \
82         "pmaddhw    %[ftmp1],   %[ftmp5],   %[ftmp13]                 \n\t" \
83         "pmaddhw    %[ftmp2],   %[ftmp7],   %[ftmp14]                 \n\t" \
84         "paddw      %[ftmp1],   %[ftmp1],   %[ftmp2]                  \n\t" \
85         "pmaddhw    %[ftmp2],   %[ftmp6],   %[ftmp13]                 \n\t" \
86         "pmaddhw    %[ftmp3],   %[ftmp8],   %[ftmp14]                 \n\t" \
87         "paddw      %[ftmp2],   %[ftmp2],   %[ftmp3]                  \n\t" \
88                                                                             \
89         "li         %[tmp0],    "#r3"                                 \n\t" \
90         "mtc1       %[tmp0],    %[ftmp13]                             \n\t" \
91         "punpcklwd  %[ftmp13],  %[ftmp13],  %[ftmp13]                 \n\t" \
92         "li         %[tmp0],    "#r4"                                 \n\t" \
93         "mtc1       %[tmp0],    %[ftmp14]                             \n\t" \
94         "punpcklwd  %[ftmp14],  %[ftmp14],  %[ftmp14]                 \n\t" \
95         "pmaddhw    %[ftmp3],   %[ftmp9],   %[ftmp13]                 \n\t" \
96         "pmaddhw    %[ftmp4],   %[ftmp11],  %[ftmp14]                 \n\t" \
97         "paddw      %[ftmp3],   %[ftmp3],   %[ftmp4]                  \n\t" \
98         "pmaddhw    %[ftmp4],   %[ftmp10],  %[ftmp13]                 \n\t" \
99         "pmaddhw    %[ftmp13],  %[ftmp12],  %[ftmp14]                 \n\t" \
100         "paddw      %[ftmp4],   %[ftmp4],   %[ftmp13]                 \n\t" \
101                                                                             \
102         "paddw      %[ftmp13],  %[ftmp1],   %[ftmp3]                  \n\t" \
103         "psubw      %[ftmp14],  %[ftmp1],   %[ftmp3]                  \n\t" \
104         "paddw      %[ftmp14],  %[ftmp14],  "#c1"                     \n\t" \
105         "paddw      %[ftmp1],   %[ftmp2],   %[ftmp4]                  \n\t" \
106         "psubw      %[ftmp3],   %[ftmp2],   %[ftmp4]                  \n\t" \
107         "paddw      %[ftmp3],   %[ftmp3],   "#c1"                     \n\t" \
108         "paddw      %[ftmp13],  %[ftmp13],  "#c0"                     \n\t" \
109         "paddw      %[ftmp14],  %[ftmp14],  "#c0"                     \n\t" \
110         "paddw      %[ftmp1],   %[ftmp1],   "#c0"                     \n\t" \
111         "paddw      %[ftmp3],   %[ftmp3],   "#c0"                     \n\t" \
112         "psraw      %[ftmp13],  %[ftmp13],  %[ftmp0]                  \n\t" \
113         "psraw      %[ftmp1],   %[ftmp1],   %[ftmp0]                  \n\t" \
114         "psraw      %[ftmp14],  %[ftmp14],  %[ftmp0]                  \n\t" \
115         "psraw      %[ftmp3],   %[ftmp3],   %[ftmp0]                  \n\t" \
116         "punpcklhw  %[ftmp2],   %[ftmp13],  %[ftmp1]                  \n\t" \
117         "punpckhhw  %[ftmp4],   %[ftmp13],  %[ftmp1]                  \n\t" \
118         "punpcklhw  "#o1",      %[ftmp2],   %[ftmp4]                  \n\t" \
119         "punpcklhw  %[ftmp2],   %[ftmp14],  %[ftmp3]                  \n\t" \
120         "punpckhhw  %[ftmp4],   %[ftmp14],  %[ftmp3]                  \n\t" \
121         "punpcklhw  "#o2",      %[ftmp2],   %[ftmp4]                  \n\t"
122
123 /* Do inverse transform on 8x8 block */
124 void ff_vc1_inv_trans_8x8_dc_mmi(uint8_t *dest, ptrdiff_t linesize, int16_t *block)
125 {
126     int dc = block[0];
127     double ftmp[9];
128     mips_reg addr[1];
129     int count;
130
131     dc = (3 * dc +  1) >> 1;
132     dc = (3 * dc + 16) >> 5;
133
134     __asm__ volatile(
135         "xor        %[ftmp0],   %[ftmp0],       %[ftmp0]                \n\t"
136         "pshufh     %[dc],      %[dc],          %[ftmp0]                \n\t"
137         "li         %[count],   0x02                                    \n\t"
138
139         "1:                                                             \n\t"
140         MMI_LDC1(%[ftmp1], %[dest], 0x00)
141         PTR_ADDU   "%[addr0],   %[dest],        %[linesize]             \n\t"
142         MMI_LDC1(%[ftmp2], %[addr0], 0x00)
143         PTR_ADDU   "%[addr0],   %[addr0],       %[linesize]             \n\t"
144         MMI_LDC1(%[ftmp3], %[addr0], 0x00)
145         PTR_ADDU   "%[addr0],   %[addr0],       %[linesize]             \n\t"
146         MMI_LDC1(%[ftmp4], %[addr0], 0x00)
147
148         "punpckhbh  %[ftmp5],   %[ftmp1],       %[ftmp0]                \n\t"
149         "punpcklbh  %[ftmp1],   %[ftmp1],       %[ftmp0]                \n\t"
150         "punpckhbh  %[ftmp6],   %[ftmp2],       %[ftmp0]                \n\t"
151         "punpcklbh  %[ftmp2],   %[ftmp2],       %[ftmp0]                \n\t"
152         "punpckhbh  %[ftmp7],   %[ftmp3],       %[ftmp0]                \n\t"
153         "punpcklbh  %[ftmp3],   %[ftmp3],       %[ftmp0]                \n\t"
154         "punpckhbh  %[ftmp8],   %[ftmp4],       %[ftmp0]                \n\t"
155         "punpcklbh  %[ftmp4],   %[ftmp4],       %[ftmp0]                \n\t"
156
157         "paddsh     %[ftmp1],   %[ftmp1],       %[dc]                   \n\t"
158         "paddsh     %[ftmp2],   %[ftmp2],       %[dc]                   \n\t"
159         "paddsh     %[ftmp3],   %[ftmp3],       %[dc]                   \n\t"
160         "paddsh     %[ftmp4],   %[ftmp4],       %[dc]                   \n\t"
161         "paddsh     %[ftmp5],   %[ftmp5],       %[dc]                   \n\t"
162         "paddsh     %[ftmp6],   %[ftmp6],       %[dc]                   \n\t"
163         "paddsh     %[ftmp7],   %[ftmp7],       %[dc]                   \n\t"
164         "paddsh     %[ftmp8],   %[ftmp8],       %[dc]                   \n\t"
165
166         "packushb   %[ftmp1],   %[ftmp1],       %[ftmp5]                \n\t"
167         "packushb   %[ftmp2],   %[ftmp2],       %[ftmp6]                \n\t"
168         "packushb   %[ftmp3],   %[ftmp3],       %[ftmp7]                \n\t"
169         "packushb   %[ftmp4],   %[ftmp4],       %[ftmp8]                \n\t"
170
171         MMI_SDC1(%[ftmp1], %[dest], 0x00)
172         PTR_ADDU   "%[addr0],   %[dest],        %[linesize]             \n\t"
173         MMI_SDC1(%[ftmp2], %[addr0], 0x00)
174         PTR_ADDU   "%[addr0],   %[addr0],       %[linesize]             \n\t"
175         MMI_SDC1(%[ftmp3], %[addr0], 0x00)
176         PTR_ADDU   "%[addr0],   %[addr0],       %[linesize]             \n\t"
177         MMI_SDC1(%[ftmp4], %[addr0], 0x00)
178
179         "addiu      %[count],   %[count],       -0x01                   \n\t"
180         PTR_ADDU   "%[dest],    %[addr0],       %[linesize]             \n\t"
181         "bnez       %[count],   1b                                      \n\t"
182         : [ftmp0]"=&f"(ftmp[0]),        [ftmp1]"=&f"(ftmp[1]),
183           [ftmp2]"=&f"(ftmp[2]),        [ftmp3]"=&f"(ftmp[3]),
184           [ftmp4]"=&f"(ftmp[4]),        [ftmp5]"=&f"(ftmp[5]),
185           [ftmp6]"=&f"(ftmp[6]),        [ftmp7]"=&f"(ftmp[7]),
186           [ftmp8]"=&f"(ftmp[8]),
187           [addr0]"=&r"(addr[0]),
188           [count]"=&r"(count),          [dest]"+&r"(dest)
189         : [linesize]"r"((mips_reg)linesize),
190           [dc]"f"(dc)
191         : "memory"
192     );
193 }
194
195 #if _MIPS_SIM != _ABIO32
196 void ff_vc1_inv_trans_8x8_mmi(int16_t block[64])
197 {
198     DECLARE_ALIGNED(16, int16_t, temp[64]);
199     DECLARE_ALIGNED(8, const uint64_t, ff_pw_1_local) = {0x0000000100000001ULL};
200     DECLARE_ALIGNED(8, const uint64_t, ff_pw_4_local) = {0x0000000400000004ULL};
201     DECLARE_ALIGNED(8, const uint64_t, ff_pw_64_local)= {0x0000004000000040ULL};
202     double ftmp[23];
203     uint64_t tmp[1];
204
205     __asm__ volatile (
206         /* 1st loop: start */
207         "li         %[tmp0],    0x03                                    \n\t"
208         "mtc1       %[tmp0],    %[ftmp0]                                \n\t"
209
210        // 1st part
211         MMI_LDC1(%[ftmp1], %[block], 0x00)
212         MMI_LDC1(%[ftmp11], %[block], 0x10)
213         MMI_LDC1(%[ftmp2], %[block], 0x20)
214         MMI_LDC1(%[ftmp12], %[block], 0x30)
215         MMI_LDC1(%[ftmp3], %[block], 0x40)
216         MMI_LDC1(%[ftmp13], %[block], 0x50)
217         MMI_LDC1(%[ftmp4], %[block], 0x60)
218         MMI_LDC1(%[ftmp14], %[block], 0x70)
219         "punpcklhw  %[ftmp5],   %[ftmp1],   %[ftmp2]                    \n\t"
220         "punpckhhw  %[ftmp6],   %[ftmp1],   %[ftmp2]                    \n\t"
221         "punpcklhw  %[ftmp7],   %[ftmp3],   %[ftmp4]                    \n\t"
222         "punpckhhw  %[ftmp8],   %[ftmp3],   %[ftmp4]                    \n\t"
223
224         "punpcklhw  %[ftmp9],  %[ftmp11],  %[ftmp12]                    \n\t"
225         "punpckhhw  %[ftmp10], %[ftmp11],  %[ftmp12]                    \n\t"
226         "punpcklhw  %[ftmp11], %[ftmp13],  %[ftmp14]                    \n\t"
227         "punpckhhw  %[ftmp12], %[ftmp13],  %[ftmp14]                    \n\t"
228
229         /* ftmp15:dst03,dst02,dst01,dst00 ftmp22:dst73,dst72,dst71,dst70 */
230         VC1_INV_TRANCS_8_TYPE1(%[ftmp15], %[ftmp22], 0x0010000c, 0x0006000c,
231                                0x000f0010, 0x00040009, %[ff_pw_4])
232
233         /* ftmp16:dst13,dst12,dst11,dst10 ftmp21:dst63,dst62,dst61,dst60 */
234         VC1_INV_TRANCS_8_TYPE1(%[ftmp16], %[ftmp21], 0x0006000c, 0xfff0fff4,
235                                0xfffc000f, 0xfff7fff0, %[ff_pw_4])
236
237         /* ftmp17:dst23,dst22,dst21,dst20 ftmp20:dst53,dst52,dst51,dst50 */
238         VC1_INV_TRANCS_8_TYPE1(%[ftmp17], %[ftmp20], 0xfffa000c, 0x0010fff4,
239                                0xfff00009, 0x000f0004, %[ff_pw_4])
240
241         /* ftmp18:dst33,dst32,dst31,dst30 ftmp19:dst43,dst42,dst41,dst40 */
242         VC1_INV_TRANCS_8_TYPE1(%[ftmp18], %[ftmp19], 0xfff0000c, 0xfffa000c,
243                                0xfff70004, 0xfff0000f, %[ff_pw_4])
244
245         TRANSPOSE_4H(%[ftmp15], %[ftmp16], %[ftmp17], %[ftmp18],
246                      %[ftmp1], %[ftmp2], %[ftmp3], %[ftmp4])
247
248         TRANSPOSE_4H(%[ftmp19], %[ftmp20], %[ftmp21], %[ftmp22],
249                      %[ftmp1], %[ftmp2], %[ftmp3], %[ftmp4])
250
251         MMI_SDC1(%[ftmp15], %[temp], 0x00)
252         MMI_SDC1(%[ftmp19], %[temp], 0x08)
253         MMI_SDC1(%[ftmp16], %[temp], 0x10)
254         MMI_SDC1(%[ftmp20], %[temp], 0x18)
255         MMI_SDC1(%[ftmp17], %[temp], 0x20)
256         MMI_SDC1(%[ftmp21], %[temp], 0x28)
257         MMI_SDC1(%[ftmp18], %[temp], 0x30)
258         MMI_SDC1(%[ftmp22], %[temp], 0x38)
259
260        // 2nd part
261         MMI_LDC1(%[ftmp1], %[block], 0x08)
262         MMI_LDC1(%[ftmp11], %[block], 0x18)
263         MMI_LDC1(%[ftmp2], %[block], 0x28)
264         MMI_LDC1(%[ftmp12], %[block], 0x38)
265         MMI_LDC1(%[ftmp3], %[block], 0x48)
266         MMI_LDC1(%[ftmp13], %[block], 0x58)
267         MMI_LDC1(%[ftmp4], %[block], 0x68)
268         MMI_LDC1(%[ftmp14], %[block], 0x78)
269         "punpcklhw  %[ftmp5],   %[ftmp1],   %[ftmp2]                    \n\t"
270         "punpckhhw  %[ftmp6],   %[ftmp1],   %[ftmp2]                    \n\t"
271         "punpcklhw  %[ftmp7],   %[ftmp3],   %[ftmp4]                    \n\t"
272         "punpckhhw  %[ftmp8],   %[ftmp3],   %[ftmp4]                    \n\t"
273
274         "punpcklhw  %[ftmp9],   %[ftmp11],  %[ftmp12]                   \n\t"
275         "punpckhhw  %[ftmp10],  %[ftmp11],  %[ftmp12]                   \n\t"
276         "punpcklhw  %[ftmp11],  %[ftmp13],  %[ftmp14]                   \n\t"
277         "punpckhhw  %[ftmp12],  %[ftmp13],  %[ftmp14]                   \n\t"
278
279         /* ftmp15:dst03,dst02,dst01,dst00 ftmp22:dst73,dst72,dst71,dst70 */
280         VC1_INV_TRANCS_8_TYPE1(%[ftmp15], %[ftmp22], 0x0010000c, 0x0006000c,
281                                0x000f0010, 0x00040009, %[ff_pw_4])
282
283         /* ftmp16:dst13,dst12,dst11,dst10 ftmp21:dst63,dst62,dst61,dst60 */
284         VC1_INV_TRANCS_8_TYPE1(%[ftmp16], %[ftmp21], 0x0006000c, 0xfff0fff4,
285                                0xfffc000f, 0xfff7fff0, %[ff_pw_4])
286
287         /* ftmp17:dst23,dst22,dst21,dst20 ftmp20:dst53,dst52,dst51,dst50 */
288         VC1_INV_TRANCS_8_TYPE1(%[ftmp17], %[ftmp20], 0xfffa000c, 0x0010fff4,
289                                0xfff00009, 0x000f0004, %[ff_pw_4])
290
291         /* ftmp18:dst33,dst32,dst31,dst30 ftmp19:dst43,dst42,dst41,dst40 */
292         VC1_INV_TRANCS_8_TYPE1(%[ftmp18], %[ftmp19], 0xfff0000c, 0xfffa000c,
293                                0xfff70004, 0xfff0000f, %[ff_pw_4])
294
295         TRANSPOSE_4H(%[ftmp15], %[ftmp16], %[ftmp17], %[ftmp18],
296                      %[ftmp1], %[ftmp2], %[ftmp3], %[ftmp4])
297
298         TRANSPOSE_4H(%[ftmp19], %[ftmp20], %[ftmp21], %[ftmp22],
299                      %[ftmp1], %[ftmp2], %[ftmp3], %[ftmp4])
300
301         MMI_SDC1(%[ftmp19], %[temp], 0x48)
302         MMI_SDC1(%[ftmp20], %[temp], 0x58)
303         MMI_SDC1(%[ftmp21], %[temp], 0x68)
304         MMI_SDC1(%[ftmp22], %[temp], 0x78)
305         /* 1st loop: end */
306
307         /* 2nd loop: start */
308         "li         %[tmp0],    0x07                                    \n\t"
309         "mtc1       %[tmp0],    %[ftmp0]                                \n\t"
310
311         // 1st part
312         MMI_LDC1(%[ftmp1], %[temp], 0x00)
313         MMI_LDC1(%[ftmp11], %[temp], 0x10)
314         MMI_LDC1(%[ftmp2], %[temp], 0x20)
315         MMI_LDC1(%[ftmp12], %[temp], 0x30)
316         "punpcklhw  %[ftmp5],   %[ftmp1],   %[ftmp2]                    \n\t"
317         "punpckhhw  %[ftmp6],   %[ftmp1],   %[ftmp2]                    \n\t"
318         "punpcklhw  %[ftmp7],   %[ftmp15],  %[ftmp17]                   \n\t"
319         "punpckhhw  %[ftmp8],   %[ftmp15],  %[ftmp17]                   \n\t"
320
321         "punpcklhw  %[ftmp9],   %[ftmp11],  %[ftmp12]                   \n\t"
322         "punpckhhw  %[ftmp10],  %[ftmp11],  %[ftmp12]                   \n\t"
323         "punpcklhw  %[ftmp11],  %[ftmp16],  %[ftmp18]                   \n\t"
324         "punpckhhw  %[ftmp12],  %[ftmp16],  %[ftmp18]                   \n\t"
325
326         /* ftmp15:dst03,dst02,dst01,dst00 ftmp22:dst73,dst72,dst71,dst70 */
327         VC1_INV_TRANCS_8_TYPE2(%[ftmp15], %[ftmp22], 0x0010000c, 0x0006000c,
328                                0x000f0010, 0x00040009, %[ff_pw_64], %[ff_pw_1])
329
330         /* ftmp16:dst13,dst12,dst11,dst10 ftmp21:dst63,dst62,dst61,dst60 */
331         VC1_INV_TRANCS_8_TYPE2(%[ftmp16], %[ftmp21], 0x0006000c, 0xfff0fff4,
332                                0xfffc000f, 0xfff7fff0, %[ff_pw_64], %[ff_pw_1])
333
334         /* ftmp17:dst23,dst22,dst21,dst20 ftmp20:dst53,dst52,dst51,dst50 */
335         VC1_INV_TRANCS_8_TYPE2(%[ftmp17], %[ftmp20], 0xfffa000c, 0x0010fff4,
336                                0xfff00009, 0x000f0004, %[ff_pw_64], %[ff_pw_1])
337
338         /* ftmp18:dst33,dst32,dst31,dst30 ftmp19:dst43,dst42,dst41,dst40 */
339         VC1_INV_TRANCS_8_TYPE2(%[ftmp18], %[ftmp19], 0xfff0000c, 0xfffa000c,
340                                0xfff70004, 0xfff0000f, %[ff_pw_64], %[ff_pw_1])
341
342         MMI_SDC1(%[ftmp15], %[block], 0x00)
343         MMI_SDC1(%[ftmp16], %[block], 0x10)
344         MMI_SDC1(%[ftmp17], %[block], 0x20)
345         MMI_SDC1(%[ftmp18], %[block], 0x30)
346         MMI_SDC1(%[ftmp19], %[block], 0x40)
347         MMI_SDC1(%[ftmp20], %[block], 0x50)
348         MMI_SDC1(%[ftmp21], %[block], 0x60)
349         MMI_SDC1(%[ftmp22], %[block], 0x70)
350
351        // 2nd part
352         MMI_LDC1(%[ftmp1], %[temp], 0x08)
353         MMI_LDC1(%[ftmp11], %[temp], 0x18)
354         MMI_LDC1(%[ftmp2], %[temp], 0x28)
355         MMI_LDC1(%[ftmp12], %[temp], 0x38)
356         MMI_LDC1(%[ftmp3], %[temp], 0x48)
357         MMI_LDC1(%[ftmp13], %[temp], 0x58)
358         MMI_LDC1(%[ftmp4], %[temp], 0x68)
359         MMI_LDC1(%[ftmp14], %[temp], 0x78)
360         "punpcklhw  %[ftmp5],   %[ftmp1],   %[ftmp2]                    \n\t"
361         "punpckhhw  %[ftmp6],   %[ftmp1],   %[ftmp2]                    \n\t"
362         "punpcklhw  %[ftmp7],   %[ftmp3],   %[ftmp4]                    \n\t"
363         "punpckhhw  %[ftmp8],   %[ftmp3],   %[ftmp4]                    \n\t"
364
365         "punpcklhw  %[ftmp9],   %[ftmp11],  %[ftmp12]                   \n\t"
366         "punpckhhw  %[ftmp10],  %[ftmp11],  %[ftmp12]                   \n\t"
367         "punpcklhw  %[ftmp11],  %[ftmp13],  %[ftmp14]                   \n\t"
368         "punpckhhw  %[ftmp12],  %[ftmp13],  %[ftmp14]                   \n\t"
369
370         /* ftmp15:dst03,dst02,dst01,dst00 ftmp22:dst73,dst72,dst71,dst70 */
371         VC1_INV_TRANCS_8_TYPE2(%[ftmp15], %[ftmp22], 0x0010000c, 0x0006000c,
372                                0x000f0010, 0x00040009, %[ff_pw_64], %[ff_pw_1])
373
374         /* ftmp16:dst13,dst12,dst11,dst10 ftmp21:dst63,dst62,dst61,dst60 */
375         VC1_INV_TRANCS_8_TYPE2(%[ftmp16], %[ftmp21], 0x0006000c, 0xfff0fff4,
376                                0xfffc000f, 0xfff7fff0, %[ff_pw_64], %[ff_pw_1])
377
378         /* ftmp17:dst23,dst22,dst21,dst20 ftmp20:dst53,dst52,dst51,dst50 */
379         VC1_INV_TRANCS_8_TYPE2(%[ftmp17], %[ftmp20], 0xfffa000c, 0x0010fff4,
380                                0xfff00009, 0x000f0004, %[ff_pw_64], %[ff_pw_1])
381
382         /* ftmp18:dst33,dst32,dst31,dst30 ftmp19:dst43,dst42,dst41,dst40 */
383         VC1_INV_TRANCS_8_TYPE2(%[ftmp18], %[ftmp19], 0xfff0000c, 0xfffa000c,
384                                0xfff70004, 0xfff0000f, %[ff_pw_64], %[ff_pw_1])
385
386         MMI_SDC1(%[ftmp15], %[block], 0x08)
387         MMI_SDC1(%[ftmp16], %[block], 0x18)
388         MMI_SDC1(%[ftmp17], %[block], 0x28)
389         MMI_SDC1(%[ftmp18], %[block], 0x38)
390         MMI_SDC1(%[ftmp19], %[block], 0x48)
391         MMI_SDC1(%[ftmp20], %[block], 0x58)
392         MMI_SDC1(%[ftmp21], %[block], 0x68)
393         MMI_SDC1(%[ftmp22], %[block], 0x78)
394         /* 2nd loop: end */
395         : [ftmp0]"=&f"(ftmp[0]),        [ftmp1]"=&f"(ftmp[1]),
396           [ftmp2]"=&f"(ftmp[2]),        [ftmp3]"=&f"(ftmp[3]),
397           [ftmp4]"=&f"(ftmp[4]),        [ftmp5]"=&f"(ftmp[5]),
398           [ftmp6]"=&f"(ftmp[6]),        [ftmp7]"=&f"(ftmp[7]),
399           [ftmp8]"=&f"(ftmp[8]),        [ftmp9]"=&f"(ftmp[9]),
400           [ftmp10]"=&f"(ftmp[10]),      [ftmp11]"=&f"(ftmp[11]),
401           [ftmp12]"=&f"(ftmp[12]),      [ftmp13]"=&f"(ftmp[13]),
402           [ftmp14]"=&f"(ftmp[14]),      [ftmp15]"=&f"(ftmp[15]),
403           [ftmp16]"=&f"(ftmp[16]),      [ftmp17]"=&f"(ftmp[17]),
404           [ftmp18]"=&f"(ftmp[18]),      [ftmp19]"=&f"(ftmp[19]),
405           [ftmp20]"=&f"(ftmp[20]),      [ftmp21]"=&f"(ftmp[21]),
406           [ftmp22]"=&f"(ftmp[22]),
407           [tmp0]"=&r"(tmp[0])
408         : [ff_pw_1]"f"(ff_pw_1_local),  [ff_pw_64]"f"(ff_pw_64_local),
409           [ff_pw_4]"f"(ff_pw_4_local), [block]"r"(block),
410           [temp]"r"(temp)
411         : "memory"
412     );
413 }
414 #endif
415
416 /* Do inverse transform on 8x4 part of block */
417 void ff_vc1_inv_trans_8x4_dc_mmi(uint8_t *dest, ptrdiff_t linesize, int16_t *block)
418 {
419     int dc = block[0];
420     double ftmp[9];
421
422     dc = ( 3 * dc +  1) >> 1;
423     dc = (17 * dc + 64) >> 7;
424
425     __asm__ volatile(
426         "xor        %[ftmp0],   %[ftmp0],       %[ftmp0]                \n\t"
427         "pshufh     %[dc],      %[dc],          %[ftmp0]                \n\t"
428
429         MMI_LDC1(%[ftmp1], %[dest0], 0x00)
430         MMI_LDC1(%[ftmp2], %[dest1], 0x00)
431         MMI_LDC1(%[ftmp3], %[dest2], 0x00)
432         MMI_LDC1(%[ftmp4], %[dest3], 0x00)
433
434         "punpckhbh  %[ftmp5],   %[ftmp1],       %[ftmp0]                \n\t"
435         "punpcklbh  %[ftmp1],   %[ftmp1],       %[ftmp0]                \n\t"
436         "punpckhbh  %[ftmp6],   %[ftmp2],       %[ftmp0]                \n\t"
437         "punpcklbh  %[ftmp2],   %[ftmp2],       %[ftmp0]                \n\t"
438         "punpckhbh  %[ftmp7],   %[ftmp3],       %[ftmp0]                \n\t"
439         "punpcklbh  %[ftmp3],   %[ftmp3],       %[ftmp0]                \n\t"
440         "punpckhbh  %[ftmp8],   %[ftmp4],       %[ftmp0]                \n\t"
441         "punpcklbh  %[ftmp4],   %[ftmp4],       %[ftmp0]                \n\t"
442
443         "paddsh     %[ftmp1],   %[ftmp1],       %[dc]                   \n\t"
444         "paddsh     %[ftmp2],   %[ftmp2],       %[dc]                   \n\t"
445         "paddsh     %[ftmp3],   %[ftmp3],       %[dc]                   \n\t"
446         "paddsh     %[ftmp4],   %[ftmp4],       %[dc]                   \n\t"
447         "paddsh     %[ftmp5],   %[ftmp5],       %[dc]                   \n\t"
448         "paddsh     %[ftmp6],   %[ftmp6],       %[dc]                   \n\t"
449         "paddsh     %[ftmp7],   %[ftmp7],       %[dc]                   \n\t"
450         "paddsh     %[ftmp8],   %[ftmp8],       %[dc]                   \n\t"
451
452         "packushb   %[ftmp1],   %[ftmp1],       %[ftmp5]                \n\t"
453         "packushb   %[ftmp2],   %[ftmp2],       %[ftmp6]                \n\t"
454         "packushb   %[ftmp3],   %[ftmp3],       %[ftmp7]                \n\t"
455         "packushb   %[ftmp4],   %[ftmp4],       %[ftmp8]                \n\t"
456
457         MMI_SDC1(%[ftmp1], %[dest0], 0x00)
458         MMI_SDC1(%[ftmp2], %[dest1], 0x00)
459         MMI_SDC1(%[ftmp3], %[dest2], 0x00)
460         MMI_SDC1(%[ftmp4], %[dest3], 0x00)
461         : [ftmp0]"=&f"(ftmp[0]),        [ftmp1]"=&f"(ftmp[1]),
462           [ftmp2]"=&f"(ftmp[2]),        [ftmp3]"=&f"(ftmp[3]),
463           [ftmp4]"=&f"(ftmp[4]),        [ftmp5]"=&f"(ftmp[5]),
464           [ftmp6]"=&f"(ftmp[6]),        [ftmp7]"=&f"(ftmp[7]),
465           [ftmp8]"=&f"(ftmp[8])
466         : [dest0]"r"(dest+0*linesize),  [dest1]"r"(dest+1*linesize),
467           [dest2]"r"(dest+2*linesize),  [dest3]"r"(dest+3*linesize),
468           [dc]"f"(dc)
469         : "memory"
470     );
471 }
472
473 #if _MIPS_SIM != _ABIO32
474 void ff_vc1_inv_trans_8x4_mmi(uint8_t *dest, ptrdiff_t linesize, int16_t *block)
475 {
476     int16_t *src = block;
477     int16_t *dst = block;
478     double ftmp[16];
479     uint32_t tmp[1];
480     int16_t count = 4;
481     DECLARE_ALIGNED(16, const uint64_t, ff_pw_4_local) = {0x0000000400000004ULL};
482     DECLARE_ALIGNED(16, const uint64_t, ff_pw_64_local)= {0x0000004000000040ULL};
483     int16_t coeff[64] = {12, 16,  16,  15,  12,   9,   6,   4,
484                          12, 15,   6,  -4, -12, -16, -16,  -9,
485                          12,  9,  -6, -16, -12,   4,  16,  15,
486                          12,  4, -16,  -9,  12,  15,  -6, -16,
487                          12, -4, -16,   9,  12, -15,  -6,  16,
488                          12, -9,  -6,  16, -12,  -4,  16, -15,
489                          12, -15,  6,   4, -12,  16, -16,   9,
490                          12, -16, 16, -15,  12,  -9,   6,  -4};
491
492     // 1st loop
493     __asm__ volatile (
494         "li         %[tmp0],    0x03                                    \n\t"
495         "mtc1       %[tmp0],    %[ftmp0]                                \n\t"
496
497         "1:                                                             \n\t"
498         MMI_LDC1(%[ftmp1], %[src], 0x00)
499         MMI_LDC1(%[ftmp2], %[src], 0x08)
500
501         /* ftmp11: dst1,dst0 */
502         MMI_LDC1(%[ftmp3], %[coeff], 0x00)
503         MMI_LDC1(%[ftmp4], %[coeff], 0x08)
504         MMI_LDC1(%[ftmp5], %[coeff], 0x10)
505         MMI_LDC1(%[ftmp6], %[coeff], 0x18)
506         "pmaddhw    %[ftmp7],   %[ftmp1],   %[ftmp3]                    \n\t"
507         "pmaddhw    %[ftmp8],   %[ftmp2],   %[ftmp4]                    \n\t"
508         "paddw      %[ftmp9],   %[ftmp7],   %[ftmp8]                    \n\t"
509         "pmaddhw    %[ftmp7],   %[ftmp1],   %[ftmp5]                    \n\t"
510         "pmaddhw    %[ftmp8],   %[ftmp2],   %[ftmp6]                    \n\t"
511         "paddw      %[ftmp10],  %[ftmp7],   %[ftmp8]                    \n\t"
512         "punpcklwd  %[ftmp7],   %[ftmp9],   %[ftmp10]                   \n\t"
513         "punpckhwd  %[ftmp8],   %[ftmp9],   %[ftmp10]                   \n\t"
514         "paddw      %[ftmp11],  %[ftmp7],   %[ftmp8]                    \n\t"
515         "paddw      %[ftmp11],  %[ftmp11],  %[ff_pw_4]                  \n\t"
516
517         /* ftmp12: dst3,dst2 */
518         MMI_LDC1(%[ftmp3], %[coeff], 0x20)
519         MMI_LDC1(%[ftmp4], %[coeff], 0x28)
520         MMI_LDC1(%[ftmp5], %[coeff], 0x30)
521         MMI_LDC1(%[ftmp6], %[coeff], 0x38)
522         "pmaddhw    %[ftmp7],   %[ftmp1],   %[ftmp3]                    \n\t"
523         "pmaddhw    %[ftmp8],   %[ftmp2],   %[ftmp4]                    \n\t"
524         "paddw      %[ftmp9],   %[ftmp7],   %[ftmp8]                    \n\t"
525         "pmaddhw    %[ftmp7],   %[ftmp1],   %[ftmp5]                    \n\t"
526         "pmaddhw    %[ftmp8],   %[ftmp2],   %[ftmp6]                    \n\t"
527         "paddw      %[ftmp10],  %[ftmp7],   %[ftmp8]                    \n\t"
528         "punpcklwd  %[ftmp7],   %[ftmp9],   %[ftmp10]                   \n\t"
529         "punpckhwd  %[ftmp8],   %[ftmp9],   %[ftmp10]                   \n\t"
530         "paddw      %[ftmp12],  %[ftmp7],   %[ftmp8]                    \n\t"
531         "paddw      %[ftmp12],  %[ftmp12],  %[ff_pw_4]                  \n\t"
532
533         /* ftmp13: dst5,dst4 */
534         MMI_LDC1(%[ftmp3], %[coeff], 0x40)
535         MMI_LDC1(%[ftmp4], %[coeff], 0x48)
536         MMI_LDC1(%[ftmp5], %[coeff], 0x50)
537         MMI_LDC1(%[ftmp6], %[coeff], 0x58)
538         "pmaddhw    %[ftmp7],   %[ftmp1],   %[ftmp3]                    \n\t"
539         "pmaddhw    %[ftmp8],   %[ftmp2],   %[ftmp4]                    \n\t"
540         "paddw      %[ftmp9],   %[ftmp7],   %[ftmp8]                    \n\t"
541         "pmaddhw    %[ftmp7],   %[ftmp1],   %[ftmp5]                    \n\t"
542         "pmaddhw    %[ftmp8],   %[ftmp2],   %[ftmp6]                    \n\t"
543         "paddw      %[ftmp10],  %[ftmp7],   %[ftmp8]                    \n\t"
544         "punpcklwd  %[ftmp7],   %[ftmp9],   %[ftmp10]                   \n\t"
545         "punpckhwd  %[ftmp8],   %[ftmp9],   %[ftmp10]                   \n\t"
546         "paddw      %[ftmp13],  %[ftmp7],   %[ftmp8]                    \n\t"
547         "paddw      %[ftmp13],  %[ftmp13],  %[ff_pw_4]                  \n\t"
548
549         /* ftmp14: dst7,dst6 */
550         MMI_LDC1(%[ftmp3], %[coeff], 0x60)
551         MMI_LDC1(%[ftmp4], %[coeff], 0x68)
552         MMI_LDC1(%[ftmp5], %[coeff], 0x70)
553         MMI_LDC1(%[ftmp6], %[coeff], 0x78)
554         "pmaddhw    %[ftmp7],   %[ftmp1],   %[ftmp3]                    \n\t"
555         "pmaddhw    %[ftmp8],   %[ftmp2],   %[ftmp4]                    \n\t"
556         "paddw      %[ftmp9],   %[ftmp7],   %[ftmp8]                    \n\t"
557         "pmaddhw    %[ftmp7],   %[ftmp1],   %[ftmp5]                    \n\t"
558         "pmaddhw    %[ftmp8],   %[ftmp2],   %[ftmp6]                    \n\t"
559         "paddw      %[ftmp10],  %[ftmp7],   %[ftmp8]                    \n\t"
560         "punpcklwd  %[ftmp7],   %[ftmp9],   %[ftmp10]                   \n\t"
561         "punpckhwd  %[ftmp8],   %[ftmp9],   %[ftmp10]                   \n\t"
562         "paddw      %[ftmp14],  %[ftmp7],   %[ftmp8]                    \n\t"
563         "paddw      %[ftmp14],  %[ftmp14],  %[ff_pw_4]                  \n\t"
564
565         /* ftmp9: dst3,dst2,dst1,dst0    ftmp10: dst7,dst6,dst5,dst4 */
566         "psraw      %[ftmp11],  %[ftmp11],  %[ftmp0]                    \n\t"
567         "psraw      %[ftmp12],  %[ftmp12],  %[ftmp0]                    \n\t"
568         "psraw      %[ftmp13],  %[ftmp13],  %[ftmp0]                    \n\t"
569         "psraw      %[ftmp14],  %[ftmp14],  %[ftmp0]                    \n\t"
570         "punpcklhw  %[ftmp7],   %[ftmp11],  %[ftmp12]                   \n\t"
571         "punpckhhw  %[ftmp8],   %[ftmp11],  %[ftmp12]                   \n\t"
572         "punpcklhw  %[ftmp9],   %[ftmp7],   %[ftmp8]                    \n\t"
573         "punpcklhw  %[ftmp7],   %[ftmp13],  %[ftmp14]                   \n\t"
574         "punpckhhw  %[ftmp8],   %[ftmp13],  %[ftmp14]                   \n\t"
575         "punpcklhw  %[ftmp10],  %[ftmp7],   %[ftmp8]                    \n\t"
576         MMI_SDC1(%[ftmp9], %[dst], 0x00)
577         MMI_SDC1(%[ftmp10], %[dst], 0x08)
578
579         PTR_ADDIU  "%[src],     %[src],     0x10                        \n\t"
580         PTR_ADDIU  "%[dst],     %[dst],     0x10                        \n\t"
581         "addiu      %[count],   %[count],   -0x01                       \n\t"
582         "bnez       %[count],   1b                                      \n\t"
583         : [ftmp0]"=&f"(ftmp[0]),        [ftmp1]"=&f"(ftmp[1]),
584           [ftmp2]"=&f"(ftmp[2]),        [ftmp3]"=&f"(ftmp[3]),
585           [ftmp4]"=&f"(ftmp[4]),        [ftmp5]"=&f"(ftmp[5]),
586           [ftmp6]"=&f"(ftmp[6]),        [ftmp7]"=&f"(ftmp[7]),
587           [ftmp8]"=&f"(ftmp[8]),        [ftmp9]"=&f"(ftmp[9]),
588           [ftmp10]"=&f"(ftmp[10]),      [ftmp11]"=&f"(ftmp[11]),
589           [ftmp12]"=&f"(ftmp[12]),      [ftmp13]"=&f"(ftmp[13]),
590           [ftmp14]"=&f"(ftmp[14]),      [tmp0]"=&r"(tmp[0]),
591           [src]"+&r"(src), [dst]"+&r"(dst), [count]"+&r"(count)
592         : [ff_pw_4]"f"(ff_pw_4_local),  [coeff]"r"(coeff)
593         : "memory"
594     );
595
596     src = block;
597
598     // 2nd loop
599     __asm__ volatile (
600         "li         %[tmp0],    0x44                                    \n\t"
601         "mtc1       %[tmp0],    %[ftmp15]                               \n\t"
602
603         // 1st part
604         "li         %[tmp0],    0x07                                    \n\t"
605         "mtc1       %[tmp0],    %[ftmp0]                                \n\t"
606         MMI_LDC1(%[ftmp1], %[src], 0x00)
607         MMI_LDC1(%[ftmp2], %[src], 0x10)
608         MMI_LDC1(%[ftmp3], %[src], 0x20)
609         MMI_LDC1(%[ftmp4], %[src], 0x30)
610         "punpcklhw  %[ftmp5],   %[ftmp1],   %[ftmp2]                    \n\t"
611         "punpckhhw  %[ftmp6],   %[ftmp1],   %[ftmp2]                    \n\t"
612         "punpcklhw  %[ftmp7],   %[ftmp3],   %[ftmp4]                    \n\t"
613         "punpckhhw  %[ftmp8],   %[ftmp3],   %[ftmp4]                    \n\t"
614
615         /* ftmp11: dst03,dst02,dst01,dst00 */
616         "li         %[tmp0],    0x00160011                              \n\t"
617         "mtc1       %[tmp0],    %[ftmp3]                                \n\t"
618         "pshufh     %[ftmp3],   %[ftmp3],   %[ftmp15]                   \n\t"
619         "li         %[tmp0],    0x000a0011                              \n\t"
620         "mtc1       %[tmp0],    %[ftmp4]                                \n\t"
621         "pshufh     %[ftmp4],   %[ftmp4],   %[ftmp15]                   \n\t"
622         "pmaddhw    %[ftmp1],   %[ftmp5],   %[ftmp3]                    \n\t"
623         "pmaddhw    %[ftmp2],   %[ftmp7],   %[ftmp4]                    \n\t"
624         "paddw      %[ftmp9],   %[ftmp1],   %[ftmp2]                    \n\t"
625         "pmaddhw    %[ftmp1],   %[ftmp6],   %[ftmp3]                    \n\t"
626         "pmaddhw    %[ftmp2],   %[ftmp8],   %[ftmp4]                    \n\t"
627         "paddw      %[ftmp10],  %[ftmp1],   %[ftmp2]                    \n\t"
628         "paddw      %[ftmp9],   %[ftmp9],   %[ff_pw_64]                 \n\t"
629         "paddw      %[ftmp10],  %[ftmp10],  %[ff_pw_64]                 \n\t"
630         "psraw      %[ftmp9],   %[ftmp9],   %[ftmp0]                    \n\t"
631         "psraw      %[ftmp10],  %[ftmp10],  %[ftmp0]                    \n\t"
632         "punpcklhw  %[ftmp1],   %[ftmp9],   %[ftmp10]                   \n\t"
633         "punpckhhw  %[ftmp2],   %[ftmp9],   %[ftmp10]                   \n\t"
634         "punpcklhw  %[ftmp11],  %[ftmp1],   %[ftmp2]                    \n\t"
635
636         /* ftmp12: dst13,dst12,dst11,dst10 */
637         "li         %[tmp0],    0x000a0011                              \n\t"
638         "mtc1       %[tmp0],    %[ftmp3]                                \n\t"
639         "pshufh     %[ftmp3],   %[ftmp3],   %[ftmp15]                   \n\t"
640         "li         %[tmp0],    0xffeaffef                              \n\t"
641         "mtc1       %[tmp0],    %[ftmp4]                                \n\t"
642         "pshufh     %[ftmp4],   %[ftmp4],   %[ftmp15]                   \n\t"
643         "pmaddhw    %[ftmp1],   %[ftmp5],   %[ftmp3]                    \n\t"
644         "pmaddhw    %[ftmp2],   %[ftmp7],   %[ftmp4]                    \n\t"
645         "paddw      %[ftmp9],   %[ftmp1],   %[ftmp2]                    \n\t"
646         "pmaddhw    %[ftmp1],   %[ftmp6],   %[ftmp3]                    \n\t"
647         "pmaddhw    %[ftmp2],   %[ftmp8],   %[ftmp4]                    \n\t"
648         "paddw      %[ftmp10],  %[ftmp1],   %[ftmp2]                    \n\t"
649         "paddw      %[ftmp9],   %[ftmp9],   %[ff_pw_64]                 \n\t"
650         "paddw      %[ftmp10],  %[ftmp10],  %[ff_pw_64]                 \n\t"
651         "psraw      %[ftmp9],   %[ftmp9],   %[ftmp0]                    \n\t"
652         "psraw      %[ftmp10],  %[ftmp10],  %[ftmp0]                    \n\t"
653         "punpcklhw  %[ftmp1],   %[ftmp9],   %[ftmp10]                   \n\t"
654         "punpckhhw  %[ftmp2],   %[ftmp9],   %[ftmp10]                   \n\t"
655         "punpcklhw  %[ftmp12],  %[ftmp1],   %[ftmp2]                    \n\t"
656
657         /* ftmp13: dst23,dst22,dst21,dst20 */
658         "li         %[tmp0],    0xfff60011                              \n\t"
659         "mtc1       %[tmp0],    %[ftmp3]                                \n\t"
660         "pshufh     %[ftmp3],   %[ftmp3],   %[ftmp15]                   \n\t"
661         "li         %[tmp0],    0x0016ffef                              \n\t"
662         "mtc1       %[tmp0],    %[ftmp4]                                \n\t"
663         "pshufh     %[ftmp4],   %[ftmp4],   %[ftmp15]                   \n\t"
664         "pmaddhw    %[ftmp1],   %[ftmp5],   %[ftmp3]                    \n\t"
665         "pmaddhw    %[ftmp2],   %[ftmp7],   %[ftmp4]                    \n\t"
666         "paddw      %[ftmp9],   %[ftmp1],   %[ftmp2]                    \n\t"
667         "pmaddhw    %[ftmp1],   %[ftmp6],   %[ftmp3]                    \n\t"
668         "pmaddhw    %[ftmp2],   %[ftmp8],   %[ftmp4]                    \n\t"
669         "paddw      %[ftmp10],  %[ftmp1],   %[ftmp2]                    \n\t"
670         "paddw      %[ftmp9],   %[ftmp9],   %[ff_pw_64]                 \n\t"
671         "paddw      %[ftmp10],  %[ftmp10],  %[ff_pw_64]                 \n\t"
672         "psraw      %[ftmp9],   %[ftmp9],   %[ftmp0]                    \n\t"
673         "psraw      %[ftmp10],  %[ftmp10],  %[ftmp0]                    \n\t"
674         "punpcklhw  %[ftmp1],   %[ftmp9],   %[ftmp10]                   \n\t"
675         "punpckhhw  %[ftmp2],   %[ftmp9],   %[ftmp10]                   \n\t"
676         "punpcklhw  %[ftmp13],  %[ftmp1],   %[ftmp2]                    \n\t"
677
678         /* ftmp14: dst33,dst32,dst31,dst30 */
679         "li         %[tmp0],    0xffea0011                              \n\t"
680         "mtc1       %[tmp0],    %[ftmp3]                                \n\t"
681         "pshufh     %[ftmp3],   %[ftmp3],   %[ftmp15]                   \n\t"
682         "li         %[tmp0],    0xfff60011                              \n\t"
683         "mtc1       %[tmp0],    %[ftmp4]                                \n\t"
684         "pshufh     %[ftmp4],   %[ftmp4],   %[ftmp15]                   \n\t"
685         "pmaddhw    %[ftmp1],   %[ftmp5],   %[ftmp3]                    \n\t"
686         "pmaddhw    %[ftmp2],   %[ftmp7],   %[ftmp4]                    \n\t"
687         "paddw      %[ftmp9],   %[ftmp1],   %[ftmp2]                    \n\t"
688         "pmaddhw    %[ftmp1],   %[ftmp6],   %[ftmp3]                    \n\t"
689         "pmaddhw    %[ftmp2],   %[ftmp8],   %[ftmp4]                    \n\t"
690         "paddw      %[ftmp10],  %[ftmp1],   %[ftmp2]                    \n\t"
691         "paddw      %[ftmp9],   %[ftmp9],   %[ff_pw_64]                 \n\t"
692         "paddw      %[ftmp10],  %[ftmp10],  %[ff_pw_64]                 \n\t"
693         "psraw      %[ftmp9],   %[ftmp9],   %[ftmp0]                    \n\t"
694         "psraw      %[ftmp10],  %[ftmp10],  %[ftmp0]                    \n\t"
695         "punpcklhw  %[ftmp1],   %[ftmp9],   %[ftmp10]                   \n\t"
696         "punpckhhw  %[ftmp2],   %[ftmp9],   %[ftmp10]                   \n\t"
697         "punpcklhw  %[ftmp14],  %[ftmp1],   %[ftmp2]                    \n\t"
698
699         MMI_LWC1(%[ftmp1], %[dest], 0x00)
700         PTR_ADDU    "%[tmp0],   %[dest],    %[linesize]                 \n\t"
701         MMI_LWC1(%[ftmp2], %[tmp0], 0x00)
702         PTR_ADDU    "%[tmp0],   %[tmp0],    %[linesize]                 \n\t"
703         MMI_LWC1(%[ftmp3], %[tmp0], 0x00)
704         PTR_ADDU    "%[tmp0],   %[tmp0],    %[linesize]                 \n\t"
705         MMI_LWC1(%[ftmp4], %[tmp0], 0x00)
706         "xor        %[ftmp0],   %[ftmp0],   %[ftmp0]                    \n\t"
707         "punpcklbh  %[ftmp1],   %[ftmp1],   %[ftmp0]                    \n\t"
708         "punpcklbh  %[ftmp2],   %[ftmp2],   %[ftmp0]                    \n\t"
709         "punpcklbh  %[ftmp3],   %[ftmp3],   %[ftmp0]                    \n\t"
710         "punpcklbh  %[ftmp4],   %[ftmp4],   %[ftmp0]                    \n\t"
711         "paddh      %[ftmp1],   %[ftmp1],   %[ftmp11]                   \n\t"
712         "paddh      %[ftmp2],   %[ftmp2],   %[ftmp12]                   \n\t"
713         "paddh      %[ftmp3],   %[ftmp3],   %[ftmp13]                   \n\t"
714         "paddh      %[ftmp4],   %[ftmp4],   %[ftmp14]                   \n\t"
715         "packushb   %[ftmp1],   %[ftmp1],   %[ftmp0]                    \n\t"
716         "packushb   %[ftmp2],   %[ftmp2],   %[ftmp0]                    \n\t"
717         "packushb   %[ftmp3],   %[ftmp3],   %[ftmp0]                    \n\t"
718         "packushb   %[ftmp4],   %[ftmp4],   %[ftmp0]                    \n\t"
719         MMI_SWC1(%[ftmp1], %[dest], 0x00)
720         PTR_ADDU   "%[tmp0],    %[dest],    %[linesize]                 \n\t"
721         MMI_SWC1(%[ftmp2], %[tmp0], 0x00)
722         PTR_ADDU   "%[tmp0],    %[tmp0],    %[linesize]                 \n\t"
723         MMI_SWC1(%[ftmp3], %[tmp0], 0x00)
724         PTR_ADDU   "%[tmp0],    %[tmp0],    %[linesize]                 \n\t"
725         MMI_SWC1(%[ftmp4], %[tmp0], 0x00)
726
727         // 2nd part
728         "li         %[tmp0],    0x07                                    \n\t"
729         "mtc1       %[tmp0],    %[ftmp0]                                \n\t"
730         MMI_LDC1(%[ftmp1], %[src], 0x08)
731         MMI_LDC1(%[ftmp2], %[src], 0x18)
732         MMI_LDC1(%[ftmp3], %[src], 0x28)
733         MMI_LDC1(%[ftmp4], %[src], 0x38)
734         "punpcklhw  %[ftmp5],   %[ftmp1],   %[ftmp2]                    \n\t"
735         "punpckhhw  %[ftmp6],   %[ftmp1],   %[ftmp2]                    \n\t"
736         "punpcklhw  %[ftmp7],   %[ftmp3],   %[ftmp4]                    \n\t"
737         "punpckhhw  %[ftmp8],   %[ftmp3],   %[ftmp4]                    \n\t"
738
739         /* ftmp11: dst03,dst02,dst01,dst00 */
740         "li         %[tmp0],    0x00160011                              \n\t"
741         "mtc1       %[tmp0],    %[ftmp3]                                \n\t"
742         "pshufh     %[ftmp3],   %[ftmp3],   %[ftmp15]                   \n\t"
743         "li         %[tmp0],    0x000a0011                              \n\t"
744         "mtc1       %[tmp0],    %[ftmp4]                                \n\t"
745         "pshufh     %[ftmp4],   %[ftmp4],   %[ftmp15]                   \n\t"
746         "pmaddhw    %[ftmp1],   %[ftmp5],   %[ftmp3]                    \n\t"
747         "pmaddhw    %[ftmp2],   %[ftmp7],   %[ftmp4]                    \n\t"
748         "paddw      %[ftmp9],   %[ftmp1],   %[ftmp2]                    \n\t"
749         "pmaddhw    %[ftmp1],   %[ftmp6],   %[ftmp3]                    \n\t"
750         "pmaddhw    %[ftmp2],   %[ftmp8],   %[ftmp4]                    \n\t"
751         "paddw      %[ftmp10],  %[ftmp1],   %[ftmp2]                    \n\t"
752         "paddw      %[ftmp9],   %[ftmp9],   %[ff_pw_64]                 \n\t"
753         "paddw      %[ftmp10],  %[ftmp10],  %[ff_pw_64]                 \n\t"
754         "psraw      %[ftmp9],   %[ftmp9],   %[ftmp0]                    \n\t"
755         "psraw      %[ftmp10],  %[ftmp10],  %[ftmp0]                    \n\t"
756         "punpcklhw  %[ftmp1],   %[ftmp9],   %[ftmp10]                   \n\t"
757         "punpckhhw  %[ftmp2],   %[ftmp9],   %[ftmp10]                   \n\t"
758         "punpcklhw  %[ftmp11],  %[ftmp1],   %[ftmp2]                    \n\t"
759
760         /* ftmp12: dst13,dst12,dst11,dst10 */
761         "li         %[tmp0],    0x000a0011                              \n\t"
762         "mtc1       %[tmp0],    %[ftmp3]                                \n\t"
763         "pshufh     %[ftmp3],   %[ftmp3],   %[ftmp15]                   \n\t"
764         "li         %[tmp0],    0xffeaffef                              \n\t"
765         "mtc1       %[tmp0],    %[ftmp4]                                \n\t"
766         "pshufh     %[ftmp4],   %[ftmp4],   %[ftmp15]                   \n\t"
767         "pmaddhw    %[ftmp1],   %[ftmp5],   %[ftmp3]                    \n\t"
768         "pmaddhw    %[ftmp2],   %[ftmp7],   %[ftmp4]                    \n\t"
769         "paddw      %[ftmp9],   %[ftmp1],   %[ftmp2]                    \n\t"
770         "pmaddhw    %[ftmp1],   %[ftmp6],   %[ftmp3]                    \n\t"
771         "pmaddhw    %[ftmp2],   %[ftmp8],   %[ftmp4]                    \n\t"
772         "paddw      %[ftmp10],  %[ftmp1],   %[ftmp2]                    \n\t"
773         "paddw      %[ftmp9],   %[ftmp9],   %[ff_pw_64]                 \n\t"
774         "paddw      %[ftmp10],  %[ftmp10],  %[ff_pw_64]                 \n\t"
775         "psraw      %[ftmp9],   %[ftmp9],   %[ftmp0]                    \n\t"
776         "psraw      %[ftmp10],  %[ftmp10],  %[ftmp0]                    \n\t"
777         "punpcklhw  %[ftmp1],   %[ftmp9],   %[ftmp10]                   \n\t"
778         "punpckhhw  %[ftmp2],   %[ftmp9],   %[ftmp10]                   \n\t"
779         "punpcklhw  %[ftmp12],  %[ftmp1],   %[ftmp2]                    \n\t"
780
781         /* ftmp13: dst23,dst22,dst21,dst20 */
782         "li         %[tmp0],    0xfff60011                              \n\t"
783         "mtc1       %[tmp0],    %[ftmp3]                                \n\t"
784         "pshufh     %[ftmp3],   %[ftmp3],   %[ftmp15]                   \n\t"
785         "li         %[tmp0],    0x0016ffef                              \n\t"
786         "mtc1       %[tmp0],    %[ftmp4]                                \n\t"
787         "pshufh     %[ftmp4],   %[ftmp4],   %[ftmp15]                   \n\t"
788         "pmaddhw    %[ftmp1],   %[ftmp5],   %[ftmp3]                    \n\t"
789         "pmaddhw    %[ftmp2],   %[ftmp7],   %[ftmp4]                    \n\t"
790         "paddw      %[ftmp9],   %[ftmp1],   %[ftmp2]                    \n\t"
791         "pmaddhw    %[ftmp1],   %[ftmp6],   %[ftmp3]                    \n\t"
792         "pmaddhw    %[ftmp2],   %[ftmp8],   %[ftmp4]                    \n\t"
793         "paddw      %[ftmp10],  %[ftmp1],   %[ftmp2]                    \n\t"
794         "paddw      %[ftmp9],   %[ftmp9],   %[ff_pw_64]                 \n\t"
795         "paddw      %[ftmp10],  %[ftmp10],  %[ff_pw_64]                 \n\t"
796         "psraw      %[ftmp9],   %[ftmp9],   %[ftmp0]                    \n\t"
797         "psraw      %[ftmp10],  %[ftmp10],  %[ftmp0]                    \n\t"
798         "punpcklhw  %[ftmp1],   %[ftmp9],   %[ftmp10]                   \n\t"
799         "punpckhhw  %[ftmp2],   %[ftmp9],   %[ftmp10]                   \n\t"
800         "punpcklhw  %[ftmp13],  %[ftmp1],   %[ftmp2]                    \n\t"
801
802         /* ftmp14: dst33,dst32,dst31,dst30 */
803         "li         %[tmp0],    0xffea0011                              \n\t"
804         "mtc1       %[tmp0],    %[ftmp3]                                \n\t"
805         "pshufh     %[ftmp3],   %[ftmp3],   %[ftmp15]                   \n\t"
806         "li         %[tmp0],    0xfff60011                              \n\t"
807         "mtc1       %[tmp0],    %[ftmp4]                                \n\t"
808         "pshufh     %[ftmp4],   %[ftmp4],   %[ftmp15]                   \n\t"
809         "pmaddhw    %[ftmp1],   %[ftmp5],   %[ftmp3]                    \n\t"
810         "pmaddhw    %[ftmp2],   %[ftmp7],   %[ftmp4]                    \n\t"
811         "paddw      %[ftmp9],   %[ftmp1],   %[ftmp2]                    \n\t"
812         "pmaddhw    %[ftmp1],   %[ftmp6],   %[ftmp3]                    \n\t"
813         "pmaddhw    %[ftmp2],   %[ftmp8],   %[ftmp4]                    \n\t"
814         "paddw      %[ftmp10],  %[ftmp1],   %[ftmp2]                    \n\t"
815         "paddw      %[ftmp9],   %[ftmp9],   %[ff_pw_64]                 \n\t"
816         "paddw      %[ftmp10],  %[ftmp10],  %[ff_pw_64]                 \n\t"
817         "psraw      %[ftmp9],   %[ftmp9],   %[ftmp0]                    \n\t"
818         "psraw      %[ftmp10],  %[ftmp10],  %[ftmp0]                    \n\t"
819         "punpcklhw  %[ftmp1],   %[ftmp9],   %[ftmp10]                   \n\t"
820         "punpckhhw  %[ftmp2],   %[ftmp9],   %[ftmp10]                   \n\t"
821         "punpcklhw  %[ftmp14],  %[ftmp1],   %[ftmp2]                    \n\t"
822
823         MMI_LWC1(%[ftmp1], %[dest], 0x04)
824         PTR_ADDU    "%[tmp0],   %[dest],    %[linesize]                 \n\t"
825         MMI_LWC1(%[ftmp2], %[tmp0], 0x04)
826         PTR_ADDU    "%[tmp0],   %[tmp0],    %[linesize]                 \n\t"
827         MMI_LWC1(%[ftmp3], %[tmp0], 0x04)
828         PTR_ADDU    "%[tmp0],   %[tmp0],    %[linesize]                 \n\t"
829         MMI_LWC1(%[ftmp4], %[tmp0], 0x04)
830         "xor        %[ftmp0],   %[ftmp0],   %[ftmp0]                    \n\t"
831         "punpcklbh  %[ftmp1],   %[ftmp1],   %[ftmp0]                    \n\t"
832         "punpcklbh  %[ftmp2],   %[ftmp2],   %[ftmp0]                    \n\t"
833         "punpcklbh  %[ftmp3],   %[ftmp3],   %[ftmp0]                    \n\t"
834         "punpcklbh  %[ftmp4],   %[ftmp4],   %[ftmp0]                    \n\t"
835         "paddh      %[ftmp1],   %[ftmp1],   %[ftmp11]                   \n\t"
836         "paddh      %[ftmp2],   %[ftmp2],   %[ftmp12]                   \n\t"
837         "paddh      %[ftmp3],   %[ftmp3],   %[ftmp13]                   \n\t"
838         "paddh      %[ftmp4],   %[ftmp4],   %[ftmp14]                   \n\t"
839         "packushb   %[ftmp1],   %[ftmp1],   %[ftmp0]                    \n\t"
840         "packushb   %[ftmp2],   %[ftmp2],   %[ftmp0]                    \n\t"
841         "packushb   %[ftmp3],   %[ftmp3],   %[ftmp0]                    \n\t"
842         "packushb   %[ftmp4],   %[ftmp4],   %[ftmp0]                    \n\t"
843         MMI_SWC1(%[ftmp1], %[dest], 0x04)
844         PTR_ADDU   "%[tmp0],    %[dest],    %[linesize]                 \n\t"
845         MMI_SWC1(%[ftmp2], %[tmp0], 0x04)
846         PTR_ADDU   "%[tmp0],    %[tmp0],    %[linesize]                 \n\t"
847         MMI_SWC1(%[ftmp3], %[tmp0], 0x04)
848         PTR_ADDU   "%[tmp0],    %[tmp0],    %[linesize]                 \n\t"
849         MMI_SWC1(%[ftmp4], %[tmp0], 0x04)
850
851         : [ftmp0]"=&f"(ftmp[0]),        [ftmp1]"=&f"(ftmp[1]),
852           [ftmp2]"=&f"(ftmp[2]),        [ftmp3]"=&f"(ftmp[3]),
853           [ftmp4]"=&f"(ftmp[4]),        [ftmp5]"=&f"(ftmp[5]),
854           [ftmp6]"=&f"(ftmp[6]),        [ftmp7]"=&f"(ftmp[7]),
855           [ftmp8]"=&f"(ftmp[8]),        [ftmp9]"=&f"(ftmp[9]),
856           [ftmp10]"=&f"(ftmp[10]),      [ftmp11]"=&f"(ftmp[11]),
857           [ftmp12]"=&f"(ftmp[12]),      [ftmp13]"=&f"(ftmp[13]),
858           [ftmp14]"=&f"(ftmp[14]),      [ftmp15]"=&f"(ftmp[15]),
859           [tmp0]"=&r"(tmp[0])
860         : [ff_pw_64]"f"(ff_pw_64_local),
861           [src]"r"(src), [dest]"r"(dest), [linesize]"r"(linesize)
862         :"memory"
863     );
864 }
865 #endif
866
867 /* Do inverse transform on 4x8 parts of block */
868 void ff_vc1_inv_trans_4x8_dc_mmi(uint8_t *dest, ptrdiff_t linesize, int16_t *block)
869 {
870     int dc = block[0];
871     double ftmp[9];
872     DECLARE_VAR_LOW32;
873
874     dc = (17 * dc +  4) >> 3;
875     dc = (12 * dc + 64) >> 7;
876
877     __asm__ volatile(
878         "xor        %[ftmp0],   %[ftmp0],       %[ftmp0]                \n\t"
879         "pshufh     %[dc],      %[dc],          %[ftmp0]                \n\t"
880
881         MMI_LWC1(%[ftmp1], %[dest0], 0x00)
882         MMI_LWC1(%[ftmp2], %[dest1], 0x00)
883         MMI_LWC1(%[ftmp3], %[dest2], 0x00)
884         MMI_LWC1(%[ftmp4], %[dest3], 0x00)
885         MMI_LWC1(%[ftmp5], %[dest4], 0x00)
886         MMI_LWC1(%[ftmp6], %[dest5], 0x00)
887         MMI_LWC1(%[ftmp7], %[dest6], 0x00)
888         MMI_LWC1(%[ftmp8], %[dest7], 0x00)
889
890         "punpcklbh  %[ftmp1],   %[ftmp1],       %[ftmp0]                \n\t"
891         "punpcklbh  %[ftmp2],   %[ftmp2],       %[ftmp0]                \n\t"
892         "punpcklbh  %[ftmp3],   %[ftmp3],       %[ftmp0]                \n\t"
893         "punpcklbh  %[ftmp4],   %[ftmp4],       %[ftmp0]                \n\t"
894         "punpcklbh  %[ftmp5],   %[ftmp5],       %[ftmp0]                \n\t"
895         "punpcklbh  %[ftmp6],   %[ftmp6],       %[ftmp0]                \n\t"
896         "punpcklbh  %[ftmp7],   %[ftmp7],       %[ftmp0]                \n\t"
897         "punpcklbh  %[ftmp8],   %[ftmp8],       %[ftmp0]                \n\t"
898
899         "paddsh     %[ftmp1],   %[ftmp1],       %[dc]                   \n\t"
900         "paddsh     %[ftmp2],   %[ftmp2],       %[dc]                   \n\t"
901         "paddsh     %[ftmp3],   %[ftmp3],       %[dc]                   \n\t"
902         "paddsh     %[ftmp4],   %[ftmp4],       %[dc]                   \n\t"
903         "paddsh     %[ftmp5],   %[ftmp5],       %[dc]                   \n\t"
904         "paddsh     %[ftmp6],   %[ftmp6],       %[dc]                   \n\t"
905         "paddsh     %[ftmp7],   %[ftmp7],       %[dc]                   \n\t"
906         "paddsh     %[ftmp8],   %[ftmp8],       %[dc]                   \n\t"
907
908         "packushb   %[ftmp1],   %[ftmp1],       %[ftmp0]                \n\t"
909         "packushb   %[ftmp2],   %[ftmp2],       %[ftmp0]                \n\t"
910         "packushb   %[ftmp3],   %[ftmp3],       %[ftmp0]                \n\t"
911         "packushb   %[ftmp4],   %[ftmp4],       %[ftmp0]                \n\t"
912         "packushb   %[ftmp5],   %[ftmp5],       %[ftmp0]                \n\t"
913         "packushb   %[ftmp6],   %[ftmp6],       %[ftmp0]                \n\t"
914         "packushb   %[ftmp7],   %[ftmp7],       %[ftmp0]                \n\t"
915         "packushb   %[ftmp8],   %[ftmp8],       %[ftmp0]                \n\t"
916
917         MMI_SWC1(%[ftmp1], %[dest0], 0x00)
918         MMI_SWC1(%[ftmp2], %[dest1], 0x00)
919         MMI_SWC1(%[ftmp3], %[dest2], 0x00)
920         MMI_SWC1(%[ftmp4], %[dest3], 0x00)
921         MMI_SWC1(%[ftmp5], %[dest4], 0x00)
922         MMI_SWC1(%[ftmp6], %[dest5], 0x00)
923         MMI_SWC1(%[ftmp7], %[dest6], 0x00)
924         MMI_SWC1(%[ftmp8], %[dest7], 0x00)
925         : [ftmp0]"=&f"(ftmp[0]),        [ftmp1]"=&f"(ftmp[1]),
926           [ftmp2]"=&f"(ftmp[2]),        [ftmp3]"=&f"(ftmp[3]),
927           [ftmp4]"=&f"(ftmp[4]),        [ftmp5]"=&f"(ftmp[5]),
928           [ftmp6]"=&f"(ftmp[6]),        [ftmp7]"=&f"(ftmp[7]),
929           RESTRICT_ASM_LOW32
930           [ftmp8]"=&f"(ftmp[8])
931         : [dest0]"r"(dest+0*linesize),  [dest1]"r"(dest+1*linesize),
932           [dest2]"r"(dest+2*linesize),  [dest3]"r"(dest+3*linesize),
933           [dest4]"r"(dest+4*linesize),  [dest5]"r"(dest+5*linesize),
934           [dest6]"r"(dest+6*linesize),  [dest7]"r"(dest+7*linesize),
935           [dc]"f"(dc)
936         : "memory"
937     );
938 }
939
940 #if _MIPS_SIM != _ABIO32
941 void ff_vc1_inv_trans_4x8_mmi(uint8_t *dest, ptrdiff_t linesize, int16_t *block)
942 {
943     int16_t *src = block;
944     int16_t *dst = block;
945     double ftmp[23];
946     uint32_t count = 8, tmp[1];
947     int16_t coeff[16] = {17, 22, 17, 10,
948                          17, 10,-17,-22,
949                          17,-10,-17, 22,
950                          17,-22, 17,-10};
951     DECLARE_ALIGNED(8, const uint64_t, ff_pw_1_local) = {0x0000000100000001ULL};
952     DECLARE_ALIGNED(8, const uint64_t, ff_pw_4_local) = {0x0000000400000004ULL};
953     DECLARE_ALIGNED(8, const uint64_t, ff_pw_64_local)= {0x0000004000000040ULL};
954
955     // 1st loop
956     __asm__ volatile (
957
958         "li         %[tmp0],    0x03                                    \n\t"
959         "mtc1       %[tmp0],    %[ftmp0]                                \n\t"
960
961         MMI_LDC1(%[ftmp2], %[coeff], 0x00)
962         MMI_LDC1(%[ftmp3], %[coeff], 0x08)
963         MMI_LDC1(%[ftmp4], %[coeff], 0x10)
964         MMI_LDC1(%[ftmp5], %[coeff], 0x18)
965         "1:                                                             \n\t"
966         /* ftmp8: dst3,dst2,dst1,dst0 */
967         MMI_LDC1(%[ftmp1], %[src], 0x00)
968         "pmaddhw    %[ftmp6],   %[ftmp2],   %[ftmp1]                    \n\t"
969         "pmaddhw    %[ftmp7],   %[ftmp3],   %[ftmp1]                    \n\t"
970         "pmaddhw    %[ftmp8],   %[ftmp4],   %[ftmp1]                    \n\t"
971         "pmaddhw    %[ftmp9],   %[ftmp5],   %[ftmp1]                    \n\t"
972         "punpcklwd  %[ftmp10],  %[ftmp6],   %[ftmp7]                    \n\t"
973         "punpckhwd  %[ftmp11],  %[ftmp6],   %[ftmp7]                    \n\t"
974         "punpcklwd  %[ftmp6],   %[ftmp8],   %[ftmp9]                    \n\t"
975         "punpckhwd  %[ftmp7],   %[ftmp8],   %[ftmp9]                    \n\t"
976         "paddw      %[ftmp8],   %[ftmp10],  %[ftmp11]                   \n\t"
977         "paddw      %[ftmp9],   %[ftmp6],   %[ftmp7]                    \n\t"
978         "paddw      %[ftmp8],   %[ftmp8],   %[ff_pw_4]                  \n\t"
979         "paddw      %[ftmp9],   %[ftmp9],   %[ff_pw_4]                  \n\t"
980         "psraw      %[ftmp8],   %[ftmp8],   %[ftmp0]                    \n\t"
981         "psraw      %[ftmp9],   %[ftmp9],   %[ftmp0]                    \n\t"
982         "punpcklhw  %[ftmp6],   %[ftmp8],   %[ftmp9]                    \n\t"
983         "punpckhhw  %[ftmp7],   %[ftmp8],   %[ftmp9]                    \n\t"
984         "punpcklhw  %[ftmp8],   %[ftmp6],   %[ftmp7]                    \n\t"
985         MMI_SDC1(%[ftmp8], %[dst], 0x00)
986
987         PTR_ADDIU  "%[src],     %[src],     0x10                        \n\t"
988         PTR_ADDIU  "%[dst],     %[dst],     0x10                        \n\t"
989         "addiu      %[count],   %[count],   -0x01                       \n\t"
990         "bnez       %[count],   1b                                      \n\t"
991         : [ftmp0]"=&f"(ftmp[0]),        [ftmp1]"=&f"(ftmp[1]),
992           [ftmp2]"=&f"(ftmp[2]),        [ftmp3]"=&f"(ftmp[3]),
993           [ftmp4]"=&f"(ftmp[4]),        [ftmp5]"=&f"(ftmp[5]),
994           [ftmp6]"=&f"(ftmp[6]),        [ftmp7]"=&f"(ftmp[7]),
995           [ftmp8]"=&f"(ftmp[8]),        [ftmp9]"=&f"(ftmp[9]),
996           [ftmp10]"=&f"(ftmp[10]),      [ftmp11]"=&f"(ftmp[11]),
997           [tmp0]"=&r"(tmp[0]),          [count]"+&r"(count),
998           [src]"+&r"(src),              [dst]"+&r"(dst)
999         : [ff_pw_4]"f"(ff_pw_4_local),  [coeff]"r"(coeff)
1000         : "memory"
1001     );
1002
1003     src = block;
1004
1005     // 2nd loop
1006     __asm__ volatile (
1007         "li         %[tmp0],    0x07                                    \n\t"
1008         "mtc1       %[tmp0],    %[ftmp0]                                \n\t"
1009
1010         MMI_LDC1(%[ftmp1], %[src], 0x00)
1011         MMI_LDC1(%[ftmp2], %[src], 0x20)
1012         MMI_LDC1(%[ftmp3], %[src], 0x40)
1013         MMI_LDC1(%[ftmp4], %[src], 0x60)
1014         "punpcklhw  %[ftmp5],   %[ftmp1],   %[ftmp2]                    \n\t"
1015         "punpckhhw  %[ftmp6],   %[ftmp1],   %[ftmp2]                    \n\t"
1016         "punpcklhw  %[ftmp7],   %[ftmp3],   %[ftmp4]                    \n\t"
1017         "punpckhhw  %[ftmp8],   %[ftmp3],   %[ftmp4]                    \n\t"
1018
1019         MMI_LDC1(%[ftmp1], %[src], 0x10)
1020         MMI_LDC1(%[ftmp2], %[src], 0x30)
1021         MMI_LDC1(%[ftmp3], %[src], 0x50)
1022         MMI_LDC1(%[ftmp4], %[src], 0x70)
1023         "punpcklhw  %[ftmp9],   %[ftmp1],   %[ftmp2]                    \n\t"
1024         "punpckhhw  %[ftmp10],  %[ftmp1],   %[ftmp2]                    \n\t"
1025         "punpcklhw  %[ftmp11],  %[ftmp3],   %[ftmp4]                    \n\t"
1026         "punpckhhw  %[ftmp12],  %[ftmp3],   %[ftmp4]                    \n\t"
1027
1028         /* ftmp15:dst03,dst02,dst01,dst00 ftmp22:dst73,dst72,dst71,dst70 */
1029         VC1_INV_TRANCS_8_TYPE2(%[ftmp15], %[ftmp22], 0x0010000c, 0x0006000c,
1030                                0x000f0010, 0x00040009, %[ff_pw_64], %[ff_pw_1])
1031
1032         /* ftmp16:dst13,dst12,dst11,dst10 ftmp21:dst63,dst62,dst61,dst60 */
1033         VC1_INV_TRANCS_8_TYPE2(%[ftmp16], %[ftmp21], 0x0006000c, 0xfff0fff4,
1034                                0xfffc000f, 0xfff7fff0, %[ff_pw_64], %[ff_pw_1])
1035
1036         /* ftmp17:dst23,dst22,dst21,dst20 ftmp20:dst53,dst52,dst51,dst50 */
1037         VC1_INV_TRANCS_8_TYPE2(%[ftmp17], %[ftmp20], 0xfffa000c, 0x0010fff4,
1038                                0xfff00009, 0x000f0004, %[ff_pw_64], %[ff_pw_1])
1039
1040         /* ftmp18:dst33,dst32,dst31,dst30 ftmp19:dst43,dst42,dst41,dst40 */
1041         VC1_INV_TRANCS_8_TYPE2(%[ftmp18], %[ftmp19], 0xfff0000c, 0xfffa000c,
1042                                0xfff70004, 0xfff0000f, %[ff_pw_64], %[ff_pw_1])
1043
1044         MMI_LWC1(%[ftmp1], %[dest], 0x00)
1045         PTR_ADDU  "%[tmp0],   %[dest],    %[linesize]                 \n\t"
1046         MMI_LWC1(%[ftmp2], %[tmp0], 0x00)
1047         PTR_ADDU  "%[tmp0],   %[tmp0],    %[linesize]                 \n\t"
1048         MMI_LWC1(%[ftmp3], %[tmp0], 0x00)
1049         PTR_ADDU  "%[tmp0],   %[tmp0],    %[linesize]                 \n\t"
1050         MMI_LWC1(%[ftmp4], %[tmp0], 0x00)
1051         PTR_ADDU  "%[tmp0],   %[tmp0],    %[linesize]                 \n\t"
1052         MMI_LWC1(%[ftmp5], %[tmp0], 0x00)
1053         PTR_ADDU  "%[tmp0],   %[tmp0],    %[linesize]                 \n\t"
1054         MMI_LWC1(%[ftmp6], %[tmp0], 0x00)
1055         PTR_ADDU  "%[tmp0],   %[tmp0],    %[linesize]                 \n\t"
1056         MMI_LWC1(%[ftmp7], %[tmp0], 0x00)
1057         PTR_ADDU  "%[tmp0],   %[tmp0],    %[linesize]                 \n\t"
1058         MMI_LWC1(%[ftmp8], %[tmp0], 0x00)
1059         "xor        %[ftmp0],   %[ftmp0],   %[ftmp0]                    \n\t"
1060         "punpcklbh  %[ftmp1],   %[ftmp1],   %[ftmp0]                    \n\t"
1061         "punpcklbh  %[ftmp2],   %[ftmp2],   %[ftmp0]                    \n\t"
1062         "punpcklbh  %[ftmp3],   %[ftmp3],   %[ftmp0]                    \n\t"
1063         "punpcklbh  %[ftmp4],   %[ftmp4],   %[ftmp0]                    \n\t"
1064         "punpcklbh  %[ftmp5],   %[ftmp5],   %[ftmp0]                    \n\t"
1065         "punpcklbh  %[ftmp6],   %[ftmp6],   %[ftmp0]                    \n\t"
1066         "punpcklbh  %[ftmp7],   %[ftmp7],   %[ftmp0]                    \n\t"
1067         "punpcklbh  %[ftmp8],   %[ftmp8],   %[ftmp0]                    \n\t"
1068
1069         "paddh      %[ftmp1],   %[ftmp1],   %[ftmp15]                   \n\t"
1070         "paddh      %[ftmp2],   %[ftmp2],   %[ftmp16]                   \n\t"
1071         "paddh      %[ftmp3],   %[ftmp3],   %[ftmp17]                   \n\t"
1072         "paddh      %[ftmp4],   %[ftmp4],   %[ftmp18]                   \n\t"
1073         "paddh      %[ftmp5],   %[ftmp5],   %[ftmp19]                   \n\t"
1074         "paddh      %[ftmp6],   %[ftmp6],   %[ftmp20]                   \n\t"
1075         "paddh      %[ftmp7],   %[ftmp7],   %[ftmp21]                   \n\t"
1076         "paddh      %[ftmp8],   %[ftmp8],   %[ftmp22]                   \n\t"
1077
1078         "packushb   %[ftmp1],   %[ftmp1],   %[ftmp0]                    \n\t"
1079         "packushb   %[ftmp2],   %[ftmp2],   %[ftmp0]                    \n\t"
1080         "packushb   %[ftmp3],   %[ftmp3],   %[ftmp0]                    \n\t"
1081         "packushb   %[ftmp4],   %[ftmp4],   %[ftmp0]                    \n\t"
1082         "packushb   %[ftmp5],   %[ftmp5],   %[ftmp0]                    \n\t"
1083         "packushb   %[ftmp6],   %[ftmp6],   %[ftmp0]                    \n\t"
1084         "packushb   %[ftmp7],   %[ftmp7],   %[ftmp0]                    \n\t"
1085         "packushb   %[ftmp8],   %[ftmp8],   %[ftmp0]                    \n\t"
1086
1087         MMI_SWC1(%[ftmp1], %[dest], 0x00)
1088         PTR_ADDU   "%[tmp0],    %[dest],    %[linesize]                 \n\t"
1089         MMI_SWC1(%[ftmp2], %[tmp0], 0x00)
1090         PTR_ADDU   "%[tmp0],    %[tmp0],    %[linesize]                 \n\t"
1091         MMI_SWC1(%[ftmp3], %[tmp0], 0x00)
1092         PTR_ADDU   "%[tmp0],    %[tmp0],    %[linesize]                 \n\t"
1093         MMI_SWC1(%[ftmp4], %[tmp0], 0x00)
1094         PTR_ADDU   "%[tmp0],    %[tmp0],    %[linesize]                 \n\t"
1095         MMI_SWC1(%[ftmp5], %[tmp0], 0x00)
1096         PTR_ADDU   "%[tmp0],    %[tmp0],    %[linesize]                 \n\t"
1097         MMI_SWC1(%[ftmp6], %[tmp0], 0x00)
1098         PTR_ADDU   "%[tmp0],    %[tmp0],    %[linesize]                 \n\t"
1099         MMI_SWC1(%[ftmp7], %[tmp0], 0x00)
1100         PTR_ADDU   "%[tmp0],    %[tmp0],    %[linesize]                 \n\t"
1101         MMI_SWC1(%[ftmp8], %[tmp0], 0x00)
1102
1103         : [ftmp0]"=&f"(ftmp[0]),        [ftmp1]"=&f"(ftmp[1]),
1104           [ftmp2]"=&f"(ftmp[2]),        [ftmp3]"=&f"(ftmp[3]),
1105           [ftmp4]"=&f"(ftmp[4]),        [ftmp5]"=&f"(ftmp[5]),
1106           [ftmp6]"=&f"(ftmp[6]),        [ftmp7]"=&f"(ftmp[7]),
1107           [ftmp8]"=&f"(ftmp[8]),        [ftmp9]"=&f"(ftmp[9]),
1108           [ftmp10]"=&f"(ftmp[10]),      [ftmp11]"=&f"(ftmp[11]),
1109           [ftmp12]"=&f"(ftmp[12]),      [ftmp13]"=&f"(ftmp[13]),
1110           [ftmp14]"=&f"(ftmp[14]),      [ftmp15]"=&f"(ftmp[15]),
1111           [ftmp16]"=&f"(ftmp[16]),      [ftmp17]"=&f"(ftmp[17]),
1112           [ftmp18]"=&f"(ftmp[18]),      [ftmp19]"=&f"(ftmp[19]),
1113           [ftmp20]"=&f"(ftmp[20]),      [ftmp21]"=&f"(ftmp[21]),
1114           [ftmp22]"=&f"(ftmp[22]),
1115           [tmp0]"=&r"(tmp[0])
1116         : [ff_pw_1]"f"(ff_pw_1_local),  [ff_pw_64]"f"(ff_pw_64_local),
1117           [src]"r"(src), [dest]"r"(dest), [linesize]"r"(linesize)
1118         : "memory"
1119     );
1120 }
1121 #endif
1122
1123 /* Do inverse transform on 4x4 part of block */
1124 void ff_vc1_inv_trans_4x4_dc_mmi(uint8_t *dest, ptrdiff_t linesize, int16_t *block)
1125 {
1126     int dc = block[0];
1127     double ftmp[5];
1128     DECLARE_VAR_LOW32;
1129
1130     dc = (17 * dc +  4) >> 3;
1131     dc = (17 * dc + 64) >> 7;
1132
1133     __asm__ volatile(
1134         "xor        %[ftmp0],   %[ftmp0],       %[ftmp0]                \n\t"
1135         "pshufh     %[dc],      %[dc],          %[ftmp0]                \n\t"
1136
1137         MMI_LWC1(%[ftmp1], %[dest0], 0x00)
1138         MMI_LWC1(%[ftmp2], %[dest1], 0x00)
1139         MMI_LWC1(%[ftmp3], %[dest2], 0x00)
1140         MMI_LWC1(%[ftmp4], %[dest3], 0x00)
1141
1142         "punpcklbh  %[ftmp1],   %[ftmp1],       %[ftmp0]                \n\t"
1143         "punpcklbh  %[ftmp2],   %[ftmp2],       %[ftmp0]                \n\t"
1144         "punpcklbh  %[ftmp3],   %[ftmp3],       %[ftmp0]                \n\t"
1145         "punpcklbh  %[ftmp4],   %[ftmp4],       %[ftmp0]                \n\t"
1146
1147         "paddsh     %[ftmp1],   %[ftmp1],       %[dc]                   \n\t"
1148         "paddsh     %[ftmp2],   %[ftmp2],       %[dc]                   \n\t"
1149         "paddsh     %[ftmp3],   %[ftmp3],       %[dc]                   \n\t"
1150         "paddsh     %[ftmp4],   %[ftmp4],       %[dc]                   \n\t"
1151
1152         "packushb   %[ftmp1],   %[ftmp1],       %[ftmp0]                \n\t"
1153         "packushb   %[ftmp2],   %[ftmp2],       %[ftmp0]                \n\t"
1154         "packushb   %[ftmp3],   %[ftmp3],       %[ftmp0]                \n\t"
1155         "packushb   %[ftmp4],   %[ftmp4],       %[ftmp0]                \n\t"
1156
1157         MMI_SWC1(%[ftmp1], %[dest0], 0x00)
1158         MMI_SWC1(%[ftmp2], %[dest1], 0x00)
1159         MMI_SWC1(%[ftmp3], %[dest2], 0x00)
1160         MMI_SWC1(%[ftmp4], %[dest3], 0x00)
1161         : [ftmp0]"=&f"(ftmp[0]),        [ftmp1]"=&f"(ftmp[1]),
1162           [ftmp2]"=&f"(ftmp[2]),        [ftmp3]"=&f"(ftmp[3]),
1163           RESTRICT_ASM_LOW32
1164           [ftmp4]"=&f"(ftmp[4])
1165         : [dest0]"r"(dest+0*linesize),  [dest1]"r"(dest+1*linesize),
1166           [dest2]"r"(dest+2*linesize),  [dest3]"r"(dest+3*linesize),
1167           [dc]"f"(dc)
1168         : "memory"
1169     );
1170 }
1171
1172 void ff_vc1_inv_trans_4x4_mmi(uint8_t *dest, ptrdiff_t linesize, int16_t *block)
1173 {
1174     int16_t *src = block;
1175     int16_t *dst = block;
1176     double ftmp[16];
1177     uint32_t count = 4, tmp[1];
1178     int16_t coeff[16] = {17, 22, 17, 10,
1179                          17, 10,-17,-22,
1180                          17,-10,-17, 22,
1181                          17,-22, 17,-10};
1182     DECLARE_ALIGNED(8, const uint64_t, ff_pw_4_local) = {0x0000000400000004ULL};
1183     DECLARE_ALIGNED(8, const uint64_t, ff_pw_64_local)= {0x0000004000000040ULL};
1184     // 1st loop
1185     __asm__ volatile (
1186
1187         "li         %[tmp0],    0x03                                    \n\t"
1188         "mtc1       %[tmp0],    %[ftmp0]                                \n\t"
1189         MMI_LDC1(%[ftmp2], %[coeff], 0x00)
1190         MMI_LDC1(%[ftmp3], %[coeff], 0x08)
1191         MMI_LDC1(%[ftmp4], %[coeff], 0x10)
1192         MMI_LDC1(%[ftmp5], %[coeff], 0x18)
1193         "1:                                                             \n\t"
1194         /* ftmp8: dst3,dst2,dst1,dst0 */
1195         MMI_LDC1(%[ftmp1], %[src], 0x00)
1196         "pmaddhw    %[ftmp6],   %[ftmp2],   %[ftmp1]                    \n\t"
1197         "pmaddhw    %[ftmp7],   %[ftmp3],   %[ftmp1]                    \n\t"
1198         "pmaddhw    %[ftmp8],   %[ftmp4],   %[ftmp1]                    \n\t"
1199         "pmaddhw    %[ftmp9],   %[ftmp5],   %[ftmp1]                    \n\t"
1200         "punpcklwd  %[ftmp10],  %[ftmp6],   %[ftmp7]                    \n\t"
1201         "punpckhwd  %[ftmp11],  %[ftmp6],   %[ftmp7]                    \n\t"
1202         "punpcklwd  %[ftmp6],   %[ftmp8],   %[ftmp9]                    \n\t"
1203         "punpckhwd  %[ftmp7],   %[ftmp8],   %[ftmp9]                    \n\t"
1204         "paddw      %[ftmp8],   %[ftmp10],  %[ftmp11]                   \n\t"
1205         "paddw      %[ftmp9],   %[ftmp6],   %[ftmp7]                    \n\t"
1206         "paddw      %[ftmp8],   %[ftmp8],   %[ff_pw_4]                  \n\t"
1207         "paddw      %[ftmp9],   %[ftmp9],   %[ff_pw_4]                  \n\t"
1208         "psraw      %[ftmp8],   %[ftmp8],   %[ftmp0]                    \n\t"
1209         "psraw      %[ftmp9],   %[ftmp9],   %[ftmp0]                    \n\t"
1210         "punpcklhw  %[ftmp6],   %[ftmp8],   %[ftmp9]                    \n\t"
1211         "punpckhhw  %[ftmp7],   %[ftmp8],   %[ftmp9]                    \n\t"
1212         "punpcklhw  %[ftmp8],   %[ftmp6],   %[ftmp7]                    \n\t"
1213         MMI_SDC1(%[ftmp8], %[dst], 0x00)
1214
1215         PTR_ADDIU  "%[src],     %[src],     0x10                        \n\t"
1216         PTR_ADDIU  "%[dst],     %[dst],     0x10                        \n\t"
1217         "addiu      %[count],   %[count],   -0x01                       \n\t"
1218         "bnez       %[count],   1b                                      \n\t"
1219         : [ftmp0]"=&f"(ftmp[0]),        [ftmp1]"=&f"(ftmp[1]),
1220           [ftmp2]"=&f"(ftmp[2]),        [ftmp3]"=&f"(ftmp[3]),
1221           [ftmp4]"=&f"(ftmp[4]),        [ftmp5]"=&f"(ftmp[5]),
1222           [ftmp6]"=&f"(ftmp[6]),        [ftmp7]"=&f"(ftmp[7]),
1223           [ftmp8]"=&f"(ftmp[8]),        [ftmp9]"=&f"(ftmp[9]),
1224           [ftmp10]"=&f"(ftmp[10]),      [ftmp11]"=&f"(ftmp[11]),
1225           [tmp0]"=&r"(tmp[0]),          [count]"+&r"(count),
1226           [src]"+&r"(src),              [dst]"+&r"(dst)
1227         : [ff_pw_4]"f"(ff_pw_4_local),  [coeff]"r"(coeff)
1228         : "memory"
1229     );
1230
1231     src = block;
1232
1233     // 2nd loop
1234     __asm__ volatile (
1235         "li         %[tmp0],    0x07                                    \n\t"
1236         "mtc1       %[tmp0],    %[ftmp0]                                \n\t"
1237         "li         %[tmp0],    0x44                                    \n\t"
1238         "mtc1       %[tmp0],    %[ftmp15]                               \n\t"
1239
1240         MMI_LDC1(%[ftmp1], %[src], 0x00)
1241         MMI_LDC1(%[ftmp2], %[src], 0x10)
1242         MMI_LDC1(%[ftmp3], %[src], 0x20)
1243         MMI_LDC1(%[ftmp4], %[src], 0x30)
1244         "punpcklhw  %[ftmp5],   %[ftmp1],   %[ftmp2]                    \n\t"
1245         "punpckhhw  %[ftmp6],   %[ftmp1],   %[ftmp2]                    \n\t"
1246         "punpcklhw  %[ftmp7],   %[ftmp3],   %[ftmp4]                    \n\t"
1247         "punpckhhw  %[ftmp8],   %[ftmp3],   %[ftmp4]                    \n\t"
1248
1249         /* ftmp11: dst03,dst02,dst01,dst00 */
1250         "li         %[tmp0],    0x00160011                              \n\t"
1251         "mtc1       %[tmp0],    %[ftmp3]                                \n\t"
1252         "pshufh     %[ftmp3],   %[ftmp3],   %[ftmp15]                   \n\t"
1253         "li         %[tmp0],    0x000a0011                              \n\t"
1254         "mtc1       %[tmp0],    %[ftmp4]                                \n\t"
1255         "pshufh     %[ftmp4],   %[ftmp4],   %[ftmp15]                   \n\t"
1256         "pmaddhw    %[ftmp1],   %[ftmp5],   %[ftmp3]                    \n\t"
1257         "pmaddhw    %[ftmp2],   %[ftmp7],   %[ftmp4]                    \n\t"
1258         "paddw      %[ftmp9],   %[ftmp1],   %[ftmp2]                    \n\t"
1259         "pmaddhw    %[ftmp1],   %[ftmp6],   %[ftmp3]                    \n\t"
1260         "pmaddhw    %[ftmp2],   %[ftmp8],   %[ftmp4]                    \n\t"
1261         "paddw      %[ftmp10],  %[ftmp1],   %[ftmp2]                    \n\t"
1262         "paddw      %[ftmp9],   %[ftmp9],   %[ff_pw_64]                 \n\t"
1263         "paddw      %[ftmp10],  %[ftmp10],  %[ff_pw_64]                 \n\t"
1264         "psraw      %[ftmp9],   %[ftmp9],   %[ftmp0]                    \n\t"
1265         "psraw      %[ftmp10],  %[ftmp10],  %[ftmp0]                    \n\t"
1266         "punpcklhw  %[ftmp1],   %[ftmp9],   %[ftmp10]                   \n\t"
1267         "punpckhhw  %[ftmp2],   %[ftmp9],   %[ftmp10]                   \n\t"
1268         "punpcklhw  %[ftmp11],  %[ftmp1],   %[ftmp2]                    \n\t"
1269
1270         /* ftmp12: dst13,dst12,dst11,dst10 */
1271         "li         %[tmp0],    0x000a0011                              \n\t"
1272         "mtc1       %[tmp0],    %[ftmp3]                                \n\t"
1273         "pshufh     %[ftmp3],   %[ftmp3],   %[ftmp15]                   \n\t"
1274         "li         %[tmp0],    0xffeaffef                              \n\t"
1275         "mtc1       %[tmp0],    %[ftmp4]                                \n\t"
1276         "pshufh     %[ftmp4],   %[ftmp4],   %[ftmp15]                   \n\t"
1277         "pmaddhw    %[ftmp1],   %[ftmp5],   %[ftmp3]                    \n\t"
1278         "pmaddhw    %[ftmp2],   %[ftmp7],   %[ftmp4]                    \n\t"
1279         "paddw      %[ftmp9],   %[ftmp1],   %[ftmp2]                    \n\t"
1280         "pmaddhw    %[ftmp1],   %[ftmp6],   %[ftmp3]                    \n\t"
1281         "pmaddhw    %[ftmp2],   %[ftmp8],   %[ftmp4]                    \n\t"
1282         "paddw      %[ftmp10],  %[ftmp1],   %[ftmp2]                    \n\t"
1283         "paddw      %[ftmp9],   %[ftmp9],   %[ff_pw_64]                 \n\t"
1284         "paddw      %[ftmp10],  %[ftmp10],  %[ff_pw_64]                 \n\t"
1285         "psraw      %[ftmp9],   %[ftmp9],   %[ftmp0]                    \n\t"
1286         "psraw      %[ftmp10],  %[ftmp10],  %[ftmp0]                    \n\t"
1287         "punpcklhw  %[ftmp1],   %[ftmp9],   %[ftmp10]                   \n\t"
1288         "punpckhhw  %[ftmp2],   %[ftmp9],   %[ftmp10]                   \n\t"
1289         "punpcklhw  %[ftmp12],  %[ftmp1],   %[ftmp2]                    \n\t"
1290
1291         /* ftmp13: dst23,dst22,dst21,dst20 */
1292         "li         %[tmp0],    0xfff60011                              \n\t"
1293         "mtc1       %[tmp0],    %[ftmp3]                                \n\t"
1294         "pshufh     %[ftmp3],   %[ftmp3],   %[ftmp15]                   \n\t"
1295         "li         %[tmp0],    0x0016ffef                              \n\t"
1296         "mtc1       %[tmp0],    %[ftmp4]                                \n\t"
1297         "pshufh     %[ftmp4],   %[ftmp4],   %[ftmp15]                   \n\t"
1298         "pmaddhw    %[ftmp1],   %[ftmp5],   %[ftmp3]                    \n\t"
1299         "pmaddhw    %[ftmp2],   %[ftmp7],   %[ftmp4]                    \n\t"
1300         "paddw      %[ftmp9],   %[ftmp1],   %[ftmp2]                    \n\t"
1301         "pmaddhw    %[ftmp1],   %[ftmp6],   %[ftmp3]                    \n\t"
1302         "pmaddhw    %[ftmp2],   %[ftmp8],   %[ftmp4]                    \n\t"
1303         "paddw      %[ftmp10],  %[ftmp1],   %[ftmp2]                    \n\t"
1304         "paddw      %[ftmp9],   %[ftmp9],   %[ff_pw_64]                 \n\t"
1305         "paddw      %[ftmp10],  %[ftmp10],  %[ff_pw_64]                 \n\t"
1306         "psraw      %[ftmp9],   %[ftmp9],   %[ftmp0]                    \n\t"
1307         "psraw      %[ftmp10],  %[ftmp10],  %[ftmp0]                    \n\t"
1308         "punpcklhw  %[ftmp1],   %[ftmp9],   %[ftmp10]                   \n\t"
1309         "punpckhhw  %[ftmp2],   %[ftmp9],   %[ftmp10]                   \n\t"
1310         "punpcklhw  %[ftmp13],  %[ftmp1],   %[ftmp2]                    \n\t"
1311
1312         /* ftmp14: dst33,dst32,dst31,dst30 */
1313         "li         %[tmp0],    0xffea0011                              \n\t"
1314         "mtc1       %[tmp0],    %[ftmp3]                                \n\t"
1315         "pshufh     %[ftmp3],   %[ftmp3],   %[ftmp15]                   \n\t"
1316         "li         %[tmp0],    0xfff60011                              \n\t"
1317         "mtc1       %[tmp0],    %[ftmp4]                                \n\t"
1318         "pshufh     %[ftmp4],   %[ftmp4],   %[ftmp15]                   \n\t"
1319         "pmaddhw    %[ftmp1],   %[ftmp5],   %[ftmp3]                    \n\t"
1320         "pmaddhw    %[ftmp2],   %[ftmp7],   %[ftmp4]                    \n\t"
1321         "paddw      %[ftmp9],   %[ftmp1],   %[ftmp2]                    \n\t"
1322         "pmaddhw    %[ftmp1],   %[ftmp6],   %[ftmp3]                    \n\t"
1323         "pmaddhw    %[ftmp2],   %[ftmp8],   %[ftmp4]                    \n\t"
1324         "paddw      %[ftmp10],  %[ftmp1],   %[ftmp2]                    \n\t"
1325         "paddw      %[ftmp9],   %[ftmp9],   %[ff_pw_64]                 \n\t"
1326         "paddw      %[ftmp10],  %[ftmp10],  %[ff_pw_64]                 \n\t"
1327         "psraw      %[ftmp9],   %[ftmp9],   %[ftmp0]                    \n\t"
1328         "psraw      %[ftmp10],  %[ftmp10],  %[ftmp0]                    \n\t"
1329         "punpcklhw  %[ftmp1],   %[ftmp9],   %[ftmp10]                   \n\t"
1330         "punpckhhw  %[ftmp2],   %[ftmp9],   %[ftmp10]                   \n\t"
1331         "punpcklhw  %[ftmp14],  %[ftmp1],   %[ftmp2]                    \n\t"
1332
1333         MMI_LWC1(%[ftmp1], %[dest], 0x00)
1334         PTR_ADDU    "%[tmp0],   %[dest],    %[linesize]                 \n\t"
1335         MMI_LWC1(%[ftmp2], %[tmp0], 0x00)
1336         PTR_ADDU    "%[tmp0],   %[tmp0],    %[linesize]                 \n\t"
1337         MMI_LWC1(%[ftmp3], %[tmp0], 0x00)
1338         PTR_ADDU    "%[tmp0],   %[tmp0],    %[linesize]                 \n\t"
1339         MMI_LWC1(%[ftmp4], %[tmp0], 0x00)
1340         "xor        %[ftmp0],   %[ftmp0],   %[ftmp0]                    \n\t"
1341         "punpcklbh  %[ftmp1],   %[ftmp1],   %[ftmp0]                    \n\t"
1342         "punpcklbh  %[ftmp2],   %[ftmp2],   %[ftmp0]                    \n\t"
1343         "punpcklbh  %[ftmp3],   %[ftmp3],   %[ftmp0]                    \n\t"
1344         "punpcklbh  %[ftmp4],   %[ftmp4],   %[ftmp0]                    \n\t"
1345         "paddh      %[ftmp1],   %[ftmp1],   %[ftmp11]                   \n\t"
1346         "paddh      %[ftmp2],   %[ftmp2],   %[ftmp12]                   \n\t"
1347         "paddh      %[ftmp3],   %[ftmp3],   %[ftmp13]                   \n\t"
1348         "paddh      %[ftmp4],   %[ftmp4],   %[ftmp14]                   \n\t"
1349         "packushb   %[ftmp1],   %[ftmp1],   %[ftmp0]                    \n\t"
1350         "packushb   %[ftmp2],   %[ftmp2],   %[ftmp0]                    \n\t"
1351         "packushb   %[ftmp3],   %[ftmp3],   %[ftmp0]                    \n\t"
1352         "packushb   %[ftmp4],   %[ftmp4],   %[ftmp0]                    \n\t"
1353
1354         MMI_SWC1(%[ftmp1], %[dest], 0x00)
1355         PTR_ADDU   "%[tmp0],    %[dest],    %[linesize]                 \n\t"
1356         MMI_SWC1(%[ftmp2], %[tmp0], 0x00)
1357         PTR_ADDU   "%[tmp0],    %[tmp0],    %[linesize]                 \n\t"
1358         MMI_SWC1(%[ftmp3], %[tmp0], 0x00)
1359         PTR_ADDU   "%[tmp0],    %[tmp0],    %[linesize]                 \n\t"
1360         MMI_SWC1(%[ftmp4], %[tmp0], 0x00)
1361
1362         : [ftmp0]"=&f"(ftmp[0]),        [ftmp1]"=&f"(ftmp[1]),
1363           [ftmp2]"=&f"(ftmp[2]),        [ftmp3]"=&f"(ftmp[3]),
1364           [ftmp4]"=&f"(ftmp[4]),        [ftmp5]"=&f"(ftmp[5]),
1365           [ftmp6]"=&f"(ftmp[6]),        [ftmp7]"=&f"(ftmp[7]),
1366           [ftmp8]"=&f"(ftmp[8]),        [ftmp9]"=&f"(ftmp[9]),
1367           [ftmp10]"=&f"(ftmp[10]),      [ftmp11]"=&f"(ftmp[11]),
1368           [ftmp12]"=&f"(ftmp[12]),      [ftmp13]"=&f"(ftmp[13]),
1369           [ftmp14]"=&f"(ftmp[14]),      [ftmp15]"=&f"(ftmp[15]),
1370           [tmp0]"=&r"(tmp[0])
1371         : [ff_pw_64]"f"(ff_pw_64_local),
1372           [src]"r"(src), [dest]"r"(dest), [linesize]"r"(linesize)
1373         :"memory"
1374     );
1375 }
1376
1377 /* Apply overlap transform to horizontal edge */
1378 void ff_vc1_h_overlap_mmi(uint8_t *src, int stride)
1379 {
1380     int i;
1381     int a, b, c, d;
1382     int d1, d2;
1383     int rnd = 1;
1384     for (i = 0; i < 8; i++) {
1385         a  = src[-2];
1386         b  = src[-1];
1387         c  = src[0];
1388         d  = src[1];
1389         d1 = (a - d + 3 + rnd) >> 3;
1390         d2 = (a - d + b - c + 4 - rnd) >> 3;
1391
1392         src[-2] = a - d1;
1393         src[-1] = av_clip_uint8(b - d2);
1394         src[0]  = av_clip_uint8(c + d2);
1395         src[1]  = d + d1;
1396         src    += stride;
1397         rnd     = !rnd;
1398     }
1399 }
1400
1401 void ff_vc1_h_s_overlap_mmi(int16_t *left, int16_t *right, int left_stride, int right_stride, int flags)
1402 {
1403     int i;
1404     int a, b, c, d;
1405     int d1, d2;
1406     int rnd1 = flags & 2 ? 3 : 4;
1407     int rnd2 = 7 - rnd1;
1408     for (i = 0; i < 8; i++) {
1409         a  = left[6];
1410         b  = left[7];
1411         c  = right[0];
1412         d  = right[1];
1413         d1 = a - d;
1414         d2 = a - d + b - c;
1415
1416         left[6]  = ((a << 3) - d1 + rnd1) >> 3;
1417         left[7]  = ((b << 3) - d2 + rnd2) >> 3;
1418         right[0] = ((c << 3) + d2 + rnd1) >> 3;
1419         right[1] = ((d << 3) + d1 + rnd2) >> 3;
1420
1421         right += right_stride;
1422         left  += left_stride;
1423         if (flags & 1) {
1424             rnd2   = 7 - rnd2;
1425             rnd1   = 7 - rnd1;
1426         }
1427     }
1428 }
1429
1430 /* Apply overlap transform to vertical edge */
1431 void ff_vc1_v_overlap_mmi(uint8_t *src, int stride)
1432 {
1433     int i;
1434     int a, b, c, d;
1435     int d1, d2;
1436     int rnd = 1;
1437     for (i = 0; i < 8; i++) {
1438         a  = src[-2 * stride];
1439         b  = src[-stride];
1440         c  = src[0];
1441         d  = src[stride];
1442         d1 = (a - d + 3 + rnd) >> 3;
1443         d2 = (a - d + b - c + 4 - rnd) >> 3;
1444
1445         src[-2 * stride] = a - d1;
1446         src[-stride]     = av_clip_uint8(b - d2);
1447         src[0]           = av_clip_uint8(c + d2);
1448         src[stride]      = d + d1;
1449         src++;
1450         rnd = !rnd;
1451     }
1452 }
1453
1454 void ff_vc1_v_s_overlap_mmi(int16_t *top, int16_t *bottom)
1455 {
1456     int i;
1457     int a, b, c, d;
1458     int d1, d2;
1459     int rnd1 = 4, rnd2 = 3;
1460     for (i = 0; i < 8; i++) {
1461         a  = top[48];
1462         b  = top[56];
1463         c  = bottom[0];
1464         d  = bottom[8];
1465         d1 = a - d;
1466         d2 = a - d + b - c;
1467
1468         top[48]   = ((a << 3) - d1 + rnd1) >> 3;
1469         top[56]   = ((b << 3) - d2 + rnd2) >> 3;
1470         bottom[0] = ((c << 3) + d2 + rnd1) >> 3;
1471         bottom[8] = ((d << 3) + d1 + rnd2) >> 3;
1472
1473         bottom++;
1474         top++;
1475         rnd2 = 7 - rnd2;
1476         rnd1 = 7 - rnd1;
1477     }
1478 }
1479
1480 /**
1481  * VC-1 in-loop deblocking filter for one line
1482  * @param src source block type
1483  * @param stride block stride
1484  * @param pq block quantizer
1485  * @return whether other 3 pairs should be filtered or not
1486  * @see 8.6
1487  */
1488 static av_always_inline int vc1_filter_line(uint8_t *src, int stride, int pq)
1489 {
1490     int a0 = (2 * (src[-2 * stride] - src[1 * stride]) -
1491               5 * (src[-1 * stride] - src[0 * stride]) + 4) >> 3;
1492     int a0_sign = a0 >> 31;        /* Store sign */
1493
1494     a0 = (a0 ^ a0_sign) - a0_sign; /* a0 = FFABS(a0); */
1495     if (a0 < pq) {
1496         int a1 = FFABS((2 * (src[-4 * stride] - src[-1 * stride]) -
1497                         5 * (src[-3 * stride] - src[-2 * stride]) + 4) >> 3);
1498         int a2 = FFABS((2 * (src[ 0 * stride] - src[ 3 * stride]) -
1499                         5 * (src[ 1 * stride] - src[ 2 * stride]) + 4) >> 3);
1500         if (a1 < a0 || a2 < a0) {
1501             int clip      = src[-1 * stride] - src[0 * stride];
1502             int clip_sign = clip >> 31;
1503
1504             clip = ((clip ^ clip_sign) - clip_sign) >> 1;
1505             if (clip) {
1506                 int a3     = FFMIN(a1, a2);
1507                 int d      = 5 * (a3 - a0);
1508                 int d_sign = (d >> 31);
1509
1510                 d       = ((d ^ d_sign) - d_sign) >> 3;
1511                 d_sign ^= a0_sign;
1512
1513                 if (d_sign ^ clip_sign)
1514                     d = 0;
1515                 else {
1516                     d = FFMIN(d, clip);
1517                     d = (d ^ d_sign) - d_sign; /* Restore sign */
1518                     src[-1 * stride] = av_clip_uint8(src[-1 * stride] - d);
1519                     src[ 0 * stride] = av_clip_uint8(src[ 0 * stride] + d);
1520                 }
1521                 return 1;
1522             }
1523         }
1524     }
1525     return 0;
1526 }
1527
1528 /**
1529  * VC-1 in-loop deblocking filter
1530  * @param src source block type
1531  * @param step distance between horizontally adjacent elements
1532  * @param stride distance between vertically adjacent elements
1533  * @param len edge length to filter (4 or 8 pixels)
1534  * @param pq block quantizer
1535  * @see 8.6
1536  */
1537 static inline void vc1_loop_filter(uint8_t *src, int step, int stride,
1538                                    int len, int pq)
1539 {
1540     int i;
1541     int filt3;
1542
1543     for (i = 0; i < len; i += 4) {
1544         filt3 = vc1_filter_line(src + 2 * step, stride, pq);
1545         if (filt3) {
1546             vc1_filter_line(src + 0 * step, stride, pq);
1547             vc1_filter_line(src + 1 * step, stride, pq);
1548             vc1_filter_line(src + 3 * step, stride, pq);
1549         }
1550         src += step * 4;
1551     }
1552 }
1553
1554 void ff_vc1_v_loop_filter4_mmi(uint8_t *src, int stride, int pq)
1555 {
1556     vc1_loop_filter(src, 1, stride, 4, pq);
1557 }
1558
1559 void ff_vc1_h_loop_filter4_mmi(uint8_t *src, int stride, int pq)
1560 {
1561     vc1_loop_filter(src, stride, 1, 4, pq);
1562 }
1563
1564 void ff_vc1_v_loop_filter8_mmi(uint8_t *src, int stride, int pq)
1565 {
1566     vc1_loop_filter(src, 1, stride, 8, pq);
1567 }
1568
1569 void ff_vc1_h_loop_filter8_mmi(uint8_t *src, int stride, int pq)
1570 {
1571     vc1_loop_filter(src, stride, 1, 8, pq);
1572 }
1573
1574 void ff_vc1_v_loop_filter16_mmi(uint8_t *src, int stride, int pq)
1575 {
1576     vc1_loop_filter(src, 1, stride, 16, pq);
1577 }
1578
1579 void ff_vc1_h_loop_filter16_mmi(uint8_t *src, int stride, int pq)
1580 {
1581     vc1_loop_filter(src, stride, 1, 16, pq);
1582 }
1583
1584 void ff_put_vc1_mspel_mc00_mmi(uint8_t *dst, const uint8_t *src,
1585                                ptrdiff_t stride, int rnd)
1586 {
1587     ff_put_pixels8_8_mmi(dst, src, stride, 8);
1588 }
1589 void ff_put_vc1_mspel_mc00_16_mmi(uint8_t *dst, const uint8_t *src,
1590                                   ptrdiff_t stride, int rnd)
1591 {
1592     ff_put_pixels16_8_mmi(dst, src, stride, 16);
1593 }
1594 void ff_avg_vc1_mspel_mc00_mmi(uint8_t *dst, const uint8_t *src,
1595                                ptrdiff_t stride, int rnd)
1596 {
1597     ff_avg_pixels8_8_mmi(dst, src, stride, 8);
1598 }
1599 void ff_avg_vc1_mspel_mc00_16_mmi(uint8_t *dst, const uint8_t *src,
1600                                   ptrdiff_t stride, int rnd)
1601 {
1602     ff_avg_pixels16_8_mmi(dst, src, stride, 16);
1603 }
1604
1605 #define OP_PUT(S, D)
1606 #define OP_AVG(S, D)                                                        \
1607     "ldc1       $f16,   "#S"                        \n\t"                   \
1608     "pavgb      "#D",   "#D",   $f16                \n\t"
1609
1610 /** Add rounder from $f14 to $f6 and pack result at destination */
1611 #define NORMALIZE_MMI(SHIFT)                                                \
1612     "paddh      $f6,    $f6,    $f14                \n\t" /* +bias-r */     \
1613     "paddh      $f8,    $f8,    $f14                \n\t" /* +bias-r */     \
1614     "psrah      $f6,    $f6,    "SHIFT"             \n\t"                   \
1615     "psrah      $f8,    $f8,    "SHIFT"             \n\t"
1616
1617 #define TRANSFER_DO_PACK(OP)                                                \
1618     "packushb   $f6,    $f6,    $f8                 \n\t"                   \
1619     OP((%[dst]), $f6)                                                       \
1620     "sdc1       $f6,    0x00(%[dst])                \n\t"
1621
1622 #define TRANSFER_DONT_PACK(OP)                                              \
1623      OP(0(%[dst]), $f6)                                                     \
1624      OP(8(%[dst]), $f8)                                                     \
1625      "sdc1      $f6,    0x00(%[dst])                \n\t"                   \
1626      "sdc1      $f8,    0x08(%[dst])                \n\t"
1627
1628 /** @see MSPEL_FILTER13_CORE for use as UNPACK macro */
1629 #define DO_UNPACK(reg)                                                      \
1630     "punpcklbh  "reg",  "reg",  $f0                 \n\t"
1631 #define DONT_UNPACK(reg)
1632
1633 /** Compute the rounder 32-r or 8-r and unpacks it to $f14 */
1634 #define LOAD_ROUNDER_MMI(ROUND)                                             \
1635     "lwc1       $f14,   "ROUND"                     \n\t"                   \
1636     "punpcklhw  $f14,   $f14,   $f14                \n\t"                   \
1637     "punpcklwd  $f14,   $f14,   $f14                \n\t"
1638
1639
1640 #define SHIFT2_LINE(OFF, R0, R1, R2, R3)                                    \
1641     "paddh      "#R1",      "#R1",  "#R2"           \n\t"                   \
1642     PTR_ADDU    "$9,        %[src], %[stride1]      \n\t"                   \
1643     MMI_ULWC1(R0, $9, 0x00)                                                 \
1644     "pmullh     "#R1",      "#R1",  $f6             \n\t"                   \
1645     "punpcklbh  "#R0",      "#R0",  $f0             \n\t"                   \
1646     PTR_ADDU    "$9,        %[src], %[stride]       \n\t"                   \
1647     MMI_ULWC1(R3, $9, 0x00)                                                 \
1648     "psubh      "#R1",      "#R1",  "#R0"           \n\t"                   \
1649     "punpcklbh  "#R3",      "#R3",  $f0             \n\t"                   \
1650     "paddh      "#R1",      "#R1",  $f14            \n\t"                   \
1651     "psubh      "#R1",      "#R1",  "#R3"           \n\t"                   \
1652     "psrah      "#R1",      "#R1",  %[shift]        \n\t"                   \
1653     MMI_SDC1(R1, %[dst], OFF)                                               \
1654     PTR_ADDU    "%[src],    %[src], %[stride]       \n\t"
1655
1656 /** Sacrificing $f12 makes it possible to pipeline loads from src */
1657 static void vc1_put_ver_16b_shift2_mmi(int16_t *dst,
1658                                        const uint8_t *src, mips_reg stride,
1659                                        int rnd, int64_t shift)
1660 {
1661     DECLARE_VAR_LOW32;
1662     DECLARE_VAR_ADDRT;
1663
1664     __asm__ volatile(
1665         "xor        $f0,    $f0,    $f0             \n\t"
1666         "li         $8,     0x03                    \n\t"
1667         LOAD_ROUNDER_MMI("%[rnd]")
1668         "ldc1       $f12,   %[ff_pw_9]              \n\t"
1669         "1:                                         \n\t"
1670         MMI_ULWC1($f4, %[src], 0x00)
1671         PTR_ADDU   "%[src], %[src], %[stride]       \n\t"
1672         MMI_ULWC1($f6, %[src], 0x00)
1673         "punpcklbh  $f4,    $f4,    $f0             \n\t"
1674         "punpcklbh  $f6,    $f6,    $f0             \n\t"
1675         SHIFT2_LINE(  0, $f2, $f4, $f6, $f8)
1676         SHIFT2_LINE( 24, $f4, $f6, $f8, $f2)
1677         SHIFT2_LINE( 48, $f6, $f8, $f2, $f4)
1678         SHIFT2_LINE( 72, $f8, $f2, $f4, $f6)
1679         SHIFT2_LINE( 96, $f2, $f4, $f6, $f8)
1680         SHIFT2_LINE(120, $f4, $f6, $f8, $f2)
1681         SHIFT2_LINE(144, $f6, $f8, $f2, $f4)
1682         SHIFT2_LINE(168, $f8, $f2, $f4, $f6)
1683         PTR_SUBU   "%[src], %[src], %[stride2]      \n\t"
1684         PTR_ADDIU  "%[dst], %[dst], 0x08            \n\t"
1685         "addiu      $8,     $8,    -0x01            \n\t"
1686         "bnez       $8,     1b                      \n\t"
1687         : RESTRICT_ASM_LOW32            RESTRICT_ASM_ADDRT
1688           [src]"+r"(src),               [dst]"+r"(dst)
1689         : [stride]"r"(stride),          [stride1]"r"(-2*stride),
1690           [shift]"f"(shift),            [rnd]"m"(rnd),
1691           [stride2]"r"(9*stride-4),     [ff_pw_9]"m"(ff_pw_9)
1692         : "$8", "$9", "$f0", "$f2", "$f4", "$f6", "$f8", "$f10", "$f12",
1693           "$f14", "$f16", "memory"
1694     );
1695 }
1696
1697 /**
1698  * Data is already unpacked, so some operations can directly be made from
1699  * memory.
1700  */
1701 #define VC1_HOR_16B_SHIFT2(OP, OPNAME)                                      \
1702 static void OPNAME ## vc1_hor_16b_shift2_mmi(uint8_t *dst, mips_reg stride, \
1703                                              const int16_t *src, int rnd)   \
1704 {                                                                           \
1705     int h = 8;                                                              \
1706     DECLARE_VAR_ALL64;                                                      \
1707     DECLARE_VAR_ADDRT;                                                      \
1708                                                                             \
1709     src -= 1;                                                               \
1710     rnd -= (-1+9+9-1)*1024; /* Add -1024 bias */                            \
1711                                                                             \
1712     __asm__ volatile(                                                       \
1713         LOAD_ROUNDER_MMI("%[rnd]")                                          \
1714         "ldc1       $f12,   %[ff_pw_128]            \n\t"                   \
1715         "ldc1       $f10,   %[ff_pw_9]              \n\t"                   \
1716         "1:                                         \n\t"                   \
1717         MMI_ULDC1($f2, %[src], 0x00)                                        \
1718         MMI_ULDC1($f4, %[src], 0x08)                                        \
1719         MMI_ULDC1($f6, %[src], 0x02)                                        \
1720         MMI_ULDC1($f8, %[src], 0x0a)                                        \
1721         MMI_ULDC1($f0, %[src], 0x06)                                        \
1722         "paddh      $f2,    $f2,    $f0             \n\t"                   \
1723         MMI_ULDC1($f0, %[src], 0x0e)                                        \
1724         "paddh      $f4,    $f4,    $f0             \n\t"                   \
1725         MMI_ULDC1($f0, %[src], 0x04)                                        \
1726         "paddh      $f6,    $f6,    $f0             \n\t"                   \
1727         MMI_ULDC1($f0, %[src], 0x0b)                                        \
1728         "paddh      $f8,    $f8,    $f0             \n\t"                   \
1729         "pmullh     $f6,    $f6,    $f10            \n\t"                   \
1730         "pmullh     $f8,    $f8,    $f10            \n\t"                   \
1731         "psubh      $f6,    $f6,    $f2             \n\t"                   \
1732         "psubh      $f8,    $f8,    $f4             \n\t"                   \
1733         "li         $8,     0x07                    \n\t"                   \
1734         "mtc1       $8,     $f16                    \n\t"                   \
1735         NORMALIZE_MMI("$f16")                                               \
1736         /* Remove bias */                                                   \
1737         "paddh      $f6,    $f6,    $f12            \n\t"                   \
1738         "paddh      $f8,    $f8,    $f12            \n\t"                   \
1739         TRANSFER_DO_PACK(OP)                                                \
1740         "addiu      %[h],   %[h],  -0x01            \n\t"                   \
1741         PTR_ADDIU  "%[src], %[src], 0x18            \n\t"                   \
1742         PTR_ADDU   "%[dst], %[dst], %[stride]       \n\t"                   \
1743         "bnez       %[h],   1b                      \n\t"                   \
1744         : RESTRICT_ASM_ALL64            RESTRICT_ASM_ADDRT                  \
1745           [h]"+r"(h),                                                       \
1746           [src]"+r"(src),               [dst]"+r"(dst)                      \
1747         : [stride]"r"(stride),          [rnd]"m"(rnd),                      \
1748           [ff_pw_9]"m"(ff_pw_9),        [ff_pw_128]"m"(ff_pw_128)           \
1749         : "$8", "$f0", "$f2", "$f4", "$f6", "$f8", "$f10", "$f12", "$f14",  \
1750           "$f16", "memory"                                                  \
1751     );                                                                      \
1752 }
1753
1754 VC1_HOR_16B_SHIFT2(OP_PUT, put_)
1755 VC1_HOR_16B_SHIFT2(OP_AVG, avg_)
1756
1757 /**
1758  * Purely vertical or horizontal 1/2 shift interpolation.
1759  * Sacrify $f12 for *9 factor.
1760  */
1761 #define VC1_SHIFT2(OP, OPNAME)\
1762 static void OPNAME ## vc1_shift2_mmi(uint8_t *dst, const uint8_t *src,      \
1763                                      mips_reg stride, int rnd,              \
1764                                      mips_reg offset)                       \
1765 {                                                                           \
1766     DECLARE_VAR_LOW32;                                                      \
1767     DECLARE_VAR_ADDRT;                                                      \
1768                                                                             \
1769     rnd = 8 - rnd;                                                          \
1770                                                                             \
1771     __asm__ volatile(                                                       \
1772         "xor        $f0,    $f0,    $f0             \n\t"                   \
1773         "li         $10,    0x08                    \n\t"                   \
1774         LOAD_ROUNDER_MMI("%[rnd]")                                          \
1775         "ldc1       $f12,   %[ff_pw_9]              \n\t"                   \
1776         "1:                                         \n\t"                   \
1777         MMI_ULWC1($f6, %[src], 0x00)                                        \
1778         MMI_ULWC1($f8, %[src], 0x04)                                        \
1779         PTR_ADDU   "$9,     %[src], %[offset]       \n\t"                   \
1780         MMI_ULWC1($f2, $9, 0x00)                                            \
1781         MMI_ULWC1($f4, $9, 0x04)                                            \
1782         PTR_ADDU   "%[src], %[src], %[offset]       \n\t"                   \
1783         "punpcklbh  $f6,    $f6,    $f0             \n\t"                   \
1784         "punpcklbh  $f8,    $f8,    $f0             \n\t"                   \
1785         "punpcklbh  $f2,    $f2,    $f0             \n\t"                   \
1786         "punpcklbh  $f4,    $f4,    $f0             \n\t"                   \
1787         "paddh      $f6,    $f6,    $f2             \n\t"                   \
1788         "paddh      $f8,    $f8,    $f4             \n\t"                   \
1789         PTR_ADDU   "$9,     %[src], %[offset_x2n]   \n\t"                   \
1790         MMI_ULWC1($f2, $9, 0x00)                                            \
1791         MMI_ULWC1($f4, $9, 0x04)                                            \
1792         "pmullh     $f6,    $f6,    $f12            \n\t" /* 0,9,9,0*/      \
1793         "pmullh     $f8,    $f8,    $f12            \n\t" /* 0,9,9,0*/      \
1794         "punpcklbh  $f2,    $f2,    $f0             \n\t"                   \
1795         "punpcklbh  $f4,    $f4,    $f0             \n\t"                   \
1796         "psubh      $f6,    $f6,    $f2             \n\t" /*-1,9,9,0*/      \
1797         "psubh      $f8,    $f8,    $f4             \n\t" /*-1,9,9,0*/      \
1798         PTR_ADDU   "$9,     %[src], %[offset]       \n\t"                   \
1799         MMI_ULWC1($f2, $9, 0x00)                                            \
1800         MMI_ULWC1($f4, $9, 0x04)                                            \
1801         "punpcklbh  $f2,    $f2,    $f0             \n\t"                   \
1802         "punpcklbh  $f4,    $f4,    $f0             \n\t"                   \
1803         "psubh      $f6,    $f6,    $f2             \n\t" /*-1,9,9,-1*/     \
1804         "psubh      $f8,    $f8,    $f4             \n\t" /*-1,9,9,-1*/     \
1805         "li         $8,     0x04                    \n\t"                   \
1806         "mtc1       $8,     $f16                    \n\t"                   \
1807         NORMALIZE_MMI("$f16")                                               \
1808         "packushb   $f6,    $f6,    $f8             \n\t"                   \
1809         OP((%[dst]), $f6)                                                   \
1810         "sdc1       $f6,    0x00(%[dst])            \n\t"                   \
1811         "addiu      $10,    $10,   -0x01            \n\t"                   \
1812         PTR_ADDU   "%[src], %[src], %[stride1]      \n\t"                   \
1813         PTR_ADDU   "%[dst], %[dst], %[stride]       \n\t"                   \
1814         "bnez       $10,    1b                      \n\t"                   \
1815         : RESTRICT_ASM_LOW32            RESTRICT_ASM_ADDRT                  \
1816           [src]"+r"(src),               [dst]"+r"(dst)                      \
1817         : [offset]"r"(offset),          [offset_x2n]"r"(-2*offset),         \
1818           [stride]"r"(stride),          [rnd]"m"(rnd),                      \
1819           [stride1]"r"(stride-offset),                                      \
1820           [ff_pw_9]"m"(ff_pw_9)                                             \
1821         : "$8", "$9", "$10", "$f0", "$f2", "$f4", "$f6", "$f8", "$f10",     \
1822           "$f12", "$f14", "$f16", "memory"                                  \
1823     );                                                                      \
1824 }
1825
1826 VC1_SHIFT2(OP_PUT, put_)
1827 VC1_SHIFT2(OP_AVG, avg_)
1828
1829 /**
1830  * Core of the 1/4 and 3/4 shift bicubic interpolation.
1831  *
1832  * @param UNPACK  Macro unpacking arguments from 8 to 16bits (can be empty).
1833  * @param LOAD    "MMI_ULWC1" or "MMI_ULDC1", if data read is already unpacked.
1834  * @param M       "1" for MMI_ULWC1, "2" for MMI_ULDC1.
1835  * @param A1      Stride address of 1st tap (beware of unpacked/packed).
1836  * @param A2      Stride address of 2nd tap
1837  * @param A3      Stride address of 3rd tap
1838  * @param A4      Stride address of 4th tap
1839  */
1840 #define MSPEL_FILTER13_CORE(UNPACK, LOAD, M, A1, A2, A3, A4)                \
1841     PTR_ADDU   "$9,     %[src], "#A1"           \n\t"                       \
1842     LOAD($f2, $9, M*0)                                                      \
1843     LOAD($f4, $9, M*4)                                                      \
1844     UNPACK("$f2")                                                           \
1845     UNPACK("$f4")                                                           \
1846     "pmullh     $f2,    $f2,    %[ff_pw_3]      \n\t"                       \
1847     "pmullh     $f4,    $f4,    %[ff_pw_3]      \n\t"                       \
1848     PTR_ADDU   "$9,     %[src], "#A2"           \n\t"                       \
1849     LOAD($f6, $9, M*0)                                                      \
1850     LOAD($f8, $9, M*4)                                                      \
1851     UNPACK("$f6")                                                           \
1852     UNPACK("$f8")                                                           \
1853     "pmullh     $f6,    $f6,    $f12            \n\t" /* *18 */             \
1854     "pmullh     $f8,    $f8,    $f12            \n\t" /* *18 */             \
1855     "psubh      $f6,    $f6,    $f2             \n\t" /* *18, -3 */         \
1856     "psubh      $f8,    $f8,    $f4             \n\t" /* *18, -3 */         \
1857     PTR_ADDU   "$9,     %[src], "#A4"           \n\t"                       \
1858     LOAD($f2, $9, M*0)                                                      \
1859     LOAD($f4, $9, M*4)                                                      \
1860     UNPACK("$f2")                                                           \
1861     UNPACK("$f4")                                                           \
1862     "li         $8,     0x02                    \n\t"                       \
1863     "mtc1       $8,     $f16                    \n\t"                       \
1864     "psllh      $f2,    $f2,    $f16            \n\t" /* 4* */              \
1865     "psllh      $f4,    $f4,    $f16            \n\t" /* 4* */              \
1866     "psubh      $f6,    $f6,    $f2             \n\t" /* -4,18,-3 */        \
1867     "psubh      $f8,    $f8,    $f4             \n\t" /* -4,18,-3 */        \
1868     PTR_ADDU   "$9,     %[src], "#A3"           \n\t"                       \
1869     LOAD($f2, $9, M*0)                                                      \
1870     LOAD($f4, $9, M*4)                                                      \
1871     UNPACK("$f2")                                                           \
1872     UNPACK("$f4")                                                           \
1873     "pmullh     $f2,    $f2,    $f10            \n\t" /* *53 */             \
1874     "pmullh     $f4,    $f4,    $f10            \n\t" /* *53 */             \
1875     "paddh      $f6,    $f6,    $f2             \n\t" /* 4,53,18,-3 */      \
1876     "paddh      $f8,    $f8,    $f4             \n\t" /* 4,53,18,-3 */
1877
1878 /**
1879  * Macro to build the vertical 16bits version of vc1_put_shift[13].
1880  * Here, offset=src_stride. Parameters passed A1 to A4 must use
1881  * %3 (src_stride), %4 (2*src_stride) and %5 (3*src_stride).
1882  *
1883  * @param  NAME   Either 1 or 3
1884  * @see MSPEL_FILTER13_CORE for information on A1->A4
1885  */
1886 #define MSPEL_FILTER13_VER_16B(NAME, A1, A2, A3, A4)                        \
1887 static void                                                                 \
1888 vc1_put_ver_16b_ ## NAME ## _mmi(int16_t *dst, const uint8_t *src,          \
1889                                  mips_reg src_stride,                       \
1890                                  int rnd, int64_t shift)                    \
1891 {                                                                           \
1892     int h = 8;                                                              \
1893     DECLARE_VAR_LOW32;                                                      \
1894     DECLARE_VAR_ADDRT;                                                      \
1895                                                                             \
1896     src -= src_stride;                                                      \
1897                                                                             \
1898     __asm__ volatile(                                                       \
1899         "xor        $f0,    $f0,    $f0             \n\t"                   \
1900         LOAD_ROUNDER_MMI("%[rnd]")                                          \
1901         "ldc1       $f10,   %[ff_pw_53]             \n\t"                   \
1902         "ldc1       $f12,   %[ff_pw_18]             \n\t"                   \
1903         ".p2align 3                                 \n\t"                   \
1904         "1:                                         \n\t"                   \
1905         MSPEL_FILTER13_CORE(DO_UNPACK, MMI_ULWC1, 1, A1, A2, A3, A4)        \
1906         NORMALIZE_MMI("%[shift]")                                           \
1907         TRANSFER_DONT_PACK(OP_PUT)                                          \
1908         /* Last 3 (in fact 4) bytes on the line */                          \
1909         PTR_ADDU   "$9,     %[src], "#A1"           \n\t"                   \
1910         MMI_ULWC1($f2, $9, 0x08)                                            \
1911         DO_UNPACK("$f2")                                                    \
1912         "mov.d      $f6,    $f2                     \n\t"                   \
1913         "paddh      $f2,    $f2,    $f2             \n\t"                   \
1914         "paddh      $f2,    $f2,    $f6             \n\t" /* 3* */          \
1915         PTR_ADDU   "$9,     %[src], "#A2"           \n\t"                   \
1916         MMI_ULWC1($f6, $9, 0x08)                                            \
1917         DO_UNPACK("$f6")                                                    \
1918         "pmullh     $f6,    $f6,    $f12            \n\t" /* *18 */         \
1919         "psubh      $f6,    $f6,    $f2             \n\t" /* *18,-3 */      \
1920         PTR_ADDU   "$9,     %[src], "#A3"           \n\t"                   \
1921         MMI_ULWC1($f2, $9, 0x08)                                            \
1922         DO_UNPACK("$f2")                                                    \
1923         "pmullh     $f2,    $f2,    $f10            \n\t" /* *53 */         \
1924         "paddh      $f6,    $f6,    $f2             \n\t" /* *53,18,-3 */   \
1925         PTR_ADDU   "$9,     %[src], "#A4"           \n\t"                   \
1926         MMI_ULWC1($f2, $9, 0x08)                                            \
1927         DO_UNPACK("$f2")                                                    \
1928         "li         $8,     0x02                    \n\t"                   \
1929         "mtc1       $8,     $f16                    \n\t"                   \
1930         "psllh      $f2,    $f2,    $f16            \n\t" /* 4* */          \
1931         "psubh      $f6,    $f6,    $f2             \n\t"                   \
1932         "paddh      $f6,    $f6,    $f14            \n\t"                   \
1933         "li         $8,     0x06                    \n\t"                   \
1934         "mtc1       $8,     $f16                    \n\t"                   \
1935         "psrah      $f6,    $f6,    $f16            \n\t"                   \
1936         "sdc1       $f6,    0x10(%[dst])            \n\t"                   \
1937         "addiu      %[h],   %[h],  -0x01            \n\t"                   \
1938         PTR_ADDU   "%[src], %[src], %[stride_x1]    \n\t"                   \
1939         PTR_ADDIU  "%[dst], %[dst], 0x18            \n\t"                   \
1940         "bnez       %[h],   1b                      \n\t"                   \
1941         : RESTRICT_ASM_LOW32            RESTRICT_ASM_ADDRT                  \
1942           [h]"+r"(h),                                                       \
1943           [src]"+r"(src),               [dst]"+r"(dst)                      \
1944         : [stride_x1]"r"(src_stride),   [stride_x2]"r"(2*src_stride),       \
1945           [stride_x3]"r"(3*src_stride),                                     \
1946           [rnd]"m"(rnd),                [shift]"f"(shift),                  \
1947           [ff_pw_53]"m"(ff_pw_53),      [ff_pw_18]"m"(ff_pw_18),            \
1948           [ff_pw_3]"f"(ff_pw_3)                                             \
1949         : "$8", "$9", "$f0", "$f2", "$f4", "$f6", "$f8", "$f10", "$f12",    \
1950           "$f14", "$f16", "memory"                                          \
1951     );                                                                      \
1952 }
1953
1954 /**
1955  * Macro to build the horizontal 16bits version of vc1_put_shift[13].
1956  * Here, offset=16bits, so parameters passed A1 to A4 should be simple.
1957  *
1958  * @param  NAME   Either 1 or 3
1959  * @see MSPEL_FILTER13_CORE for information on A1->A4
1960  */
1961 #define MSPEL_FILTER13_HOR_16B(NAME, A1, A2, A3, A4, OP, OPNAME)            \
1962 static void                                                                 \
1963 OPNAME ## vc1_hor_16b_ ## NAME ## _mmi(uint8_t *dst, mips_reg stride,       \
1964                                        const int16_t *src, int rnd)         \
1965 {                                                                           \
1966     int h = 8;                                                              \
1967     DECLARE_VAR_ALL64;                                                      \
1968     DECLARE_VAR_ADDRT;                                                      \
1969                                                                             \
1970     src -= 1;                                                               \
1971     rnd -= (-4+58+13-3)*256; /* Add -256 bias */                            \
1972                                                                             \
1973     __asm__ volatile(                                                       \
1974         "xor        $f0,    $f0,    $f0             \n\t"                   \
1975         LOAD_ROUNDER_MMI("%[rnd]")                                          \
1976         "ldc1       $f10,   %[ff_pw_53]             \n\t"                   \
1977         "ldc1       $f12,   %[ff_pw_18]             \n\t"                   \
1978         ".p2align 3                                 \n\t"                   \
1979         "1:                                         \n\t"                   \
1980         MSPEL_FILTER13_CORE(DONT_UNPACK, MMI_ULDC1, 2, A1, A2, A3, A4)      \
1981         "li         $8,     0x07                    \n\t"                   \
1982         "mtc1       $8,     $f16                    \n\t"                   \
1983         NORMALIZE_MMI("$f16")                                               \
1984         /* Remove bias */                                                   \
1985         "paddh      $f6,    $f6,    %[ff_pw_128]    \n\t"                   \
1986         "paddh      $f8,    $f8,    %[ff_pw_128]    \n\t"                   \
1987         TRANSFER_DO_PACK(OP)                                                \
1988         "addiu      %[h],   %[h],  -0x01            \n\t"                   \
1989         PTR_ADDU   "%[src], %[src], 0x18            \n\t"                   \
1990         PTR_ADDU   "%[dst], %[dst], %[stride]       \n\t"                   \
1991         "bnez       %[h],   1b                      \n\t"                   \
1992         : RESTRICT_ASM_ALL64            RESTRICT_ASM_ADDRT                  \
1993           [h]"+r"(h),                                                       \
1994           [src]"+r"(src),               [dst]"+r"(dst)                      \
1995         : [stride]"r"(stride),          [rnd]"m"(rnd),                      \
1996           [ff_pw_53]"m"(ff_pw_53),      [ff_pw_18]"m"(ff_pw_18),            \
1997           [ff_pw_3]"f"(ff_pw_3),        [ff_pw_128]"f"(ff_pw_128)           \
1998         : "$8", "$9", "$f0", "$f2", "$f4", "$f6", "$f8", "$f10", "$f12",    \
1999           "$f14", "$f16", "memory"                                          \
2000     );                                                                      \
2001 }
2002
2003 /**
2004  * Macro to build the 8bits, any direction, version of vc1_put_shift[13].
2005  * Here, offset=src_stride. Parameters passed A1 to A4 must use
2006  * %3 (offset), %4 (2*offset) and %5 (3*offset).
2007  *
2008  * @param  NAME   Either 1 or 3
2009  * @see MSPEL_FILTER13_CORE for information on A1->A4
2010  */
2011 #define MSPEL_FILTER13_8B(NAME, A1, A2, A3, A4, OP, OPNAME)                 \
2012 static void                                                                 \
2013 OPNAME ## vc1_## NAME ## _mmi(uint8_t *dst, const uint8_t *src,             \
2014                               mips_reg stride, int rnd, mips_reg offset)    \
2015 {                                                                           \
2016     int h = 8;                                                              \
2017     DECLARE_VAR_LOW32;                                                      \
2018     DECLARE_VAR_ADDRT;                                                      \
2019                                                                             \
2020     src -= offset;                                                          \
2021     rnd = 32-rnd;                                                           \
2022                                                                             \
2023     __asm__ volatile (                                                      \
2024         "xor        $f0,    $f0,    $f0             \n\t"                   \
2025         LOAD_ROUNDER_MMI("%[rnd]")                                          \
2026         "ldc1       $f10,   %[ff_pw_53]             \n\t"                   \
2027         "ldc1       $f12,   %[ff_pw_18]             \n\t"                   \
2028         ".p2align 3                                 \n\t"                   \
2029         "1:                                         \n\t"                   \
2030         MSPEL_FILTER13_CORE(DO_UNPACK, MMI_ULWC1, 1, A1, A2, A3, A4)        \
2031         "li         $8,     0x06                    \n\t"                   \
2032         "mtc1       $8,     $f16                    \n\t"                   \
2033         NORMALIZE_MMI("$f16")                                               \
2034         TRANSFER_DO_PACK(OP)                                                \
2035         "addiu      %[h],   %[h],      -0x01        \n\t"                   \
2036         PTR_ADDU   "%[src], %[src],     %[stride]   \n\t"                   \
2037         PTR_ADDU   "%[dst], %[dst],     %[stride]   \n\t"                   \
2038         "bnez       %[h],   1b                      \n\t"                   \
2039         : RESTRICT_ASM_LOW32            RESTRICT_ASM_ADDRT                  \
2040           [h]"+r"(h),                                                       \
2041           [src]"+r"(src),               [dst]"+r"(dst)                      \
2042         : [offset_x1]"r"(offset),       [offset_x2]"r"(2*offset),           \
2043           [offset_x3]"r"(3*offset),     [stride]"r"(stride),                \
2044           [rnd]"m"(rnd),                                                    \
2045           [ff_pw_53]"m"(ff_pw_53),      [ff_pw_18]"m"(ff_pw_18),            \
2046           [ff_pw_3]"f"(ff_pw_3)                                             \
2047         : "$8", "$9", "$f0", "$f2", "$f4", "$f6", "$f8", "$f10", "$f12",    \
2048           "$f14", "$f16", "memory"                                          \
2049     );                                                                      \
2050 }
2051
2052
2053 /** 1/4 shift bicubic interpolation */
2054 MSPEL_FILTER13_8B(shift1, %[offset_x3], %[offset_x2], %[offset_x1], $0, OP_PUT, put_)
2055 MSPEL_FILTER13_8B(shift1, %[offset_x3], %[offset_x2], %[offset_x1], $0, OP_AVG, avg_)
2056 MSPEL_FILTER13_VER_16B(shift1, %[stride_x3], %[stride_x2], %[stride_x1], $0)
2057 MSPEL_FILTER13_HOR_16B(shift1, 6, 4, 2, 0, OP_PUT, put_)
2058 MSPEL_FILTER13_HOR_16B(shift1, 6, 4, 2, 0, OP_AVG, avg_)
2059
2060 /** 3/4 shift bicubic interpolation */
2061 MSPEL_FILTER13_8B(shift3, $0, %[offset_x1], %[offset_x2], %[offset_x3], OP_PUT, put_)
2062 MSPEL_FILTER13_8B(shift3, $0, %[offset_x1], %[offset_x2], %[offset_x3], OP_AVG, avg_)
2063 MSPEL_FILTER13_VER_16B(shift3, $0, %[stride_x1], %[stride_x2], %[stride_x3])
2064 MSPEL_FILTER13_HOR_16B(shift3, 0, 2, 4, 6, OP_PUT, put_)
2065 MSPEL_FILTER13_HOR_16B(shift3, 0, 2, 4, 6, OP_AVG, avg_)
2066
2067 typedef void (*vc1_mspel_mc_filter_ver_16bits)
2068              (int16_t *dst, const uint8_t *src, mips_reg src_stride, int rnd,
2069               int64_t shift);
2070 typedef void (*vc1_mspel_mc_filter_hor_16bits)
2071              (uint8_t *dst, mips_reg dst_stride, const int16_t *src, int rnd);
2072 typedef void (*vc1_mspel_mc_filter_8bits)
2073              (uint8_t *dst, const uint8_t *src, mips_reg stride, int rnd,
2074               mips_reg offset);
2075
2076 /**
2077  * Interpolate fractional pel values by applying proper vertical then
2078  * horizontal filter.
2079  *
2080  * @param  dst     Destination buffer for interpolated pels.
2081  * @param  src     Source buffer.
2082  * @param  stride  Stride for both src and dst buffers.
2083  * @param  hmode   Horizontal filter (expressed in quarter pixels shift).
2084  * @param  hmode   Vertical filter.
2085  * @param  rnd     Rounding bias.
2086  */
2087 #define VC1_MSPEL_MC(OP)                                                    \
2088 static void OP ## vc1_mspel_mc(uint8_t *dst, const uint8_t *src, int stride,\
2089                                int hmode, int vmode, int rnd)               \
2090 {                                                                           \
2091     static const vc1_mspel_mc_filter_ver_16bits vc1_put_shift_ver_16bits[] =\
2092          { NULL, vc1_put_ver_16b_shift1_mmi,                                \
2093                  vc1_put_ver_16b_shift2_mmi,                                \
2094                  vc1_put_ver_16b_shift3_mmi };                              \
2095     static const vc1_mspel_mc_filter_hor_16bits vc1_put_shift_hor_16bits[] =\
2096          { NULL, OP ## vc1_hor_16b_shift1_mmi,                              \
2097                  OP ## vc1_hor_16b_shift2_mmi,                              \
2098                  OP ## vc1_hor_16b_shift3_mmi };                            \
2099     static const vc1_mspel_mc_filter_8bits vc1_put_shift_8bits[] =          \
2100          { NULL, OP ## vc1_shift1_mmi,                                      \
2101                  OP ## vc1_shift2_mmi,                                      \
2102                  OP ## vc1_shift3_mmi };                                    \
2103                                                                             \
2104     if (vmode) { /* Vertical filter to apply */                             \
2105         if (hmode) { /* Horizontal filter to apply, output to tmp */        \
2106             static const int shift_value[] = { 0, 5, 1, 5 };                \
2107             int    shift = (shift_value[hmode]+shift_value[vmode])>>1;      \
2108             int    r;                                                       \
2109             LOCAL_ALIGNED(16, int16_t, tmp, [12*8]);                        \
2110                                                                             \
2111             r = (1<<(shift-1)) + rnd-1;                                     \
2112             vc1_put_shift_ver_16bits[vmode](tmp, src-1, stride, r, shift);  \
2113                                                                             \
2114             vc1_put_shift_hor_16bits[hmode](dst, stride, tmp+1, 64-rnd);    \
2115             return;                                                         \
2116         }                                                                   \
2117         else { /* No horizontal filter, output 8 lines to dst */            \
2118             vc1_put_shift_8bits[vmode](dst, src, stride, 1-rnd, stride);    \
2119             return;                                                         \
2120         }                                                                   \
2121     }                                                                       \
2122                                                                             \
2123     /* Horizontal mode with no vertical mode */                             \
2124     vc1_put_shift_8bits[hmode](dst, src, stride, rnd, 1);                   \
2125 }                                                                           \
2126 static void OP ## vc1_mspel_mc_16(uint8_t *dst, const uint8_t *src,         \
2127                                   int stride, int hmode, int vmode, int rnd)\
2128 {                                                                           \
2129     OP ## vc1_mspel_mc(dst + 0, src + 0, stride, hmode, vmode, rnd);        \
2130     OP ## vc1_mspel_mc(dst + 8, src + 8, stride, hmode, vmode, rnd);        \
2131     dst += 8*stride; src += 8*stride;                                       \
2132     OP ## vc1_mspel_mc(dst + 0, src + 0, stride, hmode, vmode, rnd);        \
2133     OP ## vc1_mspel_mc(dst + 8, src + 8, stride, hmode, vmode, rnd);        \
2134 }
2135
2136 VC1_MSPEL_MC(put_)
2137 VC1_MSPEL_MC(avg_)
2138
2139 /** Macro to ease bicubic filter interpolation functions declarations */
2140 #define DECLARE_FUNCTION(a, b)                                              \
2141 void ff_put_vc1_mspel_mc ## a ## b ## _mmi(uint8_t *dst,                    \
2142                                            const uint8_t *src,              \
2143                                            ptrdiff_t stride,                \
2144                                            int rnd)                         \
2145 {                                                                           \
2146      put_vc1_mspel_mc(dst, src, stride, a, b, rnd);                         \
2147 }                                                                           \
2148 void ff_avg_vc1_mspel_mc ## a ## b ## _mmi(uint8_t *dst,                    \
2149                                            const uint8_t *src,              \
2150                                            ptrdiff_t stride,                \
2151                                            int rnd)                         \
2152 {                                                                           \
2153      avg_vc1_mspel_mc(dst, src, stride, a, b, rnd);                         \
2154 }                                                                           \
2155 void ff_put_vc1_mspel_mc ## a ## b ## _16_mmi(uint8_t *dst,                 \
2156                                               const uint8_t *src,           \
2157                                               ptrdiff_t stride,             \
2158                                               int rnd)                      \
2159 {                                                                           \
2160      put_vc1_mspel_mc_16(dst, src, stride, a, b, rnd);                      \
2161 }                                                                           \
2162 void ff_avg_vc1_mspel_mc ## a ## b ## _16_mmi(uint8_t *dst,                 \
2163                                               const uint8_t *src,           \
2164                                               ptrdiff_t stride,             \
2165                                               int rnd)                      \
2166 {                                                                           \
2167      avg_vc1_mspel_mc_16(dst, src, stride, a, b, rnd);                      \
2168 }
2169
2170 DECLARE_FUNCTION(0, 1)
2171 DECLARE_FUNCTION(0, 2)
2172 DECLARE_FUNCTION(0, 3)
2173
2174 DECLARE_FUNCTION(1, 0)
2175 DECLARE_FUNCTION(1, 1)
2176 DECLARE_FUNCTION(1, 2)
2177 DECLARE_FUNCTION(1, 3)
2178
2179 DECLARE_FUNCTION(2, 0)
2180 DECLARE_FUNCTION(2, 1)
2181 DECLARE_FUNCTION(2, 2)
2182 DECLARE_FUNCTION(2, 3)
2183
2184 DECLARE_FUNCTION(3, 0)
2185 DECLARE_FUNCTION(3, 1)
2186 DECLARE_FUNCTION(3, 2)
2187 DECLARE_FUNCTION(3, 3)
2188
2189 #define CHROMA_MC_8_MMI                                                     \
2190         "punpckhbh  %[ftmp5],   %[ftmp1],   %[ftmp0]                \n\t"   \
2191         "punpcklbh  %[ftmp1],   %[ftmp1],   %[ftmp0]                \n\t"   \
2192         "punpckhbh  %[ftmp6],   %[ftmp2],   %[ftmp0]                \n\t"   \
2193         "punpcklbh  %[ftmp2],   %[ftmp2],   %[ftmp0]                \n\t"   \
2194         "punpckhbh  %[ftmp7],   %[ftmp3],   %[ftmp0]                \n\t"   \
2195         "punpcklbh  %[ftmp3],   %[ftmp3],   %[ftmp0]                \n\t"   \
2196         "punpckhbh  %[ftmp8],   %[ftmp4],   %[ftmp0]                \n\t"   \
2197         "punpcklbh  %[ftmp4],   %[ftmp4],   %[ftmp0]                \n\t"   \
2198                                                                             \
2199         "pmullh     %[ftmp1],   %[ftmp1],   %[A]                    \n\t"   \
2200         "pmullh     %[ftmp5],   %[ftmp5],   %[A]                    \n\t"   \
2201         "pmullh     %[ftmp2],   %[ftmp2],   %[B]                    \n\t"   \
2202         "pmullh     %[ftmp6],   %[ftmp6],   %[B]                    \n\t"   \
2203         "pmullh     %[ftmp3],   %[ftmp3],   %[C]                    \n\t"   \
2204         "pmullh     %[ftmp7],   %[ftmp7],   %[C]                    \n\t"   \
2205         "pmullh     %[ftmp4],   %[ftmp4],   %[D]                    \n\t"   \
2206         "pmullh     %[ftmp8],   %[ftmp8],   %[D]                    \n\t"   \
2207                                                                             \
2208         "paddh      %[ftmp1],   %[ftmp1],   %[ftmp2]                \n\t"   \
2209         "paddh      %[ftmp3],   %[ftmp3],   %[ftmp4]                \n\t"   \
2210         "paddh      %[ftmp1],   %[ftmp1],   %[ftmp3]                \n\t"   \
2211         "paddh      %[ftmp1],   %[ftmp1],   %[ff_pw_28]             \n\t"   \
2212                                                                             \
2213         "paddh      %[ftmp5],   %[ftmp5],   %[ftmp6]                \n\t"   \
2214         "paddh      %[ftmp7],   %[ftmp7],   %[ftmp8]                \n\t"   \
2215         "paddh      %[ftmp5],   %[ftmp5],   %[ftmp7]                \n\t"   \
2216         "paddh      %[ftmp5],   %[ftmp5],   %[ff_pw_28]             \n\t"   \
2217                                                                             \
2218         "psrlh      %[ftmp1],   %[ftmp1],   %[ftmp9]                \n\t"   \
2219         "psrlh      %[ftmp5],   %[ftmp5],   %[ftmp9]                \n\t"   \
2220         "packushb   %[ftmp1],   %[ftmp1],   %[ftmp5]                \n\t"
2221
2222
2223 #define CHROMA_MC_4_MMI                                                     \
2224         "punpcklbh  %[ftmp1],   %[ftmp1],   %[ftmp0]                \n\t"   \
2225         "punpcklbh  %[ftmp2],   %[ftmp2],   %[ftmp0]                \n\t"   \
2226         "punpcklbh  %[ftmp3],   %[ftmp3],   %[ftmp0]                \n\t"   \
2227         "punpcklbh  %[ftmp4],   %[ftmp4],   %[ftmp0]                \n\t"   \
2228                                                                             \
2229         "pmullh     %[ftmp1],   %[ftmp1],   %[A]                    \n\t"   \
2230         "pmullh     %[ftmp2],   %[ftmp2],   %[B]                    \n\t"   \
2231         "pmullh     %[ftmp3],   %[ftmp3],   %[C]                    \n\t"   \
2232         "pmullh     %[ftmp4],   %[ftmp4],   %[D]                    \n\t"   \
2233                                                                             \
2234         "paddh      %[ftmp1],   %[ftmp1],   %[ftmp2]                \n\t"   \
2235         "paddh      %[ftmp3],   %[ftmp3],   %[ftmp4]                \n\t"   \
2236         "paddh      %[ftmp1],   %[ftmp1],   %[ftmp3]                \n\t"   \
2237         "paddh      %[ftmp1],   %[ftmp1],   %[ff_pw_28]             \n\t"   \
2238                                                                             \
2239         "psrlh      %[ftmp1],   %[ftmp1],   %[ftmp5]                \n\t"   \
2240         "packushb   %[ftmp1],   %[ftmp1],   %[ftmp0]                \n\t"
2241
2242
2243 void ff_put_no_rnd_vc1_chroma_mc8_mmi(uint8_t *dst /* align 8 */,
2244                                       uint8_t *src /* align 1 */,
2245                                       ptrdiff_t stride, int h, int x, int y)
2246 {
2247     const int A = (8 - x) * (8 - y);
2248     const int B =     (x) * (8 - y);
2249     const int C = (8 - x) *     (y);
2250     const int D =     (x) *     (y);
2251     double ftmp[10];
2252     uint32_t tmp[1];
2253     DECLARE_VAR_ALL64;
2254     DECLARE_VAR_ADDRT;
2255
2256     av_assert2(x < 8 && y < 8 && x >= 0 && y >= 0);
2257
2258     __asm__ volatile(
2259         "li         %[tmp0],    0x06                                    \n\t"
2260         "xor        %[ftmp0],   %[ftmp0],   %[ftmp0]                    \n\t"
2261         "mtc1       %[tmp0],    %[ftmp9]                                \n\t"
2262         "pshufh     %[A],       %[A],       %[ftmp0]                    \n\t"
2263         "pshufh     %[B],       %[B],       %[ftmp0]                    \n\t"
2264         "pshufh     %[C],       %[C],       %[ftmp0]                    \n\t"
2265         "pshufh     %[D],       %[D],       %[ftmp0]                    \n\t"
2266
2267         "1:                                                             \n\t"
2268         MMI_ULDC1(%[ftmp1], %[src], 0x00)
2269         MMI_ULDC1(%[ftmp2], %[src], 0x01)
2270         PTR_ADDU   "%[src],     %[src],     %[stride]                   \n\t"
2271         MMI_ULDC1(%[ftmp3], %[src], 0x00)
2272         MMI_ULDC1(%[ftmp4], %[src], 0x01)
2273
2274         CHROMA_MC_8_MMI
2275
2276         MMI_SDC1(%[ftmp1], %[dst], 0x00)
2277         "addiu      %[h],       %[h],      -0x01                        \n\t"
2278         PTR_ADDU   "%[dst],     %[dst],     %[stride]                   \n\t"
2279         "bnez       %[h],       1b                                      \n\t"
2280         : [ftmp0]"=&f"(ftmp[0]),        [ftmp1]"=&f"(ftmp[1]),
2281           [ftmp2]"=&f"(ftmp[2]),        [ftmp3]"=&f"(ftmp[3]),
2282           [ftmp4]"=&f"(ftmp[4]),        [ftmp5]"=&f"(ftmp[5]),
2283           [ftmp6]"=&f"(ftmp[6]),        [ftmp7]"=&f"(ftmp[7]),
2284           [ftmp8]"=&f"(ftmp[8]),        [ftmp9]"=&f"(ftmp[9]),
2285           RESTRICT_ASM_ALL64
2286           RESTRICT_ASM_ADDRT
2287           [tmp0]"=&r"(tmp[0]),
2288           [src]"+&r"(src),              [dst]"+&r"(dst),
2289           [h]"+&r"(h)
2290         : [stride]"r"((mips_reg)stride),
2291           [A]"f"(A),                    [B]"f"(B),
2292           [C]"f"(C),                    [D]"f"(D),
2293           [ff_pw_28]"f"(ff_pw_28)
2294         : "memory"
2295     );
2296 }
2297
2298 void ff_put_no_rnd_vc1_chroma_mc4_mmi(uint8_t *dst /* align 8 */,
2299                                       uint8_t *src /* align 1 */,
2300                                       ptrdiff_t stride, int h, int x, int y)
2301 {
2302     const int A = (8 - x) * (8 - y);
2303     const int B =     (x) * (8 - y);
2304     const int C = (8 - x) *     (y);
2305     const int D =     (x) *     (y);
2306     double ftmp[6];
2307     uint32_t tmp[1];
2308     DECLARE_VAR_LOW32;
2309     DECLARE_VAR_ADDRT;
2310
2311     av_assert2(x < 8 && y < 8 && x >= 0 && y >= 0);
2312
2313     __asm__ volatile(
2314         "li         %[tmp0],    0x06                                    \n\t"
2315         "xor        %[ftmp0],   %[ftmp0],   %[ftmp0]                    \n\t"
2316         "mtc1       %[tmp0],    %[ftmp5]                                \n\t"
2317         "pshufh     %[A],       %[A],       %[ftmp0]                    \n\t"
2318         "pshufh     %[B],       %[B],       %[ftmp0]                    \n\t"
2319         "pshufh     %[C],       %[C],       %[ftmp0]                    \n\t"
2320         "pshufh     %[D],       %[D],       %[ftmp0]                    \n\t"
2321
2322         "1:                                                             \n\t"
2323         MMI_ULWC1(%[ftmp1], %[src], 0x00)
2324         MMI_ULWC1(%[ftmp2], %[src], 0x01)
2325         PTR_ADDU   "%[src],     %[src],     %[stride]                   \n\t"
2326         MMI_ULWC1(%[ftmp3], %[src], 0x00)
2327         MMI_ULWC1(%[ftmp4], %[src], 0x01)
2328
2329         CHROMA_MC_4_MMI
2330
2331         MMI_SWC1(%[ftmp1], %[dst], 0x00)
2332         "addiu      %[h],       %[h],      -0x01                        \n\t"
2333         PTR_ADDU   "%[dst],     %[dst],     %[stride]                   \n\t"
2334         "bnez       %[h],       1b                                      \n\t"
2335         : [ftmp0]"=&f"(ftmp[0]),        [ftmp1]"=&f"(ftmp[1]),
2336           [ftmp2]"=&f"(ftmp[2]),        [ftmp3]"=&f"(ftmp[3]),
2337           [ftmp4]"=&f"(ftmp[4]),        [ftmp5]"=&f"(ftmp[5]),
2338           [tmp0]"=&r"(tmp[0]),
2339           RESTRICT_ASM_LOW32
2340           RESTRICT_ASM_ADDRT
2341           [src]"+&r"(src),              [dst]"+&r"(dst),
2342           [h]"+&r"(h)
2343         : [stride]"r"((mips_reg)stride),
2344           [A]"f"(A),                    [B]"f"(B),
2345           [C]"f"(C),                    [D]"f"(D),
2346           [ff_pw_28]"f"(ff_pw_28)
2347         : "memory"
2348     );
2349 }
2350
2351 void ff_avg_no_rnd_vc1_chroma_mc8_mmi(uint8_t *dst /* align 8 */,
2352                                       uint8_t *src /* align 1 */,
2353                                       ptrdiff_t stride, int h, int x, int y)
2354 {
2355     const int A = (8 - x) * (8 - y);
2356     const int B =     (x) * (8 - y);
2357     const int C = (8 - x) *     (y);
2358     const int D =     (x) *     (y);
2359     double ftmp[10];
2360     uint32_t tmp[1];
2361     DECLARE_VAR_ALL64;
2362     DECLARE_VAR_ADDRT;
2363
2364     av_assert2(x < 8 && y < 8 && x >= 0 && y >= 0);
2365
2366     __asm__ volatile(
2367         "li         %[tmp0],    0x06                                    \n\t"
2368         "xor        %[ftmp0],   %[ftmp0],   %[ftmp0]                    \n\t"
2369         "mtc1       %[tmp0],    %[ftmp9]                                \n\t"
2370         "pshufh     %[A],       %[A],       %[ftmp0]                    \n\t"
2371         "pshufh     %[B],       %[B],       %[ftmp0]                    \n\t"
2372         "pshufh     %[C],       %[C],       %[ftmp0]                    \n\t"
2373         "pshufh     %[D],       %[D],       %[ftmp0]                    \n\t"
2374
2375         "1:                                                             \n\t"
2376         MMI_ULDC1(%[ftmp1], %[src], 0x00)
2377         MMI_ULDC1(%[ftmp2], %[src], 0x01)
2378         PTR_ADDU   "%[src],     %[src],     %[stride]                   \n\t"
2379         MMI_ULDC1(%[ftmp3], %[src], 0x00)
2380         MMI_ULDC1(%[ftmp4], %[src], 0x01)
2381
2382         CHROMA_MC_8_MMI
2383
2384         MMI_LDC1(%[ftmp2], %[dst], 0x00)
2385         "pavgb      %[ftmp1],   %[ftmp1],   %[ftmp2]                    \n\t"
2386
2387         MMI_SDC1(%[ftmp1], %[dst], 0x00)
2388         "addiu      %[h],       %[h],      -0x01                        \n\t"
2389         PTR_ADDU   "%[dst],     %[dst],     %[stride]                   \n\t"
2390         "bnez       %[h],       1b                                      \n\t"
2391         : [ftmp0]"=&f"(ftmp[0]),        [ftmp1]"=&f"(ftmp[1]),
2392           [ftmp2]"=&f"(ftmp[2]),        [ftmp3]"=&f"(ftmp[3]),
2393           [ftmp4]"=&f"(ftmp[4]),        [ftmp5]"=&f"(ftmp[5]),
2394           [ftmp6]"=&f"(ftmp[6]),        [ftmp7]"=&f"(ftmp[7]),
2395           [ftmp8]"=&f"(ftmp[8]),        [ftmp9]"=&f"(ftmp[9]),
2396           [tmp0]"=&r"(tmp[0]),
2397           RESTRICT_ASM_ALL64
2398           RESTRICT_ASM_ADDRT
2399           [src]"+&r"(src),              [dst]"+&r"(dst),
2400           [h]"+&r"(h)
2401         : [stride]"r"((mips_reg)stride),
2402           [A]"f"(A),                    [B]"f"(B),
2403           [C]"f"(C),                    [D]"f"(D),
2404           [ff_pw_28]"f"(ff_pw_28)
2405         : "memory"
2406     );
2407 }
2408
2409 void ff_avg_no_rnd_vc1_chroma_mc4_mmi(uint8_t *dst /* align 8 */,
2410                                       uint8_t *src /* align 1 */,
2411                                       ptrdiff_t stride, int h, int x, int y)
2412 {
2413     const int A = (8 - x) * (8 - y);
2414     const int B = (    x) * (8 - y);
2415     const int C = (8 - x) * (    y);
2416     const int D = (    x) * (    y);
2417     double ftmp[6];
2418     uint32_t tmp[1];
2419     DECLARE_VAR_LOW32;
2420     DECLARE_VAR_ADDRT;
2421
2422     av_assert2(x < 8 && y < 8 && x >= 0 && y >= 0);
2423
2424     __asm__ volatile(
2425         "li         %[tmp0],    0x06                                    \n\t"
2426         "xor        %[ftmp0],   %[ftmp0],   %[ftmp0]                    \n\t"
2427         "mtc1       %[tmp0],    %[ftmp5]                                \n\t"
2428         "pshufh     %[A],       %[A],       %[ftmp0]                    \n\t"
2429         "pshufh     %[B],       %[B],       %[ftmp0]                    \n\t"
2430         "pshufh     %[C],       %[C],       %[ftmp0]                    \n\t"
2431         "pshufh     %[D],       %[D],       %[ftmp0]                    \n\t"
2432
2433         "1:                                                             \n\t"
2434         MMI_ULWC1(%[ftmp1], %[src], 0x00)
2435         MMI_ULWC1(%[ftmp2], %[src], 0x01)
2436         PTR_ADDU   "%[src],     %[src],     %[stride]                   \n\t"
2437         MMI_ULWC1(%[ftmp3], %[src], 0x00)
2438         MMI_ULWC1(%[ftmp4], %[src], 0x01)
2439
2440         CHROMA_MC_4_MMI
2441
2442         MMI_LWC1(%[ftmp2], %[dst], 0x00)
2443         "pavgb      %[ftmp1],   %[ftmp1],   %[ftmp2]                    \n\t"
2444
2445         MMI_SWC1(%[ftmp1], %[dst], 0x00)
2446         "addiu      %[h],       %[h],      -0x01                        \n\t"
2447         PTR_ADDU   "%[dst],     %[dst],     %[stride]                   \n\t"
2448         "bnez       %[h],       1b                                      \n\t"
2449         : [ftmp0]"=&f"(ftmp[0]),        [ftmp1]"=&f"(ftmp[1]),
2450           [ftmp2]"=&f"(ftmp[2]),        [ftmp3]"=&f"(ftmp[3]),
2451           [ftmp4]"=&f"(ftmp[4]),        [ftmp5]"=&f"(ftmp[5]),
2452           [tmp0]"=&r"(tmp[0]),
2453           RESTRICT_ASM_LOW32
2454           RESTRICT_ASM_ADDRT
2455           [src]"+&r"(src),              [dst]"+&r"(dst),
2456           [h]"+&r"(h)
2457         : [stride]"r"((mips_reg)stride),
2458           [A]"f"(A),                    [B]"f"(B),
2459           [C]"f"(C),                    [D]"f"(D),
2460           [ff_pw_28]"f"(ff_pw_28)
2461         : "memory"
2462     );
2463 }