]> rtime.felk.cvut.cz Git - frescor/ffmpeg.git/blob - libavcodec/i386/vp3dsp_sse2.c
3d45fdfa673845b13fb556b6de9cf0d61df806c1
[frescor/ffmpeg.git] / libavcodec / i386 / vp3dsp_sse2.c
1 /*
2  * Copyright (C) 2004 the ffmpeg project
3  *
4  * This file is part of FFmpeg.
5  *
6  * FFmpeg is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or (at your option) any later version.
10  *
11  * FFmpeg is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with FFmpeg; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19  */
20
21 /**
22  * @file vp3dsp_sse2.c
23  * SSE2-optimized functions cribbed from the original VP3 source code.
24  */
25
26 #include "libavcodec/dsputil.h"
27 #include "dsputil_mmx.h"
28
29 DECLARE_ALIGNED_16(const uint16_t, ff_vp3_idct_data[7 * 8]) =
30 {
31     64277,64277,64277,64277,64277,64277,64277,64277,
32     60547,60547,60547,60547,60547,60547,60547,60547,
33     54491,54491,54491,54491,54491,54491,54491,54491,
34     46341,46341,46341,46341,46341,46341,46341,46341,
35     36410,36410,36410,36410,36410,36410,36410,36410,
36     25080,25080,25080,25080,25080,25080,25080,25080,
37     12785,12785,12785,12785,12785,12785,12785,12785
38 };
39
40
41 #define SSE2_Column_IDCT() \
42     \
43     "movdqa "I(3)", %%xmm2 \n\t"     /* xmm2 = i3 */ \
44     "movdqa "C(3)", %%xmm6 \n\t"     /* xmm6 = c3 */ \
45     \
46     "movdqa %%xmm2, %%xmm4 \n\t"     /* xmm4 = i3 */ \
47     "movdqa "I(5)", %%xmm7 \n\t"     /* xmm7 = i5 */ \
48     \
49     "pmulhw %%xmm6, %%xmm4 \n\t"     /* xmm4 = c3 * i3 - i3 */ \
50     "movdqa "C(5)", %%xmm1 \n\t"     /* xmm1 = c5 */ \
51     \
52     "pmulhw %%xmm7, %%xmm6 \n\t"     /* xmm6 = c3 * i5 - i5 */ \
53     "movdqa %%xmm1, %%xmm5 \n\t"     /* xmm5 = c5 */ \
54     \
55     "pmulhw %%xmm2, %%xmm1 \n\t"     /* xmm1 = c5 * i3 - i3 */ \
56     "movdqa "I(1)", %%xmm3 \n\t"     /* xmm3 = i1 */ \
57     \
58     "pmulhw %%xmm7, %%xmm5 \n\t"     /* xmm5 = c5 * i5 - i5 */ \
59     "movdqa "C(1)", %%xmm0 \n\t"     /* xmm0 = c1 */ \
60     \
61     /* all registers are in use */ \
62     \
63     "paddw  %%xmm2, %%xmm4 \n\t"     /* xmm4 = c3 * i3 */ \
64     "paddw  %%xmm7, %%xmm6 \n\t"     /* xmm6 = c3 * i5 */ \
65     \
66     "paddw  %%xmm1, %%xmm2 \n\t"     /* xmm2 = c5 * i3 */ \
67     "movdqa "I(7)", %%xmm1 \n\t"     /* xmm1 = i7 */ \
68     \
69     "paddw  %%xmm5, %%xmm7 \n\t"     /* xmm7 = c5 * i5 */ \
70     "movdqa %%xmm0, %%xmm5 \n\t"     /* xmm5 = c1 */ \
71     \
72     "pmulhw %%xmm3, %%xmm0 \n\t"     /* xmm0 = c1 * i1 - i1 */ \
73     "paddsw %%xmm7, %%xmm4 \n\t"     /* xmm4 = c3 * i3 + c5 * i5 = C */ \
74     \
75     "pmulhw %%xmm1, %%xmm5 \n\t"     /* xmm5 = c1 * i7 - i7 */ \
76     "movdqa "C(7)", %%xmm7 \n\t"     /* xmm7 = c7 */ \
77     \
78     "psubsw %%xmm2, %%xmm6 \n\t"     /* xmm6 = c3 * i5 - c5 * i3 = D */ \
79     "paddw  %%xmm3, %%xmm0 \n\t"     /* xmm0 = c1 * i1 */ \
80     \
81     "pmulhw %%xmm7, %%xmm3 \n\t"     /* xmm3 = c7 * i1 */ \
82     "movdqa "I(2)", %%xmm2 \n\t"     /* xmm2 = i2 */ \
83     \
84     "pmulhw %%xmm1, %%xmm7 \n\t"     /* xmm7 = c7 * i7 */ \
85     "paddw  %%xmm1, %%xmm5 \n\t"     /* xmm5 = c1 * i7 */ \
86     \
87     "movdqa %%xmm2, %%xmm1 \n\t"     /* xmm1 = i2 */ \
88     "pmulhw "C(2)", %%xmm2 \n\t"     /* xmm2 = i2 * c2 -i2 */ \
89     \
90     "psubsw %%xmm5, %%xmm3 \n\t"     /* xmm3 = c7 * i1 - c1 * i7 = B */ \
91     "movdqa "I(6)", %%xmm5 \n\t"     /* xmm5 = i6 */ \
92     \
93     "paddsw %%xmm7, %%xmm0 \n\t"     /* xmm0 = c1 * i1 + c7 * i7 = A */ \
94     "movdqa %%xmm5, %%xmm7 \n\t"     /* xmm7 = i6 */ \
95     \
96     "psubsw %%xmm4, %%xmm0 \n\t"     /* xmm0 = A - C */ \
97     "pmulhw "C(2)", %%xmm5 \n\t"     /* xmm5 = c2 * i6 - i6 */ \
98     \
99     "paddw  %%xmm1, %%xmm2 \n\t"     /* xmm2 = i2 * c2 */ \
100     "pmulhw "C(6)", %%xmm1 \n\t"     /* xmm1 = c6 * i2 */ \
101     \
102     "paddsw %%xmm4, %%xmm4 \n\t"     /* xmm4 = C + C */ \
103     "paddsw %%xmm0, %%xmm4 \n\t"     /* xmm4 = A + C = C. */ \
104     \
105     "psubsw %%xmm6, %%xmm3 \n\t"     /* xmm3 = B - D */ \
106     "paddw  %%xmm7, %%xmm5 \n\t"     /* xmm5 = c2 * i6 */ \
107     \
108     "paddsw %%xmm6, %%xmm6 \n\t"     /* xmm6 = D + D */ \
109     "pmulhw "C(6)", %%xmm7 \n\t"     /* xmm7 = c6 * i6 */ \
110     \
111     "paddsw %%xmm3, %%xmm6 \n\t"     /* xmm6 = B + D = D. */ \
112     "movdqa %%xmm4, "I(1)" \n\t"     /* Save C. at I(1) */ \
113     \
114     "psubsw %%xmm5, %%xmm1 \n\t"     /* xmm1 = c6 * i2 - c2 * i6 = H */ \
115     "movdqa "C(4)", %%xmm4 \n\t"     /* xmm4 = c4 */ \
116     \
117     "movdqa %%xmm3, %%xmm5 \n\t"     /* xmm5 = B - D */ \
118     "pmulhw %%xmm4, %%xmm3 \n\t"     /* xmm3 = ( c4 -1 ) * ( B - D ) */ \
119     \
120     "paddsw %%xmm2, %%xmm7 \n\t"     /* xmm7 = c2 * i2 + c6 * i6 = G */ \
121     "movdqa %%xmm6, "I(2)" \n\t"     /* Save D. at I(2) */ \
122     \
123     "movdqa %%xmm0, %%xmm2 \n\t"     /* xmm2 = A - C */ \
124     "movdqa "I(0)", %%xmm6 \n\t"     /* xmm6 = i0 */ \
125     \
126     "pmulhw %%xmm4, %%xmm0 \n\t"     /* xmm0 = ( c4 - 1 ) * ( A - C ) = A. */ \
127     "paddw  %%xmm3, %%xmm5 \n\t"     /* xmm5 = c4 * ( B - D ) = B. */ \
128     \
129     "movdqa "I(4)", %%xmm3 \n\t"     /* xmm3 = i4 */ \
130     "psubsw %%xmm1, %%xmm5 \n\t"     /* xmm5 = B. - H = B.. */ \
131     \
132     "paddw  %%xmm0, %%xmm2 \n\t"     /* xmm2 = c4 * ( A - C) = A. */ \
133     "psubsw %%xmm3, %%xmm6 \n\t"     /* xmm6 = i0 - i4 */ \
134     \
135     "movdqa %%xmm6, %%xmm0 \n\t"     /* xmm0 = i0 - i4 */ \
136     "pmulhw %%xmm4, %%xmm6 \n\t"     /* xmm6 = (c4 - 1) * (i0 - i4) = F */ \
137     \
138     "paddsw %%xmm3, %%xmm3 \n\t"     /* xmm3 = i4 + i4 */ \
139     "paddsw %%xmm1, %%xmm1 \n\t"     /* xmm1 = H + H */ \
140     \
141     "paddsw %%xmm0, %%xmm3 \n\t"     /* xmm3 = i0 + i4 */ \
142     "paddsw %%xmm5, %%xmm1 \n\t"     /* xmm1 = B. + H = H. */ \
143     \
144     "pmulhw %%xmm3, %%xmm4 \n\t"     /* xmm4 = ( c4 - 1 ) * ( i0 + i4 )  */ \
145     "paddw  %%xmm0, %%xmm6 \n\t"     /* xmm6 = c4 * ( i0 - i4 ) */ \
146     \
147     "psubsw %%xmm2, %%xmm6 \n\t"     /* xmm6 = F - A. = F. */ \
148     "paddsw %%xmm2, %%xmm2 \n\t"     /* xmm2 = A. + A. */ \
149     \
150     "movdqa "I(1)", %%xmm0 \n\t"     /* Load        C. from I(1) */ \
151     "paddsw %%xmm6, %%xmm2 \n\t"     /* xmm2 = F + A. = A.. */ \
152     \
153     "paddw  %%xmm3, %%xmm4 \n\t"     /* xmm4 = c4 * ( i0 + i4 ) = 3 */ \
154     "psubsw %%xmm1, %%xmm2 \n\t"     /* xmm2 = A.. - H. = R2 */ \
155     \
156     "paddsw "OC_8", %%xmm2 \n\t"     /* Adjust R2 and R1 before shifting */ \
157     "paddsw %%xmm1, %%xmm1 \n\t"     /* xmm1 = H. + H. */ \
158     \
159     "paddsw %%xmm2, %%xmm1 \n\t"     /* xmm1 = A.. + H. = R1 */ \
160     "psraw      $4, %%xmm2 \n\t"     /* xmm2 = op2 */ \
161     \
162     "psubsw %%xmm7, %%xmm4 \n\t"     /* xmm4 = E - G = E. */ \
163     "psraw      $4, %%xmm1 \n\t"     /* xmm1 = op1 */ \
164     \
165     "movdqa "I(2)", %%xmm3 \n\t"     /* Load D. from I(2) */ \
166     "paddsw %%xmm7, %%xmm7 \n\t"     /* xmm7 = G + G */ \
167     \
168     "movdqa %%xmm2, "O(2)" \n\t"     /* Write out op2 */ \
169     "paddsw %%xmm4, %%xmm7 \n\t"     /* xmm7 = E + G = G. */ \
170     \
171     "movdqa %%xmm1, "O(1)" \n\t"     /* Write out op1 */ \
172     "psubsw %%xmm3, %%xmm4 \n\t"     /* xmm4 = E. - D. = R4 */ \
173     \
174     "paddsw "OC_8", %%xmm4 \n\t"     /* Adjust R4 and R3 before shifting */ \
175     "paddsw %%xmm3, %%xmm3 \n\t"     /* xmm3 = D. + D. */ \
176     \
177     "paddsw %%xmm4, %%xmm3 \n\t"     /* xmm3 = E. + D. = R3 */ \
178     "psraw      $4, %%xmm4 \n\t"     /* xmm4 = op4 */ \
179     \
180     "psubsw %%xmm5, %%xmm6 \n\t"     /* xmm6 = F. - B..= R6 */ \
181     "psraw      $4, %%xmm3 \n\t"     /* xmm3 = op3 */ \
182     \
183     "paddsw "OC_8", %%xmm6 \n\t"     /* Adjust R6 and R5 before shifting */ \
184     "paddsw %%xmm5, %%xmm5 \n\t"     /* xmm5 = B.. + B.. */ \
185     \
186     "paddsw %%xmm6, %%xmm5 \n\t"     /* xmm5 = F. + B.. = R5 */ \
187     "psraw      $4, %%xmm6 \n\t"     /* xmm6 = op6 */ \
188     \
189     "movdqa %%xmm4, "O(4)" \n\t"     /* Write out op4 */ \
190     "psraw      $4, %%xmm5 \n\t"     /* xmm5 = op5 */ \
191     \
192     "movdqa %%xmm3, "O(3)" \n\t"     /* Write out op3 */ \
193     "psubsw %%xmm0, %%xmm7 \n\t"     /* xmm7 = G. - C. = R7 */ \
194     \
195     "paddsw "OC_8", %%xmm7 \n\t"     /* Adjust R7 and R0 before shifting */ \
196     "paddsw %%xmm0, %%xmm0 \n\t"     /* xmm0 = C. + C. */ \
197     \
198     "paddsw %%xmm7, %%xmm0 \n\t"     /* xmm0 = G. + C. */ \
199     "psraw      $4, %%xmm7 \n\t"     /* xmm7 = op7 */ \
200     \
201     "movdqa %%xmm6, "O(6)" \n\t"     /* Write out op6 */ \
202     "psraw      $4, %%xmm0 \n\t"     /* xmm0 = op0 */ \
203     \
204     "movdqa %%xmm5, "O(5)" \n\t"     /* Write out op5 */ \
205     "movdqa %%xmm7, "O(7)" \n\t"     /* Write out op7 */ \
206     \
207     "movdqa %%xmm0, "O(0)" \n\t"     /* Write out op0 */
208
209
210 #define SSE2_Row_IDCT() \
211     \
212     "movdqa "I(3)", %%xmm2 \n\t"     /* xmm2 = i3 */ \
213     "movdqa "C(3)", %%xmm6 \n\t"     /* xmm6 = c3 */ \
214     \
215     "movdqa %%xmm2, %%xmm4 \n\t"     /* xmm4 = i3 */ \
216     "movdqa "I(5)", %%xmm7 \n\t"     /* xmm7 = i5 */ \
217     \
218     "pmulhw %%xmm6, %%xmm4 \n\t"     /* xmm4 = c3 * i3 - i3 */ \
219     "movdqa "C(5)", %%xmm1 \n\t"     /* xmm1 = c5 */ \
220     \
221     "pmulhw %%xmm7, %%xmm6 \n\t"     /* xmm6 = c3 * i5 - i5 */ \
222     "movdqa %%xmm1, %%xmm5 \n\t"     /* xmm5 = c5 */ \
223     \
224     "pmulhw %%xmm2, %%xmm1 \n\t"     /* xmm1 = c5 * i3 - i3 */ \
225     "movdqa "I(1)", %%xmm3 \n\t"     /* xmm3 = i1 */ \
226     \
227     "pmulhw %%xmm7, %%xmm5 \n\t"     /* xmm5 = c5 * i5 - i5 */ \
228     "movdqa "C(1)", %%xmm0 \n\t"     /* xmm0 = c1 */ \
229     \
230     /* all registers are in use */ \
231     \
232     "paddw  %%xmm2, %%xmm4 \n\t"     /* xmm4 = c3 * i3 */ \
233     "paddw  %%xmm7, %%xmm6 \n\t"     /* xmm6 = c3 * i5 */ \
234     \
235     "paddw  %%xmm1, %%xmm2 \n\t"     /* xmm2 = c5 * i3 */ \
236     "movdqa "I(7)", %%xmm1 \n\t"     /* xmm1 = i7 */ \
237     \
238     "paddw  %%xmm5, %%xmm7 \n\t"     /* xmm7 = c5 * i5 */ \
239     "movdqa %%xmm0, %%xmm5 \n\t"     /* xmm5 = c1 */ \
240     \
241     "pmulhw %%xmm3, %%xmm0 \n\t"     /* xmm0 = c1 * i1 - i1 */ \
242     "paddsw %%xmm7, %%xmm4 \n\t"     /* xmm4 = c3 * i3 + c5 * i5 = C */ \
243     \
244     "pmulhw %%xmm1, %%xmm5 \n\t"     /* xmm5 = c1 * i7 - i7 */ \
245     "movdqa "C(7)", %%xmm7 \n\t"     /* xmm7 = c7 */ \
246     \
247     "psubsw %%xmm2, %%xmm6 \n\t"     /* xmm6 = c3 * i5 - c5 * i3 = D */ \
248     "paddw  %%xmm3, %%xmm0 \n\t"     /* xmm0 = c1 * i1 */ \
249     \
250     "pmulhw %%xmm7, %%xmm3 \n\t"     /* xmm3 = c7 * i1 */ \
251     "movdqa "I(2)", %%xmm2 \n\t"     /* xmm2 = i2 */ \
252     \
253     "pmulhw %%xmm1, %%xmm7 \n\t"     /* xmm7 = c7 * i7 */ \
254     "paddw  %%xmm1, %%xmm5 \n\t"     /* xmm5 = c1 * i7 */ \
255     \
256     "movdqa %%xmm2, %%xmm1 \n\t"     /* xmm1 = i2 */ \
257     "pmulhw "C(2)", %%xmm2 \n\t"     /* xmm2 = i2 * c2 -i2 */ \
258     \
259     "psubsw %%xmm5, %%xmm3 \n\t"     /* xmm3 = c7 * i1 - c1 * i7 = B */ \
260     "movdqa "I(6)", %%xmm5 \n\t"     /* xmm5 = i6 */ \
261     \
262     "paddsw %%xmm7, %%xmm0 \n\t"     /* xmm0 = c1 * i1 + c7 * i7        = A */ \
263     "movdqa %%xmm5, %%xmm7 \n\t"     /* xmm7 = i6 */ \
264     \
265     "psubsw %%xmm4, %%xmm0 \n\t"     /* xmm0 = A - C */ \
266     "pmulhw "C(2)", %%xmm5 \n\t"     /* xmm5 = c2 * i6 - i6 */ \
267     \
268     "paddw  %%xmm1, %%xmm2 \n\t"     /* xmm2 = i2 * c2 */ \
269     "pmulhw "C(6)", %%xmm1 \n\t"     /* xmm1 = c6 * i2 */ \
270     \
271     "paddsw %%xmm4, %%xmm4 \n\t"     /* xmm4 = C + C */ \
272     "paddsw %%xmm0, %%xmm4 \n\t"     /* xmm4 = A + C = C. */ \
273     \
274     "psubsw %%xmm6, %%xmm3 \n\t"     /* xmm3 = B - D */ \
275     "paddw  %%xmm7, %%xmm5 \n\t"     /* xmm5 = c2 * i6 */ \
276     \
277     "paddsw %%xmm6, %%xmm6 \n\t"     /* xmm6 = D + D */ \
278     "pmulhw "C(6)", %%xmm7 \n\t"     /* xmm7 = c6 * i6 */ \
279     \
280     "paddsw %%xmm3, %%xmm6 \n\t"     /* xmm6 = B + D = D. */ \
281     "movdqa %%xmm4, "I(1)" \n\t"     /* Save C. at I(1)        */ \
282     \
283     "psubsw %%xmm5, %%xmm1 \n\t"     /* xmm1 = c6 * i2 - c2 * i6 = H */ \
284     "movdqa "C(4)", %%xmm4 \n\t"     /* xmm4 = c4 */ \
285     \
286     "movdqa %%xmm3, %%xmm5 \n\t"     /* xmm5 = B - D */ \
287     "pmulhw %%xmm4, %%xmm3 \n\t"     /* xmm3 = ( c4 -1 ) * ( B - D ) */ \
288     \
289     "paddsw %%xmm2, %%xmm7 \n\t"     /* xmm7 = c2 * i2 + c6 * i6 = G */ \
290     "movdqa %%xmm6, "I(2)" \n\t"     /* Save D. at I(2) */ \
291     \
292     "movdqa %%xmm0, %%xmm2 \n\t"     /* xmm2 = A - C */ \
293     "movdqa "I(0)", %%xmm6 \n\t"     /* xmm6 = i0 */ \
294     \
295     "pmulhw %%xmm4, %%xmm0 \n\t"     /* xmm0 = ( c4 - 1 ) * ( A - C ) = A. */ \
296     "paddw  %%xmm3, %%xmm5 \n\t"     /* xmm5 = c4 * ( B - D ) = B. */ \
297     \
298     "movdqa "I(4)", %%xmm3 \n\t"     /* xmm3 = i4 */ \
299     "psubsw %%xmm1, %%xmm5 \n\t"     /* xmm5 = B. - H = B.. */ \
300     \
301     "paddw  %%xmm0, %%xmm2 \n\t"     /* xmm2 = c4 * ( A - C) = A. */ \
302     "psubsw %%xmm3, %%xmm6 \n\t"     /* xmm6 = i0 - i4 */ \
303     \
304     "movdqa %%xmm6, %%xmm0 \n\t"     /* xmm0 = i0 - i4 */ \
305     "pmulhw %%xmm4, %%xmm6 \n\t"     /* xmm6 = ( c4 - 1 ) * ( i0 - i4 ) = F */ \
306     \
307     "paddsw %%xmm3, %%xmm3 \n\t"     /* xmm3 = i4 + i4 */ \
308     "paddsw %%xmm1, %%xmm1 \n\t"     /* xmm1 = H + H */ \
309     \
310     "paddsw %%xmm0, %%xmm3 \n\t"     /* xmm3 = i0 + i4 */ \
311     "paddsw %%xmm5, %%xmm1 \n\t"     /* xmm1 = B. + H = H. */ \
312     \
313     "pmulhw %%xmm3, %%xmm4 \n\t"     /* xmm4 = ( c4 - 1 ) * ( i0 + i4 )  */ \
314     "paddw  %%xmm0, %%xmm6 \n\t"     /* xmm6 = c4 * ( i0 - i4 ) */ \
315     \
316     "psubsw %%xmm2, %%xmm6 \n\t"     /* xmm6 = F - A. = F. */ \
317     "paddsw %%xmm2, %%xmm2 \n\t"     /* xmm2 = A. + A. */ \
318     \
319     "movdqa "I(1)", %%xmm0 \n\t"     /* Load C. from I(1) */ \
320     "paddsw %%xmm6, %%xmm2 \n\t"     /* xmm2 = F + A. = A.. */ \
321     \
322     "paddw  %%xmm3, %%xmm4 \n\t"     /* xmm4 = c4 * ( i0 + i4 ) = 3 */ \
323     "psubsw %%xmm1, %%xmm2 \n\t"     /* xmm2 = A.. - H. = R2 */ \
324     \
325     "paddsw %%xmm1, %%xmm1 \n\t"     /* xmm1 = H. + H. */ \
326     "paddsw %%xmm2, %%xmm1 \n\t"     /* xmm1 = A.. + H. = R1 */ \
327     \
328     "psubsw %%xmm7, %%xmm4 \n\t"     /* xmm4 = E - G = E. */ \
329     \
330     "movdqa "I(2)", %%xmm3 \n\t"     /* Load D. from I(2) */ \
331     "paddsw %%xmm7, %%xmm7 \n\t"     /* xmm7 = G + G */ \
332     \
333     "movdqa %%xmm2, "I(2)" \n\t"     /* Write out op2 */ \
334     "paddsw %%xmm4, %%xmm7 \n\t"     /* xmm7 = E + G = G. */ \
335     \
336     "movdqa %%xmm1, "I(1)" \n\t"     /* Write out op1 */ \
337     "psubsw %%xmm3, %%xmm4 \n\t"     /* xmm4 = E. - D. = R4 */ \
338     \
339     "paddsw %%xmm3, %%xmm3 \n\t"     /* xmm3 = D. + D. */ \
340     \
341     "paddsw %%xmm4, %%xmm3 \n\t"     /* xmm3 = E. + D. = R3 */ \
342     \
343     "psubsw %%xmm5, %%xmm6 \n\t"     /* xmm6 = F. - B..= R6 */ \
344     \
345     "paddsw %%xmm5, %%xmm5 \n\t"     /* xmm5 = B.. + B.. */ \
346     \
347     "paddsw %%xmm6, %%xmm5 \n\t"     /* xmm5 = F. + B.. = R5 */ \
348     \
349     "movdqa %%xmm4, "I(4)" \n\t"     /* Write out op4 */ \
350     \
351     "movdqa %%xmm3, "I(3)" \n\t"     /* Write out op3 */ \
352     "psubsw %%xmm0, %%xmm7 \n\t"     /* xmm7 = G. - C. = R7 */ \
353     \
354     "paddsw %%xmm0, %%xmm0 \n\t"     /* xmm0 = C. + C. */ \
355     \
356     "paddsw %%xmm7, %%xmm0 \n\t"     /* xmm0 = G. + C. */ \
357     \
358     "movdqa %%xmm6, "I(6)" \n\t"     /* Write out op6 */ \
359     \
360     "movdqa %%xmm5, "I(5)" \n\t"     /* Write out op5 */ \
361     "movdqa %%xmm7, "I(7)" \n\t"     /* Write out op7 */ \
362     \
363     \
364     "movdqa %%xmm0, "I(0)" \n\t"     /* Write out op0 */
365
366
367 #define SSE2_Transpose() \
368     \
369     "movdqa     "I(4)", %%xmm4 \n\t"     /* xmm4=e7e6e5e4e3e2e1e0 */ \
370     "movdqa     "I(5)", %%xmm0 \n\t"     /* xmm4=f7f6f5f4f3f2f1f0 */ \
371     \
372     "movdqa     %%xmm4, %%xmm5 \n\t"     /* make a copy */ \
373     "punpcklwd  %%xmm0, %%xmm4 \n\t"     /* xmm4=f3e3f2e2f1e1f0e0 */ \
374     \
375     "punpckhwd  %%xmm0, %%xmm5 \n\t"     /* xmm5=f7e7f6e6f5e5f4e4 */ \
376     "movdqa     "I(6)", %%xmm6 \n\t"     /* xmm6=g7g6g5g4g3g2g1g0 */ \
377     \
378     "movdqa     "I(7)", %%xmm0 \n\t"     /* xmm0=h7h6h5h4h3h2h1h0 */ \
379     "movdqa     %%xmm6, %%xmm7 \n\t"     /* make a copy */ \
380     \
381     "punpcklwd  %%xmm0, %%xmm6 \n\t"     /* xmm6=h3g3h3g2h1g1h0g0 */ \
382     "punpckhwd  %%xmm0, %%xmm7 \n\t"     /* xmm7=h7g7h6g6h5g5h4g4 */ \
383     \
384     "movdqa     %%xmm4, %%xmm3 \n\t"     /* make a copy */ \
385     "punpckldq  %%xmm6, %%xmm4 \n\t"     /* xmm4=h1g1f1e1h0g0f0e0 */ \
386     \
387     "punpckhdq  %%xmm6, %%xmm3 \n\t"     /* xmm3=h3g3g3e3h2g2f2e2 */ \
388     "movdqa     %%xmm3, "I(6)" \n\t"     /* save h3g3g3e3h2g2f2e2 */ \
389     /* Free xmm6 */ \
390     "movdqa     %%xmm5, %%xmm6 \n\t"     /* make a copy */ \
391     "punpckldq  %%xmm7, %%xmm5 \n\t"     /* xmm5=h5g5f5e5h4g4f4e4 */ \
392     \
393     "punpckhdq  %%xmm7, %%xmm6 \n\t"     /* xmm6=h7g7f7e7h6g6f6e6 */ \
394     "movdqa     "I(0)", %%xmm0 \n\t"     /* xmm0=a7a6a5a4a3a2a1a0 */ \
395     /* Free xmm7 */ \
396     "movdqa     "I(1)", %%xmm1 \n\t"     /* xmm1=b7b6b5b4b3b2b1b0 */ \
397     "movdqa     %%xmm0, %%xmm7 \n\t"     /* make a copy */ \
398     \
399     "punpcklwd  %%xmm1, %%xmm0 \n\t"     /* xmm0=b3a3b2a2b1a1b0a0 */ \
400     "punpckhwd  %%xmm1, %%xmm7 \n\t"     /* xmm7=b7a7b6a6b5a5b4a4 */ \
401     /* Free xmm1 */ \
402     "movdqa     "I(2)", %%xmm2 \n\t"     /* xmm2=c7c6c5c4c3c2c1c0 */ \
403     "movdqa     "I(3)", %%xmm3 \n\t"     /* xmm3=d7d6d5d4d3d2d1d0 */ \
404     \
405     "movdqa     %%xmm2, %%xmm1 \n\t"     /* make a copy */ \
406     "punpcklwd  %%xmm3, %%xmm2 \n\t"     /* xmm2=d3c3d2c2d1c1d0c0 */ \
407     \
408     "punpckhwd  %%xmm3, %%xmm1 \n\t"     /* xmm1=d7c7d6c6d5c5d4c4 */ \
409     "movdqa     %%xmm0, %%xmm3 \n\t"     /* make a copy        */ \
410     \
411     "punpckldq  %%xmm2, %%xmm0 \n\t"     /* xmm0=d1c1b1a1d0c0b0a0 */ \
412     "punpckhdq  %%xmm2, %%xmm3 \n\t"     /* xmm3=d3c3b3a3d2c2b2a2 */ \
413     /* Free xmm2 */ \
414     "movdqa     %%xmm7, %%xmm2 \n\t"     /* make a copy */ \
415     "punpckldq  %%xmm1, %%xmm2 \n\t"     /* xmm2=d5c5b5a5d4c4b4a4 */ \
416     \
417     "punpckhdq  %%xmm1, %%xmm7 \n\t"     /* xmm7=d7c7b7a7d6c6b6a6 */ \
418     "movdqa     %%xmm0, %%xmm1 \n\t"     /* make a copy */ \
419     \
420     "punpcklqdq %%xmm4, %%xmm0 \n\t"     /* xmm0=h0g0f0e0d0c0b0a0 */ \
421     "punpckhqdq %%xmm4, %%xmm1 \n\t"     /* xmm1=h1g1g1e1d1c1b1a1 */ \
422     \
423     "movdqa     %%xmm0, "I(0)" \n\t"     /* save I(0) */ \
424     "movdqa     %%xmm1, "I(1)" \n\t"     /* save I(1) */ \
425     \
426     "movdqa     "I(6)", %%xmm0 \n\t"     /* load h3g3g3e3h2g2f2e2 */ \
427     "movdqa     %%xmm3, %%xmm1 \n\t"     /* make a copy */ \
428     \
429     "punpcklqdq %%xmm0, %%xmm1 \n\t"     /* xmm1=h2g2f2e2d2c2b2a2 */ \
430     "punpckhqdq %%xmm0, %%xmm3 \n\t"     /* xmm3=h3g3f3e3d3c3b3a3 */ \
431     \
432     "movdqa     %%xmm2, %%xmm4 \n\t"     /* make a copy */ \
433     "punpcklqdq %%xmm5, %%xmm4 \n\t"     /* xmm4=h4g4f4e4d4c4b4a4 */ \
434     \
435     "punpckhqdq %%xmm5, %%xmm2 \n\t"     /* xmm2=h5g5f5e5d5c5b5a5 */ \
436     "movdqa     %%xmm1, "I(2)" \n\t"     /* save I(2) */ \
437     \
438     "movdqa     %%xmm3, "I(3)" \n\t"     /* save I(3) */ \
439     "movdqa     %%xmm4, "I(4)" \n\t"     /* save I(4) */ \
440     \
441     "movdqa     %%xmm2, "I(5)" \n\t"     /* save I(5) */ \
442     "movdqa     %%xmm7, %%xmm5 \n\t"     /* make a copy */ \
443     \
444     "punpcklqdq %%xmm6, %%xmm5 \n\t"     /* xmm5=h6g6f6e6d6c6b6a6 */ \
445     "punpckhqdq %%xmm6, %%xmm7 \n\t"     /* xmm7=h7g7f7e7d7c7b7a7 */ \
446     \
447     \
448     "movdqa     %%xmm5, "I(6)" \n\t"     /* save I(6) */ \
449     "movdqa     %%xmm7, "I(7)" \n\t"     /* save I(7) */
450
451 void ff_vp3_idct_sse2(int16_t *input_data)
452 {
453 #define OC_8 "%2"
454
455 #define I(x) AV_STRINGIFY(16*x)"(%0)"
456 #define O(x) I(x)
457 #define C(x) AV_STRINGIFY(16*(x-1))"(%1)"
458
459     asm volatile (
460     SSE2_Row_IDCT()
461
462     SSE2_Transpose()
463
464     SSE2_Column_IDCT()
465         :: "r"(input_data), "r"(ff_vp3_idct_data), "m"(ff_pw_8)
466     );
467 }
468
469 void ff_vp3_idct_put_sse2(uint8_t *dest, int line_size, DCTELEM *block)
470 {
471     ff_vp3_idct_sse2(block);
472     put_signed_pixels_clamped_mmx(block, dest, line_size);
473 }
474
475 void ff_vp3_idct_add_sse2(uint8_t *dest, int line_size, DCTELEM *block)
476 {
477     ff_vp3_idct_sse2(block);
478     add_pixels_clamped_mmx(block, dest, line_size);
479 }