Subversion Repositories Kolibri OS

Rev

Blame | Last modification | View Log | RSS feed

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