Fixed strict aliasing (or inline asm?) issue. SDL-1.2
authorRyan C. Gordon <icculus@icculus.org>
Tue, 29 Sep 2009 04:03:58 +0000
branchSDL-1.2
changeset 4262800f3cb78e45
parent 4261 0530394b5830
child 4263 3c12d2e84bcb
Fixed strict aliasing (or inline asm?) issue.

Some versions of GCC need this fix or alpha blending is broken.

Fixes Bugzilla #648.
src/video/SDL_blit_A.c
     1.1 --- a/src/video/SDL_blit_A.c	Tue Sep 29 00:37:36 2009 +0000
     1.2 +++ b/src/video/SDL_blit_A.c	Tue Sep 29 04:03:58 2009 +0000
     1.3 @@ -234,12 +234,12 @@
     1.4  	Uint32 *dstp = (Uint32 *)info->d_pixels;
     1.5  	int dstskip = info->d_skip >> 2;
     1.6  	Uint32 dalpha = info->dst->Amask;
     1.7 -	Uint8 load[8];
     1.8 +	Uint64 load;
     1.9  
    1.10 -	*(Uint64 *)load = 0x00fefefe00fefefeULL;/* alpha128 mask */
    1.11 -	movq_m2r(*load, mm4); /* alpha128 mask -> mm4 */
    1.12 -	*(Uint64 *)load = 0x0001010100010101ULL;/* !alpha128 mask */
    1.13 -	movq_m2r(*load, mm3); /* !alpha128 mask -> mm3 */
    1.14 +	load = 0x00fefefe00fefefeULL;/* alpha128 mask */
    1.15 +	movq_m2r(load, mm4); /* alpha128 mask -> mm4 */
    1.16 +	load = 0x0001010100010101ULL;/* !alpha128 mask */
    1.17 +	movq_m2r(load, mm3); /* !alpha128 mask -> mm3 */
    1.18  	movd_m2r(dalpha, mm7); /* dst alpha mask */
    1.19  	punpckldq_r2r(mm7, mm7); /* dst alpha mask | dst alpha mask -> mm7 */
    1.20  	while(height--) {
    1.21 @@ -1883,13 +1883,13 @@
    1.22  		Uint16 *dstp = (Uint16 *)info->d_pixels;
    1.23  		int dstskip = info->d_skip >> 1;
    1.24  		Uint32 s, d;
    1.25 -		Uint8 load[8];
    1.26 +		Uint64 load;
    1.27  	  
    1.28  		alpha &= ~(1+2+4);		/* cut alpha to get the exact same behaviour */
    1.29 -		*(Uint64 *)load = alpha;
    1.30 +		load = alpha;
    1.31  		alpha >>= 3;		/* downscale alpha to 5 bits */
    1.32  
    1.33 -		movq_m2r(*load, mm0); /* alpha(0000000A) -> mm0 */
    1.34 +		movq_m2r(load, mm0); /* alpha(0000000A) -> mm0 */
    1.35  		punpcklwd_r2r(mm0, mm0); /* 00000A0A -> mm0 */
    1.36  		punpcklwd_r2r(mm0, mm0); /* 0A0A0A0A -> mm0 */
    1.37  		/* position alpha to allow for mullo and mulhi on diff channels
    1.38 @@ -1897,10 +1897,10 @@
    1.39  		psllq_i2r(3, mm0);
    1.40  	  
    1.41  		/* Setup the 565 color channel masks */
    1.42 -		*(Uint64 *)load = 0x07E007E007E007E0ULL;
    1.43 -		movq_m2r(*load, mm4); /* MASKGREEN -> mm4 */
    1.44 -		*(Uint64 *)load = 0x001F001F001F001FULL;
    1.45 -		movq_m2r(*load, mm7); /* MASKBLUE -> mm7 */
    1.46 +		load = 0x07E007E007E007E0ULL;
    1.47 +		movq_m2r(load, mm4); /* MASKGREEN -> mm4 */
    1.48 +		load = 0x001F001F001F001FULL;
    1.49 +		movq_m2r(load, mm7); /* MASKBLUE -> mm7 */
    1.50  		while(height--) {
    1.51  			DUFFS_LOOP_QUATRO2(
    1.52  			{
    1.53 @@ -2022,13 +2022,13 @@
    1.54  		Uint16 *dstp = (Uint16 *)info->d_pixels;
    1.55  		int dstskip = info->d_skip >> 1;
    1.56  		Uint32 s, d;
    1.57 -		Uint8 load[8];
    1.58 +		Uint64 load;
    1.59  	  
    1.60  		alpha &= ~(1+2+4);		/* cut alpha to get the exact same behaviour */
    1.61 -		*(Uint64 *)load = alpha;
    1.62 +		load = alpha;
    1.63  		alpha >>= 3;		/* downscale alpha to 5 bits */
    1.64  
    1.65 -		movq_m2r(*load, mm0); /* alpha(0000000A) -> mm0 */
    1.66 +		movq_m2r(load, mm0); /* alpha(0000000A) -> mm0 */
    1.67  		punpcklwd_r2r(mm0, mm0); /* 00000A0A -> mm0 */
    1.68  		punpcklwd_r2r(mm0, mm0); /* 0A0A0A0A -> mm0 */
    1.69  		/* position alpha to allow for mullo and mulhi on diff channels
    1.70 @@ -2036,10 +2036,10 @@
    1.71  		psllq_i2r(3, mm0);
    1.72  
    1.73  		/* Setup the 555 color channel masks */
    1.74 -		*(Uint64 *)load = 0x03E003E003E003E0ULL;
    1.75 -		movq_m2r(*load, mm4); /* MASKGREEN -> mm4 */
    1.76 -		*(Uint64 *)load = 0x001F001F001F001FULL;
    1.77 -		movq_m2r(*load, mm7); /* MASKBLUE -> mm7 */
    1.78 +		load = 0x03E003E003E003E0ULL;
    1.79 +		movq_m2r(load, mm4); /* MASKGREEN -> mm4 */
    1.80 +		load = 0x001F001F001F001FULL;
    1.81 +		movq_m2r(load, mm7); /* MASKBLUE -> mm7 */
    1.82  		while(height--) {
    1.83  			DUFFS_LOOP_QUATRO2(
    1.84  			{