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