ditherer_mmx16.cc
上传用户:aoeyumen
上传日期:2007-01-06
资源大小:3329k
文件大小:12k
- #ifdef HAVE_MMX
- #include "ditherer_mmx16.hh"
- static long long MMX_0 = 0L;
- static unsigned long MMX_10w[] = {0x00100010, 0x00100010}; //dd 00010 0010h, 000100010h
- static unsigned long MMX_80w[] = {0x00800080, 0x00800080}; //dd 00080 0080h, 000800080h
- static unsigned long MMX_00FFw[] = {0x00ff00ff, 0x00ff00ff}; //dd 000FF 00FFh, 000FF00FFh
- static unsigned short MMX_Ublucoeff[] = {0x81, 0x81, 0x81, 0x81}; //dd 00081 0081h, 000810081h
- static unsigned short MMX_Vredcoeff[] = {0x66, 0x66, 0x66, 0x66}; //dd 00066 0066h, 000660066h
- static unsigned short MMX_Ugrncoeff[] = {0xffe8, 0xffe8, 0xffe8, 0xffe8}; //dd 0FFE7 FFE7h, 0FFE7FFE7h
- static unsigned short MMX_Vgrncoeff[] = {0xffcd, 0xffcd, 0xffcd, 0xffcd}; //dd 0FFCC FFCCh, 0FFCCFFCCh
- static unsigned short MMX_Ycoeff[] = {0x4a, 0x4a, 0x4a, 0x4a}; //dd 0004A 004Ah, 0004A004Ah
- static unsigned short MMX_redmask[] = {0xf800, 0xf800, 0xf800, 0xf800}; //dd 07c00 7c00h, 07c007c00h
- static unsigned short MMX_grnmask[] = {0x7e0, 0x7e0, 0x7e0, 0x7e0}; //dd 003e0 03e0h, 003e003e0h
- // static unsigned short MMX_blumask[] = {0x1f, 0x1f, 0x1f, 0x1f}; //dd 0001f 001fh, 0001f001fh
- void Dither_MMX16::ditherBlock(unsigned char *lum, unsigned char *cb, unsigned char *cr,
- unsigned char *out,
- int cols, int rows, int screen_width) {
- unsigned short *row1;
- int x;
- unsigned char *y;
- int col1;
- int mod = screen_width-cols;
- row1 = (unsigned short *)out;
- col1 = cols +mod;
- mod += cols +mod;
- mod *=2;
- y = lum +cols*rows;
- x = 0;
- __asm__ __volatile__(
- ".align 8n"
- "1:n"
- "movd (%1), %%mm0n" // 4 Cb 0 0 0 0 u3 u2 u1 u0
- "pxor %%mm7, %%mm7n"
- "movd (%0), %%mm1n" // 4 Cr 0 0 0 0 v3 v2 v1 v0
- "punpcklbw %%mm7, %%mm0n" // 4 W cb 0 u3 0 u2 0 u1 0 u0
- "punpcklbw %%mm7, %%mm1n" // 4 W cr 0 v3 0 v2 0 v1 0 v0
- "psubw MMX_80w, %%mm0n"
- "psubw MMX_80w, %%mm1n"
- "movq %%mm0, %%mm2n" // Cb 0 u3 0 u2 0 u1 0 u0
- "movq %%mm1, %%mm3n" // Cr
- "pmullw MMX_Ugrncoeff, %%mm2n" // Cb2green 0 R3 0 R2 0 R1 0 R0
- "movq (%2), %%mm6n" // L1 l7 L6 L5 L4 L3 L2 L1 L0
- "pmullw MMX_Ublucoeff, %%mm0n" // Cb2blue
- "pand MMX_00FFw, %%mm6n" // L1 00 L6 00 L4 00 L2 00 L0
- "pmullw MMX_Vgrncoeff, %%mm3n" // Cr2green
- "movq (%2), %%mm7n" // L2
- "pmullw MMX_Vredcoeff, %%mm1n" // Cr2red
- // "psubw MMX_10w, %%mm6n"
- "psrlw $8, %%mm7n" // L2 00 L7 00 L5 00 L3 00 L1
- "pmullw MMX_Ycoeff, %%mm6n" // lum1
- // "psubw MMX_10w, %%mm7n" // L2
- "paddw %%mm3, %%mm2n" // Cb2green + Cr2green == green
- "pmullw MMX_Ycoeff, %%mm7n" // lum2
- "movq %%mm6, %%mm4n" // lum1
- "paddw %%mm0, %%mm6n" // lum1 +blue 00 B6 00 B4 00 B2 00 B0
- "movq %%mm4, %%mm5n" // lum1
- "paddw %%mm1, %%mm4n" // lum1 +red 00 R6 00 R4 00 R2 00 R0
- "paddw %%mm2, %%mm5n" // lum1 +green 00 G6 00 G4 00 G2 00 G0
- "psraw $6, %%mm4n" // R1 0 .. 64
- "movq %%mm7, %%mm3n" // lum2 00 L7 00 L5 00 L3 00 L1
- "psraw $6, %%mm5n" // G1 - .. +
- "paddw %%mm0, %%mm7n" // Lum2 +blue 00 B7 00 B5 00 B3 00 B1
- "psraw $6, %%mm6n" // B1 0 .. 64
- "packuswb %%mm4, %%mm4n" // R1 R1
- "packuswb %%mm5, %%mm5n" // G1 G1
- "packuswb %%mm6, %%mm6n" // B1 B1
- "punpcklbw %%mm4, %%mm4n"
- "punpcklbw %%mm5, %%mm5n"
- "pand MMX_redmask, %%mm4n"
- "psllw $3, %%mm5n" // GREEN 1
- "punpcklbw %%mm6, %%mm6n"
- "pand MMX_grnmask, %%mm5n"
- "pand MMX_redmask, %%mm6n"
- "por %%mm5, %%mm4n" //
- "psrlw $11, %%mm6n" // BLUE 1
- "movq %%mm3, %%mm5n" // lum2
- "paddw %%mm1, %%mm3n" // lum2 +red 00 R7 00 R5 00 R3 00 R1
- "paddw %%mm2, %%mm5n" // lum2 +green 00 G7 00 G5 00 G3 00 G1
- "psraw $6, %%mm3n" // R2
- "por %%mm6, %%mm4n" // MM4
- "psraw $6, %%mm5n" // G2
- "movq (%2, %3), %%mm6n" // L3
- "psraw $6, %%mm7n"
- "packuswb %%mm3, %%mm3n"
- "packuswb %%mm5, %%mm5n"
- "packuswb %%mm7, %%mm7n"
- "pand MMX_00FFw, %%mm6n" // L3
- "punpcklbw %%mm3, %%mm3n"
- // "psubw MMX_10w, %%mm6n" // L3
- "punpcklbw %%mm5, %%mm5n"
- "pmullw MMX_Ycoeff, %%mm6n" // lum3
- "punpcklbw %%mm7, %%mm7n"
- "psllw $3, %%mm5n" // GREEN 2
- "pand MMX_redmask, %%mm7n"
- "pand MMX_redmask, %%mm3n"
- "psrlw $11, %%mm7n" // BLUE 2
- "pand MMX_grnmask, %%mm5n"
- "por %%mm7, %%mm3n"
- "movq (%2,%3), %%mm7n" // L4
- "por %%mm5, %%mm3n" //
- "psrlw $8, %%mm7n" // L4
- "movq %%mm4, %%mm5n"
- // "psubw MMX_10w, %%mm7n" // L4
- "punpcklwd %%mm3, %%mm4n"
- "pmullw MMX_Ycoeff, %%mm7n" // lum4
- "punpckhwd %%mm3, %%mm5n"
- "movq %%mm4, (%4)n"
- "movq %%mm5, 8(%4)n"
- "movq %%mm6, %%mm4n" // Lum3
- "paddw %%mm0, %%mm6n" // Lum3 +blue
- "movq %%mm4, %%mm5n" // Lum3
- "paddw %%mm1, %%mm4n" // Lum3 +red
- "paddw %%mm2, %%mm5n" // Lum3 +green
- "psraw $6, %%mm4n"
- "movq %%mm7, %%mm3n" // Lum4
- "psraw $6, %%mm5n"
- "paddw %%mm0, %%mm7n" // Lum4 +blue
- "psraw $6, %%mm6n" // Lum3 +blue
- "movq %%mm3, %%mm0n" // Lum4
- "packuswb %%mm4, %%mm4n"
- "paddw %%mm1, %%mm3n" // Lum4 +red
- "packuswb %%mm5, %%mm5n"
- "paddw %%mm2, %%mm0n" // Lum4 +green
- "packuswb %%mm6, %%mm6n"
- "punpcklbw %%mm4, %%mm4n"
- "punpcklbw %%mm5, %%mm5n"
- "punpcklbw %%mm6, %%mm6n"
- "psllw $3, %%mm5n" // GREEN 3
- "pand MMX_redmask, %%mm4n"
- "psraw $6, %%mm3n" // psr 6
- "psraw $6, %%mm0n"
- "pand MMX_redmask, %%mm6n" // BLUE
- "pand MMX_grnmask, %%mm5n"
- "psrlw $11, %%mm6n" // BLUE 3
- "por %%mm5, %%mm4n"
- "psraw $6, %%mm7n"
- "por %%mm6, %%mm4n"
- "packuswb %%mm3, %%mm3n"
- "packuswb %%mm0, %%mm0n"
- "packuswb %%mm7, %%mm7n"
- "punpcklbw %%mm3, %%mm3n"
- "punpcklbw %%mm0, %%mm0n"
- "punpcklbw %%mm7, %%mm7n"
- "pand MMX_redmask, %%mm3n"
- "pand MMX_redmask, %%mm7n" // BLUE
- "psllw $3, %%mm0n" // GREEN 4
- "psrlw $11, %%mm7n"
- "pand MMX_grnmask, %%mm0n"
- "por %%mm7, %%mm3n"
- "addl $8, %6n"
- "por %%mm0, %%mm3n"
- "movq %%mm4, %%mm5n"
- "punpcklwd %%mm3, %%mm4n"
- "punpckhwd %%mm3, %%mm5n"
- "movq %%mm4, (%4,%5,2)n"
- "movq %%mm5, 8(%4,%5,2)n"
- "addl $8, %2n"
- "addl $4, %0n"
- "addl $4, %1n"
- "cmpl %3, %6n"
- "leal 16(%4), %4n"
- "jl 1bn"
- "addl %3, %2n" /* lum += cols */
- "addl %7, %4n" /* row1 += mod */
- "movl $0, %6n"
- "cmpl %8, %2n"
- "jl 1bn"
- :
- : "r" (cr), "r" (cb), "r" (lum), "r" (cols), "r" (row1) ,"r" (col1), "m" (x), "m" (mod)
- , "m" (y)
- );
- __asm__ __volatile__(
- "emmsn"
- );
- }
- #endif