src/video/SDL_yuv_mmx.c
author Ryan C. Gordon <icculus@icculus.org>
Wed, 11 Jul 2007 06:26:22 +0000
branchSDL-1.2
changeset 4045 f420bba13676
parent 1413 40edc79b0926
child 4046 3a9e60224efe
permissions -rw-r--r--
GCC inline asm for MMX YUV processing no longer has textrels and now works when
gcc wants to hog %%ebx for the PIC register.

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