swscale: Remove unused variables in x86 code.
[ffmpeg.git] / libswscale / x86 / swscale_template.c
1 /*
2  * Copyright (C) 2001-2003 Michael Niedermayer <michaelni@gmx.at>
3  *
4  * This file is part of Libav.
5  *
6  * Libav 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  * Libav 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 Libav; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19  */
20
21 #include "swscale_template.h"
22
23 #undef REAL_MOVNTQ
24 #undef MOVNTQ
25 #undef PREFETCH
26
27 #if COMPILE_TEMPLATE_MMX2
28 #define PREFETCH "prefetchnta"
29 #else
30 #define PREFETCH  " # nop"
31 #endif
32
33 #if COMPILE_TEMPLATE_MMX2
34 #define REAL_MOVNTQ(a,b) "movntq " #a ", " #b " \n\t"
35 #else
36 #define REAL_MOVNTQ(a,b) "movq " #a ", " #b " \n\t"
37 #endif
38 #define MOVNTQ(a,b)  REAL_MOVNTQ(a,b)
39
40 #define YSCALEYUV2YV12X(offset, dest, end, pos) \
41     __asm__ volatile(\
42         "movq             "VROUNDER_OFFSET"(%0), %%mm3      \n\t"\
43         "movq                             %%mm3, %%mm4      \n\t"\
44         "lea                     " offset "(%0), %%"REG_d"  \n\t"\
45         "mov                        (%%"REG_d"), %%"REG_S"  \n\t"\
46         ".p2align                             4             \n\t" /* FIXME Unroll? */\
47         "1:                                                 \n\t"\
48         "movq                      8(%%"REG_d"), %%mm0      \n\t" /* filterCoeff */\
49         "movq                (%%"REG_S", %3, 2), %%mm2      \n\t" /* srcData */\
50         "movq               8(%%"REG_S", %3, 2), %%mm5      \n\t" /* srcData */\
51         "add                                $16, %%"REG_d"  \n\t"\
52         "mov                        (%%"REG_d"), %%"REG_S"  \n\t"\
53         "test                         %%"REG_S", %%"REG_S"  \n\t"\
54         "pmulhw                           %%mm0, %%mm2      \n\t"\
55         "pmulhw                           %%mm0, %%mm5      \n\t"\
56         "paddw                            %%mm2, %%mm3      \n\t"\
57         "paddw                            %%mm5, %%mm4      \n\t"\
58         " jnz                                1b             \n\t"\
59         "psraw                               $3, %%mm3      \n\t"\
60         "psraw                               $3, %%mm4      \n\t"\
61         "packuswb                         %%mm4, %%mm3      \n\t"\
62         MOVNTQ(%%mm3, (%1, %3))\
63         "add                                 $8, %3         \n\t"\
64         "cmp                                 %2, %3         \n\t"\
65         "movq             "VROUNDER_OFFSET"(%0), %%mm3      \n\t"\
66         "movq                             %%mm3, %%mm4      \n\t"\
67         "lea                     " offset "(%0), %%"REG_d"  \n\t"\
68         "mov                        (%%"REG_d"), %%"REG_S"  \n\t"\
69         "jb                                  1b             \n\t"\
70         :: "r" (&c->redDither),\
71            "r" (dest), "g" ((x86_reg)(end)), "r"((x86_reg)(pos))\
72         : "%"REG_d, "%"REG_S\
73     );
74
75 static inline void RENAME(yuv2yuvX)(SwsContext *c, const int16_t *lumFilter,
76                                     const int16_t **lumSrc, int lumFilterSize,
77                                     const int16_t *chrFilter, const int16_t **chrUSrc,
78                                     const int16_t **chrVSrc,
79                                     int chrFilterSize, const int16_t **alpSrc,
80                                     uint8_t *dest, uint8_t *uDest, uint8_t *vDest,
81                                     uint8_t *aDest, long dstW, long chrDstW)
82 {
83     if (uDest) {
84         x86_reg uv_off = c->uv_off;
85         YSCALEYUV2YV12X(CHR_MMX_FILTER_OFFSET, uDest, chrDstW, 0)
86         YSCALEYUV2YV12X(CHR_MMX_FILTER_OFFSET, vDest - uv_off, chrDstW + uv_off, uv_off)
87     }
88     if (CONFIG_SWSCALE_ALPHA && aDest) {
89         YSCALEYUV2YV12X(ALP_MMX_FILTER_OFFSET, aDest, dstW, 0)
90     }
91
92     YSCALEYUV2YV12X(LUM_MMX_FILTER_OFFSET, dest, dstW, 0)
93 }
94
95 #define YSCALEYUV2YV12X_ACCURATE(offset, dest, end, pos) \
96     __asm__ volatile(\
97         "lea                     " offset "(%0), %%"REG_d"  \n\t"\
98         "pxor                             %%mm4, %%mm4      \n\t"\
99         "pxor                             %%mm5, %%mm5      \n\t"\
100         "pxor                             %%mm6, %%mm6      \n\t"\
101         "pxor                             %%mm7, %%mm7      \n\t"\
102         "mov                        (%%"REG_d"), %%"REG_S"  \n\t"\
103         ".p2align                             4             \n\t"\
104         "1:                                                 \n\t"\
105         "movq                (%%"REG_S", %3, 2), %%mm0      \n\t" /* srcData */\
106         "movq               8(%%"REG_S", %3, 2), %%mm2      \n\t" /* srcData */\
107         "mov        "STR(APCK_PTR2)"(%%"REG_d"), %%"REG_S"  \n\t"\
108         "movq                (%%"REG_S", %3, 2), %%mm1      \n\t" /* srcData */\
109         "movq                             %%mm0, %%mm3      \n\t"\
110         "punpcklwd                        %%mm1, %%mm0      \n\t"\
111         "punpckhwd                        %%mm1, %%mm3      \n\t"\
112         "movq       "STR(APCK_COEF)"(%%"REG_d"), %%mm1      \n\t" /* filterCoeff */\
113         "pmaddwd                          %%mm1, %%mm0      \n\t"\
114         "pmaddwd                          %%mm1, %%mm3      \n\t"\
115         "paddd                            %%mm0, %%mm4      \n\t"\
116         "paddd                            %%mm3, %%mm5      \n\t"\
117         "movq               8(%%"REG_S", %3, 2), %%mm3      \n\t" /* srcData */\
118         "mov        "STR(APCK_SIZE)"(%%"REG_d"), %%"REG_S"  \n\t"\
119         "add                  $"STR(APCK_SIZE)", %%"REG_d"  \n\t"\
120         "test                         %%"REG_S", %%"REG_S"  \n\t"\
121         "movq                             %%mm2, %%mm0      \n\t"\
122         "punpcklwd                        %%mm3, %%mm2      \n\t"\
123         "punpckhwd                        %%mm3, %%mm0      \n\t"\
124         "pmaddwd                          %%mm1, %%mm2      \n\t"\
125         "pmaddwd                          %%mm1, %%mm0      \n\t"\
126         "paddd                            %%mm2, %%mm6      \n\t"\
127         "paddd                            %%mm0, %%mm7      \n\t"\
128         " jnz                                1b             \n\t"\
129         "psrad                              $16, %%mm4      \n\t"\
130         "psrad                              $16, %%mm5      \n\t"\
131         "psrad                              $16, %%mm6      \n\t"\
132         "psrad                              $16, %%mm7      \n\t"\
133         "movq             "VROUNDER_OFFSET"(%0), %%mm0      \n\t"\
134         "packssdw                         %%mm5, %%mm4      \n\t"\
135         "packssdw                         %%mm7, %%mm6      \n\t"\
136         "paddw                            %%mm0, %%mm4      \n\t"\
137         "paddw                            %%mm0, %%mm6      \n\t"\
138         "psraw                               $3, %%mm4      \n\t"\
139         "psraw                               $3, %%mm6      \n\t"\
140         "packuswb                         %%mm6, %%mm4      \n\t"\
141         MOVNTQ(%%mm4, (%1, %3))\
142         "add                                 $8, %3         \n\t"\
143         "cmp                                 %2, %3         \n\t"\
144         "lea                     " offset "(%0), %%"REG_d"  \n\t"\
145         "pxor                             %%mm4, %%mm4      \n\t"\
146         "pxor                             %%mm5, %%mm5      \n\t"\
147         "pxor                             %%mm6, %%mm6      \n\t"\
148         "pxor                             %%mm7, %%mm7      \n\t"\
149         "mov                        (%%"REG_d"), %%"REG_S"  \n\t"\
150         "jb                                  1b             \n\t"\
151         :: "r" (&c->redDither),\
152         "r" (dest), "g" ((x86_reg)(end)), "r"((x86_reg)(pos))\
153         : "%"REG_a, "%"REG_d, "%"REG_S\
154     );
155
156 static inline void RENAME(yuv2yuvX_ar)(SwsContext *c, const int16_t *lumFilter,
157                                        const int16_t **lumSrc, int lumFilterSize,
158                                        const int16_t *chrFilter, const int16_t **chrUSrc,
159                                        const int16_t **chrVSrc,
160                                        int chrFilterSize, const int16_t **alpSrc,
161                                        uint8_t *dest, uint8_t *uDest, uint8_t *vDest,
162                                        uint8_t *aDest, long dstW, long chrDstW)
163 {
164     if (uDest) {
165         x86_reg uv_off = c->uv_off;
166         YSCALEYUV2YV12X_ACCURATE(CHR_MMX_FILTER_OFFSET, uDest, chrDstW, 0)
167         YSCALEYUV2YV12X_ACCURATE(CHR_MMX_FILTER_OFFSET, vDest - uv_off, chrDstW + uv_off, uv_off)
168     }
169     if (CONFIG_SWSCALE_ALPHA && aDest) {
170         YSCALEYUV2YV12X_ACCURATE(ALP_MMX_FILTER_OFFSET, aDest, dstW, 0)
171     }
172
173     YSCALEYUV2YV12X_ACCURATE(LUM_MMX_FILTER_OFFSET, dest, dstW, 0)
174 }
175
176 #define YSCALEYUV2YV121 \
177     "mov %2, %%"REG_a"                    \n\t"\
178     ".p2align               4             \n\t" /* FIXME Unroll? */\
179     "1:                                   \n\t"\
180     "movq  (%0, %%"REG_a", 2), %%mm0      \n\t"\
181     "movq 8(%0, %%"REG_a", 2), %%mm1      \n\t"\
182     "psraw                 $7, %%mm0      \n\t"\
183     "psraw                 $7, %%mm1      \n\t"\
184     "packuswb           %%mm1, %%mm0      \n\t"\
185     MOVNTQ(%%mm0, (%1, %%REGa))\
186     "add                   $8, %%"REG_a"  \n\t"\
187     "jnc                   1b             \n\t"
188
189 static inline void RENAME(yuv2yuv1)(SwsContext *c, const int16_t *lumSrc,
190                                     const int16_t *chrUSrc, const int16_t *chrVSrc,
191                                     const int16_t *alpSrc,
192                                     uint8_t *dest, uint8_t *uDest, uint8_t *vDest,
193                                     uint8_t *aDest, long dstW, long chrDstW)
194 {
195     long p= 4;
196     const uint8_t *src[4]= { alpSrc + dstW, lumSrc + dstW, chrUSrc + chrDstW, chrVSrc + chrDstW };
197     uint8_t *dst[4]= { aDest, dest, uDest, vDest };
198     x86_reg counter[4]= { dstW, dstW, chrDstW, chrDstW };
199
200     while (p--) {
201         if (dst[p]) {
202             __asm__ volatile(
203                YSCALEYUV2YV121
204                :: "r" (src[p]), "r" (dst[p] + counter[p]),
205                   "g" (-counter[p])
206                : "%"REG_a
207             );
208         }
209     }
210 }
211
212 #define YSCALEYUV2YV121_ACCURATE \
213     "mov %2, %%"REG_a"                    \n\t"\
214     "pcmpeqw %%mm7, %%mm7                 \n\t"\
215     "psrlw                 $15, %%mm7     \n\t"\
216     "psllw                  $6, %%mm7     \n\t"\
217     ".p2align                4            \n\t" /* FIXME Unroll? */\
218     "1:                                   \n\t"\
219     "movq  (%0, %%"REG_a", 2), %%mm0      \n\t"\
220     "movq 8(%0, %%"REG_a", 2), %%mm1      \n\t"\
221     "paddsw             %%mm7, %%mm0      \n\t"\
222     "paddsw             %%mm7, %%mm1      \n\t"\
223     "psraw                 $7, %%mm0      \n\t"\
224     "psraw                 $7, %%mm1      \n\t"\
225     "packuswb           %%mm1, %%mm0      \n\t"\
226     MOVNTQ(%%mm0, (%1, %%REGa))\
227     "add                   $8, %%"REG_a"  \n\t"\
228     "jnc                   1b             \n\t"
229
230 static inline void RENAME(yuv2yuv1_ar)(SwsContext *c, const int16_t *lumSrc,
231                                        const int16_t *chrUSrc, const int16_t *chrVSrc,
232                                        const int16_t *alpSrc,
233                                        uint8_t *dest, uint8_t *uDest, uint8_t *vDest,
234                                        uint8_t *aDest, long dstW, long chrDstW)
235 {
236     long p= 4;
237     const uint8_t *src[4]= { alpSrc + dstW, lumSrc + dstW, chrUSrc + chrDstW, chrVSrc + chrDstW };
238     uint8_t *dst[4]= { aDest, dest, uDest, vDest };
239     x86_reg counter[4]= { dstW, dstW, chrDstW, chrDstW };
240
241     while (p--) {
242         if (dst[p]) {
243             __asm__ volatile(
244                 YSCALEYUV2YV121_ACCURATE
245                 :: "r" (src[p]), "r" (dst[p] + counter[p]),
246                    "g" (-counter[p])
247                 : "%"REG_a
248             );
249         }
250     }
251 }
252
253 #define YSCALEYUV2PACKEDX_UV \
254     __asm__ volatile(\
255         "xor                   %%"REG_a", %%"REG_a"     \n\t"\
256         ".p2align                      4                \n\t"\
257         "nop                                            \n\t"\
258         "1:                                             \n\t"\
259         "lea "CHR_MMX_FILTER_OFFSET"(%0), %%"REG_d"     \n\t"\
260         "mov                 (%%"REG_d"), %%"REG_S"     \n\t"\
261         "movq      "VROUNDER_OFFSET"(%0), %%mm3         \n\t"\
262         "movq                      %%mm3, %%mm4         \n\t"\
263         ".p2align                      4                \n\t"\
264         "2:                                             \n\t"\
265         "movq               8(%%"REG_d"), %%mm0         \n\t" /* filterCoeff */\
266         "movq     (%%"REG_S", %%"REG_a"), %%mm2         \n\t" /* UsrcData */\
267         "add                          %6, %%"REG_S"     \n\t" \
268         "movq     (%%"REG_S", %%"REG_a"), %%mm5         \n\t" /* VsrcData */\
269         "add                         $16, %%"REG_d"     \n\t"\
270         "mov                 (%%"REG_d"), %%"REG_S"     \n\t"\
271         "pmulhw                    %%mm0, %%mm2         \n\t"\
272         "pmulhw                    %%mm0, %%mm5         \n\t"\
273         "paddw                     %%mm2, %%mm3         \n\t"\
274         "paddw                     %%mm5, %%mm4         \n\t"\
275         "test                  %%"REG_S", %%"REG_S"     \n\t"\
276         " jnz                         2b                \n\t"\
277
278 #define YSCALEYUV2PACKEDX_YA(offset,coeff,src1,src2,dst1,dst2) \
279     "lea                "offset"(%0), %%"REG_d"     \n\t"\
280     "mov                 (%%"REG_d"), %%"REG_S"     \n\t"\
281     "movq      "VROUNDER_OFFSET"(%0), "#dst1"       \n\t"\
282     "movq                    "#dst1", "#dst2"       \n\t"\
283     ".p2align                      4                \n\t"\
284     "2:                                             \n\t"\
285     "movq               8(%%"REG_d"), "#coeff"      \n\t" /* filterCoeff */\
286     "movq  (%%"REG_S", %%"REG_a", 2), "#src1"       \n\t" /* Y1srcData */\
287     "movq 8(%%"REG_S", %%"REG_a", 2), "#src2"       \n\t" /* Y2srcData */\
288     "add                         $16, %%"REG_d"            \n\t"\
289     "mov                 (%%"REG_d"), %%"REG_S"     \n\t"\
290     "pmulhw                 "#coeff", "#src1"       \n\t"\
291     "pmulhw                 "#coeff", "#src2"       \n\t"\
292     "paddw                   "#src1", "#dst1"       \n\t"\
293     "paddw                   "#src2", "#dst2"       \n\t"\
294     "test                  %%"REG_S", %%"REG_S"     \n\t"\
295     " jnz                         2b                \n\t"\
296
297 #define YSCALEYUV2PACKEDX \
298     YSCALEYUV2PACKEDX_UV \
299     YSCALEYUV2PACKEDX_YA(LUM_MMX_FILTER_OFFSET,%%mm0,%%mm2,%%mm5,%%mm1,%%mm7) \
300
301 #define YSCALEYUV2PACKEDX_END                     \
302         :: "r" (&c->redDither),                   \
303             "m" (dummy), "m" (dummy), "m" (dummy),\
304             "r" (dest), "m" (dstW_reg), "m"(uv_off) \
305         : "%"REG_a, "%"REG_d, "%"REG_S            \
306     );
307
308 #define YSCALEYUV2PACKEDX_ACCURATE_UV \
309     __asm__ volatile(\
310         "xor %%"REG_a", %%"REG_a"                       \n\t"\
311         ".p2align                      4                \n\t"\
312         "nop                                            \n\t"\
313         "1:                                             \n\t"\
314         "lea "CHR_MMX_FILTER_OFFSET"(%0), %%"REG_d"     \n\t"\
315         "mov                 (%%"REG_d"), %%"REG_S"     \n\t"\
316         "pxor                      %%mm4, %%mm4         \n\t"\
317         "pxor                      %%mm5, %%mm5         \n\t"\
318         "pxor                      %%mm6, %%mm6         \n\t"\
319         "pxor                      %%mm7, %%mm7         \n\t"\
320         ".p2align                      4                \n\t"\
321         "2:                                             \n\t"\
322         "movq     (%%"REG_S", %%"REG_a"), %%mm0         \n\t" /* UsrcData */\
323         "add                          %6, %%"REG_S"      \n\t" \
324         "movq     (%%"REG_S", %%"REG_a"), %%mm2         \n\t" /* VsrcData */\
325         "mov "STR(APCK_PTR2)"(%%"REG_d"), %%"REG_S"     \n\t"\
326         "movq     (%%"REG_S", %%"REG_a"), %%mm1         \n\t" /* UsrcData */\
327         "movq                      %%mm0, %%mm3         \n\t"\
328         "punpcklwd                 %%mm1, %%mm0         \n\t"\
329         "punpckhwd                 %%mm1, %%mm3         \n\t"\
330         "movq "STR(APCK_COEF)"(%%"REG_d"),%%mm1         \n\t" /* filterCoeff */\
331         "pmaddwd                   %%mm1, %%mm0         \n\t"\
332         "pmaddwd                   %%mm1, %%mm3         \n\t"\
333         "paddd                     %%mm0, %%mm4         \n\t"\
334         "paddd                     %%mm3, %%mm5         \n\t"\
335         "add                          %6, %%"REG_S"      \n\t" \
336         "movq     (%%"REG_S", %%"REG_a"), %%mm3         \n\t" /* VsrcData */\
337         "mov "STR(APCK_SIZE)"(%%"REG_d"), %%"REG_S"     \n\t"\
338         "add           $"STR(APCK_SIZE)", %%"REG_d"     \n\t"\
339         "test                  %%"REG_S", %%"REG_S"     \n\t"\
340         "movq                      %%mm2, %%mm0         \n\t"\
341         "punpcklwd                 %%mm3, %%mm2         \n\t"\
342         "punpckhwd                 %%mm3, %%mm0         \n\t"\
343         "pmaddwd                   %%mm1, %%mm2         \n\t"\
344         "pmaddwd                   %%mm1, %%mm0         \n\t"\
345         "paddd                     %%mm2, %%mm6         \n\t"\
346         "paddd                     %%mm0, %%mm7         \n\t"\
347         " jnz                         2b                \n\t"\
348         "psrad                       $16, %%mm4         \n\t"\
349         "psrad                       $16, %%mm5         \n\t"\
350         "psrad                       $16, %%mm6         \n\t"\
351         "psrad                       $16, %%mm7         \n\t"\
352         "movq      "VROUNDER_OFFSET"(%0), %%mm0         \n\t"\
353         "packssdw                  %%mm5, %%mm4         \n\t"\
354         "packssdw                  %%mm7, %%mm6         \n\t"\
355         "paddw                     %%mm0, %%mm4         \n\t"\
356         "paddw                     %%mm0, %%mm6         \n\t"\
357         "movq                      %%mm4, "U_TEMP"(%0)  \n\t"\
358         "movq                      %%mm6, "V_TEMP"(%0)  \n\t"\
359
360 #define YSCALEYUV2PACKEDX_ACCURATE_YA(offset) \
361     "lea                "offset"(%0), %%"REG_d"     \n\t"\
362     "mov                 (%%"REG_d"), %%"REG_S"     \n\t"\
363     "pxor                      %%mm1, %%mm1         \n\t"\
364     "pxor                      %%mm5, %%mm5         \n\t"\
365     "pxor                      %%mm7, %%mm7         \n\t"\
366     "pxor                      %%mm6, %%mm6         \n\t"\
367     ".p2align                      4                \n\t"\
368     "2:                                             \n\t"\
369     "movq  (%%"REG_S", %%"REG_a", 2), %%mm0         \n\t" /* Y1srcData */\
370     "movq 8(%%"REG_S", %%"REG_a", 2), %%mm2         \n\t" /* Y2srcData */\
371     "mov "STR(APCK_PTR2)"(%%"REG_d"), %%"REG_S"     \n\t"\
372     "movq  (%%"REG_S", %%"REG_a", 2), %%mm4         \n\t" /* Y1srcData */\
373     "movq                      %%mm0, %%mm3         \n\t"\
374     "punpcklwd                 %%mm4, %%mm0         \n\t"\
375     "punpckhwd                 %%mm4, %%mm3         \n\t"\
376     "movq "STR(APCK_COEF)"(%%"REG_d"), %%mm4         \n\t" /* filterCoeff */\
377     "pmaddwd                   %%mm4, %%mm0         \n\t"\
378     "pmaddwd                   %%mm4, %%mm3         \n\t"\
379     "paddd                     %%mm0, %%mm1         \n\t"\
380     "paddd                     %%mm3, %%mm5         \n\t"\
381     "movq 8(%%"REG_S", %%"REG_a", 2), %%mm3         \n\t" /* Y2srcData */\
382     "mov "STR(APCK_SIZE)"(%%"REG_d"), %%"REG_S"     \n\t"\
383     "add           $"STR(APCK_SIZE)", %%"REG_d"     \n\t"\
384     "test                  %%"REG_S", %%"REG_S"     \n\t"\
385     "movq                      %%mm2, %%mm0         \n\t"\
386     "punpcklwd                 %%mm3, %%mm2         \n\t"\
387     "punpckhwd                 %%mm3, %%mm0         \n\t"\
388     "pmaddwd                   %%mm4, %%mm2         \n\t"\
389     "pmaddwd                   %%mm4, %%mm0         \n\t"\
390     "paddd                     %%mm2, %%mm7         \n\t"\
391     "paddd                     %%mm0, %%mm6         \n\t"\
392     " jnz                         2b                \n\t"\
393     "psrad                       $16, %%mm1         \n\t"\
394     "psrad                       $16, %%mm5         \n\t"\
395     "psrad                       $16, %%mm7         \n\t"\
396     "psrad                       $16, %%mm6         \n\t"\
397     "movq      "VROUNDER_OFFSET"(%0), %%mm0         \n\t"\
398     "packssdw                  %%mm5, %%mm1         \n\t"\
399     "packssdw                  %%mm6, %%mm7         \n\t"\
400     "paddw                     %%mm0, %%mm1         \n\t"\
401     "paddw                     %%mm0, %%mm7         \n\t"\
402     "movq               "U_TEMP"(%0), %%mm3         \n\t"\
403     "movq               "V_TEMP"(%0), %%mm4         \n\t"\
404
405 #define YSCALEYUV2PACKEDX_ACCURATE \
406     YSCALEYUV2PACKEDX_ACCURATE_UV \
407     YSCALEYUV2PACKEDX_ACCURATE_YA(LUM_MMX_FILTER_OFFSET)
408
409 #define YSCALEYUV2RGBX \
410     "psubw  "U_OFFSET"(%0), %%mm3       \n\t" /* (U-128)8*/\
411     "psubw  "V_OFFSET"(%0), %%mm4       \n\t" /* (V-128)8*/\
412     "movq            %%mm3, %%mm2       \n\t" /* (U-128)8*/\
413     "movq            %%mm4, %%mm5       \n\t" /* (V-128)8*/\
414     "pmulhw "UG_COEFF"(%0), %%mm3       \n\t"\
415     "pmulhw "VG_COEFF"(%0), %%mm4       \n\t"\
416     /* mm2=(U-128)8, mm3=ug, mm4=vg mm5=(V-128)8 */\
417     "pmulhw "UB_COEFF"(%0), %%mm2       \n\t"\
418     "pmulhw "VR_COEFF"(%0), %%mm5       \n\t"\
419     "psubw  "Y_OFFSET"(%0), %%mm1       \n\t" /* 8(Y-16)*/\
420     "psubw  "Y_OFFSET"(%0), %%mm7       \n\t" /* 8(Y-16)*/\
421     "pmulhw  "Y_COEFF"(%0), %%mm1       \n\t"\
422     "pmulhw  "Y_COEFF"(%0), %%mm7       \n\t"\
423     /* mm1= Y1, mm2=ub, mm3=ug, mm4=vg mm5=vr, mm7=Y2 */\
424     "paddw           %%mm3, %%mm4       \n\t"\
425     "movq            %%mm2, %%mm0       \n\t"\
426     "movq            %%mm5, %%mm6       \n\t"\
427     "movq            %%mm4, %%mm3       \n\t"\
428     "punpcklwd       %%mm2, %%mm2       \n\t"\
429     "punpcklwd       %%mm5, %%mm5       \n\t"\
430     "punpcklwd       %%mm4, %%mm4       \n\t"\
431     "paddw           %%mm1, %%mm2       \n\t"\
432     "paddw           %%mm1, %%mm5       \n\t"\
433     "paddw           %%mm1, %%mm4       \n\t"\
434     "punpckhwd       %%mm0, %%mm0       \n\t"\
435     "punpckhwd       %%mm6, %%mm6       \n\t"\
436     "punpckhwd       %%mm3, %%mm3       \n\t"\
437     "paddw           %%mm7, %%mm0       \n\t"\
438     "paddw           %%mm7, %%mm6       \n\t"\
439     "paddw           %%mm7, %%mm3       \n\t"\
440     /* mm0=B1, mm2=B2, mm3=G2, mm4=G1, mm5=R1, mm6=R2 */\
441     "packuswb        %%mm0, %%mm2       \n\t"\
442     "packuswb        %%mm6, %%mm5       \n\t"\
443     "packuswb        %%mm3, %%mm4       \n\t"\
444
445 #define REAL_WRITEBGR32(dst, dstw, index, b, g, r, a, q0, q2, q3, t) \
446     "movq       "#b", "#q2"     \n\t" /* B */\
447     "movq       "#r", "#t"      \n\t" /* R */\
448     "punpcklbw  "#g", "#b"      \n\t" /* GBGBGBGB 0 */\
449     "punpcklbw  "#a", "#r"      \n\t" /* ARARARAR 0 */\
450     "punpckhbw  "#g", "#q2"     \n\t" /* GBGBGBGB 2 */\
451     "punpckhbw  "#a", "#t"      \n\t" /* ARARARAR 2 */\
452     "movq       "#b", "#q0"     \n\t" /* GBGBGBGB 0 */\
453     "movq      "#q2", "#q3"     \n\t" /* GBGBGBGB 2 */\
454     "punpcklwd  "#r", "#q0"     \n\t" /* ARGBARGB 0 */\
455     "punpckhwd  "#r", "#b"      \n\t" /* ARGBARGB 1 */\
456     "punpcklwd  "#t", "#q2"     \n\t" /* ARGBARGB 2 */\
457     "punpckhwd  "#t", "#q3"     \n\t" /* ARGBARGB 3 */\
458 \
459     MOVNTQ(   q0,   (dst, index, 4))\
460     MOVNTQ(    b,  8(dst, index, 4))\
461     MOVNTQ(   q2, 16(dst, index, 4))\
462     MOVNTQ(   q3, 24(dst, index, 4))\
463 \
464     "add      $8, "#index"      \n\t"\
465     "cmp "#dstw", "#index"      \n\t"\
466     " jb      1b                \n\t"
467 #define WRITEBGR32(dst, dstw, index, b, g, r, a, q0, q2, q3, t)  REAL_WRITEBGR32(dst, dstw, index, b, g, r, a, q0, q2, q3, t)
468
469 static inline void RENAME(yuv2rgb32_X_ar)(SwsContext *c, const int16_t *lumFilter,
470                                           const int16_t **lumSrc, int lumFilterSize,
471                                           const int16_t *chrFilter, const int16_t **chrUSrc,
472                                           const int16_t **chrVSrc,
473                                           int chrFilterSize, const int16_t **alpSrc,
474                                           uint8_t *dest, long dstW, long dstY)
475 {
476     x86_reg dummy=0;
477     x86_reg dstW_reg = dstW;
478     x86_reg uv_off = c->uv_off << 1;
479
480     if (CONFIG_SWSCALE_ALPHA && c->alpPixBuf) {
481         YSCALEYUV2PACKEDX_ACCURATE
482         YSCALEYUV2RGBX
483         "movq                      %%mm2, "U_TEMP"(%0)  \n\t"
484         "movq                      %%mm4, "V_TEMP"(%0)  \n\t"
485         "movq                      %%mm5, "Y_TEMP"(%0)  \n\t"
486         YSCALEYUV2PACKEDX_ACCURATE_YA(ALP_MMX_FILTER_OFFSET)
487         "movq               "Y_TEMP"(%0), %%mm5         \n\t"
488         "psraw                        $3, %%mm1         \n\t"
489         "psraw                        $3, %%mm7         \n\t"
490         "packuswb                  %%mm7, %%mm1         \n\t"
491         WRITEBGR32(%4, %5, %%REGa, %%mm3, %%mm4, %%mm5, %%mm1, %%mm0, %%mm7, %%mm2, %%mm6)
492         YSCALEYUV2PACKEDX_END
493     } else {
494         YSCALEYUV2PACKEDX_ACCURATE
495         YSCALEYUV2RGBX
496         "pcmpeqd %%mm7, %%mm7 \n\t"
497         WRITEBGR32(%4, %5, %%REGa, %%mm2, %%mm4, %%mm5, %%mm7, %%mm0, %%mm1, %%mm3, %%mm6)
498         YSCALEYUV2PACKEDX_END
499     }
500 }
501
502 static inline void RENAME(yuv2rgb32_X)(SwsContext *c, const int16_t *lumFilter,
503                                        const int16_t **lumSrc, int lumFilterSize,
504                                        const int16_t *chrFilter, const int16_t **chrUSrc,
505                                        const int16_t **chrVSrc,
506                                        int chrFilterSize, const int16_t **alpSrc,
507                                        uint8_t *dest, long dstW, long dstY)
508 {
509     x86_reg dummy=0;
510     x86_reg dstW_reg = dstW;
511     x86_reg uv_off = c->uv_off << 1;
512
513     if (CONFIG_SWSCALE_ALPHA && c->alpPixBuf) {
514         YSCALEYUV2PACKEDX
515         YSCALEYUV2RGBX
516         YSCALEYUV2PACKEDX_YA(ALP_MMX_FILTER_OFFSET, %%mm0, %%mm3, %%mm6, %%mm1, %%mm7)
517         "psraw                        $3, %%mm1         \n\t"
518         "psraw                        $3, %%mm7         \n\t"
519         "packuswb                  %%mm7, %%mm1         \n\t"
520         WRITEBGR32(%4, %5, %%REGa, %%mm2, %%mm4, %%mm5, %%mm1, %%mm0, %%mm7, %%mm3, %%mm6)
521         YSCALEYUV2PACKEDX_END
522     } else {
523         YSCALEYUV2PACKEDX
524         YSCALEYUV2RGBX
525         "pcmpeqd %%mm7, %%mm7 \n\t"
526         WRITEBGR32(%4, %5, %%REGa, %%mm2, %%mm4, %%mm5, %%mm7, %%mm0, %%mm1, %%mm3, %%mm6)
527         YSCALEYUV2PACKEDX_END
528     }
529 }
530
531 #define REAL_WRITERGB16(dst, dstw, index) \
532     "pand "MANGLE(bF8)", %%mm2  \n\t" /* B */\
533     "pand "MANGLE(bFC)", %%mm4  \n\t" /* G */\
534     "pand "MANGLE(bF8)", %%mm5  \n\t" /* R */\
535     "psrlq           $3, %%mm2  \n\t"\
536 \
537     "movq         %%mm2, %%mm1  \n\t"\
538     "movq         %%mm4, %%mm3  \n\t"\
539 \
540     "punpcklbw    %%mm7, %%mm3  \n\t"\
541     "punpcklbw    %%mm5, %%mm2  \n\t"\
542     "punpckhbw    %%mm7, %%mm4  \n\t"\
543     "punpckhbw    %%mm5, %%mm1  \n\t"\
544 \
545     "psllq           $3, %%mm3  \n\t"\
546     "psllq           $3, %%mm4  \n\t"\
547 \
548     "por          %%mm3, %%mm2  \n\t"\
549     "por          %%mm4, %%mm1  \n\t"\
550 \
551     MOVNTQ(%%mm2,  (dst, index, 2))\
552     MOVNTQ(%%mm1, 8(dst, index, 2))\
553 \
554     "add             $8, "#index"   \n\t"\
555     "cmp        "#dstw", "#index"   \n\t"\
556     " jb             1b             \n\t"
557 #define WRITERGB16(dst, dstw, index)  REAL_WRITERGB16(dst, dstw, index)
558
559 static inline void RENAME(yuv2rgb565_X_ar)(SwsContext *c, const int16_t *lumFilter,
560                                            const int16_t **lumSrc, int lumFilterSize,
561                                            const int16_t *chrFilter, const int16_t **chrUSrc,
562                                            const int16_t **chrVSrc,
563                                            int chrFilterSize, const int16_t **alpSrc,
564                                            uint8_t *dest, long dstW, long dstY)
565 {
566     x86_reg dummy=0;
567     x86_reg dstW_reg = dstW;
568     x86_reg uv_off = c->uv_off << 1;
569
570     YSCALEYUV2PACKEDX_ACCURATE
571     YSCALEYUV2RGBX
572     "pxor %%mm7, %%mm7 \n\t"
573     /* mm2=B, %%mm4=G, %%mm5=R, %%mm7=0 */
574 #ifdef DITHER1XBPP
575     "paddusb "BLUE_DITHER"(%0), %%mm2\n\t"
576     "paddusb "GREEN_DITHER"(%0), %%mm4\n\t"
577     "paddusb "RED_DITHER"(%0), %%mm5\n\t"
578 #endif
579     WRITERGB16(%4, %5, %%REGa)
580     YSCALEYUV2PACKEDX_END
581 }
582
583 static inline void RENAME(yuv2rgb565_X)(SwsContext *c, const int16_t *lumFilter,
584                                         const int16_t **lumSrc, int lumFilterSize,
585                                         const int16_t *chrFilter, const int16_t **chrUSrc,
586                                         const int16_t **chrVSrc,
587                                         int chrFilterSize, const int16_t **alpSrc,
588                                         uint8_t *dest, long dstW, long dstY)
589 {
590     x86_reg dummy=0;
591     x86_reg dstW_reg = dstW;
592     x86_reg uv_off = c->uv_off << 1;
593
594     YSCALEYUV2PACKEDX
595     YSCALEYUV2RGBX
596     "pxor %%mm7, %%mm7 \n\t"
597     /* mm2=B, %%mm4=G, %%mm5=R, %%mm7=0 */
598 #ifdef DITHER1XBPP
599     "paddusb "BLUE_DITHER"(%0), %%mm2  \n\t"
600     "paddusb "GREEN_DITHER"(%0), %%mm4  \n\t"
601     "paddusb "RED_DITHER"(%0), %%mm5  \n\t"
602 #endif
603     WRITERGB16(%4, %5, %%REGa)
604     YSCALEYUV2PACKEDX_END
605 }
606
607 #define REAL_WRITERGB15(dst, dstw, index) \
608     "pand "MANGLE(bF8)", %%mm2  \n\t" /* B */\
609     "pand "MANGLE(bF8)", %%mm4  \n\t" /* G */\
610     "pand "MANGLE(bF8)", %%mm5  \n\t" /* R */\
611     "psrlq           $3, %%mm2  \n\t"\
612     "psrlq           $1, %%mm5  \n\t"\
613 \
614     "movq         %%mm2, %%mm1  \n\t"\
615     "movq         %%mm4, %%mm3  \n\t"\
616 \
617     "punpcklbw    %%mm7, %%mm3  \n\t"\
618     "punpcklbw    %%mm5, %%mm2  \n\t"\
619     "punpckhbw    %%mm7, %%mm4  \n\t"\
620     "punpckhbw    %%mm5, %%mm1  \n\t"\
621 \
622     "psllq           $2, %%mm3  \n\t"\
623     "psllq           $2, %%mm4  \n\t"\
624 \
625     "por          %%mm3, %%mm2  \n\t"\
626     "por          %%mm4, %%mm1  \n\t"\
627 \
628     MOVNTQ(%%mm2,  (dst, index, 2))\
629     MOVNTQ(%%mm1, 8(dst, index, 2))\
630 \
631     "add             $8, "#index"   \n\t"\
632     "cmp        "#dstw", "#index"   \n\t"\
633     " jb             1b             \n\t"
634 #define WRITERGB15(dst, dstw, index)  REAL_WRITERGB15(dst, dstw, index)
635
636 static inline void RENAME(yuv2rgb555_X_ar)(SwsContext *c, const int16_t *lumFilter,
637                                            const int16_t **lumSrc, int lumFilterSize,
638                                            const int16_t *chrFilter, const int16_t **chrUSrc,
639                                            const int16_t **chrVSrc,
640                                            int chrFilterSize, const int16_t **alpSrc,
641                                            uint8_t *dest, long dstW, long dstY)
642 {
643     x86_reg dummy=0;
644     x86_reg dstW_reg = dstW;
645     x86_reg uv_off = c->uv_off << 1;
646
647     YSCALEYUV2PACKEDX_ACCURATE
648     YSCALEYUV2RGBX
649     "pxor %%mm7, %%mm7 \n\t"
650     /* mm2=B, %%mm4=G, %%mm5=R, %%mm7=0 */
651 #ifdef DITHER1XBPP
652     "paddusb "BLUE_DITHER"(%0), %%mm2\n\t"
653     "paddusb "GREEN_DITHER"(%0), %%mm4\n\t"
654     "paddusb "RED_DITHER"(%0), %%mm5\n\t"
655 #endif
656     WRITERGB15(%4, %5, %%REGa)
657     YSCALEYUV2PACKEDX_END
658 }
659
660 static inline void RENAME(yuv2rgb555_X)(SwsContext *c, const int16_t *lumFilter,
661                                         const int16_t **lumSrc, int lumFilterSize,
662                                         const int16_t *chrFilter, const int16_t **chrUSrc,
663                                         const int16_t **chrVSrc,
664                                         int chrFilterSize, const int16_t **alpSrc,
665                                         uint8_t *dest, long dstW, long dstY)
666 {
667     x86_reg dummy=0;
668     x86_reg dstW_reg = dstW;
669     x86_reg uv_off = c->uv_off << 1;
670
671     YSCALEYUV2PACKEDX
672     YSCALEYUV2RGBX
673     "pxor %%mm7, %%mm7 \n\t"
674     /* mm2=B, %%mm4=G, %%mm5=R, %%mm7=0 */
675 #ifdef DITHER1XBPP
676     "paddusb "BLUE_DITHER"(%0), %%mm2  \n\t"
677     "paddusb "GREEN_DITHER"(%0), %%mm4  \n\t"
678     "paddusb "RED_DITHER"(%0), %%mm5  \n\t"
679 #endif
680     WRITERGB15(%4, %5, %%REGa)
681     YSCALEYUV2PACKEDX_END
682 }
683
684 #define WRITEBGR24MMX(dst, dstw, index) \
685     /* mm2=B, %%mm4=G, %%mm5=R, %%mm7=0 */\
686     "movq      %%mm2, %%mm1     \n\t" /* B */\
687     "movq      %%mm5, %%mm6     \n\t" /* R */\
688     "punpcklbw %%mm4, %%mm2     \n\t" /* GBGBGBGB 0 */\
689     "punpcklbw %%mm7, %%mm5     \n\t" /* 0R0R0R0R 0 */\
690     "punpckhbw %%mm4, %%mm1     \n\t" /* GBGBGBGB 2 */\
691     "punpckhbw %%mm7, %%mm6     \n\t" /* 0R0R0R0R 2 */\
692     "movq      %%mm2, %%mm0     \n\t" /* GBGBGBGB 0 */\
693     "movq      %%mm1, %%mm3     \n\t" /* GBGBGBGB 2 */\
694     "punpcklwd %%mm5, %%mm0     \n\t" /* 0RGB0RGB 0 */\
695     "punpckhwd %%mm5, %%mm2     \n\t" /* 0RGB0RGB 1 */\
696     "punpcklwd %%mm6, %%mm1     \n\t" /* 0RGB0RGB 2 */\
697     "punpckhwd %%mm6, %%mm3     \n\t" /* 0RGB0RGB 3 */\
698 \
699     "movq      %%mm0, %%mm4     \n\t" /* 0RGB0RGB 0 */\
700     "movq      %%mm2, %%mm6     \n\t" /* 0RGB0RGB 1 */\
701     "movq      %%mm1, %%mm5     \n\t" /* 0RGB0RGB 2 */\
702     "movq      %%mm3, %%mm7     \n\t" /* 0RGB0RGB 3 */\
703 \
704     "psllq       $40, %%mm0     \n\t" /* RGB00000 0 */\
705     "psllq       $40, %%mm2     \n\t" /* RGB00000 1 */\
706     "psllq       $40, %%mm1     \n\t" /* RGB00000 2 */\
707     "psllq       $40, %%mm3     \n\t" /* RGB00000 3 */\
708 \
709     "punpckhdq %%mm4, %%mm0     \n\t" /* 0RGBRGB0 0 */\
710     "punpckhdq %%mm6, %%mm2     \n\t" /* 0RGBRGB0 1 */\
711     "punpckhdq %%mm5, %%mm1     \n\t" /* 0RGBRGB0 2 */\
712     "punpckhdq %%mm7, %%mm3     \n\t" /* 0RGBRGB0 3 */\
713 \
714     "psrlq        $8, %%mm0     \n\t" /* 00RGBRGB 0 */\
715     "movq      %%mm2, %%mm6     \n\t" /* 0RGBRGB0 1 */\
716     "psllq       $40, %%mm2     \n\t" /* GB000000 1 */\
717     "por       %%mm2, %%mm0     \n\t" /* GBRGBRGB 0 */\
718     MOVNTQ(%%mm0, (dst))\
719 \
720     "psrlq       $24, %%mm6     \n\t" /* 0000RGBR 1 */\
721     "movq      %%mm1, %%mm5     \n\t" /* 0RGBRGB0 2 */\
722     "psllq       $24, %%mm1     \n\t" /* BRGB0000 2 */\
723     "por       %%mm1, %%mm6     \n\t" /* BRGBRGBR 1 */\
724     MOVNTQ(%%mm6, 8(dst))\
725 \
726     "psrlq       $40, %%mm5     \n\t" /* 000000RG 2 */\
727     "psllq        $8, %%mm3     \n\t" /* RGBRGB00 3 */\
728     "por       %%mm3, %%mm5     \n\t" /* RGBRGBRG 2 */\
729     MOVNTQ(%%mm5, 16(dst))\
730 \
731     "add         $24, "#dst"    \n\t"\
732 \
733     "add          $8, "#index"  \n\t"\
734     "cmp     "#dstw", "#index"  \n\t"\
735     " jb          1b            \n\t"
736
737 #define WRITEBGR24MMX2(dst, dstw, index) \
738     /* mm2=B, %%mm4=G, %%mm5=R, %%mm7=0 */\
739     "movq "MANGLE(ff_M24A)", %%mm0 \n\t"\
740     "movq "MANGLE(ff_M24C)", %%mm7 \n\t"\
741     "pshufw $0x50, %%mm2, %%mm1 \n\t" /* B3 B2 B3 B2  B1 B0 B1 B0 */\
742     "pshufw $0x50, %%mm4, %%mm3 \n\t" /* G3 G2 G3 G2  G1 G0 G1 G0 */\
743     "pshufw $0x00, %%mm5, %%mm6 \n\t" /* R1 R0 R1 R0  R1 R0 R1 R0 */\
744 \
745     "pand   %%mm0, %%mm1        \n\t" /*    B2        B1       B0 */\
746     "pand   %%mm0, %%mm3        \n\t" /*    G2        G1       G0 */\
747     "pand   %%mm7, %%mm6        \n\t" /*       R1        R0       */\
748 \
749     "psllq     $8, %%mm3        \n\t" /* G2        G1       G0    */\
750     "por    %%mm1, %%mm6        \n\t"\
751     "por    %%mm3, %%mm6        \n\t"\
752     MOVNTQ(%%mm6, (dst))\
753 \
754     "psrlq     $8, %%mm4        \n\t" /* 00 G7 G6 G5  G4 G3 G2 G1 */\
755     "pshufw $0xA5, %%mm2, %%mm1 \n\t" /* B5 B4 B5 B4  B3 B2 B3 B2 */\
756     "pshufw $0x55, %%mm4, %%mm3 \n\t" /* G4 G3 G4 G3  G4 G3 G4 G3 */\
757     "pshufw $0xA5, %%mm5, %%mm6 \n\t" /* R5 R4 R5 R4  R3 R2 R3 R2 */\
758 \
759     "pand "MANGLE(ff_M24B)", %%mm1 \n\t" /* B5       B4        B3    */\
760     "pand   %%mm7, %%mm3        \n\t" /*       G4        G3       */\
761     "pand   %%mm0, %%mm6        \n\t" /*    R4        R3       R2 */\
762 \
763     "por    %%mm1, %%mm3        \n\t" /* B5    G4 B4     G3 B3    */\
764     "por    %%mm3, %%mm6        \n\t"\
765     MOVNTQ(%%mm6, 8(dst))\
766 \
767     "pshufw $0xFF, %%mm2, %%mm1 \n\t" /* B7 B6 B7 B6  B7 B6 B6 B7 */\
768     "pshufw $0xFA, %%mm4, %%mm3 \n\t" /* 00 G7 00 G7  G6 G5 G6 G5 */\
769     "pshufw $0xFA, %%mm5, %%mm6 \n\t" /* R7 R6 R7 R6  R5 R4 R5 R4 */\
770 \
771     "pand   %%mm7, %%mm1        \n\t" /*       B7        B6       */\
772     "pand   %%mm0, %%mm3        \n\t" /*    G7        G6       G5 */\
773     "pand "MANGLE(ff_M24B)", %%mm6 \n\t" /* R7       R6        R5    */\
774 \
775     "por    %%mm1, %%mm3        \n\t"\
776     "por    %%mm3, %%mm6        \n\t"\
777     MOVNTQ(%%mm6, 16(dst))\
778 \
779     "add      $24, "#dst"       \n\t"\
780 \
781     "add       $8, "#index"     \n\t"\
782     "cmp  "#dstw", "#index"     \n\t"\
783     " jb       1b               \n\t"
784
785 #if COMPILE_TEMPLATE_MMX2
786 #undef WRITEBGR24
787 #define WRITEBGR24(dst, dstw, index)  WRITEBGR24MMX2(dst, dstw, index)
788 #else
789 #undef WRITEBGR24
790 #define WRITEBGR24(dst, dstw, index)  WRITEBGR24MMX(dst, dstw, index)
791 #endif
792
793 static inline void RENAME(yuv2bgr24_X_ar)(SwsContext *c, const int16_t *lumFilter,
794                                           const int16_t **lumSrc, int lumFilterSize,
795                                           const int16_t *chrFilter, const int16_t **chrUSrc,
796                                           const int16_t **chrVSrc,
797                                           int chrFilterSize, const int16_t **alpSrc,
798                                           uint8_t *dest, long dstW, long dstY)
799 {
800     x86_reg dummy=0;
801     x86_reg dstW_reg = dstW;
802     x86_reg uv_off = c->uv_off << 1;
803
804     YSCALEYUV2PACKEDX_ACCURATE
805     YSCALEYUV2RGBX
806     "pxor %%mm7, %%mm7 \n\t"
807     "lea (%%"REG_a", %%"REG_a", 2), %%"REG_c"\n\t" //FIXME optimize
808     "add %4, %%"REG_c"                        \n\t"
809     WRITEBGR24(%%REGc, %5, %%REGa)
810     :: "r" (&c->redDither),
811        "m" (dummy), "m" (dummy), "m" (dummy),
812        "r" (dest), "m" (dstW_reg), "m"(uv_off)
813     : "%"REG_a, "%"REG_c, "%"REG_d, "%"REG_S
814     );
815 }
816
817 static inline void RENAME(yuv2bgr24_X)(SwsContext *c, const int16_t *lumFilter,
818                                        const int16_t **lumSrc, int lumFilterSize,
819                                        const int16_t *chrFilter, const int16_t **chrUSrc,
820                                        const int16_t **chrVSrc,
821                                        int chrFilterSize, const int16_t **alpSrc,
822                                        uint8_t *dest, long dstW, long dstY)
823 {
824     x86_reg dummy=0;
825     x86_reg dstW_reg = dstW;
826     x86_reg uv_off = c->uv_off << 1;
827
828     YSCALEYUV2PACKEDX
829     YSCALEYUV2RGBX
830     "pxor                    %%mm7, %%mm7       \n\t"
831     "lea (%%"REG_a", %%"REG_a", 2), %%"REG_c"   \n\t" //FIXME optimize
832     "add                        %4, %%"REG_c"   \n\t"
833     WRITEBGR24(%%REGc, %5, %%REGa)
834     :: "r" (&c->redDither),
835        "m" (dummy), "m" (dummy), "m" (dummy),
836        "r" (dest),  "m" (dstW_reg), "m"(uv_off)
837     : "%"REG_a, "%"REG_c, "%"REG_d, "%"REG_S
838     );
839 }
840
841 #define REAL_WRITEYUY2(dst, dstw, index) \
842     "packuswb  %%mm3, %%mm3     \n\t"\
843     "packuswb  %%mm4, %%mm4     \n\t"\
844     "packuswb  %%mm7, %%mm1     \n\t"\
845     "punpcklbw %%mm4, %%mm3     \n\t"\
846     "movq      %%mm1, %%mm7     \n\t"\
847     "punpcklbw %%mm3, %%mm1     \n\t"\
848     "punpckhbw %%mm3, %%mm7     \n\t"\
849 \
850     MOVNTQ(%%mm1, (dst, index, 2))\
851     MOVNTQ(%%mm7, 8(dst, index, 2))\
852 \
853     "add          $8, "#index"  \n\t"\
854     "cmp     "#dstw", "#index"  \n\t"\
855     " jb          1b            \n\t"
856 #define WRITEYUY2(dst, dstw, index)  REAL_WRITEYUY2(dst, dstw, index)
857
858 static inline void RENAME(yuv2yuyv422_X_ar)(SwsContext *c, const int16_t *lumFilter,
859                                             const int16_t **lumSrc, int lumFilterSize,
860                                             const int16_t *chrFilter, const int16_t **chrUSrc,
861                                             const int16_t **chrVSrc,
862                                             int chrFilterSize, const int16_t **alpSrc,
863                                             uint8_t *dest, long dstW, long dstY)
864 {
865     x86_reg dummy=0;
866     x86_reg dstW_reg = dstW;
867     x86_reg uv_off = c->uv_off << 1;
868
869     YSCALEYUV2PACKEDX_ACCURATE
870     /* mm2=B, %%mm4=G, %%mm5=R, %%mm7=0 */
871     "psraw $3, %%mm3    \n\t"
872     "psraw $3, %%mm4    \n\t"
873     "psraw $3, %%mm1    \n\t"
874     "psraw $3, %%mm7    \n\t"
875     WRITEYUY2(%4, %5, %%REGa)
876     YSCALEYUV2PACKEDX_END
877 }
878
879 static inline void RENAME(yuv2yuyv422_X)(SwsContext *c, const int16_t *lumFilter,
880                                          const int16_t **lumSrc, int lumFilterSize,
881                                          const int16_t *chrFilter, const int16_t **chrUSrc,
882                                          const int16_t **chrVSrc,
883                                          int chrFilterSize, const int16_t **alpSrc,
884                                          uint8_t *dest, long dstW, long dstY)
885 {
886     x86_reg dummy=0;
887     x86_reg dstW_reg = dstW;
888     x86_reg uv_off = c->uv_off << 1;
889
890     YSCALEYUV2PACKEDX
891     /* mm2=B, %%mm4=G, %%mm5=R, %%mm7=0 */
892     "psraw $3, %%mm3    \n\t"
893     "psraw $3, %%mm4    \n\t"
894     "psraw $3, %%mm1    \n\t"
895     "psraw $3, %%mm7    \n\t"
896     WRITEYUY2(%4, %5, %%REGa)
897     YSCALEYUV2PACKEDX_END
898 }
899
900 #define REAL_YSCALEYUV2RGB_UV(index, c, uv_off) \
901     "xor            "#index", "#index"  \n\t"\
902     ".p2align              4            \n\t"\
903     "1:                                 \n\t"\
904     "movq     (%2, "#index"), %%mm2     \n\t" /* uvbuf0[eax]*/\
905     "movq     (%3, "#index"), %%mm3     \n\t" /* uvbuf1[eax]*/\
906     "add           "#uv_off", "#index"  \n\t" \
907     "movq     (%2, "#index"), %%mm5     \n\t" /* uvbuf0[eax+2048]*/\
908     "movq     (%3, "#index"), %%mm4     \n\t" /* uvbuf1[eax+2048]*/\
909     "sub           "#uv_off", "#index"  \n\t" \
910     "psubw             %%mm3, %%mm2     \n\t" /* uvbuf0[eax] - uvbuf1[eax]*/\
911     "psubw             %%mm4, %%mm5     \n\t" /* uvbuf0[eax+2048] - uvbuf1[eax+2048]*/\
912     "movq "CHR_MMX_FILTER_OFFSET"+8("#c"), %%mm0    \n\t"\
913     "pmulhw            %%mm0, %%mm2     \n\t" /* (uvbuf0[eax] - uvbuf1[eax])uvalpha1>>16*/\
914     "pmulhw            %%mm0, %%mm5     \n\t" /* (uvbuf0[eax+2048] - uvbuf1[eax+2048])uvalpha1>>16*/\
915     "psraw                $4, %%mm3     \n\t" /* uvbuf0[eax] - uvbuf1[eax] >>4*/\
916     "psraw                $4, %%mm4     \n\t" /* uvbuf0[eax+2048] - uvbuf1[eax+2048] >>4*/\
917     "paddw             %%mm2, %%mm3     \n\t" /* uvbuf0[eax]uvalpha1 - uvbuf1[eax](1-uvalpha1)*/\
918     "paddw             %%mm5, %%mm4     \n\t" /* uvbuf0[eax+2048]uvalpha1 - uvbuf1[eax+2048](1-uvalpha1)*/\
919     "psubw  "U_OFFSET"("#c"), %%mm3     \n\t" /* (U-128)8*/\
920     "psubw  "V_OFFSET"("#c"), %%mm4     \n\t" /* (V-128)8*/\
921     "movq              %%mm3, %%mm2     \n\t" /* (U-128)8*/\
922     "movq              %%mm4, %%mm5     \n\t" /* (V-128)8*/\
923     "pmulhw "UG_COEFF"("#c"), %%mm3     \n\t"\
924     "pmulhw "VG_COEFF"("#c"), %%mm4     \n\t"\
925     /* mm2=(U-128)8, mm3=ug, mm4=vg mm5=(V-128)8 */\
926
927 #define REAL_YSCALEYUV2RGB_YA(index, c, b1, b2) \
928     "movq  ("#b1", "#index", 2), %%mm0     \n\t" /*buf0[eax]*/\
929     "movq  ("#b2", "#index", 2), %%mm1     \n\t" /*buf1[eax]*/\
930     "movq 8("#b1", "#index", 2), %%mm6     \n\t" /*buf0[eax]*/\
931     "movq 8("#b2", "#index", 2), %%mm7     \n\t" /*buf1[eax]*/\
932     "psubw             %%mm1, %%mm0     \n\t" /* buf0[eax] - buf1[eax]*/\
933     "psubw             %%mm7, %%mm6     \n\t" /* buf0[eax] - buf1[eax]*/\
934     "pmulhw "LUM_MMX_FILTER_OFFSET"+8("#c"), %%mm0  \n\t" /* (buf0[eax] - buf1[eax])yalpha1>>16*/\
935     "pmulhw "LUM_MMX_FILTER_OFFSET"+8("#c"), %%mm6  \n\t" /* (buf0[eax] - buf1[eax])yalpha1>>16*/\
936     "psraw                $4, %%mm1     \n\t" /* buf0[eax] - buf1[eax] >>4*/\
937     "psraw                $4, %%mm7     \n\t" /* buf0[eax] - buf1[eax] >>4*/\
938     "paddw             %%mm0, %%mm1     \n\t" /* buf0[eax]yalpha1 + buf1[eax](1-yalpha1) >>16*/\
939     "paddw             %%mm6, %%mm7     \n\t" /* buf0[eax]yalpha1 + buf1[eax](1-yalpha1) >>16*/\
940
941 #define REAL_YSCALEYUV2RGB_COEFF(c) \
942     "pmulhw "UB_COEFF"("#c"), %%mm2     \n\t"\
943     "pmulhw "VR_COEFF"("#c"), %%mm5     \n\t"\
944     "psubw  "Y_OFFSET"("#c"), %%mm1     \n\t" /* 8(Y-16)*/\
945     "psubw  "Y_OFFSET"("#c"), %%mm7     \n\t" /* 8(Y-16)*/\
946     "pmulhw  "Y_COEFF"("#c"), %%mm1     \n\t"\
947     "pmulhw  "Y_COEFF"("#c"), %%mm7     \n\t"\
948     /* mm1= Y1, mm2=ub, mm3=ug, mm4=vg mm5=vr, mm7=Y2 */\
949     "paddw             %%mm3, %%mm4     \n\t"\
950     "movq              %%mm2, %%mm0     \n\t"\
951     "movq              %%mm5, %%mm6     \n\t"\
952     "movq              %%mm4, %%mm3     \n\t"\
953     "punpcklwd         %%mm2, %%mm2     \n\t"\
954     "punpcklwd         %%mm5, %%mm5     \n\t"\
955     "punpcklwd         %%mm4, %%mm4     \n\t"\
956     "paddw             %%mm1, %%mm2     \n\t"\
957     "paddw             %%mm1, %%mm5     \n\t"\
958     "paddw             %%mm1, %%mm4     \n\t"\
959     "punpckhwd         %%mm0, %%mm0     \n\t"\
960     "punpckhwd         %%mm6, %%mm6     \n\t"\
961     "punpckhwd         %%mm3, %%mm3     \n\t"\
962     "paddw             %%mm7, %%mm0     \n\t"\
963     "paddw             %%mm7, %%mm6     \n\t"\
964     "paddw             %%mm7, %%mm3     \n\t"\
965     /* mm0=B1, mm2=B2, mm3=G2, mm4=G1, mm5=R1, mm6=R2 */\
966     "packuswb          %%mm0, %%mm2     \n\t"\
967     "packuswb          %%mm6, %%mm5     \n\t"\
968     "packuswb          %%mm3, %%mm4     \n\t"\
969
970 #define YSCALEYUV2RGB_YA(index, c, b1, b2) REAL_YSCALEYUV2RGB_YA(index, c, b1, b2)
971
972 #define YSCALEYUV2RGB(index, c, uv_off) \
973     REAL_YSCALEYUV2RGB_UV(index, c, uv_off) \
974     REAL_YSCALEYUV2RGB_YA(index, c, %0, %1) \
975     REAL_YSCALEYUV2RGB_COEFF(c)
976
977 /**
978  * vertical bilinear scale YV12 to RGB
979  */
980 static inline void RENAME(yuv2rgb32_2)(SwsContext *c, const uint16_t *buf0,
981                                        const uint16_t *buf1, const uint16_t *ubuf0,
982                                        const uint16_t *ubuf1, const uint16_t *vbuf0,
983                                        const uint16_t *vbuf1, const uint16_t *abuf0,
984                                        const uint16_t *abuf1, uint8_t *dest,
985                                        int dstW, int yalpha, int uvalpha, int y)
986 {
987     x86_reg uv_off = c->uv_off << 1;
988
989     if (CONFIG_SWSCALE_ALPHA && c->alpPixBuf) {
990 #if ARCH_X86_64
991         __asm__ volatile(
992             YSCALEYUV2RGB(%%r8, %5, %8)
993             YSCALEYUV2RGB_YA(%%r8, %5, %6, %7)
994             "psraw                  $3, %%mm1       \n\t" /* abuf0[eax] - abuf1[eax] >>7*/
995             "psraw                  $3, %%mm7       \n\t" /* abuf0[eax] - abuf1[eax] >>7*/
996             "packuswb            %%mm7, %%mm1       \n\t"
997             WRITEBGR32(%4, 8280(%5), %%r8, %%mm2, %%mm4, %%mm5, %%mm1, %%mm0, %%mm7, %%mm3, %%mm6)
998             :: "c" (buf0), "d" (buf1), "S" (ubuf0), "D" (ubuf1), "r" (dest),
999                "a" (&c->redDither),
1000                "r" (abuf0), "r" (abuf1), "m"(uv_off)
1001             : "%r8"
1002         );
1003 #else
1004         *(const uint16_t **)(&c->u_temp)=abuf0;
1005         *(const uint16_t **)(&c->v_temp)=abuf1;
1006         __asm__ volatile(
1007             "mov %%"REG_b", "ESP_OFFSET"(%5)        \n\t"
1008             "mov        %4, %%"REG_b"               \n\t"
1009             "push %%"REG_BP"                        \n\t"
1010             YSCALEYUV2RGB(%%REGBP, %5, %6)
1011             "push                   %0              \n\t"
1012             "push                   %1              \n\t"
1013             "mov          "U_TEMP"(%5), %0          \n\t"
1014             "mov          "V_TEMP"(%5), %1          \n\t"
1015             YSCALEYUV2RGB_YA(%%REGBP, %5, %0, %1)
1016             "psraw                  $3, %%mm1       \n\t" /* abuf0[eax] - abuf1[eax] >>7*/
1017             "psraw                  $3, %%mm7       \n\t" /* abuf0[eax] - abuf1[eax] >>7*/
1018             "packuswb            %%mm7, %%mm1       \n\t"
1019             "pop                    %1              \n\t"
1020             "pop                    %0              \n\t"
1021             WRITEBGR32(%%REGb, 8280(%5), %%REGBP, %%mm2, %%mm4, %%mm5, %%mm1, %%mm0, %%mm7, %%mm3, %%mm6)
1022             "pop %%"REG_BP"                         \n\t"
1023             "mov "ESP_OFFSET"(%5), %%"REG_b"        \n\t"
1024             :: "c" (buf0), "d" (buf1), "S" (ubuf0), "D" (ubuf1), "m" (dest),
1025                "a" (&c->redDither), "m"(uv_off)
1026         );
1027 #endif
1028     } else {
1029         __asm__ volatile(
1030             "mov %%"REG_b", "ESP_OFFSET"(%5)        \n\t"
1031             "mov        %4, %%"REG_b"               \n\t"
1032             "push %%"REG_BP"                        \n\t"
1033             YSCALEYUV2RGB(%%REGBP, %5, %6)
1034             "pcmpeqd %%mm7, %%mm7                   \n\t"
1035             WRITEBGR32(%%REGb, 8280(%5), %%REGBP, %%mm2, %%mm4, %%mm5, %%mm7, %%mm0, %%mm1, %%mm3, %%mm6)
1036             "pop %%"REG_BP"                         \n\t"
1037             "mov "ESP_OFFSET"(%5), %%"REG_b"        \n\t"
1038             :: "c" (buf0), "d" (buf1), "S" (ubuf0), "D" (ubuf1), "m" (dest),
1039                "a" (&c->redDither), "m"(uv_off)
1040         );
1041     }
1042 }
1043
1044 static inline void RENAME(yuv2bgr24_2)(SwsContext *c, const uint16_t *buf0,
1045                                        const uint16_t *buf1, const uint16_t *ubuf0,
1046                                        const uint16_t *ubuf1, const uint16_t *vbuf0,
1047                                        const uint16_t *vbuf1, const uint16_t *abuf0,
1048                                        const uint16_t *abuf1, uint8_t *dest,
1049                                        int dstW, int yalpha, int uvalpha, int y)
1050 {
1051     x86_reg uv_off = c->uv_off << 1;
1052
1053     //Note 8280 == DSTW_OFFSET but the preprocessor can't handle that there :(
1054     __asm__ volatile(
1055         "mov %%"REG_b", "ESP_OFFSET"(%5)        \n\t"
1056         "mov        %4, %%"REG_b"               \n\t"
1057         "push %%"REG_BP"                        \n\t"
1058         YSCALEYUV2RGB(%%REGBP, %5, %6)
1059         "pxor    %%mm7, %%mm7                   \n\t"
1060         WRITEBGR24(%%REGb, 8280(%5), %%REGBP)
1061         "pop %%"REG_BP"                         \n\t"
1062         "mov "ESP_OFFSET"(%5), %%"REG_b"        \n\t"
1063         :: "c" (buf0), "d" (buf1), "S" (ubuf0), "D" (ubuf1), "m" (dest),
1064            "a" (&c->redDither), "m"(uv_off)
1065     );
1066 }
1067
1068 static inline void RENAME(yuv2rgb555_2)(SwsContext *c, const uint16_t *buf0,
1069                                         const uint16_t *buf1, const uint16_t *ubuf0,
1070                                         const uint16_t *ubuf1, const uint16_t *vbuf0,
1071                                         const uint16_t *vbuf1, const uint16_t *abuf0,
1072                                         const uint16_t *abuf1, uint8_t *dest,
1073                                         int dstW, int yalpha, int uvalpha, int y)
1074 {
1075     x86_reg uv_off = c->uv_off << 1;
1076
1077     //Note 8280 == DSTW_OFFSET but the preprocessor can't handle that there :(
1078     __asm__ volatile(
1079         "mov %%"REG_b", "ESP_OFFSET"(%5)        \n\t"
1080         "mov        %4, %%"REG_b"               \n\t"
1081         "push %%"REG_BP"                        \n\t"
1082         YSCALEYUV2RGB(%%REGBP, %5, %6)
1083         "pxor    %%mm7, %%mm7                   \n\t"
1084         /* mm2=B, %%mm4=G, %%mm5=R, %%mm7=0 */
1085 #ifdef DITHER1XBPP
1086         "paddusb "BLUE_DITHER"(%5), %%mm2      \n\t"
1087         "paddusb "GREEN_DITHER"(%5), %%mm4      \n\t"
1088         "paddusb "RED_DITHER"(%5), %%mm5      \n\t"
1089 #endif
1090         WRITERGB15(%%REGb, 8280(%5), %%REGBP)
1091         "pop %%"REG_BP"                         \n\t"
1092         "mov "ESP_OFFSET"(%5), %%"REG_b"        \n\t"
1093         :: "c" (buf0), "d" (buf1), "S" (ubuf0), "D" (ubuf1), "m" (dest),
1094            "a" (&c->redDither), "m"(uv_off)
1095     );
1096 }
1097
1098 static inline void RENAME(yuv2rgb565_2)(SwsContext *c, const uint16_t *buf0,
1099                                         const uint16_t *buf1, const uint16_t *ubuf0,
1100                                         const uint16_t *ubuf1, const uint16_t *vbuf0,
1101                                         const uint16_t *vbuf1, const uint16_t *abuf0,
1102                                         const uint16_t *abuf1, uint8_t *dest,
1103                                         int dstW, int yalpha, int uvalpha, int y)
1104 {
1105     x86_reg uv_off = c->uv_off << 1;
1106
1107     //Note 8280 == DSTW_OFFSET but the preprocessor can't handle that there :(
1108     __asm__ volatile(
1109         "mov %%"REG_b", "ESP_OFFSET"(%5)        \n\t"
1110         "mov        %4, %%"REG_b"               \n\t"
1111         "push %%"REG_BP"                        \n\t"
1112         YSCALEYUV2RGB(%%REGBP, %5, %6)
1113         "pxor    %%mm7, %%mm7                   \n\t"
1114         /* mm2=B, %%mm4=G, %%mm5=R, %%mm7=0 */
1115 #ifdef DITHER1XBPP
1116         "paddusb "BLUE_DITHER"(%5), %%mm2      \n\t"
1117         "paddusb "GREEN_DITHER"(%5), %%mm4      \n\t"
1118         "paddusb "RED_DITHER"(%5), %%mm5      \n\t"
1119 #endif
1120         WRITERGB16(%%REGb, 8280(%5), %%REGBP)
1121         "pop %%"REG_BP"                         \n\t"
1122         "mov "ESP_OFFSET"(%5), %%"REG_b"        \n\t"
1123         :: "c" (buf0), "d" (buf1), "S" (ubuf0), "D" (ubuf1), "m" (dest),
1124            "a" (&c->redDither), "m"(uv_off)
1125     );
1126 }
1127
1128 #define REAL_YSCALEYUV2PACKED(index, c, uv_off) \
1129     "movq "CHR_MMX_FILTER_OFFSET"+8("#c"), %%mm0              \n\t"\
1130     "movq "LUM_MMX_FILTER_OFFSET"+8("#c"), %%mm1              \n\t"\
1131     "psraw                $3, %%mm0                           \n\t"\
1132     "psraw                $3, %%mm1                           \n\t"\
1133     "movq              %%mm0, "CHR_MMX_FILTER_OFFSET"+8("#c") \n\t"\
1134     "movq              %%mm1, "LUM_MMX_FILTER_OFFSET"+8("#c") \n\t"\
1135     "xor            "#index", "#index"                        \n\t"\
1136     ".p2align              4            \n\t"\
1137     "1:                                 \n\t"\
1138     "movq     (%2, "#index"), %%mm2     \n\t" /* uvbuf0[eax]*/\
1139     "movq     (%3, "#index"), %%mm3     \n\t" /* uvbuf1[eax]*/\
1140     "add           "#uv_off", "#index"  \n\t" \
1141     "movq     (%2, "#index"), %%mm5     \n\t" /* uvbuf0[eax+2048]*/\
1142     "movq     (%3, "#index"), %%mm4     \n\t" /* uvbuf1[eax+2048]*/\
1143     "sub           "#uv_off", "#index"  \n\t" \
1144     "psubw             %%mm3, %%mm2     \n\t" /* uvbuf0[eax] - uvbuf1[eax]*/\
1145     "psubw             %%mm4, %%mm5     \n\t" /* uvbuf0[eax+2048] - uvbuf1[eax+2048]*/\
1146     "movq "CHR_MMX_FILTER_OFFSET"+8("#c"), %%mm0    \n\t"\
1147     "pmulhw            %%mm0, %%mm2     \n\t" /* (uvbuf0[eax] - uvbuf1[eax])uvalpha1>>16*/\
1148     "pmulhw            %%mm0, %%mm5     \n\t" /* (uvbuf0[eax+2048] - uvbuf1[eax+2048])uvalpha1>>16*/\
1149     "psraw                $7, %%mm3     \n\t" /* uvbuf0[eax] - uvbuf1[eax] >>4*/\
1150     "psraw                $7, %%mm4     \n\t" /* uvbuf0[eax+2048] - uvbuf1[eax+2048] >>4*/\
1151     "paddw             %%mm2, %%mm3     \n\t" /* uvbuf0[eax]uvalpha1 - uvbuf1[eax](1-uvalpha1)*/\
1152     "paddw             %%mm5, %%mm4     \n\t" /* uvbuf0[eax+2048]uvalpha1 - uvbuf1[eax+2048](1-uvalpha1)*/\
1153     "movq  (%0, "#index", 2), %%mm0     \n\t" /*buf0[eax]*/\
1154     "movq  (%1, "#index", 2), %%mm1     \n\t" /*buf1[eax]*/\
1155     "movq 8(%0, "#index", 2), %%mm6     \n\t" /*buf0[eax]*/\
1156     "movq 8(%1, "#index", 2), %%mm7     \n\t" /*buf1[eax]*/\
1157     "psubw             %%mm1, %%mm0     \n\t" /* buf0[eax] - buf1[eax]*/\
1158     "psubw             %%mm7, %%mm6     \n\t" /* buf0[eax] - buf1[eax]*/\
1159     "pmulhw "LUM_MMX_FILTER_OFFSET"+8("#c"), %%mm0  \n\t" /* (buf0[eax] - buf1[eax])yalpha1>>16*/\
1160     "pmulhw "LUM_MMX_FILTER_OFFSET"+8("#c"), %%mm6  \n\t" /* (buf0[eax] - buf1[eax])yalpha1>>16*/\
1161     "psraw                $7, %%mm1     \n\t" /* buf0[eax] - buf1[eax] >>4*/\
1162     "psraw                $7, %%mm7     \n\t" /* buf0[eax] - buf1[eax] >>4*/\
1163     "paddw             %%mm0, %%mm1     \n\t" /* buf0[eax]yalpha1 + buf1[eax](1-yalpha1) >>16*/\
1164     "paddw             %%mm6, %%mm7     \n\t" /* buf0[eax]yalpha1 + buf1[eax](1-yalpha1) >>16*/\
1165
1166 #define YSCALEYUV2PACKED(index, c, uv_off)  REAL_YSCALEYUV2PACKED(index, c, uv_off)
1167
1168 static inline void RENAME(yuv2yuyv422_2)(SwsContext *c, const uint16_t *buf0,
1169                                          const uint16_t *buf1, const uint16_t *ubuf0,
1170                                          const uint16_t *ubuf1, const uint16_t *vbuf0,
1171                                          const uint16_t *vbuf1, const uint16_t *abuf0,
1172                                          const uint16_t *abuf1, uint8_t *dest,
1173                                          int dstW, int yalpha, int uvalpha, int y)
1174 {
1175     x86_reg uv_off = c->uv_off << 1;
1176
1177     //Note 8280 == DSTW_OFFSET but the preprocessor can't handle that there :(
1178     __asm__ volatile(
1179         "mov %%"REG_b", "ESP_OFFSET"(%5)        \n\t"
1180         "mov %4, %%"REG_b"                        \n\t"
1181         "push %%"REG_BP"                        \n\t"
1182         YSCALEYUV2PACKED(%%REGBP, %5, %6)
1183         WRITEYUY2(%%REGb, 8280(%5), %%REGBP)
1184         "pop %%"REG_BP"                         \n\t"
1185         "mov "ESP_OFFSET"(%5), %%"REG_b"        \n\t"
1186         :: "c" (buf0), "d" (buf1), "S" (ubuf0), "D" (ubuf1), "m" (dest),
1187            "a" (&c->redDither), "m"(uv_off)
1188     );
1189 }
1190
1191 #define REAL_YSCALEYUV2RGB1(index, c, uv_off) \
1192     "xor            "#index", "#index"  \n\t"\
1193     ".p2align              4            \n\t"\
1194     "1:                                 \n\t"\
1195     "movq     (%2, "#index"), %%mm3     \n\t" /* uvbuf0[eax]*/\
1196     "add           "#uv_off", "#index"  \n\t" \
1197     "movq     (%2, "#index"), %%mm4     \n\t" /* uvbuf0[eax+2048]*/\
1198     "sub           "#uv_off", "#index"  \n\t" \
1199     "psraw                $4, %%mm3     \n\t" /* uvbuf0[eax] - uvbuf1[eax] >>4*/\
1200     "psraw                $4, %%mm4     \n\t" /* uvbuf0[eax+2048] - uvbuf1[eax+2048] >>4*/\
1201     "psubw  "U_OFFSET"("#c"), %%mm3     \n\t" /* (U-128)8*/\
1202     "psubw  "V_OFFSET"("#c"), %%mm4     \n\t" /* (V-128)8*/\
1203     "movq              %%mm3, %%mm2     \n\t" /* (U-128)8*/\
1204     "movq              %%mm4, %%mm5     \n\t" /* (V-128)8*/\
1205     "pmulhw "UG_COEFF"("#c"), %%mm3     \n\t"\
1206     "pmulhw "VG_COEFF"("#c"), %%mm4     \n\t"\
1207     /* mm2=(U-128)8, mm3=ug, mm4=vg mm5=(V-128)8 */\
1208     "movq  (%0, "#index", 2), %%mm1     \n\t" /*buf0[eax]*/\
1209     "movq 8(%0, "#index", 2), %%mm7     \n\t" /*buf0[eax]*/\
1210     "psraw                $4, %%mm1     \n\t" /* buf0[eax] - buf1[eax] >>4*/\
1211     "psraw                $4, %%mm7     \n\t" /* buf0[eax] - buf1[eax] >>4*/\
1212     "pmulhw "UB_COEFF"("#c"), %%mm2     \n\t"\
1213     "pmulhw "VR_COEFF"("#c"), %%mm5     \n\t"\
1214     "psubw  "Y_OFFSET"("#c"), %%mm1     \n\t" /* 8(Y-16)*/\
1215     "psubw  "Y_OFFSET"("#c"), %%mm7     \n\t" /* 8(Y-16)*/\
1216     "pmulhw  "Y_COEFF"("#c"), %%mm1     \n\t"\
1217     "pmulhw  "Y_COEFF"("#c"), %%mm7     \n\t"\
1218     /* mm1= Y1, mm2=ub, mm3=ug, mm4=vg mm5=vr, mm7=Y2 */\
1219     "paddw             %%mm3, %%mm4     \n\t"\
1220     "movq              %%mm2, %%mm0     \n\t"\
1221     "movq              %%mm5, %%mm6     \n\t"\
1222     "movq              %%mm4, %%mm3     \n\t"\
1223     "punpcklwd         %%mm2, %%mm2     \n\t"\
1224     "punpcklwd         %%mm5, %%mm5     \n\t"\
1225     "punpcklwd         %%mm4, %%mm4     \n\t"\
1226     "paddw             %%mm1, %%mm2     \n\t"\
1227     "paddw             %%mm1, %%mm5     \n\t"\
1228     "paddw             %%mm1, %%mm4     \n\t"\
1229     "punpckhwd         %%mm0, %%mm0     \n\t"\
1230     "punpckhwd         %%mm6, %%mm6     \n\t"\
1231     "punpckhwd         %%mm3, %%mm3     \n\t"\
1232     "paddw             %%mm7, %%mm0     \n\t"\
1233     "paddw             %%mm7, %%mm6     \n\t"\
1234     "paddw             %%mm7, %%mm3     \n\t"\
1235     /* mm0=B1, mm2=B2, mm3=G2, mm4=G1, mm5=R1, mm6=R2 */\
1236     "packuswb          %%mm0, %%mm2     \n\t"\
1237     "packuswb          %%mm6, %%mm5     \n\t"\
1238     "packuswb          %%mm3, %%mm4     \n\t"\
1239
1240 #define YSCALEYUV2RGB1(index, c, uv_off)  REAL_YSCALEYUV2RGB1(index, c, uv_off)
1241
1242 // do vertical chrominance interpolation
1243 #define REAL_YSCALEYUV2RGB1b(index, c, uv_off) \
1244     "xor            "#index", "#index"  \n\t"\
1245     ".p2align              4            \n\t"\
1246     "1:                                 \n\t"\
1247     "movq     (%2, "#index"), %%mm2     \n\t" /* uvbuf0[eax]*/\
1248     "movq     (%3, "#index"), %%mm3     \n\t" /* uvbuf1[eax]*/\
1249     "add           "#uv_off", "#index"  \n\t" \
1250     "movq     (%2, "#index"), %%mm5     \n\t" /* uvbuf0[eax+2048]*/\
1251     "movq     (%3, "#index"), %%mm4     \n\t" /* uvbuf1[eax+2048]*/\
1252     "sub           "#uv_off", "#index"  \n\t" \
1253     "paddw             %%mm2, %%mm3     \n\t" /* uvbuf0[eax] + uvbuf1[eax]*/\
1254     "paddw             %%mm5, %%mm4     \n\t" /* uvbuf0[eax+2048] + uvbuf1[eax+2048]*/\
1255     "psrlw                $5, %%mm3     \n\t" /*FIXME might overflow*/\
1256     "psrlw                $5, %%mm4     \n\t" /*FIXME might overflow*/\
1257     "psubw  "U_OFFSET"("#c"), %%mm3     \n\t" /* (U-128)8*/\
1258     "psubw  "V_OFFSET"("#c"), %%mm4     \n\t" /* (V-128)8*/\
1259     "movq              %%mm3, %%mm2     \n\t" /* (U-128)8*/\
1260     "movq              %%mm4, %%mm5     \n\t" /* (V-128)8*/\
1261     "pmulhw "UG_COEFF"("#c"), %%mm3     \n\t"\
1262     "pmulhw "VG_COEFF"("#c"), %%mm4     \n\t"\
1263     /* mm2=(U-128)8, mm3=ug, mm4=vg mm5=(V-128)8 */\
1264     "movq  (%0, "#index", 2), %%mm1     \n\t" /*buf0[eax]*/\
1265     "movq 8(%0, "#index", 2), %%mm7     \n\t" /*buf0[eax]*/\
1266     "psraw                $4, %%mm1     \n\t" /* buf0[eax] - buf1[eax] >>4*/\
1267     "psraw                $4, %%mm7     \n\t" /* buf0[eax] - buf1[eax] >>4*/\
1268     "pmulhw "UB_COEFF"("#c"), %%mm2     \n\t"\
1269     "pmulhw "VR_COEFF"("#c"), %%mm5     \n\t"\
1270     "psubw  "Y_OFFSET"("#c"), %%mm1     \n\t" /* 8(Y-16)*/\
1271     "psubw  "Y_OFFSET"("#c"), %%mm7     \n\t" /* 8(Y-16)*/\
1272     "pmulhw  "Y_COEFF"("#c"), %%mm1     \n\t"\
1273     "pmulhw  "Y_COEFF"("#c"), %%mm7     \n\t"\
1274     /* mm1= Y1, mm2=ub, mm3=ug, mm4=vg mm5=vr, mm7=Y2 */\
1275     "paddw             %%mm3, %%mm4     \n\t"\
1276     "movq              %%mm2, %%mm0     \n\t"\
1277     "movq              %%mm5, %%mm6     \n\t"\
1278     "movq              %%mm4, %%mm3     \n\t"\
1279     "punpcklwd         %%mm2, %%mm2     \n\t"\
1280     "punpcklwd         %%mm5, %%mm5     \n\t"\
1281     "punpcklwd         %%mm4, %%mm4     \n\t"\
1282     "paddw             %%mm1, %%mm2     \n\t"\
1283     "paddw             %%mm1, %%mm5     \n\t"\
1284     "paddw             %%mm1, %%mm4     \n\t"\
1285     "punpckhwd         %%mm0, %%mm0     \n\t"\
1286     "punpckhwd         %%mm6, %%mm6     \n\t"\
1287     "punpckhwd         %%mm3, %%mm3     \n\t"\
1288     "paddw             %%mm7, %%mm0     \n\t"\
1289     "paddw             %%mm7, %%mm6     \n\t"\
1290     "paddw             %%mm7, %%mm3     \n\t"\
1291     /* mm0=B1, mm2=B2, mm3=G2, mm4=G1, mm5=R1, mm6=R2 */\
1292     "packuswb          %%mm0, %%mm2     \n\t"\
1293     "packuswb          %%mm6, %%mm5     \n\t"\
1294     "packuswb          %%mm3, %%mm4     \n\t"\
1295
1296 #define YSCALEYUV2RGB1b(index, c, uv_off)  REAL_YSCALEYUV2RGB1b(index, c, uv_off)
1297
1298 #define REAL_YSCALEYUV2RGB1_ALPHA(index) \
1299     "movq  (%1, "#index", 2), %%mm7     \n\t" /* abuf0[index  ]     */\
1300     "movq 8(%1, "#index", 2), %%mm1     \n\t" /* abuf0[index+4]     */\
1301     "psraw                $7, %%mm7     \n\t" /* abuf0[index  ] >>7 */\
1302     "psraw                $7, %%mm1     \n\t" /* abuf0[index+4] >>7 */\
1303     "packuswb          %%mm1, %%mm7     \n\t"
1304 #define YSCALEYUV2RGB1_ALPHA(index) REAL_YSCALEYUV2RGB1_ALPHA(index)
1305
1306 /**
1307  * YV12 to RGB without scaling or interpolating
1308  */
1309 static inline void RENAME(yuv2rgb32_1)(SwsContext *c, const uint16_t *buf0,
1310                                        const uint16_t *ubuf0, const uint16_t *ubuf1,
1311                                        const uint16_t *vbuf0, const uint16_t *vbuf1,
1312                                        const uint16_t *abuf0, uint8_t *dest,
1313                                        int dstW, int uvalpha, enum PixelFormat dstFormat,
1314                                        int flags, int y)
1315 {
1316     x86_reg uv_off = c->uv_off << 1;
1317     const uint16_t *buf1= buf0; //FIXME needed for RGB1/BGR1
1318
1319     if (uvalpha < 2048) { // note this is not correct (shifts chrominance by 0.5 pixels) but it is a bit faster
1320         if (CONFIG_SWSCALE_ALPHA && c->alpPixBuf) {
1321             __asm__ volatile(
1322                 "mov %%"REG_b", "ESP_OFFSET"(%5)        \n\t"
1323                 "mov        %4, %%"REG_b"               \n\t"
1324                 "push %%"REG_BP"                        \n\t"
1325                 YSCALEYUV2RGB1(%%REGBP, %5, %6)
1326                 YSCALEYUV2RGB1_ALPHA(%%REGBP)
1327                 WRITEBGR32(%%REGb, 8280(%5), %%REGBP, %%mm2, %%mm4, %%mm5, %%mm7, %%mm0, %%mm1, %%mm3, %%mm6)
1328                 "pop %%"REG_BP"                         \n\t"
1329                 "mov "ESP_OFFSET"(%5), %%"REG_b"        \n\t"
1330                 :: "c" (buf0), "d" (abuf0), "S" (ubuf0), "D" (ubuf1), "m" (dest),
1331                    "a" (&c->redDither), "m"(uv_off)
1332             );
1333         } else {
1334             __asm__ volatile(
1335                 "mov %%"REG_b", "ESP_OFFSET"(%5)        \n\t"
1336                 "mov        %4, %%"REG_b"               \n\t"
1337                 "push %%"REG_BP"                        \n\t"
1338                 YSCALEYUV2RGB1(%%REGBP, %5, %6)
1339                 "pcmpeqd %%mm7, %%mm7                   \n\t"
1340                 WRITEBGR32(%%REGb, 8280(%5), %%REGBP, %%mm2, %%mm4, %%mm5, %%mm7, %%mm0, %%mm1, %%mm3, %%mm6)
1341                 "pop %%"REG_BP"                         \n\t"
1342                 "mov "ESP_OFFSET"(%5), %%"REG_b"        \n\t"
1343                 :: "c" (buf0), "d" (buf1), "S" (ubuf0), "D" (ubuf1), "m" (dest),
1344                    "a" (&c->redDither), "m"(uv_off)
1345             );
1346         }
1347     } else {
1348         if (CONFIG_SWSCALE_ALPHA && c->alpPixBuf) {
1349             __asm__ volatile(
1350                 "mov %%"REG_b", "ESP_OFFSET"(%5)        \n\t"
1351                 "mov        %4, %%"REG_b"               \n\t"
1352                 "push %%"REG_BP"                        \n\t"
1353                 YSCALEYUV2RGB1b(%%REGBP, %5, %6)
1354                 YSCALEYUV2RGB1_ALPHA(%%REGBP)
1355                 WRITEBGR32(%%REGb, 8280(%5), %%REGBP, %%mm2, %%mm4, %%mm5, %%mm7, %%mm0, %%mm1, %%mm3, %%mm6)
1356                 "pop %%"REG_BP"                         \n\t"
1357                 "mov "ESP_OFFSET"(%5), %%"REG_b"        \n\t"
1358                 :: "c" (buf0), "d" (abuf0), "S" (ubuf0), "D" (ubuf1), "m" (dest),
1359                    "a" (&c->redDither), "m"(uv_off)
1360             );
1361         } else {
1362             __asm__ volatile(
1363                 "mov %%"REG_b", "ESP_OFFSET"(%5)        \n\t"
1364                 "mov        %4, %%"REG_b"               \n\t"
1365                 "push %%"REG_BP"                        \n\t"
1366                 YSCALEYUV2RGB1b(%%REGBP, %5, %6)
1367                 "pcmpeqd %%mm7, %%mm7                   \n\t"
1368                 WRITEBGR32(%%REGb, 8280(%5), %%REGBP, %%mm2, %%mm4, %%mm5, %%mm7, %%mm0, %%mm1, %%mm3, %%mm6)
1369                 "pop %%"REG_BP"                         \n\t"
1370                 "mov "ESP_OFFSET"(%5), %%"REG_b"        \n\t"
1371                 :: "c" (buf0), "d" (buf1), "S" (ubuf0), "D" (ubuf1), "m" (dest),
1372                    "a" (&c->redDither), "m"(uv_off)
1373             );
1374         }
1375     }
1376 }
1377
1378 static inline void RENAME(yuv2bgr24_1)(SwsContext *c, const uint16_t *buf0,
1379                                        const uint16_t *ubuf0, const uint16_t *ubuf1,
1380                                        const uint16_t *vbuf0, const uint16_t *vbuf1,
1381                                        const uint16_t *abuf0, uint8_t *dest,
1382                                        int dstW, int uvalpha, enum PixelFormat dstFormat,
1383                                        int flags, int y)
1384 {
1385     x86_reg uv_off = c->uv_off << 1;
1386     const uint16_t *buf1= buf0; //FIXME needed for RGB1/BGR1
1387
1388     if (uvalpha < 2048) { // note this is not correct (shifts chrominance by 0.5 pixels) but it is a bit faster
1389         __asm__ volatile(
1390             "mov %%"REG_b", "ESP_OFFSET"(%5)        \n\t"
1391             "mov        %4, %%"REG_b"               \n\t"
1392             "push %%"REG_BP"                        \n\t"
1393             YSCALEYUV2RGB1(%%REGBP, %5, %6)
1394             "pxor    %%mm7, %%mm7                   \n\t"
1395             WRITEBGR24(%%REGb, 8280(%5), %%REGBP)
1396             "pop %%"REG_BP"                         \n\t"
1397             "mov "ESP_OFFSET"(%5), %%"REG_b"        \n\t"
1398             :: "c" (buf0), "d" (buf1), "S" (ubuf0), "D" (ubuf1), "m" (dest),
1399                "a" (&c->redDither), "m"(uv_off)
1400         );
1401     } else {
1402         __asm__ volatile(
1403             "mov %%"REG_b", "ESP_OFFSET"(%5)        \n\t"
1404             "mov        %4, %%"REG_b"               \n\t"
1405             "push %%"REG_BP"                        \n\t"
1406             YSCALEYUV2RGB1b(%%REGBP, %5, %6)
1407             "pxor    %%mm7, %%mm7                   \n\t"
1408             WRITEBGR24(%%REGb, 8280(%5), %%REGBP)
1409             "pop %%"REG_BP"                         \n\t"
1410             "mov "ESP_OFFSET"(%5), %%"REG_b"        \n\t"
1411             :: "c" (buf0), "d" (buf1), "S" (ubuf0), "D" (ubuf1), "m" (dest),
1412                "a" (&c->redDither), "m"(uv_off)
1413         );
1414     }
1415 }
1416
1417 static inline void RENAME(yuv2rgb555_1)(SwsContext *c, const uint16_t *buf0,
1418                                         const uint16_t *ubuf0, const uint16_t *ubuf1,
1419                                         const uint16_t *vbuf0, const uint16_t *vbuf1,
1420                                         const uint16_t *abuf0, uint8_t *dest,
1421                                         int dstW, int uvalpha, enum PixelFormat dstFormat,
1422                                         int flags, int y)
1423 {
1424     x86_reg uv_off = c->uv_off << 1;
1425     const uint16_t *buf1= buf0; //FIXME needed for RGB1/BGR1
1426
1427     if (uvalpha < 2048) { // note this is not correct (shifts chrominance by 0.5 pixels) but it is a bit faster
1428         __asm__ volatile(
1429             "mov %%"REG_b", "ESP_OFFSET"(%5)        \n\t"
1430             "mov        %4, %%"REG_b"               \n\t"
1431             "push %%"REG_BP"                        \n\t"
1432             YSCALEYUV2RGB1(%%REGBP, %5, %6)
1433             "pxor    %%mm7, %%mm7                   \n\t"
1434             /* mm2=B, %%mm4=G, %%mm5=R, %%mm7=0 */
1435 #ifdef DITHER1XBPP
1436             "paddusb "BLUE_DITHER"(%5), %%mm2      \n\t"
1437             "paddusb "GREEN_DITHER"(%5), %%mm4      \n\t"
1438             "paddusb "RED_DITHER"(%5), %%mm5      \n\t"
1439 #endif
1440             WRITERGB15(%%REGb, 8280(%5), %%REGBP)
1441             "pop %%"REG_BP"                         \n\t"
1442             "mov "ESP_OFFSET"(%5), %%"REG_b"        \n\t"
1443             :: "c" (buf0), "d" (buf1), "S" (ubuf0), "D" (ubuf1), "m" (dest),
1444                "a" (&c->redDither), "m"(uv_off)
1445         );
1446     } else {
1447         __asm__ volatile(
1448             "mov %%"REG_b", "ESP_OFFSET"(%5)        \n\t"
1449             "mov        %4, %%"REG_b"               \n\t"
1450             "push %%"REG_BP"                        \n\t"
1451             YSCALEYUV2RGB1b(%%REGBP, %5, %6)
1452             "pxor    %%mm7, %%mm7                   \n\t"
1453             /* mm2=B, %%mm4=G, %%mm5=R, %%mm7=0 */
1454 #ifdef DITHER1XBPP
1455             "paddusb "BLUE_DITHER"(%5), %%mm2      \n\t"
1456             "paddusb "GREEN_DITHER"(%5), %%mm4      \n\t"
1457             "paddusb "RED_DITHER"(%5), %%mm5      \n\t"
1458 #endif
1459             WRITERGB15(%%REGb, 8280(%5), %%REGBP)
1460             "pop %%"REG_BP"                         \n\t"
1461             "mov "ESP_OFFSET"(%5), %%"REG_b"        \n\t"
1462             :: "c" (buf0), "d" (buf1), "S" (ubuf0), "D" (ubuf1), "m" (dest),
1463                "a" (&c->redDither), "m"(uv_off)
1464         );
1465     }
1466 }
1467
1468 static inline void RENAME(yuv2rgb565_1)(SwsContext *c, const uint16_t *buf0,
1469                                         const uint16_t *ubuf0, const uint16_t *ubuf1,
1470                                         const uint16_t *vbuf0, const uint16_t *vbuf1,
1471                                         const uint16_t *abuf0, uint8_t *dest,
1472                                         int dstW, int uvalpha, enum PixelFormat dstFormat,
1473                                         int flags, int y)
1474 {
1475     x86_reg uv_off = c->uv_off << 1;
1476     const uint16_t *buf1= buf0; //FIXME needed for RGB1/BGR1
1477
1478     if (uvalpha < 2048) { // note this is not correct (shifts chrominance by 0.5 pixels) but it is a bit faster
1479         __asm__ volatile(
1480             "mov %%"REG_b", "ESP_OFFSET"(%5)        \n\t"
1481             "mov        %4, %%"REG_b"               \n\t"
1482             "push %%"REG_BP"                        \n\t"
1483             YSCALEYUV2RGB1(%%REGBP, %5, %6)
1484             "pxor    %%mm7, %%mm7                   \n\t"
1485             /* mm2=B, %%mm4=G, %%mm5=R, %%mm7=0 */
1486 #ifdef DITHER1XBPP
1487             "paddusb "BLUE_DITHER"(%5), %%mm2      \n\t"
1488             "paddusb "GREEN_DITHER"(%5), %%mm4      \n\t"
1489             "paddusb "RED_DITHER"(%5), %%mm5      \n\t"
1490 #endif
1491             WRITERGB16(%%REGb, 8280(%5), %%REGBP)
1492             "pop %%"REG_BP"                         \n\t"
1493             "mov "ESP_OFFSET"(%5), %%"REG_b"        \n\t"
1494             :: "c" (buf0), "d" (buf1), "S" (ubuf0), "D" (ubuf1), "m" (dest),
1495                "a" (&c->redDither), "m"(uv_off)
1496         );
1497     } else {
1498         __asm__ volatile(
1499             "mov %%"REG_b", "ESP_OFFSET"(%5)        \n\t"
1500             "mov        %4, %%"REG_b"               \n\t"
1501             "push %%"REG_BP"                        \n\t"
1502             YSCALEYUV2RGB1b(%%REGBP, %5, %6)
1503             "pxor    %%mm7, %%mm7                   \n\t"
1504             /* mm2=B, %%mm4=G, %%mm5=R, %%mm7=0 */
1505 #ifdef DITHER1XBPP
1506             "paddusb "BLUE_DITHER"(%5), %%mm2      \n\t"
1507             "paddusb "GREEN_DITHER"(%5), %%mm4      \n\t"
1508             "paddusb "RED_DITHER"(%5), %%mm5      \n\t"
1509 #endif
1510             WRITERGB16(%%REGb, 8280(%5), %%REGBP)
1511             "pop %%"REG_BP"                         \n\t"
1512             "mov "ESP_OFFSET"(%5), %%"REG_b"        \n\t"
1513             :: "c" (buf0), "d" (buf1), "S" (ubuf0), "D" (ubuf1), "m" (dest),
1514                "a" (&c->redDither), "m"(uv_off)
1515         );
1516     }
1517 }
1518
1519 #define REAL_YSCALEYUV2PACKED1(index, c, uv_off) \
1520     "xor            "#index", "#index"  \n\t"\
1521     ".p2align              4            \n\t"\
1522     "1:                                 \n\t"\
1523     "movq     (%2, "#index"), %%mm3     \n\t" /* uvbuf0[eax]*/\
1524     "add           "#uv_off", "#index"  \n\t" \
1525     "movq     (%2, "#index"), %%mm4     \n\t" /* uvbuf0[eax+2048]*/\
1526     "sub           "#uv_off", "#index"  \n\t" \
1527     "psraw                $7, %%mm3     \n\t" \
1528     "psraw                $7, %%mm4     \n\t" \
1529     "movq  (%0, "#index", 2), %%mm1     \n\t" /*buf0[eax]*/\
1530     "movq 8(%0, "#index", 2), %%mm7     \n\t" /*buf0[eax]*/\
1531     "psraw                $7, %%mm1     \n\t" \
1532     "psraw                $7, %%mm7     \n\t" \
1533
1534 #define YSCALEYUV2PACKED1(index, c, uv_off)  REAL_YSCALEYUV2PACKED1(index, c, uv_off)
1535
1536 #define REAL_YSCALEYUV2PACKED1b(index, c, uv_off) \
1537     "xor "#index", "#index"             \n\t"\
1538     ".p2align              4            \n\t"\
1539     "1:                                 \n\t"\
1540     "movq     (%2, "#index"), %%mm2     \n\t" /* uvbuf0[eax]*/\
1541     "movq     (%3, "#index"), %%mm3     \n\t" /* uvbuf1[eax]*/\
1542     "add           "#uv_off", "#index"  \n\t" \
1543     "movq     (%2, "#index"), %%mm5     \n\t" /* uvbuf0[eax+2048]*/\
1544     "movq     (%3, "#index"), %%mm4     \n\t" /* uvbuf1[eax+2048]*/\
1545     "sub           "#uv_off", "#index"  \n\t" \
1546     "paddw             %%mm2, %%mm3     \n\t" /* uvbuf0[eax] + uvbuf1[eax]*/\
1547     "paddw             %%mm5, %%mm4     \n\t" /* uvbuf0[eax+2048] + uvbuf1[eax+2048]*/\
1548     "psrlw                $8, %%mm3     \n\t" \
1549     "psrlw                $8, %%mm4     \n\t" \
1550     "movq  (%0, "#index", 2), %%mm1     \n\t" /*buf0[eax]*/\
1551     "movq 8(%0, "#index", 2), %%mm7     \n\t" /*buf0[eax]*/\
1552     "psraw                $7, %%mm1     \n\t" \
1553     "psraw                $7, %%mm7     \n\t"
1554 #define YSCALEYUV2PACKED1b(index, c, uv_off)  REAL_YSCALEYUV2PACKED1b(index, c, uv_off)
1555
1556 static inline void RENAME(yuv2yuyv422_1)(SwsContext *c, const uint16_t *buf0,
1557                                          const uint16_t *ubuf0, const uint16_t *ubuf1,
1558                                          const uint16_t *vbuf0, const uint16_t *vbuf1,
1559                                          const uint16_t *abuf0, uint8_t *dest,
1560                                          int dstW, int uvalpha, enum PixelFormat dstFormat,
1561                                          int flags, int y)
1562 {
1563     x86_reg uv_off = c->uv_off << 1;
1564     const uint16_t *buf1= buf0; //FIXME needed for RGB1/BGR1
1565
1566     if (uvalpha < 2048) { // note this is not correct (shifts chrominance by 0.5 pixels) but it is a bit faster
1567         __asm__ volatile(
1568             "mov %%"REG_b", "ESP_OFFSET"(%5)        \n\t"
1569             "mov        %4, %%"REG_b"               \n\t"
1570             "push %%"REG_BP"                        \n\t"
1571             YSCALEYUV2PACKED1(%%REGBP, %5, %6)
1572             WRITEYUY2(%%REGb, 8280(%5), %%REGBP)
1573             "pop %%"REG_BP"                         \n\t"
1574             "mov "ESP_OFFSET"(%5), %%"REG_b"        \n\t"
1575             :: "c" (buf0), "d" (buf1), "S" (ubuf0), "D" (ubuf1), "m" (dest),
1576                "a" (&c->redDither), "m"(uv_off)
1577         );
1578     } else {
1579         __asm__ volatile(
1580             "mov %%"REG_b", "ESP_OFFSET"(%5)        \n\t"
1581             "mov        %4, %%"REG_b"               \n\t"
1582             "push %%"REG_BP"                        \n\t"
1583             YSCALEYUV2PACKED1b(%%REGBP, %5, %6)
1584             WRITEYUY2(%%REGb, 8280(%5), %%REGBP)
1585             "pop %%"REG_BP"                         \n\t"
1586             "mov "ESP_OFFSET"(%5), %%"REG_b"        \n\t"
1587             :: "c" (buf0), "d" (buf1), "S" (ubuf0), "D" (ubuf1), "m" (dest),
1588                "a" (&c->redDither), "m"(uv_off)
1589         );
1590     }
1591 }
1592
1593 #if !COMPILE_TEMPLATE_MMX2
1594 //FIXME yuy2* can read up to 7 samples too much
1595
1596 static inline void RENAME(yuy2ToY)(uint8_t *dst, const uint8_t *src, long width, uint32_t *unused)
1597 {
1598     __asm__ volatile(
1599         "movq "MANGLE(bm01010101)", %%mm2           \n\t"
1600         "mov                    %0, %%"REG_a"       \n\t"
1601         "1:                                         \n\t"
1602         "movq    (%1, %%"REG_a",2), %%mm0           \n\t"
1603         "movq   8(%1, %%"REG_a",2), %%mm1           \n\t"
1604         "pand                %%mm2, %%mm0           \n\t"
1605         "pand                %%mm2, %%mm1           \n\t"
1606         "packuswb            %%mm1, %%mm0           \n\t"
1607         "movq                %%mm0, (%2, %%"REG_a") \n\t"
1608         "add                    $8, %%"REG_a"       \n\t"
1609         " js                    1b                  \n\t"
1610         : : "g" ((x86_reg)-width), "r" (src+width*2), "r" (dst+width)
1611         : "%"REG_a
1612     );
1613 }
1614
1615 static inline void RENAME(yuy2ToUV)(uint8_t *dstU, uint8_t *dstV, const uint8_t *src1, const uint8_t *src2, long width, uint32_t *unused)
1616 {
1617     __asm__ volatile(
1618         "movq "MANGLE(bm01010101)", %%mm4           \n\t"
1619         "mov                    %0, %%"REG_a"       \n\t"
1620         "1:                                         \n\t"
1621         "movq    (%1, %%"REG_a",4), %%mm0           \n\t"
1622         "movq   8(%1, %%"REG_a",4), %%mm1           \n\t"
1623         "psrlw                  $8, %%mm0           \n\t"
1624         "psrlw                  $8, %%mm1           \n\t"
1625         "packuswb            %%mm1, %%mm0           \n\t"
1626         "movq                %%mm0, %%mm1           \n\t"
1627         "psrlw                  $8, %%mm0           \n\t"
1628         "pand                %%mm4, %%mm1           \n\t"
1629         "packuswb            %%mm0, %%mm0           \n\t"
1630         "packuswb            %%mm1, %%mm1           \n\t"
1631         "movd                %%mm0, (%3, %%"REG_a") \n\t"
1632         "movd                %%mm1, (%2, %%"REG_a") \n\t"
1633         "add                    $4, %%"REG_a"       \n\t"
1634         " js                    1b                  \n\t"
1635         : : "g" ((x86_reg)-width), "r" (src1+width*4), "r" (dstU+width), "r" (dstV+width)
1636         : "%"REG_a
1637     );
1638     assert(src1 == src2);
1639 }
1640
1641 static inline void RENAME(LEToUV)(uint8_t *dstU, uint8_t *dstV, const uint8_t *src1, const uint8_t *src2, long width, uint32_t *unused)
1642 {
1643     __asm__ volatile(
1644         "mov                    %0, %%"REG_a"       \n\t"
1645         "1:                                         \n\t"
1646         "movq    (%1, %%"REG_a",2), %%mm0           \n\t"
1647         "movq   8(%1, %%"REG_a",2), %%mm1           \n\t"
1648         "movq    (%2, %%"REG_a",2), %%mm2           \n\t"
1649         "movq   8(%2, %%"REG_a",2), %%mm3           \n\t"
1650         "psrlw                  $8, %%mm0           \n\t"
1651         "psrlw                  $8, %%mm1           \n\t"
1652         "psrlw                  $8, %%mm2           \n\t"
1653         "psrlw                  $8, %%mm3           \n\t"
1654         "packuswb            %%mm1, %%mm0           \n\t"
1655         "packuswb            %%mm3, %%mm2           \n\t"
1656         "movq                %%mm0, (%3, %%"REG_a") \n\t"
1657         "movq                %%mm2, (%4, %%"REG_a") \n\t"
1658         "add                    $8, %%"REG_a"       \n\t"
1659         " js                    1b                  \n\t"
1660         : : "g" ((x86_reg)-width), "r" (src1+width*2), "r" (src2+width*2), "r" (dstU+width), "r" (dstV+width)
1661         : "%"REG_a
1662     );
1663 }
1664
1665 /* This is almost identical to the previous, end exists only because
1666  * yuy2ToY/UV)(dst, src+1, ...) would have 100% unaligned accesses. */
1667 static inline void RENAME(uyvyToY)(uint8_t *dst, const uint8_t *src, long width, uint32_t *unused)
1668 {
1669     __asm__ volatile(
1670         "mov                  %0, %%"REG_a"         \n\t"
1671         "1:                                         \n\t"
1672         "movq  (%1, %%"REG_a",2), %%mm0             \n\t"
1673         "movq 8(%1, %%"REG_a",2), %%mm1             \n\t"
1674         "psrlw                $8, %%mm0             \n\t"
1675         "psrlw                $8, %%mm1             \n\t"
1676         "packuswb          %%mm1, %%mm0             \n\t"
1677         "movq              %%mm0, (%2, %%"REG_a")   \n\t"
1678         "add                  $8, %%"REG_a"         \n\t"
1679         " js                  1b                    \n\t"
1680         : : "g" ((x86_reg)-width), "r" (src+width*2), "r" (dst+width)
1681         : "%"REG_a
1682     );
1683 }
1684
1685 static inline void RENAME(uyvyToUV)(uint8_t *dstU, uint8_t *dstV, const uint8_t *src1, const uint8_t *src2, long width, uint32_t *unused)
1686 {
1687     __asm__ volatile(
1688         "movq "MANGLE(bm01010101)", %%mm4           \n\t"
1689         "mov                    %0, %%"REG_a"       \n\t"
1690         "1:                                         \n\t"
1691         "movq    (%1, %%"REG_a",4), %%mm0           \n\t"
1692         "movq   8(%1, %%"REG_a",4), %%mm1           \n\t"
1693         "pand                %%mm4, %%mm0           \n\t"
1694         "pand                %%mm4, %%mm1           \n\t"
1695         "packuswb            %%mm1, %%mm0           \n\t"
1696         "movq                %%mm0, %%mm1           \n\t"
1697         "psrlw                  $8, %%mm0           \n\t"
1698         "pand                %%mm4, %%mm1           \n\t"
1699         "packuswb            %%mm0, %%mm0           \n\t"
1700         "packuswb            %%mm1, %%mm1           \n\t"
1701         "movd                %%mm0, (%3, %%"REG_a") \n\t"
1702         "movd                %%mm1, (%2, %%"REG_a") \n\t"
1703         "add                    $4, %%"REG_a"       \n\t"
1704         " js                    1b                  \n\t"
1705         : : "g" ((x86_reg)-width), "r" (src1+width*4), "r" (dstU+width), "r" (dstV+width)
1706         : "%"REG_a
1707     );
1708     assert(src1 == src2);
1709 }
1710
1711 static inline void RENAME(BEToUV)(uint8_t *dstU, uint8_t *dstV, const uint8_t *src1, const uint8_t *src2, long width, uint32_t *unused)
1712 {
1713     __asm__ volatile(
1714         "movq "MANGLE(bm01010101)", %%mm4           \n\t"
1715         "mov                    %0, %%"REG_a"       \n\t"
1716         "1:                                         \n\t"
1717         "movq    (%1, %%"REG_a",2), %%mm0           \n\t"
1718         "movq   8(%1, %%"REG_a",2), %%mm1           \n\t"
1719         "movq    (%2, %%"REG_a",2), %%mm2           \n\t"
1720         "movq   8(%2, %%"REG_a",2), %%mm3           \n\t"
1721         "pand                %%mm4, %%mm0           \n\t"
1722         "pand                %%mm4, %%mm1           \n\t"
1723         "pand                %%mm4, %%mm2           \n\t"
1724         "pand                %%mm4, %%mm3           \n\t"
1725         "packuswb            %%mm1, %%mm0           \n\t"
1726         "packuswb            %%mm3, %%mm2           \n\t"
1727         "movq                %%mm0, (%3, %%"REG_a") \n\t"
1728         "movq                %%mm2, (%4, %%"REG_a") \n\t"
1729         "add                    $8, %%"REG_a"       \n\t"
1730         " js                    1b                  \n\t"
1731         : : "g" ((x86_reg)-width), "r" (src1+width*2), "r" (src2+width*2), "r" (dstU+width), "r" (dstV+width)
1732         : "%"REG_a
1733     );
1734 }
1735
1736 static inline void RENAME(nvXXtoUV)(uint8_t *dst1, uint8_t *dst2,
1737                                     const uint8_t *src, long width)
1738 {
1739     __asm__ volatile(
1740         "movq "MANGLE(bm01010101)", %%mm4           \n\t"
1741         "mov                    %0, %%"REG_a"       \n\t"
1742         "1:                                         \n\t"
1743         "movq    (%1, %%"REG_a",2), %%mm0           \n\t"
1744         "movq   8(%1, %%"REG_a",2), %%mm1           \n\t"
1745         "movq                %%mm0, %%mm2           \n\t"
1746         "movq                %%mm1, %%mm3           \n\t"
1747         "pand                %%mm4, %%mm0           \n\t"
1748         "pand                %%mm4, %%mm1           \n\t"
1749         "psrlw                  $8, %%mm2           \n\t"
1750         "psrlw                  $8, %%mm3           \n\t"
1751         "packuswb            %%mm1, %%mm0           \n\t"
1752         "packuswb            %%mm3, %%mm2           \n\t"
1753         "movq                %%mm0, (%2, %%"REG_a") \n\t"
1754         "movq                %%mm2, (%3, %%"REG_a") \n\t"
1755         "add                    $8, %%"REG_a"       \n\t"
1756         " js                    1b                  \n\t"
1757         : : "g" ((x86_reg)-width), "r" (src+width*2), "r" (dst1+width), "r" (dst2+width)
1758         : "%"REG_a
1759     );
1760 }
1761
1762 static inline void RENAME(nv12ToUV)(uint8_t *dstU, uint8_t *dstV,
1763                                     const uint8_t *src1, const uint8_t *src2,
1764                                     long width, uint32_t *unused)
1765 {
1766     RENAME(nvXXtoUV)(dstU, dstV, src1, width);
1767 }
1768
1769 static inline void RENAME(nv21ToUV)(uint8_t *dstU, uint8_t *dstV,
1770                                     const uint8_t *src1, const uint8_t *src2,
1771                                     long width, uint32_t *unused)
1772 {
1773     RENAME(nvXXtoUV)(dstV, dstU, src1, width);
1774 }
1775 #endif /* !COMPILE_TEMPLATE_MMX2 */
1776
1777 static inline void RENAME(bgr24ToY_mmx)(uint8_t *dst, const uint8_t *src, long width, enum PixelFormat srcFormat)
1778 {
1779
1780     if(srcFormat == PIX_FMT_BGR24) {
1781         __asm__ volatile(
1782             "movq  "MANGLE(ff_bgr24toY1Coeff)", %%mm5       \n\t"
1783             "movq  "MANGLE(ff_bgr24toY2Coeff)", %%mm6       \n\t"
1784             :
1785         );
1786     } else {
1787         __asm__ volatile(
1788             "movq  "MANGLE(ff_rgb24toY1Coeff)", %%mm5       \n\t"
1789             "movq  "MANGLE(ff_rgb24toY2Coeff)", %%mm6       \n\t"
1790             :
1791         );
1792     }
1793
1794     __asm__ volatile(
1795         "movq  "MANGLE(ff_bgr24toYOffset)", %%mm4   \n\t"
1796         "mov                        %2, %%"REG_a"   \n\t"
1797         "pxor                    %%mm7, %%mm7       \n\t"
1798         "1:                                         \n\t"
1799         PREFETCH"               64(%0)              \n\t"
1800         "movd                     (%0), %%mm0       \n\t"
1801         "movd                    2(%0), %%mm1       \n\t"
1802         "movd                    6(%0), %%mm2       \n\t"
1803         "movd                    8(%0), %%mm3       \n\t"
1804         "add                       $12, %0          \n\t"
1805         "punpcklbw               %%mm7, %%mm0       \n\t"
1806         "punpcklbw               %%mm7, %%mm1       \n\t"
1807         "punpcklbw               %%mm7, %%mm2       \n\t"
1808         "punpcklbw               %%mm7, %%mm3       \n\t"
1809         "pmaddwd                 %%mm5, %%mm0       \n\t"
1810         "pmaddwd                 %%mm6, %%mm1       \n\t"
1811         "pmaddwd                 %%mm5, %%mm2       \n\t"
1812         "pmaddwd                 %%mm6, %%mm3       \n\t"
1813         "paddd                   %%mm1, %%mm0       \n\t"
1814         "paddd                   %%mm3, %%mm2       \n\t"
1815         "paddd                   %%mm4, %%mm0       \n\t"
1816         "paddd                   %%mm4, %%mm2       \n\t"
1817         "psrad                     $15, %%mm0       \n\t"
1818         "psrad                     $15, %%mm2       \n\t"
1819         "packssdw                %%mm2, %%mm0       \n\t"
1820         "packuswb                %%mm0, %%mm0       \n\t"
1821         "movd                %%mm0, (%1, %%"REG_a") \n\t"
1822         "add                        $4, %%"REG_a"   \n\t"
1823         " js                        1b              \n\t"
1824     : "+r" (src)
1825     : "r" (dst+width), "g" ((x86_reg)-width)
1826     : "%"REG_a
1827     );
1828 }
1829
1830 static inline void RENAME(bgr24ToUV_mmx)(uint8_t *dstU, uint8_t *dstV, const uint8_t *src, long width, enum PixelFormat srcFormat)
1831 {
1832     __asm__ volatile(
1833         "movq                    24(%4), %%mm6       \n\t"
1834         "mov                        %3, %%"REG_a"   \n\t"
1835         "pxor                    %%mm7, %%mm7       \n\t"
1836         "1:                                         \n\t"
1837         PREFETCH"               64(%0)              \n\t"
1838         "movd                     (%0), %%mm0       \n\t"
1839         "movd                    2(%0), %%mm1       \n\t"
1840         "punpcklbw               %%mm7, %%mm0       \n\t"
1841         "punpcklbw               %%mm7, %%mm1       \n\t"
1842         "movq                    %%mm0, %%mm2       \n\t"
1843         "movq                    %%mm1, %%mm3       \n\t"
1844         "pmaddwd                  (%4), %%mm0       \n\t"
1845         "pmaddwd                 8(%4), %%mm1       \n\t"
1846         "pmaddwd                16(%4), %%mm2       \n\t"
1847         "pmaddwd                 %%mm6, %%mm3       \n\t"
1848         "paddd                   %%mm1, %%mm0       \n\t"
1849         "paddd                   %%mm3, %%mm2       \n\t"
1850
1851         "movd                    6(%0), %%mm1       \n\t"
1852         "movd                    8(%0), %%mm3       \n\t"
1853         "add                       $12, %0          \n\t"
1854         "punpcklbw               %%mm7, %%mm1       \n\t"
1855         "punpcklbw               %%mm7, %%mm3       \n\t"
1856         "movq                    %%mm1, %%mm4       \n\t"
1857         "movq                    %%mm3, %%mm5       \n\t"
1858         "pmaddwd                  (%4), %%mm1       \n\t"
1859         "pmaddwd                 8(%4), %%mm3       \n\t"
1860         "pmaddwd                16(%4), %%mm4       \n\t"
1861         "pmaddwd                 %%mm6, %%mm5       \n\t"
1862         "paddd                   %%mm3, %%mm1       \n\t"
1863         "paddd                   %%mm5, %%mm4       \n\t"
1864
1865         "movq "MANGLE(ff_bgr24toUVOffset)", %%mm3       \n\t"
1866         "paddd                   %%mm3, %%mm0       \n\t"
1867         "paddd                   %%mm3, %%mm2       \n\t"
1868         "paddd                   %%mm3, %%mm1       \n\t"
1869         "paddd                   %%mm3, %%mm4       \n\t"
1870         "psrad                     $15, %%mm0       \n\t"
1871         "psrad                     $15, %%mm2       \n\t"
1872         "psrad                     $15, %%mm1       \n\t"
1873         "psrad                     $15, %%mm4       \n\t"
1874         "packssdw                %%mm1, %%mm0       \n\t"
1875         "packssdw                %%mm4, %%mm2       \n\t"
1876         "packuswb                %%mm0, %%mm0       \n\t"
1877         "packuswb                %%mm2, %%mm2       \n\t"
1878         "movd                %%mm0, (%1, %%"REG_a") \n\t"
1879         "movd                %%mm2, (%2, %%"REG_a") \n\t"
1880         "add                        $4, %%"REG_a"   \n\t"
1881         " js                        1b              \n\t"
1882     : "+r" (src)
1883     : "r" (dstU+width), "r" (dstV+width), "g" ((x86_reg)-width), "r"(ff_bgr24toUV[srcFormat == PIX_FMT_RGB24])
1884     : "%"REG_a
1885     );
1886 }
1887
1888 static inline void RENAME(bgr24ToY)(uint8_t *dst, const uint8_t *src, long width, uint32_t *unused)
1889 {
1890     RENAME(bgr24ToY_mmx)(dst, src, width, PIX_FMT_BGR24);
1891 }
1892
1893 static inline void RENAME(bgr24ToUV)(uint8_t *dstU, uint8_t *dstV, const uint8_t *src1, const uint8_t *src2, long width, uint32_t *unused)
1894 {
1895     RENAME(bgr24ToUV_mmx)(dstU, dstV, src1, width, PIX_FMT_BGR24);
1896     assert(src1 == src2);
1897 }
1898
1899 static inline void RENAME(rgb24ToY)(uint8_t *dst, const uint8_t *src, long width, uint32_t *unused)
1900 {
1901     RENAME(bgr24ToY_mmx)(dst, src, width, PIX_FMT_RGB24);
1902 }
1903
1904 static inline void RENAME(rgb24ToUV)(uint8_t *dstU, uint8_t *dstV, const uint8_t *src1, const uint8_t *src2, long width, uint32_t *unused)
1905 {
1906     assert(src1==src2);
1907     RENAME(bgr24ToUV_mmx)(dstU, dstV, src1, width, PIX_FMT_RGB24);
1908 }
1909
1910 #if !COMPILE_TEMPLATE_MMX2
1911 // bilinear / bicubic scaling
1912 static inline void RENAME(hScale)(int16_t *dst, int dstW, const uint8_t *src, int srcW, int xInc,
1913                                   const int16_t *filter, const int16_t *filterPos, long filterSize)
1914 {
1915     assert(filterSize % 4 == 0 && filterSize>0);
1916     if (filterSize==4) { // Always true for upscaling, sometimes for down, too.
1917         x86_reg counter= -2*dstW;
1918         filter-= counter*2;
1919         filterPos-= counter/2;
1920         dst-= counter/2;
1921         __asm__ volatile(
1922 #if defined(PIC)
1923             "push            %%"REG_b"              \n\t"
1924 #endif
1925             "pxor                %%mm7, %%mm7       \n\t"
1926             "push           %%"REG_BP"              \n\t" // we use 7 regs here ...
1927             "mov             %%"REG_a", %%"REG_BP"  \n\t"
1928             ".p2align                4              \n\t"
1929             "1:                                     \n\t"
1930             "movzwl   (%2, %%"REG_BP"), %%eax       \n\t"
1931             "movzwl  2(%2, %%"REG_BP"), %%ebx       \n\t"
1932             "movq  (%1, %%"REG_BP", 4), %%mm1       \n\t"
1933             "movq 8(%1, %%"REG_BP", 4), %%mm3       \n\t"
1934             "movd      (%3, %%"REG_a"), %%mm0       \n\t"
1935             "movd      (%3, %%"REG_b"), %%mm2       \n\t"
1936             "punpcklbw           %%mm7, %%mm0       \n\t"
1937             "punpcklbw           %%mm7, %%mm2       \n\t"
1938             "pmaddwd             %%mm1, %%mm0       \n\t"
1939             "pmaddwd             %%mm2, %%mm3       \n\t"
1940             "movq                %%mm0, %%mm4       \n\t"
1941             "punpckldq           %%mm3, %%mm0       \n\t"
1942             "punpckhdq           %%mm3, %%mm4       \n\t"
1943             "paddd               %%mm4, %%mm0       \n\t"
1944             "psrad                  $7, %%mm0       \n\t"
1945             "packssdw            %%mm0, %%mm0       \n\t"
1946             "movd                %%mm0, (%4, %%"REG_BP")    \n\t"
1947             "add                    $4, %%"REG_BP"  \n\t"
1948             " jnc                   1b              \n\t"
1949
1950             "pop            %%"REG_BP"              \n\t"
1951 #if defined(PIC)
1952             "pop             %%"REG_b"              \n\t"
1953 #endif
1954             : "+a" (counter)
1955             : "c" (filter), "d" (filterPos), "S" (src), "D" (dst)
1956 #if !defined(PIC)
1957             : "%"REG_b
1958 #endif
1959         );
1960     } else if (filterSize==8) {
1961         x86_reg counter= -2*dstW;
1962         filter-= counter*4;
1963         filterPos-= counter/2;
1964         dst-= counter/2;
1965         __asm__ volatile(
1966 #if defined(PIC)
1967             "push             %%"REG_b"             \n\t"
1968 #endif
1969             "pxor                 %%mm7, %%mm7      \n\t"
1970             "push            %%"REG_BP"             \n\t" // we use 7 regs here ...
1971             "mov              %%"REG_a", %%"REG_BP" \n\t"
1972             ".p2align                 4             \n\t"
1973             "1:                                     \n\t"
1974             "movzwl    (%2, %%"REG_BP"), %%eax      \n\t"
1975             "movzwl   2(%2, %%"REG_BP"), %%ebx      \n\t"
1976             "movq   (%1, %%"REG_BP", 8), %%mm1      \n\t"
1977             "movq 16(%1, %%"REG_BP", 8), %%mm3      \n\t"
1978             "movd       (%3, %%"REG_a"), %%mm0      \n\t"
1979             "movd       (%3, %%"REG_b"), %%mm2      \n\t"
1980             "punpcklbw            %%mm7, %%mm0      \n\t"
1981             "punpcklbw            %%mm7, %%mm2      \n\t"
1982             "pmaddwd              %%mm1, %%mm0      \n\t"
1983             "pmaddwd              %%mm2, %%mm3      \n\t"
1984
1985             "movq  8(%1, %%"REG_BP", 8), %%mm1      \n\t"
1986             "movq 24(%1, %%"REG_BP", 8), %%mm5      \n\t"
1987             "movd      4(%3, %%"REG_a"), %%mm4      \n\t"
1988             "movd      4(%3, %%"REG_b"), %%mm2      \n\t"
1989             "punpcklbw            %%mm7, %%mm4      \n\t"
1990             "punpcklbw            %%mm7, %%mm2      \n\t"
1991             "pmaddwd              %%mm1, %%mm4      \n\t"
1992             "pmaddwd              %%mm2, %%mm5      \n\t"
1993             "paddd                %%mm4, %%mm0      \n\t"
1994             "paddd                %%mm5, %%mm3      \n\t"
1995             "movq                 %%mm0, %%mm4      \n\t"
1996             "punpckldq            %%mm3, %%mm0      \n\t"
1997             "punpckhdq            %%mm3, %%mm4      \n\t"
1998             "paddd                %%mm4, %%mm0      \n\t"
1999             "psrad                   $7, %%mm0      \n\t"
2000             "packssdw             %%mm0, %%mm0      \n\t"
2001             "movd                 %%mm0, (%4, %%"REG_BP")   \n\t"
2002             "add                     $4, %%"REG_BP" \n\t"
2003             " jnc                    1b             \n\t"
2004
2005             "pop             %%"REG_BP"             \n\t"
2006 #if defined(PIC)
2007             "pop              %%"REG_b"             \n\t"
2008 #endif
2009             : "+a" (counter)
2010             : "c" (filter), "d" (filterPos), "S" (src), "D" (dst)
2011 #if !defined(PIC)
2012             : "%"REG_b
2013 #endif
2014         );
2015     } else {
2016         const uint8_t *offset = src+filterSize;
2017         x86_reg counter= -2*dstW;
2018         //filter-= counter*filterSize/2;
2019         filterPos-= counter/2;
2020         dst-= counter/2;
2021         __asm__ volatile(
2022             "pxor                  %%mm7, %%mm7     \n\t"
2023             ".p2align                  4            \n\t"
2024             "1:                                     \n\t"
2025             "mov                      %2, %%"REG_c" \n\t"
2026             "movzwl      (%%"REG_c", %0), %%eax     \n\t"
2027             "movzwl     2(%%"REG_c", %0), %%edx     \n\t"
2028             "mov                      %5, %%"REG_c" \n\t"
2029             "pxor                  %%mm4, %%mm4     \n\t"
2030             "pxor                  %%mm5, %%mm5     \n\t"
2031             "2:                                     \n\t"
2032             "movq                   (%1), %%mm1     \n\t"
2033             "movq               (%1, %6), %%mm3     \n\t"
2034             "movd (%%"REG_c", %%"REG_a"), %%mm0     \n\t"
2035             "movd (%%"REG_c", %%"REG_d"), %%mm2     \n\t"
2036             "punpcklbw             %%mm7, %%mm0     \n\t"
2037             "punpcklbw             %%mm7, %%mm2     \n\t"
2038             "pmaddwd               %%mm1, %%mm0     \n\t"
2039             "pmaddwd               %%mm2, %%mm3     \n\t"
2040             "paddd                 %%mm3, %%mm5     \n\t"
2041             "paddd                 %%mm0, %%mm4     \n\t"
2042             "add                      $8, %1        \n\t"
2043             "add                      $4, %%"REG_c" \n\t"
2044             "cmp                      %4, %%"REG_c" \n\t"
2045             " jb                      2b            \n\t"
2046             "add                      %6, %1        \n\t"
2047             "movq                  %%mm4, %%mm0     \n\t"
2048             "punpckldq             %%mm5, %%mm4     \n\t"
2049             "punpckhdq             %%mm5, %%mm0     \n\t"
2050             "paddd                 %%mm0, %%mm4     \n\t"
2051             "psrad                    $7, %%mm4     \n\t"
2052             "packssdw              %%mm4, %%mm4     \n\t"
2053             "mov                      %3, %%"REG_a" \n\t"
2054             "movd                  %%mm4, (%%"REG_a", %0)   \n\t"
2055             "add                      $4, %0        \n\t"
2056             " jnc                     1b            \n\t"
2057
2058             : "+r" (counter), "+r" (filter)
2059             : "m" (filterPos), "m" (dst), "m"(offset),
2060             "m" (src), "r" ((x86_reg)filterSize*2)
2061             : "%"REG_a, "%"REG_c, "%"REG_d
2062         );
2063     }
2064 }
2065 #endif /* !COMPILE_TEMPLATE_MMX2 */
2066
2067 #if COMPILE_TEMPLATE_MMX2
2068 static inline void RENAME(hyscale_fast)(SwsContext *c, int16_t *dst,
2069                                         long dstWidth, const uint8_t *src, int srcW,
2070                                         int xInc)
2071 {
2072     int32_t *filterPos = c->hLumFilterPos;
2073     int16_t *filter    = c->hLumFilter;
2074     void    *mmx2FilterCode= c->lumMmx2FilterCode;
2075     int i;
2076 #if defined(PIC)
2077     DECLARE_ALIGNED(8, uint64_t, ebxsave);
2078 #endif
2079
2080     __asm__ volatile(
2081 #if defined(PIC)
2082         "mov               %%"REG_b", %5        \n\t"
2083 #endif
2084         "pxor                  %%mm7, %%mm7     \n\t"
2085         "mov                      %0, %%"REG_c" \n\t"
2086         "mov                      %1, %%"REG_D" \n\t"
2087         "mov                      %2, %%"REG_d" \n\t"
2088         "mov                      %3, %%"REG_b" \n\t"
2089         "xor               %%"REG_a", %%"REG_a" \n\t" // i
2090         PREFETCH"        (%%"REG_c")            \n\t"
2091         PREFETCH"      32(%%"REG_c")            \n\t"
2092         PREFETCH"      64(%%"REG_c")            \n\t"
2093
2094 #if ARCH_X86_64
2095 #define CALL_MMX2_FILTER_CODE \
2096         "movl            (%%"REG_b"), %%esi     \n\t"\
2097         "call                    *%4            \n\t"\
2098         "movl (%%"REG_b", %%"REG_a"), %%esi     \n\t"\
2099         "add               %%"REG_S", %%"REG_c" \n\t"\
2100         "add               %%"REG_a", %%"REG_D" \n\t"\
2101         "xor               %%"REG_a", %%"REG_a" \n\t"\
2102
2103 #else
2104 #define CALL_MMX2_FILTER_CODE \
2105         "movl (%%"REG_b"), %%esi        \n\t"\
2106         "call         *%4                       \n\t"\
2107         "addl (%%"REG_b", %%"REG_a"), %%"REG_c" \n\t"\
2108         "add               %%"REG_a", %%"REG_D" \n\t"\
2109         "xor               %%"REG_a", %%"REG_a" \n\t"\
2110
2111 #endif /* ARCH_X86_64 */
2112
2113         CALL_MMX2_FILTER_CODE
2114         CALL_MMX2_FILTER_CODE
2115         CALL_MMX2_FILTER_CODE
2116         CALL_MMX2_FILTER_CODE
2117         CALL_MMX2_FILTER_CODE
2118         CALL_MMX2_FILTER_CODE
2119         CALL_MMX2_FILTER_CODE
2120         CALL_MMX2_FILTER_CODE
2121
2122 #if defined(PIC)
2123         "mov                      %5, %%"REG_b" \n\t"
2124 #endif
2125         :: "m" (src), "m" (dst), "m" (filter), "m" (filterPos),
2126            "m" (mmx2FilterCode)
2127 #if defined(PIC)
2128           ,"m" (ebxsave)
2129 #endif
2130         : "%"REG_a, "%"REG_c, "%"REG_d, "%"REG_S, "%"REG_D
2131 #if !defined(PIC)
2132          ,"%"REG_b
2133 #endif
2134     );
2135
2136     for (i=dstWidth-1; (i*xInc)>>16 >=srcW-1; i--)
2137         dst[i] = src[srcW-1]*128;
2138 }
2139
2140 static inline void RENAME(hcscale_fast)(SwsContext *c, int16_t *dst1, int16_t *dst2,
2141                                         long dstWidth, const uint8_t *src1,
2142                                         const uint8_t *src2, int srcW, int xInc)
2143 {
2144     int32_t *filterPos = c->hChrFilterPos;
2145     int16_t *filter    = c->hChrFilter;
2146     void    *mmx2FilterCode= c->chrMmx2FilterCode;
2147     int i;
2148 #if defined(PIC)
2149     DECLARE_ALIGNED(8, uint64_t, ebxsave);
2150 #endif
2151
2152     __asm__ volatile(
2153 #if defined(PIC)
2154         "mov          %%"REG_b", %7         \n\t"
2155 #endif
2156         "pxor             %%mm7, %%mm7      \n\t"
2157         "mov                 %0, %%"REG_c"  \n\t"
2158         "mov                 %1, %%"REG_D"  \n\t"
2159         "mov                 %2, %%"REG_d"  \n\t"
2160         "mov                 %3, %%"REG_b"  \n\t"
2161         "xor          %%"REG_a", %%"REG_a"  \n\t" // i
2162         PREFETCH"   (%%"REG_c")             \n\t"
2163         PREFETCH" 32(%%"REG_c")             \n\t"
2164         PREFETCH" 64(%%"REG_c")             \n\t"
2165
2166         CALL_MMX2_FILTER_CODE
2167         CALL_MMX2_FILTER_CODE
2168         CALL_MMX2_FILTER_CODE
2169         CALL_MMX2_FILTER_CODE
2170         "xor          %%"REG_a", %%"REG_a"  \n\t" // i
2171         "mov                 %5, %%"REG_c"  \n\t" // src
2172         "mov                 %6, %%"REG_D"  \n\t" // buf2
2173         PREFETCH"   (%%"REG_c")             \n\t"
2174         PREFETCH" 32(%%"REG_c")             \n\t"
2175         PREFETCH" 64(%%"REG_c")             \n\t"
2176
2177         CALL_MMX2_FILTER_CODE
2178         CALL_MMX2_FILTER_CODE
2179         CALL_MMX2_FILTER_CODE
2180         CALL_MMX2_FILTER_CODE
2181
2182 #if defined(PIC)
2183         "mov %7, %%"REG_b"    \n\t"
2184 #endif
2185         :: "m" (src1), "m" (dst1), "m" (filter), "m" (filterPos),
2186            "m" (mmx2FilterCode), "m" (src2), "m"(dst2)
2187 #if defined(PIC)
2188           ,"m" (ebxsave)
2189 #endif
2190         : "%"REG_a, "%"REG_c, "%"REG_d, "%"REG_S, "%"REG_D
2191 #if !defined(PIC)
2192          ,"%"REG_b
2193 #endif
2194     );
2195
2196     for (i=dstWidth-1; (i*xInc)>>16 >=srcW-1; i--) {
2197         dst1[i] = src1[srcW-1]*128;
2198         dst2[i] = src2[srcW-1]*128;
2199     }
2200 }
2201 #endif /* COMPILE_TEMPLATE_MMX2 */
2202
2203 #if !COMPILE_TEMPLATE_MMX2
2204 static void updateMMXDitherTables(SwsContext *c, int dstY, int lumBufIndex, int chrBufIndex,
2205                                   int lastInLumBuf, int lastInChrBuf)
2206 {
2207     const int dstH= c->dstH;
2208     const int flags= c->flags;
2209     int16_t **lumPixBuf= c->lumPixBuf;
2210     int16_t **chrUPixBuf= c->chrUPixBuf;
2211     int16_t **alpPixBuf= c->alpPixBuf;
2212     const int vLumBufSize= c->vLumBufSize;
2213     const int vChrBufSize= c->vChrBufSize;
2214     int16_t *vLumFilterPos= c->vLumFilterPos;
2215     int16_t *vChrFilterPos= c->vChrFilterPos;
2216     int16_t *vLumFilter= c->vLumFilter;
2217     int16_t *vChrFilter= c->vChrFilter;
2218     int32_t *lumMmxFilter= c->lumMmxFilter;
2219     int32_t *chrMmxFilter= c->chrMmxFilter;
2220     int32_t av_unused *alpMmxFilter= c->alpMmxFilter;
2221     const int vLumFilterSize= c->vLumFilterSize;
2222     const int vChrFilterSize= c->vChrFilterSize;
2223     const int chrDstY= dstY>>c->chrDstVSubSample;
2224     const int firstLumSrcY= vLumFilterPos[dstY]; //First line needed as input
2225     const int firstChrSrcY= vChrFilterPos[chrDstY]; //First line needed as input
2226
2227     c->blueDither= ff_dither8[dstY&1];
2228     if (c->dstFormat == PIX_FMT_RGB555 || c->dstFormat == PIX_FMT_BGR555)
2229         c->greenDither= ff_dither8[dstY&1];
2230     else
2231         c->greenDither= ff_dither4[dstY&1];
2232     c->redDither= ff_dither8[(dstY+1)&1];
2233     if (dstY < dstH - 2) {
2234         const int16_t **lumSrcPtr= (const int16_t **) lumPixBuf + lumBufIndex + firstLumSrcY - lastInLumBuf + vLumBufSize;
2235         const int16_t **chrUSrcPtr= (const int16_t **) chrUPixBuf + chrBufIndex + firstChrSrcY - lastInChrBuf + vChrBufSize;
2236         const int16_t **alpSrcPtr= (CONFIG_SWSCALE_ALPHA && alpPixBuf) ? (const int16_t **) alpPixBuf + lumBufIndex + firstLumSrcY - lastInLumBuf + vLumBufSize : NULL;
2237         int i;
2238         if (flags & SWS_ACCURATE_RND) {
2239             int s= APCK_SIZE / 8;
2240             for (i=0; i<vLumFilterSize; i+=2) {
2241                 *(const void**)&lumMmxFilter[s*i              ]= lumSrcPtr[i  ];
2242                 *(const void**)&lumMmxFilter[s*i+APCK_PTR2/4  ]= lumSrcPtr[i+(vLumFilterSize>1)];
2243                 lumMmxFilter[s*i+APCK_COEF/4  ]=
2244                 lumMmxFilter[s*i+APCK_COEF/4+1]= vLumFilter[dstY*vLumFilterSize + i    ]
2245                            + (vLumFilterSize>1 ? vLumFilter[dstY*vLumFilterSize + i + 1]<<16 : 0);
2246                 if (CONFIG_SWSCALE_ALPHA && alpPixBuf) {
2247                     *(const void**)&alpMmxFilter[s*i              ]= alpSrcPtr[i  ];
2248                     *(const void**)&alpMmxFilter[s*i+APCK_PTR2/4  ]= alpSrcPtr[i+(vLumFilterSize>1)];
2249                     alpMmxFilter[s*i+APCK_COEF/4  ]=
2250                     alpMmxFilter[s*i+APCK_COEF/4+1]= lumMmxFilter[s*i+APCK_COEF/4  ];
2251                 }
2252             }
2253             for (i=0; i<vChrFilterSize; i+=2) {
2254                 *(const void**)&chrMmxFilter[s*i              ]= chrUSrcPtr[i  ];
2255                 *(const void**)&chrMmxFilter[s*i+APCK_PTR2/4  ]= chrUSrcPtr[i+(vChrFilterSize>1)];
2256                 chrMmxFilter[s*i+APCK_COEF/4  ]=
2257                 chrMmxFilter[s*i+APCK_COEF/4+1]= vChrFilter[chrDstY*vChrFilterSize + i    ]
2258                            + (vChrFilterSize>1 ? vChrFilter[chrDstY*vChrFilterSize + i + 1]<<16 : 0);
2259             }
2260         } else {
2261             for (i=0; i<vLumFilterSize; i++) {
2262                 *(const void**)&lumMmxFilter[4*i+0]= lumSrcPtr[i];
2263                 lumMmxFilter[4*i+2]=
2264                 lumMmxFilter[4*i+3]=
2265                     ((uint16_t)vLumFilter[dstY*vLumFilterSize + i])*0x10001;
2266                 if (CONFIG_SWSCALE_ALPHA && alpPixBuf) {
2267                     *(const void**)&alpMmxFilter[4*i+0]= alpSrcPtr[i];
2268                     alpMmxFilter[4*i+2]=
2269                     alpMmxFilter[4*i+3]= lumMmxFilter[4*i+2];
2270                 }
2271             }
2272             for (i=0; i<vChrFilterSize; i++) {
2273                 *(const void**)&chrMmxFilter[4*i+0]= chrUSrcPtr[i];
2274                 chrMmxFilter[4*i+2]=
2275                 chrMmxFilter[4*i+3]=
2276                     ((uint16_t)vChrFilter[chrDstY*vChrFilterSize + i])*0x10001;
2277             }
2278         }
2279     }
2280 }
2281 #endif /* !COMPILE_TEMPLATE_MMX2 */
2282
2283 static void RENAME(sws_init_swScale)(SwsContext *c)
2284 {
2285     enum PixelFormat srcFormat = c->srcFormat;
2286
2287     if (!(c->flags & SWS_BITEXACT)) {
2288         if (c->flags & SWS_ACCURATE_RND) {
2289             c->yuv2yuv1     = RENAME(yuv2yuv1_ar    );
2290             c->yuv2yuvX     = RENAME(yuv2yuvX_ar    );
2291             switch (c->dstFormat) {
2292             case PIX_FMT_RGB32:   c->yuv2packedX = RENAME(yuv2rgb32_X_ar);   break;
2293             case PIX_FMT_BGR24:   c->yuv2packedX = RENAME(yuv2bgr24_X_ar);   break;
2294             case PIX_FMT_RGB555:  c->yuv2packedX = RENAME(yuv2rgb555_X_ar);  break;
2295             case PIX_FMT_RGB565:  c->yuv2packedX = RENAME(yuv2rgb565_X_ar);  break;
2296             case PIX_FMT_YUYV422: c->yuv2packedX = RENAME(yuv2yuyv422_X_ar); break;
2297             default: break;
2298             }
2299         } else {
2300             c->yuv2yuv1     = RENAME(yuv2yuv1    );
2301             c->yuv2yuvX     = RENAME(yuv2yuvX    );
2302             switch (c->dstFormat) {
2303             case PIX_FMT_RGB32:   c->yuv2packedX = RENAME(yuv2rgb32_X);   break;
2304             case PIX_FMT_BGR24:   c->yuv2packedX = RENAME(yuv2bgr24_X);   break;
2305             case PIX_FMT_RGB555:  c->yuv2packedX = RENAME(yuv2rgb555_X);  break;
2306             case PIX_FMT_RGB565:  c->yuv2packedX = RENAME(yuv2rgb565_X);  break;
2307             case PIX_FMT_YUYV422: c->yuv2packedX = RENAME(yuv2yuyv422_X); break;
2308             default: break;
2309             }
2310         }
2311         switch (c->dstFormat) {
2312         case PIX_FMT_RGB32:
2313                 c->yuv2packed1 = RENAME(yuv2rgb32_1);
2314                 c->yuv2packed2 = RENAME(yuv2rgb32_2);
2315                 break;
2316         case PIX_FMT_BGR24:
2317                 c->yuv2packed1 = RENAME(yuv2bgr24_1);
2318                 c->yuv2packed2 = RENAME(yuv2bgr24_2);
2319                 break;
2320         case PIX_FMT_RGB555:
2321                 c->yuv2packed1 = RENAME(yuv2rgb555_1);
2322                 c->yuv2packed2 = RENAME(yuv2rgb555_2);
2323                 break;
2324         case PIX_FMT_RGB565:
2325                 c->yuv2packed1 = RENAME(yuv2rgb565_1);
2326                 c->yuv2packed2 = RENAME(yuv2rgb565_2);
2327                 break;
2328         case PIX_FMT_YUYV422:
2329                 c->yuv2packed1 = RENAME(yuv2yuyv422_1);
2330                 c->yuv2packed2 = RENAME(yuv2yuyv422_2);
2331                 break;
2332         default:
2333                 break;
2334         }
2335     }
2336
2337 #if !COMPILE_TEMPLATE_MMX2
2338     c->hScale       = RENAME(hScale      );
2339 #endif /* !COMPILE_TEMPLATE_MMX2 */
2340
2341     // Use the new MMX scaler if the MMX2 one can't be used (it is faster than the x86 ASM one).
2342 #if COMPILE_TEMPLATE_MMX2
2343     if (c->flags & SWS_FAST_BILINEAR && c->canMMX2BeUsed)
2344     {
2345         c->hyscale_fast = RENAME(hyscale_fast);
2346         c->hcscale_fast = RENAME(hcscale_fast);
2347     } else {
2348 #endif /* COMPILE_TEMPLATE_MMX2 */
2349         c->hyscale_fast = NULL;
2350         c->hcscale_fast = NULL;
2351 #if COMPILE_TEMPLATE_MMX2
2352     }
2353 #endif /* COMPILE_TEMPLATE_MMX2 */
2354
2355 #if !COMPILE_TEMPLATE_MMX2
2356     switch(srcFormat) {
2357         case PIX_FMT_YUYV422  : c->chrToYV12 = RENAME(yuy2ToUV); break;
2358         case PIX_FMT_UYVY422  : c->chrToYV12 = RENAME(uyvyToUV); break;
2359         case PIX_FMT_NV12     : c->chrToYV12 = RENAME(nv12ToUV); break;
2360         case PIX_FMT_NV21     : c->chrToYV12 = RENAME(nv21ToUV); break;
2361         case PIX_FMT_YUV420P16BE:
2362         case PIX_FMT_YUV422P16BE:
2363         case PIX_FMT_YUV444P16BE: c->chrToYV12 = RENAME(BEToUV); break;
2364         case PIX_FMT_YUV420P16LE:
2365         case PIX_FMT_YUV422P16LE:
2366         case PIX_FMT_YUV444P16LE: c->chrToYV12 = RENAME(LEToUV); break;
2367         default: break;
2368     }
2369 #endif /* !COMPILE_TEMPLATE_MMX2 */
2370     if (!c->chrSrcHSubSample) {
2371         switch(srcFormat) {
2372         case PIX_FMT_BGR24  : c->chrToYV12 = RENAME(bgr24ToUV); break;
2373         case PIX_FMT_RGB24  : c->chrToYV12 = RENAME(rgb24ToUV); break;
2374         default: break;
2375         }
2376     }
2377
2378     switch (srcFormat) {
2379 #if !COMPILE_TEMPLATE_MMX2
2380     case PIX_FMT_YUYV422  :
2381     case PIX_FMT_YUV420P16BE:
2382     case PIX_FMT_YUV422P16BE:
2383     case PIX_FMT_YUV444P16BE:
2384     case PIX_FMT_Y400A    :
2385     case PIX_FMT_GRAY16BE : c->lumToYV12 = RENAME(yuy2ToY); break;
2386     case PIX_FMT_UYVY422  :
2387     case PIX_FMT_YUV420P16LE:
2388     case PIX_FMT_YUV422P16LE:
2389     case PIX_FMT_YUV444P16LE:
2390     case PIX_FMT_GRAY16LE : c->lumToYV12 = RENAME(uyvyToY); break;
2391 #endif /* !COMPILE_TEMPLATE_MMX2 */
2392     case PIX_FMT_BGR24    : c->lumToYV12 = RENAME(bgr24ToY); break;
2393     case PIX_FMT_RGB24    : c->lumToYV12 = RENAME(rgb24ToY); break;
2394     default: break;
2395     }
2396 #if !COMPILE_TEMPLATE_MMX2
2397     if (c->alpPixBuf) {
2398         switch (srcFormat) {
2399         case PIX_FMT_Y400A  : c->alpToYV12 = RENAME(yuy2ToY); break;
2400         default: break;
2401         }
2402     }
2403 #endif /* !COMPILE_TEMPLATE_MMX2 */
2404 }