Mercurial > sdl-ios-xcode
annotate src/video/SDL_yuv_mmx.c @ 1374:998b7f9a287a
QuickTime depends on Carbon and ApplicationServices
author | Sam Lantinga <slouken@libsdl.org> |
---|---|
date | Sun, 19 Feb 2006 17:38:32 +0000 |
parents | 19418e4422cb |
children | d910939febfa |
rev | line source |
---|---|
0 | 1 /* |
2 SDL - Simple DirectMedia Layer | |
1312
c9b51268668f
Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents:
1148
diff
changeset
|
3 Copyright (C) 1997-2006 Sam Lantinga |
0 | 4 |
5 This library is free software; you can redistribute it and/or | |
1312
c9b51268668f
Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents:
1148
diff
changeset
|
6 modify it under the terms of the GNU Lesser General Public |
0 | 7 License as published by the Free Software Foundation; either |
1312
c9b51268668f
Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents:
1148
diff
changeset
|
8 version 2.1 of the License, or (at your option) any later version. |
0 | 9 |
10 This library is distributed in the hope that it will be useful, | |
11 but WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
1312
c9b51268668f
Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents:
1148
diff
changeset
|
13 Lesser General Public License for more details. |
0 | 14 |
1312
c9b51268668f
Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents:
1148
diff
changeset
|
15 You should have received a copy of the GNU Lesser General Public |
c9b51268668f
Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents:
1148
diff
changeset
|
16 License along with this library; if not, write to the Free Software |
c9b51268668f
Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents:
1148
diff
changeset
|
17 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
0 | 18 |
19 Sam Lantinga | |
252
e8157fcb3114
Updated the source with the correct e-mail address
Sam Lantinga <slouken@libsdl.org>
parents:
0
diff
changeset
|
20 slouken@libsdl.org |
0 | 21 */ |
22 | |
1358
c71e05b4dc2e
More header massaging... works great on Windows. ;-)
Sam Lantinga <slouken@libsdl.org>
parents:
1312
diff
changeset
|
23 #include "SDL_stdinc.h" |
0 | 24 |
1361
19418e4422cb
New configure-based build system. Still work in progress, but much improved
Sam Lantinga <slouken@libsdl.org>
parents:
1358
diff
changeset
|
25 #if i386 && __GNUC__ && SDL_ASSEMBLY_BLITTERS |
0 | 26 |
1148
63fb2da89a4b
Patched inline assembly to compile on gcc 4.0.1. Details are here:
Ryan C. Gordon <icculus@icculus.org>
parents:
1038
diff
changeset
|
27 #define ASM_ARRAY(x) x[] __asm__("_" #x) __attribute__((used)) |
1038
29d7db09776e
Ugly hack to make this work with gcc 2.x and 3.x
Sam Lantinga <slouken@libsdl.org>
parents:
949
diff
changeset
|
28 |
1148
63fb2da89a4b
Patched inline assembly to compile on gcc 4.0.1. Details are here:
Ryan C. Gordon <icculus@icculus.org>
parents:
1038
diff
changeset
|
29 static unsigned int ASM_ARRAY(MMX_0080w) = {0x00800080, 0x00800080}; |
63fb2da89a4b
Patched inline assembly to compile on gcc 4.0.1. Details are here:
Ryan C. Gordon <icculus@icculus.org>
parents:
1038
diff
changeset
|
30 static unsigned int ASM_ARRAY(MMX_00FFw) = {0x00ff00ff, 0x00ff00ff}; |
63fb2da89a4b
Patched inline assembly to compile on gcc 4.0.1. Details are here:
Ryan C. Gordon <icculus@icculus.org>
parents:
1038
diff
changeset
|
31 static unsigned int ASM_ARRAY(MMX_FF00w) = {0xff00ff00, 0xff00ff00}; |
63fb2da89a4b
Patched inline assembly to compile on gcc 4.0.1. Details are here:
Ryan C. Gordon <icculus@icculus.org>
parents:
1038
diff
changeset
|
32 |
63fb2da89a4b
Patched inline assembly to compile on gcc 4.0.1. Details are here:
Ryan C. Gordon <icculus@icculus.org>
parents:
1038
diff
changeset
|
33 static unsigned short ASM_ARRAY(MMX_Ycoeff) = {0x004a, 0x004a, 0x004a, 0x004a}; |
63fb2da89a4b
Patched inline assembly to compile on gcc 4.0.1. Details are here:
Ryan C. Gordon <icculus@icculus.org>
parents:
1038
diff
changeset
|
34 |
63fb2da89a4b
Patched inline assembly to compile on gcc 4.0.1. Details are here:
Ryan C. Gordon <icculus@icculus.org>
parents:
1038
diff
changeset
|
35 static unsigned short ASM_ARRAY(MMX_UbluRGB) = {0x0072, 0x0072, 0x0072, 0x0072}; |
63fb2da89a4b
Patched inline assembly to compile on gcc 4.0.1. Details are here:
Ryan C. Gordon <icculus@icculus.org>
parents:
1038
diff
changeset
|
36 static unsigned short ASM_ARRAY(MMX_VredRGB) = {0x0059, 0x0059, 0x0059, 0x0059}; |
63fb2da89a4b
Patched inline assembly to compile on gcc 4.0.1. Details are here:
Ryan C. Gordon <icculus@icculus.org>
parents:
1038
diff
changeset
|
37 static unsigned short ASM_ARRAY(MMX_UgrnRGB) = {0xffea, 0xffea, 0xffea, 0xffea}; |
63fb2da89a4b
Patched inline assembly to compile on gcc 4.0.1. Details are here:
Ryan C. Gordon <icculus@icculus.org>
parents:
1038
diff
changeset
|
38 static unsigned short ASM_ARRAY(MMX_VgrnRGB) = {0xffd2, 0xffd2, 0xffd2, 0xffd2}; |
0 | 39 |
1148
63fb2da89a4b
Patched inline assembly to compile on gcc 4.0.1. Details are here:
Ryan C. Gordon <icculus@icculus.org>
parents:
1038
diff
changeset
|
40 static unsigned short ASM_ARRAY(MMX_Ublu5x5) = {0x0081, 0x0081, 0x0081, 0x0081}; |
63fb2da89a4b
Patched inline assembly to compile on gcc 4.0.1. Details are here:
Ryan C. Gordon <icculus@icculus.org>
parents:
1038
diff
changeset
|
41 static unsigned short ASM_ARRAY(MMX_Vred5x5) = {0x0066, 0x0066, 0x0066, 0x0066}; |
63fb2da89a4b
Patched inline assembly to compile on gcc 4.0.1. Details are here:
Ryan C. Gordon <icculus@icculus.org>
parents:
1038
diff
changeset
|
42 static unsigned short ASM_ARRAY(MMX_Ugrn555) = {0xffe7, 0xffe7, 0xffe7, 0xffe7}; |
63fb2da89a4b
Patched inline assembly to compile on gcc 4.0.1. Details are here:
Ryan C. Gordon <icculus@icculus.org>
parents:
1038
diff
changeset
|
43 static unsigned short ASM_ARRAY(MMX_Vgrn555) = {0xffcc, 0xffcc, 0xffcc, 0xffcc}; |
63fb2da89a4b
Patched inline assembly to compile on gcc 4.0.1. Details are here:
Ryan C. Gordon <icculus@icculus.org>
parents:
1038
diff
changeset
|
44 static unsigned short ASM_ARRAY(MMX_Ugrn565) = {0xffe8, 0xffe8, 0xffe8, 0xffe8}; |
63fb2da89a4b
Patched inline assembly to compile on gcc 4.0.1. Details are here:
Ryan C. Gordon <icculus@icculus.org>
parents:
1038
diff
changeset
|
45 static unsigned short ASM_ARRAY(MMX_Vgrn565) = {0xffcd, 0xffcd, 0xffcd, 0xffcd}; |
0 | 46 |
1148
63fb2da89a4b
Patched inline assembly to compile on gcc 4.0.1. Details are here:
Ryan C. Gordon <icculus@icculus.org>
parents:
1038
diff
changeset
|
47 static unsigned short ASM_ARRAY(MMX_red555) = {0x7c00, 0x7c00, 0x7c00, 0x7c00}; |
63fb2da89a4b
Patched inline assembly to compile on gcc 4.0.1. Details are here:
Ryan C. Gordon <icculus@icculus.org>
parents:
1038
diff
changeset
|
48 static unsigned short ASM_ARRAY(MMX_red565) = {0xf800, 0xf800, 0xf800, 0xf800}; |
63fb2da89a4b
Patched inline assembly to compile on gcc 4.0.1. Details are here:
Ryan C. Gordon <icculus@icculus.org>
parents:
1038
diff
changeset
|
49 static unsigned short ASM_ARRAY(MMX_grn555) = {0x03e0, 0x03e0, 0x03e0, 0x03e0}; |
63fb2da89a4b
Patched inline assembly to compile on gcc 4.0.1. Details are here:
Ryan C. Gordon <icculus@icculus.org>
parents:
1038
diff
changeset
|
50 static unsigned short ASM_ARRAY(MMX_grn565) = {0x07e0, 0x07e0, 0x07e0, 0x07e0}; |
63fb2da89a4b
Patched inline assembly to compile on gcc 4.0.1. Details are here:
Ryan C. Gordon <icculus@icculus.org>
parents:
1038
diff
changeset
|
51 static unsigned short ASM_ARRAY(MMX_blu5x5) = {0x001f, 0x001f, 0x001f, 0x001f}; |
0 | 52 |
53 /** | |
54 This MMX assembler is my first assembler/MMX program ever. | |
55 Thus it maybe buggy. | |
56 Send patches to: | |
57 mvogt@rhrk.uni-kl.de | |
58 | |
59 After it worked fine I have "obfuscated" the code a bit to have | |
60 more parallism in the MMX units. This means I moved | |
61 initilisation around and delayed other instruction. | |
62 Performance measurement did not show that this brought any advantage | |
63 but in theory it _should_ be faster this way. | |
64 | |
65 The overall performanve gain to the C based dither was 30%-40%. | |
66 The MMX routine calculates 256bit=8RGB values in each cycle | |
67 (4 for row1 & 4 for row2) | |
68 | |
69 The red/green/blue.. coefficents are taken from the mpeg_play | |
70 player. They look nice, but I dont know if you can have | |
71 better values, to avoid integer rounding errors. | |
72 | |
73 | |
74 IMPORTANT: | |
75 ========== | |
76 | |
77 It is a requirement that the cr/cb/lum are 8 byte aligned and | |
78 the out are 16byte aligned or you will/may get segfaults | |
79 | |
80 */ | |
81 | |
82 void ColorRGBDitherYV12MMX1X( int *colortab, Uint32 *rgb_2_pix, | |
83 unsigned char *lum, unsigned char *cr, | |
84 unsigned char *cb, unsigned char *out, | |
85 int rows, int cols, int mod ) | |
86 { | |
87 Uint32 *row1; | |
88 Uint32 *row2; | |
89 | |
90 unsigned char* y = lum +cols*rows; // Pointer to the end | |
91 int x=0; | |
92 row1 = (Uint32 *)out; // 32 bit target | |
93 row2 = (Uint32 *)out+cols+mod; // start of second row | |
94 mod = (mod+cols+mod)*4; // increment for row1 in byte | |
95 | |
96 __asm__ __volatile__ ( | |
97 /* We don't really care about PIC - the code should be rewritten to use | |
98 relative addressing for the static tables, so right now we take the | |
99 COW hit on the pages this code resides. Big deal. | |
100 This spill is just to reduce register pressure in the PIC case. */ | |
101 "pushl %%ebx\n" | |
102 "movl %0, %%ebx\n" | |
103 | |
104 ".align 8\n" | |
105 "1:\n" | |
106 | |
107 // create Cr (result in mm1) | |
108 "movd (%%ebx), %%mm1\n" // 0 0 0 0 v3 v2 v1 v0 | |
109 "pxor %%mm7,%%mm7\n" // 00 00 00 00 00 00 00 00 | |
110 "movd (%2), %%mm2\n" // 0 0 0 0 l3 l2 l1 l0 | |
111 "punpcklbw %%mm7,%%mm1\n" // 0 v3 0 v2 00 v1 00 v0 | |
112 "punpckldq %%mm1,%%mm1\n" // 00 v1 00 v0 00 v1 00 v0 | |
1038
29d7db09776e
Ugly hack to make this work with gcc 2.x and 3.x
Sam Lantinga <slouken@libsdl.org>
parents:
949
diff
changeset
|
113 "psubw _MMX_0080w,%%mm1\n" // mm1-128:r1 r1 r0 r0 r1 r1 r0 r0 |
0 | 114 |
115 // create Cr_g (result in mm0) | |
116 "movq %%mm1,%%mm0\n" // r1 r1 r0 r0 r1 r1 r0 r0 | |
1038
29d7db09776e
Ugly hack to make this work with gcc 2.x and 3.x
Sam Lantinga <slouken@libsdl.org>
parents:
949
diff
changeset
|
117 "pmullw _MMX_VgrnRGB,%%mm0\n"// red*-46dec=0.7136*64 |
29d7db09776e
Ugly hack to make this work with gcc 2.x and 3.x
Sam Lantinga <slouken@libsdl.org>
parents:
949
diff
changeset
|
118 "pmullw _MMX_VredRGB,%%mm1\n"// red*89dec=1.4013*64 |
0 | 119 "psraw $6, %%mm0\n" // red=red/64 |
120 "psraw $6, %%mm1\n" // red=red/64 | |
121 | |
122 // create L1 L2 (result in mm2,mm4) | |
123 // L2=lum+cols | |
124 "movq (%2,%4),%%mm3\n" // 0 0 0 0 L3 L2 L1 L0 | |
125 "punpckldq %%mm3,%%mm2\n" // L3 L2 L1 L0 l3 l2 l1 l0 | |
126 "movq %%mm2,%%mm4\n" // L3 L2 L1 L0 l3 l2 l1 l0 | |
1038
29d7db09776e
Ugly hack to make this work with gcc 2.x and 3.x
Sam Lantinga <slouken@libsdl.org>
parents:
949
diff
changeset
|
127 "pand _MMX_FF00w,%%mm2\n" // L3 0 L1 0 l3 0 l1 0 |
29d7db09776e
Ugly hack to make this work with gcc 2.x and 3.x
Sam Lantinga <slouken@libsdl.org>
parents:
949
diff
changeset
|
128 "pand _MMX_00FFw,%%mm4\n" // 0 L2 0 L0 0 l2 0 l0 |
0 | 129 "psrlw $8,%%mm2\n" // 0 L3 0 L1 0 l3 0 l1 |
130 | |
131 // create R (result in mm6) | |
132 "movq %%mm2,%%mm5\n" // 0 L3 0 L1 0 l3 0 l1 | |
133 "movq %%mm4,%%mm6\n" // 0 L2 0 L0 0 l2 0 l0 | |
134 "paddsw %%mm1, %%mm5\n" // lum1+red:x R3 x R1 x r3 x r1 | |
135 "paddsw %%mm1, %%mm6\n" // lum1+red:x R2 x R0 x r2 x r0 | |
136 "packuswb %%mm5,%%mm5\n" // R3 R1 r3 r1 R3 R1 r3 r1 | |
137 "packuswb %%mm6,%%mm6\n" // R2 R0 r2 r0 R2 R0 r2 r0 | |
138 "pxor %%mm7,%%mm7\n" // 00 00 00 00 00 00 00 00 | |
139 "punpcklbw %%mm5,%%mm6\n" // R3 R2 R1 R0 r3 r2 r1 r0 | |
140 | |
141 // create Cb (result in mm1) | |
142 "movd (%1), %%mm1\n" // 0 0 0 0 u3 u2 u1 u0 | |
143 "punpcklbw %%mm7,%%mm1\n" // 0 u3 0 u2 00 u1 00 u0 | |
144 "punpckldq %%mm1,%%mm1\n" // 00 u1 00 u0 00 u1 00 u0 | |
1038
29d7db09776e
Ugly hack to make this work with gcc 2.x and 3.x
Sam Lantinga <slouken@libsdl.org>
parents:
949
diff
changeset
|
145 "psubw _MMX_0080w,%%mm1\n" // mm1-128:u1 u1 u0 u0 u1 u1 u0 u0 |
0 | 146 // create Cb_g (result in mm5) |
147 "movq %%mm1,%%mm5\n" // u1 u1 u0 u0 u1 u1 u0 u0 | |
1038
29d7db09776e
Ugly hack to make this work with gcc 2.x and 3.x
Sam Lantinga <slouken@libsdl.org>
parents:
949
diff
changeset
|
148 "pmullw _MMX_UgrnRGB,%%mm5\n" // blue*-109dec=1.7129*64 |
29d7db09776e
Ugly hack to make this work with gcc 2.x and 3.x
Sam Lantinga <slouken@libsdl.org>
parents:
949
diff
changeset
|
149 "pmullw _MMX_UbluRGB,%%mm1\n" // blue*114dec=1.78125*64 |
0 | 150 "psraw $6, %%mm5\n" // blue=red/64 |
151 "psraw $6, %%mm1\n" // blue=blue/64 | |
152 | |
153 // create G (result in mm7) | |
154 "movq %%mm2,%%mm3\n" // 0 L3 0 L1 0 l3 0 l1 | |
155 "movq %%mm4,%%mm7\n" // 0 L2 0 L0 0 l2 0 l1 | |
156 "paddsw %%mm5, %%mm3\n" // lum1+Cb_g:x G3t x G1t x g3t x g1t | |
157 "paddsw %%mm5, %%mm7\n" // lum1+Cb_g:x G2t x G0t x g2t x g0t | |
158 "paddsw %%mm0, %%mm3\n" // lum1+Cr_g:x G3 x G1 x g3 x g1 | |
159 "paddsw %%mm0, %%mm7\n" // lum1+blue:x G2 x G0 x g2 x g0 | |
160 "packuswb %%mm3,%%mm3\n" // G3 G1 g3 g1 G3 G1 g3 g1 | |
161 "packuswb %%mm7,%%mm7\n" // G2 G0 g2 g0 G2 G0 g2 g0 | |
162 "punpcklbw %%mm3,%%mm7\n" // G3 G2 G1 G0 g3 g2 g1 g0 | |
163 | |
164 // create B (result in mm5) | |
165 "movq %%mm2,%%mm3\n" // 0 L3 0 L1 0 l3 0 l1 | |
166 "movq %%mm4,%%mm5\n" // 0 L2 0 L0 0 l2 0 l1 | |
167 "paddsw %%mm1, %%mm3\n" // lum1+blue:x B3 x B1 x b3 x b1 | |
168 "paddsw %%mm1, %%mm5\n" // lum1+blue:x B2 x B0 x b2 x b0 | |
169 "packuswb %%mm3,%%mm3\n" // B3 B1 b3 b1 B3 B1 b3 b1 | |
170 "packuswb %%mm5,%%mm5\n" // B2 B0 b2 b0 B2 B0 b2 b0 | |
171 "punpcklbw %%mm3,%%mm5\n" // B3 B2 B1 B0 b3 b2 b1 b0 | |
172 | |
173 // fill destination row1 (needed are mm6=Rr,mm7=Gg,mm5=Bb) | |
174 | |
175 "pxor %%mm2,%%mm2\n" // 0 0 0 0 0 0 0 0 | |
176 "pxor %%mm4,%%mm4\n" // 0 0 0 0 0 0 0 0 | |
177 "movq %%mm6,%%mm1\n" // R3 R2 R1 R0 r3 r2 r1 r0 | |
178 "movq %%mm5,%%mm3\n" // B3 B2 B1 B0 b3 b2 b1 b0 | |
179 // process lower lum | |
180 "punpcklbw %%mm4,%%mm1\n" // 0 r3 0 r2 0 r1 0 r0 | |
181 "punpcklbw %%mm4,%%mm3\n" // 0 b3 0 b2 0 b1 0 b0 | |
182 "movq %%mm1,%%mm2\n" // 0 r3 0 r2 0 r1 0 r0 | |
183 "movq %%mm3,%%mm0\n" // 0 b3 0 b2 0 b1 0 b0 | |
184 "punpcklwd %%mm1,%%mm3\n" // 0 r1 0 b1 0 r0 0 b0 | |
185 "punpckhwd %%mm2,%%mm0\n" // 0 r3 0 b3 0 r2 0 b2 | |
186 | |
187 "pxor %%mm2,%%mm2\n" // 0 0 0 0 0 0 0 0 | |
188 "movq %%mm7,%%mm1\n" // G3 G2 G1 G0 g3 g2 g1 g0 | |
189 "punpcklbw %%mm1,%%mm2\n" // g3 0 g2 0 g1 0 g0 0 | |
190 "punpcklwd %%mm4,%%mm2\n" // 0 0 g1 0 0 0 g0 0 | |
191 "por %%mm3, %%mm2\n" // 0 r1 g1 b1 0 r0 g0 b0 | |
192 "movq %%mm2,(%3)\n" // wrote out ! row1 | |
193 | |
194 "pxor %%mm2,%%mm2\n" // 0 0 0 0 0 0 0 0 | |
195 "punpcklbw %%mm1,%%mm4\n" // g3 0 g2 0 g1 0 g0 0 | |
196 "punpckhwd %%mm2,%%mm4\n" // 0 0 g3 0 0 0 g2 0 | |
197 "por %%mm0, %%mm4\n" // 0 r3 g3 b3 0 r2 g2 b2 | |
198 "movq %%mm4,8(%3)\n" // wrote out ! row1 | |
199 | |
200 // fill destination row2 (needed are mm6=Rr,mm7=Gg,mm5=Bb) | |
201 // this can be done "destructive" | |
202 "pxor %%mm2,%%mm2\n" // 0 0 0 0 0 0 0 0 | |
203 "punpckhbw %%mm2,%%mm6\n" // 0 R3 0 R2 0 R1 0 R0 | |
204 "punpckhbw %%mm1,%%mm5\n" // G3 B3 G2 B2 G1 B1 G0 B0 | |
205 "movq %%mm5,%%mm1\n" // G3 B3 G2 B2 G1 B1 G0 B0 | |
206 "punpcklwd %%mm6,%%mm1\n" // 0 R1 G1 B1 0 R0 G0 B0 | |
207 "movq %%mm1,(%5)\n" // wrote out ! row2 | |
208 "punpckhwd %%mm6,%%mm5\n" // 0 R3 G3 B3 0 R2 G2 B2 | |
209 "movq %%mm5,8(%5)\n" // wrote out ! row2 | |
210 | |
211 "addl $4,%2\n" // lum+4 | |
212 "leal 16(%3),%3\n" // row1+16 | |
213 "leal 16(%5),%5\n" // row2+16 | |
214 "addl $2, %%ebx\n" // cr+2 | |
215 "addl $2, %1\n" // cb+2 | |
216 | |
217 "addl $4,%6\n" // x+4 | |
218 "cmpl %4,%6\n" | |
219 | |
220 "jl 1b\n" | |
221 "addl %4, %2\n" // lum += cols | |
222 "addl %8, %3\n" // row1+= mod | |
223 "addl %8, %5\n" // row2+= mod | |
224 "movl $0, %6\n" // x=0 | |
225 "cmpl %7, %2\n" | |
226 "jl 1b\n" | |
227 "emms\n" | |
228 "popl %%ebx\n" | |
229 : | |
230 : "m" (cr), "r"(cb),"r"(lum), | |
1148
63fb2da89a4b
Patched inline assembly to compile on gcc 4.0.1. Details are here:
Ryan C. Gordon <icculus@icculus.org>
parents:
1038
diff
changeset
|
231 "r"(row1),"r"(cols),"r"(row2),"m"(x),"m"(y),"m"(mod)); |
0 | 232 } |
233 | |
234 void Color565DitherYV12MMX1X( int *colortab, Uint32 *rgb_2_pix, | |
235 unsigned char *lum, unsigned char *cr, | |
236 unsigned char *cb, unsigned char *out, | |
237 int rows, int cols, int mod ) | |
238 { | |
239 Uint16 *row1; | |
240 Uint16 *row2; | |
241 | |
242 unsigned char* y = lum +cols*rows; /* Pointer to the end */ | |
243 int x=0; | |
244 row1 = (Uint16 *)out; /* 16 bit target */ | |
245 row2 = (Uint16 *)out+cols+mod; /* start of second row */ | |
246 mod = (mod+cols+mod)*2; /* increment for row1 in byte */ | |
247 | |
248 | |
249 __asm__ __volatile__( | |
250 "pushl %%ebx\n" | |
251 "movl %0, %%ebx\n" | |
252 | |
253 ".align 8\n" | |
254 "1:\n" | |
255 "movd (%1), %%mm0\n" // 4 Cb 0 0 0 0 u3 u2 u1 u0 | |
256 "pxor %%mm7, %%mm7\n" | |
257 "movd (%%ebx), %%mm1\n" // 4 Cr 0 0 0 0 v3 v2 v1 v0 | |
258 "punpcklbw %%mm7, %%mm0\n" // 4 W cb 0 u3 0 u2 0 u1 0 u0 | |
259 "punpcklbw %%mm7, %%mm1\n" // 4 W cr 0 v3 0 v2 0 v1 0 v0 | |
1038
29d7db09776e
Ugly hack to make this work with gcc 2.x and 3.x
Sam Lantinga <slouken@libsdl.org>
parents:
949
diff
changeset
|
260 "psubw _MMX_0080w, %%mm0\n" |
29d7db09776e
Ugly hack to make this work with gcc 2.x and 3.x
Sam Lantinga <slouken@libsdl.org>
parents:
949
diff
changeset
|
261 "psubw _MMX_0080w, %%mm1\n" |
0 | 262 "movq %%mm0, %%mm2\n" // Cb 0 u3 0 u2 0 u1 0 u0 |
263 "movq %%mm1, %%mm3\n" // Cr | |
1038
29d7db09776e
Ugly hack to make this work with gcc 2.x and 3.x
Sam Lantinga <slouken@libsdl.org>
parents:
949
diff
changeset
|
264 "pmullw _MMX_Ugrn565, %%mm2\n" // Cb2green 0 R3 0 R2 0 R1 0 R0 |
0 | 265 "movq (%2), %%mm6\n" // L1 l7 L6 L5 L4 L3 L2 L1 L0 |
1038
29d7db09776e
Ugly hack to make this work with gcc 2.x and 3.x
Sam Lantinga <slouken@libsdl.org>
parents:
949
diff
changeset
|
266 "pmullw _MMX_Ublu5x5, %%mm0\n" // Cb2blue |
29d7db09776e
Ugly hack to make this work with gcc 2.x and 3.x
Sam Lantinga <slouken@libsdl.org>
parents:
949
diff
changeset
|
267 "pand _MMX_00FFw, %%mm6\n" // L1 00 L6 00 L4 00 L2 00 L0 |
29d7db09776e
Ugly hack to make this work with gcc 2.x and 3.x
Sam Lantinga <slouken@libsdl.org>
parents:
949
diff
changeset
|
268 "pmullw _MMX_Vgrn565, %%mm3\n" // Cr2green |
0 | 269 "movq (%2), %%mm7\n" // L2 |
1038
29d7db09776e
Ugly hack to make this work with gcc 2.x and 3.x
Sam Lantinga <slouken@libsdl.org>
parents:
949
diff
changeset
|
270 "pmullw _MMX_Vred5x5, %%mm1\n" // Cr2red |
0 | 271 "psrlw $8, %%mm7\n" // L2 00 L7 00 L5 00 L3 00 L1 |
1038
29d7db09776e
Ugly hack to make this work with gcc 2.x and 3.x
Sam Lantinga <slouken@libsdl.org>
parents:
949
diff
changeset
|
272 "pmullw _MMX_Ycoeff, %%mm6\n" // lum1 |
0 | 273 "paddw %%mm3, %%mm2\n" // Cb2green + Cr2green == green |
1038
29d7db09776e
Ugly hack to make this work with gcc 2.x and 3.x
Sam Lantinga <slouken@libsdl.org>
parents:
949
diff
changeset
|
274 "pmullw _MMX_Ycoeff, %%mm7\n" // lum2 |
0 | 275 |
276 "movq %%mm6, %%mm4\n" // lum1 | |
277 "paddw %%mm0, %%mm6\n" // lum1 +blue 00 B6 00 B4 00 B2 00 B0 | |
278 "movq %%mm4, %%mm5\n" // lum1 | |
279 "paddw %%mm1, %%mm4\n" // lum1 +red 00 R6 00 R4 00 R2 00 R0 | |
280 "paddw %%mm2, %%mm5\n" // lum1 +green 00 G6 00 G4 00 G2 00 G0 | |
281 "psraw $6, %%mm4\n" // R1 0 .. 64 | |
282 "movq %%mm7, %%mm3\n" // lum2 00 L7 00 L5 00 L3 00 L1 | |
283 "psraw $6, %%mm5\n" // G1 - .. + | |
284 "paddw %%mm0, %%mm7\n" // Lum2 +blue 00 B7 00 B5 00 B3 00 B1 | |
285 "psraw $6, %%mm6\n" // B1 0 .. 64 | |
286 "packuswb %%mm4, %%mm4\n" // R1 R1 | |
287 "packuswb %%mm5, %%mm5\n" // G1 G1 | |
288 "packuswb %%mm6, %%mm6\n" // B1 B1 | |
289 "punpcklbw %%mm4, %%mm4\n" | |
290 "punpcklbw %%mm5, %%mm5\n" | |
291 | |
1038
29d7db09776e
Ugly hack to make this work with gcc 2.x and 3.x
Sam Lantinga <slouken@libsdl.org>
parents:
949
diff
changeset
|
292 "pand _MMX_red565, %%mm4\n" |
0 | 293 "psllw $3, %%mm5\n" // GREEN 1 |
294 "punpcklbw %%mm6, %%mm6\n" | |
1038
29d7db09776e
Ugly hack to make this work with gcc 2.x and 3.x
Sam Lantinga <slouken@libsdl.org>
parents:
949
diff
changeset
|
295 "pand _MMX_grn565, %%mm5\n" |
29d7db09776e
Ugly hack to make this work with gcc 2.x and 3.x
Sam Lantinga <slouken@libsdl.org>
parents:
949
diff
changeset
|
296 "pand _MMX_red565, %%mm6\n" |
0 | 297 "por %%mm5, %%mm4\n" // |
298 "psrlw $11, %%mm6\n" // BLUE 1 | |
299 "movq %%mm3, %%mm5\n" // lum2 | |
300 "paddw %%mm1, %%mm3\n" // lum2 +red 00 R7 00 R5 00 R3 00 R1 | |
301 "paddw %%mm2, %%mm5\n" // lum2 +green 00 G7 00 G5 00 G3 00 G1 | |
302 "psraw $6, %%mm3\n" // R2 | |
303 "por %%mm6, %%mm4\n" // MM4 | |
304 "psraw $6, %%mm5\n" // G2 | |
305 "movq (%2, %4), %%mm6\n" // L3 load lum2 | |
306 "psraw $6, %%mm7\n" | |
307 "packuswb %%mm3, %%mm3\n" | |
308 "packuswb %%mm5, %%mm5\n" | |
309 "packuswb %%mm7, %%mm7\n" | |
1038
29d7db09776e
Ugly hack to make this work with gcc 2.x and 3.x
Sam Lantinga <slouken@libsdl.org>
parents:
949
diff
changeset
|
310 "pand _MMX_00FFw, %%mm6\n" // L3 |
0 | 311 "punpcklbw %%mm3, %%mm3\n" |
312 "punpcklbw %%mm5, %%mm5\n" | |
1038
29d7db09776e
Ugly hack to make this work with gcc 2.x and 3.x
Sam Lantinga <slouken@libsdl.org>
parents:
949
diff
changeset
|
313 "pmullw _MMX_Ycoeff, %%mm6\n" // lum3 |
0 | 314 "punpcklbw %%mm7, %%mm7\n" |
315 "psllw $3, %%mm5\n" // GREEN 2 | |
1038
29d7db09776e
Ugly hack to make this work with gcc 2.x and 3.x
Sam Lantinga <slouken@libsdl.org>
parents:
949
diff
changeset
|
316 "pand _MMX_red565, %%mm7\n" |
29d7db09776e
Ugly hack to make this work with gcc 2.x and 3.x
Sam Lantinga <slouken@libsdl.org>
parents:
949
diff
changeset
|
317 "pand _MMX_red565, %%mm3\n" |
0 | 318 "psrlw $11, %%mm7\n" // BLUE 2 |
1038
29d7db09776e
Ugly hack to make this work with gcc 2.x and 3.x
Sam Lantinga <slouken@libsdl.org>
parents:
949
diff
changeset
|
319 "pand _MMX_grn565, %%mm5\n" |
0 | 320 "por %%mm7, %%mm3\n" |
321 "movq (%2,%4), %%mm7\n" // L4 load lum2 | |
322 "por %%mm5, %%mm3\n" // | |
323 "psrlw $8, %%mm7\n" // L4 | |
324 "movq %%mm4, %%mm5\n" | |
325 "punpcklwd %%mm3, %%mm4\n" | |
1038
29d7db09776e
Ugly hack to make this work with gcc 2.x and 3.x
Sam Lantinga <slouken@libsdl.org>
parents:
949
diff
changeset
|
326 "pmullw _MMX_Ycoeff, %%mm7\n" // lum4 |
0 | 327 "punpckhwd %%mm3, %%mm5\n" |
328 | |
329 "movq %%mm4, (%3)\n" // write row1 | |
330 "movq %%mm5, 8(%3)\n" // write row1 | |
331 | |
332 "movq %%mm6, %%mm4\n" // Lum3 | |
333 "paddw %%mm0, %%mm6\n" // Lum3 +blue | |
334 | |
335 "movq %%mm4, %%mm5\n" // Lum3 | |
336 "paddw %%mm1, %%mm4\n" // Lum3 +red | |
337 "paddw %%mm2, %%mm5\n" // Lum3 +green | |
338 "psraw $6, %%mm4\n" | |
339 "movq %%mm7, %%mm3\n" // Lum4 | |
340 "psraw $6, %%mm5\n" | |
341 "paddw %%mm0, %%mm7\n" // Lum4 +blue | |
342 "psraw $6, %%mm6\n" // Lum3 +blue | |
343 "movq %%mm3, %%mm0\n" // Lum4 | |
344 "packuswb %%mm4, %%mm4\n" | |
345 "paddw %%mm1, %%mm3\n" // Lum4 +red | |
346 "packuswb %%mm5, %%mm5\n" | |
347 "paddw %%mm2, %%mm0\n" // Lum4 +green | |
348 "packuswb %%mm6, %%mm6\n" | |
349 "punpcklbw %%mm4, %%mm4\n" | |
350 "punpcklbw %%mm5, %%mm5\n" | |
351 "punpcklbw %%mm6, %%mm6\n" | |
352 "psllw $3, %%mm5\n" // GREEN 3 | |
1038
29d7db09776e
Ugly hack to make this work with gcc 2.x and 3.x
Sam Lantinga <slouken@libsdl.org>
parents:
949
diff
changeset
|
353 "pand _MMX_red565, %%mm4\n" |
0 | 354 "psraw $6, %%mm3\n" // psr 6 |
355 "psraw $6, %%mm0\n" | |
1038
29d7db09776e
Ugly hack to make this work with gcc 2.x and 3.x
Sam Lantinga <slouken@libsdl.org>
parents:
949
diff
changeset
|
356 "pand _MMX_red565, %%mm6\n" // BLUE |
29d7db09776e
Ugly hack to make this work with gcc 2.x and 3.x
Sam Lantinga <slouken@libsdl.org>
parents:
949
diff
changeset
|
357 "pand _MMX_grn565, %%mm5\n" |
0 | 358 "psrlw $11, %%mm6\n" // BLUE 3 |
359 "por %%mm5, %%mm4\n" | |
360 "psraw $6, %%mm7\n" | |
361 "por %%mm6, %%mm4\n" | |
362 "packuswb %%mm3, %%mm3\n" | |
363 "packuswb %%mm0, %%mm0\n" | |
364 "packuswb %%mm7, %%mm7\n" | |
365 "punpcklbw %%mm3, %%mm3\n" | |
366 "punpcklbw %%mm0, %%mm0\n" | |
367 "punpcklbw %%mm7, %%mm7\n" | |
1038
29d7db09776e
Ugly hack to make this work with gcc 2.x and 3.x
Sam Lantinga <slouken@libsdl.org>
parents:
949
diff
changeset
|
368 "pand _MMX_red565, %%mm3\n" |
29d7db09776e
Ugly hack to make this work with gcc 2.x and 3.x
Sam Lantinga <slouken@libsdl.org>
parents:
949
diff
changeset
|
369 "pand _MMX_red565, %%mm7\n" // BLUE |
0 | 370 "psllw $3, %%mm0\n" // GREEN 4 |
371 "psrlw $11, %%mm7\n" | |
1038
29d7db09776e
Ugly hack to make this work with gcc 2.x and 3.x
Sam Lantinga <slouken@libsdl.org>
parents:
949
diff
changeset
|
372 "pand _MMX_grn565, %%mm0\n" |
0 | 373 "por %%mm7, %%mm3\n" |
374 "por %%mm0, %%mm3\n" | |
375 | |
376 "movq %%mm4, %%mm5\n" | |
377 | |
378 "punpcklwd %%mm3, %%mm4\n" | |
379 "punpckhwd %%mm3, %%mm5\n" | |
380 | |
381 "movq %%mm4, (%5)\n" | |
382 "movq %%mm5, 8(%5)\n" | |
383 | |
384 "addl $8, %6\n" | |
385 "addl $8, %2\n" | |
386 "addl $4, %%ebx\n" | |
387 "addl $4, %1\n" | |
388 "cmpl %4, %6\n" | |
389 "leal 16(%3), %3\n" | |
390 "leal 16(%5),%5\n" // row2+16 | |
391 | |
392 | |
393 "jl 1b\n" | |
394 "addl %4, %2\n" // lum += cols | |
395 "addl %8, %3\n" // row1+= mod | |
396 "addl %8, %5\n" // row2+= mod | |
397 "movl $0, %6\n" // x=0 | |
398 "cmpl %7, %2\n" | |
399 "jl 1b\n" | |
400 "emms\n" | |
401 "popl %%ebx\n" | |
1038
29d7db09776e
Ugly hack to make this work with gcc 2.x and 3.x
Sam Lantinga <slouken@libsdl.org>
parents:
949
diff
changeset
|
402 : |
29d7db09776e
Ugly hack to make this work with gcc 2.x and 3.x
Sam Lantinga <slouken@libsdl.org>
parents:
949
diff
changeset
|
403 :"m" (cr), "r"(cb),"r"(lum), |
1148
63fb2da89a4b
Patched inline assembly to compile on gcc 4.0.1. Details are here:
Ryan C. Gordon <icculus@icculus.org>
parents:
1038
diff
changeset
|
404 "r"(row1),"r"(cols),"r"(row2),"m"(x),"m"(y),"m"(mod)); |
0 | 405 } |
406 | |
407 #endif /* GCC i386 inline assembly */ |