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