Date: Tue, 19 Aug 2003 17:57:00 +0200
authorSam Lantinga <slouken@libsdl.org>
Fri, 22 Aug 2003 05:51:19 +0000
changeset 6895bb080d35049
parent 688 c0522010bb6d
child 690 b87d8d4c205d
Date: Tue, 19 Aug 2003 17:57:00 +0200
From: Stephane Marchesin
Subject: Re: [SDL] [patch] MMX alpha blit patches with MMX detection

I think everything is correct now. I've done as much testing as I could,
but some real-world testing wouldn't hurt, I think.
The patch is here : http://icps.u-strasbg.fr/~marchesin/sdl_mmxblit.patch

If you do byte-by-byte comparison of the output between C and MMX
functions, you'll notice that the results for 555 and 565 RGB alpha
blits aren't exactly the same. This is because MMX functions for 555 and
565 RGB have an higher accuracy. If you want the exact same behaviour
that's possible by masking the three lower alpha bits in the MMX
functions. Just ask !

I removed one MMX function because after I fixed it to match its C
equivalent, it revealed to be slower than the C version on a PIII
(although a bit faster on an Athlon XP).

I've also added MMX and PIII replacements for SDL_memcpy. Those provide
some speed up in testvidinfo -benchmark (at least for me, under linux &
X11).
src/video/Makefile.am
src/video/SDL_RLEaccel.c
src/video/SDL_blit.c
src/video/SDL_blit.h
src/video/SDL_blit_A.c
src/video/mmx.h
     1.1 --- a/src/video/Makefile.am	Tue Aug 12 15:17:20 2003 +0000
     1.2 +++ b/src/video/Makefile.am	Fri Aug 22 05:51:19 2003 +0000
     1.3 @@ -42,6 +42,7 @@
     1.4  	SDL_yuv_sw.c		\
     1.5  	SDL_yuv_sw_c.h		\
     1.6  	SDL_yuv_mmx.c		\
     1.7 +	mmx.h			\
     1.8  	blank_cursor.h		\
     1.9  	default_cursor.h
    1.10  
     2.1 --- a/src/video/SDL_RLEaccel.c	Tue Aug 12 15:17:20 2003 +0000
     2.2 +++ b/src/video/SDL_RLEaccel.c	Fri Aug 22 05:51:19 2003 +0000
     2.3 @@ -102,6 +102,18 @@
     2.4  #include "SDL_memops.h"
     2.5  #include "SDL_RLEaccel_c.h"
     2.6  
     2.7 +#if defined(i386) && defined(__GNUC__) && defined(USE_ASMBLIT)
     2.8 +#include "mmx.h"
     2.9 +/* Function to check the CPU flags */
    2.10 +#define MMX_CPU		0x800000
    2.11 +#define CPU_Flags()	Hermes_X86_CPU()
    2.12 +#define X86_ASSEMBLER
    2.13 +#define HermesConverterInterface	void
    2.14 +#define HermesClearInterface		void
    2.15 +#define STACKCALL
    2.16 +#include "HeadX86.h"
    2.17 +#endif
    2.18 +
    2.19  #ifndef MAX
    2.20  #define MAX(a, b) ((a) > (b) ? (a) : (b))
    2.21  #endif
    2.22 @@ -125,6 +137,262 @@
    2.23  #define OPAQUE_BLIT(to, from, length, bpp, alpha)	\
    2.24      PIXEL_COPY(to, from, length, bpp)
    2.25  
    2.26 +#if defined(i386) && defined(__GNUC__) && defined(USE_ASMBLIT)
    2.27 +
    2.28 +#define ALPHA_BLIT32_888MMX(to, from, length, bpp, alpha)	\
    2.29 +    do {							\
    2.30 +	Uint32 *srcp = (Uint32 *)(from);			\
    2.31 +	Uint32 *dstp = (Uint32 *)(to);				\
    2.32 +        int i = 0x00FF00FF;					\
    2.33 +        movd_m2r(*(&i), mm3);					\
    2.34 +        punpckldq_r2r(mm3, mm3);				\
    2.35 +        i = 0xFF000000;						\
    2.36 +        movd_m2r(*(&i), mm7);					\
    2.37 +        punpckldq_r2r(mm7, mm7);				\
    2.38 +        i = alpha | alpha << 16;				\
    2.39 +        movd_m2r(*(&i), mm4);					\
    2.40 +        punpckldq_r2r(mm4, mm4);				\
    2.41 +	pcmpeqd_r2r(mm5,mm5); /* set mm5 to "1" */		\
    2.42 +	pxor_r2r(mm7, mm5); /* make clear alpha mask */		\
    2.43 +        i = length;						\
    2.44 +	if(i & 1) {						\
    2.45 +          movd_m2r((*srcp), mm1); /* src -> mm1 */		\
    2.46 +          punpcklbw_r2r(mm1, mm1);				\
    2.47 +          pand_r2r(mm3, mm1);					\
    2.48 +	  movd_m2r((*dstp), mm2); /* dst -> mm2 */		\
    2.49 +          punpcklbw_r2r(mm2, mm2);				\
    2.50 +          pand_r2r(mm3, mm2);					\
    2.51 +	  psubw_r2r(mm2, mm1);					\
    2.52 +	  pmullw_r2r(mm4, mm1);					\
    2.53 +	  psrlw_i2r(8, mm1);					\
    2.54 +	  paddw_r2r(mm1, mm2);					\
    2.55 +	  pand_r2r(mm3, mm2);					\
    2.56 +	  packuswb_r2r(mm2, mm2);				\
    2.57 +	  pand_r2r(mm5, mm2); /* 00000RGB -> mm2 */		\
    2.58 +	  movd_r2m(mm2, *dstp);					\
    2.59 +	  ++srcp;						\
    2.60 +	  ++dstp;						\
    2.61 +	  i--;							\
    2.62 +	}							\
    2.63 +	for(; i > 0; --i) {					\
    2.64 +          movq_m2r((*srcp), mm0);				\
    2.65 +	  movq_r2r(mm0, mm1);					\
    2.66 +          punpcklbw_r2r(mm0, mm0);				\
    2.67 +	  movq_m2r((*dstp), mm2);				\
    2.68 +	  punpckhbw_r2r(mm1, mm1);				\
    2.69 +	  movq_r2r(mm2, mm6);					\
    2.70 +          pand_r2r(mm3, mm0);					\
    2.71 +          punpcklbw_r2r(mm2, mm2);				\
    2.72 +	  pand_r2r(mm3, mm1);					\
    2.73 +	  punpckhbw_r2r(mm6, mm6);				\
    2.74 +          pand_r2r(mm3, mm2);					\
    2.75 +	  psubw_r2r(mm2, mm0);					\
    2.76 +	  pmullw_r2r(mm4, mm0);					\
    2.77 +	  pand_r2r(mm3, mm6);					\
    2.78 +	  psubw_r2r(mm6, mm1);					\
    2.79 +	  pmullw_r2r(mm4, mm1);					\
    2.80 +	  psrlw_i2r(8, mm0);					\
    2.81 +	  paddw_r2r(mm0, mm2);					\
    2.82 +	  psrlw_i2r(8, mm1);					\
    2.83 +	  paddw_r2r(mm1, mm6);					\
    2.84 +	  pand_r2r(mm3, mm2);					\
    2.85 +	  pand_r2r(mm3, mm6);					\
    2.86 +	  packuswb_r2r(mm2, mm2);				\
    2.87 +	  packuswb_r2r(mm6, mm6);				\
    2.88 +	  psrlq_i2r(32, mm2);					\
    2.89 +	  psllq_i2r(32, mm6);					\
    2.90 +	  por_r2r(mm6, mm2);					\
    2.91 +	  pand_r2r(mm5, mm2); /* 00000RGB -> mm2 */		\
    2.92 +         movq_r2m(mm2, *dstp);					\
    2.93 +	  srcp += 2;						\
    2.94 +	  dstp += 2;						\
    2.95 +	  i--;							\
    2.96 +	}							\
    2.97 +	emms();							\
    2.98 +    } while(0)
    2.99 +
   2.100 +#define ALPHA_BLIT16_565MMX(to, from, length, bpp, alpha)	\
   2.101 +    do {						\
   2.102 +        int i, n = 0;					\
   2.103 +	Uint16 *srcp = (Uint16 *)(from);		\
   2.104 +	Uint16 *dstp = (Uint16 *)(to);			\
   2.105 +        Uint32 ALPHA = 0xF800;				\
   2.106 +	movd_m2r(*(&ALPHA), mm1);			\
   2.107 +        punpcklwd_r2r(mm1, mm1);			\
   2.108 +        punpcklwd_r2r(mm1, mm1);			\
   2.109 +	ALPHA = 0x07E0;					\
   2.110 +	movd_m2r(*(&ALPHA), mm4);			\
   2.111 +        punpcklwd_r2r(mm4, mm4);			\
   2.112 +        punpcklwd_r2r(mm4, mm4);			\
   2.113 +	ALPHA = 0x001F;					\
   2.114 +	movd_m2r(*(&ALPHA), mm7);			\
   2.115 +        punpcklwd_r2r(mm7, mm7);			\
   2.116 +        punpcklwd_r2r(mm7, mm7);			\
   2.117 +	alpha &= ~(1+2+4);				\
   2.118 +        i = (Uint32)alpha | (Uint32)alpha << 16;	\
   2.119 +        movd_m2r(*(&i), mm0);				\
   2.120 +        punpckldq_r2r(mm0, mm0);			\
   2.121 +        ALPHA = alpha >> 3;				\
   2.122 +        i = ((int)(length) & 3);			\
   2.123 +	for(; i > 0; --i) {				\
   2.124 +	    Uint32 s = *srcp++;				\
   2.125 +	    Uint32 d = *dstp;				\
   2.126 +	    s = (s | s << 16) & 0x07e0f81f;		\
   2.127 +	    d = (d | d << 16) & 0x07e0f81f;		\
   2.128 +	    d += (s - d) * ALPHA >> 5;			\
   2.129 +	    d &= 0x07e0f81f;				\
   2.130 +	    *dstp++ = d | d >> 16;			\
   2.131 +	    n++;					\
   2.132 +	}						\
   2.133 +	i = (int)(length) - n;				\
   2.134 +	for(; i > 0; --i) {				\
   2.135 +	  movq_m2r((*dstp), mm3);			\
   2.136 +	  movq_m2r((*srcp), mm2);			\
   2.137 +	  movq_r2r(mm2, mm5);				\
   2.138 +	  pand_r2r(mm1 , mm5);				\
   2.139 +	  psrlq_i2r(11, mm5);				\
   2.140 +	  movq_r2r(mm3, mm6);				\
   2.141 +	  pand_r2r(mm1 , mm6);				\
   2.142 +	  psrlq_i2r(11, mm6);				\
   2.143 +	  psubw_r2r(mm6, mm5);				\
   2.144 +	  pmullw_r2r(mm0, mm5);				\
   2.145 +	  psrlw_i2r(8, mm5);				\
   2.146 +	  paddw_r2r(mm5, mm6);				\
   2.147 +	  psllq_i2r(11, mm6);				\
   2.148 +	  pand_r2r(mm1, mm6);				\
   2.149 +	  movq_r2r(mm4, mm5);				\
   2.150 +	  por_r2r(mm7, mm5);				\
   2.151 +	  pand_r2r(mm5, mm3);				\
   2.152 +	  por_r2r(mm6, mm3);				\
   2.153 +	  movq_r2r(mm2, mm5);				\
   2.154 +	  pand_r2r(mm4 , mm5);				\
   2.155 +	  psrlq_i2r(5, mm5);				\
   2.156 +	  movq_r2r(mm3, mm6);				\
   2.157 +	  pand_r2r(mm4 , mm6);				\
   2.158 +	  psrlq_i2r(5, mm6);				\
   2.159 +	  psubw_r2r(mm6, mm5);				\
   2.160 +	  pmullw_r2r(mm0, mm5);				\
   2.161 +	  psrlw_i2r(8, mm5);				\
   2.162 +	  paddw_r2r(mm5, mm6);				\
   2.163 +	  psllq_i2r(5, mm6);				\
   2.164 +	  pand_r2r(mm4, mm6);				\
   2.165 +	  movq_r2r(mm1, mm5);				\
   2.166 +	  por_r2r(mm7, mm5);				\
   2.167 +	  pand_r2r(mm5, mm3);				\
   2.168 +	  por_r2r(mm6, mm3);				\
   2.169 +	  movq_r2r(mm2, mm5);				\
   2.170 +	  pand_r2r(mm7 , mm5);				\
   2.171 +          movq_r2r(mm3, mm6);				\
   2.172 +	  pand_r2r(mm7 , mm6);				\
   2.173 +	  psubw_r2r(mm6, mm5);				\
   2.174 +	  pmullw_r2r(mm0, mm5);				\
   2.175 +	  psrlw_i2r(8, mm5);				\
   2.176 +	  paddw_r2r(mm5, mm6);				\
   2.177 +	  pand_r2r(mm7, mm6);				\
   2.178 +	  movq_r2r(mm1, mm5);				\
   2.179 +	  por_r2r(mm4, mm5);				\
   2.180 +	  pand_r2r(mm5, mm3);				\
   2.181 +	  por_r2r(mm6, mm3);				\
   2.182 +	  movq_r2m(mm3, *dstp);				\
   2.183 +	  srcp += 4;					\
   2.184 +	  dstp += 4;					\
   2.185 +	  i -= 3;					\
   2.186 +	}						\
   2.187 +	emms();						\
   2.188 +    } while(0)
   2.189 +
   2.190 +#define ALPHA_BLIT16_555MMX(to, from, length, bpp, alpha)	\
   2.191 +    do {						\
   2.192 +        int i, n = 0;					\
   2.193 +	Uint16 *srcp = (Uint16 *)(from);		\
   2.194 +	Uint16 *dstp = (Uint16 *)(to);			\
   2.195 +        Uint32 ALPHA = 0x7C00;				\
   2.196 +	movd_m2r(*(&ALPHA), mm1);			\
   2.197 +        punpcklwd_r2r(mm1, mm1);			\
   2.198 +        punpcklwd_r2r(mm1, mm1);			\
   2.199 +	ALPHA = 0x03E0;					\
   2.200 +        movd_m2r(*(&ALPHA), mm4);			\
   2.201 +        punpcklwd_r2r(mm4, mm4);			\
   2.202 +        punpcklwd_r2r(mm4, mm4);			\
   2.203 +	ALPHA = 0x001F;					\
   2.204 +	movd_m2r(*(&ALPHA), mm7);			\
   2.205 +        punpcklwd_r2r(mm7, mm7);			\
   2.206 +        punpcklwd_r2r(mm7, mm7);			\
   2.207 +	alpha &= ~(1+2+4);				\
   2.208 +        i = (Uint32)alpha | (Uint32)alpha << 16;	\
   2.209 +        movd_m2r(*(&i), mm0);				\
   2.210 +        punpckldq_r2r(mm0, mm0);			\
   2.211 +        i = ((int)(length) & 3);				\
   2.212 +        ALPHA = alpha >> 3;				\
   2.213 +	for(; i > 0; --i) {				\
   2.214 +	    Uint32 s = *srcp++;				\
   2.215 +	    Uint32 d = *dstp;				\
   2.216 +	    s = (s | s << 16) & 0x03e07c1f;		\
   2.217 +	    d = (d | d << 16) & 0x03e07c1f;		\
   2.218 +	    d += (s - d) * ALPHA >> 5;			\
   2.219 +	    d &= 0x03e07c1f;				\
   2.220 +	    *dstp++ = d | d >> 16;			\
   2.221 +	    n++;					\
   2.222 +	}						\
   2.223 +	i = (int)(length) - n;				\
   2.224 +	for(; i > 0; --i) {				\
   2.225 +	  movq_m2r((*dstp), mm3);			\
   2.226 +	  movq_m2r((*srcp), mm2);			\
   2.227 +	  movq_r2r(mm2, mm5);				\
   2.228 +	  pand_r2r(mm1 , mm5);				\
   2.229 +	  psrlq_i2r(10, mm5);				\
   2.230 +	  movq_r2r(mm3, mm6);				\
   2.231 +	  pand_r2r(mm1 , mm6);				\
   2.232 +	  psrlq_i2r(10, mm6);				\
   2.233 +	  psubw_r2r(mm6, mm5);				\
   2.234 +	  pmullw_r2r(mm0, mm5);				\
   2.235 +	  psrlw_i2r(8, mm5);				\
   2.236 +	  paddw_r2r(mm5, mm6);				\
   2.237 +	  psllq_i2r(10, mm6);				\
   2.238 +	  pand_r2r(mm1, mm6);				\
   2.239 +	  movq_r2r(mm4, mm5);				\
   2.240 +	  por_r2r(mm7, mm5);				\
   2.241 +	  pand_r2r(mm5, mm3);				\
   2.242 +	  por_r2r(mm6, mm3);				\
   2.243 +	  movq_r2r(mm2, mm5);				\
   2.244 +	  pand_r2r(mm4 , mm5);				\
   2.245 +	  psrlq_i2r(5, mm5);				\
   2.246 +	  movq_r2r(mm3, mm6);				\
   2.247 +	  pand_r2r(mm4 , mm6);				\
   2.248 +	  psrlq_i2r(5, mm6);				\
   2.249 +	  psubw_r2r(mm6, mm5);				\
   2.250 +	  pmullw_r2r(mm0, mm5);				\
   2.251 +	  psrlw_i2r(8, mm5);				\
   2.252 +	  paddw_r2r(mm5, mm6);				\
   2.253 +	  psllq_i2r(5, mm6);				\
   2.254 +	  pand_r2r(mm4, mm6);				\
   2.255 +	  movq_r2r(mm1, mm5);				\
   2.256 +	  por_r2r(mm7, mm5);				\
   2.257 +	  pand_r2r(mm5, mm3);				\
   2.258 +	  por_r2r(mm6, mm3);				\
   2.259 +	  movq_r2r(mm2, mm5);				\
   2.260 +	  pand_r2r(mm7 , mm5);				\
   2.261 +          movq_r2r(mm3, mm6);				\
   2.262 +	  pand_r2r(mm7 , mm6);				\
   2.263 +	  psubw_r2r(mm6, mm5);				\
   2.264 +	  pmullw_r2r(mm0, mm5);				\
   2.265 +	  psrlw_i2r(8, mm5);				\
   2.266 +	  paddw_r2r(mm5, mm6);				\
   2.267 +	  pand_r2r(mm7, mm6);				\
   2.268 +	  movq_r2r(mm1, mm5);				\
   2.269 +	  por_r2r(mm4, mm5);				\
   2.270 +	  pand_r2r(mm5, mm3);				\
   2.271 +	  por_r2r(mm6, mm3);				\
   2.272 +	  movq_r2m(mm3, *dstp);				\
   2.273 +	  srcp += 4;					\
   2.274 +	  dstp += 4;					\
   2.275 +	  i -= 3;					\
   2.276 +	}						\
   2.277 +	emms();						\
   2.278 +    } while(0)
   2.279 +
   2.280 +#endif
   2.281 +
   2.282  /*
   2.283   * For 32bpp pixels on the form 0x00rrggbb:
   2.284   * If we treat the middle component separately, we can process the two
   2.285 @@ -161,12 +429,13 @@
   2.286          int i;						\
   2.287  	Uint16 *src = (Uint16 *)(from);			\
   2.288  	Uint16 *dst = (Uint16 *)(to);			\
   2.289 +	Uint32 ALPHA = alpha >> 3;			\
   2.290  	for(i = 0; i < (int)(length); i++) {		\
   2.291  	    Uint32 s = *src++;				\
   2.292  	    Uint32 d = *dst;				\
   2.293  	    s = (s | s << 16) & 0x07e0f81f;		\
   2.294  	    d = (d | d << 16) & 0x07e0f81f;		\
   2.295 -	    d += (s - d) * alpha >> 5;			\
   2.296 +	    d += (s - d) * ALPHA >> 5;			\
   2.297  	    d &= 0x07e0f81f;				\
   2.298  	    *dst++ = d | d >> 16;			\
   2.299  	}						\
   2.300 @@ -177,12 +446,13 @@
   2.301          int i;						\
   2.302  	Uint16 *src = (Uint16 *)(from);			\
   2.303  	Uint16 *dst = (Uint16 *)(to);			\
   2.304 +	Uint32 ALPHA = alpha >> 3;			\
   2.305  	for(i = 0; i < (int)(length); i++) {		\
   2.306  	    Uint32 s = *src++;				\
   2.307  	    Uint32 d = *dst;				\
   2.308  	    s = (s | s << 16) & 0x03e07c1f;		\
   2.309  	    d = (d | d << 16) & 0x03e07c1f;		\
   2.310 -	    d += (s - d) * alpha >> 5;			\
   2.311 +	    d += (s - d) * ALPHA >> 5;			\
   2.312  	    d &= 0x03e07c1f;				\
   2.313  	    *dst++ = d | d >> 16;			\
   2.314  	}						\
   2.315 @@ -248,7 +518,48 @@
   2.316  	}								\
   2.317      } while(0)
   2.318  
   2.319 +#if defined(i386) && defined(__GNUC__) && defined(USE_ASMBLIT)
   2.320  
   2.321 +#define ALPHA_BLIT32_888_50MMX(to, from, length, bpp, alpha)		\
   2.322 +    do {								\
   2.323 +	Uint32 *srcp = (Uint32 *)(from);				\
   2.324 +	Uint32 *dstp = (Uint32 *)(to);					\
   2.325 +        int i = 0x00fefefe;						\
   2.326 +        movd_m2r(*(&i), mm4);						\
   2.327 +        punpckldq_r2r(mm4, mm4);					\
   2.328 +        i = 0x00010101;							\
   2.329 +        movd_m2r(*(&i), mm3);						\
   2.330 +        punpckldq_r2r(mm3, mm3);					\
   2.331 +        i = (int)(length);						\
   2.332 +        if( i & 1 ) {							\
   2.333 +	  Uint32 s = *srcp++;						\
   2.334 +	  Uint32 d = *dstp;						\
   2.335 +	  *dstp++ = (((s & 0x00fefefe) + (d & 0x00fefefe)) >> 1)	\
   2.336 +		     + (s & d & 0x00010101);				\
   2.337 +	  i--;								\
   2.338 +	}								\
   2.339 +	for(; i > 0; --i) {						\
   2.340 +	    movq_m2r((*dstp), mm2); /* dst -> mm2 */			\
   2.341 +	    movq_r2r(mm2, mm6);	/* dst -> mm6 */			\
   2.342 +	    movq_m2r((*srcp), mm1); /* src -> mm1 */			\
   2.343 +	    movq_r2r(mm1, mm5);	/* src -> mm5 */			\
   2.344 +	    pand_r2r(mm4, mm6);	/* dst & 0x00fefefe -> mm6 */		\
   2.345 +	    pand_r2r(mm4, mm5); /* src & 0x00fefefe -> mm5 */		\
   2.346 +	    paddd_r2r(mm6, mm5); /* (dst & 0x00fefefe) + (dst & 0x00fefefe) -> mm5 */	\
   2.347 +	    psrld_i2r(1, mm5);						\
   2.348 +	    pand_r2r(mm1, mm2);	/* s & d -> mm2 */			\
   2.349 +	    pand_r2r(mm3, mm2);	/* s & d & 0x00010101 -> mm2 */		\
   2.350 +	    paddd_r2r(mm5, mm2);					\
   2.351 +	    movq_r2m(mm2, (*dstp));					\
   2.352 +	    dstp += 2;							\
   2.353 +	    srcp += 2;							\
   2.354 +	    i--;							\
   2.355 +	}								\
   2.356 +	emms();								\
   2.357 +    } while(0)
   2.358 +
   2.359 +#endif
   2.360 +    
   2.361  /*
   2.362   * Special case: 50% alpha (alpha=128)
   2.363   * This is treated specially because it can be optimized very well, and
   2.364 @@ -320,6 +631,7 @@
   2.365  #define ALPHA_BLIT16_555_50(to, from, length, bpp, alpha)	\
   2.366      ALPHA_BLIT16_50(to, from, length, bpp, alpha, 0xfbde)
   2.367  
   2.368 +#if defined(i386) && defined(__GNUC__) && defined(USE_ASMBLIT)
   2.369  
   2.370  #define CHOOSE_BLIT(blitter, alpha, fmt)				\
   2.371      do {								\
   2.372 @@ -345,7 +657,92 @@
   2.373  			if(alpha == 128)				\
   2.374  			    blitter(2, Uint8, ALPHA_BLIT16_565_50);	\
   2.375  			else {						\
   2.376 -			    alpha >>= 3; /* use 5 bit alpha */		\
   2.377 +			    if((CPU_Flags()&MMX_CPU)!=0)		\
   2.378 +				blitter(2, Uint8, ALPHA_BLIT16_565MMX);	\
   2.379 +			    else					\
   2.380 +				blitter(2, Uint8, ALPHA_BLIT16_565);	\
   2.381 +			}						\
   2.382 +		    } else						\
   2.383 +			goto general16;					\
   2.384 +		    break;						\
   2.385 +									\
   2.386 +		case 0x7fff:						\
   2.387 +		    if(fmt->Gmask == 0x03e0				\
   2.388 +		       || fmt->Rmask == 0x03e0				\
   2.389 +		       || fmt->Bmask == 0x03e0) {			\
   2.390 +			if(alpha == 128)				\
   2.391 +			    blitter(2, Uint8, ALPHA_BLIT16_555_50);	\
   2.392 +			else {						\
   2.393 +			    if((CPU_Flags()&MMX_CPU)!=0)		\
   2.394 +				blitter(2, Uint8, ALPHA_BLIT16_555MMX);	\
   2.395 +			    else					\
   2.396 +				blitter(2, Uint8, ALPHA_BLIT16_555);	\
   2.397 +			}						\
   2.398 +			break;						\
   2.399 +		    }							\
   2.400 +		    /* fallthrough */					\
   2.401 +									\
   2.402 +		default:						\
   2.403 +		general16:						\
   2.404 +		    blitter(2, Uint8, ALPHA_BLIT_ANY);			\
   2.405 +		}							\
   2.406 +		break;							\
   2.407 +									\
   2.408 +	    case 3:							\
   2.409 +		blitter(3, Uint8, ALPHA_BLIT_ANY);			\
   2.410 +		break;							\
   2.411 +									\
   2.412 +	    case 4:							\
   2.413 +		if((fmt->Rmask | fmt->Gmask | fmt->Bmask) == 0x00ffffff	\
   2.414 +		   && (fmt->Gmask == 0xff00 || fmt->Rmask == 0xff00	\
   2.415 +		       || fmt->Bmask == 0xff00)) {			\
   2.416 +		    if(alpha == 128)					\
   2.417 +		    {							\
   2.418 +			if((CPU_Flags()&MMX_CPU)!=0)			\
   2.419 +				blitter(4, Uint16, ALPHA_BLIT32_888_50MMX);\
   2.420 +			else						\
   2.421 +				blitter(4, Uint16, ALPHA_BLIT32_888_50);\
   2.422 +		    }							\
   2.423 +		    else						\
   2.424 +		    {							\
   2.425 +			if((CPU_Flags()&MMX_CPU)!=0)			\
   2.426 +				blitter(4, Uint16, ALPHA_BLIT32_888MMX);\
   2.427 +			else						\
   2.428 +				blitter(4, Uint16, ALPHA_BLIT32_888);	\
   2.429 +		    }							\
   2.430 +		} else							\
   2.431 +		    blitter(4, Uint16, ALPHA_BLIT_ANY);			\
   2.432 +		break;							\
   2.433 +	    }								\
   2.434 +	}								\
   2.435 +    } while(0)
   2.436 +
   2.437 +#else
   2.438 +	
   2.439 +#define CHOOSE_BLIT(blitter, alpha, fmt)				\
   2.440 +    do {								\
   2.441 +        if(alpha == 255) {						\
   2.442 +	    switch(fmt->BytesPerPixel) {				\
   2.443 +	    case 1: blitter(1, Uint8, OPAQUE_BLIT); break;		\
   2.444 +	    case 2: blitter(2, Uint8, OPAQUE_BLIT); break;		\
   2.445 +	    case 3: blitter(3, Uint8, OPAQUE_BLIT); break;		\
   2.446 +	    case 4: blitter(4, Uint16, OPAQUE_BLIT); break;		\
   2.447 +	    }								\
   2.448 +	} else {							\
   2.449 +	    switch(fmt->BytesPerPixel) {				\
   2.450 +	    case 1:							\
   2.451 +		/* No 8bpp alpha blitting */				\
   2.452 +		break;							\
   2.453 +									\
   2.454 +	    case 2:							\
   2.455 +		switch(fmt->Rmask | fmt->Gmask | fmt->Bmask) {		\
   2.456 +		case 0xffff:						\
   2.457 +		    if(fmt->Gmask == 0x07e0				\
   2.458 +		       || fmt->Rmask == 0x07e0				\
   2.459 +		       || fmt->Bmask == 0x07e0) {			\
   2.460 +			if(alpha == 128)				\
   2.461 +			    blitter(2, Uint8, ALPHA_BLIT16_565_50);	\
   2.462 +			else {						\
   2.463  			    blitter(2, Uint8, ALPHA_BLIT16_565);	\
   2.464  			}						\
   2.465  		    } else						\
   2.466 @@ -359,7 +756,6 @@
   2.467  			if(alpha == 128)				\
   2.468  			    blitter(2, Uint8, ALPHA_BLIT16_555_50);	\
   2.469  			else {						\
   2.470 -			    alpha >>= 3; /* use 5 bit alpha */		\
   2.471  			    blitter(2, Uint8, ALPHA_BLIT16_555);	\
   2.472  			}						\
   2.473  			break;						\
   2.474 @@ -391,6 +787,7 @@
   2.475  	}								\
   2.476      } while(0)
   2.477  
   2.478 +#endif
   2.479  
   2.480  /*
   2.481   * This takes care of the case when the surface is clipped on the left and/or
     3.1 --- a/src/video/SDL_blit.c	Tue Aug 12 15:17:20 2003 +0000
     3.2 +++ b/src/video/SDL_blit.c	Fri Aug 22 05:51:19 2003 +0000
     3.3 @@ -37,6 +37,19 @@
     3.4  #include "SDL_pixels_c.h"
     3.5  #include "SDL_memops.h"
     3.6  
     3.7 +#if defined(i386) && defined(__GNUC__) && defined(USE_ASMBLIT)
     3.8 +#include "mmx.h"
     3.9 +/* Function to check the CPU flags */
    3.10 +#define MMX_CPU		0x800000
    3.11 +#define SSE_CPU		0x2000000
    3.12 +#define CPU_Flags()	Hermes_X86_CPU()
    3.13 +#define X86_ASSEMBLER
    3.14 +#define HermesConverterInterface	void
    3.15 +#define HermesClearInterface		void
    3.16 +#define STACKCALL
    3.17 +#include "HeadX86.h"
    3.18 +#endif
    3.19 +
    3.20  /* The general purpose software blit routine */
    3.21  static int SDL_SoftBlit(SDL_Surface *src, SDL_Rect *srcrect,
    3.22  			SDL_Surface *dst, SDL_Rect *dstrect)
    3.23 @@ -106,11 +119,54 @@
    3.24  	return(okay ? 0 : -1);
    3.25  }
    3.26  
    3.27 +#if defined(i386) && defined(__GNUC__) && defined(USE_ASMBLIT)
    3.28 +void SDL_memcpyMMX(char* to,char* from,int len)
    3.29 +{
    3.30 +	int i;
    3.31 +
    3.32 +	for(i=0; i<len/8; i++) {
    3.33 +		__asm__ __volatile__ (
    3.34 +		"	movq (%0), %%mm0\n"
    3.35 +		"	movq %%mm0, (%1)\n"
    3.36 +		: : "r" (from), "r" (to) : "memory");
    3.37 +		from+=8;
    3.38 +		to+=8;
    3.39 +	}
    3.40 +	if (len&7)
    3.41 +		SDL_memcpy(to, from, len&7);
    3.42 +}
    3.43 +
    3.44 +void SDL_memcpySSE(char* to,char* from,int len)
    3.45 +{
    3.46 +	int i;
    3.47 +
    3.48 +	__asm__ __volatile__ (
    3.49 +	"	prefetchnta (%0)\n"
    3.50 +	"	prefetchnta 64(%0)\n"
    3.51 +	"	prefetchnta 128(%0)\n"
    3.52 +	"	prefetchnta 192(%0)\n"
    3.53 +	: : "r" (from) );
    3.54 +
    3.55 +	for(i=0; i<len/8; i++) {
    3.56 +		__asm__ __volatile__ (
    3.57 +		"	prefetchnta 256(%0)\n"
    3.58 +		"	movq (%0), %%mm0\n"
    3.59 +		"	movntq %%mm0, (%1)\n"
    3.60 +		: : "r" (from), "r" (to) : "memory");
    3.61 +		from+=8;
    3.62 +		to+=8;
    3.63 +	}
    3.64 +	if (len&7)
    3.65 +		SDL_memcpy(to, from, len&7);
    3.66 +}
    3.67 +#endif
    3.68 +
    3.69  static void SDL_BlitCopy(SDL_BlitInfo *info)
    3.70  {
    3.71  	Uint8 *src, *dst;
    3.72  	int w, h;
    3.73  	int srcskip, dstskip;
    3.74 +	Uint32 f;
    3.75  
    3.76  	w = info->d_width*info->dst->BytesPerPixel;
    3.77  	h = info->d_height;
    3.78 @@ -118,6 +174,33 @@
    3.79  	dst = info->d_pixels;
    3.80  	srcskip = w+info->s_skip;
    3.81  	dstskip = w+info->d_skip;
    3.82 +#if defined(i386) && defined(__GNUC__) && defined(USE_ASMBLIT)
    3.83 +	f=CPU_Flags();
    3.84 +	if((f&(MMX_CPU|SSE_CPU))==(MMX_CPU|SSE_CPU))
    3.85 +	{
    3.86 +		while ( h-- ) {
    3.87 +			SDL_memcpySSE(dst, src, w);
    3.88 +			src += srcskip;
    3.89 +			dst += dstskip;
    3.90 +		}
    3.91 +		__asm__ __volatile__ (
    3.92 +		"	emms\n"
    3.93 +		::);
    3.94 +	}
    3.95 +	else
    3.96 +	if((f&(MMX_CPU))!=0)
    3.97 +	{
    3.98 +		while ( h-- ) {
    3.99 +			SDL_memcpyMMX(dst, src, w);
   3.100 +			src += srcskip;
   3.101 +			dst += dstskip;
   3.102 +		}
   3.103 +		__asm__ __volatile__ (
   3.104 +		"	emms\n"
   3.105 +		::);
   3.106 +	}
   3.107 +	else
   3.108 +#endif
   3.109  	while ( h-- ) {
   3.110  		SDL_memcpy(dst, src, w);
   3.111  		src += srcskip;
     4.1 --- a/src/video/SDL_blit.h	Tue Aug 12 15:17:20 2003 +0000
     4.2 +++ b/src/video/SDL_blit.h	Fri Aug 22 05:51:19 2003 +0000
     4.3 @@ -410,6 +410,47 @@
     4.4  	}								\
     4.5  }
     4.6  
     4.7 +/* 2 - times unrolled loop */
     4.8 +#define DUFFS_LOOP_DOUBLE2(pixel_copy_increment,			\
     4.9 +				double_pixel_copy_increment, width)	\
    4.10 +{ int n, w = width;							\
    4.11 +	if( w & 1 ) {							\
    4.12 +	    pixel_copy_increment;					\
    4.13 +	    w--;							\
    4.14 +	}								\
    4.15 +	if ( w > 0 )	{						\
    4.16 +	    n = ( w + 2) / 4;						\
    4.17 +	    switch( w & 2 ) {						\
    4.18 +	    case 0: do {	double_pixel_copy_increment;		\
    4.19 +	    case 2:		double_pixel_copy_increment;		\
    4.20 +		    } while ( --n > 0 );					\
    4.21 +	    }								\
    4.22 +	}								\
    4.23 +}
    4.24 +
    4.25 +/* 2 - times unrolled loop 4 pixels */
    4.26 +#define DUFFS_LOOP_QUATRO2(pixel_copy_increment,			\
    4.27 +				double_pixel_copy_increment,		\
    4.28 +				quatro_pixel_copy_increment, width)	\
    4.29 +{ int n, w = width;								\
    4.30 +        if(w & 1) {							\
    4.31 +	  pixel_copy_increment;						\
    4.32 +	  w--;								\
    4.33 +	}								\
    4.34 +	if(w & 2) {							\
    4.35 +	  double_pixel_copy_increment;					\
    4.36 +	  w -= 2;							\
    4.37 +	}								\
    4.38 +	if ( w > 0 ) {							\
    4.39 +	    n = ( w + 7 ) / 8;						\
    4.40 +	    switch( w & 4 ) {						\
    4.41 +	    case 0: do {	quatro_pixel_copy_increment;		\
    4.42 +	    case 4:		quatro_pixel_copy_increment;		\
    4.43 +		    } while ( --n > 0 );					\
    4.44 +	    }								\
    4.45 +	}								\
    4.46 +}
    4.47 +
    4.48  /* Use the 8-times version of the loop by default */
    4.49  #define DUFFS_LOOP(pixel_copy_increment, width)				\
    4.50  	DUFFS_LOOP8(pixel_copy_increment, width)
    4.51 @@ -417,6 +458,39 @@
    4.52  #else
    4.53  
    4.54  /* Don't use Duff's device to unroll loops */
    4.55 +#define DUFFS_LOOP_DOUBLE2(pixel_copy_increment,			\
    4.56 +			 double_pixel_copy_increment, width)		\
    4.57 +{ int n = width;								\
    4.58 +    if( n & 1 ) {							\
    4.59 +	pixel_copy_increment;						\
    4.60 +	n--;								\
    4.61 +    }									\
    4.62 +    n=n>>1;								\
    4.63 +    for(; n > 0; --n) {   						\
    4.64 +	double_pixel_copy_increment;					\
    4.65 +    }									\
    4.66 +}
    4.67 +
    4.68 +/* Don't use Duff's device to unroll loops */
    4.69 +#define DUFFS_LOOP_QUATRO2(pixel_copy_increment,			\
    4.70 +				double_pixel_copy_increment,		\
    4.71 +				quatro_pixel_copy_increment, width)	\
    4.72 +{ int n = width;								\
    4.73 +        if(n & 1) {							\
    4.74 +	  pixel_copy_increment;						\
    4.75 +	  n--;								\
    4.76 +	}								\
    4.77 +	if(n & 2) {							\
    4.78 +	  double_pixel_copy_increment;					\
    4.79 +	  n -= 2;							\
    4.80 +	}								\
    4.81 +	n=n>>2;								\
    4.82 +	for(; n > 0; --n) {   						\
    4.83 +	  quatro_pixel_copy_increment;					\
    4.84 +        }								\
    4.85 +}
    4.86 +
    4.87 +/* Don't use Duff's device to unroll loops */
    4.88  #define DUFFS_LOOP(pixel_copy_increment, width)				\
    4.89  { int n;								\
    4.90  	for ( n=width; n > 0; --n ) {					\
     5.1 --- a/src/video/SDL_blit_A.c	Tue Aug 12 15:17:20 2003 +0000
     5.2 +++ b/src/video/SDL_blit_A.c	Fri Aug 22 05:51:19 2003 +0000
     5.3 @@ -31,6 +31,19 @@
     5.4  #include "SDL_video.h"
     5.5  #include "SDL_blit.h"
     5.6  
     5.7 +#if defined(i386) && defined(__GNUC__) && defined(USE_ASMBLIT)
     5.8 +#include "mmx.h"
     5.9 +/* Function to check the CPU flags */
    5.10 +#define MMX_CPU		0x800000
    5.11 +#define TDNOW_CPU	0x80000000
    5.12 +#define CPU_Flags()	Hermes_X86_CPU()
    5.13 +#define X86_ASSEMBLER
    5.14 +#define HermesConverterInterface	void
    5.15 +#define HermesClearInterface		void
    5.16 +#define STACKCALL
    5.17 +#include "HeadX86.h"
    5.18 +#endif
    5.19 +
    5.20  /* Functions to perform alpha blended blitting */
    5.21  
    5.22  /* N->1 blending with per-surface alpha */
    5.23 @@ -195,6 +208,222 @@
    5.24  	}
    5.25  }
    5.26  
    5.27 +#if defined(i386) && defined(__GNUC__) && defined(USE_ASMBLIT)
    5.28 +/* fast RGB888->(A)RGB888 blending with surface alpha=128 special case */
    5.29 +static void BlitRGBtoRGBSurfaceAlpha128MMX(SDL_BlitInfo *info)
    5.30 +{
    5.31 +	int width = info->d_width;
    5.32 +	int height = info->d_height;
    5.33 +	Uint32 *srcp = (Uint32 *)info->s_pixels;
    5.34 +	int srcskip = info->s_skip >> 2;
    5.35 +	Uint32 *dstp = (Uint32 *)info->d_pixels;
    5.36 +	int dstskip = info->d_skip >> 2;
    5.37 +        Uint8 load[8];
    5.38 +  
    5.39 +        *(Uint64 *)load = 0x00fefefe00fefefe;/* alpha128 mask */
    5.40 +        movq_m2r(*load, mm4); /* alpha128 mask -> mm4 */
    5.41 +        *(Uint64 *)load = 0x0001010100010101;/* !alpha128 mask */
    5.42 +        movq_m2r(*load, mm3); /* !alpha128 mask -> mm3 */
    5.43 +        *(Uint64 *)load = 0xFF000000FF000000;/* dst alpha mask */
    5.44 +        movq_m2r(*load, mm7); /* dst alpha mask -> mm7 */
    5.45 +	while(height--) {
    5.46 +            DUFFS_LOOP_DOUBLE2(
    5.47 +            {
    5.48 +		    Uint32 s = *srcp++;
    5.49 +		    Uint32 d = *dstp;
    5.50 +		    *dstp++ = ((((s & 0x00fefefe) + (d & 0x00fefefe)) >> 1)
    5.51 +			       + (s & d & 0x00010101)) | 0xff000000;
    5.52 +            },{
    5.53 +	            movq_m2r((*dstp), mm2);/* 2 x dst -> mm2(ARGBARGB) */
    5.54 +	            movq_r2r(mm2, mm6); /* 2 x dst -> mm6(ARGBARGB) */
    5.55 +	      
    5.56 +	            movq_m2r((*srcp), mm1);/* 2 x src -> mm1(ARGBARGB) */
    5.57 +	            movq_r2r(mm1, mm5); /* 2 x src -> mm5(ARGBARGB) */
    5.58 +		
    5.59 +	            pand_r2r(mm4, mm6); /* dst & mask -> mm6 */
    5.60 +	            pand_r2r(mm4, mm5); /* src & mask -> mm5 */
    5.61 +	            paddd_r2r(mm6, mm5); /* mm6 + mm5 -> mm5 */
    5.62 +	            psrld_i2r(1, mm5); /* mm5 >> 1 -> mm5 */
    5.63 +	
    5.64 +	            pand_r2r(mm1, mm2); /* src & dst -> mm2 */
    5.65 +	            pand_r2r(mm3, mm2); /* mm2 & !mask -> mm2 */
    5.66 +	            paddd_r2r(mm5, mm2); /* mm5 + mm2 -> mm2 */
    5.67 +	            por_r2r(mm7, mm2); /* mm7(full alpha) | mm2 -> mm2 */
    5.68 +	            movq_r2m(mm2, (*dstp));/* mm2 -> 2 x dst pixels */
    5.69 +	            dstp += 2;
    5.70 +	            srcp += 2;
    5.71 +            }, width);
    5.72 +	    srcp += srcskip;
    5.73 +	    dstp += dstskip;
    5.74 +	}
    5.75 +	emms();
    5.76 +}
    5.77 +
    5.78 +/* fast RGB888->(A)RGB888 blending with surface alpha */
    5.79 +static void BlitRGBtoRGBSurfaceAlphaMMX(SDL_BlitInfo *info)
    5.80 +{
    5.81 +	unsigned alpha = info->src->alpha;
    5.82 +	if(alpha == 128) {
    5.83 +		BlitRGBtoRGBSurfaceAlpha128MMX(info);
    5.84 +	} else {
    5.85 +		int width = info->d_width;
    5.86 +		int height = info->d_height;
    5.87 +		Uint32 *srcp = (Uint32 *)info->s_pixels;
    5.88 +		int srcskip = info->s_skip >> 2;
    5.89 +		Uint32 *dstp = (Uint32 *)info->d_pixels;
    5.90 +		int dstskip = info->d_skip >> 2;
    5.91 +                Uint8 load[8] = {alpha, alpha, alpha, alpha,
    5.92 +    					alpha, alpha, alpha, alpha};
    5.93 +					
    5.94 +                movq_m2r(*load, mm4); /* alpha -> mm4 */
    5.95 +		*(Uint64 *)load = 0x00FF00FF00FF00FF;
    5.96 +                movq_m2r(*load, mm3); /* mask -> mm3 */
    5.97 +		pand_r2r(mm3, mm4); /* mm4 & mask -> 0A0A0A0A -> mm4 */
    5.98 +		*(Uint64 *)load = 0xFF000000FF000000;/* dst alpha mask */
    5.99 +		movq_m2r(*load, mm7); /* dst alpha mask -> mm7 */
   5.100 +		
   5.101 +		while(height--) {
   5.102 +			DUFFS_LOOP_DOUBLE2({
   5.103 +				/* One Pixel Blend */
   5.104 +	                        movd_m2r((*srcp), mm1);/* src(ARGB) -> mm1 (0000ARGB)*/
   5.105 +                                punpcklbw_r2r(mm1, mm1); /* AARRGGBB -> mm1 */
   5.106 +                                pand_r2r(mm3, mm1); /* 0A0R0G0B -> mm1 */
   5.107 +			  
   5.108 +	                        movd_m2r((*dstp), mm2);/* dst(ARGB) -> mm2 (0000ARGB)*/
   5.109 +			        movq_r2r(mm2, mm6);/* dst(ARGB) -> mm6 (0000ARGB)*/
   5.110 +                                punpcklbw_r2r(mm2, mm2); /* AARRGGBB -> mm2 */
   5.111 +                                pand_r2r(mm3, mm2); /* 0A0R0G0B -> mm2 */
   5.112 +			  
   5.113 +                                psubw_r2r(mm2, mm1);/* src - dst -> mm1 */
   5.114 +	                        pmullw_r2r(mm4, mm1); /* mm1 * alpha -> mm1 */
   5.115 +	                        psrlw_i2r(8, mm1); /* mm1 >> 8 -> mm1 */
   5.116 +	                        paddw_r2r(mm1, mm2); /* mm1 + mm2(dst) -> mm2 */
   5.117 +	                        pand_r2r(mm3, mm2); /* 0A0R0G0B -> mm2 */
   5.118 +	                        packuswb_r2r(mm2, mm2);  /* ARGBARGB -> mm2 */
   5.119 +	                        por_r2r(mm7, mm2); /* mm7(full alpha) | mm2 -> mm2 */
   5.120 +			        movd_r2m(mm2, *dstp);/* mm2 -> pixel */
   5.121 +				++srcp;
   5.122 +				++dstp;
   5.123 +			},{
   5.124 +			        /* Two Pixels Blend */
   5.125 +				movq_m2r((*srcp), mm0);/* 2 x src -> mm0(ARGBARGB)*/
   5.126 +			        movq_r2r(mm0, mm1); /* 2 x src -> mm1(ARGBARGB) */
   5.127 +                                punpcklbw_r2r(mm0, mm0); /* low - AARRGGBB -> mm0 */
   5.128 +			        pand_r2r(mm3, mm0); /* 0A0R0G0B -> mm0(src1) */
   5.129 +			        punpckhbw_r2r(mm1, mm1); /* high - AARRGGBB -> mm1 */
   5.130 +	                        pand_r2r(mm3, mm1); /* 0A0R0G0B -> mm1(src2) */
   5.131 +	
   5.132 +	                        movq_m2r((*dstp), mm2);/* 2 x dst -> mm2(ARGBARGB) */
   5.133 +	                        movq_r2r(mm2, mm5); /* 2 x dst -> mm5(ARGBARGB) */
   5.134 +			        movq_r2r(mm2, mm6); /* 2 x dst -> mm6(ARGBARGB) */
   5.135 +                                punpcklbw_r2r(mm2, mm2); /* low - AARRGGBB -> mm2 */
   5.136 +	                        punpckhbw_r2r(mm6, mm6); /* high - AARRGGBB -> mm6 */
   5.137 +                                pand_r2r(mm3, mm2); /* 0A0R0G0B -> mm2(dst1) */
   5.138 +	                  
   5.139 +                                psubw_r2r(mm2, mm0);/* src1 - dst1 -> mm0 */
   5.140 +	                        pmullw_r2r(mm4, mm0); /* mm0 * alpha -> mm0 */
   5.141 +			        pand_r2r(mm3, mm6); /* 0A0R0G0B -> mm6(dst2) */
   5.142 +			        psrlw_i2r(8, mm0); /* mm0 >> 8 -> mm1 */
   5.143 +			        psubw_r2r(mm6, mm1);/* src2 - dst2 -> mm1 */
   5.144 +	                        pmullw_r2r(mm4, mm1); /* mm1 * alpha -> mm1 */
   5.145 +				paddw_r2r(mm0, mm2); /* mm0 + mm2(dst1) -> mm2 */
   5.146 +	                        psrlw_i2r(8, mm1); /* mm1 >> 8 -> mm0 */
   5.147 +				pand_r2r(mm3, mm2); /* 0A0R0G0B -> mm2 */
   5.148 +	                        paddw_r2r(mm1, mm6); /* mm1 + mm6(dst2) -> mm6 */
   5.149 +	                        pand_r2r(mm3, mm6); /* 0A0R0G0B -> mm6 */
   5.150 +	                        packuswb_r2r(mm2, mm2);  /* ARGBARGB -> mm2 */
   5.151 +	                        packuswb_r2r(mm6, mm6);  /* ARGBARGB -> mm6 */
   5.152 +	                        psrlq_i2r(32, mm2); /* mm2 >> 32 -> mm2 */
   5.153 +	                        psllq_i2r(32, mm6); /* mm6 << 32 -> mm6 */
   5.154 +	                        por_r2r(mm6, mm2); /* mm6 | mm2 -> mm2 */				
   5.155 +				por_r2r(mm7, mm2); /* mm7(full alpha) | mm2 -> mm2 */
   5.156 +                                movq_r2m(mm2, *dstp);/* mm2 -> 2 x pixel */
   5.157 +				srcp += 2;
   5.158 +				dstp += 2;
   5.159 +			}, width);
   5.160 +			srcp += srcskip;
   5.161 +			dstp += dstskip;
   5.162 +		}
   5.163 +		emms();
   5.164 +	}
   5.165 +}
   5.166 +
   5.167 +/* fast ARGB888->(A)RGB888 blending with pixel alpha */
   5.168 +static void BlitRGBtoRGBPixelAlphaMMX(SDL_BlitInfo *info)
   5.169 +{
   5.170 +	int width = info->d_width;
   5.171 +	int height = info->d_height;
   5.172 +	Uint32 *srcp = (Uint32 *)info->s_pixels;
   5.173 +	int srcskip = info->s_skip >> 2;
   5.174 +	Uint32 *dstp = (Uint32 *)info->d_pixels;
   5.175 +	int dstskip = info->d_skip >> 2;
   5.176 +        Uint32 alpha = 0;
   5.177 +        Uint8 load[8];
   5.178 +	                
   5.179 +	*(Uint64 *)load = 0x00FF00FF00FF00FF;
   5.180 +        movq_m2r(*load, mm3); /* mask -> mm2 */
   5.181 +	*(Uint64 *)load = 0x00FF000000000000;
   5.182 +        movq_m2r(*load, mm7); /* dst alpha mask -> mm2 */
   5.183 +        *(Uint64 *)load = 0x00FFFFFF00FFFFFF;
   5.184 +        movq_m2r(*load, mm0); /* alpha 255 mask -> mm0 */
   5.185 +        *(Uint64 *)load = 0xFF000000FF000000;
   5.186 +        movq_m2r(*load, mm6); /* alpha 255 !mask -> mm6 */
   5.187 +	while(height--) {
   5.188 +	    DUFFS_LOOP4({
   5.189 +	        alpha = *srcp;
   5.190 +	        alpha >>= 24;
   5.191 +		/* FIXME: Here we special-case opaque alpha since the
   5.192 +		   compositioning used (>>8 instead of /255) doesn't handle
   5.193 +		   it correctly. Also special-case alpha=0 for speed?
   5.194 +		   Benchmark this! */
   5.195 +		if(alpha) {   
   5.196 +		  if(alpha == SDL_ALPHA_OPAQUE) {
   5.197 +		    movd_m2r((*srcp), mm1);/* src(ARGB) -> mm1 (0000ARGB)*/
   5.198 +		    movd_m2r((*dstp), mm2);/* dst(ARGB) -> mm2 (0000ARGB)*/
   5.199 +		    pand_r2r(mm0, mm1);
   5.200 +		    pand_r2r(mm6, mm2);
   5.201 +		    por_r2r(mm1, mm2);
   5.202 +		    movd_r2m(mm2, (*dstp));
   5.203 +		  } else {
   5.204 +		    movd_m2r((*srcp), mm1);/* src(ARGB) -> mm1 (0000ARGB)*/
   5.205 +                    punpcklbw_r2r(mm1, mm1); /* AARRGGBB -> mm1 */
   5.206 +                    pand_r2r(mm3, mm1); /* 0A0R0G0B -> mm1 */
   5.207 +			  
   5.208 +	            movd_m2r((*dstp), mm2);/* dst(ARGB) -> mm2 (0000ARGB)*/
   5.209 +                    punpcklbw_r2r(mm2, mm2); /* AARRGGBB -> mm2 */
   5.210 +                    pand_r2r(mm3, mm2); /* 0A0R0G0B -> mm2 */
   5.211 +		
   5.212 +		    movq_r2r(mm2, mm5);/* mm2(0A0R0G0B) -> mm5 */
   5.213 +		    pand_r2r(mm7, mm5); /* mm5 & dst alpha mask -> mm5(0A000000) */
   5.214 +		    psrlq_i2r(24, mm5); /* mm5 >> 24 -> mm5 (0000A000)*/
   5.215 +		    
   5.216 +		    movq_r2r(mm1, mm4);/* mm1(0A0R0G0B) -> mm4 */
   5.217 +		    psrlq_i2r(48, mm4); /* mm4 >> 48 -> mm4(0000000A) */
   5.218 +		    punpcklwd_r2r(mm4, mm4); /* 00000A0A -> mm4 */
   5.219 +                    punpcklwd_r2r(mm4, mm4); /* 0A0A0A0A -> mm4 */
   5.220 +		                        		    
   5.221 +                    /* blend */		    
   5.222 +                    psubw_r2r(mm2, mm1);/* src - dst -> mm1 */
   5.223 +	            pmullw_r2r(mm4, mm1); /* mm1 * alpha -> mm1 */
   5.224 +	            psrlw_i2r(8, mm1); /* mm1 >> 8 -> mm1 */
   5.225 +	            paddw_r2r(mm1, mm2); /* mm1 + mm2(dst) -> mm2 */
   5.226 +	            pand_r2r(mm3, mm2); /* 0A0R0G0B -> mm2 */
   5.227 +		    packuswb_r2r(mm2, mm2);  /* ARGBARGB -> mm2 */
   5.228 +		    pand_r2r(mm0, mm2); /* 0RGB0RGB -> mm2 */
   5.229 +		    por_r2r(mm5, mm2); /* dst alpha | mm2 -> mm2 */
   5.230 +		    movd_r2m(mm2, *dstp);/* mm2 -> dst */
   5.231 +		  }
   5.232 +		}
   5.233 +		++srcp;
   5.234 +		++dstp;
   5.235 +	    }, width);
   5.236 +	    srcp += srcskip;
   5.237 +	    dstp += dstskip;
   5.238 +	}
   5.239 +	emms();
   5.240 +}
   5.241 +#endif
   5.242 +
   5.243  /* fast RGB888->(A)RGB888 blending with surface alpha=128 special case */
   5.244  static void BlitRGBtoRGBSurfaceAlpha128(SDL_BlitInfo *info)
   5.245  {
   5.246 @@ -230,13 +459,14 @@
   5.247  		int srcskip = info->s_skip >> 2;
   5.248  		Uint32 *dstp = (Uint32 *)info->d_pixels;
   5.249  		int dstskip = info->d_skip >> 2;
   5.250 +		Uint32 s;
   5.251 +		Uint32 d;
   5.252 +		Uint32 s1;
   5.253 +		Uint32 d1;
   5.254  
   5.255  		while(height--) {
   5.256 -			DUFFS_LOOP4({
   5.257 -				Uint32 s;
   5.258 -				Uint32 d;
   5.259 -				Uint32 s1;
   5.260 -				Uint32 d1;
   5.261 +			DUFFS_LOOP_DOUBLE2({
   5.262 +				/* One Pixel Blend */
   5.263  				s = *srcp;
   5.264  				d = *dstp;
   5.265  				s1 = s & 0xff00ff;
   5.266 @@ -249,6 +479,35 @@
   5.267  				*dstp = d1 | d | 0xff000000;
   5.268  				++srcp;
   5.269  				++dstp;
   5.270 +			},{
   5.271 +			        /* Two Pixels Blend */
   5.272 +				s = *srcp;
   5.273 +				d = *dstp;
   5.274 +				s1 = s & 0xff00ff;
   5.275 +				d1 = d & 0xff00ff;
   5.276 +				d1 += (s1 - d1) * alpha >> 8;
   5.277 +				d1 &= 0xff00ff;
   5.278 +				     
   5.279 +				s = ((s & 0xff00) >> 8) | 
   5.280 +					((srcp[1] & 0xff00) << 8);
   5.281 +				d = ((d & 0xff00) >> 8) |
   5.282 +					((dstp[1] & 0xff00) << 8);
   5.283 +				d += (s - d) * alpha >> 8;
   5.284 +				d &= 0x00ff00ff;
   5.285 +				
   5.286 +				*dstp++ = d1 | ((d << 8) & 0xff00) | 0xff000000;
   5.287 +				++srcp;
   5.288 +				
   5.289 +			        s1 = *srcp;
   5.290 +				d1 = *dstp;
   5.291 +				s1 &= 0xff00ff;
   5.292 +				d1 &= 0xff00ff;
   5.293 +				d1 += (s1 - d1) * alpha >> 8;
   5.294 +				d1 &= 0xff00ff;
   5.295 +				
   5.296 +				*dstp = d1 | ((d >> 8) & 0xff00) | 0xff000000;
   5.297 +				++srcp;
   5.298 +				++dstp;
   5.299  			}, width);
   5.300  			srcp += srcskip;
   5.301  			dstp += dstskip;
   5.302 @@ -278,9 +537,10 @@
   5.303  		   compositioning used (>>8 instead of /255) doesn't handle
   5.304  		   it correctly. Also special-case alpha=0 for speed?
   5.305  		   Benchmark this! */
   5.306 -		if(alpha == SDL_ALPHA_OPAQUE) {
   5.307 +		if(alpha) {   
   5.308 +		  if(alpha == SDL_ALPHA_OPAQUE) {
   5.309  		    *dstp = (s & 0x00ffffff) | (*dstp & 0xff000000);
   5.310 -		} else {
   5.311 +		  } else {
   5.312  		    /*
   5.313  		     * take out the middle component (green), and process
   5.314  		     * the other two in parallel. One multiply less.
   5.315 @@ -294,6 +554,7 @@
   5.316  		    d &= 0xff00;
   5.317  		    d = (d + ((s - d) * alpha >> 8)) & 0xff00;
   5.318  		    *dstp = d1 | d | dalpha;
   5.319 +		  }
   5.320  		}
   5.321  		++srcp;
   5.322  		++dstp;
   5.323 @@ -303,6 +564,101 @@
   5.324  	}
   5.325  }
   5.326  
   5.327 +#if defined(i386) && defined(__GNUC__) && defined(USE_ASMBLIT)
   5.328 +/* fast (as in MMX with prefetch) ARGB888->(A)RGB888 blending with pixel alpha */
   5.329 +inline static void BlitRGBtoRGBPixelAlphaMMX3DNOW(SDL_BlitInfo *info)
   5.330 +{
   5.331 +	int width = info->d_width;
   5.332 +	int height = info->d_height;
   5.333 +	Uint32 *srcp = (Uint32 *)info->s_pixels;
   5.334 +	int srcskip = info->s_skip >> 2;
   5.335 +	Uint32 *dstp = (Uint32 *)info->d_pixels;
   5.336 +	int dstskip = info->d_skip >> 2;
   5.337 +
   5.338 +	Uint32 s;
   5.339 +	Uint32 alpha;
   5.340 +
   5.341 +	__asm__ (
   5.342 +	/* make mm6 all zeros. */
   5.343 +	"pxor       %%mm6, %%mm6\n"
   5.344 +	
   5.345 +	/* Make a mask to preserve the alpha. */
   5.346 +	"pcmpeqb   %%mm7, %%mm7\n\t"            /* mm7(s) = FF FF FF FF | FF FF FF FF */
   5.347 +	"psrlq     $16, %%mm7\n\t"		    /* mm7(s) = 00 00 FF FF | FF FF FF FF */
   5.348 +
   5.349 +		: );
   5.350 +
   5.351 +	while(height--) {
   5.352 +
   5.353 +	    DUFFS_LOOP4({
   5.354 +
   5.355 +		__asm__ (
   5.356 +		"prefetch 64(%0)\n"
   5.357 +		"prefetch 64(%1)\n"
   5.358 +			: : "r" (srcp), "r" (dstp) );
   5.359 +
   5.360 +		s = *srcp;
   5.361 +		alpha = s >> 24;
   5.362 +		/* FIXME: Here we special-case opaque alpha since the
   5.363 +		   compositioning used (>>8 instead of /255) doesn't handle
   5.364 +		   it correctly. Also special-case alpha=0 for speed?
   5.365 +		   Benchmark this! */
   5.366 +		
   5.367 +		if(alpha == SDL_ALPHA_OPAQUE) {
   5.368 +		    *dstp = (s & 0x00ffffff) | (*dstp & 0xff000000);
   5.369 +		} 
   5.370 +
   5.371 +		else {
   5.372 +			    __asm__ (
   5.373 +		    /* load in the source, and dst. */
   5.374 +		    "movd      (%0), %%mm0\n"		    /* mm0(s) = 0 0 0 0 | As Rs Gs Bs */
   5.375 +		    "movd      (%1), %%mm1\n"		    /* mm1(d) = 0 0 0 0 | Ad Rd Gd Bd */
   5.376 +
   5.377 +		    /* Move the src alpha into mm2 */
   5.378 +
   5.379 +		    /* if supporting pshufw */
   5.380 +		    /*"pshufw     $0x55, %%mm0, %%mm2\n" */ /* mm2 = 0 As 0 As |  0 As  0  As */
   5.381 +		    /*"psrlw     $8, %%mm2\n" */
   5.382 +		    
   5.383 +		    /* else: */
   5.384 +		    "movq      %%mm0, %%mm2\n"
   5.385 +		    "psrld     $24, %%mm2\n"                /* mm2 = 0 0 0 0 | 0  0  0  As */
   5.386 +		    "punpcklwd	%%mm2, %%mm2\n"	            /* mm2 = 0 0 0 0 |  0 As  0  As */
   5.387 +		    "punpckldq	%%mm2, %%mm2\n"             /* mm2 = 0 As 0 As |  0 As  0  As */
   5.388 +
   5.389 +		    /* move the colors into words. */
   5.390 +		    "punpcklbw %%mm6, %%mm0\n"		    /* mm0 = 0 As 0 Rs | 0 Gs 0 Bs */
   5.391 +		    "punpcklbw %%mm6, %%mm1\n"              /* mm0 = 0 Ad 0 Rd | 0 Gd 0 Bd */
   5.392 +
   5.393 +		    /* src - dst */
   5.394 +		    "psubw    %%mm1, %%mm0\n"		    /* mm0 = As-Ad Rs-Rd | Gs-Gd  Bs-Bd */
   5.395 +
   5.396 +		    /* A * (src-dst) */
   5.397 +		    "pmullw    %%mm2, %%mm0\n"		    /* mm0 = As*As-d As*Rs-d | As*Gs-d  As*Bs-d */
   5.398 +		    "pand      %%mm7, %%mm0\n"              /* to preserve dest alpha */
   5.399 +		    "psrlw     $8,    %%mm0\n"		    /* mm0 = Ac>>8 Rc>>8 | Gc>>8  Bc>>8 */
   5.400 +		    "paddb     %%mm1, %%mm0\n"		    /* mm0 = Ac+Ad Rc+Rd | Gc+Gd  Bc+Bd */
   5.401 +
   5.402 +		    "packuswb  %%mm0, %%mm0\n"              /* mm0 =             | Ac Rc Gc Bc */
   5.403 +		    
   5.404 +		    "movd      %%mm0, (%1)\n"               /* result in mm0 */
   5.405 +
   5.406 +		     : : "r" (srcp), "r" (dstp) );
   5.407 +
   5.408 +		}
   5.409 +		++srcp;
   5.410 +		++dstp;
   5.411 +	    }, width);
   5.412 +	    srcp += srcskip;
   5.413 +	    dstp += dstskip;
   5.414 +	}
   5.415 +
   5.416 +	__asm__ (
   5.417 +	"emms\n"
   5.418 +		:   );
   5.419 +}
   5.420 +#endif
   5.421 +
   5.422  /* 16bpp special case for per-surface alpha=50%: blend 2 pixels in parallel */
   5.423  
   5.424  /* blend a single 16 bit pixel at 50% */
   5.425 @@ -410,6 +766,308 @@
   5.426  	}
   5.427  }
   5.428  
   5.429 +#if defined(i386) && defined(__GNUC__) && defined(USE_ASMBLIT)
   5.430 +/* fast RGB565->RGB565 blending with surface alpha */
   5.431 +static void Blit565to565SurfaceAlphaMMX(SDL_BlitInfo *info)
   5.432 +{
   5.433 +	unsigned alpha = info->src->alpha; /* downscale alpha to 5 bits */
   5.434 +	if(alpha == 128) {
   5.435 +		Blit16to16SurfaceAlpha128(info, 0xf7de);
   5.436 +	} else {
   5.437 +		int width = info->d_width;
   5.438 +		int height = info->d_height;
   5.439 +		Uint16 *srcp = (Uint16 *)info->s_pixels;
   5.440 +		int srcskip = info->s_skip >> 1;
   5.441 +		Uint16 *dstp = (Uint16 *)info->d_pixels;
   5.442 +		int dstskip = info->d_skip >> 1;
   5.443 +	        Uint32 s, d;
   5.444 +	        Uint8 load[8];
   5.445 +	  
   5.446 +		alpha &= ~(1+2+4);		/* cut alpha to get the exact same behaviour */
   5.447 +	        *(Uint64 *)load = alpha;
   5.448 +		alpha >>= 3;		/* downscale alpha to 5 bits */
   5.449 +
   5.450 +                movq_m2r(*load, mm0); /* alpha(0000000A) -> mm0 */
   5.451 +                punpcklwd_r2r(mm0, mm0); /* 00000A0A -> mm0 */
   5.452 +                punpcklwd_r2r(mm0, mm0); /* 0A0A0A0A -> mm0 */
   5.453 +	  
   5.454 + 	        /* Setup the 565 color channel masks */
   5.455 +	        *(Uint64 *)load = 0xF800F800F800F800;
   5.456 +		movq_m2r(*load, mm1); /* MASKRED -> mm1 */
   5.457 +		*(Uint64 *)load = 0x07E007E007E007E0;
   5.458 +		movq_m2r(*load, mm4); /* MASKGREEN -> mm4 */
   5.459 +		*(Uint64 *)load = 0x001F001F001F001F;
   5.460 +		movq_m2r(*load, mm7); /* MASKBLUE -> mm7 */
   5.461 +		while(height--) {
   5.462 +                        DUFFS_LOOP_QUATRO2(
   5.463 +                        {
   5.464 +	                        s = *srcp++;
   5.465 +				d = *dstp;
   5.466 +				/*
   5.467 +				 * shift out the middle component (green) to
   5.468 +				 * the high 16 bits, and process all three RGB
   5.469 +				 * components at the same time.
   5.470 +				 */
   5.471 +				s = (s | s << 16) & 0x07e0f81f;
   5.472 +				d = (d | d << 16) & 0x07e0f81f;
   5.473 +				d += (s - d) * alpha >> 5;
   5.474 +				d &= 0x07e0f81f;
   5.475 +				*dstp++ = d | d >> 16;
   5.476 +                        },{
   5.477 +	                        s = *srcp++;
   5.478 +				d = *dstp;
   5.479 +				/*
   5.480 +				 * shift out the middle component (green) to
   5.481 +				 * the high 16 bits, and process all three RGB
   5.482 +				 * components at the same time.
   5.483 +				 */
   5.484 +				s = (s | s << 16) & 0x07e0f81f;
   5.485 +				d = (d | d << 16) & 0x07e0f81f;
   5.486 +				d += (s - d) * alpha >> 5;
   5.487 +				d &= 0x07e0f81f;
   5.488 +				*dstp++ = d | d >> 16;
   5.489 +			        s = *srcp++;
   5.490 +				d = *dstp;
   5.491 +				/*
   5.492 +				 * shift out the middle component (green) to
   5.493 +				 * the high 16 bits, and process all three RGB
   5.494 +				 * components at the same time.
   5.495 +				 */
   5.496 +				s = (s | s << 16) & 0x07e0f81f;
   5.497 +				d = (d | d << 16) & 0x07e0f81f;
   5.498 +				d += (s - d) * alpha >> 5;
   5.499 +				d &= 0x07e0f81f;
   5.500 +				*dstp++ = d | d >> 16;
   5.501 +                        },{
   5.502 +	                        movq_m2r((*dstp), mm3);/* 4 dst pixels -> mm3 */
   5.503 +	                        movq_m2r((*srcp), mm2);/* 4 src pixels -> mm2 */
   5.504 +			  
   5.505 +	                        /* RED */
   5.506 +	                        movq_r2r(mm2, mm5); /* src -> mm5 */
   5.507 +	                        pand_r2r(mm1 , mm5); /* src & MASKRED -> mm5 */
   5.508 +	                        psrlq_i2r(11, mm5); /* mm5 >> 11 -> mm5 [000r 000r 000r 000r] */
   5.509 +	
   5.510 +	                        movq_r2r(mm3, mm6); /* dst -> mm6 */
   5.511 +	                        pand_r2r(mm1 , mm6); /* dst & MASKRED -> mm6 */
   5.512 +	                        psrlq_i2r(11, mm6); /* mm6 >> 11 -> mm6 [000r 000r 000r 000r] */
   5.513 +	
   5.514 +	                        /* blend */
   5.515 +	                        psubw_r2r(mm6, mm5);/* src - dst -> mm5 */
   5.516 +	                        pmullw_r2r(mm0, mm5); /* mm5 * alpha -> mm5 */
   5.517 +	                        psrlw_i2r(8, mm5); /* mm5 >> 8 -> mm5 */
   5.518 +	                        paddw_r2r(mm5, mm6); /* mm5 + mm6(dst) -> mm6 */
   5.519 +	                        psllq_i2r(11, mm6); /* mm6 << 11 -> mm6 */
   5.520 +	                        pand_r2r(mm1, mm6); /* mm6 & MASKRED -> mm6 */
   5.521 +	
   5.522 +	                        movq_r2r(mm4, mm5); /* MASKGREEN -> mm5 */
   5.523 +	                        por_r2r(mm7, mm5);  /* MASKBLUE | mm5 -> mm5 */
   5.524 +	                        pand_r2r(mm5, mm3); /* mm3 & mm5(!MASKRED) -> mm3 */
   5.525 +	                        por_r2r(mm6, mm3); /* save new reds in dsts */
   5.526 +	
   5.527 +	                        /* green */
   5.528 +	                        movq_r2r(mm2, mm5); /* src -> mm5 */
   5.529 +	                        pand_r2r(mm4 , mm5); /* src & MASKGREEN -> mm5 */
   5.530 +	                        psrlq_i2r(5, mm5); /* mm5 >> 5 -> mm5 [000g 000g 000g 000g] */
   5.531 +	
   5.532 +	                        movq_r2r(mm3, mm6); /* dst -> mm6 */
   5.533 +	                        pand_r2r(mm4 , mm6); /* dst & MASKGREEN -> mm6 */
   5.534 +	                        psrlq_i2r(5, mm6); /* mm6 >> 5 -> mm6 [000g 000g 000g 000g] */
   5.535 +	
   5.536 +	                        /* blend */
   5.537 +	                        psubw_r2r(mm6, mm5);/* src - dst -> mm5 */
   5.538 +	                        pmullw_r2r(mm0, mm5); /* mm5 * alpha -> mm5 */
   5.539 +	                        psrlw_i2r(8, mm5); /* mm5 >> 8 -> mm5 */
   5.540 +	                        paddw_r2r(mm5, mm6); /* mm5 + mm6(dst) -> mm6 */
   5.541 +	                        psllq_i2r(5, mm6); /* mm6 << 5 -> mm6 */
   5.542 +	                        pand_r2r(mm4, mm6); /* mm6 & MASKGREEN -> mm6 */
   5.543 +	
   5.544 +	                        movq_r2r(mm1, mm5); /* MASKRED -> mm5 */
   5.545 +	                        por_r2r(mm7, mm5);  /* MASKBLUE | mm5 -> mm5 */
   5.546 +	                        pand_r2r(mm5, mm3); /* mm3 & mm5(!MASKGREEN) -> mm3 */
   5.547 +	                        por_r2r(mm6, mm3); /* save new greens in dsts */
   5.548 +	
   5.549 +	                        /* blue */
   5.550 +	                        movq_r2r(mm2, mm5); /* src -> mm5 */
   5.551 +	                        pand_r2r(mm7 , mm5); /* src & MASKRED -> mm5[000b 000b 000b 000b] */
   5.552 +		
   5.553 +	                        movq_r2r(mm3, mm6); /* dst -> mm6 */
   5.554 +	                        pand_r2r(mm7 , mm6); /* dst & MASKBLUE -> mm6[000b 000b 000b 000b] */
   5.555 +	
   5.556 +	                        /* blend */
   5.557 +	                        psubw_r2r(mm6, mm5);/* src - dst -> mm5 */
   5.558 +	                        pmullw_r2r(mm0, mm5); /* mm5 * alpha -> mm5 */
   5.559 +	                        psrlw_i2r(8, mm5); /* mm5 >> 8 -> mm5 */
   5.560 +	                        paddw_r2r(mm5, mm6); /* mm5 + mm6(dst) -> mm6 */
   5.561 +	                        pand_r2r(mm7, mm6); /* mm6 & MASKBLUE -> mm6 */
   5.562 +	
   5.563 +	                        movq_r2r(mm1, mm5); /* MASKRED -> mm5 */
   5.564 +	                        por_r2r(mm4, mm5);  /* MASKGREEN | mm5 -> mm5 */
   5.565 +	                        pand_r2r(mm5, mm3); /* mm3 & mm5(!MASKBLUE) -> mm3 */
   5.566 +	                        por_r2r(mm6, mm3); /* save new blues in dsts */
   5.567 +	
   5.568 +	                        movq_r2m(mm3, *dstp);/* mm3 -> 4 dst pixels */
   5.569 +	
   5.570 +	                        srcp += 4;
   5.571 +	                        dstp += 4;
   5.572 +                        }, width);			
   5.573 +			srcp += srcskip;
   5.574 +			dstp += dstskip;
   5.575 +		}
   5.576 +		emms();
   5.577 +	}
   5.578 +}
   5.579 +
   5.580 +/* fast RGB555->RGB555 blending with surface alpha */
   5.581 +static void Blit555to555SurfaceAlphaMMX(SDL_BlitInfo *info)
   5.582 +{
   5.583 +	unsigned alpha = info->src->alpha; /* downscale alpha to 5 bits */
   5.584 +	if(alpha == 128) {
   5.585 +		Blit16to16SurfaceAlpha128(info, 0xfbde);
   5.586 +	} else {
   5.587 +		int width = info->d_width;
   5.588 +		int height = info->d_height;
   5.589 +		Uint16 *srcp = (Uint16 *)info->s_pixels;
   5.590 +		int srcskip = info->s_skip >> 1;
   5.591 +		Uint16 *dstp = (Uint16 *)info->d_pixels;
   5.592 +		int dstskip = info->d_skip >> 1;
   5.593 +	        Uint32 s, d;
   5.594 +	        Uint8 load[8];
   5.595 +	  
   5.596 +		alpha &= ~(1+2+4);		/* cut alpha to get the exact same behaviour */
   5.597 +	        *(Uint64 *)load = alpha;
   5.598 +		alpha >>= 3;		/* downscale alpha to 5 bits */
   5.599 +
   5.600 +                movq_m2r(*load, mm0); /* alpha(0000000A) -> mm0 */
   5.601 +                punpcklwd_r2r(mm0, mm0); /* 00000A0A -> mm0 */
   5.602 +                punpcklwd_r2r(mm0, mm0); /* 0A0A0A0A -> mm0 */
   5.603 +	  
   5.604 + 	        /* Setup the 555 color channel masks */
   5.605 +	        *(Uint64 *)load = 0x7C007C007C007C00;
   5.606 +		movq_m2r(*load, mm1); /* MASKRED -> mm1 */
   5.607 +		*(Uint64 *)load = 0x03E003E003E003E0;
   5.608 +		movq_m2r(*load, mm4); /* MASKGREEN -> mm4 */
   5.609 +		*(Uint64 *)load = 0x001F001F001F001F;
   5.610 +		movq_m2r(*load, mm7); /* MASKBLUE -> mm7 */
   5.611 +		while(height--) {
   5.612 +                        DUFFS_LOOP_QUATRO2(
   5.613 +                        {
   5.614 +	                        s = *srcp++;
   5.615 +				d = *dstp;
   5.616 +				/*
   5.617 +				 * shift out the middle component (green) to
   5.618 +				 * the high 16 bits, and process all three RGB
   5.619 +				 * components at the same time.
   5.620 +				 */
   5.621 +				s = (s | s << 16) & 0x03e07c1f;
   5.622 +				d = (d | d << 16) & 0x03e07c1f;
   5.623 +				d += (s - d) * alpha >> 5;
   5.624 +				d &= 0x03e07c1f;
   5.625 +				*dstp++ = d | d >> 16;
   5.626 +                        },{
   5.627 +	                        s = *srcp++;
   5.628 +				d = *dstp;
   5.629 +				/*
   5.630 +				 * shift out the middle component (green) to
   5.631 +				 * the high 16 bits, and process all three RGB
   5.632 +				 * components at the same time.
   5.633 +				 */
   5.634 +				s = (s | s << 16) & 0x03e07c1f;
   5.635 +				d = (d | d << 16) & 0x03e07c1f;
   5.636 +				d += (s - d) * alpha >> 5;
   5.637 +				d &= 0x03e07c1f;
   5.638 +				*dstp++ = d | d >> 16;
   5.639 +			        s = *srcp++;
   5.640 +				d = *dstp;
   5.641 +				/*
   5.642 +				 * shift out the middle component (green) to
   5.643 +				 * the high 16 bits, and process all three RGB
   5.644 +				 * components at the same time.
   5.645 +				 */
   5.646 +				s = (s | s << 16) & 0x03e07c1f;
   5.647 +				d = (d | d << 16) & 0x03e07c1f;
   5.648 +				d += (s - d) * alpha >> 5;
   5.649 +				d &= 0x03e07c1f;
   5.650 +				*dstp++ = d | d >> 16;
   5.651 +                        },{
   5.652 +	                        movq_m2r((*dstp), mm3);/* 4 dst pixels -> mm3 */
   5.653 +	                        movq_m2r((*srcp), mm2);/* 4 src pixels -> mm2 */
   5.654 +			  
   5.655 +	                        /* RED */
   5.656 +	                        movq_r2r(mm2, mm5); /* src -> mm5 */
   5.657 +	                        pand_r2r(mm1 , mm5); /* src & MASKRED -> mm5 */
   5.658 +	                        psrlq_i2r(10, mm5); /* mm5 >> 10 -> mm5 [000r 000r 000r 000r] */
   5.659 +	
   5.660 +	                        movq_r2r(mm3, mm6); /* dst -> mm6 */
   5.661 +	                        pand_r2r(mm1 , mm6); /* dst & MASKRED -> mm6 */
   5.662 +	                        psrlq_i2r(10, mm6); /* mm6 >> 10 -> mm6 [000r 000r 000r 000r] */
   5.663 +	
   5.664 +	                        /* blend */
   5.665 +	                        psubw_r2r(mm6, mm5);/* src - dst -> mm5 */
   5.666 +	                        pmullw_r2r(mm0, mm5); /* mm5 * alpha -> mm5 */
   5.667 +	                        psrlw_i2r(8, mm5); /* mm5 >> 8 -> mm5 */
   5.668 +	                        paddw_r2r(mm5, mm6); /* mm5 + mm6(dst) -> mm6 */
   5.669 +	                        psllq_i2r(10, mm6); /* mm6 << 10 -> mm6 */
   5.670 +	                        pand_r2r(mm1, mm6); /* mm6 & MASKRED -> mm6 */
   5.671 +	
   5.672 +	                        movq_r2r(mm4, mm5); /* MASKGREEN -> mm5 */
   5.673 +	                        por_r2r(mm7, mm5);  /* MASKBLUE | mm5 -> mm5 */
   5.674 +	                        pand_r2r(mm5, mm3); /* mm3 & mm5(!MASKRED) -> mm3 */
   5.675 +	                        por_r2r(mm6, mm3); /* save new reds in dsts */
   5.676 +	
   5.677 +	                        /* green */
   5.678 +	                        movq_r2r(mm2, mm5); /* src -> mm5 */
   5.679 +	                        pand_r2r(mm4 , mm5); /* src & MASKGREEN -> mm5 */
   5.680 +	                        psrlq_i2r(5, mm5); /* mm5 >> 5 -> mm5 [000g 000g 000g 000g] */
   5.681 +	
   5.682 +	                        movq_r2r(mm3, mm6); /* dst -> mm6 */
   5.683 +	                        pand_r2r(mm4 , mm6); /* dst & MASKGREEN -> mm6 */
   5.684 +	                        psrlq_i2r(5, mm6); /* mm6 >> 5 -> mm6 [000g 000g 000g 000g] */
   5.685 +	
   5.686 +	                        /* blend */
   5.687 +	                        psubw_r2r(mm6, mm5);/* src - dst -> mm5 */
   5.688 +	                        pmullw_r2r(mm0, mm5); /* mm5 * alpha -> mm5 */
   5.689 +	                        psrlw_i2r(8, mm5); /* mm5 >> 8 -> mm5 */
   5.690 +	                        paddw_r2r(mm5, mm6); /* mm5 + mm6(dst) -> mm6 */
   5.691 +	                        psllq_i2r(5, mm6); /* mm6 << 5 -> mm6 */
   5.692 +	                        pand_r2r(mm4, mm6); /* mm6 & MASKGREEN -> mm6 */
   5.693 +	
   5.694 +	                        movq_r2r(mm1, mm5); /* MASKRED -> mm5 */
   5.695 +	                        por_r2r(mm7, mm5);  /* MASKBLUE | mm5 -> mm5 */
   5.696 +	                        pand_r2r(mm5, mm3); /* mm3 & mm5(!MASKGREEN) -> mm3 */
   5.697 +	                        por_r2r(mm6, mm3); /* save new greens in dsts */
   5.698 +	
   5.699 +	                        /* blue */
   5.700 +	                        movq_r2r(mm2, mm5); /* src -> mm5 */
   5.701 +	                        pand_r2r(mm7 , mm5); /* src & MASKRED -> mm5[000b 000b 000b 000b] */
   5.702 +		
   5.703 +	                        movq_r2r(mm3, mm6); /* dst -> mm6 */
   5.704 +	                        pand_r2r(mm7 , mm6); /* dst & MASKBLUE -> mm6[000b 000b 000b 000b] */
   5.705 +	
   5.706 +	                        /* blend */
   5.707 +	                        psubw_r2r(mm6, mm5);/* src - dst -> mm5 */
   5.708 +	                        pmullw_r2r(mm0, mm5); /* mm5 * alpha -> mm5 */
   5.709 +	                        psrlw_i2r(8, mm5); /* mm5 >> 8 -> mm5 */
   5.710 +	                        paddw_r2r(mm5, mm6); /* mm5 + mm6(dst) -> mm6 */
   5.711 +	                        pand_r2r(mm7, mm6); /* mm6 & MASKBLUE -> mm6 */
   5.712 +	
   5.713 +	                        movq_r2r(mm1, mm5); /* MASKRED -> mm5 */
   5.714 +	                        por_r2r(mm4, mm5);  /* MASKGREEN | mm5 -> mm5 */
   5.715 +	                        pand_r2r(mm5, mm3); /* mm3 & mm5(!MASKBLUE) -> mm3 */
   5.716 +	                        por_r2r(mm6, mm3); /* save new blues in dsts */
   5.717 +	
   5.718 +	                        movq_r2m(mm3, *dstp);/* mm3 -> 4 dst pixels */
   5.719 +	
   5.720 +	                        srcp += 4;
   5.721 +	                        dstp += 4;
   5.722 +                        }, width);			
   5.723 +			srcp += srcskip;
   5.724 +			dstp += dstskip;
   5.725 +		}
   5.726 +		emms();
   5.727 +	}
   5.728 +}
   5.729 +#endif
   5.730 +
   5.731  /* fast RGB565->RGB565 blending with surface alpha */
   5.732  static void Blit565to565SurfaceAlpha(SDL_BlitInfo *info)
   5.733  {
   5.734 @@ -500,10 +1158,11 @@
   5.735  		   compositioning used (>>8 instead of /255) doesn't handle
   5.736  		   it correctly. Also special-case alpha=0 for speed?
   5.737  		   Benchmark this! */
   5.738 -		if(alpha == (SDL_ALPHA_OPAQUE >> 3)) {
   5.739 +		if(alpha) {   
   5.740 +		  if(alpha == (SDL_ALPHA_OPAQUE >> 3)) {
   5.741  		    *dstp = (s >> 8 & 0xf800) + (s >> 5 & 0x7e0)
   5.742  			  + (s >> 3  & 0x1f);
   5.743 -		} else {
   5.744 +		  } else {
   5.745  		    Uint32 d = *dstp;
   5.746  		    /*
   5.747  		     * convert source and destination to G0RAB65565
   5.748 @@ -515,6 +1174,7 @@
   5.749  		    d += (s - d) * alpha >> 5;
   5.750  		    d &= 0x07e0f81f;
   5.751  		    *dstp = d | d >> 16;
   5.752 +		  }
   5.753  		}
   5.754  		srcp++;
   5.755  		dstp++;
   5.756 @@ -543,10 +1203,11 @@
   5.757  		   compositioning used (>>8 instead of /255) doesn't handle
   5.758  		   it correctly. Also special-case alpha=0 for speed?
   5.759  		   Benchmark this! */
   5.760 -		if(alpha == (SDL_ALPHA_OPAQUE >> 3)) {
   5.761 +		if(alpha) {   
   5.762 +		  if(alpha == (SDL_ALPHA_OPAQUE >> 3)) {
   5.763  		    *dstp = (s >> 9 & 0x7c00) + (s >> 6 & 0x3e0)
   5.764  			  + (s >> 3  & 0x1f);
   5.765 -		} else {
   5.766 +		  } else {
   5.767  		    Uint32 d = *dstp;
   5.768  		    /*
   5.769  		     * convert source and destination to G0RAB65565
   5.770 @@ -558,6 +1219,7 @@
   5.771  		    d += (s - d) * alpha >> 5;
   5.772  		    d &= 0x03e07c1f;
   5.773  		    *dstp = d | d >> 16;
   5.774 +		  }
   5.775  		}
   5.776  		srcp++;
   5.777  		dstp++;
   5.778 @@ -583,7 +1245,8 @@
   5.779  	unsigned sA = srcfmt->alpha;
   5.780  	unsigned dA = dstfmt->Amask ? SDL_ALPHA_OPAQUE : 0;
   5.781  
   5.782 -	while ( height-- ) {
   5.783 +	if(sA) {
   5.784 +	  while ( height-- ) {
   5.785  	    DUFFS_LOOP4(
   5.786  	    {
   5.787  		Uint32 pixel;
   5.788 @@ -603,6 +1266,7 @@
   5.789  	    width);
   5.790  	    src += srcskip;
   5.791  	    dst += dstskip;
   5.792 +	  }
   5.793  	}
   5.794  }
   5.795  
   5.796 @@ -634,7 +1298,7 @@
   5.797  		unsigned dG;
   5.798  		unsigned dB;
   5.799  		RETRIEVE_RGB_PIXEL(src, srcbpp, pixel);
   5.800 -		if(pixel != ckey) {
   5.801 +		if(sA && pixel != ckey) {
   5.802  		    RGB_FROM_PIXEL(pixel, srcfmt, sR, sG, sB);
   5.803  		    DISEMBLE_RGB(dst, dstbpp, dstfmt, pixel, dR, dG, dB);
   5.804  		    ALPHA_BLEND(sR, sG, sB, sA, dR, dG, dB);
   5.805 @@ -686,9 +1350,11 @@
   5.806  		unsigned sA;
   5.807  		unsigned dA;
   5.808  		DISEMBLE_RGBA(src, srcbpp, srcfmt, pixel, sR, sG, sB, sA);
   5.809 -		DISEMBLE_RGBA(dst, dstbpp, dstfmt, pixel, dR, dG, dB, dA);
   5.810 -		ALPHA_BLEND(sR, sG, sB, sA, dR, dG, dB);
   5.811 -		ASSEMBLE_RGBA(dst, dstbpp, dstfmt, dR, dG, dB, dA);
   5.812 +		if(sA) {
   5.813 +		  DISEMBLE_RGBA(dst, dstbpp, dstfmt, pixel, dR, dG, dB, dA);
   5.814 +		  ALPHA_BLEND(sR, sG, sB, sA, dR, dG, dB);
   5.815 +		  ASSEMBLE_RGBA(dst, dstbpp, dstfmt, dR, dG, dB, dA);
   5.816 +		}
   5.817  		src += srcbpp;
   5.818  		dst += dstbpp;
   5.819  	    },
   5.820 @@ -719,9 +1385,23 @@
   5.821  	    case 2:
   5.822  		if(surface->map->identity) {
   5.823  		    if(df->Gmask == 0x7e0)
   5.824 +		    {
   5.825 +#if defined(i386) && defined(__GNUC__) && defined(USE_ASMBLIT)
   5.826 +		if((CPU_Flags()&MMX_CPU)!=0)
   5.827 +			return Blit565to565SurfaceAlphaMMX;
   5.828 +		else
   5.829 +#endif
   5.830  			return Blit565to565SurfaceAlpha;
   5.831 +		    }
   5.832  		    else if(df->Gmask == 0x3e0)
   5.833 +		    {
   5.834 +#if defined(i386) && defined(__GNUC__) && defined(USE_ASMBLIT)
   5.835 +		if((CPU_Flags()&MMX_CPU)!=0)
   5.836 +			return Blit555to555SurfaceAlphaMMX;
   5.837 +		else
   5.838 +#endif
   5.839  			return Blit555to555SurfaceAlpha;
   5.840 +		    }
   5.841  		}
   5.842  		return BlitNtoNSurfaceAlpha;
   5.843  
   5.844 @@ -731,7 +1411,14 @@
   5.845  		   && sf->Bmask == df->Bmask
   5.846  		   && (sf->Rmask | sf->Gmask | sf->Bmask) == 0xffffff
   5.847  		   && sf->BytesPerPixel == 4)
   5.848 +		{
   5.849 +#if defined(i386) && defined(__GNUC__) && defined(USE_ASMBLIT)
   5.850 +		if((CPU_Flags()&MMX_CPU)!=0)
   5.851 +		    return BlitRGBtoRGBSurfaceAlphaMMX;
   5.852 +		else
   5.853 +#endif
   5.854  		    return BlitRGBtoRGBSurfaceAlpha;
   5.855 +		}
   5.856  		else
   5.857  		    return BlitNtoNSurfaceAlpha;
   5.858  
   5.859 @@ -764,7 +1451,19 @@
   5.860  	       && sf->Gmask == df->Gmask
   5.861  	       && sf->Bmask == df->Bmask
   5.862  	       && sf->BytesPerPixel == 4)
   5.863 -		return BlitRGBtoRGBPixelAlpha;
   5.864 +	    {
   5.865 +#if defined(i386) && defined(__GNUC__) && defined(USE_ASMBLIT)
   5.866 +		Uint32 f;
   5.867 +		f=CPU_Flags();
   5.868 +		if((f&(TDNOW_CPU|MMX_CPU))==(TDNOW_CPU|MMX_CPU))
   5.869 +		    return BlitRGBtoRGBPixelAlphaMMX3DNOW;
   5.870 +		else
   5.871 +		if((f&MMX_CPU)!=0)
   5.872 +		    return BlitRGBtoRGBPixelAlphaMMX;
   5.873 +		else
   5.874 +#endif
   5.875 +		    return BlitRGBtoRGBPixelAlpha;
   5.876 +	    }
   5.877  	    return BlitNtoNPixelAlpha;
   5.878  
   5.879  	case 3:
     6.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     6.2 +++ b/src/video/mmx.h	Fri Aug 22 05:51:19 2003 +0000
     6.3 @@ -0,0 +1,706 @@
     6.4 +/*	mmx.h
     6.5 +
     6.6 +	MultiMedia eXtensions GCC interface library for IA32.
     6.7 +
     6.8 +	To use this library, simply include this header file
     6.9 +	and compile with GCC.  You MUST have inlining enabled
    6.10 +	in order for mmx_ok() to work; this can be done by
    6.11 +	simply using -O on the GCC command line.
    6.12 +
    6.13 +	Compiling with -DMMX_TRACE will cause detailed trace
    6.14 +	output to be sent to stderr for each mmx operation.
    6.15 +	This adds lots of code, and obviously slows execution to
    6.16 +	a crawl, but can be very useful for debugging.
    6.17 +
    6.18 +	THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY
    6.19 +	EXPRESS OR IMPLIED WARRANTIES, INCLUDING, WITHOUT
    6.20 +	LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTABILITY
    6.21 +	AND FITNESS FOR ANY PARTICULAR PURPOSE.
    6.22 +
    6.23 +	1997-99 by H. Dietz and R. Fisher
    6.24 +
    6.25 + Notes:
    6.26 +	It appears that the latest gas has the pand problem fixed, therefore
    6.27 +	  I'll undefine BROKEN_PAND by default.
    6.28 +*/
    6.29 +
    6.30 +#ifndef _MMX_H
    6.31 +#define _MMX_H
    6.32 +
    6.33 +
    6.34 +/*	Warning:  at this writing, the version of GAS packaged
    6.35 +	with most Linux distributions does not handle the
    6.36 +	parallel AND operation mnemonic correctly.  If the
    6.37 +	symbol BROKEN_PAND is defined, a slower alternative
    6.38 +	coding will be used.  If execution of mmxtest results
    6.39 +	in an illegal instruction fault, define this symbol.
    6.40 +*/
    6.41 +#undef	BROKEN_PAND
    6.42 +
    6.43 +
    6.44 +/*	The type of an value that fits in an MMX register
    6.45 +	(note that long long constant values MUST be suffixed
    6.46 +	 by LL and unsigned long long values by ULL, lest
    6.47 +	 they be truncated by the compiler)
    6.48 +*/
    6.49 +typedef	union {
    6.50 +	long long		q;	/* Quadword (64-bit) value */
    6.51 +	unsigned long long	uq;	/* Unsigned Quadword */
    6.52 +	int			d[2];	/* 2 Doubleword (32-bit) values */
    6.53 +	unsigned int		ud[2];	/* 2 Unsigned Doubleword */
    6.54 +	short			w[4];	/* 4 Word (16-bit) values */
    6.55 +	unsigned short		uw[4];	/* 4 Unsigned Word */
    6.56 +	char			b[8];	/* 8 Byte (8-bit) values */
    6.57 +	unsigned char		ub[8];	/* 8 Unsigned Byte */
    6.58 +	float			s[2];	/* Single-precision (32-bit) value */
    6.59 +} __attribute__ ((aligned (8))) mmx_t;	/* On an 8-byte (64-bit) boundary */
    6.60 +
    6.61 +
    6.62 +#if 0
    6.63 +/*	Function to test if multimedia instructions are supported...
    6.64 +*/
    6.65 +inline extern int
    6.66 +mm_support(void)
    6.67 +{
    6.68 +	/* Returns 1 if MMX instructions are supported,
    6.69 +	   3 if Cyrix MMX and Extended MMX instructions are supported
    6.70 +	   5 if AMD MMX and 3DNow! instructions are supported
    6.71 +	   0 if hardware does not support any of these
    6.72 +	*/
    6.73 +	register int rval = 0;
    6.74 +
    6.75 +	__asm__ __volatile__ (
    6.76 +		/* See if CPUID instruction is supported ... */
    6.77 +		/* ... Get copies of EFLAGS into eax and ecx */
    6.78 +		"pushf\n\t"
    6.79 +		"popl %%eax\n\t"
    6.80 +		"movl %%eax, %%ecx\n\t"
    6.81 +
    6.82 +		/* ... Toggle the ID bit in one copy and store */
    6.83 +		/*     to the EFLAGS reg */
    6.84 +		"xorl $0x200000, %%eax\n\t"
    6.85 +		"push %%eax\n\t"
    6.86 +		"popf\n\t"
    6.87 +
    6.88 +		/* ... Get the (hopefully modified) EFLAGS */
    6.89 +		"pushf\n\t"
    6.90 +		"popl %%eax\n\t"
    6.91 +
    6.92 +		/* ... Compare and test result */
    6.93 +		"xorl %%eax, %%ecx\n\t"
    6.94 +		"testl $0x200000, %%ecx\n\t"
    6.95 +		"jz NotSupported1\n\t"		/* CPUID not supported */
    6.96 +
    6.97 +
    6.98 +		/* Get standard CPUID information, and
    6.99 +		       go to a specific vendor section */
   6.100 +		"movl $0, %%eax\n\t"
   6.101 +		"cpuid\n\t"
   6.102 +
   6.103 +		/* Check for Intel */
   6.104 +		"cmpl $0x756e6547, %%ebx\n\t"
   6.105 +		"jne TryAMD\n\t"
   6.106 +		"cmpl $0x49656e69, %%edx\n\t"
   6.107 +		"jne TryAMD\n\t"
   6.108 +		"cmpl $0x6c65746e, %%ecx\n"
   6.109 +		"jne TryAMD\n\t"
   6.110 +		"jmp Intel\n\t"
   6.111 +
   6.112 +		/* Check for AMD */
   6.113 +		"\nTryAMD:\n\t"
   6.114 +		"cmpl $0x68747541, %%ebx\n\t"
   6.115 +		"jne TryCyrix\n\t"
   6.116 +		"cmpl $0x69746e65, %%edx\n\t"
   6.117 +		"jne TryCyrix\n\t"
   6.118 +		"cmpl $0x444d4163, %%ecx\n"
   6.119 +		"jne TryCyrix\n\t"
   6.120 +		"jmp AMD\n\t"
   6.121 +
   6.122 +		/* Check for Cyrix */
   6.123 +		"\nTryCyrix:\n\t"
   6.124 +		"cmpl $0x69727943, %%ebx\n\t"
   6.125 +		"jne NotSupported2\n\t"
   6.126 +		"cmpl $0x736e4978, %%edx\n\t"
   6.127 +		"jne NotSupported3\n\t"
   6.128 +		"cmpl $0x64616574, %%ecx\n\t"
   6.129 +		"jne NotSupported4\n\t"
   6.130 +		/* Drop through to Cyrix... */
   6.131 +
   6.132 +
   6.133 +		/* Cyrix Section */
   6.134 +		/* See if extended CPUID level 80000001 is supported */
   6.135 +		/* The value of CPUID/80000001 for the 6x86MX is undefined
   6.136 +		   according to the Cyrix CPU Detection Guide (Preliminary
   6.137 +		   Rev. 1.01 table 1), so we'll check the value of eax for
   6.138 +		   CPUID/0 to see if standard CPUID level 2 is supported.
   6.139 +		   According to the table, the only CPU which supports level
   6.140 +		   2 is also the only one which supports extended CPUID levels.
   6.141 +		*/
   6.142 +		"cmpl $0x2, %%eax\n\t"
   6.143 +		"jne MMXtest\n\t"	/* Use standard CPUID instead */
   6.144 +
   6.145 +		/* Extended CPUID supported (in theory), so get extended
   6.146 +		   features */
   6.147 +		"movl $0x80000001, %%eax\n\t"
   6.148 +		"cpuid\n\t"
   6.149 +		"testl $0x00800000, %%eax\n\t"	/* Test for MMX */
   6.150 +		"jz NotSupported5\n\t"		/* MMX not supported */
   6.151 +		"testl $0x01000000, %%eax\n\t"	/* Test for Ext'd MMX */
   6.152 +		"jnz EMMXSupported\n\t"
   6.153 +		"movl $1, %0:\n\n\t"		/* MMX Supported */
   6.154 +		"jmp Return\n\n"
   6.155 +		"EMMXSupported:\n\t"
   6.156 +		"movl $3, %0:\n\n\t"		/* EMMX and MMX Supported */
   6.157 +		"jmp Return\n\t"
   6.158 +
   6.159 +
   6.160 +		/* AMD Section */
   6.161 +		"AMD:\n\t"
   6.162 +
   6.163 +		/* See if extended CPUID is supported */
   6.164 +		"movl $0x80000000, %%eax\n\t"
   6.165 +		"cpuid\n\t"
   6.166 +		"cmpl $0x80000000, %%eax\n\t"
   6.167 +		"jl MMXtest\n\t"	/* Use standard CPUID instead */
   6.168 +
   6.169 +		/* Extended CPUID supported, so get extended features */
   6.170 +		"movl $0x80000001, %%eax\n\t"
   6.171 +		"cpuid\n\t"
   6.172 +		"testl $0x00800000, %%edx\n\t"	/* Test for MMX */
   6.173 +		"jz NotSupported6\n\t"		/* MMX not supported */
   6.174 +		"testl $0x80000000, %%edx\n\t"	/* Test for 3DNow! */
   6.175 +		"jnz ThreeDNowSupported\n\t"
   6.176 +		"movl $1, %0:\n\n\t"		/* MMX Supported */
   6.177 +		"jmp Return\n\n"
   6.178 +		"ThreeDNowSupported:\n\t"
   6.179 +		"movl $5, %0:\n\n\t"		/* 3DNow! and MMX Supported */
   6.180 +		"jmp Return\n\t"
   6.181 +
   6.182 +
   6.183 +		/* Intel Section */
   6.184 +		"Intel:\n\t"
   6.185 +
   6.186 +		/* Check for MMX */
   6.187 +		"MMXtest:\n\t"
   6.188 +		"movl $1, %%eax\n\t"
   6.189 +		"cpuid\n\t"
   6.190 +		"testl $0x00800000, %%edx\n\t"	/* Test for MMX */
   6.191 +		"jz NotSupported7\n\t"		/* MMX Not supported */
   6.192 +		"movl $1, %0:\n\n\t"		/* MMX Supported */
   6.193 +		"jmp Return\n\t"
   6.194 +
   6.195 +		/* Nothing supported */
   6.196 +		"\nNotSupported1:\n\t"
   6.197 +		"#movl $101, %0:\n\n\t"
   6.198 +		"\nNotSupported2:\n\t"
   6.199 +		"#movl $102, %0:\n\n\t"
   6.200 +		"\nNotSupported3:\n\t"
   6.201 +		"#movl $103, %0:\n\n\t"
   6.202 +		"\nNotSupported4:\n\t"
   6.203 +		"#movl $104, %0:\n\n\t"
   6.204 +		"\nNotSupported5:\n\t"
   6.205 +		"#movl $105, %0:\n\n\t"
   6.206 +		"\nNotSupported6:\n\t"
   6.207 +		"#movl $106, %0:\n\n\t"
   6.208 +		"\nNotSupported7:\n\t"
   6.209 +		"#movl $107, %0:\n\n\t"
   6.210 +		"movl $0, %0:\n\n\t"
   6.211 +
   6.212 +		"Return:\n\t"
   6.213 +		: "=a" (rval)
   6.214 +		: /* no input */
   6.215 +		: "eax", "ebx", "ecx", "edx"
   6.216 +	);
   6.217 +
   6.218 +	/* Return */
   6.219 +	return(rval);
   6.220 +}
   6.221 +
   6.222 +/*	Function to test if mmx instructions are supported...
   6.223 +*/
   6.224 +inline extern int
   6.225 +mmx_ok(void)
   6.226 +{
   6.227 +	/* Returns 1 if MMX instructions are supported, 0 otherwise */
   6.228 +	return ( mm_support() & 0x1 );
   6.229 +}
   6.230 +#endif
   6.231 +
   6.232 +/*	Helper functions for the instruction macros that follow...
   6.233 +	(note that memory-to-register, m2r, instructions are nearly
   6.234 +	 as efficient as register-to-register, r2r, instructions;
   6.235 +	 however, memory-to-memory instructions are really simulated
   6.236 +	 as a convenience, and are only 1/3 as efficient)
   6.237 +*/
   6.238 +#ifdef	MMX_TRACE
   6.239 +
   6.240 +/*	Include the stuff for printing a trace to stderr...
   6.241 +*/
   6.242 +
   6.243 +#include <stdio.h>
   6.244 +
   6.245 +#define	mmx_i2r(op, imm, reg) \
   6.246 +	{ \
   6.247 +		mmx_t mmx_trace; \
   6.248 +		mmx_trace.uq = (imm); \
   6.249 +		printf(#op "_i2r(" #imm "=0x%08x%08x, ", \
   6.250 +			mmx_trace.d[1], mmx_trace.d[0]); \
   6.251 +		__asm__ __volatile__ ("movq %%" #reg ", %0" \
   6.252 +				      : "=X" (mmx_trace) \
   6.253 +				      : /* nothing */ ); \
   6.254 +		printf(#reg "=0x%08x%08x) => ", \
   6.255 +			mmx_trace.d[1], mmx_trace.d[0]); \
   6.256 +		__asm__ __volatile__ (#op " %0, %%" #reg \
   6.257 +				      : /* nothing */ \
   6.258 +				      : "X" (imm)); \
   6.259 +		__asm__ __volatile__ ("movq %%" #reg ", %0" \
   6.260 +				      : "=X" (mmx_trace) \
   6.261 +				      : /* nothing */ ); \
   6.262 +		printf(#reg "=0x%08x%08x\n", \
   6.263 +			mmx_trace.d[1], mmx_trace.d[0]); \
   6.264 +	}
   6.265 +
   6.266 +#define	mmx_m2r(op, mem, reg) \
   6.267 +	{ \
   6.268 +		mmx_t mmx_trace; \
   6.269 +		mmx_trace = (mem); \
   6.270 +		printf(#op "_m2r(" #mem "=0x%08x%08x, ", \
   6.271 +			mmx_trace.d[1], mmx_trace.d[0]); \
   6.272 +		__asm__ __volatile__ ("movq %%" #reg ", %0" \
   6.273 +				      : "=X" (mmx_trace) \
   6.274 +				      : /* nothing */ ); \
   6.275 +		printf(#reg "=0x%08x%08x) => ", \
   6.276 +			mmx_trace.d[1], mmx_trace.d[0]); \
   6.277 +		__asm__ __volatile__ (#op " %0, %%" #reg \
   6.278 +				      : /* nothing */ \
   6.279 +				      : "X" (mem)); \
   6.280 +		__asm__ __volatile__ ("movq %%" #reg ", %0" \
   6.281 +				      : "=X" (mmx_trace) \
   6.282 +				      : /* nothing */ ); \
   6.283 +		printf(#reg "=0x%08x%08x\n", \
   6.284 +			mmx_trace.d[1], mmx_trace.d[0]); \
   6.285 +	}
   6.286 +
   6.287 +#define	mmx_r2m(op, reg, mem) \
   6.288 +	{ \
   6.289 +		mmx_t mmx_trace; \
   6.290 +		__asm__ __volatile__ ("movq %%" #reg ", %0" \
   6.291 +				      : "=X" (mmx_trace) \
   6.292 +				      : /* nothing */ ); \
   6.293 +		printf(#op "_r2m(" #reg "=0x%08x%08x, ", \
   6.294 +			mmx_trace.d[1], mmx_trace.d[0]); \
   6.295 +		mmx_trace = (mem); \
   6.296 +		printf(#mem "=0x%08x%08x) => ", \
   6.297 +			mmx_trace.d[1], mmx_trace.d[0]); \
   6.298 +		__asm__ __volatile__ (#op " %%" #reg ", %0" \
   6.299 +				      : "=X" (mem) \
   6.300 +				      : /* nothing */ ); \
   6.301 +		mmx_trace = (mem); \
   6.302 +		printf(#mem "=0x%08x%08x\n", \
   6.303 +			mmx_trace.d[1], mmx_trace.d[0]); \
   6.304 +	}
   6.305 +
   6.306 +#define	mmx_r2r(op, regs, regd) \
   6.307 +	{ \
   6.308 +		mmx_t mmx_trace; \
   6.309 +		__asm__ __volatile__ ("movq %%" #regs ", %0" \
   6.310 +				      : "=X" (mmx_trace) \
   6.311 +				      : /* nothing */ ); \
   6.312 +		printf(#op "_r2r(" #regs "=0x%08x%08x, ", \
   6.313 +			mmx_trace.d[1], mmx_trace.d[0]); \
   6.314 +		__asm__ __volatile__ ("movq %%" #regd ", %0" \
   6.315 +				      : "=X" (mmx_trace) \
   6.316 +				      : /* nothing */ ); \
   6.317 +		printf(#regd "=0x%08x%08x) => ", \
   6.318 +			mmx_trace.d[1], mmx_trace.d[0]); \
   6.319 +		__asm__ __volatile__ (#op " %" #regs ", %" #regd); \
   6.320 +		__asm__ __volatile__ ("movq %%" #regd ", %0" \
   6.321 +				      : "=X" (mmx_trace) \
   6.322 +				      : /* nothing */ ); \
   6.323 +		printf(#regd "=0x%08x%08x\n", \
   6.324 +			mmx_trace.d[1], mmx_trace.d[0]); \
   6.325 +	}
   6.326 +
   6.327 +#define	mmx_m2m(op, mems, memd) \
   6.328 +	{ \
   6.329 +		mmx_t mmx_trace; \
   6.330 +		mmx_trace = (mems); \
   6.331 +		printf(#op "_m2m(" #mems "=0x%08x%08x, ", \
   6.332 +			mmx_trace.d[1], mmx_trace.d[0]); \
   6.333 +		mmx_trace = (memd); \
   6.334 +		printf(#memd "=0x%08x%08x) => ", \
   6.335 +			mmx_trace.d[1], mmx_trace.d[0]); \
   6.336 +		__asm__ __volatile__ ("movq %0, %%mm0\n\t" \
   6.337 +				      #op " %1, %%mm0\n\t" \
   6.338 +				      "movq %%mm0, %0" \
   6.339 +				      : "=X" (memd) \
   6.340 +				      : "X" (mems)); \
   6.341 +		mmx_trace = (memd); \
   6.342 +		printf(#memd "=0x%08x%08x\n", \
   6.343 +			mmx_trace.d[1], mmx_trace.d[0]); \
   6.344 +	}
   6.345 +
   6.346 +#else
   6.347 +
   6.348 +/*	These macros are a lot simpler without the tracing...
   6.349 +*/
   6.350 +
   6.351 +#define	mmx_i2r(op, imm, reg) \
   6.352 +	__asm__ __volatile__ (#op " %0, %%" #reg \
   6.353 +			      : /* nothing */ \
   6.354 +			      : "X" (imm) )
   6.355 +
   6.356 +#define	mmx_m2r(op, mem, reg) \
   6.357 +	__asm__ __volatile__ (#op " %0, %%" #reg \
   6.358 +			      : /* nothing */ \
   6.359 +			      : "X" (mem))
   6.360 +
   6.361 +#define	mmx_r2m(op, reg, mem) \
   6.362 +	__asm__ __volatile__ (#op " %%" #reg ", %0" \
   6.363 +			      : "=X" (mem) \
   6.364 +			      : /* nothing */ )
   6.365 +
   6.366 +#define	mmx_r2r(op, regs, regd) \
   6.367 +	__asm__ __volatile__ (#op " %" #regs ", %" #regd)
   6.368 +
   6.369 +#define	mmx_m2m(op, mems, memd) \
   6.370 +	__asm__ __volatile__ ("movq %0, %%mm0\n\t" \
   6.371 +			      #op " %1, %%mm0\n\t" \
   6.372 +			      "movq %%mm0, %0" \
   6.373 +			      : "=X" (memd) \
   6.374 +			      : "X" (mems))
   6.375 +
   6.376 +#endif
   6.377 +
   6.378 +
   6.379 +/*	1x64 MOVe Quadword
   6.380 +	(this is both a load and a store...
   6.381 +	 in fact, it is the only way to store)
   6.382 +*/
   6.383 +#define	movq_m2r(var, reg)	mmx_m2r(movq, var, reg)
   6.384 +#define	movq_r2m(reg, var)	mmx_r2m(movq, reg, var)
   6.385 +#define	movq_r2r(regs, regd)	mmx_r2r(movq, regs, regd)
   6.386 +#define	movq(vars, vard) \
   6.387 +	__asm__ __volatile__ ("movq %1, %%mm0\n\t" \
   6.388 +			      "movq %%mm0, %0" \
   6.389 +			      : "=X" (vard) \
   6.390 +			      : "X" (vars))
   6.391 +
   6.392 +
   6.393 +/*	1x32 MOVe Doubleword
   6.394 +	(like movq, this is both load and store...
   6.395 +	 but is most useful for moving things between
   6.396 +	 mmx registers and ordinary registers)
   6.397 +*/
   6.398 +#define	movd_m2r(var, reg)	mmx_m2r(movd, var, reg)
   6.399 +#define	movd_r2m(reg, var)	mmx_r2m(movd, reg, var)
   6.400 +#define	movd_r2r(regs, regd)	mmx_r2r(movd, regs, regd)
   6.401 +#define	movd(vars, vard) \
   6.402 +	__asm__ __volatile__ ("movd %1, %%mm0\n\t" \
   6.403 +			      "movd %%mm0, %0" \
   6.404 +			      : "=X" (vard) \
   6.405 +			      : "X" (vars))
   6.406 +
   6.407 +
   6.408 +/*	2x32, 4x16, and 8x8 Parallel ADDs
   6.409 +*/
   6.410 +#define	paddd_m2r(var, reg)	mmx_m2r(paddd, var, reg)
   6.411 +#define	paddd_r2r(regs, regd)	mmx_r2r(paddd, regs, regd)
   6.412 +#define	paddd(vars, vard)	mmx_m2m(paddd, vars, vard)
   6.413 +
   6.414 +#define	paddw_m2r(var, reg)	mmx_m2r(paddw, var, reg)
   6.415 +#define	paddw_r2r(regs, regd)	mmx_r2r(paddw, regs, regd)
   6.416 +#define	paddw(vars, vard)	mmx_m2m(paddw, vars, vard)
   6.417 +
   6.418 +#define	paddb_m2r(var, reg)	mmx_m2r(paddb, var, reg)
   6.419 +#define	paddb_r2r(regs, regd)	mmx_r2r(paddb, regs, regd)
   6.420 +#define	paddb(vars, vard)	mmx_m2m(paddb, vars, vard)
   6.421 +
   6.422 +
   6.423 +/*	4x16 and 8x8 Parallel ADDs using Saturation arithmetic
   6.424 +*/
   6.425 +#define	paddsw_m2r(var, reg)	mmx_m2r(paddsw, var, reg)
   6.426 +#define	paddsw_r2r(regs, regd)	mmx_r2r(paddsw, regs, regd)
   6.427 +#define	paddsw(vars, vard)	mmx_m2m(paddsw, vars, vard)
   6.428 +
   6.429 +#define	paddsb_m2r(var, reg)	mmx_m2r(paddsb, var, reg)
   6.430 +#define	paddsb_r2r(regs, regd)	mmx_r2r(paddsb, regs, regd)
   6.431 +#define	paddsb(vars, vard)	mmx_m2m(paddsb, vars, vard)
   6.432 +
   6.433 +
   6.434 +/*	4x16 and 8x8 Parallel ADDs using Unsigned Saturation arithmetic
   6.435 +*/
   6.436 +#define	paddusw_m2r(var, reg)	mmx_m2r(paddusw, var, reg)
   6.437 +#define	paddusw_r2r(regs, regd)	mmx_r2r(paddusw, regs, regd)
   6.438 +#define	paddusw(vars, vard)	mmx_m2m(paddusw, vars, vard)
   6.439 +
   6.440 +#define	paddusb_m2r(var, reg)	mmx_m2r(paddusb, var, reg)
   6.441 +#define	paddusb_r2r(regs, regd)	mmx_r2r(paddusb, regs, regd)
   6.442 +#define	paddusb(vars, vard)	mmx_m2m(paddusb, vars, vard)
   6.443 +
   6.444 +
   6.445 +/*	2x32, 4x16, and 8x8 Parallel SUBs
   6.446 +*/
   6.447 +#define	psubd_m2r(var, reg)	mmx_m2r(psubd, var, reg)
   6.448 +#define	psubd_r2r(regs, regd)	mmx_r2r(psubd, regs, regd)
   6.449 +#define	psubd(vars, vard)	mmx_m2m(psubd, vars, vard)
   6.450 +
   6.451 +#define	psubw_m2r(var, reg)	mmx_m2r(psubw, var, reg)
   6.452 +#define	psubw_r2r(regs, regd)	mmx_r2r(psubw, regs, regd)
   6.453 +#define	psubw(vars, vard)	mmx_m2m(psubw, vars, vard)
   6.454 +
   6.455 +#define	psubb_m2r(var, reg)	mmx_m2r(psubb, var, reg)
   6.456 +#define	psubb_r2r(regs, regd)	mmx_r2r(psubb, regs, regd)
   6.457 +#define	psubb(vars, vard)	mmx_m2m(psubb, vars, vard)
   6.458 +
   6.459 +
   6.460 +/*	4x16 and 8x8 Parallel SUBs using Saturation arithmetic
   6.461 +*/
   6.462 +#define	psubsw_m2r(var, reg)	mmx_m2r(psubsw, var, reg)
   6.463 +#define	psubsw_r2r(regs, regd)	mmx_r2r(psubsw, regs, regd)
   6.464 +#define	psubsw(vars, vard)	mmx_m2m(psubsw, vars, vard)
   6.465 +
   6.466 +#define	psubsb_m2r(var, reg)	mmx_m2r(psubsb, var, reg)
   6.467 +#define	psubsb_r2r(regs, regd)	mmx_r2r(psubsb, regs, regd)
   6.468 +#define	psubsb(vars, vard)	mmx_m2m(psubsb, vars, vard)
   6.469 +
   6.470 +
   6.471 +/*	4x16 and 8x8 Parallel SUBs using Unsigned Saturation arithmetic
   6.472 +*/
   6.473 +#define	psubusw_m2r(var, reg)	mmx_m2r(psubusw, var, reg)
   6.474 +#define	psubusw_r2r(regs, regd)	mmx_r2r(psubusw, regs, regd)
   6.475 +#define	psubusw(vars, vard)	mmx_m2m(psubusw, vars, vard)
   6.476 +
   6.477 +#define	psubusb_m2r(var, reg)	mmx_m2r(psubusb, var, reg)
   6.478 +#define	psubusb_r2r(regs, regd)	mmx_r2r(psubusb, regs, regd)
   6.479 +#define	psubusb(vars, vard)	mmx_m2m(psubusb, vars, vard)
   6.480 +
   6.481 +
   6.482 +/*	4x16 Parallel MULs giving Low 4x16 portions of results
   6.483 +*/
   6.484 +#define	pmullw_m2r(var, reg)	mmx_m2r(pmullw, var, reg)
   6.485 +#define	pmullw_r2r(regs, regd)	mmx_r2r(pmullw, regs, regd)
   6.486 +#define	pmullw(vars, vard)	mmx_m2m(pmullw, vars, vard)
   6.487 +
   6.488 +
   6.489 +/*	4x16 Parallel MULs giving High 4x16 portions of results
   6.490 +*/
   6.491 +#define	pmulhw_m2r(var, reg)	mmx_m2r(pmulhw, var, reg)
   6.492 +#define	pmulhw_r2r(regs, regd)	mmx_r2r(pmulhw, regs, regd)
   6.493 +#define	pmulhw(vars, vard)	mmx_m2m(pmulhw, vars, vard)
   6.494 +
   6.495 +
   6.496 +/*	4x16->2x32 Parallel Mul-ADD
   6.497 +	(muls like pmullw, then adds adjacent 16-bit fields
   6.498 +	 in the multiply result to make the final 2x32 result)
   6.499 +*/
   6.500 +#define	pmaddwd_m2r(var, reg)	mmx_m2r(pmaddwd, var, reg)
   6.501 +#define	pmaddwd_r2r(regs, regd)	mmx_r2r(pmaddwd, regs, regd)
   6.502 +#define	pmaddwd(vars, vard)	mmx_m2m(pmaddwd, vars, vard)
   6.503 +
   6.504 +
   6.505 +/*	1x64 bitwise AND
   6.506 +*/
   6.507 +#ifdef	BROKEN_PAND
   6.508 +#define	pand_m2r(var, reg) \
   6.509 +	{ \
   6.510 +		mmx_m2r(pandn, (mmx_t) -1LL, reg); \
   6.511 +		mmx_m2r(pandn, var, reg); \
   6.512 +	}
   6.513 +#define	pand_r2r(regs, regd) \
   6.514 +	{ \
   6.515 +		mmx_m2r(pandn, (mmx_t) -1LL, regd); \
   6.516 +		mmx_r2r(pandn, regs, regd) \
   6.517 +	}
   6.518 +#define	pand(vars, vard) \
   6.519 +	{ \
   6.520 +		movq_m2r(vard, mm0); \
   6.521 +		mmx_m2r(pandn, (mmx_t) -1LL, mm0); \
   6.522 +		mmx_m2r(pandn, vars, mm0); \
   6.523 +		movq_r2m(mm0, vard); \
   6.524 +	}
   6.525 +#else
   6.526 +#define	pand_m2r(var, reg)	mmx_m2r(pand, var, reg)
   6.527 +#define	pand_r2r(regs, regd)	mmx_r2r(pand, regs, regd)
   6.528 +#define	pand(vars, vard)	mmx_m2m(pand, vars, vard)
   6.529 +#endif
   6.530 +
   6.531 +
   6.532 +/*	1x64 bitwise AND with Not the destination
   6.533 +*/
   6.534 +#define	pandn_m2r(var, reg)	mmx_m2r(pandn, var, reg)
   6.535 +#define	pandn_r2r(regs, regd)	mmx_r2r(pandn, regs, regd)
   6.536 +#define	pandn(vars, vard)	mmx_m2m(pandn, vars, vard)
   6.537 +
   6.538 +
   6.539 +/*	1x64 bitwise OR
   6.540 +*/
   6.541 +#define	por_m2r(var, reg)	mmx_m2r(por, var, reg)
   6.542 +#define	por_r2r(regs, regd)	mmx_r2r(por, regs, regd)
   6.543 +#define	por(vars, vard)	mmx_m2m(por, vars, vard)
   6.544 +
   6.545 +
   6.546 +/*	1x64 bitwise eXclusive OR
   6.547 +*/
   6.548 +#define	pxor_m2r(var, reg)	mmx_m2r(pxor, var, reg)
   6.549 +#define	pxor_r2r(regs, regd)	mmx_r2r(pxor, regs, regd)
   6.550 +#define	pxor(vars, vard)	mmx_m2m(pxor, vars, vard)
   6.551 +
   6.552 +
   6.553 +/*	2x32, 4x16, and 8x8 Parallel CoMPare for EQuality
   6.554 +	(resulting fields are either 0 or -1)
   6.555 +*/
   6.556 +#define	pcmpeqd_m2r(var, reg)	mmx_m2r(pcmpeqd, var, reg)
   6.557 +#define	pcmpeqd_r2r(regs, regd)	mmx_r2r(pcmpeqd, regs, regd)
   6.558 +#define	pcmpeqd(vars, vard)	mmx_m2m(pcmpeqd, vars, vard)
   6.559 +
   6.560 +#define	pcmpeqw_m2r(var, reg)	mmx_m2r(pcmpeqw, var, reg)
   6.561 +#define	pcmpeqw_r2r(regs, regd)	mmx_r2r(pcmpeqw, regs, regd)
   6.562 +#define	pcmpeqw(vars, vard)	mmx_m2m(pcmpeqw, vars, vard)
   6.563 +
   6.564 +#define	pcmpeqb_m2r(var, reg)	mmx_m2r(pcmpeqb, var, reg)
   6.565 +#define	pcmpeqb_r2r(regs, regd)	mmx_r2r(pcmpeqb, regs, regd)
   6.566 +#define	pcmpeqb(vars, vard)	mmx_m2m(pcmpeqb, vars, vard)
   6.567 +
   6.568 +
   6.569 +/*	2x32, 4x16, and 8x8 Parallel CoMPare for Greater Than
   6.570 +	(resulting fields are either 0 or -1)
   6.571 +*/
   6.572 +#define	pcmpgtd_m2r(var, reg)	mmx_m2r(pcmpgtd, var, reg)
   6.573 +#define	pcmpgtd_r2r(regs, regd)	mmx_r2r(pcmpgtd, regs, regd)
   6.574 +#define	pcmpgtd(vars, vard)	mmx_m2m(pcmpgtd, vars, vard)
   6.575 +
   6.576 +#define	pcmpgtw_m2r(var, reg)	mmx_m2r(pcmpgtw, var, reg)
   6.577 +#define	pcmpgtw_r2r(regs, regd)	mmx_r2r(pcmpgtw, regs, regd)
   6.578 +#define	pcmpgtw(vars, vard)	mmx_m2m(pcmpgtw, vars, vard)
   6.579 +
   6.580 +#define	pcmpgtb_m2r(var, reg)	mmx_m2r(pcmpgtb, var, reg)
   6.581 +#define	pcmpgtb_r2r(regs, regd)	mmx_r2r(pcmpgtb, regs, regd)
   6.582 +#define	pcmpgtb(vars, vard)	mmx_m2m(pcmpgtb, vars, vard)
   6.583 +
   6.584 +
   6.585 +/*	1x64, 2x32, and 4x16 Parallel Shift Left Logical
   6.586 +*/
   6.587 +#define	psllq_i2r(imm, reg)	mmx_i2r(psllq, imm, reg)
   6.588 +#define	psllq_m2r(var, reg)	mmx_m2r(psllq, var, reg)
   6.589 +#define	psllq_r2r(regs, regd)	mmx_r2r(psllq, regs, regd)
   6.590 +#define	psllq(vars, vard)	mmx_m2m(psllq, vars, vard)
   6.591 +
   6.592 +#define	pslld_i2r(imm, reg)	mmx_i2r(pslld, imm, reg)
   6.593 +#define	pslld_m2r(var, reg)	mmx_m2r(pslld, var, reg)
   6.594 +#define	pslld_r2r(regs, regd)	mmx_r2r(pslld, regs, regd)
   6.595 +#define	pslld(vars, vard)	mmx_m2m(pslld, vars, vard)
   6.596 +
   6.597 +#define	psllw_i2r(imm, reg)	mmx_i2r(psllw, imm, reg)
   6.598 +#define	psllw_m2r(var, reg)	mmx_m2r(psllw, var, reg)
   6.599 +#define	psllw_r2r(regs, regd)	mmx_r2r(psllw, regs, regd)
   6.600 +#define	psllw(vars, vard)	mmx_m2m(psllw, vars, vard)
   6.601 +
   6.602 +
   6.603 +/*	1x64, 2x32, and 4x16 Parallel Shift Right Logical
   6.604 +*/
   6.605 +#define	psrlq_i2r(imm, reg)	mmx_i2r(psrlq, imm, reg)
   6.606 +#define	psrlq_m2r(var, reg)	mmx_m2r(psrlq, var, reg)
   6.607 +#define	psrlq_r2r(regs, regd)	mmx_r2r(psrlq, regs, regd)
   6.608 +#define	psrlq(vars, vard)	mmx_m2m(psrlq, vars, vard)
   6.609 +
   6.610 +#define	psrld_i2r(imm, reg)	mmx_i2r(psrld, imm, reg)
   6.611 +#define	psrld_m2r(var, reg)	mmx_m2r(psrld, var, reg)
   6.612 +#define	psrld_r2r(regs, regd)	mmx_r2r(psrld, regs, regd)
   6.613 +#define	psrld(vars, vard)	mmx_m2m(psrld, vars, vard)
   6.614 +
   6.615 +#define	psrlw_i2r(imm, reg)	mmx_i2r(psrlw, imm, reg)
   6.616 +#define	psrlw_m2r(var, reg)	mmx_m2r(psrlw, var, reg)
   6.617 +#define	psrlw_r2r(regs, regd)	mmx_r2r(psrlw, regs, regd)
   6.618 +#define	psrlw(vars, vard)	mmx_m2m(psrlw, vars, vard)
   6.619 +
   6.620 +
   6.621 +/*	2x32 and 4x16 Parallel Shift Right Arithmetic
   6.622 +*/
   6.623 +#define	psrad_i2r(imm, reg)	mmx_i2r(psrad, imm, reg)
   6.624 +#define	psrad_m2r(var, reg)	mmx_m2r(psrad, var, reg)
   6.625 +#define	psrad_r2r(regs, regd)	mmx_r2r(psrad, regs, regd)
   6.626 +#define	psrad(vars, vard)	mmx_m2m(psrad, vars, vard)
   6.627 +
   6.628 +#define	psraw_i2r(imm, reg)	mmx_i2r(psraw, imm, reg)
   6.629 +#define	psraw_m2r(var, reg)	mmx_m2r(psraw, var, reg)
   6.630 +#define	psraw_r2r(regs, regd)	mmx_r2r(psraw, regs, regd)
   6.631 +#define	psraw(vars, vard)	mmx_m2m(psraw, vars, vard)
   6.632 +
   6.633 +
   6.634 +/*	2x32->4x16 and 4x16->8x8 PACK and Signed Saturate
   6.635 +	(packs source and dest fields into dest in that order)
   6.636 +*/
   6.637 +#define	packssdw_m2r(var, reg)	mmx_m2r(packssdw, var, reg)
   6.638 +#define	packssdw_r2r(regs, regd) mmx_r2r(packssdw, regs, regd)
   6.639 +#define	packssdw(vars, vard)	mmx_m2m(packssdw, vars, vard)
   6.640 +
   6.641 +#define	packsswb_m2r(var, reg)	mmx_m2r(packsswb, var, reg)
   6.642 +#define	packsswb_r2r(regs, regd) mmx_r2r(packsswb, regs, regd)
   6.643 +#define	packsswb(vars, vard)	mmx_m2m(packsswb, vars, vard)
   6.644 +
   6.645 +
   6.646 +/*	4x16->8x8 PACK and Unsigned Saturate
   6.647 +	(packs source and dest fields into dest in that order)
   6.648 +*/
   6.649 +#define	packuswb_m2r(var, reg)	mmx_m2r(packuswb, var, reg)
   6.650 +#define	packuswb_r2r(regs, regd) mmx_r2r(packuswb, regs, regd)
   6.651 +#define	packuswb(vars, vard)	mmx_m2m(packuswb, vars, vard)
   6.652 +
   6.653 +
   6.654 +/*	2x32->1x64, 4x16->2x32, and 8x8->4x16 UNPaCK Low
   6.655 +	(interleaves low half of dest with low half of source
   6.656 +	 as padding in each result field)
   6.657 +*/
   6.658 +#define	punpckldq_m2r(var, reg)	mmx_m2r(punpckldq, var, reg)
   6.659 +#define	punpckldq_r2r(regs, regd) mmx_r2r(punpckldq, regs, regd)
   6.660 +#define	punpckldq(vars, vard)	mmx_m2m(punpckldq, vars, vard)
   6.661 +
   6.662 +#define	punpcklwd_m2r(var, reg)	mmx_m2r(punpcklwd, var, reg)
   6.663 +#define	punpcklwd_r2r(regs, regd) mmx_r2r(punpcklwd, regs, regd)
   6.664 +#define	punpcklwd(vars, vard)	mmx_m2m(punpcklwd, vars, vard)
   6.665 +
   6.666 +#define	punpcklbw_m2r(var, reg)	mmx_m2r(punpcklbw, var, reg)
   6.667 +#define	punpcklbw_r2r(regs, regd) mmx_r2r(punpcklbw, regs, regd)
   6.668 +#define	punpcklbw(vars, vard)	mmx_m2m(punpcklbw, vars, vard)
   6.669 +
   6.670 +
   6.671 +/*	2x32->1x64, 4x16->2x32, and 8x8->4x16 UNPaCK High
   6.672 +	(interleaves high half of dest with high half of source
   6.673 +	 as padding in each result field)
   6.674 +*/
   6.675 +#define	punpckhdq_m2r(var, reg)	mmx_m2r(punpckhdq, var, reg)
   6.676 +#define	punpckhdq_r2r(regs, regd) mmx_r2r(punpckhdq, regs, regd)
   6.677 +#define	punpckhdq(vars, vard)	mmx_m2m(punpckhdq, vars, vard)
   6.678 +
   6.679 +#define	punpckhwd_m2r(var, reg)	mmx_m2r(punpckhwd, var, reg)
   6.680 +#define	punpckhwd_r2r(regs, regd) mmx_r2r(punpckhwd, regs, regd)
   6.681 +#define	punpckhwd(vars, vard)	mmx_m2m(punpckhwd, vars, vard)
   6.682 +
   6.683 +#define	punpckhbw_m2r(var, reg)	mmx_m2r(punpckhbw, var, reg)
   6.684 +#define	punpckhbw_r2r(regs, regd) mmx_r2r(punpckhbw, regs, regd)
   6.685 +#define	punpckhbw(vars, vard)	mmx_m2m(punpckhbw, vars, vard)
   6.686 +
   6.687 +
   6.688 +/*	Empty MMx State
   6.689 +	(used to clean-up when going from mmx to float use
   6.690 +	 of the registers that are shared by both; note that
   6.691 +	 there is no float-to-mmx operation needed, because
   6.692 +	 only the float tag word info is corruptible)
   6.693 +*/
   6.694 +#ifdef	MMX_TRACE
   6.695 +
   6.696 +#define	emms() \
   6.697 +	{ \
   6.698 +		printf("emms()\n"); \
   6.699 +		__asm__ __volatile__ ("emms"); \
   6.700 +	}
   6.701 +
   6.702 +#else
   6.703 +
   6.704 +#define	emms()			__asm__ __volatile__ ("emms")
   6.705 +
   6.706 +#endif
   6.707 +
   6.708 +#endif
   6.709 +