src/video/SDL_yuv_mmx.c
author Ryan C. Gordon <icculus@icculus.org>
Sat, 14 Jul 2007 07:28:45 +0000
changeset 2197 2ff40f30af31
parent 2195 46e373b27d6d
child 2859 99210400e8b9
permissions -rw-r--r--
Merged r3261:3262 from branches/SDL-1.2: MMX/YUV with __OPTIMIZE__.

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