Merged r3211:3213 from branches/SDL-1.2: YUV MMX inline asm for GCC.
authorRyan C. Gordon <icculus@icculus.org>
Wed, 11 Jul 2007 07:39:01 +0000
changeset 216807f084fe97d0
parent 2167 8f2174e22cd5
child 2169 13cf2d5eda86
Merged r3211:3213 from branches/SDL-1.2: YUV MMX inline asm for GCC.
src/video/SDL_yuv_mmx.c
src/video/SDL_yuv_sw.c
     1.1 --- a/src/video/SDL_yuv_mmx.c	Wed Jul 11 04:47:25 2007 +0000
     1.2 +++ b/src/video/SDL_yuv_mmx.c	Wed Jul 11 07:39:01 2007 +0000
     1.3 @@ -21,38 +21,37 @@
     1.4  */
     1.5  #include "SDL_config.h"
     1.6  
     1.7 -/* *INDENT-OFF* */
     1.8 -
     1.9 -#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) */
    1.10 -#if defined(__GNUC__) && defined(__i386__) && SDL_ASSEMBLY_ROUTINES
    1.11 +#if (__GNUC__ > 2) && defined(__i386__) && SDL_ASSEMBLY_ROUTINES
    1.12  
    1.13  #include "SDL_stdinc.h"
    1.14  
    1.15 -#define ASM_ARRAY(x) x[] __asm__("_" #x) __attribute__((used))
    1.16 - 
    1.17 -static unsigned int  ASM_ARRAY(MMX_0080w)    = {0x00800080, 0x00800080};
    1.18 -static unsigned int  ASM_ARRAY(MMX_00FFw)    = {0x00ff00ff, 0x00ff00ff};
    1.19 -static unsigned int  ASM_ARRAY(MMX_FF00w)    = {0xff00ff00, 0xff00ff00};
    1.20 +#include "mmx.h"
    1.21  
    1.22 -static unsigned short ASM_ARRAY(MMX_Ycoeff)  = {0x004a, 0x004a, 0x004a, 0x004a};
    1.23 +/* *INDENT-OFF* */
    1.24  
    1.25 -static unsigned short ASM_ARRAY(MMX_UbluRGB) = {0x0072, 0x0072, 0x0072, 0x0072};
    1.26 -static unsigned short ASM_ARRAY(MMX_VredRGB) = {0x0059, 0x0059, 0x0059, 0x0059};
    1.27 -static unsigned short ASM_ARRAY(MMX_UgrnRGB) = {0xffea, 0xffea, 0xffea, 0xffea};
    1.28 -static unsigned short ASM_ARRAY(MMX_VgrnRGB) = {0xffd2, 0xffd2, 0xffd2, 0xffd2};
    1.29 +static mmx_t MMX_0080w    = { .ud = {0x00800080, 0x00800080} };
    1.30 +static mmx_t MMX_00FFw    = { .ud = {0x00ff00ff, 0x00ff00ff} };
    1.31 +static mmx_t MMX_FF00w    = { .ud = {0xff00ff00, 0xff00ff00} };
    1.32  
    1.33 -static unsigned short ASM_ARRAY(MMX_Ublu5x5) = {0x0081, 0x0081, 0x0081, 0x0081};
    1.34 -static unsigned short ASM_ARRAY(MMX_Vred5x5) = {0x0066, 0x0066, 0x0066, 0x0066};
    1.35 -static unsigned short ASM_ARRAY(MMX_Ugrn555) = {0xffe7, 0xffe7, 0xffe7, 0xffe7};
    1.36 -static unsigned short ASM_ARRAY(MMX_Vgrn555) = {0xffcc, 0xffcc, 0xffcc, 0xffcc};
    1.37 -static unsigned short ASM_ARRAY(MMX_Ugrn565) = {0xffe8, 0xffe8, 0xffe8, 0xffe8};
    1.38 -static unsigned short ASM_ARRAY(MMX_Vgrn565) = {0xffcd, 0xffcd, 0xffcd, 0xffcd};
    1.39 +static mmx_t MMX_Ycoeff   = { .uw = {0x004a, 0x004a, 0x004a, 0x004a} };
    1.40  
    1.41 -static unsigned short ASM_ARRAY(MMX_red555)  = {0x7c00, 0x7c00, 0x7c00, 0x7c00};
    1.42 -static unsigned short ASM_ARRAY(MMX_red565)  = {0xf800, 0xf800, 0xf800, 0xf800};
    1.43 -static unsigned short ASM_ARRAY(MMX_grn555)  = {0x03e0, 0x03e0, 0x03e0, 0x03e0};
    1.44 -static unsigned short ASM_ARRAY(MMX_grn565)  = {0x07e0, 0x07e0, 0x07e0, 0x07e0};
    1.45 -static unsigned short ASM_ARRAY(MMX_blu5x5)  = {0x001f, 0x001f, 0x001f, 0x001f};
    1.46 +static mmx_t MMX_UbluRGB  = { .uw = {0x0072, 0x0072, 0x0072, 0x0072} };
    1.47 +static mmx_t MMX_VredRGB  = { .uw = {0x0059, 0x0059, 0x0059, 0x0059} };
    1.48 +static mmx_t MMX_UgrnRGB  = { .uw = {0xffea, 0xffea, 0xffea, 0xffea} };
    1.49 +static mmx_t MMX_VgrnRGB  = { .uw = {0xffd2, 0xffd2, 0xffd2, 0xffd2} };
    1.50 +
    1.51 +static mmx_t MMX_Ublu5x5  = { .uw = {0x0081, 0x0081, 0x0081, 0x0081} };
    1.52 +static mmx_t MMX_Vred5x5  = { .uw = {0x0066, 0x0066, 0x0066, 0x0066} };
    1.53 +static mmx_t MMX_Ugrn555  = { .uw = {0xffe7, 0xffe7, 0xffe7, 0xffe7} };
    1.54 +static mmx_t MMX_Vgrn555  = { .uw = {0xffcc, 0xffcc, 0xffcc, 0xffcc} };
    1.55 +static mmx_t MMX_Ugrn565  = { .uw = {0xffe8, 0xffe8, 0xffe8, 0xffe8} };
    1.56 +static mmx_t MMX_Vgrn565  = { .uw = {0xffcd, 0xffcd, 0xffcd, 0xffcd} };
    1.57 +
    1.58 +static mmx_t MMX_red555   = { .uw = {0x7c00, 0x7c00, 0x7c00, 0x7c00} };
    1.59 +static mmx_t MMX_red565   = { .uw = {0xf800, 0xf800, 0xf800, 0xf800} };
    1.60 +static mmx_t MMX_grn555   = { .uw = {0x03e0, 0x03e0, 0x03e0, 0x03e0} };
    1.61 +static mmx_t MMX_grn565   = { .uw = {0x07e0, 0x07e0, 0x07e0, 0x07e0} };
    1.62 +static mmx_t MMX_blu5x5   = { .uw = {0x001f, 0x001f, 0x001f, 0x001f} };
    1.63  
    1.64  /**
    1.65     This MMX assembler is my first assembler/MMX program ever.
    1.66 @@ -92,147 +91,158 @@
    1.67      Uint32 *row2;
    1.68  
    1.69      unsigned char* y = lum +cols*rows;    // Pointer to the end
    1.70 -    int x=0;
    1.71 +    int x = 0;
    1.72      row1 = (Uint32 *)out;                 // 32 bit target
    1.73 -    row2 = (Uint32 *)out+cols+mod;        // start of second row 
    1.74 +    row2 = (Uint32 *)out+cols+mod;        // start of second row
    1.75      mod = (mod+cols+mod)*4;               // increment for row1 in byte
    1.76  
    1.77      __asm__ __volatile__ (
    1.78 -/* We don't really care about PIC - the code should be rewritten to use
    1.79 -   relative addressing for the static tables, so right now we take the
    1.80 -   COW hit on the pages this code resides. Big deal.
    1.81 -   This spill is just to reduce register pressure in the PIC case. */
    1.82 -		 "pushl %%ebx\n"
    1.83 -		 "movl %0, %%ebx\n"
    1.84 +        // tap dance to workaround the inability to use %%ebx at will...
    1.85 +        //  move one thing to the stack...
    1.86 +        "pushl $0\n"  // save a slot on the stack.
    1.87 +        "pushl %%ebx\n"  // save %%ebx.
    1.88 +        "movl %0, %%ebx\n"  // put the thing in ebx.
    1.89 +        "movl %%ebx,4(%%esp)\n"  // put the thing in the stack slot.
    1.90 +        "popl %%ebx\n"  // get back %%ebx (the PIC register).
    1.91  
    1.92 -	         ".align 8\n"
    1.93 -		 "1:\n"
    1.94 -		
    1.95 -		 // create Cr (result in mm1)
    1.96 -		 "movd (%%ebx), %%mm1\n"   //         0  0  0  0  v3 v2 v1 v0
    1.97 -		 "pxor %%mm7,%%mm7\n"      //         00 00 00 00 00 00 00 00
    1.98 -		 "movd (%2), %%mm2\n"           //    0  0  0  0 l3 l2 l1 l0
    1.99 -		 "punpcklbw %%mm7,%%mm1\n" //         0  v3 0  v2 00 v1 00 v0
   1.100 -		 "punpckldq %%mm1,%%mm1\n" //         00 v1 00 v0 00 v1 00 v0
   1.101 -		 "psubw _MMX_0080w,%%mm1\n"  // mm1-128:r1 r1 r0 r0 r1 r1 r0 r0 
   1.102 +        ".align 8\n"
   1.103 +        "1:\n"
   1.104  
   1.105 -		 // create Cr_g (result in mm0)
   1.106 -		 "movq %%mm1,%%mm0\n"           // r1 r1 r0 r0 r1 r1 r0 r0
   1.107 -		 "pmullw _MMX_VgrnRGB,%%mm0\n"// red*-46dec=0.7136*64
   1.108 -		 "pmullw _MMX_VredRGB,%%mm1\n"// red*89dec=1.4013*64
   1.109 -		 "psraw  $6, %%mm0\n"           // red=red/64
   1.110 -		 "psraw  $6, %%mm1\n"           // red=red/64
   1.111 -		 
   1.112 -		 // create L1 L2 (result in mm2,mm4)
   1.113 -		 // L2=lum+cols
   1.114 -		 "movq (%2,%4),%%mm3\n"         //    0  0  0  0 L3 L2 L1 L0
   1.115 -		 "punpckldq %%mm3,%%mm2\n"      //   L3 L2 L1 L0 l3 l2 l1 l0
   1.116 -		 "movq %%mm2,%%mm4\n"           //   L3 L2 L1 L0 l3 l2 l1 l0
   1.117 -		 "pand _MMX_FF00w,%%mm2\n"      //   L3 0  L1  0 l3  0 l1  0
   1.118 -		 "pand _MMX_00FFw,%%mm4\n"      //   0  L2  0 L0  0 l2  0 l0
   1.119 -		 "psrlw $8,%%mm2\n"             //   0  L3  0 L1  0 l3  0 l1
   1.120 +        // create Cr (result in mm1)
   1.121 +        "pushl %%ebx\n"
   1.122 +        "movl 4(%%esp),%%ebx\n"
   1.123 +        "movd (%%ebx),%%mm1\n"   //         0  0  0  0  v3 v2 v1 v0
   1.124 +        "popl %%ebx\n"
   1.125 +        "pxor %%mm7,%%mm7\n"      //         00 00 00 00 00 00 00 00
   1.126 +        "movd (%2), %%mm2\n"           //    0  0  0  0 l3 l2 l1 l0
   1.127 +        "punpcklbw %%mm7,%%mm1\n" //         0  v3 0  v2 00 v1 00 v0
   1.128 +        "punpckldq %%mm1,%%mm1\n" //         00 v1 00 v0 00 v1 00 v0
   1.129 +        "psubw %9,%%mm1\n"        // mm1-128:r1 r1 r0 r0 r1 r1 r0 r0
   1.130  
   1.131 -		 // create R (result in mm6)
   1.132 -		 "movq %%mm2,%%mm5\n"           //   0 L3  0 L1  0 l3  0 l1
   1.133 -		 "movq %%mm4,%%mm6\n"           //   0 L2  0 L0  0 l2  0 l0
   1.134 -		 "paddsw  %%mm1, %%mm5\n"       // lum1+red:x R3 x R1 x r3 x r1
   1.135 -		 "paddsw  %%mm1, %%mm6\n"       // lum1+red:x R2 x R0 x r2 x r0
   1.136 -		 "packuswb %%mm5,%%mm5\n"       //  R3 R1 r3 r1 R3 R1 r3 r1
   1.137 -		 "packuswb %%mm6,%%mm6\n"       //  R2 R0 r2 r0 R2 R0 r2 r0
   1.138 -		 "pxor %%mm7,%%mm7\n"      //         00 00 00 00 00 00 00 00
   1.139 -		 "punpcklbw %%mm5,%%mm6\n"      //  R3 R2 R1 R0 r3 r2 r1 r0
   1.140 +        // create Cr_g (result in mm0)
   1.141 +        "movq %%mm1,%%mm0\n"           // r1 r1 r0 r0 r1 r1 r0 r0
   1.142 +        "pmullw %10,%%mm0\n"           // red*-46dec=0.7136*64
   1.143 +        "pmullw %11,%%mm1\n"           // red*89dec=1.4013*64
   1.144 +        "psraw  $6, %%mm0\n"           // red=red/64
   1.145 +        "psraw  $6, %%mm1\n"           // red=red/64
   1.146  
   1.147 -		 // create Cb (result in mm1)
   1.148 -		 "movd (%1), %%mm1\n"      //         0  0  0  0  u3 u2 u1 u0
   1.149 -		 "punpcklbw %%mm7,%%mm1\n" //         0  u3 0  u2 00 u1 00 u0
   1.150 -		 "punpckldq %%mm1,%%mm1\n" //         00 u1 00 u0 00 u1 00 u0
   1.151 -		 "psubw _MMX_0080w,%%mm1\n"  // mm1-128:u1 u1 u0 u0 u1 u1 u0 u0 
   1.152 -		 // create Cb_g (result in mm5)
   1.153 -		 "movq %%mm1,%%mm5\n"            // u1 u1 u0 u0 u1 u1 u0 u0
   1.154 -		 "pmullw _MMX_UgrnRGB,%%mm5\n"    // blue*-109dec=1.7129*64
   1.155 -		 "pmullw _MMX_UbluRGB,%%mm1\n"    // blue*114dec=1.78125*64
   1.156 -		 "psraw  $6, %%mm5\n"            // blue=red/64
   1.157 -		 "psraw  $6, %%mm1\n"            // blue=blue/64
   1.158 +        // create L1 L2 (result in mm2,mm4)
   1.159 +        // L2=lum+cols
   1.160 +        "movq (%2,%4),%%mm3\n"         //    0  0  0  0 L3 L2 L1 L0
   1.161 +        "punpckldq %%mm3,%%mm2\n"      //   L3 L2 L1 L0 l3 l2 l1 l0
   1.162 +        "movq %%mm2,%%mm4\n"           //   L3 L2 L1 L0 l3 l2 l1 l0
   1.163 +        "pand %12,%%mm2\n"             //   L3 0  L1  0 l3  0 l1  0
   1.164 +        "pand %13,%%mm4\n"             //   0  L2  0 L0  0 l2  0 l0
   1.165 +        "psrlw $8,%%mm2\n"             //   0  L3  0 L1  0 l3  0 l1
   1.166  
   1.167 -		 // create G (result in mm7)
   1.168 -		 "movq %%mm2,%%mm3\n"      //   0  L3  0 L1  0 l3  0 l1
   1.169 -		 "movq %%mm4,%%mm7\n"      //   0  L2  0 L0  0 l2  0 l1
   1.170 -		 "paddsw  %%mm5, %%mm3\n"  // lum1+Cb_g:x G3t x G1t x g3t x g1t
   1.171 -		 "paddsw  %%mm5, %%mm7\n"  // lum1+Cb_g:x G2t x G0t x g2t x g0t
   1.172 -		 "paddsw  %%mm0, %%mm3\n"  // lum1+Cr_g:x G3  x G1  x g3  x g1
   1.173 -		 "paddsw  %%mm0, %%mm7\n"  // lum1+blue:x G2  x G0  x g2  x g0
   1.174 -		 "packuswb %%mm3,%%mm3\n"  // G3 G1 g3 g1 G3 G1 g3 g1
   1.175 -		 "packuswb %%mm7,%%mm7\n"  // G2 G0 g2 g0 G2 G0 g2 g0
   1.176 -		 "punpcklbw %%mm3,%%mm7\n" // G3 G2 G1 G0 g3 g2 g1 g0
   1.177 -		 
   1.178 -		 // create B (result in mm5)
   1.179 -		 "movq %%mm2,%%mm3\n"         //   0  L3  0 L1  0 l3  0 l1
   1.180 -		 "movq %%mm4,%%mm5\n"         //   0  L2  0 L0  0 l2  0 l1
   1.181 -		 "paddsw  %%mm1, %%mm3\n"     // lum1+blue:x B3 x B1 x b3 x b1
   1.182 -		 "paddsw  %%mm1, %%mm5\n"     // lum1+blue:x B2 x B0 x b2 x b0
   1.183 -		 "packuswb %%mm3,%%mm3\n"     // B3 B1 b3 b1 B3 B1 b3 b1
   1.184 -		 "packuswb %%mm5,%%mm5\n"     // B2 B0 b2 b0 B2 B0 b2 b0
   1.185 -		 "punpcklbw %%mm3,%%mm5\n"    // B3 B2 B1 B0 b3 b2 b1 b0
   1.186 +        // create R (result in mm6)
   1.187 +        "movq %%mm2,%%mm5\n"           //   0 L3  0 L1  0 l3  0 l1
   1.188 +        "movq %%mm4,%%mm6\n"           //   0 L2  0 L0  0 l2  0 l0
   1.189 +        "paddsw  %%mm1, %%mm5\n"       // lum1+red:x R3 x R1 x r3 x r1
   1.190 +        "paddsw  %%mm1, %%mm6\n"       // lum1+red:x R2 x R0 x r2 x r0
   1.191 +        "packuswb %%mm5,%%mm5\n"       //  R3 R1 r3 r1 R3 R1 r3 r1
   1.192 +        "packuswb %%mm6,%%mm6\n"       //  R2 R0 r2 r0 R2 R0 r2 r0
   1.193 +        "pxor %%mm7,%%mm7\n"      //         00 00 00 00 00 00 00 00
   1.194 +        "punpcklbw %%mm5,%%mm6\n"      //  R3 R2 R1 R0 r3 r2 r1 r0
   1.195  
   1.196 -		 // fill destination row1 (needed are mm6=Rr,mm7=Gg,mm5=Bb)
   1.197 +        // create Cb (result in mm1)
   1.198 +        "movd (%1), %%mm1\n"      //         0  0  0  0  u3 u2 u1 u0
   1.199 +        "punpcklbw %%mm7,%%mm1\n" //         0  u3 0  u2 00 u1 00 u0
   1.200 +        "punpckldq %%mm1,%%mm1\n" //         00 u1 00 u0 00 u1 00 u0
   1.201 +        "psubw %9,%%mm1\n"        // mm1-128:u1 u1 u0 u0 u1 u1 u0 u0
   1.202  
   1.203 -		 "pxor %%mm2,%%mm2\n"           //  0  0  0  0  0  0  0  0
   1.204 -		 "pxor %%mm4,%%mm4\n"           //  0  0  0  0  0  0  0  0
   1.205 -		 "movq %%mm6,%%mm1\n"           // R3 R2 R1 R0 r3 r2 r1 r0
   1.206 -		 "movq %%mm5,%%mm3\n"           // B3 B2 B1 B0 b3 b2 b1 b0
   1.207 -		 // process lower lum
   1.208 -		 "punpcklbw %%mm4,%%mm1\n"      //  0 r3  0 r2  0 r1  0 r0
   1.209 -		 "punpcklbw %%mm4,%%mm3\n"      //  0 b3  0 b2  0 b1  0 b0
   1.210 -		 "movq %%mm1,%%mm2\n"           //  0 r3  0 r2  0 r1  0 r0
   1.211 -		 "movq %%mm3,%%mm0\n"           //  0 b3  0 b2  0 b1  0 b0
   1.212 -		 "punpcklwd %%mm1,%%mm3\n"      //  0 r1  0 b1  0 r0  0 b0
   1.213 -		 "punpckhwd %%mm2,%%mm0\n"      //  0 r3  0 b3  0 r2  0 b2
   1.214 +        // create Cb_g (result in mm5)
   1.215 +        "movq %%mm1,%%mm5\n"            // u1 u1 u0 u0 u1 u1 u0 u0
   1.216 +        "pmullw %14,%%mm5\n"            // blue*-109dec=1.7129*64
   1.217 +        "pmullw %15,%%mm1\n"            // blue*114dec=1.78125*64
   1.218 +        "psraw  $6, %%mm5\n"            // blue=red/64
   1.219 +        "psraw  $6, %%mm1\n"            // blue=blue/64
   1.220  
   1.221 -		 "pxor %%mm2,%%mm2\n"           //  0  0  0  0  0  0  0  0
   1.222 -		 "movq %%mm7,%%mm1\n"           // G3 G2 G1 G0 g3 g2 g1 g0
   1.223 -		 "punpcklbw %%mm1,%%mm2\n"      // g3  0 g2  0 g1  0 g0  0
   1.224 -		 "punpcklwd %%mm4,%%mm2\n"      //  0  0 g1  0  0  0 g0  0 
   1.225 -		 "por  %%mm3, %%mm2\n"          //  0 r1 g1 b1  0 r0 g0 b0
   1.226 -		 "movq   %%mm2,(%3)\n"          // wrote out ! row1
   1.227 +        // create G (result in mm7)
   1.228 +        "movq %%mm2,%%mm3\n"      //   0  L3  0 L1  0 l3  0 l1
   1.229 +        "movq %%mm4,%%mm7\n"      //   0  L2  0 L0  0 l2  0 l1
   1.230 +        "paddsw  %%mm5, %%mm3\n"  // lum1+Cb_g:x G3t x G1t x g3t x g1t
   1.231 +        "paddsw  %%mm5, %%mm7\n"  // lum1+Cb_g:x G2t x G0t x g2t x g0t
   1.232 +        "paddsw  %%mm0, %%mm3\n"  // lum1+Cr_g:x G3  x G1  x g3  x g1
   1.233 +        "paddsw  %%mm0, %%mm7\n"  // lum1+blue:x G2  x G0  x g2  x g0
   1.234 +        "packuswb %%mm3,%%mm3\n"  // G3 G1 g3 g1 G3 G1 g3 g1
   1.235 +        "packuswb %%mm7,%%mm7\n"  // G2 G0 g2 g0 G2 G0 g2 g0
   1.236 +        "punpcklbw %%mm3,%%mm7\n" // G3 G2 G1 G0 g3 g2 g1 g0
   1.237  
   1.238 -		 "pxor %%mm2,%%mm2\n"           //  0  0  0  0  0  0  0  0
   1.239 -		 "punpcklbw %%mm1,%%mm4\n"      // g3  0 g2  0 g1  0 g0  0
   1.240 -		 "punpckhwd %%mm2,%%mm4\n"      //  0  0 g3  0  0  0 g2  0 
   1.241 -		 "por  %%mm0, %%mm4\n"          //  0 r3 g3 b3  0 r2 g2 b2
   1.242 -		 "movq   %%mm4,8(%3)\n"         // wrote out ! row1
   1.243 -		 
   1.244 -		 // fill destination row2 (needed are mm6=Rr,mm7=Gg,mm5=Bb)
   1.245 -		 // this can be done "destructive"
   1.246 -		 "pxor %%mm2,%%mm2\n"           //  0  0  0  0  0  0  0  0
   1.247 -		 "punpckhbw %%mm2,%%mm6\n"      //  0 R3  0 R2  0 R1  0 R0
   1.248 -		 "punpckhbw %%mm1,%%mm5\n"      // G3 B3 G2 B2 G1 B1 G0 B0
   1.249 -		 "movq %%mm5,%%mm1\n"           // G3 B3 G2 B2 G1 B1 G0 B0
   1.250 -		 "punpcklwd %%mm6,%%mm1\n"      //  0 R1 G1 B1  0 R0 G0 B0
   1.251 -		 "movq   %%mm1,(%5)\n"          // wrote out ! row2
   1.252 -		 "punpckhwd %%mm6,%%mm5\n"      //  0 R3 G3 B3  0 R2 G2 B2
   1.253 -		 "movq   %%mm5,8(%5)\n"         // wrote out ! row2
   1.254 -		 
   1.255 -		 "addl  $4,%2\n"            // lum+4
   1.256 -		 "leal  16(%3),%3\n"        // row1+16
   1.257 -		 "leal  16(%5),%5\n"        // row2+16
   1.258 -		 "addl  $2, %%ebx\n"        // cr+2
   1.259 -		 "addl  $2, %1\n"           // cb+2
   1.260 +        // create B (result in mm5)
   1.261 +        "movq %%mm2,%%mm3\n"         //   0  L3  0 L1  0 l3  0 l1
   1.262 +        "movq %%mm4,%%mm5\n"         //   0  L2  0 L0  0 l2  0 l1
   1.263 +        "paddsw  %%mm1, %%mm3\n"     // lum1+blue:x B3 x B1 x b3 x b1
   1.264 +        "paddsw  %%mm1, %%mm5\n"     // lum1+blue:x B2 x B0 x b2 x b0
   1.265 +        "packuswb %%mm3,%%mm3\n"     // B3 B1 b3 b1 B3 B1 b3 b1
   1.266 +        "packuswb %%mm5,%%mm5\n"     // B2 B0 b2 b0 B2 B0 b2 b0
   1.267 +        "punpcklbw %%mm3,%%mm5\n"    // B3 B2 B1 B0 b3 b2 b1 b0
   1.268  
   1.269 -		 "addl  $4,%6\n"            // x+4
   1.270 -		 "cmpl  %4,%6\n"
   1.271 +        // fill destination row1 (needed are mm6=Rr,mm7=Gg,mm5=Bb)
   1.272  
   1.273 -		 "jl    1b\n"
   1.274 -		 "addl           %4,     %2\n" // lum += cols 
   1.275 -		 "addl           %8,     %3\n" // row1+= mod
   1.276 -		 "addl           %8,     %5\n" // row2+= mod
   1.277 -		 "movl           $0,     %6\n" // x=0
   1.278 -		 "cmpl           %7,     %2\n"
   1.279 -		 "jl             1b\n"
   1.280 -		 "emms\n"
   1.281 -		 "popl %%ebx\n"
   1.282 -		 :
   1.283 -		 : "m" (cr), "r"(cb),"r"(lum),
   1.284 -		 "r"(row1),"r"(cols),"r"(row2),"m"(x),"m"(y),"m"(mod));
   1.285 +        "pxor %%mm2,%%mm2\n"           //  0  0  0  0  0  0  0  0
   1.286 +        "pxor %%mm4,%%mm4\n"           //  0  0  0  0  0  0  0  0
   1.287 +        "movq %%mm6,%%mm1\n"           // R3 R2 R1 R0 r3 r2 r1 r0
   1.288 +        "movq %%mm5,%%mm3\n"           // B3 B2 B1 B0 b3 b2 b1 b0
   1.289 +
   1.290 +        // process lower lum
   1.291 +        "punpcklbw %%mm4,%%mm1\n"      //  0 r3  0 r2  0 r1  0 r0
   1.292 +        "punpcklbw %%mm4,%%mm3\n"      //  0 b3  0 b2  0 b1  0 b0
   1.293 +        "movq %%mm1,%%mm2\n"           //  0 r3  0 r2  0 r1  0 r0
   1.294 +        "movq %%mm3,%%mm0\n"           //  0 b3  0 b2  0 b1  0 b0
   1.295 +        "punpcklwd %%mm1,%%mm3\n"      //  0 r1  0 b1  0 r0  0 b0
   1.296 +        "punpckhwd %%mm2,%%mm0\n"      //  0 r3  0 b3  0 r2  0 b2
   1.297 +
   1.298 +        "pxor %%mm2,%%mm2\n"           //  0  0  0  0  0  0  0  0
   1.299 +        "movq %%mm7,%%mm1\n"           // G3 G2 G1 G0 g3 g2 g1 g0
   1.300 +        "punpcklbw %%mm1,%%mm2\n"      // g3  0 g2  0 g1  0 g0  0
   1.301 +        "punpcklwd %%mm4,%%mm2\n"      //  0  0 g1  0  0  0 g0  0
   1.302 +        "por %%mm3, %%mm2\n"          //  0 r1 g1 b1  0 r0 g0 b0
   1.303 +        "movq %%mm2,(%3)\n"          // wrote out ! row1
   1.304 +
   1.305 +        "pxor %%mm2,%%mm2\n"           //  0  0  0  0  0  0  0  0
   1.306 +        "punpcklbw %%mm1,%%mm4\n"      // g3  0 g2  0 g1  0 g0  0
   1.307 +        "punpckhwd %%mm2,%%mm4\n"      //  0  0 g3  0  0  0 g2  0
   1.308 +        "por %%mm0, %%mm4\n"          //  0 r3 g3 b3  0 r2 g2 b2
   1.309 +        "movq %%mm4,8(%3)\n"         // wrote out ! row1
   1.310 +
   1.311 +        // fill destination row2 (needed are mm6=Rr,mm7=Gg,mm5=Bb)
   1.312 +        // this can be done "destructive"
   1.313 +        "pxor %%mm2,%%mm2\n"           //  0  0  0  0  0  0  0  0
   1.314 +        "punpckhbw %%mm2,%%mm6\n"      //  0 R3  0 R2  0 R1  0 R0
   1.315 +        "punpckhbw %%mm1,%%mm5\n"      // G3 B3 G2 B2 G1 B1 G0 B0
   1.316 +        "movq %%mm5,%%mm1\n"           // G3 B3 G2 B2 G1 B1 G0 B0
   1.317 +        "punpcklwd %%mm6,%%mm1\n"      //  0 R1 G1 B1  0 R0 G0 B0
   1.318 +        "movq %%mm1,(%5)\n"          // wrote out ! row2
   1.319 +        "punpckhwd %%mm6,%%mm5\n"      //  0 R3 G3 B3  0 R2 G2 B2
   1.320 +        "movq %%mm5,8(%5)\n"         // wrote out ! row2
   1.321 +
   1.322 +        "addl $4,%2\n"            // lum+4
   1.323 +        "leal 16(%3),%3\n"        // row1+16
   1.324 +        "leal 16(%5),%5\n"        // row2+16
   1.325 +        "addl $2,(%%esp)\n"        // cr+2
   1.326 +        "addl $2,%1\n"           // cb+2
   1.327 +
   1.328 +        "addl $4,%6\n"            // x+4
   1.329 +        "cmpl %4,%6\n"
   1.330 +
   1.331 +        "jl 1b\n"
   1.332 +        "addl %4,%2\n" // lum += cols
   1.333 +        "addl %8,%3\n" // row1+= mod
   1.334 +        "addl %8,%5\n" // row2+= mod
   1.335 +        "movl $0,%6\n" // x=0
   1.336 +        "cmpl %7,%2\n"
   1.337 +        "jl 1b\n"
   1.338 +
   1.339 +        "addl $4,%%esp\n"  // get rid of the stack slot we reserved.
   1.340 +        "emms\n"  // reset MMX registers.
   1.341 +        :
   1.342 +        : "m" (cr), "r"(cb),"r"(lum),
   1.343 +          "r"(row1),"r"(cols),"r"(row2),"m"(x),"m"(y),"m"(mod),
   1.344 +          "m"(MMX_0080w),"m"(MMX_VgrnRGB),"m"(MMX_VredRGB),
   1.345 +          "m"(MMX_FF00w),"m"(MMX_00FFw),"m"(MMX_UgrnRGB),
   1.346 +          "m"(MMX_UbluRGB)
   1.347 +    );
   1.348  }
   1.349  
   1.350  void Color565DitherYV12MMX1X( int *colortab, Uint32 *rgb_2_pix,
   1.351 @@ -244,173 +254,185 @@
   1.352      Uint16 *row2;
   1.353  
   1.354      unsigned char* y = lum +cols*rows;    /* Pointer to the end */
   1.355 -    int x=0;
   1.356 +    int x = 0;
   1.357      row1 = (Uint16 *)out;                 /* 16 bit target */
   1.358      row2 = (Uint16 *)out+cols+mod;        /* start of second row  */
   1.359      mod = (mod+cols+mod)*2;               /* increment for row1 in byte */
   1.360  
   1.361 +    __asm__ __volatile__(
   1.362 +        // tap dance to workaround the inability to use %%ebx at will...
   1.363 +        //  move one thing to the stack...
   1.364 +        "pushl $0\n"  // save a slot on the stack.
   1.365 +        "pushl %%ebx\n"  // save %%ebx.
   1.366 +        "movl %0, %%ebx\n"  // put the thing in ebx.
   1.367 +        "movl %%ebx, 4(%%esp)\n"  // put the thing in the stack slot.
   1.368 +        "popl %%ebx\n"  // get back %%ebx (the PIC register).
   1.369  
   1.370 -      __asm__ __volatile__(
   1.371 -         "pushl %%ebx\n"
   1.372 -	 "movl %0, %%ebx\n"
   1.373 +        ".align 8\n"
   1.374 +        "1:\n"
   1.375  
   1.376 -         ".align 8\n"
   1.377 -         "1:\n"
   1.378 -         "movd           (%1),                   %%mm0\n" // 4 Cb         0  0  0  0 u3 u2 u1 u0
   1.379 -         "pxor           %%mm7,                  %%mm7\n"
   1.380 -         "movd           (%%ebx),                %%mm1\n" // 4 Cr                0  0  0  0 v3 v2 v1 v0
   1.381 -         "punpcklbw      %%mm7,                  %%mm0\n" // 4 W cb   0 u3  0 u2  0 u1  0 u0
   1.382 -         "punpcklbw      %%mm7,                  %%mm1\n" // 4 W cr   0 v3  0 v2  0 v1  0 v0
   1.383 -         "psubw          _MMX_0080w,             %%mm0\n"
   1.384 -         "psubw          _MMX_0080w,             %%mm1\n"
   1.385 -         "movq           %%mm0,                  %%mm2\n" // Cb                   0 u3  0 u2  0 u1  0 u0
   1.386 -         "movq           %%mm1,                  %%mm3\n" // Cr
   1.387 -         "pmullw         _MMX_Ugrn565,           %%mm2\n" // Cb2green 0 R3  0 R2  0 R1  0 R0
   1.388 -         "movq           (%2),                   %%mm6\n" // L1      l7 L6 L5 L4 L3 L2 L1 L0
   1.389 -         "pmullw         _MMX_Ublu5x5,           %%mm0\n" // Cb2blue
   1.390 -         "pand           _MMX_00FFw,             %%mm6\n" // L1      00 L6 00 L4 00 L2 00 L0
   1.391 -         "pmullw         _MMX_Vgrn565,           %%mm3\n" // Cr2green
   1.392 -         "movq           (%2),                   %%mm7\n" // L2
   1.393 -         "pmullw         _MMX_Vred5x5,           %%mm1\n" // Cr2red
   1.394 -         "psrlw          $8,                     %%mm7\n"        // L2           00 L7 00 L5 00 L3 00 L1
   1.395 -         "pmullw         _MMX_Ycoeff,            %%mm6\n" // lum1
   1.396 -         "paddw          %%mm3,                  %%mm2\n" // Cb2green + Cr2green == green
   1.397 -         "pmullw         _MMX_Ycoeff,            %%mm7\n" // lum2
   1.398 +        "movd           (%1),                   %%mm0\n" // 4 Cb         0  0  0  0 u3 u2 u1 u0
   1.399 +        "pxor           %%mm7,                  %%mm7\n"
   1.400 +        "pushl %%ebx\n"
   1.401 +        "movl 4(%%esp), %%ebx\n"
   1.402 +        "movd (%%ebx), %%mm1\n"   // 4 Cr                0  0  0  0 v3 v2 v1 v0
   1.403 +        "popl %%ebx\n"
   1.404  
   1.405 -         "movq           %%mm6,                  %%mm4\n" // lum1
   1.406 -         "paddw          %%mm0,                  %%mm6\n" // lum1 +blue 00 B6 00 B4 00 B2 00 B0
   1.407 -         "movq           %%mm4,                  %%mm5\n" // lum1
   1.408 -         "paddw          %%mm1,                  %%mm4\n" // lum1 +red  00 R6 00 R4 00 R2 00 R0
   1.409 -         "paddw          %%mm2,                  %%mm5\n" // lum1 +green 00 G6 00 G4 00 G2 00 G0
   1.410 -         "psraw          $6,                     %%mm4\n" // R1 0 .. 64
   1.411 -         "movq           %%mm7,                  %%mm3\n" // lum2                       00 L7 00 L5 00 L3 00 L1
   1.412 -         "psraw          $6,                     %%mm5\n" // G1  - .. +
   1.413 -         "paddw          %%mm0,                  %%mm7\n" // Lum2 +blue 00 B7 00 B5 00 B3 00 B1
   1.414 -         "psraw          $6,                     %%mm6\n" // B1         0 .. 64
   1.415 -         "packuswb       %%mm4,                  %%mm4\n" // R1 R1
   1.416 -         "packuswb       %%mm5,                  %%mm5\n" // G1 G1
   1.417 -         "packuswb       %%mm6,                  %%mm6\n" // B1 B1
   1.418 -         "punpcklbw      %%mm4,                  %%mm4\n"
   1.419 -         "punpcklbw      %%mm5,                  %%mm5\n"
   1.420 +        "punpcklbw      %%mm7,                  %%mm0\n" // 4 W cb   0 u3  0 u2  0 u1  0 u0
   1.421 +        "punpcklbw      %%mm7,                  %%mm1\n" // 4 W cr   0 v3  0 v2  0 v1  0 v0
   1.422 +        "psubw          %9,                     %%mm0\n"
   1.423 +        "psubw          %9,                     %%mm1\n"
   1.424 +        "movq           %%mm0,                  %%mm2\n" // Cb                   0 u3  0 u2  0 u1  0 u0
   1.425 +        "movq           %%mm1,                  %%mm3\n" // Cr
   1.426 +        "pmullw         %10,                    %%mm2\n" // Cb2green 0 R3  0 R2  0 R1  0 R0
   1.427 +        "movq           (%2),                   %%mm6\n" // L1      l7 L6 L5 L4 L3 L2 L1 L0
   1.428 +        "pmullw         %11,                    %%mm0\n" // Cb2blue
   1.429 +        "pand           %12,                    %%mm6\n" // L1      00 L6 00 L4 00 L2 00 L0
   1.430 +        "pmullw         %13,                    %%mm3\n" // Cr2green
   1.431 +        "movq           (%2),                   %%mm7\n" // L2
   1.432 +        "pmullw         %14,                    %%mm1\n" // Cr2red
   1.433 +        "psrlw          $8,                     %%mm7\n"        // L2           00 L7 00 L5 00 L3 00 L1
   1.434 +        "pmullw         %15,                    %%mm6\n" // lum1
   1.435 +        "paddw          %%mm3,                  %%mm2\n" // Cb2green + Cr2green == green
   1.436 +        "pmullw         %15,                    %%mm7\n" // lum2
   1.437  
   1.438 -         "pand           _MMX_red565,            %%mm4\n"
   1.439 -         "psllw          $3,                     %%mm5\n" // GREEN       1
   1.440 -         "punpcklbw      %%mm6,                  %%mm6\n"
   1.441 -         "pand           _MMX_grn565,            %%mm5\n"
   1.442 -         "pand           _MMX_red565,            %%mm6\n"
   1.443 -         "por            %%mm5,                  %%mm4\n" //
   1.444 -         "psrlw          $11,                    %%mm6\n" // BLUE        1
   1.445 -         "movq           %%mm3,                  %%mm5\n" // lum2
   1.446 -         "paddw          %%mm1,                  %%mm3\n" // lum2 +red      00 R7 00 R5 00 R3 00 R1
   1.447 -         "paddw          %%mm2,                  %%mm5\n" // lum2 +green 00 G7 00 G5 00 G3 00 G1
   1.448 -         "psraw          $6,                     %%mm3\n" // R2
   1.449 -         "por            %%mm6,                  %%mm4\n" // MM4
   1.450 -         "psraw          $6,                     %%mm5\n" // G2
   1.451 -         "movq           (%2, %4),               %%mm6\n" // L3 load lum2
   1.452 -         "psraw          $6,                     %%mm7\n"
   1.453 -         "packuswb       %%mm3,                  %%mm3\n"
   1.454 -         "packuswb       %%mm5,                  %%mm5\n"
   1.455 -         "packuswb       %%mm7,                  %%mm7\n"
   1.456 -         "pand           _MMX_00FFw,             %%mm6\n" // L3
   1.457 -         "punpcklbw      %%mm3,                  %%mm3\n"
   1.458 -         "punpcklbw      %%mm5,                  %%mm5\n"
   1.459 -         "pmullw         _MMX_Ycoeff,            %%mm6\n" // lum3
   1.460 -         "punpcklbw      %%mm7,                  %%mm7\n"
   1.461 -         "psllw          $3,                     %%mm5\n" // GREEN 2
   1.462 -         "pand           _MMX_red565,            %%mm7\n"
   1.463 -         "pand           _MMX_red565,            %%mm3\n"
   1.464 -         "psrlw          $11,                    %%mm7\n" // BLUE  2
   1.465 -         "pand           _MMX_grn565,            %%mm5\n"
   1.466 -         "por            %%mm7,                  %%mm3\n"
   1.467 -         "movq           (%2,%4),                %%mm7\n" // L4 load lum2
   1.468 -         "por            %%mm5,                  %%mm3\n" //
   1.469 -         "psrlw          $8,                     %%mm7\n" // L4
   1.470 -         "movq           %%mm4,                  %%mm5\n"
   1.471 -         "punpcklwd      %%mm3,                  %%mm4\n"
   1.472 -         "pmullw         _MMX_Ycoeff,            %%mm7\n" // lum4
   1.473 -         "punpckhwd      %%mm3,                  %%mm5\n"
   1.474 +        "movq           %%mm6,                  %%mm4\n" // lum1
   1.475 +        "paddw          %%mm0,                  %%mm6\n" // lum1 +blue 00 B6 00 B4 00 B2 00 B0
   1.476 +        "movq           %%mm4,                  %%mm5\n" // lum1
   1.477 +        "paddw          %%mm1,                  %%mm4\n" // lum1 +red  00 R6 00 R4 00 R2 00 R0
   1.478 +        "paddw          %%mm2,                  %%mm5\n" // lum1 +green 00 G6 00 G4 00 G2 00 G0
   1.479 +        "psraw          $6,                     %%mm4\n" // R1 0 .. 64
   1.480 +        "movq           %%mm7,                  %%mm3\n" // lum2                       00 L7 00 L5 00 L3 00 L1
   1.481 +        "psraw          $6,                     %%mm5\n" // G1  - .. +
   1.482 +        "paddw          %%mm0,                  %%mm7\n" // Lum2 +blue 00 B7 00 B5 00 B3 00 B1
   1.483 +        "psraw          $6,                     %%mm6\n" // B1         0 .. 64
   1.484 +        "packuswb       %%mm4,                  %%mm4\n" // R1 R1
   1.485 +        "packuswb       %%mm5,                  %%mm5\n" // G1 G1
   1.486 +        "packuswb       %%mm6,                  %%mm6\n" // B1 B1
   1.487 +        "punpcklbw      %%mm4,                  %%mm4\n"
   1.488 +        "punpcklbw      %%mm5,                  %%mm5\n"
   1.489  
   1.490 -         "movq           %%mm4,                  (%3)\n"  // write row1
   1.491 -         "movq           %%mm5,                  8(%3)\n" // write row1
   1.492 +        "pand           %16,                    %%mm4\n"
   1.493 +        "psllw          $3,                     %%mm5\n" // GREEN       1
   1.494 +        "punpcklbw      %%mm6,                  %%mm6\n"
   1.495 +        "pand           %17,                    %%mm5\n"
   1.496 +        "pand           %16,                    %%mm6\n"
   1.497 +        "por            %%mm5,                  %%mm4\n" //
   1.498 +        "psrlw          $11,                    %%mm6\n" // BLUE        1
   1.499 +        "movq           %%mm3,                  %%mm5\n" // lum2
   1.500 +        "paddw          %%mm1,                  %%mm3\n" // lum2 +red      00 R7 00 R5 00 R3 00 R1
   1.501 +        "paddw          %%mm2,                  %%mm5\n" // lum2 +green 00 G7 00 G5 00 G3 00 G1
   1.502 +        "psraw          $6,                     %%mm3\n" // R2
   1.503 +        "por            %%mm6,                  %%mm4\n" // MM4
   1.504 +        "psraw          $6,                     %%mm5\n" // G2
   1.505 +        "movq           (%2, %4),               %%mm6\n" // L3 load lum2
   1.506 +        "psraw          $6,                     %%mm7\n"
   1.507 +        "packuswb       %%mm3,                  %%mm3\n"
   1.508 +        "packuswb       %%mm5,                  %%mm5\n"
   1.509 +        "packuswb       %%mm7,                  %%mm7\n"
   1.510 +        "pand           %12,                    %%mm6\n" // L3
   1.511 +        "punpcklbw      %%mm3,                  %%mm3\n"
   1.512 +        "punpcklbw      %%mm5,                  %%mm5\n"
   1.513 +        "pmullw         %15,                    %%mm6\n" // lum3
   1.514 +        "punpcklbw      %%mm7,                  %%mm7\n"
   1.515 +        "psllw          $3,                     %%mm5\n" // GREEN 2
   1.516 +        "pand           %16,                    %%mm7\n"
   1.517 +        "pand           %16,                    %%mm3\n"
   1.518 +        "psrlw          $11,                    %%mm7\n" // BLUE  2
   1.519 +        "pand           %17,                    %%mm5\n"
   1.520 +        "por            %%mm7,                  %%mm3\n"
   1.521 +        "movq           (%2,%4),                %%mm7\n" // L4 load lum2
   1.522 +        "por            %%mm5,                  %%mm3\n" //
   1.523 +        "psrlw          $8,                     %%mm7\n" // L4
   1.524 +        "movq           %%mm4,                  %%mm5\n"
   1.525 +        "punpcklwd      %%mm3,                  %%mm4\n"
   1.526 +        "pmullw         %15,                    %%mm7\n" // lum4
   1.527 +        "punpckhwd      %%mm3,                  %%mm5\n"
   1.528  
   1.529 -         "movq           %%mm6,                  %%mm4\n" // Lum3
   1.530 -         "paddw          %%mm0,                  %%mm6\n" // Lum3 +blue
   1.531 +        "movq           %%mm4,                  (%3)\n"  // write row1
   1.532 +        "movq           %%mm5,                  8(%3)\n" // write row1
   1.533  
   1.534 -         "movq           %%mm4,                  %%mm5\n" // Lum3
   1.535 -         "paddw          %%mm1,                  %%mm4\n" // Lum3 +red
   1.536 -         "paddw          %%mm2,                  %%mm5\n" // Lum3 +green
   1.537 -         "psraw          $6,                     %%mm4\n"
   1.538 -         "movq           %%mm7,                  %%mm3\n" // Lum4
   1.539 -         "psraw          $6,                     %%mm5\n"
   1.540 -         "paddw          %%mm0,                  %%mm7\n" // Lum4 +blue
   1.541 -         "psraw          $6,                     %%mm6\n" // Lum3 +blue
   1.542 -         "movq           %%mm3,                  %%mm0\n" // Lum4
   1.543 -         "packuswb       %%mm4,                  %%mm4\n"
   1.544 -         "paddw          %%mm1,                  %%mm3\n" // Lum4 +red
   1.545 -         "packuswb       %%mm5,                  %%mm5\n"
   1.546 -         "paddw          %%mm2,                  %%mm0\n" // Lum4 +green
   1.547 -         "packuswb       %%mm6,                  %%mm6\n"
   1.548 -         "punpcklbw      %%mm4,                  %%mm4\n"
   1.549 -         "punpcklbw      %%mm5,                  %%mm5\n"
   1.550 -         "punpcklbw      %%mm6,                  %%mm6\n"
   1.551 -         "psllw          $3,                     %%mm5\n" // GREEN 3
   1.552 -         "pand           _MMX_red565,            %%mm4\n"
   1.553 -         "psraw          $6,                     %%mm3\n" // psr 6
   1.554 -         "psraw          $6,                     %%mm0\n"
   1.555 -         "pand           _MMX_red565,            %%mm6\n" // BLUE
   1.556 -         "pand           _MMX_grn565,            %%mm5\n"
   1.557 -         "psrlw          $11,                    %%mm6\n" // BLUE  3
   1.558 -         "por            %%mm5,                  %%mm4\n"
   1.559 -         "psraw          $6,                     %%mm7\n"
   1.560 -         "por            %%mm6,                  %%mm4\n"
   1.561 -         "packuswb       %%mm3,                  %%mm3\n"
   1.562 -         "packuswb       %%mm0,                  %%mm0\n"
   1.563 -         "packuswb       %%mm7,                  %%mm7\n"
   1.564 -         "punpcklbw      %%mm3,                  %%mm3\n"
   1.565 -         "punpcklbw      %%mm0,                  %%mm0\n"
   1.566 -         "punpcklbw      %%mm7,                  %%mm7\n"
   1.567 -         "pand           _MMX_red565,            %%mm3\n"
   1.568 -         "pand           _MMX_red565,            %%mm7\n" // BLUE
   1.569 -         "psllw          $3,                     %%mm0\n" // GREEN 4
   1.570 -         "psrlw          $11,                    %%mm7\n"
   1.571 -         "pand           _MMX_grn565,            %%mm0\n"
   1.572 -         "por            %%mm7,                  %%mm3\n"
   1.573 -         "por            %%mm0,                  %%mm3\n"
   1.574 +        "movq           %%mm6,                  %%mm4\n" // Lum3
   1.575 +        "paddw          %%mm0,                  %%mm6\n" // Lum3 +blue
   1.576  
   1.577 -         "movq           %%mm4,                  %%mm5\n"
   1.578 +        "movq           %%mm4,                  %%mm5\n" // Lum3
   1.579 +        "paddw          %%mm1,                  %%mm4\n" // Lum3 +red
   1.580 +        "paddw          %%mm2,                  %%mm5\n" // Lum3 +green
   1.581 +        "psraw          $6,                     %%mm4\n"
   1.582 +        "movq           %%mm7,                  %%mm3\n" // Lum4
   1.583 +        "psraw          $6,                     %%mm5\n"
   1.584 +        "paddw          %%mm0,                  %%mm7\n" // Lum4 +blue
   1.585 +        "psraw          $6,                     %%mm6\n" // Lum3 +blue
   1.586 +        "movq           %%mm3,                  %%mm0\n" // Lum4
   1.587 +        "packuswb       %%mm4,                  %%mm4\n"
   1.588 +        "paddw          %%mm1,                  %%mm3\n" // Lum4 +red
   1.589 +        "packuswb       %%mm5,                  %%mm5\n"
   1.590 +        "paddw          %%mm2,                  %%mm0\n" // Lum4 +green
   1.591 +        "packuswb       %%mm6,                  %%mm6\n"
   1.592 +        "punpcklbw      %%mm4,                  %%mm4\n"
   1.593 +        "punpcklbw      %%mm5,                  %%mm5\n"
   1.594 +        "punpcklbw      %%mm6,                  %%mm6\n"
   1.595 +        "psllw          $3,                     %%mm5\n" // GREEN 3
   1.596 +        "pand           %16,                    %%mm4\n"
   1.597 +        "psraw          $6,                     %%mm3\n" // psr 6
   1.598 +        "psraw          $6,                     %%mm0\n"
   1.599 +        "pand           %16,                    %%mm6\n" // BLUE
   1.600 +        "pand           %17,                    %%mm5\n"
   1.601 +        "psrlw          $11,                    %%mm6\n" // BLUE  3
   1.602 +        "por            %%mm5,                  %%mm4\n"
   1.603 +        "psraw          $6,                     %%mm7\n"
   1.604 +        "por            %%mm6,                  %%mm4\n"
   1.605 +        "packuswb       %%mm3,                  %%mm3\n"
   1.606 +        "packuswb       %%mm0,                  %%mm0\n"
   1.607 +        "packuswb       %%mm7,                  %%mm7\n"
   1.608 +        "punpcklbw      %%mm3,                  %%mm3\n"
   1.609 +        "punpcklbw      %%mm0,                  %%mm0\n"
   1.610 +        "punpcklbw      %%mm7,                  %%mm7\n"
   1.611 +        "pand           %16,                    %%mm3\n"
   1.612 +        "pand           %16,                    %%mm7\n" // BLUE
   1.613 +        "psllw          $3,                     %%mm0\n" // GREEN 4
   1.614 +        "psrlw          $11,                    %%mm7\n"
   1.615 +        "pand           %17,                    %%mm0\n"
   1.616 +        "por            %%mm7,                  %%mm3\n"
   1.617 +        "por            %%mm0,                  %%mm3\n"
   1.618  
   1.619 -         "punpcklwd      %%mm3,                  %%mm4\n"
   1.620 -         "punpckhwd      %%mm3,                  %%mm5\n"
   1.621 +        "movq           %%mm4,                  %%mm5\n"
   1.622  
   1.623 -         "movq           %%mm4,                  (%5)\n"
   1.624 -	 "movq           %%mm5,                  8(%5)\n"
   1.625 +        "punpcklwd      %%mm3,                  %%mm4\n"
   1.626 +        "punpckhwd      %%mm3,                  %%mm5\n"
   1.627  
   1.628 -         "addl           $8,                     %6\n"
   1.629 -         "addl           $8,                     %2\n"
   1.630 -         "addl           $4,                     %%ebx\n"
   1.631 -         "addl           $4,                     %1\n"
   1.632 -         "cmpl           %4,                     %6\n"
   1.633 -         "leal           16(%3),                 %3\n"
   1.634 -	 "leal           16(%5),%5\n" // row2+16
   1.635 +        "movq           %%mm4,                  (%5)\n"
   1.636 +        "movq           %%mm5,                  8(%5)\n"
   1.637  
   1.638 +        "addl           $8,                     %6\n"
   1.639 +        "addl           $8,                     %2\n"
   1.640 +        "addl           $4,                     (%%esp)\n"
   1.641 +        "addl           $4,                     %1\n"
   1.642 +        "cmpl           %4,                     %6\n"
   1.643 +        "leal           16(%3),                 %3\n"
   1.644 +        "leal           16(%5),%5\n" // row2+16
   1.645  
   1.646 -         "jl             1b\n"
   1.647 -	 "addl           %4,     %2\n" // lum += cols 
   1.648 -	 "addl           %8,     %3\n" // row1+= mod
   1.649 -	 "addl           %8,     %5\n" // row2+= mod
   1.650 -	 "movl           $0,     %6\n" // x=0
   1.651 -	 "cmpl           %7,     %2\n"
   1.652 -	 "jl             1b\n"
   1.653 -         "emms\n"
   1.654 -	 "popl %%ebx\n"
   1.655 -         :
   1.656 -         :"m" (cr), "r"(cb),"r"(lum),
   1.657 -	 "r"(row1),"r"(cols),"r"(row2),"m"(x),"m"(y),"m"(mod));
   1.658 +        "jl             1b\n"
   1.659 +        "addl           %4,     %2\n" // lum += cols
   1.660 +        "addl           %8,     %3\n" // row1+= mod
   1.661 +        "addl           %8,     %5\n" // row2+= mod
   1.662 +        "movl           $0,     %6\n" // x=0
   1.663 +        "cmpl           %7,     %2\n"
   1.664 +        "jl             1b\n"
   1.665 +        "addl $4, %%esp\n"  // get rid of the stack slot we reserved.
   1.666 +        "emms\n"
   1.667 +        :
   1.668 +        : "m" (cr), "r"(cb),"r"(lum),
   1.669 +          "r"(row1),"r"(cols),"r"(row2),"m"(x),"m"(y),"m"(mod),
   1.670 +          "m"(MMX_0080w),"m"(MMX_Ugrn565),"m"(MMX_Ublu5x5),
   1.671 +          "m"(MMX_00FFw),"m"(MMX_Vgrn565),"m"(MMX_Vred5x5),
   1.672 +          "m"(MMX_Ycoeff),"m"(MMX_red565),"m"(MMX_grn565)
   1.673 +    );
   1.674  }
   1.675  
   1.676 -#endif /* GCC i386 inline assembly */
   1.677 -#endif /* 0 */
   1.678 -
   1.679  /* *INDENT-ON* */
   1.680  
   1.681 +#endif /* GCC3 i386 inline assembly */
   1.682 +
   1.683  /* vi: set ts=4 sw=4 expandtab: */
   1.684 +
     2.1 --- a/src/video/SDL_yuv_sw.c	Wed Jul 11 04:47:25 2007 +0000
     2.2 +++ b/src/video/SDL_yuv_sw.c	Wed Jul 11 07:39:01 2007 +0000
     2.3 @@ -117,7 +117,7 @@
     2.4  
     2.5  /* The colorspace conversion functions */
     2.6  
     2.7 -#if 0                           /*defined(__GNUC__) && defined(__i386__) && SDL_ASSEMBLY_ROUTINES */
     2.8 +#if (__GNUC__ > 2) && defined(__i386__) && SDL_ASSEMBLY_ROUTINES
     2.9  extern void Color565DitherYV12MMX1X(int *colortab, Uint32 * rgb_2_pix,
    2.10                                      unsigned char *lum, unsigned char *cr,
    2.11                                      unsigned char *cb, unsigned char *out,
    2.12 @@ -978,7 +978,7 @@
    2.13      case SDL_PIXELFORMAT_YV12:
    2.14      case SDL_PIXELFORMAT_IYUV:
    2.15          if (SDL_BYTESPERPIXEL(target_format) == 2) {
    2.16 -#if 0                           /*defined(__GNUC__) && defined(__i386__) && SDL_ASSEMBLY_ROUTINES */
    2.17 +#if (__GNUC__ > 2) && defined(__i386__) && SDL_ASSEMBLY_ROUTINES
    2.18              /* inline assembly functions */
    2.19              if (SDL_HasMMX() && (Rmask == 0xF800) &&
    2.20                  (Gmask == 0x07E0) && (Bmask == 0x001F) && (width & 15) == 0) {
    2.21 @@ -998,7 +998,7 @@
    2.22              swdata->Display2X = Color24DitherYV12Mod2X;
    2.23          }
    2.24          if (SDL_BYTESPERPIXEL(target_format) == 4) {
    2.25 -#if 0                           /*defined(__GNUC__) && defined(__i386__) && SDL_ASSEMBLY_ROUTINES */
    2.26 +#if (__GNUC__ > 2) && defined(__i386__) && SDL_ASSEMBLY_ROUTINES
    2.27              /* inline assembly functions */
    2.28              if (SDL_HasMMX() && (Rmask == 0x00FF0000) &&
    2.29                  (Gmask == 0x0000FF00) &&