Mercurial > mplayer.hg
annotate postproc/yuv2rgb_template.c @ 3024:7a5021d0a2de
Small two pass mencoder helper script in perl.
author | atmos4 |
---|---|
date | Tue, 20 Nov 2001 13:02:56 +0000 |
parents | 2cbecedb2616 |
children | 86910f54c391 |
rev | line source |
---|---|
2732 | 1 |
2 /* | |
3 * yuv2rgb_mmx.c, Software YUV to RGB coverter with Intel MMX "technology" | |
4 * | |
5 * Copyright (C) 2000, Silicon Integrated System Corp. | |
6 * All Rights Reserved. | |
7 * | |
8 * Author: Olie Lho <ollie@sis.com.tw> | |
9 * | |
10 * This file is part of mpeg2dec, a free MPEG-2 video decoder | |
11 * | |
12 * mpeg2dec is free software; you can redistribute it and/or modify | |
13 * it under the terms of the GNU General Public License as published by | |
14 * the Free Software Foundation; either version 2, or (at your option) | |
15 * any later version. | |
16 * | |
17 * mpeg2dec is distributed in the hope that it will be useful, | |
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
20 * GNU General Public License for more details. | |
21 * | |
22 * You should have received a copy of the GNU General Public License | |
23 * along with GNU Make; see the file COPYING. If not, write to | |
24 * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. | |
25 * | |
2749 | 26 * 15,24 bpp and dithering from Michael Niedermayer (michaelni@gmx.at) |
2732 | 27 */ |
28 | |
29 #include <stdio.h> | |
30 #include <stdlib.h> | |
31 | |
32 #include "../config.h" | |
33 | |
34 //#include "libmpeg2/mpeg2.h" | |
35 //#include "libmpeg2/mpeg2_internal.h" | |
36 #include <inttypes.h> | |
37 | |
38 #include "rgb2rgb.h" | |
2736 | 39 #include "../mmx_defs.h" |
2732 | 40 |
2749 | 41 #define DITHER1XBPP |
42 | |
2732 | 43 /* hope these constant values are cache line aligned */ |
2737
d0f34e15aa5f
vars are aligned by 8 now (even faster, yes they where not aligned correctly)
michael
parents:
2736
diff
changeset
|
44 uint64_t __attribute__((aligned(8))) mmx_80w = 0x0080008000800080; |
d0f34e15aa5f
vars are aligned by 8 now (even faster, yes they where not aligned correctly)
michael
parents:
2736
diff
changeset
|
45 uint64_t __attribute__((aligned(8))) mmx_10w = 0x1010101010101010; |
d0f34e15aa5f
vars are aligned by 8 now (even faster, yes they where not aligned correctly)
michael
parents:
2736
diff
changeset
|
46 uint64_t __attribute__((aligned(8))) mmx_00ffw = 0x00ff00ff00ff00ff; |
d0f34e15aa5f
vars are aligned by 8 now (even faster, yes they where not aligned correctly)
michael
parents:
2736
diff
changeset
|
47 uint64_t __attribute__((aligned(8))) mmx_Y_coeff = 0x253f253f253f253f; |
2732 | 48 |
49 /* hope these constant values are cache line aligned */ | |
2737
d0f34e15aa5f
vars are aligned by 8 now (even faster, yes they where not aligned correctly)
michael
parents:
2736
diff
changeset
|
50 uint64_t __attribute__((aligned(8))) mmx_U_green = 0xf37df37df37df37d; |
d0f34e15aa5f
vars are aligned by 8 now (even faster, yes they where not aligned correctly)
michael
parents:
2736
diff
changeset
|
51 uint64_t __attribute__((aligned(8))) mmx_U_blue = 0x4093409340934093; |
d0f34e15aa5f
vars are aligned by 8 now (even faster, yes they where not aligned correctly)
michael
parents:
2736
diff
changeset
|
52 uint64_t __attribute__((aligned(8))) mmx_V_red = 0x3312331233123312; |
d0f34e15aa5f
vars are aligned by 8 now (even faster, yes they where not aligned correctly)
michael
parents:
2736
diff
changeset
|
53 uint64_t __attribute__((aligned(8))) mmx_V_green = 0xe5fce5fce5fce5fc; |
2732 | 54 |
55 /* hope these constant values are cache line aligned */ | |
2737
d0f34e15aa5f
vars are aligned by 8 now (even faster, yes they where not aligned correctly)
michael
parents:
2736
diff
changeset
|
56 uint64_t __attribute__((aligned(8))) mmx_redmask = 0xf8f8f8f8f8f8f8f8; |
d0f34e15aa5f
vars are aligned by 8 now (even faster, yes they where not aligned correctly)
michael
parents:
2736
diff
changeset
|
57 uint64_t __attribute__((aligned(8))) mmx_grnmask = 0xfcfcfcfcfcfcfcfc; |
2732 | 58 |
2739 | 59 uint64_t __attribute__((aligned(8))) M24A= 0x00FF0000FF0000FFLL; |
60 uint64_t __attribute__((aligned(8))) M24B= 0xFF0000FF0000FF00LL; | |
61 uint64_t __attribute__((aligned(8))) M24C= 0x0000FF0000FF0000LL; | |
62 | |
2749 | 63 // the volatile is required because gcc otherwise optimizes some writes away not knowing that these |
64 // are read in the asm block | |
65 volatile uint64_t __attribute__((aligned(8))) b5Dither; | |
66 volatile uint64_t __attribute__((aligned(8))) g5Dither; | |
67 volatile uint64_t __attribute__((aligned(8))) g6Dither; | |
68 volatile uint64_t __attribute__((aligned(8))) r5Dither; | |
69 | |
70 uint64_t __attribute__((aligned(8))) dither4[2]={ | |
71 0x0103010301030103LL, | |
72 0x0200020002000200LL,}; | |
73 | |
74 uint64_t __attribute__((aligned(8))) dither8[2]={ | |
75 0x0602060206020602LL, | |
76 0x0004000400040004LL,}; | |
77 | |
78 | |
2739 | 79 |
2734 | 80 #define YUV2RGB \ |
81 /* Do the multiply part of the conversion for even and odd pixels, | |
82 register usage: | |
83 mm0 -> Cblue, mm1 -> Cred, mm2 -> Cgreen even pixels, | |
84 mm3 -> Cblue, mm4 -> Cred, mm5 -> Cgreen odd pixels, | |
85 mm6 -> Y even, mm7 -> Y odd */\ | |
86 /* convert the chroma part */\ | |
87 "punpcklbw %%mm4, %%mm0;" /* scatter 4 Cb 00 u3 00 u2 00 u1 00 u0 */ \ | |
88 "punpcklbw %%mm4, %%mm1;" /* scatter 4 Cr 00 v3 00 v2 00 v1 00 v0 */ \ | |
89 \ | |
90 "psubsw mmx_80w, %%mm0;" /* Cb -= 128 */ \ | |
91 "psubsw mmx_80w, %%mm1;" /* Cr -= 128 */ \ | |
92 \ | |
93 "psllw $3, %%mm0;" /* Promote precision */ \ | |
94 "psllw $3, %%mm1;" /* Promote precision */ \ | |
95 \ | |
96 "movq %%mm0, %%mm2;" /* Copy 4 Cb 00 u3 00 u2 00 u1 00 u0 */ \ | |
97 "movq %%mm1, %%mm3;" /* Copy 4 Cr 00 v3 00 v2 00 v1 00 v0 */ \ | |
98 \ | |
99 "pmulhw mmx_U_green, %%mm2;" /* Mul Cb with green coeff -> Cb green */ \ | |
100 "pmulhw mmx_V_green, %%mm3;" /* Mul Cr with green coeff -> Cr green */ \ | |
101 \ | |
102 "pmulhw mmx_U_blue, %%mm0;" /* Mul Cb -> Cblue 00 b3 00 b2 00 b1 00 b0 */\ | |
103 "pmulhw mmx_V_red, %%mm1;" /* Mul Cr -> Cred 00 r3 00 r2 00 r1 00 r0 */\ | |
104 \ | |
105 "paddsw %%mm3, %%mm2;" /* Cb green + Cr green -> Cgreen */\ | |
106 \ | |
107 /* convert the luma part */\ | |
108 "psubusb mmx_10w, %%mm6;" /* Y -= 16 */\ | |
109 \ | |
110 "movq %%mm6, %%mm7;" /* Copy 8 Y Y7 Y6 Y5 Y4 Y3 Y2 Y1 Y0 */\ | |
111 "pand mmx_00ffw, %%mm6;" /* get Y even 00 Y6 00 Y4 00 Y2 00 Y0 */\ | |
112 \ | |
113 "psrlw $8, %%mm7;" /* get Y odd 00 Y7 00 Y5 00 Y3 00 Y1 */\ | |
114 \ | |
115 "psllw $3, %%mm6;" /* Promote precision */\ | |
116 "psllw $3, %%mm7;" /* Promote precision */\ | |
117 \ | |
118 "pmulhw mmx_Y_coeff, %%mm6;" /* Mul 4 Y even 00 y6 00 y4 00 y2 00 y0 */\ | |
119 "pmulhw mmx_Y_coeff, %%mm7;" /* Mul 4 Y odd 00 y7 00 y5 00 y3 00 y1 */\ | |
120 \ | |
121 /* Do the addition part of the conversion for even and odd pixels, | |
122 register usage: | |
123 mm0 -> Cblue, mm1 -> Cred, mm2 -> Cgreen even pixels, | |
124 mm3 -> Cblue, mm4 -> Cred, mm5 -> Cgreen odd pixels, | |
125 mm6 -> Y even, mm7 -> Y odd */\ | |
126 "movq %%mm0, %%mm3;" /* Copy Cblue */\ | |
127 "movq %%mm1, %%mm4;" /* Copy Cred */\ | |
128 "movq %%mm2, %%mm5;" /* Copy Cgreen */\ | |
129 \ | |
130 "paddsw %%mm6, %%mm0;" /* Y even + Cblue 00 B6 00 B4 00 B2 00 B0 */\ | |
131 "paddsw %%mm7, %%mm3;" /* Y odd + Cblue 00 B7 00 B5 00 B3 00 B1 */\ | |
132 \ | |
133 "paddsw %%mm6, %%mm1;" /* Y even + Cred 00 R6 00 R4 00 R2 00 R0 */\ | |
134 "paddsw %%mm7, %%mm4;" /* Y odd + Cred 00 R7 00 R5 00 R3 00 R1 */\ | |
135 \ | |
136 "paddsw %%mm6, %%mm2;" /* Y even + Cgreen 00 G6 00 G4 00 G2 00 G0 */\ | |
137 "paddsw %%mm7, %%mm5;" /* Y odd + Cgreen 00 G7 00 G5 00 G3 00 G1 */\ | |
138 \ | |
139 /* Limit RGB even to 0..255 */\ | |
140 "packuswb %%mm0, %%mm0;" /* B6 B4 B2 B0 B6 B4 B2 B0 */\ | |
141 "packuswb %%mm1, %%mm1;" /* R6 R4 R2 R0 R6 R4 R2 R0 */\ | |
142 "packuswb %%mm2, %%mm2;" /* G6 G4 G2 G0 G6 G4 G2 G0 */\ | |
143 \ | |
144 /* Limit RGB odd to 0..255 */\ | |
145 "packuswb %%mm3, %%mm3;" /* B7 B5 B3 B1 B7 B5 B3 B1 */\ | |
146 "packuswb %%mm4, %%mm4;" /* R7 R5 R3 R1 R7 R5 R3 R1 */\ | |
147 "packuswb %%mm5, %%mm5;" /* G7 G5 G3 G1 G7 G5 G3 G1 */\ | |
148 \ | |
149 /* Interleave RGB even and odd */\ | |
150 "punpcklbw %%mm3, %%mm0;" /* B7 B6 B5 B4 B3 B2 B1 B0 */\ | |
151 "punpcklbw %%mm4, %%mm1;" /* R7 R6 R5 R4 R3 R2 R1 R0 */\ | |
152 "punpcklbw %%mm5, %%mm2;" /* G7 G6 G5 G4 G3 G2 G1 G0 */\ | |
153 | |
154 | |
2732 | 155 static void yuv420_rgb16_mmx (uint8_t * image, uint8_t * py, |
156 uint8_t * pu, uint8_t * pv, | |
157 int h_size, int v_size, | |
158 int rgb_stride, int y_stride, int uv_stride) | |
159 { | |
160 int even = 1; | |
161 int x, y; | |
162 | |
163 __asm__ __volatile__ ("pxor %mm4, %mm4;" /* zero mm4 */ ); | |
164 | |
165 for (y = v_size; --y >= 0; ) { | |
166 uint8_t *_image = image; | |
167 uint8_t *_py = py; | |
168 uint8_t *_pu = pu; | |
169 uint8_t *_pv = pv; | |
170 | |
2749 | 171 b5Dither= dither8[y&1]; |
172 g6Dither= dither4[y&1]; | |
173 g5Dither= dither8[y&1]; | |
174 r5Dither= dither8[(y+1)&1]; | |
175 | |
2732 | 176 /* load data for start of next scan line */ |
177 __asm__ __volatile__ ( | |
2734 | 178 "movd (%1), %%mm0;" /* Load 4 Cb 00 00 00 00 u3 u2 u1 u0 */ |
179 "movd (%2), %%mm1;" /* Load 4 Cr 00 00 00 00 v3 v2 v1 v0 */ | |
180 "movq (%0), %%mm6;" /* Load 8 Y Y7 Y6 Y5 Y4 Y3 Y2 Y1 Y0 */ | |
2732 | 181 |
182 : : "r" (_py), "r" (_pu), "r" (_pv)); | |
183 | |
184 for (x = h_size >> 3; --x >= 0; ) { | |
185 /* this mmx assembly code deals with SINGLE scan line at a time, it convert 8 | |
186 pixels in each iteration */ | |
187 | |
188 __asm__ __volatile__ ( | |
2736 | 189 /* no speed diference on my p3@500 with prefetch, |
190 * if it is faster for anyone with -benchmark then tell me | |
191 PREFETCH" 64(%0) \n\t" | |
192 PREFETCH" 64(%1) \n\t" | |
193 PREFETCH" 64(%2) \n\t" | |
194 */ | |
2734 | 195 YUV2RGB |
2732 | 196 |
2749 | 197 #ifdef DITHER1XBPP |
198 "paddusb b5Dither, %%mm0;" | |
199 "paddusb g6Dither, %%mm2;" | |
200 "paddusb r5Dither, %%mm1;" | |
201 #endif | |
2732 | 202 /* mask unneeded bits off */ |
2734 | 203 "pand mmx_redmask, %%mm0;" /* b7b6b5b4 b3_0_0_0 b7b6b5b4 b3_0_0_0 */ |
204 "pand mmx_grnmask, %%mm2;" /* g7g6g5g4 g3g2_0_0 g7g6g5g4 g3g2_0_0 */ | |
205 "pand mmx_redmask, %%mm1;" /* r7r6r5r4 r3_0_0_0 r7r6r5r4 r3_0_0_0 */ | |
2732 | 206 |
2736 | 207 "psrlw $3,%%mm0;" /* 0_0_0_b7 b6b5b4b3 0_0_0_b7 b6b5b4b3 */ |
2734 | 208 "pxor %%mm4, %%mm4;" /* zero mm4 */ |
2732 | 209 |
2734 | 210 "movq %%mm0, %%mm5;" /* Copy B7-B0 */ |
211 "movq %%mm2, %%mm7;" /* Copy G7-G0 */ | |
2732 | 212 |
213 /* convert rgb24 plane to rgb16 pack for pixel 0-3 */ | |
2734 | 214 "punpcklbw %%mm4, %%mm2;" /* 0_0_0_0 0_0_0_0 g7g6g5g4 g3g2_0_0 */ |
215 "punpcklbw %%mm1, %%mm0;" /* r7r6r5r4 r3_0_0_0 0_0_0_b7 b6b5b4b3 */ | |
2732 | 216 |
2736 | 217 "psllw $3, %%mm2;" /* 0_0_0_0 0_g7g6g5 g4g3g2_0 0_0_0_0 */ |
2734 | 218 "por %%mm2, %%mm0;" /* r7r6r5r4 r3g7g6g5 g4g3g2b7 b6b5b4b3 */ |
2732 | 219 |
2734 | 220 "movq 8 (%0), %%mm6;" /* Load 8 Y Y7 Y6 Y5 Y4 Y3 Y2 Y1 Y0 */ |
221 MOVNTQ " %%mm0, (%3);" /* store pixel 0-3 */ | |
2732 | 222 |
223 /* convert rgb24 plane to rgb16 pack for pixel 0-3 */ | |
2734 | 224 "punpckhbw %%mm4, %%mm7;" /* 0_0_0_0 0_0_0_0 g7g6g5g4 g3g2_0_0 */ |
225 "punpckhbw %%mm1, %%mm5;" /* r7r6r5r4 r3_0_0_0 0_0_0_b7 b6b5b4b3 */ | |
2732 | 226 |
2736 | 227 "psllw $3, %%mm7;" /* 0_0_0_0 0_g7g6g5 g4g3g2_0 0_0_0_0 */ |
2734 | 228 "movd 4 (%1), %%mm0;" /* Load 4 Cb 00 00 00 00 u3 u2 u1 u0 */ |
2732 | 229 |
2734 | 230 "por %%mm7, %%mm5;" /* r7r6r5r4 r3g7g6g5 g4g3g2b7 b6b5b4b3 */ |
231 "movd 4 (%2), %%mm1;" /* Load 4 Cr 00 00 00 00 v3 v2 v1 v0 */ | |
2732 | 232 |
2734 | 233 MOVNTQ " %%mm5, 8 (%3);" /* store pixel 4-7 */ |
2732 | 234 : : "r" (_py), "r" (_pu), "r" (_pv), "r" (_image)); |
235 | |
236 _py += 8; | |
237 _pu += 4; | |
238 _pv += 4; | |
239 _image += 16; | |
240 } | |
241 | |
242 if (!even) { | |
243 pu += uv_stride; | |
244 pv += uv_stride; | |
245 } | |
246 | |
247 py += y_stride; | |
248 image += rgb_stride; | |
249 | |
250 even = (!even); | |
251 } | |
252 | |
253 __asm__ __volatile__ (EMMS); | |
254 } | |
255 | |
2735 | 256 static void yuv420_rgb15_mmx (uint8_t * image, uint8_t * py, |
257 uint8_t * pu, uint8_t * pv, | |
258 int h_size, int v_size, | |
259 int rgb_stride, int y_stride, int uv_stride) | |
260 { | |
261 int even = 1; | |
262 int x, y; | |
263 | |
264 __asm__ __volatile__ ("pxor %mm4, %mm4;" /* zero mm4 */ ); | |
265 | |
266 for (y = v_size; --y >= 0; ) { | |
267 uint8_t *_image = image; | |
268 uint8_t *_py = py; | |
269 uint8_t *_pu = pu; | |
270 uint8_t *_pv = pv; | |
271 | |
2749 | 272 b5Dither= dither8[y&1]; |
273 g6Dither= dither4[y&1]; | |
274 g5Dither= dither8[y&1]; | |
275 r5Dither= dither8[(y+1)&1]; | |
276 | |
2735 | 277 /* load data for start of next scan line */ |
278 __asm__ __volatile__ ( | |
279 "movd (%1), %%mm0;" /* Load 4 Cb 00 00 00 00 u3 u2 u1 u0 */ | |
280 "movd (%2), %%mm1;" /* Load 4 Cr 00 00 00 00 v3 v2 v1 v0 */ | |
281 "movq (%0), %%mm6;" /* Load 8 Y Y7 Y6 Y5 Y4 Y3 Y2 Y1 Y0 */ | |
282 | |
283 : : "r" (_py), "r" (_pu), "r" (_pv)); | |
284 | |
285 for (x = h_size >> 3; --x >= 0; ) { | |
286 /* this mmx assembly code deals with SINGLE scan line at a time, it convert 8 | |
287 pixels in each iteration */ | |
288 | |
289 __asm__ __volatile__ ( | |
290 YUV2RGB | |
291 | |
2749 | 292 #ifdef DITHER1XBPP |
293 "paddusb b5Dither, %%mm0 \n\t" | |
294 "paddusb g5Dither, %%mm2 \n\t" | |
295 "paddusb r5Dither, %%mm1 \n\t" | |
296 #endif | |
297 | |
2735 | 298 /* mask unneeded bits off */ |
299 "pand mmx_redmask, %%mm0;" /* b7b6b5b4 b3_0_0_0 b7b6b5b4 b3_0_0_0 */ | |
300 "pand mmx_redmask, %%mm2;" /* g7g6g5g4 g3_0_0_0 g7g6g5g4 g3_0_0_0 */ | |
301 "pand mmx_redmask, %%mm1;" /* r7r6r5r4 r3_0_0_0 r7r6r5r4 r3_0_0_0 */ | |
302 | |
2736 | 303 "psrlw $3,%%mm0;" /* 0_0_0_b7 b6b5b4b3 0_0_0_b7 b6b5b4b3 */ |
2735 | 304 "psrlw $1,%%mm1;" /* 0_r7r6r5 r4r3_0_0 0_r7r6r5 r4r3_0_0 */ |
305 "pxor %%mm4, %%mm4;" /* zero mm4 */ | |
306 | |
307 "movq %%mm0, %%mm5;" /* Copy B7-B0 */ | |
308 "movq %%mm2, %%mm7;" /* Copy G7-G0 */ | |
309 | |
310 /* convert rgb24 plane to rgb16 pack for pixel 0-3 */ | |
311 "punpcklbw %%mm4, %%mm2;" /* 0_0_0_0 0_0_0_0 g7g6g5g4 g3_0_0_0 */ | |
312 "punpcklbw %%mm1, %%mm0;" /* r7r6r5r4 r3_0_0_0 0_0_0_b7 b6b5b4b3 */ | |
313 | |
314 "psllw $2, %%mm2;" /* 0_0_0_0 0_0_g7g6 g5g4g3_0 0_0_0_0 */ | |
315 "por %%mm2, %%mm0;" /* 0_r7r6r5 r4r3g7g6 g5g4g3b7 b6b5b4b3 */ | |
316 | |
317 "movq 8 (%0), %%mm6;" /* Load 8 Y Y7 Y6 Y5 Y4 Y3 Y2 Y1 Y0 */ | |
318 MOVNTQ " %%mm0, (%3);" /* store pixel 0-3 */ | |
319 | |
320 /* convert rgb24 plane to rgb16 pack for pixel 0-3 */ | |
321 "punpckhbw %%mm4, %%mm7;" /* 0_0_0_0 0_0_0_0 0_g7g6g5 g4g3_0_0 */ | |
322 "punpckhbw %%mm1, %%mm5;" /* r7r6r5r4 r3_0_0_0 0_0_0_b7 b6b5b4b3 */ | |
323 | |
324 "psllw $2, %%mm7;" /* 0_0_0_0 0_0_g7g6 g5g4g3_0 0_0_0_0 */ | |
325 "movd 4 (%1), %%mm0;" /* Load 4 Cb 00 00 00 00 u3 u2 u1 u0 */ | |
326 | |
327 "por %%mm7, %%mm5;" /* 0_r7r6r5 r4r3g7g6 g5g4g3b7 b6b5b4b3 */ | |
328 "movd 4 (%2), %%mm1;" /* Load 4 Cr 00 00 00 00 v3 v2 v1 v0 */ | |
329 | |
330 MOVNTQ " %%mm5, 8 (%3);" /* store pixel 4-7 */ | |
331 : : "r" (_py), "r" (_pu), "r" (_pv), "r" (_image)); | |
332 | |
333 _py += 8; | |
334 _pu += 4; | |
335 _pv += 4; | |
336 _image += 16; | |
337 } | |
338 | |
339 if (!even) { | |
340 pu += uv_stride; | |
341 pv += uv_stride; | |
342 } | |
343 | |
344 py += y_stride; | |
345 image += rgb_stride; | |
346 | |
347 even = (!even); | |
348 } | |
349 | |
350 __asm__ __volatile__ (EMMS); | |
351 } | |
352 | |
2734 | 353 static void yuv420_rgb24_mmx (uint8_t * image, uint8_t * py, |
354 uint8_t * pu, uint8_t * pv, | |
355 int h_size, int v_size, | |
356 int rgb_stride, int y_stride, int uv_stride) | |
357 { | |
358 int even = 1; | |
359 int x, y; | |
360 | |
361 __asm__ __volatile__ ("pxor %mm4, %mm4;" /* zero mm4 */ ); | |
362 | |
363 for (y = v_size; --y >= 0; ) { | |
364 uint8_t *_image = image; | |
365 uint8_t *_py = py; | |
366 uint8_t *_pu = pu; | |
367 uint8_t *_pv = pv; | |
368 | |
369 /* load data for start of next scan line */ | |
370 __asm__ __volatile__ ( | |
371 "movd (%1), %%mm0;" /* Load 4 Cb 00 00 00 00 u3 u2 u1 u0 */ | |
372 "movd (%2), %%mm1;" /* Load 4 Cr 00 00 00 00 v3 v2 v1 v0 */ | |
373 "movq (%0), %%mm6;" /* Load 8 Y Y7 Y6 Y5 Y4 Y3 Y2 Y1 Y0 */ | |
374 | |
375 : : "r" (_py), "r" (_pu), "r" (_pv)); | |
376 | |
377 for (x = h_size >> 3; --x >= 0; ) { | |
378 /* this mmx assembly code deals with SINGLE scan line at a time, it convert 8 | |
379 pixels in each iteration */ | |
380 | |
381 __asm__ __volatile__ ( | |
382 YUV2RGB | |
2739 | 383 /* mm0=B, %%mm2=G, %%mm1=R */ |
384 #ifdef HAVE_MMX2 | |
385 "movq M24A, %%mm4 \n\t" | |
386 "movq M24C, %%mm7 \n\t" | |
387 "pshufw $0x50, %%mm0, %%mm5 \n\t" /* B3 B2 B3 B2 B1 B0 B1 B0 */ | |
388 "pshufw $0x50, %%mm2, %%mm3 \n\t" /* G3 G2 G3 G2 G1 G0 G1 G0 */ | |
389 "pshufw $0x00, %%mm1, %%mm6 \n\t" /* R1 R0 R1 R0 R1 R0 R1 R0 */ | |
2734 | 390 |
2739 | 391 "pand %%mm4, %%mm5 \n\t" /* B2 B1 B0 */ |
392 "pand %%mm4, %%mm3 \n\t" /* G2 G1 G0 */ | |
393 "pand %%mm7, %%mm6 \n\t" /* R1 R0 */ | |
394 | |
395 "psllq $8, %%mm3 \n\t" /* G2 G1 G0 */ | |
396 "por %%mm5, %%mm6 \n\t" | |
397 "por %%mm3, %%mm6 \n\t" | |
398 MOVNTQ" %%mm6, (%3) \n\t" | |
399 | |
400 "psrlq $8, %%mm2 \n\t" /* 00 G7 G6 G5 G4 G3 G2 G1 */ | |
401 "pshufw $0xA5, %%mm0, %%mm5 \n\t" /* B5 B4 B5 B4 B3 B2 B3 B2 */ | |
402 "pshufw $0x55, %%mm2, %%mm3 \n\t" /* G4 G3 G4 G3 G4 G3 G4 G3 */ | |
403 "pshufw $0xA5, %%mm1, %%mm6 \n\t" /* R5 R4 R5 R4 R3 R2 R3 R2 */ | |
404 | |
405 "pand M24B, %%mm5 \n\t" /* B5 B4 B3 */ | |
406 "pand %%mm7, %%mm3 \n\t" /* G4 G3 */ | |
407 "pand %%mm4, %%mm6 \n\t" /* R4 R3 R2 */ | |
408 | |
409 "por %%mm5, %%mm3 \n\t" /* B5 G4 B4 G3 B3 */ | |
410 "por %%mm3, %%mm6 \n\t" | |
411 MOVNTQ" %%mm6, 8(%3) \n\t" | |
412 | |
413 "pshufw $0xFF, %%mm0, %%mm5 \n\t" /* B7 B6 B7 B6 B7 B6 B6 B7 */ | |
414 "pshufw $0xFA, %%mm2, %%mm3 \n\t" /* 00 G7 00 G7 G6 G5 G6 G5 */ | |
415 "pshufw $0xFA, %%mm1, %%mm6 \n\t" /* R7 R6 R7 R6 R5 R4 R5 R4 */ | |
416 "movd 4 (%1), %%mm0;" /* Load 4 Cb 00 00 00 00 u3 u2 u1 u0 */ | |
417 | |
418 "pand %%mm7, %%mm5 \n\t" /* B7 B6 */ | |
419 "pand %%mm4, %%mm3 \n\t" /* G7 G6 G5 */ | |
420 "pand M24B, %%mm6 \n\t" /* R7 R6 R5 */ | |
421 "movd 4 (%2), %%mm1;" /* Load 4 Cr 00 00 00 00 v3 v2 v1 v0 */ | |
422 \ | |
423 "por %%mm5, %%mm3 \n\t" | |
424 "por %%mm3, %%mm6 \n\t" | |
425 MOVNTQ" %%mm6, 16(%3) \n\t" | |
426 "movq 8 (%0), %%mm6;" /* Load 8 Y Y7 Y6 Y5 Y4 Y3 Y2 Y1 Y0 */ | |
427 "pxor %%mm4, %%mm4 \n\t" | |
428 | |
429 #else | |
430 | |
2734 | 431 "pxor %%mm4, %%mm4 \n\t" |
432 "movq %%mm0, %%mm5 \n\t" /* B */ | |
433 "movq %%mm1, %%mm6 \n\t" /* R */ | |
434 "punpcklbw %%mm2, %%mm0 \n\t" /* GBGBGBGB 0 */ | |
435 "punpcklbw %%mm4, %%mm1 \n\t" /* 0R0R0R0R 0 */ | |
436 "punpckhbw %%mm2, %%mm5 \n\t" /* GBGBGBGB 2 */ | |
437 "punpckhbw %%mm4, %%mm6 \n\t" /* 0R0R0R0R 2 */ | |
438 "movq %%mm0, %%mm7 \n\t" /* GBGBGBGB 0 */ | |
439 "movq %%mm5, %%mm3 \n\t" /* GBGBGBGB 2 */ | |
440 "punpcklwd %%mm1, %%mm7 \n\t" /* 0RGB0RGB 0 */ | |
441 "punpckhwd %%mm1, %%mm0 \n\t" /* 0RGB0RGB 1 */ | |
442 "punpcklwd %%mm6, %%mm5 \n\t" /* 0RGB0RGB 2 */ | |
443 "punpckhwd %%mm6, %%mm3 \n\t" /* 0RGB0RGB 3 */ | |
444 | |
445 "movq %%mm7, %%mm2 \n\t" /* 0RGB0RGB 0 */ | |
446 "movq %%mm0, %%mm6 \n\t" /* 0RGB0RGB 1 */ | |
447 "movq %%mm5, %%mm1 \n\t" /* 0RGB0RGB 2 */ | |
448 "movq %%mm3, %%mm4 \n\t" /* 0RGB0RGB 3 */ | |
449 | |
450 "psllq $40, %%mm7 \n\t" /* RGB00000 0 */ | |
451 "psllq $40, %%mm0 \n\t" /* RGB00000 1 */ | |
452 "psllq $40, %%mm5 \n\t" /* RGB00000 2 */ | |
453 "psllq $40, %%mm3 \n\t" /* RGB00000 3 */ | |
454 | |
455 "punpckhdq %%mm2, %%mm7 \n\t" /* 0RGBRGB0 0 */ | |
456 "punpckhdq %%mm6, %%mm0 \n\t" /* 0RGBRGB0 1 */ | |
457 "punpckhdq %%mm1, %%mm5 \n\t" /* 0RGBRGB0 2 */ | |
458 "punpckhdq %%mm4, %%mm3 \n\t" /* 0RGBRGB0 3 */ | |
459 | |
460 "psrlq $8, %%mm7 \n\t" /* 00RGBRGB 0 */ | |
461 "movq %%mm0, %%mm6 \n\t" /* 0RGBRGB0 1 */ | |
462 "psllq $40, %%mm0 \n\t" /* GB000000 1 */ | |
463 "por %%mm0, %%mm7 \n\t" /* GBRGBRGB 0 */ | |
464 MOVNTQ" %%mm7, (%3) \n\t" | |
465 | |
466 "movd 4 (%1), %%mm0;" /* Load 4 Cb 00 00 00 00 u3 u2 u1 u0 */ | |
467 | |
468 "psrlq $24, %%mm6 \n\t" /* 0000RGBR 1 */ | |
469 "movq %%mm5, %%mm1 \n\t" /* 0RGBRGB0 2 */ | |
470 "psllq $24, %%mm5 \n\t" /* BRGB0000 2 */ | |
471 "por %%mm5, %%mm6 \n\t" /* BRGBRGBR 1 */ | |
472 MOVNTQ" %%mm6, 8(%3) \n\t" | |
473 | |
474 "movq 8 (%0), %%mm6;" /* Load 8 Y Y7 Y6 Y5 Y4 Y3 Y2 Y1 Y0 */ | |
475 | |
476 "psrlq $40, %%mm1 \n\t" /* 000000RG 2 */ | |
477 "psllq $8, %%mm3 \n\t" /* RGBRGB00 3 */ | |
478 "por %%mm3, %%mm1 \n\t" /* RGBRGBRG 2 */ | |
479 MOVNTQ" %%mm1, 16(%3) \n\t" | |
480 | |
481 "movd 4 (%2), %%mm1;" /* Load 4 Cr 00 00 00 00 v3 v2 v1 v0 */ | |
482 "pxor %%mm4, %%mm4 \n\t" | |
2739 | 483 #endif |
2734 | 484 |
485 : : "r" (_py), "r" (_pu), "r" (_pv), "r" (_image)); | |
486 | |
487 _py += 8; | |
488 _pu += 4; | |
489 _pv += 4; | |
490 _image += 24; | |
491 } | |
492 | |
493 if (!even) { | |
494 pu += uv_stride; | |
495 pv += uv_stride; | |
496 } | |
497 | |
498 py += y_stride; | |
499 image += rgb_stride; | |
500 | |
501 even = (!even); | |
502 } | |
503 | |
504 __asm__ __volatile__ (EMMS); | |
505 } | |
506 | |
507 | |
2732 | 508 static void yuv420_argb32_mmx (uint8_t * image, uint8_t * py, |
509 uint8_t * pu, uint8_t * pv, | |
510 int h_size, int v_size, | |
511 int rgb_stride, int y_stride, int uv_stride) | |
512 { | |
513 int even = 1; | |
514 int x, y; | |
515 | |
516 __asm__ __volatile__ ("pxor %mm4, %mm4;" /* zero mm4 */ ); | |
517 | |
518 for (y = v_size; --y >= 0; ) { | |
519 uint8_t *_image = image; | |
520 uint8_t *_py = py; | |
521 uint8_t *_pu = pu; | |
522 uint8_t *_pv = pv; | |
523 | |
524 /* load data for start of next scan line */ | |
525 __asm__ __volatile__ | |
526 ( | |
527 "movd (%1), %%mm0;" /* Load 4 Cb 00 00 00 00 u3 u2 u1 u0 */ | |
528 "movd (%2), %%mm1;" /* Load 4 Cr 00 00 00 00 v3 v2 v1 v0 */ | |
529 "movq (%0), %%mm6;" /* Load 8 Y Y7 Y6 Y5 Y4 Y3 Y2 Y1 Y0 */ | |
530 : : "r" (_py), "r" (_pu), "r" (_pv) | |
531 ); | |
532 | |
533 for (x = h_size >> 3; --x >= 0; ) { | |
534 /* this mmx assembly code deals with SINGLE scan line at a time, it convert 8 | |
535 pixels in each iteration */ | |
536 __asm__ __volatile__ ( | |
2734 | 537 YUV2RGB |
538 /* convert RGB plane to RGB packed format, | |
2732 | 539 mm0 -> B, mm1 -> R, mm2 -> G, mm3 -> 0, |
540 mm4 -> GB, mm5 -> AR pixel 4-7, | |
541 mm6 -> GB, mm7 -> AR pixel 0-3 */ | |
2734 | 542 "pxor %%mm3, %%mm3;" /* zero mm3 */ |
2732 | 543 |
2734 | 544 "movq %%mm0, %%mm6;" /* B7 B6 B5 B4 B3 B2 B1 B0 */ |
545 "movq %%mm1, %%mm7;" /* R7 R6 R5 R4 R3 R2 R1 R0 */ | |
2732 | 546 |
2734 | 547 "movq %%mm0, %%mm4;" /* B7 B6 B5 B4 B3 B2 B1 B0 */ |
548 "movq %%mm1, %%mm5;" /* R7 R6 R5 R4 R3 R2 R1 R0 */ | |
2732 | 549 |
2734 | 550 "punpcklbw %%mm2, %%mm6;" /* G3 B3 G2 B2 G1 B1 G0 B0 */ |
551 "punpcklbw %%mm3, %%mm7;" /* 00 R3 00 R2 00 R1 00 R0 */ | |
2732 | 552 |
2734 | 553 "punpcklwd %%mm7, %%mm6;" /* 00 R1 B1 G1 00 R0 B0 G0 */ |
554 MOVNTQ " %%mm6, (%3);" /* Store ARGB1 ARGB0 */ | |
2732 | 555 |
2734 | 556 "movq %%mm0, %%mm6;" /* B7 B6 B5 B4 B3 B2 B1 B0 */ |
557 "punpcklbw %%mm2, %%mm6;" /* G3 B3 G2 B2 G1 B1 G0 B0 */ | |
2732 | 558 |
2734 | 559 "punpckhwd %%mm7, %%mm6;" /* 00 R3 G3 B3 00 R2 B3 G2 */ |
560 MOVNTQ " %%mm6, 8 (%3);" /* Store ARGB3 ARGB2 */ | |
2732 | 561 |
2734 | 562 "punpckhbw %%mm2, %%mm4;" /* G7 B7 G6 B6 G5 B5 G4 B4 */ |
563 "punpckhbw %%mm3, %%mm5;" /* 00 R7 00 R6 00 R5 00 R4 */ | |
564 | |
565 "punpcklwd %%mm5, %%mm4;" /* 00 R5 B5 G5 00 R4 B4 G4 */ | |
566 MOVNTQ " %%mm4, 16 (%3);" /* Store ARGB5 ARGB4 */ | |
2732 | 567 |
2734 | 568 "movq %%mm0, %%mm4;" /* B7 B6 B5 B4 B3 B2 B1 B0 */ |
569 "punpckhbw %%mm2, %%mm4;" /* G7 B7 G6 B6 G5 B5 G4 B4 */ | |
2732 | 570 |
2734 | 571 "punpckhwd %%mm5, %%mm4;" /* 00 R7 G7 B7 00 R6 B6 G6 */ |
572 MOVNTQ " %%mm4, 24 (%3);" /* Store ARGB7 ARGB6 */ | |
2732 | 573 |
2734 | 574 "movd 4 (%1), %%mm0;" /* Load 4 Cb 00 00 00 00 u3 u2 u1 u0 */ |
575 "movd 4 (%2), %%mm1;" /* Load 4 Cr 00 00 00 00 v3 v2 v1 v0 */ | |
2732 | 576 |
2734 | 577 "pxor %%mm4, %%mm4;" /* zero mm4 */ |
578 "movq 8 (%0), %%mm6;" /* Load 8 Y Y7 Y6 Y5 Y4 Y3 Y2 Y1 Y0 */ | |
2732 | 579 |
580 : : "r" (_py), "r" (_pu), "r" (_pv), "r" (_image)); | |
581 | |
582 _py += 8; | |
583 _pu += 4; | |
584 _pv += 4; | |
585 _image += 32; | |
586 } | |
587 | |
588 if (!even) { | |
589 pu += uv_stride; | |
590 pv += uv_stride; | |
591 } | |
592 | |
593 py += y_stride; | |
594 image += rgb_stride; | |
595 | |
596 even = (!even); | |
597 } | |
598 | |
599 __asm__ __volatile__ (EMMS); | |
600 } | |
601 | |
602 yuv2rgb_fun yuv2rgb_init_mmx (int bpp, int mode) | |
603 { | |
2735 | 604 if (bpp == 15 && mode == MODE_RGB) return yuv420_rgb15_mmx; |
2732 | 605 if (bpp == 16 && mode == MODE_RGB) return yuv420_rgb16_mmx; |
2734 | 606 if (bpp == 24 && mode == MODE_RGB) return yuv420_rgb24_mmx; |
2732 | 607 if (bpp == 32 && mode == MODE_RGB) return yuv420_argb32_mmx; |
608 return NULL; // Fallback to C. | |
609 } | |
610 |