clib/libmpeg2/convert/rgb_mmx.c

filter: Statementstmt 0.0% 0 / 167 Branchbran 0.0% 0 / 44 Conditioncond n/a MC/DCmcdc n/a Subroutinesub n/a Podpod n/a totaltotal 0.0% 0 / 211 CC 0 SCAR 0
CC
0
Cov
0%
CRAP 0
« clib/libmpeg2/convert/rgb.c ↑ Summary clib/libmpeg2/convert/uyvy.c »
1 /*
2 * rgb_mmx.c
3 * Copyright (C) 2000-2003 Silicon Integrated System Corp.
4 * All Rights Reserved.
5 *
6 * Author: Olie Lho <ollie@sis.com.tw>
7 *
8 * This file is part of mpeg2dec, a free MPEG-2 video stream decoder.
9 * See http://libmpeg2.sourceforge.net/ for updates.
10 *
11 * mpeg2dec is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
15 *
16 * mpeg2dec is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
20 *
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24 */
25  
26 #include "config.h"
27  
28 #ifdef ARCH_X86
29  
30 #include <stdio.h>
31 #include <stdlib.h>
32 #include <inttypes.h>
33  
34 #include "mpeg2.h"
35 #include "mpeg2convert.h"
36 #include "convert_internal.h"
37 #include "attributes.h"
38 #include "mmx.h"
39  
40 #define CPU_MMXEXT 0
41 #define CPU_MMX 1
42  
43 /* CPU_MMXEXT/CPU_MMX adaptation layer */
44  
45 #define movntq(src,dest) \
46 do { \
47 if (cpu == CPU_MMXEXT) \
48 movntq_r2m (src, dest); \
49 else \
50 movq_r2m (src, dest); \
51 } while (0)
52  
53 0 static inline void mmx_yuv2rgb (uint8_t * py, uint8_t * pu, uint8_t * pv)
54 {
55 static mmx_t mmx_80w = {0x0080008000800080LL};
56 static mmx_t mmx_U_green = {0xf37df37df37df37dLL};
57 static mmx_t mmx_U_blue = {0x4093409340934093LL};
58 static mmx_t mmx_V_red = {0x3312331233123312LL};
59 static mmx_t mmx_V_green = {0xe5fce5fce5fce5fcLL};
60 static mmx_t mmx_10w = {0x1010101010101010LL};
61 static mmx_t mmx_00ffw = {0x00ff00ff00ff00ffLL};
62 static mmx_t mmx_Y_coeff = {0x253f253f253f253fLL};
63  
64 0 movd_m2r (*pu, mm0); /* mm0 = 00 00 00 00 u3 u2 u1 u0 */
65 0 movd_m2r (*pv, mm1); /* mm1 = 00 00 00 00 v3 v2 v1 v0 */
66 0 movq_m2r (*py, mm6); /* mm6 = Y7 Y6 Y5 Y4 Y3 Y2 Y1 Y0 */
67 0 pxor_r2r (mm4, mm4); /* mm4 = 0 */
68 /* XXX might do cache preload for image here */
69  
70 /*
71 * Do the multiply part of the conversion for even and odd pixels
72 * register usage:
73 * mm0 -> Cblue, mm1 -> Cred, mm2 -> Cgreen even pixels
74 * mm3 -> Cblue, mm4 -> Cred, mm5 -> Cgreen odd pixels
75 * mm6 -> Y even, mm7 -> Y odd
76 */
77  
78 0 punpcklbw_r2r (mm4, mm0); /* mm0 = u3 u2 u1 u0 */
79 0 punpcklbw_r2r (mm4, mm1); /* mm1 = v3 v2 v1 v0 */
80 0 psubsw_m2r (mmx_80w, mm0); /* u -= 128 */
81 0 psubsw_m2r (mmx_80w, mm1); /* v -= 128 */
82 0 psllw_i2r (3, mm0); /* promote precision */
83 0 psllw_i2r (3, mm1); /* promote precision */
84 0 movq_r2r (mm0, mm2); /* mm2 = u3 u2 u1 u0 */
85 0 movq_r2r (mm1, mm3); /* mm3 = v3 v2 v1 v0 */
86 0 pmulhw_m2r (mmx_U_green, mm2); /* mm2 = u * u_green */
87 0 pmulhw_m2r (mmx_V_green, mm3); /* mm3 = v * v_green */
88 0 pmulhw_m2r (mmx_U_blue, mm0); /* mm0 = chroma_b */
89 0 pmulhw_m2r (mmx_V_red, mm1); /* mm1 = chroma_r */
90 0 paddsw_r2r (mm3, mm2); /* mm2 = chroma_g */
91  
92 0 psubusb_m2r (mmx_10w, mm6); /* Y -= 16 */
93 0 movq_r2r (mm6, mm7); /* mm7 = Y7 Y6 Y5 Y4 Y3 Y2 Y1 Y0 */
94 0 pand_m2r (mmx_00ffw, mm6); /* mm6 = Y6 Y4 Y2 Y0 */
95 0 psrlw_i2r (8, mm7); /* mm7 = Y7 Y5 Y3 Y1 */
96 0 psllw_i2r (3, mm6); /* promote precision */
97 0 psllw_i2r (3, mm7); /* promote precision */
98 0 pmulhw_m2r (mmx_Y_coeff, mm6); /* mm6 = luma_rgb even */
99 0 pmulhw_m2r (mmx_Y_coeff, mm7); /* mm7 = luma_rgb odd */
100  
101 /*
102 * Do the addition part of the conversion for even and odd pixels
103 * register usage:
104 * mm0 -> Cblue, mm1 -> Cred, mm2 -> Cgreen even pixels
105 * mm3 -> Cblue, mm4 -> Cred, mm5 -> Cgreen odd pixels
106 * mm6 -> Y even, mm7 -> Y odd
107 */
108  
109 0 movq_r2r (mm0, mm3); /* mm3 = chroma_b */
110 0 movq_r2r (mm1, mm4); /* mm4 = chroma_r */
111 0 movq_r2r (mm2, mm5); /* mm5 = chroma_g */
112 0 paddsw_r2r (mm6, mm0); /* mm0 = B6 B4 B2 B0 */
113 0 paddsw_r2r (mm7, mm3); /* mm3 = B7 B5 B3 B1 */
114 0 paddsw_r2r (mm6, mm1); /* mm1 = R6 R4 R2 R0 */
115 0 paddsw_r2r (mm7, mm4); /* mm4 = R7 R5 R3 R1 */
116 0 paddsw_r2r (mm6, mm2); /* mm2 = G6 G4 G2 G0 */
117 0 paddsw_r2r (mm7, mm5); /* mm5 = G7 G5 G3 G1 */
118 0 packuswb_r2r (mm0, mm0); /* saturate to 0-255 */
119 0 packuswb_r2r (mm1, mm1); /* saturate to 0-255 */
120 0 packuswb_r2r (mm2, mm2); /* saturate to 0-255 */
121 0 packuswb_r2r (mm3, mm3); /* saturate to 0-255 */
122 0 packuswb_r2r (mm4, mm4); /* saturate to 0-255 */
123 0 packuswb_r2r (mm5, mm5); /* saturate to 0-255 */
124 0 punpcklbw_r2r (mm3, mm0); /* mm0 = B7 B6 B5 B4 B3 B2 B1 B0 */
125 0 punpcklbw_r2r (mm4, mm1); /* mm1 = R7 R6 R5 R4 R3 R2 R1 R0 */
126 0 punpcklbw_r2r (mm5, mm2); /* mm2 = G7 G6 G5 G4 G3 G2 G1 G0 */
127 0 }
128  
129 0 static inline void mmx_unpack_16rgb (uint8_t * image, const int cpu)
130 {
131 static mmx_t mmx_bluemask = {0xf8f8f8f8f8f8f8f8LL};
132 static mmx_t mmx_greenmask = {0xfcfcfcfcfcfcfcfcLL};
133 static mmx_t mmx_redmask = {0xf8f8f8f8f8f8f8f8LL};
134  
135 /*
136 * convert RGB plane to RGB 16 bits
137 * mm0 -> B, mm1 -> R, mm2 -> G
138 * mm4 -> GB, mm5 -> AR pixel 4-7
139 * mm6 -> GB, mm7 -> AR pixel 0-3
140 */
141  
142 0 pand_m2r (mmx_bluemask, mm0); /* mm0 = b7b6b5b4b3______ */
143 0 pand_m2r (mmx_greenmask, mm2); /* mm2 = g7g6g5g4g3g2____ */
144 0 pand_m2r (mmx_redmask, mm1); /* mm1 = r7r6r5r4r3______ */
145 0 psrlq_i2r (3, mm0); /* mm0 = ______b7b6b5b4b3 */
146 0 pxor_r2r (mm4, mm4); /* mm4 = 0 */
147 0 movq_r2r (mm0, mm5); /* mm5 = ______b7b6b5b4b3 */
148 0 movq_r2r (mm2, mm7); /* mm7 = g7g6g5g4g3g2____ */
149  
150 0 punpcklbw_r2r (mm4, mm2);
151 0 punpcklbw_r2r (mm1, mm0);
152 0 psllq_i2r (3, mm2);
153 0 por_r2r (mm2, mm0);
154 0 ▶ movntq (mm0, *image);
Branch: 1 branch
BranchTrueFalseTotal
movntq (mm0, *image); 0 0 0
155  
156 0 punpckhbw_r2r (mm4, mm7);
157 0 punpckhbw_r2r (mm1, mm5);
158 0 psllq_i2r (3, mm7);
159 0 por_r2r (mm7, mm5);
160 0 ▶ movntq (mm5, *(image+8));
Branch: 1 branch
BranchTrueFalseTotal
movntq (mm5, *(image+8)); 0 0 0
161 0 }
162  
163 0 static inline void mmx_unpack_32rgb (uint8_t * image, const int cpu)
164 {
165 /*
166 * convert RGB plane to RGB packed format,
167 * mm0 -> B, mm1 -> R, mm2 -> G, mm3 -> 0,
168 * mm4 -> GB, mm5 -> AR pixel 4-7,
169 * mm6 -> GB, mm7 -> AR pixel 0-3
170 */
171  
172 0 pxor_r2r (mm3, mm3);
173 0 movq_r2r (mm0, mm6);
174 0 movq_r2r (mm1, mm7);
175 0 movq_r2r (mm0, mm4);
176 0 movq_r2r (mm1, mm5);
177 0 punpcklbw_r2r (mm2, mm6);
178 0 punpcklbw_r2r (mm3, mm7);
179 0 punpcklwd_r2r (mm7, mm6);
180 0 ▶ movntq (mm6, *image);
Branch: 1 branch
BranchTrueFalseTotal
movntq (mm6, *image); 0 0 0
181 0 movq_r2r (mm0, mm6);
182 0 punpcklbw_r2r (mm2, mm6);
183 0 punpckhwd_r2r (mm7, mm6);
184 0 ▶ movntq (mm6, *(image+8));
Branch: 1 branch
BranchTrueFalseTotal
movntq (mm6, *(image+8)); 0 0 0
185 0 punpckhbw_r2r (mm2, mm4);
186 0 punpckhbw_r2r (mm3, mm5);
187 0 punpcklwd_r2r (mm5, mm4);
188 0 ▶ movntq (mm4, *(image+16));
Branch: 1 branch
BranchTrueFalseTotal
movntq (mm4, *(image+16)); 0 0 0
189 0 movq_r2r (mm0, mm4);
190 0 punpckhbw_r2r (mm2, mm4);
191 0 punpckhwd_r2r (mm5, mm4);
192 0 ▶ movntq (mm4, *(image+24));
Branch: 1 branch
BranchTrueFalseTotal
movntq (mm4, *(image+24)); 0 0 0
193 0 }
194  
195 0 static inline void rgb16 (void * const _id, uint8_t * const * src,
196 const unsigned int v_offset, const int cpu)
197 {
198 0 convert_rgb_t * const id = (convert_rgb_t *) _id;
199 uint8_t * dst;
200 uint8_t * py, * pu, * pv;
201 int i, j;
202  
203 0 dst = id->rgb_ptr + id->rgb_slice * v_offset;
204 0 py = src[0]; pu = src[1]; pv = src[2];
205  
206 0 i = 16;
207 do {
208 0 j = id->width;
209 do {
210 0 mmx_yuv2rgb (py, pu, pv);
211 0 mmx_unpack_16rgb (dst, cpu);
212 0 py += 8;
213 0 pu += 4;
214 0 pv += 4;
215 0 dst += 16;
216 0 ▶ } while (--j);
Branch: 1 branch
BranchTrueFalseTotal
} while (--j); 0 0 0
217  
218 0 dst += id->rgb_increm;
219 0 py += id->y_increm;
220 0 ▶ if (--i == id->field) {
Branch: 1 branch
BranchTrueFalseTotal
if (--i == id->field) { 0 0 0
221 0 dst = id->rgb_ptr + id->rgb_slice * (v_offset + 1);
222 0 py = src[0] + id->y_stride_frame;
223 0 pu = src[1] + id->uv_stride_frame;
224 0 pv = src[2] + id->uv_stride_frame;
225 0 ▶ } else if (! (i & id->chroma420)) {
Branch: 1 branch
BranchTrueFalseTotal
} else if (! (i & id->chroma420)) { 0 0 0
226 0 pu += id->uv_increm;
227 0 pv += id->uv_increm;
228 } else {
229 0 pu -= id->uv_stride_frame;
230 0 pv -= id->uv_stride_frame;
231 }
232 0 ▶ } while (i);
Branch: 1 branch
BranchTrueFalseTotal
} while (i); 0 0 0
233 0 }
234  
235 0 static inline void argb32 (void * const _id, uint8_t * const * src,
236 const unsigned int v_offset, const int cpu)
237 {
238 0 convert_rgb_t * const id = (convert_rgb_t *) _id;
239 uint8_t * dst;
240 uint8_t * py, * pu, * pv;
241 int i, j;
242  
243 0 dst = id->rgb_ptr + id->rgb_slice * v_offset;
244 0 py = src[0]; pu = src[1]; pv = src[2];
245  
246 0 i = 16;
247 do {
248 0 j = id->width;
249 do {
250 0 mmx_yuv2rgb (py, pu, pv);
251 0 mmx_unpack_32rgb (dst, cpu);
252 0 py += 8;
253 0 pu += 4;
254 0 pv += 4;
255 0 dst += 32;
256 0 ▶ } while (--j);
Branch: 1 branch
BranchTrueFalseTotal
} while (--j); 0 0 0
257  
258 0 dst += id->rgb_increm;
259 0 py += id->y_increm;
260 0 ▶ if (--i == id->field) {
Branch: 1 branch
BranchTrueFalseTotal
if (--i == id->field) { 0 0 0
261 0 dst = id->rgb_ptr + id->rgb_slice * (v_offset + 1);
262 0 py = src[0] + id->y_stride_frame;
263 0 pu = src[1] + id->uv_stride_frame;
264 0 pv = src[2] + id->uv_stride_frame;
265 0 ▶ } else if (! (i & id->chroma420)) {
Branch: 1 branch
BranchTrueFalseTotal
} else if (! (i & id->chroma420)) { 0 0 0
266 0 pu += id->uv_increm;
267 0 pv += id->uv_increm;
268 } else {
269 0 pu -= id->uv_stride_frame;
270 0 pv -= id->uv_stride_frame;
271 }
272 0 ▶ } while (i);
Branch: 1 branch
BranchTrueFalseTotal
} while (i); 0 0 0
273 0 }
274  
275 0 static void mmxext_rgb16 (void * id, uint8_t * const * src,
276 unsigned int v_offset)
277 {
278 0 rgb16 (id, src, v_offset, CPU_MMXEXT);
279 0 }
280  
281 0 static void mmxext_argb32 (void * id, uint8_t * const * src,
282 unsigned int v_offset)
283 {
284 0 argb32 (id, src, v_offset, CPU_MMXEXT);
285 0 }
286  
287 0 static void mmx_rgb16 (void * id, uint8_t * const * src, unsigned int v_offset)
288 {
289 0 rgb16 (id, src, v_offset, CPU_MMX);
290 0 }
291  
292 0 static void mmx_argb32 (void * id, uint8_t * const * src,
293 unsigned int v_offset)
294 {
295 0 argb32 (id, src, v_offset, CPU_MMX);
296 0 }
297  
298 0 mpeg2convert_copy_t * mpeg2convert_rgb_mmxext (int order, int bpp,
299 const mpeg2_sequence_t * seq)
300 {
301 0 ▶ if (order == MPEG2CONVERT_RGB && seq->chroma_width < seq->width) {
Branch: 2 branches
BranchTrueFalseTotal
if (order == MPEG2CONVERT_RGB && seq->chroma_width < seq->width) { 0 0 0
if (order == MPEG2CONVERT_RGB && seq->chroma_width < seq->width) { 0 0 0
302 0 ▶ if (bpp == 16)
Branch: 1 branch
BranchTrueFalseTotal
if (bpp == 16) 0 0 0
303 0 return mmxext_rgb16;
304 0 ▶ else if (bpp == 32)
Branch: 1 branch
BranchTrueFalseTotal
else if (bpp == 32) 0 0 0
305 0 return mmxext_argb32;
306 }
307 0 return NULL; /* Fallback to C */
308 }
309  
310 0 mpeg2convert_copy_t * mpeg2convert_rgb_mmx (int order, int bpp,
311 const mpeg2_sequence_t * seq)
312 {
313 0 ▶ if (order == MPEG2CONVERT_RGB && seq->chroma_width < seq->width) {
Branch: 2 branches
BranchTrueFalseTotal
if (order == MPEG2CONVERT_RGB && seq->chroma_width < seq->width) { 0 0 0
if (order == MPEG2CONVERT_RGB && seq->chroma_width < seq->width) { 0 0 0
314 0 ▶ if (bpp == 16)
Branch: 1 branch
BranchTrueFalseTotal
if (bpp == 16) 0 0 0
315 0 return mmx_rgb16;
316 0 ▶ else if (bpp == 32)
Branch: 1 branch
BranchTrueFalseTotal
else if (bpp == 32) 0 0 0
317 0 return mmx_argb32;
318 }
319 0 return NULL; /* Fallback to C */
320 }
321 #endif
« clib/libmpeg2/convert/rgb.c ↑ Summary clib/libmpeg2/convert/uyvy.c »