Mercurial > sdl-ios-xcode
annotate src/video/SDL_yuv_mmx.c @ 4047:810c6f4ab7aa SDL-1.2
Merged r3207:3208 from trunk/SDL: *INDENT-OFF* for inline asm.
author | Ryan C. Gordon <icculus@icculus.org> |
---|---|
date | Wed, 11 Jul 2007 07:25:57 +0000 |
parents | 3a9e60224efe |
children | ee5a38285651 |
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 */ |
1402
d910939febfa
Use consistent identifiers for the various platforms we support.
Sam Lantinga <slouken@libsdl.org>
parents:
1361
diff
changeset
|
22 #include "SDL_config.h" |
0 | 23 |
4045
f420bba13676
GCC inline asm for MMX YUV processing no longer has textrels and now works when
Ryan C. Gordon <icculus@icculus.org>
parents:
1413
diff
changeset
|
24 #if (__GNUC__ > 2) && defined(__i386__) && SDL_ASSEMBLY_ROUTINES |
0 | 25 |
1407
0c6941483cc6
Whoops, forgot to check in this fix
Sam Lantinga <slouken@libsdl.org>
parents:
1402
diff
changeset
|
26 #include "SDL_stdinc.h" |
0c6941483cc6
Whoops, forgot to check in this fix
Sam Lantinga <slouken@libsdl.org>
parents:
1402
diff
changeset
|
27 |
4045
f420bba13676
GCC inline asm for MMX YUV processing no longer has textrels and now works when
Ryan C. Gordon <icculus@icculus.org>
parents:
1413
diff
changeset
|
28 #include "mmx.h" |
f420bba13676
GCC inline asm for MMX YUV processing no longer has textrels and now works when
Ryan C. Gordon <icculus@icculus.org>
parents:
1413
diff
changeset
|
29 |
4047
810c6f4ab7aa
Merged r3207:3208 from trunk/SDL: *INDENT-OFF* for inline asm.
Ryan C. Gordon <icculus@icculus.org>
parents:
4046
diff
changeset
|
30 /* *INDENT-OFF* */ |
810c6f4ab7aa
Merged r3207:3208 from trunk/SDL: *INDENT-OFF* for inline asm.
Ryan C. Gordon <icculus@icculus.org>
parents:
4046
diff
changeset
|
31 |
4045
f420bba13676
GCC inline asm for MMX YUV processing no longer has textrels and now works when
Ryan C. Gordon <icculus@icculus.org>
parents:
1413
diff
changeset
|
32 static mmx_t MMX_0080w = { .ud = {0x00800080, 0x00800080} }; |
f420bba13676
GCC inline asm for MMX YUV processing no longer has textrels and now works when
Ryan C. Gordon <icculus@icculus.org>
parents:
1413
diff
changeset
|
33 static mmx_t MMX_00FFw = { .ud = {0x00ff00ff, 0x00ff00ff} }; |
f420bba13676
GCC inline asm for MMX YUV processing no longer has textrels and now works when
Ryan C. Gordon <icculus@icculus.org>
parents:
1413
diff
changeset
|
34 static mmx_t MMX_FF00w = { .ud = {0xff00ff00, 0xff00ff00} }; |
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
|
35 |
4045
f420bba13676
GCC inline asm for MMX YUV processing no longer has textrels and now works when
Ryan C. Gordon <icculus@icculus.org>
parents:
1413
diff
changeset
|
36 static mmx_t MMX_Ycoeff = { .uw = {0x004a, 0x004a, 0x004a, 0x004a} }; |
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
|
37 |
4045
f420bba13676
GCC inline asm for MMX YUV processing no longer has textrels and now works when
Ryan C. Gordon <icculus@icculus.org>
parents:
1413
diff
changeset
|
38 static mmx_t MMX_UbluRGB = { .uw = {0x0072, 0x0072, 0x0072, 0x0072} }; |
f420bba13676
GCC inline asm for MMX YUV processing no longer has textrels and now works when
Ryan C. Gordon <icculus@icculus.org>
parents:
1413
diff
changeset
|
39 static mmx_t MMX_VredRGB = { .uw = {0x0059, 0x0059, 0x0059, 0x0059} }; |
f420bba13676
GCC inline asm for MMX YUV processing no longer has textrels and now works when
Ryan C. Gordon <icculus@icculus.org>
parents:
1413
diff
changeset
|
40 static mmx_t MMX_UgrnRGB = { .uw = {0xffea, 0xffea, 0xffea, 0xffea} }; |
f420bba13676
GCC inline asm for MMX YUV processing no longer has textrels and now works when
Ryan C. Gordon <icculus@icculus.org>
parents:
1413
diff
changeset
|
41 static mmx_t MMX_VgrnRGB = { .uw = {0xffd2, 0xffd2, 0xffd2, 0xffd2} }; |
0 | 42 |
4045
f420bba13676
GCC inline asm for MMX YUV processing no longer has textrels and now works when
Ryan C. Gordon <icculus@icculus.org>
parents:
1413
diff
changeset
|
43 static mmx_t MMX_Ublu5x5 = { .uw = {0x0081, 0x0081, 0x0081, 0x0081} }; |
f420bba13676
GCC inline asm for MMX YUV processing no longer has textrels and now works when
Ryan C. Gordon <icculus@icculus.org>
parents:
1413
diff
changeset
|
44 static mmx_t MMX_Vred5x5 = { .uw = {0x0066, 0x0066, 0x0066, 0x0066} }; |
f420bba13676
GCC inline asm for MMX YUV processing no longer has textrels and now works when
Ryan C. Gordon <icculus@icculus.org>
parents:
1413
diff
changeset
|
45 static mmx_t MMX_Ugrn555 = { .uw = {0xffe7, 0xffe7, 0xffe7, 0xffe7} }; |
f420bba13676
GCC inline asm for MMX YUV processing no longer has textrels and now works when
Ryan C. Gordon <icculus@icculus.org>
parents:
1413
diff
changeset
|
46 static mmx_t MMX_Vgrn555 = { .uw = {0xffcc, 0xffcc, 0xffcc, 0xffcc} }; |
f420bba13676
GCC inline asm for MMX YUV processing no longer has textrels and now works when
Ryan C. Gordon <icculus@icculus.org>
parents:
1413
diff
changeset
|
47 static mmx_t MMX_Ugrn565 = { .uw = {0xffe8, 0xffe8, 0xffe8, 0xffe8} }; |
f420bba13676
GCC inline asm for MMX YUV processing no longer has textrels and now works when
Ryan C. Gordon <icculus@icculus.org>
parents:
1413
diff
changeset
|
48 static mmx_t MMX_Vgrn565 = { .uw = {0xffcd, 0xffcd, 0xffcd, 0xffcd} }; |
0 | 49 |
4045
f420bba13676
GCC inline asm for MMX YUV processing no longer has textrels and now works when
Ryan C. Gordon <icculus@icculus.org>
parents:
1413
diff
changeset
|
50 static mmx_t MMX_red555 = { .uw = {0x7c00, 0x7c00, 0x7c00, 0x7c00} }; |
f420bba13676
GCC inline asm for MMX YUV processing no longer has textrels and now works when
Ryan C. Gordon <icculus@icculus.org>
parents:
1413
diff
changeset
|
51 static mmx_t MMX_red565 = { .uw = {0xf800, 0xf800, 0xf800, 0xf800} }; |
f420bba13676
GCC inline asm for MMX YUV processing no longer has textrels and now works when
Ryan C. Gordon <icculus@icculus.org>
parents:
1413
diff
changeset
|
52 static mmx_t MMX_grn555 = { .uw = {0x03e0, 0x03e0, 0x03e0, 0x03e0} }; |
f420bba13676
GCC inline asm for MMX YUV processing no longer has textrels and now works when
Ryan C. Gordon <icculus@icculus.org>
parents:
1413
diff
changeset
|
53 static mmx_t MMX_grn565 = { .uw = {0x07e0, 0x07e0, 0x07e0, 0x07e0} }; |
f420bba13676
GCC inline asm for MMX YUV processing no longer has textrels and now works when
Ryan C. Gordon <icculus@icculus.org>
parents:
1413
diff
changeset
|
54 static mmx_t MMX_blu5x5 = { .uw = {0x001f, 0x001f, 0x001f, 0x001f} }; |
0 | 55 |
56 /** | |
57 This MMX assembler is my first assembler/MMX program ever. | |
58 Thus it maybe buggy. | |
59 Send patches to: | |
60 mvogt@rhrk.uni-kl.de | |
61 | |
62 After it worked fine I have "obfuscated" the code a bit to have | |
63 more parallism in the MMX units. This means I moved | |
64 initilisation around and delayed other instruction. | |
65 Performance measurement did not show that this brought any advantage | |
66 but in theory it _should_ be faster this way. | |
67 | |
68 The overall performanve gain to the C based dither was 30%-40%. | |
69 The MMX routine calculates 256bit=8RGB values in each cycle | |
70 (4 for row1 & 4 for row2) | |
71 | |
72 The red/green/blue.. coefficents are taken from the mpeg_play | |
73 player. They look nice, but I dont know if you can have | |
74 better values, to avoid integer rounding errors. | |
75 | |
76 | |
77 IMPORTANT: | |
78 ========== | |
79 | |
80 It is a requirement that the cr/cb/lum are 8 byte aligned and | |
81 the out are 16byte aligned or you will/may get segfaults | |
82 | |
83 */ | |
84 | |
85 void ColorRGBDitherYV12MMX1X( int *colortab, Uint32 *rgb_2_pix, | |
86 unsigned char *lum, unsigned char *cr, | |
87 unsigned char *cb, unsigned char *out, | |
88 int rows, int cols, int mod ) | |
89 { | |
4045
f420bba13676
GCC inline asm for MMX YUV processing no longer has textrels and now works when
Ryan C. Gordon <icculus@icculus.org>
parents:
1413
diff
changeset
|
90 Uint32 *row1; |
f420bba13676
GCC inline asm for MMX YUV processing no longer has textrels and now works when
Ryan C. Gordon <icculus@icculus.org>
parents:
1413
diff
changeset
|
91 Uint32 *row2; |
0 | 92 |
4045
f420bba13676
GCC inline asm for MMX YUV processing no longer has textrels and now works when
Ryan C. Gordon <icculus@icculus.org>
parents:
1413
diff
changeset
|
93 unsigned char* y = lum +cols*rows; // Pointer to the end |
f420bba13676
GCC inline asm for MMX YUV processing no longer has textrels and now works when
Ryan C. Gordon <icculus@icculus.org>
parents:
1413
diff
changeset
|
94 int x = 0; |
f420bba13676
GCC inline asm for MMX YUV processing no longer has textrels and now works when
Ryan C. Gordon <icculus@icculus.org>
parents:
1413
diff
changeset
|
95 row1 = (Uint32 *)out; // 32 bit target |
f420bba13676
GCC inline asm for MMX YUV processing no longer has textrels and now works when
Ryan C. Gordon <icculus@icculus.org>
parents:
1413
diff
changeset
|
96 row2 = (Uint32 *)out+cols+mod; // start of second row |
f420bba13676
GCC inline asm for MMX YUV processing no longer has textrels and now works when
Ryan C. Gordon <icculus@icculus.org>
parents:
1413
diff
changeset
|
97 mod = (mod+cols+mod)*4; // increment for row1 in byte |
0 | 98 |
4045
f420bba13676
GCC inline asm for MMX YUV processing no longer has textrels and now works when
Ryan C. Gordon <icculus@icculus.org>
parents:
1413
diff
changeset
|
99 __asm__ __volatile__ ( |
4046 | 100 // tap dance to workaround the inability to use %%ebx at will... |
101 // move one thing to the stack... | |
102 "pushl $0\n" // save a slot on the stack. | |
103 "pushl %%ebx\n" // save %%ebx. | |
104 "movl %0, %%ebx\n" // put the thing in ebx. | |
105 "movl %%ebx,4(%%esp)\n" // put the thing in the stack slot. | |
106 "popl %%ebx\n" // get back %%ebx (the PIC register). | |
107 | |
108 ".align 8\n" | |
109 "1:\n" | |
0 | 110 |
4046 | 111 // create Cr (result in mm1) |
112 "pushl %%ebx\n" | |
113 "movl 4(%%esp),%%ebx\n" | |
114 "movd (%%ebx),%%mm1\n" // 0 0 0 0 v3 v2 v1 v0 | |
115 "popl %%ebx\n" | |
116 "pxor %%mm7,%%mm7\n" // 00 00 00 00 00 00 00 00 | |
117 "movd (%2), %%mm2\n" // 0 0 0 0 l3 l2 l1 l0 | |
118 "punpcklbw %%mm7,%%mm1\n" // 0 v3 0 v2 00 v1 00 v0 | |
119 "punpckldq %%mm1,%%mm1\n" // 00 v1 00 v0 00 v1 00 v0 | |
120 "psubw %9,%%mm1\n" // mm1-128:r1 r1 r0 r0 r1 r1 r0 r0 | |
0 | 121 |
122 // create Cr_g (result in mm0) | |
4046 | 123 "movq %%mm1,%%mm0\n" // r1 r1 r0 r0 r1 r1 r0 r0 |
124 "pmullw %10,%%mm0\n" // red*-46dec=0.7136*64 | |
125 "pmullw %11,%%mm1\n" // red*89dec=1.4013*64 | |
126 "psraw $6, %%mm0\n" // red=red/64 | |
127 "psraw $6, %%mm1\n" // red=red/64 | |
0 | 128 |
4046 | 129 // create L1 L2 (result in mm2,mm4) |
130 // L2=lum+cols | |
131 "movq (%2,%4),%%mm3\n" // 0 0 0 0 L3 L2 L1 L0 | |
132 "punpckldq %%mm3,%%mm2\n" // L3 L2 L1 L0 l3 l2 l1 l0 | |
133 "movq %%mm2,%%mm4\n" // L3 L2 L1 L0 l3 l2 l1 l0 | |
134 "pand %12,%%mm2\n" // L3 0 L1 0 l3 0 l1 0 | |
135 "pand %13,%%mm4\n" // 0 L2 0 L0 0 l2 0 l0 | |
136 "psrlw $8,%%mm2\n" // 0 L3 0 L1 0 l3 0 l1 | |
137 | |
138 // create R (result in mm6) | |
139 "movq %%mm2,%%mm5\n" // 0 L3 0 L1 0 l3 0 l1 | |
140 "movq %%mm4,%%mm6\n" // 0 L2 0 L0 0 l2 0 l0 | |
141 "paddsw %%mm1, %%mm5\n" // lum1+red:x R3 x R1 x r3 x r1 | |
142 "paddsw %%mm1, %%mm6\n" // lum1+red:x R2 x R0 x r2 x r0 | |
143 "packuswb %%mm5,%%mm5\n" // R3 R1 r3 r1 R3 R1 r3 r1 | |
144 "packuswb %%mm6,%%mm6\n" // R2 R0 r2 r0 R2 R0 r2 r0 | |
145 "pxor %%mm7,%%mm7\n" // 00 00 00 00 00 00 00 00 | |
146 "punpcklbw %%mm5,%%mm6\n" // R3 R2 R1 R0 r3 r2 r1 r0 | |
0 | 147 |
4046 | 148 // create Cb (result in mm1) |
149 "movd (%1), %%mm1\n" // 0 0 0 0 u3 u2 u1 u0 | |
150 "punpcklbw %%mm7,%%mm1\n" // 0 u3 0 u2 00 u1 00 u0 | |
151 "punpckldq %%mm1,%%mm1\n" // 00 u1 00 u0 00 u1 00 u0 | |
152 "psubw %9,%%mm1\n" // mm1-128:u1 u1 u0 u0 u1 u1 u0 u0 | |
153 // create Cb_g (result in mm5) | |
154 "movq %%mm1,%%mm5\n" // u1 u1 u0 u0 u1 u1 u0 u0 | |
155 "pmullw %14,%%mm5\n" // blue*-109dec=1.7129*64 | |
156 "pmullw %15,%%mm1\n" // blue*114dec=1.78125*64 | |
157 "psraw $6, %%mm5\n" // blue=red/64 | |
158 "psraw $6, %%mm1\n" // blue=blue/64 | |
0 | 159 |
4046 | 160 // create G (result in mm7) |
161 "movq %%mm2,%%mm3\n" // 0 L3 0 L1 0 l3 0 l1 | |
162 "movq %%mm4,%%mm7\n" // 0 L2 0 L0 0 l2 0 l1 | |
163 "paddsw %%mm5, %%mm3\n" // lum1+Cb_g:x G3t x G1t x g3t x g1t | |
164 "paddsw %%mm5, %%mm7\n" // lum1+Cb_g:x G2t x G0t x g2t x g0t | |
165 "paddsw %%mm0, %%mm3\n" // lum1+Cr_g:x G3 x G1 x g3 x g1 | |
166 "paddsw %%mm0, %%mm7\n" // lum1+blue:x G2 x G0 x g2 x g0 | |
167 "packuswb %%mm3,%%mm3\n" // G3 G1 g3 g1 G3 G1 g3 g1 | |
168 "packuswb %%mm7,%%mm7\n" // G2 G0 g2 g0 G2 G0 g2 g0 | |
169 "punpcklbw %%mm3,%%mm7\n" // G3 G2 G1 G0 g3 g2 g1 g0 | |
0 | 170 |
4046 | 171 // create B (result in mm5) |
172 "movq %%mm2,%%mm3\n" // 0 L3 0 L1 0 l3 0 l1 | |
173 "movq %%mm4,%%mm5\n" // 0 L2 0 L0 0 l2 0 l1 | |
174 "paddsw %%mm1, %%mm3\n" // lum1+blue:x B3 x B1 x b3 x b1 | |
175 "paddsw %%mm1, %%mm5\n" // lum1+blue:x B2 x B0 x b2 x b0 | |
176 "packuswb %%mm3,%%mm3\n" // B3 B1 b3 b1 B3 B1 b3 b1 | |
177 "packuswb %%mm5,%%mm5\n" // B2 B0 b2 b0 B2 B0 b2 b0 | |
178 "punpcklbw %%mm3,%%mm5\n" // B3 B2 B1 B0 b3 b2 b1 b0 | |
179 | |
180 // fill destination row1 (needed are mm6=Rr,mm7=Gg,mm5=Bb) | |
0 | 181 |
4046 | 182 "pxor %%mm2,%%mm2\n" // 0 0 0 0 0 0 0 0 |
183 "pxor %%mm4,%%mm4\n" // 0 0 0 0 0 0 0 0 | |
184 "movq %%mm6,%%mm1\n" // R3 R2 R1 R0 r3 r2 r1 r0 | |
185 "movq %%mm5,%%mm3\n" // B3 B2 B1 B0 b3 b2 b1 b0 | |
186 // process lower lum | |
187 "punpcklbw %%mm4,%%mm1\n" // 0 r3 0 r2 0 r1 0 r0 | |
188 "punpcklbw %%mm4,%%mm3\n" // 0 b3 0 b2 0 b1 0 b0 | |
189 "movq %%mm1,%%mm2\n" // 0 r3 0 r2 0 r1 0 r0 | |
190 "movq %%mm3,%%mm0\n" // 0 b3 0 b2 0 b1 0 b0 | |
191 "punpcklwd %%mm1,%%mm3\n" // 0 r1 0 b1 0 r0 0 b0 | |
192 "punpckhwd %%mm2,%%mm0\n" // 0 r3 0 b3 0 r2 0 b2 | |
0 | 193 |
4046 | 194 "pxor %%mm2,%%mm2\n" // 0 0 0 0 0 0 0 0 |
195 "movq %%mm7,%%mm1\n" // G3 G2 G1 G0 g3 g2 g1 g0 | |
196 "punpcklbw %%mm1,%%mm2\n" // g3 0 g2 0 g1 0 g0 0 | |
197 "punpcklwd %%mm4,%%mm2\n" // 0 0 g1 0 0 0 g0 0 | |
198 "por %%mm3, %%mm2\n" // 0 r1 g1 b1 0 r0 g0 b0 | |
199 "movq %%mm2,(%3)\n" // wrote out ! row1 | |
0 | 200 |
4046 | 201 "pxor %%mm2,%%mm2\n" // 0 0 0 0 0 0 0 0 |
202 "punpcklbw %%mm1,%%mm4\n" // g3 0 g2 0 g1 0 g0 0 | |
203 "punpckhwd %%mm2,%%mm4\n" // 0 0 g3 0 0 0 g2 0 | |
204 "por %%mm0, %%mm4\n" // 0 r3 g3 b3 0 r2 g2 b2 | |
205 "movq %%mm4,8(%3)\n" // wrote out ! row1 | |
0 | 206 |
4046 | 207 // fill destination row2 (needed are mm6=Rr,mm7=Gg,mm5=Bb) |
208 // this can be done "destructive" | |
209 "pxor %%mm2,%%mm2\n" // 0 0 0 0 0 0 0 0 | |
210 "punpckhbw %%mm2,%%mm6\n" // 0 R3 0 R2 0 R1 0 R0 | |
211 "punpckhbw %%mm1,%%mm5\n" // G3 B3 G2 B2 G1 B1 G0 B0 | |
212 "movq %%mm5,%%mm1\n" // G3 B3 G2 B2 G1 B1 G0 B0 | |
213 "punpcklwd %%mm6,%%mm1\n" // 0 R1 G1 B1 0 R0 G0 B0 | |
214 "movq %%mm1,(%5)\n" // wrote out ! row2 | |
215 "punpckhwd %%mm6,%%mm5\n" // 0 R3 G3 B3 0 R2 G2 B2 | |
216 "movq %%mm5,8(%5)\n" // wrote out ! row2 | |
0 | 217 |
4046 | 218 "addl $4,%2\n" // lum+4 |
219 "leal 16(%3),%3\n" // row1+16 | |
220 "leal 16(%5),%5\n" // row2+16 | |
221 "addl $2,(%%esp)\n" // cr+2 | |
222 "addl $2,%1\n" // cb+2 | |
0 | 223 |
4046 | 224 "addl $4,%6\n" // x+4 |
225 "cmpl %4,%6\n" | |
0 | 226 |
4046 | 227 "jl 1b\n" |
228 "addl %4,%2\n" // lum += cols | |
229 "addl %8,%3\n" // row1+= mod | |
230 "addl %8,%5\n" // row2+= mod | |
231 "movl $0,%6\n" // x=0 | |
232 "cmpl %7,%2\n" | |
233 "jl 1b\n" | |
4045
f420bba13676
GCC inline asm for MMX YUV processing no longer has textrels and now works when
Ryan C. Gordon <icculus@icculus.org>
parents:
1413
diff
changeset
|
234 |
4046 | 235 "addl $4,%%esp\n" // get rid of the stack slot we reserved. |
236 "emms\n" // reset MMX registers. | |
237 : | |
238 : "m" (cr), "r"(cb),"r"(lum), | |
239 "r"(row1),"r"(cols),"r"(row2),"m"(x),"m"(y),"m"(mod), | |
240 "m"(MMX_0080w),"m"(MMX_VgrnRGB),"m"(MMX_VredRGB), | |
241 "m"(MMX_FF00w),"m"(MMX_00FFw),"m"(MMX_UgrnRGB), | |
242 "m"(MMX_UbluRGB) | |
4045
f420bba13676
GCC inline asm for MMX YUV processing no longer has textrels and now works when
Ryan C. Gordon <icculus@icculus.org>
parents:
1413
diff
changeset
|
243 ); |
0 | 244 } |
245 | |
246 void Color565DitherYV12MMX1X( int *colortab, Uint32 *rgb_2_pix, | |
247 unsigned char *lum, unsigned char *cr, | |
248 unsigned char *cb, unsigned char *out, | |
249 int rows, int cols, int mod ) | |
250 { | |
4046 | 251 Uint16 *row1; |
252 Uint16 *row2; | |
0 | 253 |
4046 | 254 unsigned char* y = lum +cols*rows; /* Pointer to the end */ |
255 int x = 0; | |
256 row1 = (Uint16 *)out; /* 16 bit target */ | |
257 row2 = (Uint16 *)out+cols+mod; /* start of second row */ | |
258 mod = (mod+cols+mod)*2; /* increment for row1 in byte */ | |
0 | 259 |
4046 | 260 __asm__ __volatile__( |
261 // tap dance to workaround the inability to use %%ebx at will... | |
262 // move one thing to the stack... | |
263 "pushl $0\n" // save a slot on the stack. | |
264 "pushl %%ebx\n" // save %%ebx. | |
265 "movl %0, %%ebx\n" // put the thing in ebx. | |
266 "movl %%ebx, 4(%%esp)\n" // put the thing in the stack slot. | |
267 "popl %%ebx\n" // get back %%ebx (the PIC register). | |
0 | 268 |
4046 | 269 ".align 8\n" |
270 "1:\n" | |
271 "movd (%1), %%mm0\n" // 4 Cb 0 0 0 0 u3 u2 u1 u0 | |
272 "pxor %%mm7, %%mm7\n" | |
273 "pushl %%ebx\n" | |
274 "movl 4(%%esp), %%ebx\n" | |
275 "movd (%%ebx), %%mm1\n" // 4 Cr 0 0 0 0 v3 v2 v1 v0 | |
276 "popl %%ebx\n" | |
4045
f420bba13676
GCC inline asm for MMX YUV processing no longer has textrels and now works when
Ryan C. Gordon <icculus@icculus.org>
parents:
1413
diff
changeset
|
277 |
4046 | 278 "punpcklbw %%mm7, %%mm0\n" // 4 W cb 0 u3 0 u2 0 u1 0 u0 |
279 "punpcklbw %%mm7, %%mm1\n" // 4 W cr 0 v3 0 v2 0 v1 0 v0 | |
280 "psubw %9, %%mm0\n" | |
281 "psubw %9, %%mm1\n" | |
282 "movq %%mm0, %%mm2\n" // Cb 0 u3 0 u2 0 u1 0 u0 | |
283 "movq %%mm1, %%mm3\n" // Cr | |
284 "pmullw %10, %%mm2\n" // Cb2green 0 R3 0 R2 0 R1 0 R0 | |
285 "movq (%2), %%mm6\n" // L1 l7 L6 L5 L4 L3 L2 L1 L0 | |
286 "pmullw %11, %%mm0\n" // Cb2blue | |
287 "pand %12, %%mm6\n" // L1 00 L6 00 L4 00 L2 00 L0 | |
288 "pmullw %13, %%mm3\n" // Cr2green | |
289 "movq (%2), %%mm7\n" // L2 | |
290 "pmullw %14, %%mm1\n" // Cr2red | |
291 "psrlw $8, %%mm7\n" // L2 00 L7 00 L5 00 L3 00 L1 | |
292 "pmullw %15, %%mm6\n" // lum1 | |
293 "paddw %%mm3, %%mm2\n" // Cb2green + Cr2green == green | |
294 "pmullw %15, %%mm7\n" // lum2 | |
0 | 295 |
4046 | 296 "movq %%mm6, %%mm4\n" // lum1 |
297 "paddw %%mm0, %%mm6\n" // lum1 +blue 00 B6 00 B4 00 B2 00 B0 | |
298 "movq %%mm4, %%mm5\n" // lum1 | |
299 "paddw %%mm1, %%mm4\n" // lum1 +red 00 R6 00 R4 00 R2 00 R0 | |
300 "paddw %%mm2, %%mm5\n" // lum1 +green 00 G6 00 G4 00 G2 00 G0 | |
301 "psraw $6, %%mm4\n" // R1 0 .. 64 | |
302 "movq %%mm7, %%mm3\n" // lum2 00 L7 00 L5 00 L3 00 L1 | |
303 "psraw $6, %%mm5\n" // G1 - .. + | |
304 "paddw %%mm0, %%mm7\n" // Lum2 +blue 00 B7 00 B5 00 B3 00 B1 | |
305 "psraw $6, %%mm6\n" // B1 0 .. 64 | |
306 "packuswb %%mm4, %%mm4\n" // R1 R1 | |
307 "packuswb %%mm5, %%mm5\n" // G1 G1 | |
308 "packuswb %%mm6, %%mm6\n" // B1 B1 | |
309 "punpcklbw %%mm4, %%mm4\n" | |
310 "punpcklbw %%mm5, %%mm5\n" | |
0 | 311 |
4046 | 312 "pand %16, %%mm4\n" |
313 "psllw $3, %%mm5\n" // GREEN 1 | |
314 "punpcklbw %%mm6, %%mm6\n" | |
315 "pand %17, %%mm5\n" | |
316 "pand %16, %%mm6\n" | |
317 "por %%mm5, %%mm4\n" // | |
318 "psrlw $11, %%mm6\n" // BLUE 1 | |
319 "movq %%mm3, %%mm5\n" // lum2 | |
320 "paddw %%mm1, %%mm3\n" // lum2 +red 00 R7 00 R5 00 R3 00 R1 | |
321 "paddw %%mm2, %%mm5\n" // lum2 +green 00 G7 00 G5 00 G3 00 G1 | |
322 "psraw $6, %%mm3\n" // R2 | |
323 "por %%mm6, %%mm4\n" // MM4 | |
324 "psraw $6, %%mm5\n" // G2 | |
325 "movq (%2, %4), %%mm6\n" // L3 load lum2 | |
326 "psraw $6, %%mm7\n" | |
327 "packuswb %%mm3, %%mm3\n" | |
328 "packuswb %%mm5, %%mm5\n" | |
329 "packuswb %%mm7, %%mm7\n" | |
330 "pand %12, %%mm6\n" // L3 | |
331 "punpcklbw %%mm3, %%mm3\n" | |
332 "punpcklbw %%mm5, %%mm5\n" | |
333 "pmullw %15, %%mm6\n" // lum3 | |
334 "punpcklbw %%mm7, %%mm7\n" | |
335 "psllw $3, %%mm5\n" // GREEN 2 | |
336 "pand %16, %%mm7\n" | |
337 "pand %16, %%mm3\n" | |
338 "psrlw $11, %%mm7\n" // BLUE 2 | |
339 "pand %17, %%mm5\n" | |
340 "por %%mm7, %%mm3\n" | |
341 "movq (%2,%4), %%mm7\n" // L4 load lum2 | |
342 "por %%mm5, %%mm3\n" // | |
343 "psrlw $8, %%mm7\n" // L4 | |
344 "movq %%mm4, %%mm5\n" | |
345 "punpcklwd %%mm3, %%mm4\n" | |
346 "pmullw %15, %%mm7\n" // lum4 | |
347 "punpckhwd %%mm3, %%mm5\n" | |
0 | 348 |
4046 | 349 "movq %%mm4, (%3)\n" // write row1 |
350 "movq %%mm5, 8(%3)\n" // write row1 | |
0 | 351 |
4046 | 352 "movq %%mm6, %%mm4\n" // Lum3 |
353 "paddw %%mm0, %%mm6\n" // Lum3 +blue | |
0 | 354 |
4046 | 355 "movq %%mm4, %%mm5\n" // Lum3 |
356 "paddw %%mm1, %%mm4\n" // Lum3 +red | |
357 "paddw %%mm2, %%mm5\n" // Lum3 +green | |
358 "psraw $6, %%mm4\n" | |
359 "movq %%mm7, %%mm3\n" // Lum4 | |
360 "psraw $6, %%mm5\n" | |
361 "paddw %%mm0, %%mm7\n" // Lum4 +blue | |
362 "psraw $6, %%mm6\n" // Lum3 +blue | |
363 "movq %%mm3, %%mm0\n" // Lum4 | |
364 "packuswb %%mm4, %%mm4\n" | |
365 "paddw %%mm1, %%mm3\n" // Lum4 +red | |
366 "packuswb %%mm5, %%mm5\n" | |
367 "paddw %%mm2, %%mm0\n" // Lum4 +green | |
368 "packuswb %%mm6, %%mm6\n" | |
369 "punpcklbw %%mm4, %%mm4\n" | |
370 "punpcklbw %%mm5, %%mm5\n" | |
371 "punpcklbw %%mm6, %%mm6\n" | |
372 "psllw $3, %%mm5\n" // GREEN 3 | |
373 "pand %16, %%mm4\n" | |
374 "psraw $6, %%mm3\n" // psr 6 | |
375 "psraw $6, %%mm0\n" | |
376 "pand %16, %%mm6\n" // BLUE | |
377 "pand %17, %%mm5\n" | |
378 "psrlw $11, %%mm6\n" // BLUE 3 | |
379 "por %%mm5, %%mm4\n" | |
380 "psraw $6, %%mm7\n" | |
381 "por %%mm6, %%mm4\n" | |
382 "packuswb %%mm3, %%mm3\n" | |
383 "packuswb %%mm0, %%mm0\n" | |
384 "packuswb %%mm7, %%mm7\n" | |
385 "punpcklbw %%mm3, %%mm3\n" | |
386 "punpcklbw %%mm0, %%mm0\n" | |
387 "punpcklbw %%mm7, %%mm7\n" | |
388 "pand %16, %%mm3\n" | |
389 "pand %16, %%mm7\n" // BLUE | |
390 "psllw $3, %%mm0\n" // GREEN 4 | |
391 "psrlw $11, %%mm7\n" | |
392 "pand %17, %%mm0\n" | |
393 "por %%mm7, %%mm3\n" | |
394 "por %%mm0, %%mm3\n" | |
0 | 395 |
4046 | 396 "movq %%mm4, %%mm5\n" |
0 | 397 |
4046 | 398 "punpcklwd %%mm3, %%mm4\n" |
399 "punpckhwd %%mm3, %%mm5\n" | |
0 | 400 |
4046 | 401 "movq %%mm4, (%5)\n" |
402 "movq %%mm5, 8(%5)\n" | |
0 | 403 |
4046 | 404 "addl $8, %6\n" |
405 "addl $8, %2\n" | |
406 "addl $4, (%%esp)\n" | |
407 "addl $4, %1\n" | |
408 "cmpl %4, %6\n" | |
409 "leal 16(%3), %3\n" | |
410 "leal 16(%5),%5\n" // row2+16 | |
0 | 411 |
4046 | 412 "jl 1b\n" |
413 "addl %4, %2\n" // lum += cols | |
414 "addl %8, %3\n" // row1+= mod | |
415 "addl %8, %5\n" // row2+= mod | |
416 "movl $0, %6\n" // x=0 | |
417 "cmpl %7, %2\n" | |
418 "jl 1b\n" | |
419 "addl $4, %%esp\n" // get rid of the stack slot we reserved. | |
420 "emms\n" | |
421 : | |
422 : "m" (cr), "r"(cb),"r"(lum), | |
423 "r"(row1),"r"(cols),"r"(row2),"m"(x),"m"(y),"m"(mod), | |
424 "m"(MMX_0080w),"m"(MMX_Ugrn565),"m"(MMX_Ublu5x5), | |
425 "m"(MMX_00FFw),"m"(MMX_Vgrn565),"m"(MMX_Vred5x5), | |
426 "m"(MMX_Ycoeff),"m"(MMX_red565),"m"(MMX_grn565) | |
427 ); | |
0 | 428 } |
429 | |
4047
810c6f4ab7aa
Merged r3207:3208 from trunk/SDL: *INDENT-OFF* for inline asm.
Ryan C. Gordon <icculus@icculus.org>
parents:
4046
diff
changeset
|
430 /* *INDENT-ON* */ |
810c6f4ab7aa
Merged r3207:3208 from trunk/SDL: *INDENT-OFF* for inline asm.
Ryan C. Gordon <icculus@icculus.org>
parents:
4046
diff
changeset
|
431 |
4045
f420bba13676
GCC inline asm for MMX YUV processing no longer has textrels and now works when
Ryan C. Gordon <icculus@icculus.org>
parents:
1413
diff
changeset
|
432 #endif /* GCC3 i386 inline assembly */ |
f420bba13676
GCC inline asm for MMX YUV processing no longer has textrels and now works when
Ryan C. Gordon <icculus@icculus.org>
parents:
1413
diff
changeset
|
433 |