src/video/SDL_yuv_mmx.c
changeset 0 74212992fb08
child 252 e8157fcb3114
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/src/video/SDL_yuv_mmx.c	Thu Apr 26 16:45:43 2001 +0000
     1.3 @@ -0,0 +1,421 @@
     1.4 +/*
     1.5 +    SDL - Simple DirectMedia Layer
     1.6 +    Copyright (C) 1997, 1998, 1999, 2000, 2001  Sam Lantinga
     1.7 +
     1.8 +    This library is free software; you can redistribute it and/or
     1.9 +    modify it under the terms of the GNU Library General Public
    1.10 +    License as published by the Free Software Foundation; either
    1.11 +    version 2 of the License, or (at your option) any later version.
    1.12 +
    1.13 +    This library is distributed in the hope that it will be useful,
    1.14 +    but WITHOUT ANY WARRANTY; without even the implied warranty of
    1.15 +    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    1.16 +    Library General Public License for more details.
    1.17 +
    1.18 +    You should have received a copy of the GNU Library General Public
    1.19 +    License along with this library; if not, write to the Free
    1.20 +    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
    1.21 +
    1.22 +    Sam Lantinga
    1.23 +    slouken@devolution.com
    1.24 +*/
    1.25 +
    1.26 +#ifdef SAVE_RCSID
    1.27 +static char rcsid =
    1.28 + "@(#) $Id$";
    1.29 +#endif
    1.30 +
    1.31 +
    1.32 +#if defined(i386) && defined(__GNUC__) && defined(USE_ASMBLIT)
    1.33 +
    1.34 +#include "SDL_types.h"
    1.35 +
    1.36 +#ifdef __ELF__
    1.37 +#define ASM_VAR(X) _##X
    1.38 +#else
    1.39 +#define ASM_VAR(X) X
    1.40 +#endif
    1.41 +
    1.42 +static unsigned int  ASM_VAR(MMX_0080w)[]    = {0x00800080, 0x00800080};
    1.43 +static unsigned int  ASM_VAR(MMX_00FFw)[]    = {0x00ff00ff, 0x00ff00ff}; 
    1.44 +static unsigned int  ASM_VAR(MMX_FF00w)[]    = {0xff00ff00, 0xff00ff00}; 
    1.45 +
    1.46 +static unsigned short ASM_VAR(MMX_Ycoeff)[]  = {0x004a, 0x004a, 0x004a, 0x004a}; 
    1.47 +
    1.48 +static unsigned short ASM_VAR(MMX_UbluRGB)[] = {0x0072, 0x0072, 0x0072, 0x0072};    
    1.49 +static unsigned short ASM_VAR(MMX_VredRGB)[] = {0x0059, 0x0059, 0x0059, 0x0059};  
    1.50 +static unsigned short ASM_VAR(MMX_UgrnRGB)[] = {0xffea, 0xffea, 0xffea, 0xffea}; 
    1.51 +static unsigned short ASM_VAR(MMX_VgrnRGB)[] = {0xffd2, 0xffd2, 0xffd2, 0xffd2};  
    1.52 +
    1.53 +static unsigned short ASM_VAR(MMX_Ublu5x5)[] = {0x0081, 0x0081, 0x0081, 0x0081};
    1.54 +static unsigned short ASM_VAR(MMX_Vred5x5)[] = {0x0066, 0x0066, 0x0066, 0x0066};
    1.55 +static unsigned short ASM_VAR(MMX_Ugrn555)[] = {0xffe7, 0xffe7, 0xffe7, 0xffe7};
    1.56 +static unsigned short ASM_VAR(MMX_Vgrn555)[] = {0xffcc, 0xffcc, 0xffcc, 0xffcc};
    1.57 +static unsigned short ASM_VAR(MMX_Ugrn565)[] = {0xffe8, 0xffe8, 0xffe8, 0xffe8};
    1.58 +static unsigned short ASM_VAR(MMX_Vgrn565)[] = {0xffcd, 0xffcd, 0xffcd, 0xffcd};
    1.59 +
    1.60 +static unsigned short ASM_VAR(MMX_red555)[]  = {0x7c00, 0x7c00, 0x7c00, 0x7c00};
    1.61 +static unsigned short ASM_VAR(MMX_red565)[]  = {0xf800, 0xf800, 0xf800, 0xf800};
    1.62 +static unsigned short ASM_VAR(MMX_grn555)[]  = {0x03e0, 0x03e0, 0x03e0, 0x03e0};
    1.63 +static unsigned short ASM_VAR(MMX_grn565)[]  = {0x07e0, 0x07e0, 0x07e0, 0x07e0};
    1.64 +static unsigned short ASM_VAR(MMX_blu5x5)[]  = {0x001f, 0x001f, 0x001f, 0x001f};
    1.65 +
    1.66 +/**
    1.67 +   This MMX assembler is my first assembler/MMX program ever.
    1.68 +   Thus it maybe buggy.
    1.69 +   Send patches to:
    1.70 +   mvogt@rhrk.uni-kl.de
    1.71 +
    1.72 +   After it worked fine I have "obfuscated" the code a bit to have
    1.73 +   more parallism in the MMX units. This means I moved
    1.74 +   initilisation around and delayed other instruction.
    1.75 +   Performance measurement did not show that this brought any advantage
    1.76 +   but in theory it _should_ be faster this way.
    1.77 +
    1.78 +   The overall performanve gain to the C based dither was 30%-40%.
    1.79 +   The MMX routine calculates 256bit=8RGB values in each cycle
    1.80 +   (4 for row1 & 4 for row2)
    1.81 +
    1.82 +   The red/green/blue.. coefficents are taken from the mpeg_play 
    1.83 +   player. They look nice, but I dont know if you can have
    1.84 +   better values, to avoid integer rounding errors.
    1.85 +   
    1.86 +
    1.87 +   IMPORTANT:
    1.88 +   ==========
    1.89 +
    1.90 +   It is a requirement that the cr/cb/lum are 8 byte aligned and
    1.91 +   the out are 16byte aligned or you will/may get segfaults
    1.92 +
    1.93 +*/
    1.94 +
    1.95 +void ColorRGBDitherYV12MMX1X( int *colortab, Uint32 *rgb_2_pix,
    1.96 +                              unsigned char *lum, unsigned char *cr,
    1.97 +                              unsigned char *cb, unsigned char *out,
    1.98 +                              int rows, int cols, int mod )
    1.99 +{
   1.100 +    Uint32 *row1;
   1.101 +    Uint32 *row2;
   1.102 +
   1.103 +    unsigned char* y = lum +cols*rows;    // Pointer to the end
   1.104 +    int x=0;
   1.105 +    row1 = (Uint32 *)out;                 // 32 bit target
   1.106 +    row2 = (Uint32 *)out+cols+mod;        // start of second row 
   1.107 +    mod = (mod+cols+mod)*4;               // increment for row1 in byte
   1.108 +
   1.109 +    __asm__ __volatile__ (
   1.110 +/* We don't really care about PIC - the code should be rewritten to use
   1.111 +   relative addressing for the static tables, so right now we take the
   1.112 +   COW hit on the pages this code resides. Big deal.
   1.113 +   This spill is just to reduce register pressure in the PIC case. */
   1.114 +		 "pushl %%ebx\n"
   1.115 +		 "movl %0, %%ebx\n"
   1.116 +
   1.117 +	         ".align 8\n"
   1.118 +		 "1:\n"
   1.119 +		
   1.120 +		 // create Cr (result in mm1)
   1.121 +		 "movd (%%ebx), %%mm1\n"   //         0  0  0  0  v3 v2 v1 v0
   1.122 +		 "pxor %%mm7,%%mm7\n"      //         00 00 00 00 00 00 00 00
   1.123 +		 "movd (%2), %%mm2\n"           //    0  0  0  0 l3 l2 l1 l0
   1.124 +		 "punpcklbw %%mm7,%%mm1\n" //         0  v3 0  v2 00 v1 00 v0
   1.125 +		 "punpckldq %%mm1,%%mm1\n" //         00 v1 00 v0 00 v1 00 v0
   1.126 +		 "psubw _MMX_0080w,%%mm1\n"  // mm1-128:r1 r1 r0 r0 r1 r1 r0 r0 
   1.127 +
   1.128 +		 // create Cr_g (result in mm0)
   1.129 +		 "movq %%mm1,%%mm0\n"           // r1 r1 r0 r0 r1 r1 r0 r0
   1.130 +		 "pmullw _MMX_VgrnRGB,%%mm0\n"// red*-46dec=0.7136*64
   1.131 +		 "pmullw _MMX_VredRGB,%%mm1\n"// red*89dec=1.4013*64
   1.132 +		 "psraw  $6, %%mm0\n"           // red=red/64
   1.133 +		 "psraw  $6, %%mm1\n"           // red=red/64
   1.134 +		 
   1.135 +		 // create L1 L2 (result in mm2,mm4)
   1.136 +		 // L2=lum+cols
   1.137 +		 "movq (%2,%4),%%mm3\n"         //    0  0  0  0 L3 L2 L1 L0
   1.138 +		 "punpckldq %%mm3,%%mm2\n"      //   L3 L2 L1 L0 l3 l2 l1 l0
   1.139 +		 "movq %%mm2,%%mm4\n"           //   L3 L2 L1 L0 l3 l2 l1 l0
   1.140 +		 "pand _MMX_FF00w,%%mm2\n"      //   L3 0  L1  0 l3  0 l1  0
   1.141 +		 "pand _MMX_00FFw,%%mm4\n"      //   0  L2  0 L0  0 l2  0 l0
   1.142 +		 "psrlw $8,%%mm2\n"             //   0  L3  0 L1  0 l3  0 l1
   1.143 +
   1.144 +		 // create R (result in mm6)
   1.145 +		 "movq %%mm2,%%mm5\n"           //   0 L3  0 L1  0 l3  0 l1
   1.146 +		 "movq %%mm4,%%mm6\n"           //   0 L2  0 L0  0 l2  0 l0
   1.147 +		 "paddsw  %%mm1, %%mm5\n"       // lum1+red:x R3 x R1 x r3 x r1
   1.148 +		 "paddsw  %%mm1, %%mm6\n"       // lum1+red:x R2 x R0 x r2 x r0
   1.149 +		 "packuswb %%mm5,%%mm5\n"       //  R3 R1 r3 r1 R3 R1 r3 r1
   1.150 +		 "packuswb %%mm6,%%mm6\n"       //  R2 R0 r2 r0 R2 R0 r2 r0
   1.151 +		 "pxor %%mm7,%%mm7\n"      //         00 00 00 00 00 00 00 00
   1.152 +		 "punpcklbw %%mm5,%%mm6\n"      //  R3 R2 R1 R0 r3 r2 r1 r0
   1.153 +
   1.154 +		 // create Cb (result in mm1)
   1.155 +		 "movd (%1), %%mm1\n"      //         0  0  0  0  u3 u2 u1 u0
   1.156 +		 "punpcklbw %%mm7,%%mm1\n" //         0  u3 0  u2 00 u1 00 u0
   1.157 +		 "punpckldq %%mm1,%%mm1\n" //         00 u1 00 u0 00 u1 00 u0
   1.158 +		 "psubw _MMX_0080w,%%mm1\n"  // mm1-128:u1 u1 u0 u0 u1 u1 u0 u0 
   1.159 +		 // create Cb_g (result in mm5)
   1.160 +		 "movq %%mm1,%%mm5\n"            // u1 u1 u0 u0 u1 u1 u0 u0
   1.161 +		 "pmullw _MMX_UgrnRGB,%%mm5\n"    // blue*-109dec=1.7129*64
   1.162 +		 "pmullw _MMX_UbluRGB,%%mm1\n"    // blue*114dec=1.78125*64
   1.163 +		 "psraw  $6, %%mm5\n"            // blue=red/64
   1.164 +		 "psraw  $6, %%mm1\n"            // blue=blue/64
   1.165 +
   1.166 +		 // create G (result in mm7)
   1.167 +		 "movq %%mm2,%%mm3\n"      //   0  L3  0 L1  0 l3  0 l1
   1.168 +		 "movq %%mm4,%%mm7\n"      //   0  L2  0 L0  0 l2  0 l1
   1.169 +		 "paddsw  %%mm5, %%mm3\n"  // lum1+Cb_g:x G3t x G1t x g3t x g1t
   1.170 +		 "paddsw  %%mm5, %%mm7\n"  // lum1+Cb_g:x G2t x G0t x g2t x g0t
   1.171 +		 "paddsw  %%mm0, %%mm3\n"  // lum1+Cr_g:x G3  x G1  x g3  x g1
   1.172 +		 "paddsw  %%mm0, %%mm7\n"  // lum1+blue:x G2  x G0  x g2  x g0
   1.173 +		 "packuswb %%mm3,%%mm3\n"  // G3 G1 g3 g1 G3 G1 g3 g1
   1.174 +		 "packuswb %%mm7,%%mm7\n"  // G2 G0 g2 g0 G2 G0 g2 g0
   1.175 +		 "punpcklbw %%mm3,%%mm7\n" // G3 G2 G1 G0 g3 g2 g1 g0
   1.176 +		 
   1.177 +		 // create B (result in mm5)
   1.178 +		 "movq %%mm2,%%mm3\n"         //   0  L3  0 L1  0 l3  0 l1
   1.179 +		 "movq %%mm4,%%mm5\n"         //   0  L2  0 L0  0 l2  0 l1
   1.180 +		 "paddsw  %%mm1, %%mm3\n"     // lum1+blue:x B3 x B1 x b3 x b1
   1.181 +		 "paddsw  %%mm1, %%mm5\n"     // lum1+blue:x B2 x B0 x b2 x b0
   1.182 +		 "packuswb %%mm3,%%mm3\n"     // B3 B1 b3 b1 B3 B1 b3 b1
   1.183 +		 "packuswb %%mm5,%%mm5\n"     // B2 B0 b2 b0 B2 B0 b2 b0
   1.184 +		 "punpcklbw %%mm3,%%mm5\n"    // B3 B2 B1 B0 b3 b2 b1 b0
   1.185 +
   1.186 +		 // fill destination row1 (needed are mm6=Rr,mm7=Gg,mm5=Bb)
   1.187 +
   1.188 +		 "pxor %%mm2,%%mm2\n"           //  0  0  0  0  0  0  0  0
   1.189 +		 "pxor %%mm4,%%mm4\n"           //  0  0  0  0  0  0  0  0
   1.190 +		 "movq %%mm6,%%mm1\n"           // R3 R2 R1 R0 r3 r2 r1 r0
   1.191 +		 "movq %%mm5,%%mm3\n"           // B3 B2 B1 B0 b3 b2 b1 b0
   1.192 +		 // process lower lum
   1.193 +		 "punpcklbw %%mm4,%%mm1\n"      //  0 r3  0 r2  0 r1  0 r0
   1.194 +		 "punpcklbw %%mm4,%%mm3\n"      //  0 b3  0 b2  0 b1  0 b0
   1.195 +		 "movq %%mm1,%%mm2\n"           //  0 r3  0 r2  0 r1  0 r0
   1.196 +		 "movq %%mm3,%%mm0\n"           //  0 b3  0 b2  0 b1  0 b0
   1.197 +		 "punpcklwd %%mm1,%%mm3\n"      //  0 r1  0 b1  0 r0  0 b0
   1.198 +		 "punpckhwd %%mm2,%%mm0\n"      //  0 r3  0 b3  0 r2  0 b2
   1.199 +
   1.200 +		 "pxor %%mm2,%%mm2\n"           //  0  0  0  0  0  0  0  0
   1.201 +		 "movq %%mm7,%%mm1\n"           // G3 G2 G1 G0 g3 g2 g1 g0
   1.202 +		 "punpcklbw %%mm1,%%mm2\n"      // g3  0 g2  0 g1  0 g0  0
   1.203 +		 "punpcklwd %%mm4,%%mm2\n"      //  0  0 g1  0  0  0 g0  0 
   1.204 +		 "por  %%mm3, %%mm2\n"          //  0 r1 g1 b1  0 r0 g0 b0
   1.205 +		 "movq   %%mm2,(%3)\n"          // wrote out ! row1
   1.206 +
   1.207 +		 "pxor %%mm2,%%mm2\n"           //  0  0  0  0  0  0  0  0
   1.208 +		 "punpcklbw %%mm1,%%mm4\n"      // g3  0 g2  0 g1  0 g0  0
   1.209 +		 "punpckhwd %%mm2,%%mm4\n"      //  0  0 g3  0  0  0 g2  0 
   1.210 +		 "por  %%mm0, %%mm4\n"          //  0 r3 g3 b3  0 r2 g2 b2
   1.211 +		 "movq   %%mm4,8(%3)\n"         // wrote out ! row1
   1.212 +		 
   1.213 +		 // fill destination row2 (needed are mm6=Rr,mm7=Gg,mm5=Bb)
   1.214 +		 // this can be done "destructive"
   1.215 +		 "pxor %%mm2,%%mm2\n"           //  0  0  0  0  0  0  0  0
   1.216 +		 "punpckhbw %%mm2,%%mm6\n"      //  0 R3  0 R2  0 R1  0 R0
   1.217 +		 "punpckhbw %%mm1,%%mm5\n"      // G3 B3 G2 B2 G1 B1 G0 B0
   1.218 +		 "movq %%mm5,%%mm1\n"           // G3 B3 G2 B2 G1 B1 G0 B0
   1.219 +		 "punpcklwd %%mm6,%%mm1\n"      //  0 R1 G1 B1  0 R0 G0 B0
   1.220 +		 "movq   %%mm1,(%5)\n"          // wrote out ! row2
   1.221 +		 "punpckhwd %%mm6,%%mm5\n"      //  0 R3 G3 B3  0 R2 G2 B2
   1.222 +		 "movq   %%mm5,8(%5)\n"         // wrote out ! row2
   1.223 +		 
   1.224 +		 "addl  $4,%2\n"            // lum+4
   1.225 +		 "leal  16(%3),%3\n"        // row1+16
   1.226 +		 "leal  16(%5),%5\n"        // row2+16
   1.227 +		 "addl  $2, %%ebx\n"        // cr+2
   1.228 +		 "addl  $2, %1\n"           // cb+2
   1.229 +
   1.230 +		 "addl  $4,%6\n"            // x+4
   1.231 +		 "cmpl  %4,%6\n"
   1.232 +
   1.233 +		 "jl    1b\n"
   1.234 +		 "addl           %4,     %2\n" // lum += cols 
   1.235 +		 "addl           %8,     %3\n" // row1+= mod
   1.236 +		 "addl           %8,     %5\n" // row2+= mod
   1.237 +		 "movl           $0,     %6\n" // x=0
   1.238 +		 "cmpl           %7,     %2\n"
   1.239 +		 "jl             1b\n"
   1.240 +		 "emms\n"
   1.241 +		 "popl %%ebx\n"
   1.242 +		 :
   1.243 +		 : "m" (cr), "r"(cb),"r"(lum),
   1.244 +		 "r"(row1),"r"(cols),"r"(row2),"m"(x),"m"(y),"m"(mod)
   1.245 +		 : "%ebx"
   1.246 +		 );
   1.247 +}
   1.248 +
   1.249 +void Color565DitherYV12MMX1X( int *colortab, Uint32 *rgb_2_pix,
   1.250 +                             unsigned char *lum, unsigned char *cr,
   1.251 +                             unsigned char *cb, unsigned char *out,
   1.252 +                             int rows, int cols, int mod )
   1.253 +{
   1.254 +    Uint16 *row1;
   1.255 +    Uint16 *row2;
   1.256 +
   1.257 +    unsigned char* y = lum +cols*rows;    /* Pointer to the end */
   1.258 +    int x=0;
   1.259 +    row1 = (Uint16 *)out;                 /* 16 bit target */
   1.260 +    row2 = (Uint16 *)out+cols+mod;        /* start of second row  */
   1.261 +    mod = (mod+cols+mod)*2;               /* increment for row1 in byte */
   1.262 +
   1.263 +
   1.264 +      __asm__ __volatile__(
   1.265 +         "pushl %%ebx\n"
   1.266 +	 "movl %0, %%ebx\n"
   1.267 +
   1.268 +         ".align 8\n"
   1.269 +         "1:\n"
   1.270 +         "movd           (%1),                   %%mm0\n" // 4 Cb         0  0  0  0 u3 u2 u1 u0
   1.271 +         "pxor           %%mm7,                  %%mm7\n"
   1.272 +         "movd           (%%ebx),                %%mm1\n" // 4 Cr                0  0  0  0 v3 v2 v1 v0
   1.273 +         "punpcklbw      %%mm7,                  %%mm0\n" // 4 W cb   0 u3  0 u2  0 u1  0 u0
   1.274 +         "punpcklbw      %%mm7,                  %%mm1\n" // 4 W cr   0 v3  0 v2  0 v1  0 v0
   1.275 +         "psubw          _MMX_0080w,             %%mm0\n"
   1.276 +         "psubw          _MMX_0080w,             %%mm1\n"
   1.277 +         "movq           %%mm0,                  %%mm2\n" // Cb                   0 u3  0 u2  0 u1  0 u0
   1.278 +         "movq           %%mm1,                  %%mm3\n" // Cr
   1.279 +         "pmullw         _MMX_Ugrn565,           %%mm2\n" // Cb2green 0 R3  0 R2  0 R1  0 R0
   1.280 +         "movq           (%2),                   %%mm6\n" // L1      l7 L6 L5 L4 L3 L2 L1 L0
   1.281 +         "pmullw         _MMX_Ublu5x5,           %%mm0\n" // Cb2blue
   1.282 +         "pand           _MMX_00FFw,             %%mm6\n" // L1      00 L6 00 L4 00 L2 00 L0
   1.283 +         "pmullw         _MMX_Vgrn565,           %%mm3\n" // Cr2green
   1.284 +         "movq           (%2),                   %%mm7\n" // L2
   1.285 +         "pmullw         _MMX_Vred5x5,           %%mm1\n" // Cr2red
   1.286 +         "psrlw          $8,                     %%mm7\n"        // L2           00 L7 00 L5 00 L3 00 L1
   1.287 +         "pmullw         _MMX_Ycoeff,            %%mm6\n" // lum1
   1.288 +         "paddw          %%mm3,                  %%mm2\n" // Cb2green + Cr2green == green
   1.289 +         "pmullw         _MMX_Ycoeff,            %%mm7\n" // lum2
   1.290 +
   1.291 +         "movq           %%mm6,                  %%mm4\n" // lum1
   1.292 +         "paddw          %%mm0,                  %%mm6\n" // lum1 +blue 00 B6 00 B4 00 B2 00 B0
   1.293 +         "movq           %%mm4,                  %%mm5\n" // lum1
   1.294 +         "paddw          %%mm1,                  %%mm4\n" // lum1 +red  00 R6 00 R4 00 R2 00 R0
   1.295 +         "paddw          %%mm2,                  %%mm5\n" // lum1 +green 00 G6 00 G4 00 G2 00 G0
   1.296 +         "psraw          $6,                     %%mm4\n" // R1 0 .. 64
   1.297 +         "movq           %%mm7,                  %%mm3\n" // lum2                       00 L7 00 L5 00 L3 00 L1
   1.298 +         "psraw          $6,                     %%mm5\n" // G1  - .. +
   1.299 +         "paddw          %%mm0,                  %%mm7\n" // Lum2 +blue 00 B7 00 B5 00 B3 00 B1
   1.300 +         "psraw          $6,                     %%mm6\n" // B1         0 .. 64
   1.301 +         "packuswb       %%mm4,                  %%mm4\n" // R1 R1
   1.302 +         "packuswb       %%mm5,                  %%mm5\n" // G1 G1
   1.303 +         "packuswb       %%mm6,                  %%mm6\n" // B1 B1
   1.304 +         "punpcklbw      %%mm4,                  %%mm4\n"
   1.305 +         "punpcklbw      %%mm5,                  %%mm5\n"
   1.306 +
   1.307 +         "pand           _MMX_red565,            %%mm4\n"
   1.308 +         "psllw          $3,                     %%mm5\n" // GREEN       1
   1.309 +         "punpcklbw      %%mm6,                  %%mm6\n"
   1.310 +         "pand           _MMX_grn565,            %%mm5\n"
   1.311 +         "pand           _MMX_red565,            %%mm6\n"
   1.312 +         "por            %%mm5,                  %%mm4\n" //
   1.313 +         "psrlw          $11,                    %%mm6\n" // BLUE        1
   1.314 +         "movq           %%mm3,                  %%mm5\n" // lum2
   1.315 +         "paddw          %%mm1,                  %%mm3\n" // lum2 +red      00 R7 00 R5 00 R3 00 R1
   1.316 +         "paddw          %%mm2,                  %%mm5\n" // lum2 +green 00 G7 00 G5 00 G3 00 G1
   1.317 +         "psraw          $6,                     %%mm3\n" // R2
   1.318 +         "por            %%mm6,                  %%mm4\n" // MM4
   1.319 +         "psraw          $6,                     %%mm5\n" // G2
   1.320 +         "movq           (%2, %4),               %%mm6\n" // L3 load lum2
   1.321 +         "psraw          $6,                     %%mm7\n"
   1.322 +         "packuswb       %%mm3,                  %%mm3\n"
   1.323 +         "packuswb       %%mm5,                  %%mm5\n"
   1.324 +         "packuswb       %%mm7,                  %%mm7\n"
   1.325 +         "pand           _MMX_00FFw,             %%mm6\n" // L3
   1.326 +         "punpcklbw      %%mm3,                  %%mm3\n"
   1.327 +         "punpcklbw      %%mm5,                  %%mm5\n"
   1.328 +         "pmullw         _MMX_Ycoeff,            %%mm6\n" // lum3
   1.329 +         "punpcklbw      %%mm7,                  %%mm7\n"
   1.330 +         "psllw          $3,                     %%mm5\n" // GREEN 2
   1.331 +         "pand           _MMX_red565,            %%mm7\n"
   1.332 +         "pand           _MMX_red565,            %%mm3\n"
   1.333 +         "psrlw          $11,                    %%mm7\n" // BLUE  2
   1.334 +         "pand           _MMX_grn565,            %%mm5\n"
   1.335 +         "por            %%mm7,                  %%mm3\n"
   1.336 +         "movq           (%2,%4),                %%mm7\n" // L4 load lum2
   1.337 +         "por            %%mm5,                  %%mm3\n" //
   1.338 +         "psrlw          $8,                     %%mm7\n" // L4
   1.339 +         "movq           %%mm4,                  %%mm5\n"
   1.340 +         "punpcklwd      %%mm3,                  %%mm4\n"
   1.341 +         "pmullw         _MMX_Ycoeff,            %%mm7\n" // lum4
   1.342 +         "punpckhwd      %%mm3,                  %%mm5\n"
   1.343 +
   1.344 +         "movq           %%mm4,                  (%3)\n"  // write row1
   1.345 +         "movq           %%mm5,                  8(%3)\n" // write row1
   1.346 +
   1.347 +         "movq           %%mm6,                  %%mm4\n" // Lum3
   1.348 +         "paddw          %%mm0,                  %%mm6\n" // Lum3 +blue
   1.349 +
   1.350 +         "movq           %%mm4,                  %%mm5\n" // Lum3
   1.351 +         "paddw          %%mm1,                  %%mm4\n" // Lum3 +red
   1.352 +         "paddw          %%mm2,                  %%mm5\n" // Lum3 +green
   1.353 +         "psraw          $6,                     %%mm4\n"
   1.354 +         "movq           %%mm7,                  %%mm3\n" // Lum4
   1.355 +         "psraw          $6,                     %%mm5\n"
   1.356 +         "paddw          %%mm0,                  %%mm7\n" // Lum4 +blue
   1.357 +         "psraw          $6,                     %%mm6\n" // Lum3 +blue
   1.358 +         "movq           %%mm3,                  %%mm0\n" // Lum4
   1.359 +         "packuswb       %%mm4,                  %%mm4\n"
   1.360 +         "paddw          %%mm1,                  %%mm3\n" // Lum4 +red
   1.361 +         "packuswb       %%mm5,                  %%mm5\n"
   1.362 +         "paddw          %%mm2,                  %%mm0\n" // Lum4 +green
   1.363 +         "packuswb       %%mm6,                  %%mm6\n"
   1.364 +         "punpcklbw      %%mm4,                  %%mm4\n"
   1.365 +         "punpcklbw      %%mm5,                  %%mm5\n"
   1.366 +         "punpcklbw      %%mm6,                  %%mm6\n"
   1.367 +         "psllw          $3,                     %%mm5\n" // GREEN 3
   1.368 +         "pand           _MMX_red565,            %%mm4\n"
   1.369 +         "psraw          $6,                     %%mm3\n" // psr 6
   1.370 +         "psraw          $6,                     %%mm0\n"
   1.371 +         "pand           _MMX_red565,            %%mm6\n" // BLUE
   1.372 +         "pand           _MMX_grn565,            %%mm5\n"
   1.373 +         "psrlw          $11,                    %%mm6\n" // BLUE  3
   1.374 +         "por            %%mm5,                  %%mm4\n"
   1.375 +         "psraw          $6,                     %%mm7\n"
   1.376 +         "por            %%mm6,                  %%mm4\n"
   1.377 +         "packuswb       %%mm3,                  %%mm3\n"
   1.378 +         "packuswb       %%mm0,                  %%mm0\n"
   1.379 +         "packuswb       %%mm7,                  %%mm7\n"
   1.380 +         "punpcklbw      %%mm3,                  %%mm3\n"
   1.381 +         "punpcklbw      %%mm0,                  %%mm0\n"
   1.382 +         "punpcklbw      %%mm7,                  %%mm7\n"
   1.383 +         "pand           _MMX_red565,            %%mm3\n"
   1.384 +         "pand           _MMX_red565,            %%mm7\n" // BLUE
   1.385 +         "psllw          $3,                     %%mm0\n" // GREEN 4
   1.386 +         "psrlw          $11,                    %%mm7\n"
   1.387 +         "pand           _MMX_grn565,            %%mm0\n"
   1.388 +         "por            %%mm7,                  %%mm3\n"
   1.389 +         "por            %%mm0,                  %%mm3\n"
   1.390 +
   1.391 +         "movq           %%mm4,                  %%mm5\n"
   1.392 +
   1.393 +         "punpcklwd      %%mm3,                  %%mm4\n"
   1.394 +         "punpckhwd      %%mm3,                  %%mm5\n"
   1.395 +
   1.396 +         "movq           %%mm4,                  (%5)\n"
   1.397 +	 "movq           %%mm5,                  8(%5)\n"
   1.398 +
   1.399 +         "addl           $8,                     %6\n"
   1.400 +         "addl           $8,                     %2\n"
   1.401 +         "addl           $4,                     %%ebx\n"
   1.402 +         "addl           $4,                     %1\n"
   1.403 +         "cmpl           %4,                     %6\n"
   1.404 +         "leal           16(%3),                 %3\n"
   1.405 +	 "leal           16(%5),%5\n" // row2+16
   1.406 +
   1.407 +
   1.408 +         "jl             1b\n"
   1.409 +	 "addl           %4,     %2\n" // lum += cols 
   1.410 +	 "addl           %8,     %3\n" // row1+= mod
   1.411 +	 "addl           %8,     %5\n" // row2+= mod
   1.412 +	 "movl           $0,     %6\n" // x=0
   1.413 +	 "cmpl           %7,     %2\n"
   1.414 +	 "jl             1b\n"
   1.415 +         "emms\n"
   1.416 +	 "popl %%ebx\n"
   1.417 +         :
   1.418 +         :"m" (cr), "r"(cb),"r"(lum),
   1.419 +	 "r"(row1),"r"(cols),"r"(row2),"m"(x),"m"(y),"m"(mod)
   1.420 +	 : "%ebx"
   1.421 +         );
   1.422 +}
   1.423 +
   1.424 +#endif /* GCC i386 inline assembly */