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