comparison src/video/SDL_yuv_mmx.c @ 2168:07f084fe97d0

Merged r3211:3213 from branches/SDL-1.2: YUV MMX inline asm for GCC.
author Ryan C. Gordon <icculus@icculus.org>
date Wed, 11 Jul 2007 07:39:01 +0000
parents 8f2174e22cd5
children 26233707bc94
comparison
equal deleted inserted replaced
2167:8f2174e22cd5 2168:07f084fe97d0
19 Sam Lantinga 19 Sam Lantinga
20 slouken@libsdl.org 20 slouken@libsdl.org
21 */ 21 */
22 #include "SDL_config.h" 22 #include "SDL_config.h"
23 23
24 #if (__GNUC__ > 2) && defined(__i386__) && SDL_ASSEMBLY_ROUTINES
25
26 #include "SDL_stdinc.h"
27
28 #include "mmx.h"
29
24 /* *INDENT-OFF* */ 30 /* *INDENT-OFF* */
25 31
26 #if 0 /* FIXME: This code needs to be rewritten to reference the static data using relocatable addresses (e.g. http://www.gentoo.org/proj/en/hardened/pic-fix-guide.xml or http://nasm.sourceforge.net/doc/html/nasmdoc8.html#section-8.2) This code currently breaks on systems with readonly text segments (hardened Linux / Intel Mac) */ 32 static mmx_t MMX_0080w = { .ud = {0x00800080, 0x00800080} };
27 #if defined(__GNUC__) && defined(__i386__) && SDL_ASSEMBLY_ROUTINES 33 static mmx_t MMX_00FFw = { .ud = {0x00ff00ff, 0x00ff00ff} };
28 34 static mmx_t MMX_FF00w = { .ud = {0xff00ff00, 0xff00ff00} };
29 #include "SDL_stdinc.h" 35
30 36 static mmx_t MMX_Ycoeff = { .uw = {0x004a, 0x004a, 0x004a, 0x004a} };
31 #define ASM_ARRAY(x) x[] __asm__("_" #x) __attribute__((used)) 37
32 38 static mmx_t MMX_UbluRGB = { .uw = {0x0072, 0x0072, 0x0072, 0x0072} };
33 static unsigned int ASM_ARRAY(MMX_0080w) = {0x00800080, 0x00800080}; 39 static mmx_t MMX_VredRGB = { .uw = {0x0059, 0x0059, 0x0059, 0x0059} };
34 static unsigned int ASM_ARRAY(MMX_00FFw) = {0x00ff00ff, 0x00ff00ff}; 40 static mmx_t MMX_UgrnRGB = { .uw = {0xffea, 0xffea, 0xffea, 0xffea} };
35 static unsigned int ASM_ARRAY(MMX_FF00w) = {0xff00ff00, 0xff00ff00}; 41 static mmx_t MMX_VgrnRGB = { .uw = {0xffd2, 0xffd2, 0xffd2, 0xffd2} };
36 42
37 static unsigned short ASM_ARRAY(MMX_Ycoeff) = {0x004a, 0x004a, 0x004a, 0x004a}; 43 static mmx_t MMX_Ublu5x5 = { .uw = {0x0081, 0x0081, 0x0081, 0x0081} };
38 44 static mmx_t MMX_Vred5x5 = { .uw = {0x0066, 0x0066, 0x0066, 0x0066} };
39 static unsigned short ASM_ARRAY(MMX_UbluRGB) = {0x0072, 0x0072, 0x0072, 0x0072}; 45 static mmx_t MMX_Ugrn555 = { .uw = {0xffe7, 0xffe7, 0xffe7, 0xffe7} };
40 static unsigned short ASM_ARRAY(MMX_VredRGB) = {0x0059, 0x0059, 0x0059, 0x0059}; 46 static mmx_t MMX_Vgrn555 = { .uw = {0xffcc, 0xffcc, 0xffcc, 0xffcc} };
41 static unsigned short ASM_ARRAY(MMX_UgrnRGB) = {0xffea, 0xffea, 0xffea, 0xffea}; 47 static mmx_t MMX_Ugrn565 = { .uw = {0xffe8, 0xffe8, 0xffe8, 0xffe8} };
42 static unsigned short ASM_ARRAY(MMX_VgrnRGB) = {0xffd2, 0xffd2, 0xffd2, 0xffd2}; 48 static mmx_t MMX_Vgrn565 = { .uw = {0xffcd, 0xffcd, 0xffcd, 0xffcd} };
43 49
44 static unsigned short ASM_ARRAY(MMX_Ublu5x5) = {0x0081, 0x0081, 0x0081, 0x0081}; 50 static mmx_t MMX_red555 = { .uw = {0x7c00, 0x7c00, 0x7c00, 0x7c00} };
45 static unsigned short ASM_ARRAY(MMX_Vred5x5) = {0x0066, 0x0066, 0x0066, 0x0066}; 51 static mmx_t MMX_red565 = { .uw = {0xf800, 0xf800, 0xf800, 0xf800} };
46 static unsigned short ASM_ARRAY(MMX_Ugrn555) = {0xffe7, 0xffe7, 0xffe7, 0xffe7}; 52 static mmx_t MMX_grn555 = { .uw = {0x03e0, 0x03e0, 0x03e0, 0x03e0} };
47 static unsigned short ASM_ARRAY(MMX_Vgrn555) = {0xffcc, 0xffcc, 0xffcc, 0xffcc}; 53 static mmx_t MMX_grn565 = { .uw = {0x07e0, 0x07e0, 0x07e0, 0x07e0} };
48 static unsigned short ASM_ARRAY(MMX_Ugrn565) = {0xffe8, 0xffe8, 0xffe8, 0xffe8}; 54 static mmx_t MMX_blu5x5 = { .uw = {0x001f, 0x001f, 0x001f, 0x001f} };
49 static unsigned short ASM_ARRAY(MMX_Vgrn565) = {0xffcd, 0xffcd, 0xffcd, 0xffcd};
50
51 static unsigned short ASM_ARRAY(MMX_red555) = {0x7c00, 0x7c00, 0x7c00, 0x7c00};
52 static unsigned short ASM_ARRAY(MMX_red565) = {0xf800, 0xf800, 0xf800, 0xf800};
53 static unsigned short ASM_ARRAY(MMX_grn555) = {0x03e0, 0x03e0, 0x03e0, 0x03e0};
54 static unsigned short ASM_ARRAY(MMX_grn565) = {0x07e0, 0x07e0, 0x07e0, 0x07e0};
55 static unsigned short ASM_ARRAY(MMX_blu5x5) = {0x001f, 0x001f, 0x001f, 0x001f};
56 55
57 /** 56 /**
58 This MMX assembler is my first assembler/MMX program ever. 57 This MMX assembler is my first assembler/MMX program ever.
59 Thus it maybe buggy. 58 Thus it maybe buggy.
60 Send patches to: 59 Send patches to:
90 { 89 {
91 Uint32 *row1; 90 Uint32 *row1;
92 Uint32 *row2; 91 Uint32 *row2;
93 92
94 unsigned char* y = lum +cols*rows; // Pointer to the end 93 unsigned char* y = lum +cols*rows; // Pointer to the end
95 int x=0; 94 int x = 0;
96 row1 = (Uint32 *)out; // 32 bit target 95 row1 = (Uint32 *)out; // 32 bit target
97 row2 = (Uint32 *)out+cols+mod; // start of second row 96 row2 = (Uint32 *)out+cols+mod; // start of second row
98 mod = (mod+cols+mod)*4; // increment for row1 in byte 97 mod = (mod+cols+mod)*4; // increment for row1 in byte
99 98
100 __asm__ __volatile__ ( 99 __asm__ __volatile__ (
101 /* We don't really care about PIC - the code should be rewritten to use 100 // tap dance to workaround the inability to use %%ebx at will...
102 relative addressing for the static tables, so right now we take the 101 // move one thing to the stack...
103 COW hit on the pages this code resides. Big deal. 102 "pushl $0\n" // save a slot on the stack.
104 This spill is just to reduce register pressure in the PIC case. */ 103 "pushl %%ebx\n" // save %%ebx.
105 "pushl %%ebx\n" 104 "movl %0, %%ebx\n" // put the thing in ebx.
106 "movl %0, %%ebx\n" 105 "movl %%ebx,4(%%esp)\n" // put the thing in the stack slot.
107 106 "popl %%ebx\n" // get back %%ebx (the PIC register).
108 ".align 8\n" 107
109 "1:\n" 108 ".align 8\n"
110 109 "1:\n"
111 // create Cr (result in mm1) 110
112 "movd (%%ebx), %%mm1\n" // 0 0 0 0 v3 v2 v1 v0 111 // create Cr (result in mm1)
113 "pxor %%mm7,%%mm7\n" // 00 00 00 00 00 00 00 00 112 "pushl %%ebx\n"
114 "movd (%2), %%mm2\n" // 0 0 0 0 l3 l2 l1 l0 113 "movl 4(%%esp),%%ebx\n"
115 "punpcklbw %%mm7,%%mm1\n" // 0 v3 0 v2 00 v1 00 v0 114 "movd (%%ebx),%%mm1\n" // 0 0 0 0 v3 v2 v1 v0
116 "punpckldq %%mm1,%%mm1\n" // 00 v1 00 v0 00 v1 00 v0 115 "popl %%ebx\n"
117 "psubw _MMX_0080w,%%mm1\n" // mm1-128:r1 r1 r0 r0 r1 r1 r0 r0 116 "pxor %%mm7,%%mm7\n" // 00 00 00 00 00 00 00 00
118 117 "movd (%2), %%mm2\n" // 0 0 0 0 l3 l2 l1 l0
119 // create Cr_g (result in mm0) 118 "punpcklbw %%mm7,%%mm1\n" // 0 v3 0 v2 00 v1 00 v0
120 "movq %%mm1,%%mm0\n" // r1 r1 r0 r0 r1 r1 r0 r0 119 "punpckldq %%mm1,%%mm1\n" // 00 v1 00 v0 00 v1 00 v0
121 "pmullw _MMX_VgrnRGB,%%mm0\n"// red*-46dec=0.7136*64 120 "psubw %9,%%mm1\n" // mm1-128:r1 r1 r0 r0 r1 r1 r0 r0
122 "pmullw _MMX_VredRGB,%%mm1\n"// red*89dec=1.4013*64 121
123 "psraw $6, %%mm0\n" // red=red/64 122 // create Cr_g (result in mm0)
124 "psraw $6, %%mm1\n" // red=red/64 123 "movq %%mm1,%%mm0\n" // r1 r1 r0 r0 r1 r1 r0 r0
125 124 "pmullw %10,%%mm0\n" // red*-46dec=0.7136*64
126 // create L1 L2 (result in mm2,mm4) 125 "pmullw %11,%%mm1\n" // red*89dec=1.4013*64
127 // L2=lum+cols 126 "psraw $6, %%mm0\n" // red=red/64
128 "movq (%2,%4),%%mm3\n" // 0 0 0 0 L3 L2 L1 L0 127 "psraw $6, %%mm1\n" // red=red/64
129 "punpckldq %%mm3,%%mm2\n" // L3 L2 L1 L0 l3 l2 l1 l0 128
130 "movq %%mm2,%%mm4\n" // L3 L2 L1 L0 l3 l2 l1 l0 129 // create L1 L2 (result in mm2,mm4)
131 "pand _MMX_FF00w,%%mm2\n" // L3 0 L1 0 l3 0 l1 0 130 // L2=lum+cols
132 "pand _MMX_00FFw,%%mm4\n" // 0 L2 0 L0 0 l2 0 l0 131 "movq (%2,%4),%%mm3\n" // 0 0 0 0 L3 L2 L1 L0
133 "psrlw $8,%%mm2\n" // 0 L3 0 L1 0 l3 0 l1 132 "punpckldq %%mm3,%%mm2\n" // L3 L2 L1 L0 l3 l2 l1 l0
134 133 "movq %%mm2,%%mm4\n" // L3 L2 L1 L0 l3 l2 l1 l0
135 // create R (result in mm6) 134 "pand %12,%%mm2\n" // L3 0 L1 0 l3 0 l1 0
136 "movq %%mm2,%%mm5\n" // 0 L3 0 L1 0 l3 0 l1 135 "pand %13,%%mm4\n" // 0 L2 0 L0 0 l2 0 l0
137 "movq %%mm4,%%mm6\n" // 0 L2 0 L0 0 l2 0 l0 136 "psrlw $8,%%mm2\n" // 0 L3 0 L1 0 l3 0 l1
138 "paddsw %%mm1, %%mm5\n" // lum1+red:x R3 x R1 x r3 x r1 137
139 "paddsw %%mm1, %%mm6\n" // lum1+red:x R2 x R0 x r2 x r0 138 // create R (result in mm6)
140 "packuswb %%mm5,%%mm5\n" // R3 R1 r3 r1 R3 R1 r3 r1 139 "movq %%mm2,%%mm5\n" // 0 L3 0 L1 0 l3 0 l1
141 "packuswb %%mm6,%%mm6\n" // R2 R0 r2 r0 R2 R0 r2 r0 140 "movq %%mm4,%%mm6\n" // 0 L2 0 L0 0 l2 0 l0
142 "pxor %%mm7,%%mm7\n" // 00 00 00 00 00 00 00 00 141 "paddsw %%mm1, %%mm5\n" // lum1+red:x R3 x R1 x r3 x r1
143 "punpcklbw %%mm5,%%mm6\n" // R3 R2 R1 R0 r3 r2 r1 r0 142 "paddsw %%mm1, %%mm6\n" // lum1+red:x R2 x R0 x r2 x r0
144 143 "packuswb %%mm5,%%mm5\n" // R3 R1 r3 r1 R3 R1 r3 r1
145 // create Cb (result in mm1) 144 "packuswb %%mm6,%%mm6\n" // R2 R0 r2 r0 R2 R0 r2 r0
146 "movd (%1), %%mm1\n" // 0 0 0 0 u3 u2 u1 u0 145 "pxor %%mm7,%%mm7\n" // 00 00 00 00 00 00 00 00
147 "punpcklbw %%mm7,%%mm1\n" // 0 u3 0 u2 00 u1 00 u0 146 "punpcklbw %%mm5,%%mm6\n" // R3 R2 R1 R0 r3 r2 r1 r0
148 "punpckldq %%mm1,%%mm1\n" // 00 u1 00 u0 00 u1 00 u0 147
149 "psubw _MMX_0080w,%%mm1\n" // mm1-128:u1 u1 u0 u0 u1 u1 u0 u0 148 // create Cb (result in mm1)
150 // create Cb_g (result in mm5) 149 "movd (%1), %%mm1\n" // 0 0 0 0 u3 u2 u1 u0
151 "movq %%mm1,%%mm5\n" // u1 u1 u0 u0 u1 u1 u0 u0 150 "punpcklbw %%mm7,%%mm1\n" // 0 u3 0 u2 00 u1 00 u0
152 "pmullw _MMX_UgrnRGB,%%mm5\n" // blue*-109dec=1.7129*64 151 "punpckldq %%mm1,%%mm1\n" // 00 u1 00 u0 00 u1 00 u0
153 "pmullw _MMX_UbluRGB,%%mm1\n" // blue*114dec=1.78125*64 152 "psubw %9,%%mm1\n" // mm1-128:u1 u1 u0 u0 u1 u1 u0 u0
154 "psraw $6, %%mm5\n" // blue=red/64 153
155 "psraw $6, %%mm1\n" // blue=blue/64 154 // create Cb_g (result in mm5)
156 155 "movq %%mm1,%%mm5\n" // u1 u1 u0 u0 u1 u1 u0 u0
157 // create G (result in mm7) 156 "pmullw %14,%%mm5\n" // blue*-109dec=1.7129*64
158 "movq %%mm2,%%mm3\n" // 0 L3 0 L1 0 l3 0 l1 157 "pmullw %15,%%mm1\n" // blue*114dec=1.78125*64
159 "movq %%mm4,%%mm7\n" // 0 L2 0 L0 0 l2 0 l1 158 "psraw $6, %%mm5\n" // blue=red/64
160 "paddsw %%mm5, %%mm3\n" // lum1+Cb_g:x G3t x G1t x g3t x g1t 159 "psraw $6, %%mm1\n" // blue=blue/64
161 "paddsw %%mm5, %%mm7\n" // lum1+Cb_g:x G2t x G0t x g2t x g0t 160
162 "paddsw %%mm0, %%mm3\n" // lum1+Cr_g:x G3 x G1 x g3 x g1 161 // create G (result in mm7)
163 "paddsw %%mm0, %%mm7\n" // lum1+blue:x G2 x G0 x g2 x g0 162 "movq %%mm2,%%mm3\n" // 0 L3 0 L1 0 l3 0 l1
164 "packuswb %%mm3,%%mm3\n" // G3 G1 g3 g1 G3 G1 g3 g1 163 "movq %%mm4,%%mm7\n" // 0 L2 0 L0 0 l2 0 l1
165 "packuswb %%mm7,%%mm7\n" // G2 G0 g2 g0 G2 G0 g2 g0 164 "paddsw %%mm5, %%mm3\n" // lum1+Cb_g:x G3t x G1t x g3t x g1t
166 "punpcklbw %%mm3,%%mm7\n" // G3 G2 G1 G0 g3 g2 g1 g0 165 "paddsw %%mm5, %%mm7\n" // lum1+Cb_g:x G2t x G0t x g2t x g0t
167 166 "paddsw %%mm0, %%mm3\n" // lum1+Cr_g:x G3 x G1 x g3 x g1
168 // create B (result in mm5) 167 "paddsw %%mm0, %%mm7\n" // lum1+blue:x G2 x G0 x g2 x g0
169 "movq %%mm2,%%mm3\n" // 0 L3 0 L1 0 l3 0 l1 168 "packuswb %%mm3,%%mm3\n" // G3 G1 g3 g1 G3 G1 g3 g1
170 "movq %%mm4,%%mm5\n" // 0 L2 0 L0 0 l2 0 l1 169 "packuswb %%mm7,%%mm7\n" // G2 G0 g2 g0 G2 G0 g2 g0
171 "paddsw %%mm1, %%mm3\n" // lum1+blue:x B3 x B1 x b3 x b1 170 "punpcklbw %%mm3,%%mm7\n" // G3 G2 G1 G0 g3 g2 g1 g0
172 "paddsw %%mm1, %%mm5\n" // lum1+blue:x B2 x B0 x b2 x b0 171
173 "packuswb %%mm3,%%mm3\n" // B3 B1 b3 b1 B3 B1 b3 b1 172 // create B (result in mm5)
174 "packuswb %%mm5,%%mm5\n" // B2 B0 b2 b0 B2 B0 b2 b0 173 "movq %%mm2,%%mm3\n" // 0 L3 0 L1 0 l3 0 l1
175 "punpcklbw %%mm3,%%mm5\n" // B3 B2 B1 B0 b3 b2 b1 b0 174 "movq %%mm4,%%mm5\n" // 0 L2 0 L0 0 l2 0 l1
176 175 "paddsw %%mm1, %%mm3\n" // lum1+blue:x B3 x B1 x b3 x b1
177 // fill destination row1 (needed are mm6=Rr,mm7=Gg,mm5=Bb) 176 "paddsw %%mm1, %%mm5\n" // lum1+blue:x B2 x B0 x b2 x b0
178 177 "packuswb %%mm3,%%mm3\n" // B3 B1 b3 b1 B3 B1 b3 b1
179 "pxor %%mm2,%%mm2\n" // 0 0 0 0 0 0 0 0 178 "packuswb %%mm5,%%mm5\n" // B2 B0 b2 b0 B2 B0 b2 b0
180 "pxor %%mm4,%%mm4\n" // 0 0 0 0 0 0 0 0 179 "punpcklbw %%mm3,%%mm5\n" // B3 B2 B1 B0 b3 b2 b1 b0
181 "movq %%mm6,%%mm1\n" // R3 R2 R1 R0 r3 r2 r1 r0 180
182 "movq %%mm5,%%mm3\n" // B3 B2 B1 B0 b3 b2 b1 b0 181 // fill destination row1 (needed are mm6=Rr,mm7=Gg,mm5=Bb)
183 // process lower lum 182
184 "punpcklbw %%mm4,%%mm1\n" // 0 r3 0 r2 0 r1 0 r0 183 "pxor %%mm2,%%mm2\n" // 0 0 0 0 0 0 0 0
185 "punpcklbw %%mm4,%%mm3\n" // 0 b3 0 b2 0 b1 0 b0 184 "pxor %%mm4,%%mm4\n" // 0 0 0 0 0 0 0 0
186 "movq %%mm1,%%mm2\n" // 0 r3 0 r2 0 r1 0 r0 185 "movq %%mm6,%%mm1\n" // R3 R2 R1 R0 r3 r2 r1 r0
187 "movq %%mm3,%%mm0\n" // 0 b3 0 b2 0 b1 0 b0 186 "movq %%mm5,%%mm3\n" // B3 B2 B1 B0 b3 b2 b1 b0
188 "punpcklwd %%mm1,%%mm3\n" // 0 r1 0 b1 0 r0 0 b0 187
189 "punpckhwd %%mm2,%%mm0\n" // 0 r3 0 b3 0 r2 0 b2 188 // process lower lum
190 189 "punpcklbw %%mm4,%%mm1\n" // 0 r3 0 r2 0 r1 0 r0
191 "pxor %%mm2,%%mm2\n" // 0 0 0 0 0 0 0 0 190 "punpcklbw %%mm4,%%mm3\n" // 0 b3 0 b2 0 b1 0 b0
192 "movq %%mm7,%%mm1\n" // G3 G2 G1 G0 g3 g2 g1 g0 191 "movq %%mm1,%%mm2\n" // 0 r3 0 r2 0 r1 0 r0
193 "punpcklbw %%mm1,%%mm2\n" // g3 0 g2 0 g1 0 g0 0 192 "movq %%mm3,%%mm0\n" // 0 b3 0 b2 0 b1 0 b0
194 "punpcklwd %%mm4,%%mm2\n" // 0 0 g1 0 0 0 g0 0 193 "punpcklwd %%mm1,%%mm3\n" // 0 r1 0 b1 0 r0 0 b0
195 "por %%mm3, %%mm2\n" // 0 r1 g1 b1 0 r0 g0 b0 194 "punpckhwd %%mm2,%%mm0\n" // 0 r3 0 b3 0 r2 0 b2
196 "movq %%mm2,(%3)\n" // wrote out ! row1 195
197 196 "pxor %%mm2,%%mm2\n" // 0 0 0 0 0 0 0 0
198 "pxor %%mm2,%%mm2\n" // 0 0 0 0 0 0 0 0 197 "movq %%mm7,%%mm1\n" // G3 G2 G1 G0 g3 g2 g1 g0
199 "punpcklbw %%mm1,%%mm4\n" // g3 0 g2 0 g1 0 g0 0 198 "punpcklbw %%mm1,%%mm2\n" // g3 0 g2 0 g1 0 g0 0
200 "punpckhwd %%mm2,%%mm4\n" // 0 0 g3 0 0 0 g2 0 199 "punpcklwd %%mm4,%%mm2\n" // 0 0 g1 0 0 0 g0 0
201 "por %%mm0, %%mm4\n" // 0 r3 g3 b3 0 r2 g2 b2 200 "por %%mm3, %%mm2\n" // 0 r1 g1 b1 0 r0 g0 b0
202 "movq %%mm4,8(%3)\n" // wrote out ! row1 201 "movq %%mm2,(%3)\n" // wrote out ! row1
203 202
204 // fill destination row2 (needed are mm6=Rr,mm7=Gg,mm5=Bb) 203 "pxor %%mm2,%%mm2\n" // 0 0 0 0 0 0 0 0
205 // this can be done "destructive" 204 "punpcklbw %%mm1,%%mm4\n" // g3 0 g2 0 g1 0 g0 0
206 "pxor %%mm2,%%mm2\n" // 0 0 0 0 0 0 0 0 205 "punpckhwd %%mm2,%%mm4\n" // 0 0 g3 0 0 0 g2 0
207 "punpckhbw %%mm2,%%mm6\n" // 0 R3 0 R2 0 R1 0 R0 206 "por %%mm0, %%mm4\n" // 0 r3 g3 b3 0 r2 g2 b2
208 "punpckhbw %%mm1,%%mm5\n" // G3 B3 G2 B2 G1 B1 G0 B0 207 "movq %%mm4,8(%3)\n" // wrote out ! row1
209 "movq %%mm5,%%mm1\n" // G3 B3 G2 B2 G1 B1 G0 B0 208
210 "punpcklwd %%mm6,%%mm1\n" // 0 R1 G1 B1 0 R0 G0 B0 209 // fill destination row2 (needed are mm6=Rr,mm7=Gg,mm5=Bb)
211 "movq %%mm1,(%5)\n" // wrote out ! row2 210 // this can be done "destructive"
212 "punpckhwd %%mm6,%%mm5\n" // 0 R3 G3 B3 0 R2 G2 B2 211 "pxor %%mm2,%%mm2\n" // 0 0 0 0 0 0 0 0
213 "movq %%mm5,8(%5)\n" // wrote out ! row2 212 "punpckhbw %%mm2,%%mm6\n" // 0 R3 0 R2 0 R1 0 R0
214 213 "punpckhbw %%mm1,%%mm5\n" // G3 B3 G2 B2 G1 B1 G0 B0
215 "addl $4,%2\n" // lum+4 214 "movq %%mm5,%%mm1\n" // G3 B3 G2 B2 G1 B1 G0 B0
216 "leal 16(%3),%3\n" // row1+16 215 "punpcklwd %%mm6,%%mm1\n" // 0 R1 G1 B1 0 R0 G0 B0
217 "leal 16(%5),%5\n" // row2+16 216 "movq %%mm1,(%5)\n" // wrote out ! row2
218 "addl $2, %%ebx\n" // cr+2 217 "punpckhwd %%mm6,%%mm5\n" // 0 R3 G3 B3 0 R2 G2 B2
219 "addl $2, %1\n" // cb+2 218 "movq %%mm5,8(%5)\n" // wrote out ! row2
220 219
221 "addl $4,%6\n" // x+4 220 "addl $4,%2\n" // lum+4
222 "cmpl %4,%6\n" 221 "leal 16(%3),%3\n" // row1+16
223 222 "leal 16(%5),%5\n" // row2+16
224 "jl 1b\n" 223 "addl $2,(%%esp)\n" // cr+2
225 "addl %4, %2\n" // lum += cols 224 "addl $2,%1\n" // cb+2
226 "addl %8, %3\n" // row1+= mod 225
227 "addl %8, %5\n" // row2+= mod 226 "addl $4,%6\n" // x+4
228 "movl $0, %6\n" // x=0 227 "cmpl %4,%6\n"
229 "cmpl %7, %2\n" 228
230 "jl 1b\n" 229 "jl 1b\n"
231 "emms\n" 230 "addl %4,%2\n" // lum += cols
232 "popl %%ebx\n" 231 "addl %8,%3\n" // row1+= mod
233 : 232 "addl %8,%5\n" // row2+= mod
234 : "m" (cr), "r"(cb),"r"(lum), 233 "movl $0,%6\n" // x=0
235 "r"(row1),"r"(cols),"r"(row2),"m"(x),"m"(y),"m"(mod)); 234 "cmpl %7,%2\n"
235 "jl 1b\n"
236
237 "addl $4,%%esp\n" // get rid of the stack slot we reserved.
238 "emms\n" // reset MMX registers.
239 :
240 : "m" (cr), "r"(cb),"r"(lum),
241 "r"(row1),"r"(cols),"r"(row2),"m"(x),"m"(y),"m"(mod),
242 "m"(MMX_0080w),"m"(MMX_VgrnRGB),"m"(MMX_VredRGB),
243 "m"(MMX_FF00w),"m"(MMX_00FFw),"m"(MMX_UgrnRGB),
244 "m"(MMX_UbluRGB)
245 );
236 } 246 }
237 247
238 void Color565DitherYV12MMX1X( int *colortab, Uint32 *rgb_2_pix, 248 void Color565DitherYV12MMX1X( int *colortab, Uint32 *rgb_2_pix,
239 unsigned char *lum, unsigned char *cr, 249 unsigned char *lum, unsigned char *cr,
240 unsigned char *cb, unsigned char *out, 250 unsigned char *cb, unsigned char *out,
242 { 252 {
243 Uint16 *row1; 253 Uint16 *row1;
244 Uint16 *row2; 254 Uint16 *row2;
245 255
246 unsigned char* y = lum +cols*rows; /* Pointer to the end */ 256 unsigned char* y = lum +cols*rows; /* Pointer to the end */
247 int x=0; 257 int x = 0;
248 row1 = (Uint16 *)out; /* 16 bit target */ 258 row1 = (Uint16 *)out; /* 16 bit target */
249 row2 = (Uint16 *)out+cols+mod; /* start of second row */ 259 row2 = (Uint16 *)out+cols+mod; /* start of second row */
250 mod = (mod+cols+mod)*2; /* increment for row1 in byte */ 260 mod = (mod+cols+mod)*2; /* increment for row1 in byte */
251 261
252 262 __asm__ __volatile__(
253 __asm__ __volatile__( 263 // tap dance to workaround the inability to use %%ebx at will...
254 "pushl %%ebx\n" 264 // move one thing to the stack...
255 "movl %0, %%ebx\n" 265 "pushl $0\n" // save a slot on the stack.
256 266 "pushl %%ebx\n" // save %%ebx.
257 ".align 8\n" 267 "movl %0, %%ebx\n" // put the thing in ebx.
258 "1:\n" 268 "movl %%ebx, 4(%%esp)\n" // put the thing in the stack slot.
259 "movd (%1), %%mm0\n" // 4 Cb 0 0 0 0 u3 u2 u1 u0 269 "popl %%ebx\n" // get back %%ebx (the PIC register).
260 "pxor %%mm7, %%mm7\n" 270
261 "movd (%%ebx), %%mm1\n" // 4 Cr 0 0 0 0 v3 v2 v1 v0 271 ".align 8\n"
262 "punpcklbw %%mm7, %%mm0\n" // 4 W cb 0 u3 0 u2 0 u1 0 u0 272 "1:\n"
263 "punpcklbw %%mm7, %%mm1\n" // 4 W cr 0 v3 0 v2 0 v1 0 v0 273
264 "psubw _MMX_0080w, %%mm0\n" 274 "movd (%1), %%mm0\n" // 4 Cb 0 0 0 0 u3 u2 u1 u0
265 "psubw _MMX_0080w, %%mm1\n" 275 "pxor %%mm7, %%mm7\n"
266 "movq %%mm0, %%mm2\n" // Cb 0 u3 0 u2 0 u1 0 u0 276 "pushl %%ebx\n"
267 "movq %%mm1, %%mm3\n" // Cr 277 "movl 4(%%esp), %%ebx\n"
268 "pmullw _MMX_Ugrn565, %%mm2\n" // Cb2green 0 R3 0 R2 0 R1 0 R0 278 "movd (%%ebx), %%mm1\n" // 4 Cr 0 0 0 0 v3 v2 v1 v0
269 "movq (%2), %%mm6\n" // L1 l7 L6 L5 L4 L3 L2 L1 L0 279 "popl %%ebx\n"
270 "pmullw _MMX_Ublu5x5, %%mm0\n" // Cb2blue 280
271 "pand _MMX_00FFw, %%mm6\n" // L1 00 L6 00 L4 00 L2 00 L0 281 "punpcklbw %%mm7, %%mm0\n" // 4 W cb 0 u3 0 u2 0 u1 0 u0
272 "pmullw _MMX_Vgrn565, %%mm3\n" // Cr2green 282 "punpcklbw %%mm7, %%mm1\n" // 4 W cr 0 v3 0 v2 0 v1 0 v0
273 "movq (%2), %%mm7\n" // L2 283 "psubw %9, %%mm0\n"
274 "pmullw _MMX_Vred5x5, %%mm1\n" // Cr2red 284 "psubw %9, %%mm1\n"
275 "psrlw $8, %%mm7\n" // L2 00 L7 00 L5 00 L3 00 L1 285 "movq %%mm0, %%mm2\n" // Cb 0 u3 0 u2 0 u1 0 u0
276 "pmullw _MMX_Ycoeff, %%mm6\n" // lum1 286 "movq %%mm1, %%mm3\n" // Cr
277 "paddw %%mm3, %%mm2\n" // Cb2green + Cr2green == green 287 "pmullw %10, %%mm2\n" // Cb2green 0 R3 0 R2 0 R1 0 R0
278 "pmullw _MMX_Ycoeff, %%mm7\n" // lum2 288 "movq (%2), %%mm6\n" // L1 l7 L6 L5 L4 L3 L2 L1 L0
279 289 "pmullw %11, %%mm0\n" // Cb2blue
280 "movq %%mm6, %%mm4\n" // lum1 290 "pand %12, %%mm6\n" // L1 00 L6 00 L4 00 L2 00 L0
281 "paddw %%mm0, %%mm6\n" // lum1 +blue 00 B6 00 B4 00 B2 00 B0 291 "pmullw %13, %%mm3\n" // Cr2green
282 "movq %%mm4, %%mm5\n" // lum1 292 "movq (%2), %%mm7\n" // L2
283 "paddw %%mm1, %%mm4\n" // lum1 +red 00 R6 00 R4 00 R2 00 R0 293 "pmullw %14, %%mm1\n" // Cr2red
284 "paddw %%mm2, %%mm5\n" // lum1 +green 00 G6 00 G4 00 G2 00 G0 294 "psrlw $8, %%mm7\n" // L2 00 L7 00 L5 00 L3 00 L1
285 "psraw $6, %%mm4\n" // R1 0 .. 64 295 "pmullw %15, %%mm6\n" // lum1
286 "movq %%mm7, %%mm3\n" // lum2 00 L7 00 L5 00 L3 00 L1 296 "paddw %%mm3, %%mm2\n" // Cb2green + Cr2green == green
287 "psraw $6, %%mm5\n" // G1 - .. + 297 "pmullw %15, %%mm7\n" // lum2
288 "paddw %%mm0, %%mm7\n" // Lum2 +blue 00 B7 00 B5 00 B3 00 B1 298
289 "psraw $6, %%mm6\n" // B1 0 .. 64 299 "movq %%mm6, %%mm4\n" // lum1
290 "packuswb %%mm4, %%mm4\n" // R1 R1 300 "paddw %%mm0, %%mm6\n" // lum1 +blue 00 B6 00 B4 00 B2 00 B0
291 "packuswb %%mm5, %%mm5\n" // G1 G1 301 "movq %%mm4, %%mm5\n" // lum1
292 "packuswb %%mm6, %%mm6\n" // B1 B1 302 "paddw %%mm1, %%mm4\n" // lum1 +red 00 R6 00 R4 00 R2 00 R0
293 "punpcklbw %%mm4, %%mm4\n" 303 "paddw %%mm2, %%mm5\n" // lum1 +green 00 G6 00 G4 00 G2 00 G0
294 "punpcklbw %%mm5, %%mm5\n" 304 "psraw $6, %%mm4\n" // R1 0 .. 64
295 305 "movq %%mm7, %%mm3\n" // lum2 00 L7 00 L5 00 L3 00 L1
296 "pand _MMX_red565, %%mm4\n" 306 "psraw $6, %%mm5\n" // G1 - .. +
297 "psllw $3, %%mm5\n" // GREEN 1 307 "paddw %%mm0, %%mm7\n" // Lum2 +blue 00 B7 00 B5 00 B3 00 B1
298 "punpcklbw %%mm6, %%mm6\n" 308 "psraw $6, %%mm6\n" // B1 0 .. 64
299 "pand _MMX_grn565, %%mm5\n" 309 "packuswb %%mm4, %%mm4\n" // R1 R1
300 "pand _MMX_red565, %%mm6\n" 310 "packuswb %%mm5, %%mm5\n" // G1 G1
301 "por %%mm5, %%mm4\n" // 311 "packuswb %%mm6, %%mm6\n" // B1 B1
302 "psrlw $11, %%mm6\n" // BLUE 1 312 "punpcklbw %%mm4, %%mm4\n"
303 "movq %%mm3, %%mm5\n" // lum2 313 "punpcklbw %%mm5, %%mm5\n"
304 "paddw %%mm1, %%mm3\n" // lum2 +red 00 R7 00 R5 00 R3 00 R1 314
305 "paddw %%mm2, %%mm5\n" // lum2 +green 00 G7 00 G5 00 G3 00 G1 315 "pand %16, %%mm4\n"
306 "psraw $6, %%mm3\n" // R2 316 "psllw $3, %%mm5\n" // GREEN 1
307 "por %%mm6, %%mm4\n" // MM4 317 "punpcklbw %%mm6, %%mm6\n"
308 "psraw $6, %%mm5\n" // G2 318 "pand %17, %%mm5\n"
309 "movq (%2, %4), %%mm6\n" // L3 load lum2 319 "pand %16, %%mm6\n"
310 "psraw $6, %%mm7\n" 320 "por %%mm5, %%mm4\n" //
311 "packuswb %%mm3, %%mm3\n" 321 "psrlw $11, %%mm6\n" // BLUE 1
312 "packuswb %%mm5, %%mm5\n" 322 "movq %%mm3, %%mm5\n" // lum2
313 "packuswb %%mm7, %%mm7\n" 323 "paddw %%mm1, %%mm3\n" // lum2 +red 00 R7 00 R5 00 R3 00 R1
314 "pand _MMX_00FFw, %%mm6\n" // L3 324 "paddw %%mm2, %%mm5\n" // lum2 +green 00 G7 00 G5 00 G3 00 G1
315 "punpcklbw %%mm3, %%mm3\n" 325 "psraw $6, %%mm3\n" // R2
316 "punpcklbw %%mm5, %%mm5\n" 326 "por %%mm6, %%mm4\n" // MM4
317 "pmullw _MMX_Ycoeff, %%mm6\n" // lum3 327 "psraw $6, %%mm5\n" // G2
318 "punpcklbw %%mm7, %%mm7\n" 328 "movq (%2, %4), %%mm6\n" // L3 load lum2
319 "psllw $3, %%mm5\n" // GREEN 2 329 "psraw $6, %%mm7\n"
320 "pand _MMX_red565, %%mm7\n" 330 "packuswb %%mm3, %%mm3\n"
321 "pand _MMX_red565, %%mm3\n" 331 "packuswb %%mm5, %%mm5\n"
322 "psrlw $11, %%mm7\n" // BLUE 2 332 "packuswb %%mm7, %%mm7\n"
323 "pand _MMX_grn565, %%mm5\n" 333 "pand %12, %%mm6\n" // L3
324 "por %%mm7, %%mm3\n" 334 "punpcklbw %%mm3, %%mm3\n"
325 "movq (%2,%4), %%mm7\n" // L4 load lum2 335 "punpcklbw %%mm5, %%mm5\n"
326 "por %%mm5, %%mm3\n" // 336 "pmullw %15, %%mm6\n" // lum3
327 "psrlw $8, %%mm7\n" // L4 337 "punpcklbw %%mm7, %%mm7\n"
328 "movq %%mm4, %%mm5\n" 338 "psllw $3, %%mm5\n" // GREEN 2
329 "punpcklwd %%mm3, %%mm4\n" 339 "pand %16, %%mm7\n"
330 "pmullw _MMX_Ycoeff, %%mm7\n" // lum4 340 "pand %16, %%mm3\n"
331 "punpckhwd %%mm3, %%mm5\n" 341 "psrlw $11, %%mm7\n" // BLUE 2
332 342 "pand %17, %%mm5\n"
333 "movq %%mm4, (%3)\n" // write row1 343 "por %%mm7, %%mm3\n"
334 "movq %%mm5, 8(%3)\n" // write row1 344 "movq (%2,%4), %%mm7\n" // L4 load lum2
335 345 "por %%mm5, %%mm3\n" //
336 "movq %%mm6, %%mm4\n" // Lum3 346 "psrlw $8, %%mm7\n" // L4
337 "paddw %%mm0, %%mm6\n" // Lum3 +blue 347 "movq %%mm4, %%mm5\n"
338 348 "punpcklwd %%mm3, %%mm4\n"
339 "movq %%mm4, %%mm5\n" // Lum3 349 "pmullw %15, %%mm7\n" // lum4
340 "paddw %%mm1, %%mm4\n" // Lum3 +red 350 "punpckhwd %%mm3, %%mm5\n"
341 "paddw %%mm2, %%mm5\n" // Lum3 +green 351
342 "psraw $6, %%mm4\n" 352 "movq %%mm4, (%3)\n" // write row1
343 "movq %%mm7, %%mm3\n" // Lum4 353 "movq %%mm5, 8(%3)\n" // write row1
344 "psraw $6, %%mm5\n" 354
345 "paddw %%mm0, %%mm7\n" // Lum4 +blue 355 "movq %%mm6, %%mm4\n" // Lum3
346 "psraw $6, %%mm6\n" // Lum3 +blue 356 "paddw %%mm0, %%mm6\n" // Lum3 +blue
347 "movq %%mm3, %%mm0\n" // Lum4 357
348 "packuswb %%mm4, %%mm4\n" 358 "movq %%mm4, %%mm5\n" // Lum3
349 "paddw %%mm1, %%mm3\n" // Lum4 +red 359 "paddw %%mm1, %%mm4\n" // Lum3 +red
350 "packuswb %%mm5, %%mm5\n" 360 "paddw %%mm2, %%mm5\n" // Lum3 +green
351 "paddw %%mm2, %%mm0\n" // Lum4 +green 361 "psraw $6, %%mm4\n"
352 "packuswb %%mm6, %%mm6\n" 362 "movq %%mm7, %%mm3\n" // Lum4
353 "punpcklbw %%mm4, %%mm4\n" 363 "psraw $6, %%mm5\n"
354 "punpcklbw %%mm5, %%mm5\n" 364 "paddw %%mm0, %%mm7\n" // Lum4 +blue
355 "punpcklbw %%mm6, %%mm6\n" 365 "psraw $6, %%mm6\n" // Lum3 +blue
356 "psllw $3, %%mm5\n" // GREEN 3 366 "movq %%mm3, %%mm0\n" // Lum4
357 "pand _MMX_red565, %%mm4\n" 367 "packuswb %%mm4, %%mm4\n"
358 "psraw $6, %%mm3\n" // psr 6 368 "paddw %%mm1, %%mm3\n" // Lum4 +red
359 "psraw $6, %%mm0\n" 369 "packuswb %%mm5, %%mm5\n"
360 "pand _MMX_red565, %%mm6\n" // BLUE 370 "paddw %%mm2, %%mm0\n" // Lum4 +green
361 "pand _MMX_grn565, %%mm5\n" 371 "packuswb %%mm6, %%mm6\n"
362 "psrlw $11, %%mm6\n" // BLUE 3 372 "punpcklbw %%mm4, %%mm4\n"
363 "por %%mm5, %%mm4\n" 373 "punpcklbw %%mm5, %%mm5\n"
364 "psraw $6, %%mm7\n" 374 "punpcklbw %%mm6, %%mm6\n"
365 "por %%mm6, %%mm4\n" 375 "psllw $3, %%mm5\n" // GREEN 3
366 "packuswb %%mm3, %%mm3\n" 376 "pand %16, %%mm4\n"
367 "packuswb %%mm0, %%mm0\n" 377 "psraw $6, %%mm3\n" // psr 6
368 "packuswb %%mm7, %%mm7\n" 378 "psraw $6, %%mm0\n"
369 "punpcklbw %%mm3, %%mm3\n" 379 "pand %16, %%mm6\n" // BLUE
370 "punpcklbw %%mm0, %%mm0\n" 380 "pand %17, %%mm5\n"
371 "punpcklbw %%mm7, %%mm7\n" 381 "psrlw $11, %%mm6\n" // BLUE 3
372 "pand _MMX_red565, %%mm3\n" 382 "por %%mm5, %%mm4\n"
373 "pand _MMX_red565, %%mm7\n" // BLUE 383 "psraw $6, %%mm7\n"
374 "psllw $3, %%mm0\n" // GREEN 4 384 "por %%mm6, %%mm4\n"
375 "psrlw $11, %%mm7\n" 385 "packuswb %%mm3, %%mm3\n"
376 "pand _MMX_grn565, %%mm0\n" 386 "packuswb %%mm0, %%mm0\n"
377 "por %%mm7, %%mm3\n" 387 "packuswb %%mm7, %%mm7\n"
378 "por %%mm0, %%mm3\n" 388 "punpcklbw %%mm3, %%mm3\n"
379 389 "punpcklbw %%mm0, %%mm0\n"
380 "movq %%mm4, %%mm5\n" 390 "punpcklbw %%mm7, %%mm7\n"
381 391 "pand %16, %%mm3\n"
382 "punpcklwd %%mm3, %%mm4\n" 392 "pand %16, %%mm7\n" // BLUE
383 "punpckhwd %%mm3, %%mm5\n" 393 "psllw $3, %%mm0\n" // GREEN 4
384 394 "psrlw $11, %%mm7\n"
385 "movq %%mm4, (%5)\n" 395 "pand %17, %%mm0\n"
386 "movq %%mm5, 8(%5)\n" 396 "por %%mm7, %%mm3\n"
387 397 "por %%mm0, %%mm3\n"
388 "addl $8, %6\n" 398
389 "addl $8, %2\n" 399 "movq %%mm4, %%mm5\n"
390 "addl $4, %%ebx\n" 400
391 "addl $4, %1\n" 401 "punpcklwd %%mm3, %%mm4\n"
392 "cmpl %4, %6\n" 402 "punpckhwd %%mm3, %%mm5\n"
393 "leal 16(%3), %3\n" 403
394 "leal 16(%5),%5\n" // row2+16 404 "movq %%mm4, (%5)\n"
395 405 "movq %%mm5, 8(%5)\n"
396 406
397 "jl 1b\n" 407 "addl $8, %6\n"
398 "addl %4, %2\n" // lum += cols 408 "addl $8, %2\n"
399 "addl %8, %3\n" // row1+= mod 409 "addl $4, (%%esp)\n"
400 "addl %8, %5\n" // row2+= mod 410 "addl $4, %1\n"
401 "movl $0, %6\n" // x=0 411 "cmpl %4, %6\n"
402 "cmpl %7, %2\n" 412 "leal 16(%3), %3\n"
403 "jl 1b\n" 413 "leal 16(%5),%5\n" // row2+16
404 "emms\n" 414
405 "popl %%ebx\n" 415 "jl 1b\n"
406 : 416 "addl %4, %2\n" // lum += cols
407 :"m" (cr), "r"(cb),"r"(lum), 417 "addl %8, %3\n" // row1+= mod
408 "r"(row1),"r"(cols),"r"(row2),"m"(x),"m"(y),"m"(mod)); 418 "addl %8, %5\n" // row2+= mod
419 "movl $0, %6\n" // x=0
420 "cmpl %7, %2\n"
421 "jl 1b\n"
422 "addl $4, %%esp\n" // get rid of the stack slot we reserved.
423 "emms\n"
424 :
425 : "m" (cr), "r"(cb),"r"(lum),
426 "r"(row1),"r"(cols),"r"(row2),"m"(x),"m"(y),"m"(mod),
427 "m"(MMX_0080w),"m"(MMX_Ugrn565),"m"(MMX_Ublu5x5),
428 "m"(MMX_00FFw),"m"(MMX_Vgrn565),"m"(MMX_Vred5x5),
429 "m"(MMX_Ycoeff),"m"(MMX_red565),"m"(MMX_grn565)
430 );
409 } 431 }
410 432
411 #endif /* GCC i386 inline assembly */
412 #endif /* 0 */
413
414 /* *INDENT-ON* */ 433 /* *INDENT-ON* */
415 434
435 #endif /* GCC3 i386 inline assembly */
436
416 /* vi: set ts=4 sw=4 expandtab: */ 437 /* vi: set ts=4 sw=4 expandtab: */
438