src/video/SDL_yuv_mmx.c
author Sam Lantinga <slouken@libsdl.org>
Sun, 16 May 2004 17:19:48 +0000
changeset 887 b4b64bb88f2f
parent 769 b8d311d90021
child 946 8520712f8ef0
permissions -rw-r--r--
Date: Mon, 10 May 2004 10:17:46 -0400
From: Mike Frysinger
Subject: Re: [SDL] gcc-3.4.0 / PIC fix

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