src/render/SDL_yuv_mmx.c
changeset 5156 307ccc9c135e
parent 3697 f7b03b6838cb
child 5262 b530ef003506
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/src/render/SDL_yuv_mmx.c	Thu Feb 03 00:19:40 2011 -0800
     1.3 @@ -0,0 +1,432 @@
     1.4 +/*
     1.5 +    SDL - Simple DirectMedia Layer
     1.6 +    Copyright (C) 1997-2010 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 Lesser General Public
    1.10 +    License as published by the Free Software Foundation; either
    1.11 +    version 2.1 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 +    Lesser General Public License for more details.
    1.17 +
    1.18 +    You should have received a copy of the GNU Lesser General Public
    1.19 +    License along with this library; if not, write to the Free Software
    1.20 +    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
    1.21 +
    1.22 +    Sam Lantinga
    1.23 +    slouken@libsdl.org
    1.24 +*/
    1.25 +#include "SDL_config.h"
    1.26 +
    1.27 +#if (__GNUC__ > 2) && defined(__i386__) && __OPTIMIZE__ && SDL_ASSEMBLY_ROUTINES
    1.28 +
    1.29 +#include "SDL_stdinc.h"
    1.30 +
    1.31 +#include "mmx.h"
    1.32 +
    1.33 +/* *INDENT-OFF* */
    1.34 +
    1.35 +static mmx_t MMX_0080w    = { .ud = {0x00800080, 0x00800080} };
    1.36 +static mmx_t MMX_00FFw    = { .ud = {0x00ff00ff, 0x00ff00ff} };
    1.37 +static mmx_t MMX_FF00w    = { .ud = {0xff00ff00, 0xff00ff00} };
    1.38 +
    1.39 +static mmx_t MMX_Ycoeff   = { .uw = {0x004a, 0x004a, 0x004a, 0x004a} };
    1.40 +
    1.41 +static mmx_t MMX_UbluRGB  = { .uw = {0x0072, 0x0072, 0x0072, 0x0072} };
    1.42 +static mmx_t MMX_VredRGB  = { .uw = {0x0059, 0x0059, 0x0059, 0x0059} };
    1.43 +static mmx_t MMX_UgrnRGB  = { .uw = {0xffea, 0xffea, 0xffea, 0xffea} };
    1.44 +static mmx_t MMX_VgrnRGB  = { .uw = {0xffd2, 0xffd2, 0xffd2, 0xffd2} };
    1.45 +
    1.46 +static mmx_t MMX_Ublu5x5  = { .uw = {0x0081, 0x0081, 0x0081, 0x0081} };
    1.47 +static mmx_t MMX_Vred5x5  = { .uw = {0x0066, 0x0066, 0x0066, 0x0066} };
    1.48 +static mmx_t MMX_Ugrn565  = { .uw = {0xffe8, 0xffe8, 0xffe8, 0xffe8} };
    1.49 +static mmx_t MMX_Vgrn565  = { .uw = {0xffcd, 0xffcd, 0xffcd, 0xffcd} };
    1.50 +
    1.51 +static mmx_t MMX_red565   = { .uw = {0xf800, 0xf800, 0xf800, 0xf800} };
    1.52 +static mmx_t MMX_grn565   = { .uw = {0x07e0, 0x07e0, 0x07e0, 0x07e0} };
    1.53 +
    1.54 +/**
    1.55 +   This MMX assembler is my first assembler/MMX program ever.
    1.56 +   Thus it maybe buggy.
    1.57 +   Send patches to:
    1.58 +   mvogt@rhrk.uni-kl.de
    1.59 +
    1.60 +   After it worked fine I have "obfuscated" the code a bit to have
    1.61 +   more parallism in the MMX units. This means I moved
    1.62 +   initilisation around and delayed other instruction.
    1.63 +   Performance measurement did not show that this brought any advantage
    1.64 +   but in theory it _should_ be faster this way.
    1.65 +
    1.66 +   The overall performanve gain to the C based dither was 30%-40%.
    1.67 +   The MMX routine calculates 256bit=8RGB values in each cycle
    1.68 +   (4 for row1 & 4 for row2)
    1.69 +
    1.70 +   The red/green/blue.. coefficents are taken from the mpeg_play 
    1.71 +   player. They look nice, but I dont know if you can have
    1.72 +   better values, to avoid integer rounding errors.
    1.73 +   
    1.74 +
    1.75 +   IMPORTANT:
    1.76 +   ==========
    1.77 +
    1.78 +   It is a requirement that the cr/cb/lum are 8 byte aligned and
    1.79 +   the out are 16byte aligned or you will/may get segfaults
    1.80 +
    1.81 +*/
    1.82 +
    1.83 +void ColorRGBDitherYV12MMX1X( int *colortab, Uint32 *rgb_2_pix,
    1.84 +                              unsigned char *lum, unsigned char *cr,
    1.85 +                              unsigned char *cb, unsigned char *out,
    1.86 +                              int rows, int cols, int mod )
    1.87 +{
    1.88 +    Uint32 *row1;
    1.89 +    Uint32 *row2;
    1.90 +
    1.91 +    unsigned char* y = lum +cols*rows;    // Pointer to the end
    1.92 +    int x = 0;
    1.93 +    row1 = (Uint32 *)out;                 // 32 bit target
    1.94 +    row2 = (Uint32 *)out+cols+mod;        // start of second row
    1.95 +    mod = (mod+cols+mod)*4;               // increment for row1 in byte
    1.96 +
    1.97 +    __asm__ __volatile__ (
    1.98 +        // tap dance to workaround the inability to use %%ebx at will...
    1.99 +        //  move one thing to the stack...
   1.100 +        "pushl $0\n"  // save a slot on the stack.
   1.101 +        "pushl %%ebx\n"  // save %%ebx.
   1.102 +        "movl %0, %%ebx\n"  // put the thing in ebx.
   1.103 +        "movl %%ebx,4(%%esp)\n"  // put the thing in the stack slot.
   1.104 +        "popl %%ebx\n"  // get back %%ebx (the PIC register).
   1.105 +
   1.106 +        ".align 8\n"
   1.107 +        "1:\n"
   1.108 +
   1.109 +        // create Cr (result in mm1)
   1.110 +        "pushl %%ebx\n"
   1.111 +        "movl 4(%%esp),%%ebx\n"
   1.112 +        "movd (%%ebx),%%mm1\n"   //         0  0  0  0  v3 v2 v1 v0
   1.113 +        "popl %%ebx\n"
   1.114 +        "pxor %%mm7,%%mm7\n"      //         00 00 00 00 00 00 00 00
   1.115 +        "movd (%2), %%mm2\n"           //    0  0  0  0 l3 l2 l1 l0
   1.116 +        "punpcklbw %%mm7,%%mm1\n" //         0  v3 0  v2 00 v1 00 v0
   1.117 +        "punpckldq %%mm1,%%mm1\n" //         00 v1 00 v0 00 v1 00 v0
   1.118 +        "psubw %9,%%mm1\n"        // mm1-128:r1 r1 r0 r0 r1 r1 r0 r0
   1.119 +
   1.120 +        // create Cr_g (result in mm0)
   1.121 +        "movq %%mm1,%%mm0\n"           // r1 r1 r0 r0 r1 r1 r0 r0
   1.122 +        "pmullw %10,%%mm0\n"           // red*-46dec=0.7136*64
   1.123 +        "pmullw %11,%%mm1\n"           // red*89dec=1.4013*64
   1.124 +        "psraw  $6, %%mm0\n"           // red=red/64
   1.125 +        "psraw  $6, %%mm1\n"           // red=red/64
   1.126 +
   1.127 +        // create L1 L2 (result in mm2,mm4)
   1.128 +        // L2=lum+cols
   1.129 +        "movq (%2,%4),%%mm3\n"         //    0  0  0  0 L3 L2 L1 L0
   1.130 +        "punpckldq %%mm3,%%mm2\n"      //   L3 L2 L1 L0 l3 l2 l1 l0
   1.131 +        "movq %%mm2,%%mm4\n"           //   L3 L2 L1 L0 l3 l2 l1 l0
   1.132 +        "pand %12,%%mm2\n"             //   L3 0  L1  0 l3  0 l1  0
   1.133 +        "pand %13,%%mm4\n"             //   0  L2  0 L0  0 l2  0 l0
   1.134 +        "psrlw $8,%%mm2\n"             //   0  L3  0 L1  0 l3  0 l1
   1.135 +
   1.136 +        // create R (result in mm6)
   1.137 +        "movq %%mm2,%%mm5\n"           //   0 L3  0 L1  0 l3  0 l1
   1.138 +        "movq %%mm4,%%mm6\n"           //   0 L2  0 L0  0 l2  0 l0
   1.139 +        "paddsw  %%mm1, %%mm5\n"       // lum1+red:x R3 x R1 x r3 x r1
   1.140 +        "paddsw  %%mm1, %%mm6\n"       // lum1+red:x R2 x R0 x r2 x r0
   1.141 +        "packuswb %%mm5,%%mm5\n"       //  R3 R1 r3 r1 R3 R1 r3 r1
   1.142 +        "packuswb %%mm6,%%mm6\n"       //  R2 R0 r2 r0 R2 R0 r2 r0
   1.143 +        "pxor %%mm7,%%mm7\n"      //         00 00 00 00 00 00 00 00
   1.144 +        "punpcklbw %%mm5,%%mm6\n"      //  R3 R2 R1 R0 r3 r2 r1 r0
   1.145 +
   1.146 +        // create Cb (result in mm1)
   1.147 +        "movd (%1), %%mm1\n"      //         0  0  0  0  u3 u2 u1 u0
   1.148 +        "punpcklbw %%mm7,%%mm1\n" //         0  u3 0  u2 00 u1 00 u0
   1.149 +        "punpckldq %%mm1,%%mm1\n" //         00 u1 00 u0 00 u1 00 u0
   1.150 +        "psubw %9,%%mm1\n"        // mm1-128:u1 u1 u0 u0 u1 u1 u0 u0
   1.151 +
   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 %14,%%mm5\n"            // blue*-109dec=1.7129*64
   1.155 +        "pmullw %15,%%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 +
   1.159 +        // create G (result in mm7)
   1.160 +        "movq %%mm2,%%mm3\n"      //   0  L3  0 L1  0 l3  0 l1
   1.161 +        "movq %%mm4,%%mm7\n"      //   0  L2  0 L0  0 l2  0 l1
   1.162 +        "paddsw  %%mm5, %%mm3\n"  // lum1+Cb_g:x G3t x G1t x g3t x g1t
   1.163 +        "paddsw  %%mm5, %%mm7\n"  // lum1+Cb_g:x G2t x G0t x g2t x g0t
   1.164 +        "paddsw  %%mm0, %%mm3\n"  // lum1+Cr_g:x G3  x G1  x g3  x g1
   1.165 +        "paddsw  %%mm0, %%mm7\n"  // lum1+blue:x G2  x G0  x g2  x g0
   1.166 +        "packuswb %%mm3,%%mm3\n"  // G3 G1 g3 g1 G3 G1 g3 g1
   1.167 +        "packuswb %%mm7,%%mm7\n"  // G2 G0 g2 g0 G2 G0 g2 g0
   1.168 +        "punpcklbw %%mm3,%%mm7\n" // G3 G2 G1 G0 g3 g2 g1 g0
   1.169 +
   1.170 +        // create B (result in mm5)
   1.171 +        "movq %%mm2,%%mm3\n"         //   0  L3  0 L1  0 l3  0 l1
   1.172 +        "movq %%mm4,%%mm5\n"         //   0  L2  0 L0  0 l2  0 l1
   1.173 +        "paddsw  %%mm1, %%mm3\n"     // lum1+blue:x B3 x B1 x b3 x b1
   1.174 +        "paddsw  %%mm1, %%mm5\n"     // lum1+blue:x B2 x B0 x b2 x b0
   1.175 +        "packuswb %%mm3,%%mm3\n"     // B3 B1 b3 b1 B3 B1 b3 b1
   1.176 +        "packuswb %%mm5,%%mm5\n"     // B2 B0 b2 b0 B2 B0 b2 b0
   1.177 +        "punpcklbw %%mm3,%%mm5\n"    // B3 B2 B1 B0 b3 b2 b1 b0
   1.178 +
   1.179 +        // fill destination row1 (needed are mm6=Rr,mm7=Gg,mm5=Bb)
   1.180 +
   1.181 +        "pxor %%mm2,%%mm2\n"           //  0  0  0  0  0  0  0  0
   1.182 +        "pxor %%mm4,%%mm4\n"           //  0  0  0  0  0  0  0  0
   1.183 +        "movq %%mm6,%%mm1\n"           // R3 R2 R1 R0 r3 r2 r1 r0
   1.184 +        "movq %%mm5,%%mm3\n"           // B3 B2 B1 B0 b3 b2 b1 b0
   1.185 +
   1.186 +        // process lower lum
   1.187 +        "punpcklbw %%mm4,%%mm1\n"      //  0 r3  0 r2  0 r1  0 r0
   1.188 +        "punpcklbw %%mm4,%%mm3\n"      //  0 b3  0 b2  0 b1  0 b0
   1.189 +        "movq %%mm1,%%mm2\n"           //  0 r3  0 r2  0 r1  0 r0
   1.190 +        "movq %%mm3,%%mm0\n"           //  0 b3  0 b2  0 b1  0 b0
   1.191 +        "punpcklwd %%mm1,%%mm3\n"      //  0 r1  0 b1  0 r0  0 b0
   1.192 +        "punpckhwd %%mm2,%%mm0\n"      //  0 r3  0 b3  0 r2  0 b2
   1.193 +
   1.194 +        "pxor %%mm2,%%mm2\n"           //  0  0  0  0  0  0  0  0
   1.195 +        "movq %%mm7,%%mm1\n"           // G3 G2 G1 G0 g3 g2 g1 g0
   1.196 +        "punpcklbw %%mm1,%%mm2\n"      // g3  0 g2  0 g1  0 g0  0
   1.197 +        "punpcklwd %%mm4,%%mm2\n"      //  0  0 g1  0  0  0 g0  0
   1.198 +        "por %%mm3, %%mm2\n"          //  0 r1 g1 b1  0 r0 g0 b0
   1.199 +        "movq %%mm2,(%3)\n"          // wrote out ! row1
   1.200 +
   1.201 +        "pxor %%mm2,%%mm2\n"           //  0  0  0  0  0  0  0  0
   1.202 +        "punpcklbw %%mm1,%%mm4\n"      // g3  0 g2  0 g1  0 g0  0
   1.203 +        "punpckhwd %%mm2,%%mm4\n"      //  0  0 g3  0  0  0 g2  0
   1.204 +        "por %%mm0, %%mm4\n"          //  0 r3 g3 b3  0 r2 g2 b2
   1.205 +        "movq %%mm4,8(%3)\n"         // wrote out ! row1
   1.206 +
   1.207 +        // fill destination row2 (needed are mm6=Rr,mm7=Gg,mm5=Bb)
   1.208 +        // this can be done "destructive"
   1.209 +        "pxor %%mm2,%%mm2\n"           //  0  0  0  0  0  0  0  0
   1.210 +        "punpckhbw %%mm2,%%mm6\n"      //  0 R3  0 R2  0 R1  0 R0
   1.211 +        "punpckhbw %%mm1,%%mm5\n"      // G3 B3 G2 B2 G1 B1 G0 B0
   1.212 +        "movq %%mm5,%%mm1\n"           // G3 B3 G2 B2 G1 B1 G0 B0
   1.213 +        "punpcklwd %%mm6,%%mm1\n"      //  0 R1 G1 B1  0 R0 G0 B0
   1.214 +        "movq %%mm1,(%5)\n"          // wrote out ! row2
   1.215 +        "punpckhwd %%mm6,%%mm5\n"      //  0 R3 G3 B3  0 R2 G2 B2
   1.216 +        "movq %%mm5,8(%5)\n"         // wrote out ! row2
   1.217 +
   1.218 +        "addl $4,%2\n"            // lum+4
   1.219 +        "leal 16(%3),%3\n"        // row1+16
   1.220 +        "leal 16(%5),%5\n"        // row2+16
   1.221 +        "addl $2,(%%esp)\n"        // cr+2
   1.222 +        "addl $2,%1\n"           // cb+2
   1.223 +
   1.224 +        "addl $4,%6\n"            // x+4
   1.225 +        "cmpl %4,%6\n"
   1.226 +
   1.227 +        "jl 1b\n"
   1.228 +        "addl %4,%2\n" // lum += cols
   1.229 +        "addl %8,%3\n" // row1+= mod
   1.230 +        "addl %8,%5\n" // row2+= mod
   1.231 +        "movl $0,%6\n" // x=0
   1.232 +        "cmpl %7,%2\n"
   1.233 +        "jl 1b\n"
   1.234 +
   1.235 +        "addl $4,%%esp\n"  // get rid of the stack slot we reserved.
   1.236 +        "emms\n"  // reset MMX registers.
   1.237 +        :
   1.238 +        : "m" (cr), "r"(cb),"r"(lum),
   1.239 +          "r"(row1),"r"(cols),"r"(row2),"m"(x),"m"(y),"m"(mod),
   1.240 +          "m"(MMX_0080w),"m"(MMX_VgrnRGB),"m"(MMX_VredRGB),
   1.241 +          "m"(MMX_FF00w),"m"(MMX_00FFw),"m"(MMX_UgrnRGB),
   1.242 +          "m"(MMX_UbluRGB)
   1.243 +    );
   1.244 +}
   1.245 +
   1.246 +void Color565DitherYV12MMX1X( int *colortab, Uint32 *rgb_2_pix,
   1.247 +                             unsigned char *lum, unsigned char *cr,
   1.248 +                             unsigned char *cb, unsigned char *out,
   1.249 +                             int rows, int cols, int mod )
   1.250 +{
   1.251 +    Uint16 *row1;
   1.252 +    Uint16 *row2;
   1.253 +
   1.254 +    unsigned char* y = lum +cols*rows;    /* Pointer to the end */
   1.255 +    int x = 0;
   1.256 +    row1 = (Uint16 *)out;                 /* 16 bit target */
   1.257 +    row2 = (Uint16 *)out+cols+mod;        /* start of second row  */
   1.258 +    mod = (mod+cols+mod)*2;               /* increment for row1 in byte */
   1.259 +
   1.260 +    __asm__ __volatile__(
   1.261 +        // tap dance to workaround the inability to use %%ebx at will...
   1.262 +        //  move one thing to the stack...
   1.263 +        "pushl $0\n"  // save a slot on the stack.
   1.264 +        "pushl %%ebx\n"  // save %%ebx.
   1.265 +        "movl %0, %%ebx\n"  // put the thing in ebx.
   1.266 +        "movl %%ebx, 4(%%esp)\n"  // put the thing in the stack slot.
   1.267 +        "popl %%ebx\n"  // get back %%ebx (the PIC register).
   1.268 +
   1.269 +        ".align 8\n"
   1.270 +        "1:\n"
   1.271 +
   1.272 +        "movd           (%1),                   %%mm0\n" // 4 Cb         0  0  0  0 u3 u2 u1 u0
   1.273 +        "pxor           %%mm7,                  %%mm7\n"
   1.274 +        "pushl %%ebx\n"
   1.275 +        "movl 4(%%esp), %%ebx\n"
   1.276 +        "movd (%%ebx), %%mm1\n"   // 4 Cr                0  0  0  0 v3 v2 v1 v0
   1.277 +        "popl %%ebx\n"
   1.278 +
   1.279 +        "punpcklbw      %%mm7,                  %%mm0\n" // 4 W cb   0 u3  0 u2  0 u1  0 u0
   1.280 +        "punpcklbw      %%mm7,                  %%mm1\n" // 4 W cr   0 v3  0 v2  0 v1  0 v0
   1.281 +        "psubw          %9,                     %%mm0\n"
   1.282 +        "psubw          %9,                     %%mm1\n"
   1.283 +        "movq           %%mm0,                  %%mm2\n" // Cb                   0 u3  0 u2  0 u1  0 u0
   1.284 +        "movq           %%mm1,                  %%mm3\n" // Cr
   1.285 +        "pmullw         %10,                    %%mm2\n" // Cb2green 0 R3  0 R2  0 R1  0 R0
   1.286 +        "movq           (%2),                   %%mm6\n" // L1      l7 L6 L5 L4 L3 L2 L1 L0
   1.287 +        "pmullw         %11,                    %%mm0\n" // Cb2blue
   1.288 +        "pand           %12,                    %%mm6\n" // L1      00 L6 00 L4 00 L2 00 L0
   1.289 +        "pmullw         %13,                    %%mm3\n" // Cr2green
   1.290 +        "movq           (%2),                   %%mm7\n" // L2
   1.291 +        "pmullw         %14,                    %%mm1\n" // Cr2red
   1.292 +        "psrlw          $8,                     %%mm7\n"        // L2           00 L7 00 L5 00 L3 00 L1
   1.293 +        "pmullw         %15,                    %%mm6\n" // lum1
   1.294 +        "paddw          %%mm3,                  %%mm2\n" // Cb2green + Cr2green == green
   1.295 +        "pmullw         %15,                    %%mm7\n" // lum2
   1.296 +
   1.297 +        "movq           %%mm6,                  %%mm4\n" // lum1
   1.298 +        "paddw          %%mm0,                  %%mm6\n" // lum1 +blue 00 B6 00 B4 00 B2 00 B0
   1.299 +        "movq           %%mm4,                  %%mm5\n" // lum1
   1.300 +        "paddw          %%mm1,                  %%mm4\n" // lum1 +red  00 R6 00 R4 00 R2 00 R0
   1.301 +        "paddw          %%mm2,                  %%mm5\n" // lum1 +green 00 G6 00 G4 00 G2 00 G0
   1.302 +        "psraw          $6,                     %%mm4\n" // R1 0 .. 64
   1.303 +        "movq           %%mm7,                  %%mm3\n" // lum2                       00 L7 00 L5 00 L3 00 L1
   1.304 +        "psraw          $6,                     %%mm5\n" // G1  - .. +
   1.305 +        "paddw          %%mm0,                  %%mm7\n" // Lum2 +blue 00 B7 00 B5 00 B3 00 B1
   1.306 +        "psraw          $6,                     %%mm6\n" // B1         0 .. 64
   1.307 +        "packuswb       %%mm4,                  %%mm4\n" // R1 R1
   1.308 +        "packuswb       %%mm5,                  %%mm5\n" // G1 G1
   1.309 +        "packuswb       %%mm6,                  %%mm6\n" // B1 B1
   1.310 +        "punpcklbw      %%mm4,                  %%mm4\n"
   1.311 +        "punpcklbw      %%mm5,                  %%mm5\n"
   1.312 +
   1.313 +        "pand           %16,                    %%mm4\n"
   1.314 +        "psllw          $3,                     %%mm5\n" // GREEN       1
   1.315 +        "punpcklbw      %%mm6,                  %%mm6\n"
   1.316 +        "pand           %17,                    %%mm5\n"
   1.317 +        "pand           %16,                    %%mm6\n"
   1.318 +        "por            %%mm5,                  %%mm4\n" //
   1.319 +        "psrlw          $11,                    %%mm6\n" // BLUE        1
   1.320 +        "movq           %%mm3,                  %%mm5\n" // lum2
   1.321 +        "paddw          %%mm1,                  %%mm3\n" // lum2 +red      00 R7 00 R5 00 R3 00 R1
   1.322 +        "paddw          %%mm2,                  %%mm5\n" // lum2 +green 00 G7 00 G5 00 G3 00 G1
   1.323 +        "psraw          $6,                     %%mm3\n" // R2
   1.324 +        "por            %%mm6,                  %%mm4\n" // MM4
   1.325 +        "psraw          $6,                     %%mm5\n" // G2
   1.326 +        "movq           (%2, %4),               %%mm6\n" // L3 load lum2
   1.327 +        "psraw          $6,                     %%mm7\n"
   1.328 +        "packuswb       %%mm3,                  %%mm3\n"
   1.329 +        "packuswb       %%mm5,                  %%mm5\n"
   1.330 +        "packuswb       %%mm7,                  %%mm7\n"
   1.331 +        "pand           %12,                    %%mm6\n" // L3
   1.332 +        "punpcklbw      %%mm3,                  %%mm3\n"
   1.333 +        "punpcklbw      %%mm5,                  %%mm5\n"
   1.334 +        "pmullw         %15,                    %%mm6\n" // lum3
   1.335 +        "punpcklbw      %%mm7,                  %%mm7\n"
   1.336 +        "psllw          $3,                     %%mm5\n" // GREEN 2
   1.337 +        "pand           %16,                    %%mm7\n"
   1.338 +        "pand           %16,                    %%mm3\n"
   1.339 +        "psrlw          $11,                    %%mm7\n" // BLUE  2
   1.340 +        "pand           %17,                    %%mm5\n"
   1.341 +        "por            %%mm7,                  %%mm3\n"
   1.342 +        "movq           (%2,%4),                %%mm7\n" // L4 load lum2
   1.343 +        "por            %%mm5,                  %%mm3\n" //
   1.344 +        "psrlw          $8,                     %%mm7\n" // L4
   1.345 +        "movq           %%mm4,                  %%mm5\n"
   1.346 +        "punpcklwd      %%mm3,                  %%mm4\n"
   1.347 +        "pmullw         %15,                    %%mm7\n" // lum4
   1.348 +        "punpckhwd      %%mm3,                  %%mm5\n"
   1.349 +
   1.350 +        "movq           %%mm4,                  (%3)\n"  // write row1
   1.351 +        "movq           %%mm5,                  8(%3)\n" // write row1
   1.352 +
   1.353 +        "movq           %%mm6,                  %%mm4\n" // Lum3
   1.354 +        "paddw          %%mm0,                  %%mm6\n" // Lum3 +blue
   1.355 +
   1.356 +        "movq           %%mm4,                  %%mm5\n" // Lum3
   1.357 +        "paddw          %%mm1,                  %%mm4\n" // Lum3 +red
   1.358 +        "paddw          %%mm2,                  %%mm5\n" // Lum3 +green
   1.359 +        "psraw          $6,                     %%mm4\n"
   1.360 +        "movq           %%mm7,                  %%mm3\n" // Lum4
   1.361 +        "psraw          $6,                     %%mm5\n"
   1.362 +        "paddw          %%mm0,                  %%mm7\n" // Lum4 +blue
   1.363 +        "psraw          $6,                     %%mm6\n" // Lum3 +blue
   1.364 +        "movq           %%mm3,                  %%mm0\n" // Lum4
   1.365 +        "packuswb       %%mm4,                  %%mm4\n"
   1.366 +        "paddw          %%mm1,                  %%mm3\n" // Lum4 +red
   1.367 +        "packuswb       %%mm5,                  %%mm5\n"
   1.368 +        "paddw          %%mm2,                  %%mm0\n" // Lum4 +green
   1.369 +        "packuswb       %%mm6,                  %%mm6\n"
   1.370 +        "punpcklbw      %%mm4,                  %%mm4\n"
   1.371 +        "punpcklbw      %%mm5,                  %%mm5\n"
   1.372 +        "punpcklbw      %%mm6,                  %%mm6\n"
   1.373 +        "psllw          $3,                     %%mm5\n" // GREEN 3
   1.374 +        "pand           %16,                    %%mm4\n"
   1.375 +        "psraw          $6,                     %%mm3\n" // psr 6
   1.376 +        "psraw          $6,                     %%mm0\n"
   1.377 +        "pand           %16,                    %%mm6\n" // BLUE
   1.378 +        "pand           %17,                    %%mm5\n"
   1.379 +        "psrlw          $11,                    %%mm6\n" // BLUE  3
   1.380 +        "por            %%mm5,                  %%mm4\n"
   1.381 +        "psraw          $6,                     %%mm7\n"
   1.382 +        "por            %%mm6,                  %%mm4\n"
   1.383 +        "packuswb       %%mm3,                  %%mm3\n"
   1.384 +        "packuswb       %%mm0,                  %%mm0\n"
   1.385 +        "packuswb       %%mm7,                  %%mm7\n"
   1.386 +        "punpcklbw      %%mm3,                  %%mm3\n"
   1.387 +        "punpcklbw      %%mm0,                  %%mm0\n"
   1.388 +        "punpcklbw      %%mm7,                  %%mm7\n"
   1.389 +        "pand           %16,                    %%mm3\n"
   1.390 +        "pand           %16,                    %%mm7\n" // BLUE
   1.391 +        "psllw          $3,                     %%mm0\n" // GREEN 4
   1.392 +        "psrlw          $11,                    %%mm7\n"
   1.393 +        "pand           %17,                    %%mm0\n"
   1.394 +        "por            %%mm7,                  %%mm3\n"
   1.395 +        "por            %%mm0,                  %%mm3\n"
   1.396 +
   1.397 +        "movq           %%mm4,                  %%mm5\n"
   1.398 +
   1.399 +        "punpcklwd      %%mm3,                  %%mm4\n"
   1.400 +        "punpckhwd      %%mm3,                  %%mm5\n"
   1.401 +
   1.402 +        "movq           %%mm4,                  (%5)\n"
   1.403 +        "movq           %%mm5,                  8(%5)\n"
   1.404 +
   1.405 +        "addl           $8,                     %6\n"
   1.406 +        "addl           $8,                     %2\n"
   1.407 +        "addl           $4,                     (%%esp)\n"
   1.408 +        "addl           $4,                     %1\n"
   1.409 +        "cmpl           %4,                     %6\n"
   1.410 +        "leal           16(%3),                 %3\n"
   1.411 +        "leal           16(%5),%5\n" // row2+16
   1.412 +
   1.413 +        "jl             1b\n"
   1.414 +        "addl           %4,     %2\n" // lum += cols
   1.415 +        "addl           %8,     %3\n" // row1+= mod
   1.416 +        "addl           %8,     %5\n" // row2+= mod
   1.417 +        "movl           $0,     %6\n" // x=0
   1.418 +        "cmpl           %7,     %2\n"
   1.419 +        "jl             1b\n"
   1.420 +        "addl $4, %%esp\n"  // get rid of the stack slot we reserved.
   1.421 +        "emms\n"
   1.422 +        :
   1.423 +        : "m" (cr), "r"(cb),"r"(lum),
   1.424 +          "r"(row1),"r"(cols),"r"(row2),"m"(x),"m"(y),"m"(mod),
   1.425 +          "m"(MMX_0080w),"m"(MMX_Ugrn565),"m"(MMX_Ublu5x5),
   1.426 +          "m"(MMX_00FFw),"m"(MMX_Vgrn565),"m"(MMX_Vred5x5),
   1.427 +          "m"(MMX_Ycoeff),"m"(MMX_red565),"m"(MMX_grn565)
   1.428 +    );
   1.429 +}
   1.430 +
   1.431 +/* *INDENT-ON* */
   1.432 +
   1.433 +#endif /* GCC3 i386 inline assembly */
   1.434 +
   1.435 +/* vi: set ts=4 sw=4 expandtab: */