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