1 /*****************************************************************************
2 * i420_yuy2.h : YUV to YUV conversion module for vlc
3 *****************************************************************************
4 * Copyright (C) 2000, 2001 the VideoLAN team
7 * Authors: Samuel Hocevar <sam@zoy.org>
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
22 *****************************************************************************/
24 #ifdef MODULE_NAME_IS_i420_yuy2_mmx
26 #define MMX_CALL(MMX_INSTRUCTIONS) \
28 __asm__ __volatile__( \
32 : "r" (p_line1), "r" (p_line2), "r" (p_y1), "r" (p_y2), \
33 "r" (p_u), "r" (p_v) ); \
34 p_line1 += 16; p_line2 += 16; p_y1 += 8; p_y2 += 8; p_u += 4; p_v += 4; \
37 #define MMX_YUV420_YUYV " \n\
38 movq (%2), %%mm0 # Load 8 Y y7 y6 y5 y4 y3 y2 y1 y0 \n\
39 movd (%4), %%mm1 # Load 4 Cb 00 00 00 00 u3 u2 u1 u0 \n\
40 movd (%5), %%mm2 # Load 4 Cr 00 00 00 00 v3 v2 v1 v0 \n\
41 punpcklbw %%mm2, %%mm1 # v3 u3 v2 u2 v1 u1 v0 u0 \n\
42 movq %%mm0, %%mm2 # y7 y6 y5 y4 y3 y2 y1 y0 \n\
43 punpcklbw %%mm1, %%mm2 # v1 y3 u1 y2 v0 y1 u0 y0 \n\
44 movq %%mm2, (%0) # Store low YUYV \n\
45 punpckhbw %%mm1, %%mm0 # v3 y7 u3 y6 v2 y5 u2 y4 \n\
46 movq %%mm0, 8(%0) # Store high YUYV \n\
47 movq (%3), %%mm0 # Load 8 Y Y7 Y6 Y5 Y4 Y3 Y2 Y1 Y0 \n\
48 movq %%mm0, %%mm2 # Y7 Y6 Y5 Y4 Y3 Y2 Y1 Y0 \n\
49 punpcklbw %%mm1, %%mm2 # v1 Y3 u1 Y2 v0 Y1 u0 Y0 \n\
50 movq %%mm2, (%1) # Store low YUYV \n\
51 punpckhbw %%mm1, %%mm0 # v3 Y7 u3 Y6 v2 Y5 u2 Y4 \n\
52 movq %%mm0, 8(%1) # Store high YUYV \n\
55 #define MMX_YUV420_YVYU " \n\
56 movq (%2), %%mm0 # Load 8 Y y7 y6 y5 y4 y3 y2 y1 y0 \n\
57 movd (%4), %%mm2 # Load 4 Cb 00 00 00 00 u3 u2 u1 u0 \n\
58 movd (%5), %%mm1 # Load 4 Cr 00 00 00 00 v3 v2 v1 v0 \n\
59 punpcklbw %%mm2, %%mm1 # u3 v3 u2 v2 u1 v1 u0 v0 \n\
60 movq %%mm0, %%mm2 # y7 y6 y5 y4 y3 y2 y1 y0 \n\
61 punpcklbw %%mm1, %%mm2 # u1 y3 v1 y2 u0 y1 v0 y0 \n\
62 movq %%mm2, (%0) # Store low YUYV \n\
63 punpckhbw %%mm1, %%mm0 # u3 y7 v3 y6 u2 y5 v2 y4 \n\
64 movq %%mm0, 8(%0) # Store high YUYV \n\
65 movq (%3), %%mm0 # Load 8 Y Y7 Y6 Y5 Y4 Y3 Y2 Y1 Y0 \n\
66 movq %%mm0, %%mm2 # Y7 Y6 Y5 Y4 Y3 Y2 Y1 Y0 \n\
67 punpcklbw %%mm1, %%mm2 # u1 Y3 v1 Y2 u0 Y1 v0 Y0 \n\
68 movq %%mm2, (%1) # Store low YUYV \n\
69 punpckhbw %%mm1, %%mm0 # u3 Y7 v3 Y6 u2 Y5 v2 Y4 \n\
70 movq %%mm0, 8(%1) # Store high YUYV \n\
73 #define MMX_YUV420_UYVY " \n\
74 movq (%2), %%mm0 # Load 8 Y y7 y6 y5 y4 y3 y2 y1 y0 \n\
75 movq (%3), %%mm3 # Load 8 Y Y7 Y6 Y5 Y4 Y3 Y2 Y1 Y0 \n\
76 movd (%4), %%mm2 # Load 4 Cb 00 00 00 00 u3 u2 u1 u0 \n\
77 movd (%5), %%mm1 # Load 4 Cr 00 00 00 00 v3 v2 v1 v0 \n\
78 punpcklbw %%mm2, %%mm1 # u3 v3 u2 v2 u1 v1 u0 v0 \n\
79 movq %%mm1, %%mm2 # u3 v3 u2 v2 u1 v1 u0 v0 \n\
80 punpcklbw %%mm0, %%mm2 # y3 v1 y2 u1 y1 v0 y0 u0 \n\
81 movq %%mm2, (%0) # Store low UYVY \n\
82 movq %%mm1, %%mm2 # u3 v3 u2 v2 u1 v1 u0 v0 \n\
83 punpckhbw %%mm0, %%mm2 # y3 v1 y2 u1 y1 v0 y0 u0 \n\
84 movq %%mm2, 8(%0) # Store high UYVY \n\
85 movq %%mm1, %%mm2 # u3 v3 u2 v2 u1 v1 u0 v0 \n\
86 punpcklbw %%mm3, %%mm2 # Y3 v1 Y2 u1 Y1 v0 Y0 u0 \n\
87 movq %%mm2, (%1) # Store low UYVY \n\
88 punpckhbw %%mm3, %%mm1 # Y7 v3 Y6 u3 Y5 v2 Y4 u2 \n\
89 movq %%mm1, 8(%1) # Store high UYVY \n\
92 /* FIXME: this code does not work ! Chroma seems to be wrong. */
93 #define MMX_YUV420_Y211 " \n\
94 movq (%2), %%mm0 # Load 8 Y y7 y6 y5 y4 y3 y2 y1 y0 \n\
95 movq (%3), %%mm1 # Load 8 Y Y7 Y6 Y5 Y4 Y3 Y2 Y1 Y0 \n\
96 movd (%4), %%mm2 # Load 4 Cb 00 00 00 00 u3 u2 u1 u0 \n\
97 movd (%5), %%mm3 # Load 4 Cr 00 00 00 00 v3 v2 v1 v0 \n\
98 pand i_00ffw, %%mm0 # get Y even 00 Y6 00 Y4 00 Y2 00 Y0 \n\
99 packuswb %%mm0, %%mm0 # pack Y y6 y4 y2 y0 y6 y4 y2 y0 \n\
100 pand i_00ffw, %%mm2 # get U even 00 u6 00 u4 00 u2 00 u0 \n\
101 packuswb %%mm2, %%mm2 # pack U 00 00 u2 u0 00 00 u2 u0 \n\
102 pand i_00ffw, %%mm3 # get V even 00 v6 00 v4 00 v2 00 v0 \n\
103 packuswb %%mm3, %%mm3 # pack V 00 00 v2 v0 00 00 v2 v0 \n\
104 punpcklbw %%mm3, %%mm2 # 00 00 00 00 v2 u2 v0 u0 \n\
105 psubsw i_80w, %%mm2 # U,V -= 128 \n\
106 punpcklbw %%mm2, %%mm0 # v2 y6 u2 y4 v0 y2 u0 y0 \n\
107 movq %%mm0, (%0) # Store YUYV \n\
108 pand i_00ffw, %%mm1 # get Y even 00 Y6 00 Y4 00 Y2 00 Y0 \n\
109 packuswb %%mm1, %%mm1 # pack Y Y6 Y4 Y2 Y0 Y6 Y4 Y2 Y0 \n\
110 punpcklbw %%mm2, %%mm1 # v2 Y6 u2 Y4 v0 Y2 u0 Y0 \n\
111 movq %%mm1, (%1) # Store YUYV \n\
116 #define C_YUV420_YVYU( ) \
117 *(p_line1)++ = *(p_y1)++; *(p_line2)++ = *(p_y2)++; \
118 *(p_line1)++ = *(p_line2)++ = *(p_v)++; \
119 *(p_line1)++ = *(p_y1)++; *(p_line2)++ = *(p_y2)++; \
120 *(p_line1)++ = *(p_line2)++ = *(p_u)++; \
122 #define C_YUV420_UYVY( ) \
123 *(p_line1)++ = *(p_line2)++ = *(p_u)++; \
124 *(p_line1)++ = *(p_y1)++; *(p_line2)++ = *(p_y2)++; \
125 *(p_line1)++ = *(p_line2)++ = *(p_v)++; \
126 *(p_line1)++ = *(p_y1)++; *(p_line2)++ = *(p_y2)++; \
128 #define C_YUV420_Y211( ) \
129 *(p_line1)++ = *(p_y1); p_y1 += 2; \
130 *(p_line2)++ = *(p_y2); p_y2 += 2; \
131 *(p_line1)++ = *(p_line2)++ = *(p_u) - 0x80; p_u += 2; \
132 *(p_line1)++ = *(p_y1); p_y1 += 2; \
133 *(p_line2)++ = *(p_y2); p_y2 += 2; \
134 *(p_line1)++ = *(p_line2)++ = *(p_v) - 0x80; p_v += 2; \
138 /* Used in both MMX and C modules */
139 #define C_YUV420_YUYV( ) \
140 *(p_line1)++ = *(p_y1)++; *(p_line2)++ = *(p_y2)++; \
141 *(p_line1)++ = *(p_line2)++ = *(p_u)++; \
142 *(p_line1)++ = *(p_y1)++; *(p_line2)++ = *(p_y2)++; \
143 *(p_line1)++ = *(p_line2)++ = *(p_v)++; \