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