src/video/SDL_blit_A.c
author Ryan C. Gordon <icculus@icculus.org>
Thu, 20 Oct 2005 06:55:26 +0000
changeset 1162 2651158f59b8
parent 1047 ffaaf7ecf685
child 1175 867f521591e5
permissions -rw-r--r--
Enable altivec blitters on PowerPC Linux, and some fixes for recent
GCCs versions.
slouken@0
     1
/*
slouken@0
     2
    SDL - Simple DirectMedia Layer
slouken@769
     3
    Copyright (C) 1997-2004 Sam Lantinga
slouken@0
     4
slouken@0
     5
    This library is free software; you can redistribute it and/or
slouken@0
     6
    modify it under the terms of the GNU Library General Public
slouken@0
     7
    License as published by the Free Software Foundation; either
slouken@0
     8
    version 2 of the License, or (at your option) any later version.
slouken@0
     9
slouken@0
    10
    This library is distributed in the hope that it will be useful,
slouken@0
    11
    but WITHOUT ANY WARRANTY; without even the implied warranty of
slouken@0
    12
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
slouken@0
    13
    Library General Public License for more details.
slouken@0
    14
slouken@0
    15
    You should have received a copy of the GNU Library General Public
slouken@0
    16
    License along with this library; if not, write to the Free
slouken@0
    17
    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
slouken@0
    18
slouken@0
    19
    Sam Lantinga
slouken@252
    20
    slouken@libsdl.org
slouken@0
    21
*/
slouken@0
    22
slouken@0
    23
#ifdef SAVE_RCSID
slouken@0
    24
static char rcsid =
slouken@0
    25
 "@(#) $Id$";
slouken@0
    26
#endif
slouken@0
    27
slouken@0
    28
#include <stdio.h>
slouken@0
    29
slouken@0
    30
#include "SDL_types.h"
slouken@0
    31
#include "SDL_video.h"
slouken@0
    32
#include "SDL_blit.h"
slouken@0
    33
slouken@880
    34
#if (defined(i386) || defined(__x86_64__)) && defined(__GNUC__) && defined(USE_ASMBLIT)
slouken@880
    35
#define MMX_ASMBLIT
slouken@880
    36
#endif
slouken@880
    37
slouken@739
    38
/* Function to check the CPU flags */
slouken@739
    39
#include "SDL_cpuinfo.h"
icculus@1047
    40
#ifdef MMX_ASMBLIT
slouken@689
    41
#include "mmx.h"
slouken@689
    42
#endif
slouken@689
    43
slouken@0
    44
/* Functions to perform alpha blended blitting */
slouken@0
    45
slouken@0
    46
/* N->1 blending with per-surface alpha */
slouken@0
    47
static void BlitNto1SurfaceAlpha(SDL_BlitInfo *info)
slouken@0
    48
{
slouken@0
    49
	int width = info->d_width;
slouken@0
    50
	int height = info->d_height;
slouken@0
    51
	Uint8 *src = info->s_pixels;
slouken@0
    52
	int srcskip = info->s_skip;
slouken@0
    53
	Uint8 *dst = info->d_pixels;
slouken@0
    54
	int dstskip = info->d_skip;
slouken@0
    55
	Uint8 *palmap = info->table;
slouken@0
    56
	SDL_PixelFormat *srcfmt = info->src;
slouken@0
    57
	SDL_PixelFormat *dstfmt = info->dst;
slouken@0
    58
	int srcbpp = srcfmt->BytesPerPixel;
slouken@0
    59
slouken@0
    60
	const unsigned A = srcfmt->alpha;
slouken@0
    61
slouken@0
    62
	while ( height-- ) {
slouken@0
    63
	    DUFFS_LOOP4(
slouken@0
    64
	    {
icculus@1162
    65
		Uint32 Pixel;
slouken@0
    66
		unsigned sR;
slouken@0
    67
		unsigned sG;
slouken@0
    68
		unsigned sB;
slouken@0
    69
		unsigned dR;
slouken@0
    70
		unsigned dG;
slouken@0
    71
		unsigned dB;
icculus@1162
    72
		DISEMBLE_RGB(src, srcbpp, srcfmt, Pixel, sR, sG, sB);
slouken@0
    73
		dR = dstfmt->palette->colors[*dst].r;
slouken@0
    74
		dG = dstfmt->palette->colors[*dst].g;
slouken@0
    75
		dB = dstfmt->palette->colors[*dst].b;
slouken@0
    76
		ALPHA_BLEND(sR, sG, sB, A, dR, dG, dB);
slouken@0
    77
		dR &= 0xff;
slouken@0
    78
		dG &= 0xff;
slouken@0
    79
		dB &= 0xff;
slouken@0
    80
		/* Pack RGB into 8bit pixel */
slouken@0
    81
		if ( palmap == NULL ) {
slouken@0
    82
		    *dst =((dR>>5)<<(3+2))|
slouken@0
    83
			  ((dG>>5)<<(2))|
slouken@0
    84
			  ((dB>>6)<<(0));
slouken@0
    85
		} else {
slouken@0
    86
		    *dst = palmap[((dR>>5)<<(3+2))|
slouken@0
    87
				  ((dG>>5)<<(2))  |
slouken@0
    88
				  ((dB>>6)<<(0))];
slouken@0
    89
		}
slouken@0
    90
		dst++;
slouken@0
    91
		src += srcbpp;
slouken@0
    92
	    },
slouken@0
    93
	    width);
slouken@0
    94
	    src += srcskip;
slouken@0
    95
	    dst += dstskip;
slouken@0
    96
	}
slouken@0
    97
}
slouken@0
    98
slouken@0
    99
/* N->1 blending with pixel alpha */
slouken@0
   100
static void BlitNto1PixelAlpha(SDL_BlitInfo *info)
slouken@0
   101
{
slouken@0
   102
	int width = info->d_width;
slouken@0
   103
	int height = info->d_height;
slouken@0
   104
	Uint8 *src = info->s_pixels;
slouken@0
   105
	int srcskip = info->s_skip;
slouken@0
   106
	Uint8 *dst = info->d_pixels;
slouken@0
   107
	int dstskip = info->d_skip;
slouken@0
   108
	Uint8 *palmap = info->table;
slouken@0
   109
	SDL_PixelFormat *srcfmt = info->src;
slouken@0
   110
	SDL_PixelFormat *dstfmt = info->dst;
slouken@0
   111
	int srcbpp = srcfmt->BytesPerPixel;
slouken@0
   112
slouken@0
   113
	/* FIXME: fix alpha bit field expansion here too? */
slouken@0
   114
	while ( height-- ) {
slouken@0
   115
	    DUFFS_LOOP4(
slouken@0
   116
	    {
icculus@1162
   117
		Uint32 Pixel;
slouken@0
   118
		unsigned sR;
slouken@0
   119
		unsigned sG;
slouken@0
   120
		unsigned sB;
slouken@0
   121
		unsigned sA;
slouken@0
   122
		unsigned dR;
slouken@0
   123
		unsigned dG;
slouken@0
   124
		unsigned dB;
icculus@1162
   125
		DISEMBLE_RGBA(src,srcbpp,srcfmt,Pixel,sR,sG,sB,sA);
slouken@0
   126
		dR = dstfmt->palette->colors[*dst].r;
slouken@0
   127
		dG = dstfmt->palette->colors[*dst].g;
slouken@0
   128
		dB = dstfmt->palette->colors[*dst].b;
slouken@0
   129
		ALPHA_BLEND(sR, sG, sB, sA, dR, dG, dB);
slouken@0
   130
		dR &= 0xff;
slouken@0
   131
		dG &= 0xff;
slouken@0
   132
		dB &= 0xff;
slouken@0
   133
		/* Pack RGB into 8bit pixel */
slouken@0
   134
		if ( palmap == NULL ) {
slouken@0
   135
		    *dst =((dR>>5)<<(3+2))|
slouken@0
   136
			  ((dG>>5)<<(2))|
slouken@0
   137
			  ((dB>>6)<<(0));
slouken@0
   138
		} else {
slouken@0
   139
		    *dst = palmap[((dR>>5)<<(3+2))|
slouken@0
   140
				  ((dG>>5)<<(2))  |
slouken@0
   141
				  ((dB>>6)<<(0))  ];
slouken@0
   142
		}
slouken@0
   143
		dst++;
slouken@0
   144
		src += srcbpp;
slouken@0
   145
	    },
slouken@0
   146
	    width);
slouken@0
   147
	    src += srcskip;
slouken@0
   148
	    dst += dstskip;
slouken@0
   149
	}
slouken@0
   150
}
slouken@0
   151
slouken@0
   152
/* colorkeyed N->1 blending with per-surface alpha */
slouken@0
   153
static void BlitNto1SurfaceAlphaKey(SDL_BlitInfo *info)
slouken@0
   154
{
slouken@0
   155
	int width = info->d_width;
slouken@0
   156
	int height = info->d_height;
slouken@0
   157
	Uint8 *src = info->s_pixels;
slouken@0
   158
	int srcskip = info->s_skip;
slouken@0
   159
	Uint8 *dst = info->d_pixels;
slouken@0
   160
	int dstskip = info->d_skip;
slouken@0
   161
	Uint8 *palmap = info->table;
slouken@0
   162
	SDL_PixelFormat *srcfmt = info->src;
slouken@0
   163
	SDL_PixelFormat *dstfmt = info->dst;
slouken@0
   164
	int srcbpp = srcfmt->BytesPerPixel;
slouken@0
   165
	Uint32 ckey = srcfmt->colorkey;
slouken@0
   166
slouken@0
   167
	const int A = srcfmt->alpha;
slouken@0
   168
slouken@0
   169
	while ( height-- ) {
slouken@0
   170
	    DUFFS_LOOP(
slouken@0
   171
	    {
icculus@1162
   172
		Uint32 Pixel;
slouken@0
   173
		unsigned sR;
slouken@0
   174
		unsigned sG;
slouken@0
   175
		unsigned sB;
slouken@0
   176
		unsigned dR;
slouken@0
   177
		unsigned dG;
slouken@0
   178
		unsigned dB;
icculus@1162
   179
		DISEMBLE_RGB(src, srcbpp, srcfmt, Pixel, sR, sG, sB);
icculus@1162
   180
		if ( Pixel != ckey ) {
slouken@0
   181
		    dR = dstfmt->palette->colors[*dst].r;
slouken@0
   182
		    dG = dstfmt->palette->colors[*dst].g;
slouken@0
   183
		    dB = dstfmt->palette->colors[*dst].b;
slouken@0
   184
		    ALPHA_BLEND(sR, sG, sB, A, dR, dG, dB);
slouken@0
   185
		    dR &= 0xff;
slouken@0
   186
		    dG &= 0xff;
slouken@0
   187
		    dB &= 0xff;
slouken@0
   188
		    /* Pack RGB into 8bit pixel */
slouken@0
   189
		    if ( palmap == NULL ) {
slouken@0
   190
			*dst =((dR>>5)<<(3+2))|
slouken@0
   191
			      ((dG>>5)<<(2)) |
slouken@0
   192
			      ((dB>>6)<<(0));
slouken@0
   193
		    } else {
slouken@0
   194
			*dst = palmap[((dR>>5)<<(3+2))|
slouken@0
   195
				      ((dG>>5)<<(2))  |
slouken@0
   196
				      ((dB>>6)<<(0))  ];
slouken@0
   197
		    }
slouken@0
   198
		}
slouken@0
   199
		dst++;
slouken@0
   200
		src += srcbpp;
slouken@0
   201
	    },
slouken@0
   202
	    width);
slouken@0
   203
	    src += srcskip;
slouken@0
   204
	    dst += dstskip;
slouken@0
   205
	}
slouken@0
   206
}
slouken@0
   207
slouken@880
   208
#ifdef MMX_ASMBLIT
slouken@689
   209
/* fast RGB888->(A)RGB888 blending with surface alpha=128 special case */
slouken@689
   210
static void BlitRGBtoRGBSurfaceAlpha128MMX(SDL_BlitInfo *info)
slouken@689
   211
{
slouken@689
   212
	int width = info->d_width;
slouken@689
   213
	int height = info->d_height;
slouken@689
   214
	Uint32 *srcp = (Uint32 *)info->s_pixels;
slouken@689
   215
	int srcskip = info->s_skip >> 2;
slouken@689
   216
	Uint32 *dstp = (Uint32 *)info->d_pixels;
slouken@689
   217
	int dstskip = info->d_skip >> 2;
slouken@689
   218
        Uint8 load[8];
slouken@689
   219
  
slouken@720
   220
        *(Uint64 *)load = 0x00fefefe00fefefeULL;/* alpha128 mask */
slouken@689
   221
        movq_m2r(*load, mm4); /* alpha128 mask -> mm4 */
slouken@720
   222
        *(Uint64 *)load = 0x0001010100010101ULL;/* !alpha128 mask */
slouken@689
   223
        movq_m2r(*load, mm3); /* !alpha128 mask -> mm3 */
slouken@720
   224
        *(Uint64 *)load = 0xFF000000FF000000ULL;/* dst alpha mask */
slouken@689
   225
        movq_m2r(*load, mm7); /* dst alpha mask -> mm7 */
slouken@689
   226
	while(height--) {
slouken@689
   227
            DUFFS_LOOP_DOUBLE2(
slouken@689
   228
            {
slouken@689
   229
		    Uint32 s = *srcp++;
slouken@689
   230
		    Uint32 d = *dstp;
slouken@689
   231
		    *dstp++ = ((((s & 0x00fefefe) + (d & 0x00fefefe)) >> 1)
slouken@689
   232
			       + (s & d & 0x00010101)) | 0xff000000;
slouken@689
   233
            },{
slouken@689
   234
	            movq_m2r((*dstp), mm2);/* 2 x dst -> mm2(ARGBARGB) */
slouken@689
   235
	            movq_r2r(mm2, mm6); /* 2 x dst -> mm6(ARGBARGB) */
slouken@689
   236
	      
slouken@689
   237
	            movq_m2r((*srcp), mm1);/* 2 x src -> mm1(ARGBARGB) */
slouken@689
   238
	            movq_r2r(mm1, mm5); /* 2 x src -> mm5(ARGBARGB) */
slouken@689
   239
		
slouken@689
   240
	            pand_r2r(mm4, mm6); /* dst & mask -> mm6 */
slouken@689
   241
	            pand_r2r(mm4, mm5); /* src & mask -> mm5 */
slouken@689
   242
	            paddd_r2r(mm6, mm5); /* mm6 + mm5 -> mm5 */
slouken@689
   243
	            psrld_i2r(1, mm5); /* mm5 >> 1 -> mm5 */
slouken@689
   244
	
slouken@689
   245
	            pand_r2r(mm1, mm2); /* src & dst -> mm2 */
slouken@689
   246
	            pand_r2r(mm3, mm2); /* mm2 & !mask -> mm2 */
slouken@689
   247
	            paddd_r2r(mm5, mm2); /* mm5 + mm2 -> mm2 */
slouken@689
   248
	            por_r2r(mm7, mm2); /* mm7(full alpha) | mm2 -> mm2 */
slouken@689
   249
	            movq_r2m(mm2, (*dstp));/* mm2 -> 2 x dst pixels */
slouken@689
   250
	            dstp += 2;
slouken@689
   251
	            srcp += 2;
slouken@689
   252
            }, width);
slouken@689
   253
	    srcp += srcskip;
slouken@689
   254
	    dstp += dstskip;
slouken@689
   255
	}
slouken@689
   256
	emms();
slouken@689
   257
}
slouken@689
   258
slouken@689
   259
/* fast RGB888->(A)RGB888 blending with surface alpha */
slouken@689
   260
static void BlitRGBtoRGBSurfaceAlphaMMX(SDL_BlitInfo *info)
slouken@689
   261
{
slouken@689
   262
	unsigned alpha = info->src->alpha;
slouken@689
   263
	if(alpha == 128) {
slouken@689
   264
		BlitRGBtoRGBSurfaceAlpha128MMX(info);
slouken@689
   265
	} else {
slouken@689
   266
		int width = info->d_width;
slouken@689
   267
		int height = info->d_height;
slouken@689
   268
		Uint32 *srcp = (Uint32 *)info->s_pixels;
slouken@689
   269
		int srcskip = info->s_skip >> 2;
slouken@689
   270
		Uint32 *dstp = (Uint32 *)info->d_pixels;
slouken@689
   271
		int dstskip = info->d_skip >> 2;
slouken@689
   272
                Uint8 load[8] = {alpha, alpha, alpha, alpha,
slouken@689
   273
    					alpha, alpha, alpha, alpha};
slouken@689
   274
					
slouken@689
   275
                movq_m2r(*load, mm4); /* alpha -> mm4 */
slouken@720
   276
		*(Uint64 *)load = 0x00FF00FF00FF00FFULL;
slouken@689
   277
                movq_m2r(*load, mm3); /* mask -> mm3 */
slouken@689
   278
		pand_r2r(mm3, mm4); /* mm4 & mask -> 0A0A0A0A -> mm4 */
slouken@720
   279
		*(Uint64 *)load = 0xFF000000FF000000ULL;/* dst alpha mask */
slouken@689
   280
		movq_m2r(*load, mm7); /* dst alpha mask -> mm7 */
slouken@689
   281
		
slouken@689
   282
		while(height--) {
slouken@689
   283
			DUFFS_LOOP_DOUBLE2({
slouken@689
   284
				/* One Pixel Blend */
slouken@689
   285
	                        movd_m2r((*srcp), mm1);/* src(ARGB) -> mm1 (0000ARGB)*/
slouken@689
   286
                                punpcklbw_r2r(mm1, mm1); /* AARRGGBB -> mm1 */
slouken@689
   287
                                pand_r2r(mm3, mm1); /* 0A0R0G0B -> mm1 */
slouken@689
   288
			  
slouken@689
   289
	                        movd_m2r((*dstp), mm2);/* dst(ARGB) -> mm2 (0000ARGB)*/
slouken@689
   290
			        movq_r2r(mm2, mm6);/* dst(ARGB) -> mm6 (0000ARGB)*/
slouken@689
   291
                                punpcklbw_r2r(mm2, mm2); /* AARRGGBB -> mm2 */
slouken@689
   292
                                pand_r2r(mm3, mm2); /* 0A0R0G0B -> mm2 */
slouken@689
   293
			  
slouken@689
   294
                                psubw_r2r(mm2, mm1);/* src - dst -> mm1 */
slouken@689
   295
	                        pmullw_r2r(mm4, mm1); /* mm1 * alpha -> mm1 */
slouken@689
   296
	                        psrlw_i2r(8, mm1); /* mm1 >> 8 -> mm1 */
slouken@689
   297
	                        paddw_r2r(mm1, mm2); /* mm1 + mm2(dst) -> mm2 */
slouken@689
   298
	                        pand_r2r(mm3, mm2); /* 0A0R0G0B -> mm2 */
slouken@689
   299
	                        packuswb_r2r(mm2, mm2);  /* ARGBARGB -> mm2 */
slouken@689
   300
	                        por_r2r(mm7, mm2); /* mm7(full alpha) | mm2 -> mm2 */
icculus@1162
   301
			        movd_r2m(mm2, *dstp);/* mm2 -> Pixel */
slouken@689
   302
				++srcp;
slouken@689
   303
				++dstp;
slouken@689
   304
			},{
slouken@689
   305
			        /* Two Pixels Blend */
slouken@689
   306
				movq_m2r((*srcp), mm0);/* 2 x src -> mm0(ARGBARGB)*/
slouken@689
   307
			        movq_r2r(mm0, mm1); /* 2 x src -> mm1(ARGBARGB) */
slouken@689
   308
                                punpcklbw_r2r(mm0, mm0); /* low - AARRGGBB -> mm0 */
slouken@689
   309
			        pand_r2r(mm3, mm0); /* 0A0R0G0B -> mm0(src1) */
slouken@689
   310
			        punpckhbw_r2r(mm1, mm1); /* high - AARRGGBB -> mm1 */
slouken@689
   311
	                        pand_r2r(mm3, mm1); /* 0A0R0G0B -> mm1(src2) */
slouken@689
   312
	
slouken@689
   313
	                        movq_m2r((*dstp), mm2);/* 2 x dst -> mm2(ARGBARGB) */
slouken@689
   314
	                        movq_r2r(mm2, mm5); /* 2 x dst -> mm5(ARGBARGB) */
slouken@689
   315
			        movq_r2r(mm2, mm6); /* 2 x dst -> mm6(ARGBARGB) */
slouken@689
   316
                                punpcklbw_r2r(mm2, mm2); /* low - AARRGGBB -> mm2 */
slouken@689
   317
	                        punpckhbw_r2r(mm6, mm6); /* high - AARRGGBB -> mm6 */
slouken@689
   318
                                pand_r2r(mm3, mm2); /* 0A0R0G0B -> mm2(dst1) */
slouken@689
   319
	                  
slouken@689
   320
                                psubw_r2r(mm2, mm0);/* src1 - dst1 -> mm0 */
slouken@689
   321
	                        pmullw_r2r(mm4, mm0); /* mm0 * alpha -> mm0 */
slouken@689
   322
			        pand_r2r(mm3, mm6); /* 0A0R0G0B -> mm6(dst2) */
slouken@689
   323
			        psrlw_i2r(8, mm0); /* mm0 >> 8 -> mm1 */
slouken@689
   324
			        psubw_r2r(mm6, mm1);/* src2 - dst2 -> mm1 */
slouken@689
   325
	                        pmullw_r2r(mm4, mm1); /* mm1 * alpha -> mm1 */
slouken@689
   326
				paddw_r2r(mm0, mm2); /* mm0 + mm2(dst1) -> mm2 */
slouken@689
   327
	                        psrlw_i2r(8, mm1); /* mm1 >> 8 -> mm0 */
slouken@689
   328
				pand_r2r(mm3, mm2); /* 0A0R0G0B -> mm2 */
slouken@689
   329
	                        paddw_r2r(mm1, mm6); /* mm1 + mm6(dst2) -> mm6 */
slouken@689
   330
	                        pand_r2r(mm3, mm6); /* 0A0R0G0B -> mm6 */
slouken@689
   331
	                        packuswb_r2r(mm2, mm2);  /* ARGBARGB -> mm2 */
slouken@689
   332
	                        packuswb_r2r(mm6, mm6);  /* ARGBARGB -> mm6 */
slouken@689
   333
	                        psrlq_i2r(32, mm2); /* mm2 >> 32 -> mm2 */
slouken@689
   334
	                        psllq_i2r(32, mm6); /* mm6 << 32 -> mm6 */
slouken@689
   335
	                        por_r2r(mm6, mm2); /* mm6 | mm2 -> mm2 */				
slouken@689
   336
				por_r2r(mm7, mm2); /* mm7(full alpha) | mm2 -> mm2 */
icculus@1162
   337
                                movq_r2m(mm2, *dstp);/* mm2 -> 2 x Pixel */
slouken@689
   338
				srcp += 2;
slouken@689
   339
				dstp += 2;
slouken@689
   340
			}, width);
slouken@689
   341
			srcp += srcskip;
slouken@689
   342
			dstp += dstskip;
slouken@689
   343
		}
slouken@689
   344
		emms();
slouken@689
   345
	}
slouken@689
   346
}
slouken@689
   347
slouken@689
   348
/* fast ARGB888->(A)RGB888 blending with pixel alpha */
slouken@689
   349
static void BlitRGBtoRGBPixelAlphaMMX(SDL_BlitInfo *info)
slouken@689
   350
{
slouken@689
   351
	int width = info->d_width;
slouken@689
   352
	int height = info->d_height;
slouken@689
   353
	Uint32 *srcp = (Uint32 *)info->s_pixels;
slouken@689
   354
	int srcskip = info->s_skip >> 2;
slouken@689
   355
	Uint32 *dstp = (Uint32 *)info->d_pixels;
slouken@689
   356
	int dstskip = info->d_skip >> 2;
slouken@689
   357
        Uint32 alpha = 0;
slouken@689
   358
        Uint8 load[8];
slouken@689
   359
	                
slouken@720
   360
	*(Uint64 *)load = 0x00FF00FF00FF00FFULL;
slouken@689
   361
        movq_m2r(*load, mm3); /* mask -> mm2 */
slouken@720
   362
	*(Uint64 *)load = 0x00FF000000000000ULL;
slouken@689
   363
        movq_m2r(*load, mm7); /* dst alpha mask -> mm2 */
slouken@720
   364
        *(Uint64 *)load = 0x00FFFFFF00FFFFFFULL;
slouken@689
   365
        movq_m2r(*load, mm0); /* alpha 255 mask -> mm0 */
slouken@720
   366
        *(Uint64 *)load = 0xFF000000FF000000ULL;
slouken@689
   367
        movq_m2r(*load, mm6); /* alpha 255 !mask -> mm6 */
slouken@689
   368
	while(height--) {
slouken@689
   369
	    DUFFS_LOOP4({
slouken@689
   370
	        alpha = *srcp;
slouken@689
   371
	        alpha >>= 24;
slouken@689
   372
		/* FIXME: Here we special-case opaque alpha since the
slouken@689
   373
		   compositioning used (>>8 instead of /255) doesn't handle
slouken@689
   374
		   it correctly. Also special-case alpha=0 for speed?
slouken@689
   375
		   Benchmark this! */
slouken@689
   376
		if(alpha) {   
slouken@689
   377
		  if(alpha == SDL_ALPHA_OPAQUE) {
slouken@689
   378
		    movd_m2r((*srcp), mm1);/* src(ARGB) -> mm1 (0000ARGB)*/
slouken@689
   379
		    movd_m2r((*dstp), mm2);/* dst(ARGB) -> mm2 (0000ARGB)*/
slouken@689
   380
		    pand_r2r(mm0, mm1);
slouken@689
   381
		    pand_r2r(mm6, mm2);
slouken@689
   382
		    por_r2r(mm1, mm2);
slouken@689
   383
		    movd_r2m(mm2, (*dstp));
slouken@689
   384
		  } else {
slouken@689
   385
		    movd_m2r((*srcp), mm1);/* src(ARGB) -> mm1 (0000ARGB)*/
slouken@689
   386
                    punpcklbw_r2r(mm1, mm1); /* AARRGGBB -> mm1 */
slouken@689
   387
                    pand_r2r(mm3, mm1); /* 0A0R0G0B -> mm1 */
slouken@689
   388
			  
slouken@689
   389
	            movd_m2r((*dstp), mm2);/* dst(ARGB) -> mm2 (0000ARGB)*/
slouken@689
   390
                    punpcklbw_r2r(mm2, mm2); /* AARRGGBB -> mm2 */
slouken@689
   391
                    pand_r2r(mm3, mm2); /* 0A0R0G0B -> mm2 */
slouken@689
   392
		
slouken@689
   393
		    movq_r2r(mm2, mm5);/* mm2(0A0R0G0B) -> mm5 */
slouken@689
   394
		    pand_r2r(mm7, mm5); /* mm5 & dst alpha mask -> mm5(0A000000) */
slouken@689
   395
		    psrlq_i2r(24, mm5); /* mm5 >> 24 -> mm5 (0000A000)*/
slouken@689
   396
		    
slouken@689
   397
		    movq_r2r(mm1, mm4);/* mm1(0A0R0G0B) -> mm4 */
slouken@689
   398
		    psrlq_i2r(48, mm4); /* mm4 >> 48 -> mm4(0000000A) */
slouken@689
   399
		    punpcklwd_r2r(mm4, mm4); /* 00000A0A -> mm4 */
slouken@689
   400
                    punpcklwd_r2r(mm4, mm4); /* 0A0A0A0A -> mm4 */
slouken@689
   401
		                        		    
slouken@689
   402
                    /* blend */		    
slouken@689
   403
                    psubw_r2r(mm2, mm1);/* src - dst -> mm1 */
slouken@689
   404
	            pmullw_r2r(mm4, mm1); /* mm1 * alpha -> mm1 */
slouken@689
   405
	            psrlw_i2r(8, mm1); /* mm1 >> 8 -> mm1 */
slouken@689
   406
	            paddw_r2r(mm1, mm2); /* mm1 + mm2(dst) -> mm2 */
slouken@689
   407
	            pand_r2r(mm3, mm2); /* 0A0R0G0B -> mm2 */
slouken@689
   408
		    packuswb_r2r(mm2, mm2);  /* ARGBARGB -> mm2 */
slouken@689
   409
		    pand_r2r(mm0, mm2); /* 0RGB0RGB -> mm2 */
slouken@689
   410
		    por_r2r(mm5, mm2); /* dst alpha | mm2 -> mm2 */
slouken@689
   411
		    movd_r2m(mm2, *dstp);/* mm2 -> dst */
slouken@689
   412
		  }
slouken@689
   413
		}
slouken@689
   414
		++srcp;
slouken@689
   415
		++dstp;
slouken@689
   416
	    }, width);
slouken@689
   417
	    srcp += srcskip;
slouken@689
   418
	    dstp += dstskip;
slouken@689
   419
	}
slouken@689
   420
	emms();
slouken@689
   421
}
slouken@689
   422
#endif
slouken@689
   423
icculus@1047
   424
#ifdef USE_ALTIVEC_BLITTERS
icculus@1162
   425
#include <altivec.h>
icculus@1047
   426
#include <assert.h>
icculus@1162
   427
icculus@1162
   428
#if ((defined MACOSX) && (__GNUC__ < 4))
icculus@1162
   429
    #define VECUINT8_LITERAL(a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p) \
icculus@1162
   430
        (vector unsigned char) ( a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p )
icculus@1162
   431
    #define VECUINT16_LITERAL(a,b,c,d,e,f,g,h) \
icculus@1162
   432
        (vector unsigned short) ( a,b,c,d,e,f,g,h )
icculus@1162
   433
#else
icculus@1162
   434
    #define VECUINT8_LITERAL(a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p) \
icculus@1162
   435
        (vector unsigned char) { a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p }
icculus@1162
   436
    #define VECUINT16_LITERAL(a,b,c,d,e,f,g,h) \
icculus@1162
   437
        (vector unsigned short) { a,b,c,d,e,f,g,h }
icculus@1162
   438
#endif
icculus@1162
   439
icculus@1047
   440
#define UNALIGNED_PTR(x) (((size_t) x) & 0x0000000F)
icculus@1047
   441
#define VECPRINT(msg, v) do { \
icculus@1047
   442
    vector unsigned int tmpvec = (vector unsigned int)(v); \
icculus@1047
   443
    unsigned int *vp = (unsigned int *)&tmpvec; \
icculus@1047
   444
    printf("%s = %08X %08X %08X %08X\n", msg, vp[0], vp[1], vp[2], vp[3]); \
icculus@1047
   445
} while (0)
icculus@1047
   446
icculus@1047
   447
/* the permuation vector that takes the high bytes out of all the appropriate shorts 
icculus@1047
   448
    (vector unsigned char)(
icculus@1047
   449
        0x00, 0x10, 0x02, 0x12,
icculus@1047
   450
        0x04, 0x14, 0x06, 0x16,
icculus@1047
   451
        0x08, 0x18, 0x0A, 0x1A,
icculus@1047
   452
        0x0C, 0x1C, 0x0E, 0x1E );
icculus@1047
   453
*/
icculus@1047
   454
#define VEC_MERGE_PERMUTE() (vec_add(vec_lvsl(0, (int*)NULL), (vector unsigned char)vec_splat_u16(0x0F)))
icculus@1047
   455
#define VEC_U32_24() (vec_add(vec_splat_u32(12), vec_splat_u32(12)))
icculus@1047
   456
#define VEC_ALPHA_MASK() ((vector unsigned char)vec_sl((vector unsigned int)vec_splat_s8(-1), VEC_U32_24()))
icculus@1047
   457
#define VEC_ALIGNER(src) ((UNALIGNED_PTR(src)) \
icculus@1047
   458
    ? vec_lvsl(0, src) \
icculus@1047
   459
    : vec_add(vec_lvsl(8, src), vec_splat_u8(8)))
icculus@1047
   460
icculus@1047
   461
   
icculus@1047
   462
#define VEC_MULTIPLY_ALPHA(vs, vd, valpha, mergePermute, v1_16, v8_16) do { \
icculus@1047
   463
    /* vtemp1 contains source AAGGAAGGAAGGAAGG */ \
icculus@1047
   464
    vector unsigned short vtemp1 = vec_mule(vs, valpha); \
icculus@1047
   465
    /* vtemp2 contains source RRBBRRBBRRBBRRBB */ \
icculus@1047
   466
    vector unsigned short vtemp2 = vec_mulo(vs, valpha); \
icculus@1047
   467
    /* valpha2 is 255-alpha */ \
icculus@1047
   468
    vector unsigned char valpha2 = vec_nor(valpha, valpha); \
icculus@1047
   469
    /* vtemp3 contains dest AAGGAAGGAAGGAAGG */ \
icculus@1047
   470
    vector unsigned short vtemp3 = vec_mule(vd, valpha2); \
icculus@1047
   471
    /* vtemp4 contains dest RRBBRRBBRRBBRRBB */ \
icculus@1047
   472
    vector unsigned short vtemp4 = vec_mulo(vd, valpha2); \
icculus@1047
   473
    /* add source and dest */ \
icculus@1047
   474
    vtemp1 = vec_add(vtemp1, vtemp3); \
icculus@1047
   475
    vtemp2 = vec_add(vtemp2, vtemp4); \
icculus@1047
   476
    /* vtemp1 = (vtemp1 + 1) + ((vtemp1 + 1) >> 8) */ \
icculus@1047
   477
    vtemp1 = vec_add(vtemp1, v1_16); \
icculus@1047
   478
    vtemp3 = vec_sr(vtemp1, v8_16); \
icculus@1047
   479
    vtemp1 = vec_add(vtemp1, vtemp3); \
icculus@1047
   480
    /* vtemp2 = (vtemp2 + 1) + ((vtemp2 + 1) >> 8) */ \
icculus@1047
   481
    vtemp2 = vec_add(vtemp2, v1_16); \
icculus@1047
   482
    vtemp4 = vec_sr(vtemp2, v8_16); \
icculus@1047
   483
    vtemp2 = vec_add(vtemp2, vtemp4); \
icculus@1047
   484
    /* (>>8) and get ARGBARGBARGBARGB */ \
icculus@1047
   485
    vd = (vector unsigned char)vec_perm(vtemp1, vtemp2, mergePermute); \
icculus@1047
   486
} while (0)
icculus@1047
   487
 
icculus@1047
   488
/* Calculate the permute vector used for 32->32 swizzling */
icculus@1047
   489
static vector unsigned char calc_swizzle32(const SDL_PixelFormat *srcfmt,
icculus@1047
   490
                                  const SDL_PixelFormat *dstfmt)
icculus@1047
   491
{
icculus@1047
   492
    /*
icculus@1047
   493
     * We have to assume that the bits that aren't used by other
icculus@1047
   494
     *  colors is alpha, and it's one complete byte, since some formats
icculus@1047
   495
     *  leave alpha with a zero mask, but we should still swizzle the bits.
icculus@1047
   496
     */
icculus@1047
   497
    /* ARGB */
icculus@1047
   498
    const static struct SDL_PixelFormat default_pixel_format = {
icculus@1047
   499
        NULL, 0, 0,
icculus@1047
   500
        0, 0, 0, 0,
icculus@1047
   501
        16, 8, 0, 24,
icculus@1047
   502
        0x00FF0000, 0x0000FF00, 0x000000FF, 0xFF000000,
icculus@1047
   503
        0, 0};
icculus@1047
   504
    if (!srcfmt) {
icculus@1047
   505
        srcfmt = &default_pixel_format;
icculus@1047
   506
    }
icculus@1047
   507
    if (!dstfmt) {
icculus@1047
   508
        dstfmt = &default_pixel_format;
icculus@1047
   509
    }
icculus@1162
   510
    vector unsigned char plus = VECUINT8_LITERAL
icculus@1047
   511
                                            ( 0x00, 0x00, 0x00, 0x00,
icculus@1047
   512
                                              0x04, 0x04, 0x04, 0x04,
icculus@1047
   513
                                              0x08, 0x08, 0x08, 0x08,
icculus@1047
   514
                                              0x0C, 0x0C, 0x0C, 0x0C );
icculus@1047
   515
    vector unsigned char vswiz;
icculus@1047
   516
    vector unsigned int srcvec;
icculus@1047
   517
#define RESHIFT(X) (3 - ((X) >> 3))
icculus@1047
   518
    Uint32 rmask = RESHIFT(srcfmt->Rshift) << (dstfmt->Rshift);
icculus@1047
   519
    Uint32 gmask = RESHIFT(srcfmt->Gshift) << (dstfmt->Gshift);
icculus@1047
   520
    Uint32 bmask = RESHIFT(srcfmt->Bshift) << (dstfmt->Bshift);
icculus@1047
   521
    Uint32 amask;
icculus@1047
   522
    /* Use zero for alpha if either surface doesn't have alpha */
icculus@1047
   523
    if (dstfmt->Amask) {
icculus@1047
   524
        amask = ((srcfmt->Amask) ? RESHIFT(srcfmt->Ashift) : 0x10) << (dstfmt->Ashift);
icculus@1047
   525
    } else {
icculus@1047
   526
        amask = 0x10101010 & ((dstfmt->Rmask | dstfmt->Gmask | dstfmt->Bmask) ^ 0xFFFFFFFF);
icculus@1047
   527
    }
icculus@1047
   528
#undef RESHIFT  
icculus@1162
   529
    ((unsigned int *)(char*)&srcvec)[0] = (rmask | gmask | bmask | amask);
icculus@1047
   530
    vswiz = vec_add(plus, (vector unsigned char)vec_splat(srcvec, 0));
icculus@1047
   531
    return(vswiz);
icculus@1047
   532
}
icculus@1047
   533
icculus@1047
   534
static void Blit32to565PixelAlphaAltivec(SDL_BlitInfo *info)
icculus@1047
   535
{
icculus@1047
   536
    int height = info->d_height;
icculus@1047
   537
    Uint8 *src = (Uint8 *)info->s_pixels;
icculus@1047
   538
    int srcskip = info->s_skip;
icculus@1047
   539
    Uint8 *dst = (Uint8 *)info->d_pixels;
icculus@1047
   540
    int dstskip = info->d_skip;
icculus@1047
   541
    SDL_PixelFormat *srcfmt = info->src;
icculus@1047
   542
icculus@1047
   543
    vector unsigned char v0 = vec_splat_u8(0);
icculus@1047
   544
    vector unsigned short v8_16 = vec_splat_u16(8);
icculus@1047
   545
    vector unsigned short v1_16 = vec_splat_u16(1);
icculus@1047
   546
    vector unsigned short v2_16 = vec_splat_u16(2);
icculus@1047
   547
    vector unsigned short v3_16 = vec_splat_u16(3);
icculus@1047
   548
    vector unsigned int v8_32 = vec_splat_u32(8);
icculus@1047
   549
    vector unsigned int v16_32 = vec_add(v8_32, v8_32);
icculus@1162
   550
    vector unsigned short v3f = VECUINT16_LITERAL(
icculus@1047
   551
        0x003f, 0x003f, 0x003f, 0x003f,
icculus@1047
   552
        0x003f, 0x003f, 0x003f, 0x003f);
icculus@1162
   553
    vector unsigned short vfc = VECUINT16_LITERAL(
icculus@1047
   554
        0x00fc, 0x00fc, 0x00fc, 0x00fc,
icculus@1047
   555
        0x00fc, 0x00fc, 0x00fc, 0x00fc);
icculus@1047
   556
icculus@1047
   557
    /* 
icculus@1047
   558
        0x10 - 0x1f is the alpha
icculus@1047
   559
        0x00 - 0x0e evens are the red
icculus@1047
   560
        0x01 - 0x0f odds are zero
icculus@1047
   561
    */
icculus@1162
   562
    vector unsigned char vredalpha1 = VECUINT8_LITERAL(
icculus@1047
   563
        0x10, 0x00, 0x01, 0x01,
icculus@1047
   564
        0x10, 0x02, 0x01, 0x01,
icculus@1047
   565
        0x10, 0x04, 0x01, 0x01,
icculus@1047
   566
        0x10, 0x06, 0x01, 0x01
icculus@1047
   567
    );
icculus@1047
   568
    vector unsigned char vredalpha2 = (vector unsigned char)(
icculus@1047
   569
        vec_add((vector unsigned int)vredalpha1, vec_sl(v8_32, v16_32))
icculus@1047
   570
    );
icculus@1047
   571
    /*
icculus@1047
   572
        0x00 - 0x0f is ARxx ARxx ARxx ARxx
icculus@1047
   573
        0x11 - 0x0f odds are blue
icculus@1047
   574
    */
icculus@1162
   575
    vector unsigned char vblue1 = VECUINT8_LITERAL(
icculus@1047
   576
        0x00, 0x01, 0x02, 0x11,
icculus@1047
   577
        0x04, 0x05, 0x06, 0x13,
icculus@1047
   578
        0x08, 0x09, 0x0a, 0x15,
icculus@1047
   579
        0x0c, 0x0d, 0x0e, 0x17
icculus@1047
   580
    );
icculus@1047
   581
    vector unsigned char vblue2 = (vector unsigned char)(
icculus@1047
   582
        vec_add((vector unsigned int)vblue1, v8_32)
icculus@1047
   583
    );
icculus@1047
   584
    /*
icculus@1047
   585
        0x00 - 0x0f is ARxB ARxB ARxB ARxB
icculus@1047
   586
        0x10 - 0x0e evens are green
icculus@1047
   587
    */
icculus@1162
   588
    vector unsigned char vgreen1 = VECUINT8_LITERAL(
icculus@1047
   589
        0x00, 0x01, 0x10, 0x03,
icculus@1047
   590
        0x04, 0x05, 0x12, 0x07,
icculus@1047
   591
        0x08, 0x09, 0x14, 0x0b,
icculus@1047
   592
        0x0c, 0x0d, 0x16, 0x0f
icculus@1047
   593
    );
icculus@1047
   594
    vector unsigned char vgreen2 = (vector unsigned char)(
icculus@1047
   595
        vec_add((vector unsigned int)vgreen1, vec_sl(v8_32, v8_32))
icculus@1047
   596
    );
icculus@1162
   597
    vector unsigned char vgmerge = VECUINT8_LITERAL(
icculus@1047
   598
        0x00, 0x02, 0x00, 0x06,
icculus@1047
   599
        0x00, 0x0a, 0x00, 0x0e,
icculus@1047
   600
        0x00, 0x12, 0x00, 0x16,
icculus@1047
   601
        0x00, 0x1a, 0x00, 0x1e);
icculus@1047
   602
    vector unsigned char mergePermute = VEC_MERGE_PERMUTE();
icculus@1047
   603
    vector unsigned char vpermute = calc_swizzle32(srcfmt, NULL);
icculus@1047
   604
    vector unsigned char valphaPermute = vec_and(vec_lvsl(0, (int *)NULL), vec_splat_u8(0xC));
icculus@1047
   605
icculus@1047
   606
    vector unsigned short vf800 = (vector unsigned short)vec_splat_u8(-7);
icculus@1047
   607
    vf800 = vec_sl(vf800, vec_splat_u16(8));
icculus@1047
   608
icculus@1047
   609
    while(height--) {
icculus@1047
   610
        int extrawidth;
icculus@1047
   611
        vector unsigned char valigner;
icculus@1047
   612
        vector unsigned char vsrc;
icculus@1047
   613
        vector unsigned char voverflow;
icculus@1047
   614
        int width = info->d_width;
icculus@1047
   615
icculus@1047
   616
#define ONE_PIXEL_BLEND(condition, widthvar) \
icculus@1047
   617
        while (condition) { \
icculus@1162
   618
            Uint32 Pixel; \
icculus@1047
   619
            unsigned sR, sG, sB, dR, dG, dB, sA; \
icculus@1162
   620
            DISEMBLE_RGBA(src, 4, srcfmt, Pixel, sR, sG, sB, sA); \
icculus@1047
   621
            if(sA) { \
icculus@1047
   622
                unsigned short dstpixel = *((unsigned short *)dst); \
icculus@1047
   623
                dR = (dstpixel >> 8) & 0xf8; \
icculus@1047
   624
                dG = (dstpixel >> 3) & 0xfc; \
icculus@1047
   625
                dB = (dstpixel << 3) & 0xf8; \
icculus@1047
   626
                ACCURATE_ALPHA_BLEND(sR, sG, sB, sA, dR, dG, dB); \
icculus@1047
   627
                *((unsigned short *)dst) = ( \
icculus@1047
   628
                    ((dR & 0xf8) << 8) | ((dG & 0xfc) << 3) | (dB >> 3) \
icculus@1047
   629
                ); \
icculus@1047
   630
            } \
icculus@1047
   631
            src += 4; \
icculus@1047
   632
            dst += 2; \
icculus@1047
   633
            widthvar--; \
icculus@1047
   634
        }
icculus@1047
   635
        ONE_PIXEL_BLEND((UNALIGNED_PTR(dst)) && (width), width);
icculus@1047
   636
        extrawidth = (width % 8);
icculus@1047
   637
        valigner = VEC_ALIGNER(src);
icculus@1047
   638
        vsrc = (vector unsigned char)vec_ld(0, src);
icculus@1047
   639
        width -= extrawidth;
icculus@1047
   640
        while (width) {
icculus@1047
   641
            vector unsigned char valpha;
icculus@1047
   642
            vector unsigned char vsrc1, vsrc2;
icculus@1047
   643
            vector unsigned char vdst1, vdst2;
icculus@1047
   644
            vector unsigned short vR, vG, vB;
icculus@1047
   645
            vector unsigned short vpixel, vrpixel, vgpixel, vbpixel;
icculus@1047
   646
icculus@1047
   647
            /* Load 8 pixels from src as ARGB */
icculus@1047
   648
            voverflow = (vector unsigned char)vec_ld(15, src);
icculus@1047
   649
            vsrc = vec_perm(vsrc, voverflow, valigner);
icculus@1047
   650
            vsrc1 = vec_perm(vsrc, vsrc, vpermute);
icculus@1047
   651
            src += 16;
icculus@1047
   652
            vsrc = (vector unsigned char)vec_ld(15, src);
icculus@1047
   653
            voverflow = vec_perm(voverflow, vsrc, valigner);
icculus@1047
   654
            vsrc2 = vec_perm(voverflow, voverflow, vpermute);
icculus@1047
   655
            src += 16;
icculus@1047
   656
icculus@1047
   657
            /* Load 8 pixels from dst as XRGB */
icculus@1047
   658
            voverflow = vec_ld(0, dst);
icculus@1047
   659
            vR = vec_and((vector unsigned short)voverflow, vf800);
icculus@1047
   660
            vB = vec_sl((vector unsigned short)voverflow, v3_16);
icculus@1047
   661
            vG = vec_sl(vB, v2_16);
icculus@1047
   662
            vdst1 = (vector unsigned char)vec_perm((vector unsigned char)vR, (vector unsigned char)vR, vredalpha1);
icculus@1047
   663
            vdst1 = vec_perm(vdst1, (vector unsigned char)vB, vblue1);
icculus@1047
   664
            vdst1 = vec_perm(vdst1, (vector unsigned char)vG, vgreen1);
icculus@1047
   665
            vdst2 = (vector unsigned char)vec_perm((vector unsigned char)vR, (vector unsigned char)vR, vredalpha2);
icculus@1047
   666
            vdst2 = vec_perm(vdst2, (vector unsigned char)vB, vblue2);
icculus@1047
   667
            vdst2 = vec_perm(vdst2, (vector unsigned char)vG, vgreen2);
icculus@1047
   668
icculus@1047
   669
            /* Alpha blend 8 pixels as ARGB */
icculus@1047
   670
            valpha = vec_perm(vsrc1, v0, valphaPermute);
icculus@1047
   671
            VEC_MULTIPLY_ALPHA(vsrc1, vdst1, valpha, mergePermute, v1_16, v8_16);
icculus@1047
   672
            valpha = vec_perm(vsrc2, v0, valphaPermute);
icculus@1047
   673
            VEC_MULTIPLY_ALPHA(vsrc2, vdst2, valpha, mergePermute, v1_16, v8_16);
icculus@1047
   674
icculus@1047
   675
            /* Convert 8 pixels to 565 */
icculus@1047
   676
            vpixel = (vector unsigned short)vec_packpx((vector unsigned int)vdst1, (vector unsigned int)vdst2);
icculus@1047
   677
            vgpixel = (vector unsigned short)vec_perm(vdst1, vdst2, vgmerge);
icculus@1047
   678
            vgpixel = vec_and(vgpixel, vfc);
icculus@1047
   679
            vgpixel = vec_sl(vgpixel, v3_16);
icculus@1047
   680
            vrpixel = vec_sl(vpixel, v1_16);
icculus@1047
   681
            vrpixel = vec_and(vrpixel, vf800);
icculus@1047
   682
            vbpixel = vec_and(vpixel, v3f);
icculus@1047
   683
            vdst1 = vec_or((vector unsigned char)vrpixel, (vector unsigned char)vgpixel);
icculus@1047
   684
            vdst1 = vec_or(vdst1, (vector unsigned char)vbpixel);
icculus@1047
   685
            
icculus@1047
   686
            /* Store 8 pixels */
icculus@1047
   687
            vec_st(vdst1, 0, dst);
icculus@1047
   688
icculus@1047
   689
            width -= 8;
icculus@1047
   690
            dst += 16;
icculus@1047
   691
        }
icculus@1047
   692
        ONE_PIXEL_BLEND((extrawidth), extrawidth);
icculus@1047
   693
#undef ONE_PIXEL_BLEND
icculus@1047
   694
        src += srcskip;
icculus@1047
   695
        dst += dstskip;
icculus@1047
   696
    }
icculus@1047
   697
}
icculus@1047
   698
icculus@1047
   699
static void Blit32to32SurfaceAlphaKeyAltivec(SDL_BlitInfo *info)
icculus@1047
   700
{
icculus@1047
   701
    unsigned alpha = info->src->alpha;
icculus@1047
   702
    int height = info->d_height;
icculus@1047
   703
    Uint32 *srcp = (Uint32 *)info->s_pixels;
icculus@1047
   704
    int srcskip = info->s_skip >> 2;
icculus@1047
   705
    Uint32 *dstp = (Uint32 *)info->d_pixels;
icculus@1047
   706
    int dstskip = info->d_skip >> 2;
icculus@1047
   707
    SDL_PixelFormat *srcfmt = info->src;
icculus@1047
   708
    SDL_PixelFormat *dstfmt = info->dst;
icculus@1047
   709
    unsigned sA = srcfmt->alpha;
icculus@1047
   710
    unsigned dA = dstfmt->Amask ? SDL_ALPHA_OPAQUE : 0;
icculus@1047
   711
    Uint32 rgbmask = srcfmt->Rmask | srcfmt->Gmask | srcfmt->Bmask;
icculus@1047
   712
    Uint32 ckey = info->src->colorkey;
icculus@1047
   713
    vector unsigned char mergePermute;
icculus@1047
   714
    vector unsigned char vsrcPermute;
icculus@1047
   715
    vector unsigned char vdstPermute;
icculus@1047
   716
    vector unsigned char vsdstPermute;
icculus@1047
   717
    vector unsigned char valpha;
icculus@1047
   718
    vector unsigned char valphamask;
icculus@1047
   719
    vector unsigned char vbits;
icculus@1047
   720
    vector unsigned char v0;
icculus@1047
   721
    vector unsigned short v1;
icculus@1047
   722
    vector unsigned short v8;
icculus@1047
   723
    vector unsigned int vckey;
icculus@1047
   724
    vector unsigned int vrgbmask;
icculus@1047
   725
icculus@1047
   726
    mergePermute = VEC_MERGE_PERMUTE();
icculus@1047
   727
    v0 = vec_splat_u8(0);
icculus@1047
   728
    v1 = vec_splat_u16(1);
icculus@1047
   729
    v8 = vec_splat_u16(8);
icculus@1047
   730
icculus@1047
   731
    /* set the alpha to 255 on the destination surf */
icculus@1047
   732
    valphamask = VEC_ALPHA_MASK();
icculus@1047
   733
icculus@1047
   734
    vsrcPermute = calc_swizzle32(srcfmt, NULL);
icculus@1047
   735
    vdstPermute = calc_swizzle32(NULL, dstfmt);
icculus@1047
   736
    vsdstPermute = calc_swizzle32(dstfmt, NULL);
icculus@1047
   737
icculus@1047
   738
    /* set a vector full of alpha and 255-alpha */
icculus@1047
   739
    ((unsigned char *)&valpha)[0] = alpha;
icculus@1047
   740
    valpha = vec_splat(valpha, 0);
icculus@1047
   741
    vbits = (vector unsigned char)vec_splat_s8(-1);
icculus@1047
   742
icculus@1047
   743
    ckey &= rgbmask;
icculus@1162
   744
    ((unsigned int *)(char*)&vckey)[0] = ckey;
icculus@1047
   745
    vckey = vec_splat(vckey, 0);
icculus@1162
   746
    ((unsigned int *)(char*)&vrgbmask)[0] = rgbmask;
icculus@1047
   747
    vrgbmask = vec_splat(vrgbmask, 0);
icculus@1047
   748
icculus@1047
   749
    while(height--) {
icculus@1047
   750
        int width = info->d_width;
icculus@1047
   751
#define ONE_PIXEL_BLEND(condition, widthvar) \
icculus@1047
   752
        while (condition) { \
icculus@1162
   753
            Uint32 Pixel; \
icculus@1047
   754
            unsigned sR, sG, sB, dR, dG, dB; \
icculus@1162
   755
            RETRIEVE_RGB_PIXEL(((Uint8 *)srcp), 4, Pixel); \
icculus@1162
   756
            if(sA && Pixel != ckey) { \
icculus@1162
   757
                RGB_FROM_PIXEL(Pixel, srcfmt, sR, sG, sB); \
icculus@1162
   758
                DISEMBLE_RGB(((Uint8 *)dstp), 4, dstfmt, Pixel, dR, dG, dB); \
icculus@1047
   759
                ACCURATE_ALPHA_BLEND(sR, sG, sB, sA, dR, dG, dB); \
icculus@1047
   760
                ASSEMBLE_RGBA(((Uint8 *)dstp), 4, dstfmt, dR, dG, dB, dA); \
icculus@1047
   761
            } \
icculus@1162
   762
            dstp++; \
icculus@1162
   763
            srcp++; \
icculus@1047
   764
            widthvar--; \
icculus@1047
   765
        }
icculus@1047
   766
        ONE_PIXEL_BLEND((UNALIGNED_PTR(dstp)) && (width), width);
icculus@1047
   767
        if (width > 0) {
icculus@1047
   768
            int extrawidth = (width % 4);
icculus@1047
   769
            vector unsigned char valigner = VEC_ALIGNER(srcp);
icculus@1047
   770
            vector unsigned char vs = (vector unsigned char)vec_ld(0, srcp);
icculus@1047
   771
            width -= extrawidth;
icculus@1047
   772
            while (width) {
icculus@1047
   773
                vector unsigned char vsel;
icculus@1047
   774
                vector unsigned char voverflow;
icculus@1047
   775
                vector unsigned char vd;
icculus@1047
   776
                vector unsigned char vd_orig;
icculus@1047
   777
icculus@1047
   778
                /* s = *srcp */
icculus@1047
   779
                voverflow = (vector unsigned char)vec_ld(15, srcp);
icculus@1047
   780
                vs = vec_perm(vs, voverflow, valigner);
icculus@1047
   781
                
icculus@1047
   782
                /* vsel is set for items that match the key */
icculus@1047
   783
                vsel = (vector unsigned char)vec_and((vector unsigned int)vs, vrgbmask);
icculus@1047
   784
                vsel = (vector unsigned char)vec_cmpeq((vector unsigned int)vsel, vckey);
icculus@1047
   785
icculus@1047
   786
                /* permute to source format */
icculus@1047
   787
                vs = vec_perm(vs, valpha, vsrcPermute);
icculus@1047
   788
icculus@1047
   789
                /* d = *dstp */
icculus@1047
   790
                vd = (vector unsigned char)vec_ld(0, dstp);
icculus@1047
   791
                vd_orig = vd = vec_perm(vd, v0, vsdstPermute);
icculus@1047
   792
icculus@1047
   793
                VEC_MULTIPLY_ALPHA(vs, vd, valpha, mergePermute, v1, v8);
icculus@1047
   794
icculus@1047
   795
                /* set the alpha channel to full on */
icculus@1047
   796
                vd = vec_or(vd, valphamask);
icculus@1047
   797
icculus@1047
   798
                /* mask out color key */
icculus@1047
   799
                vd = vec_sel(vd, vd_orig, vsel);
icculus@1047
   800
                
icculus@1047
   801
                /* permute to dest format */
icculus@1047
   802
                vd = vec_perm(vd, vbits, vdstPermute);
icculus@1047
   803
icculus@1047
   804
                /* *dstp = res */
icculus@1047
   805
                vec_st((vector unsigned int)vd, 0, dstp);
icculus@1047
   806
                
icculus@1047
   807
                srcp += 4;
icculus@1047
   808
                dstp += 4;
icculus@1047
   809
                width -= 4;
icculus@1047
   810
                vs = voverflow;
icculus@1047
   811
            }
icculus@1047
   812
            ONE_PIXEL_BLEND((extrawidth), extrawidth);
icculus@1047
   813
        }
icculus@1047
   814
#undef ONE_PIXEL_BLEND
icculus@1047
   815
 
icculus@1047
   816
        srcp += srcskip;
icculus@1047
   817
        dstp += dstskip;
icculus@1047
   818
    }
icculus@1047
   819
}
icculus@1047
   820
icculus@1047
   821
icculus@1047
   822
static void Blit32to32PixelAlphaAltivec(SDL_BlitInfo *info)
icculus@1047
   823
{
icculus@1047
   824
    int width = info->d_width;
icculus@1047
   825
    int height = info->d_height;
icculus@1047
   826
    Uint32 *srcp = (Uint32 *)info->s_pixels;
icculus@1047
   827
    int srcskip = info->s_skip >> 2;
icculus@1047
   828
    Uint32 *dstp = (Uint32 *)info->d_pixels;
icculus@1047
   829
    int dstskip = info->d_skip >> 2;
icculus@1047
   830
    SDL_PixelFormat *srcfmt = info->src;
icculus@1047
   831
    SDL_PixelFormat *dstfmt = info->dst;
icculus@1047
   832
    vector unsigned char mergePermute;
icculus@1047
   833
    vector unsigned char valphaPermute;
icculus@1047
   834
    vector unsigned char vsrcPermute;
icculus@1047
   835
    vector unsigned char vdstPermute;
icculus@1047
   836
    vector unsigned char vsdstPermute;
icculus@1047
   837
    vector unsigned char valphamask;
icculus@1047
   838
    vector unsigned char vpixelmask;
icculus@1047
   839
    vector unsigned char v0;
icculus@1047
   840
    vector unsigned short v1;
icculus@1047
   841
    vector unsigned short v8;
icculus@1047
   842
icculus@1047
   843
    v0 = vec_splat_u8(0);
icculus@1047
   844
    v1 = vec_splat_u16(1);
icculus@1047
   845
    v8 = vec_splat_u16(8);
icculus@1047
   846
    mergePermute = VEC_MERGE_PERMUTE();
icculus@1047
   847
    valphamask = VEC_ALPHA_MASK();
icculus@1047
   848
    valphaPermute = vec_and(vec_lvsl(0, (int *)NULL), vec_splat_u8(0xC));
icculus@1047
   849
    vpixelmask = vec_nor(valphamask, v0);
icculus@1047
   850
    vsrcPermute = calc_swizzle32(srcfmt, NULL);
icculus@1047
   851
    vdstPermute = calc_swizzle32(NULL, dstfmt);
icculus@1047
   852
    vsdstPermute = calc_swizzle32(dstfmt, NULL);
icculus@1047
   853
icculus@1047
   854
	while ( height-- ) {
icculus@1047
   855
        width = info->d_width;
icculus@1047
   856
#define ONE_PIXEL_BLEND(condition, widthvar) while ((condition)) { \
icculus@1162
   857
            Uint32 Pixel; \
icculus@1047
   858
            unsigned sR, sG, sB, dR, dG, dB, sA, dA; \
icculus@1162
   859
            DISEMBLE_RGBA((Uint8 *)srcp, 4, srcfmt, Pixel, sR, sG, sB, sA); \
icculus@1047
   860
            if(sA) { \
icculus@1162
   861
              DISEMBLE_RGBA((Uint8 *)dstp, 4, dstfmt, Pixel, dR, dG, dB, dA); \
icculus@1047
   862
              ACCURATE_ALPHA_BLEND(sR, sG, sB, sA, dR, dG, dB); \
icculus@1047
   863
              ASSEMBLE_RGBA((Uint8 *)dstp, 4, dstfmt, dR, dG, dB, dA); \
icculus@1047
   864
            } \
icculus@1047
   865
            ++srcp; \
icculus@1047
   866
            ++dstp; \
icculus@1047
   867
            widthvar--; \
icculus@1047
   868
        }
icculus@1047
   869
        ONE_PIXEL_BLEND((UNALIGNED_PTR(dstp)) && (width), width);
icculus@1047
   870
        if (width > 0) {
icculus@1047
   871
            // vsrcPermute
icculus@1047
   872
            // vdstPermute
icculus@1047
   873
            int extrawidth = (width % 4);
icculus@1047
   874
            vector unsigned char valigner = VEC_ALIGNER(srcp);
icculus@1047
   875
            vector unsigned char vs = (vector unsigned char)vec_ld(0, srcp);
icculus@1047
   876
            width -= extrawidth;
icculus@1047
   877
            while (width) {
icculus@1047
   878
                vector unsigned char voverflow;
icculus@1047
   879
                vector unsigned char vd;
icculus@1047
   880
                vector unsigned char valpha;
icculus@1047
   881
                vector unsigned char vdstalpha;
icculus@1047
   882
                /* s = *srcp */
icculus@1047
   883
                voverflow = (vector unsigned char)vec_ld(15, srcp);
icculus@1047
   884
                vs = vec_perm(vs, voverflow, valigner);
icculus@1047
   885
                vs = vec_perm(vs, v0, vsrcPermute);
icculus@1047
   886
icculus@1047
   887
                valpha = vec_perm(vs, v0, valphaPermute);
icculus@1047
   888
                
icculus@1047
   889
                /* d = *dstp */
icculus@1047
   890
                vd = (vector unsigned char)vec_ld(0, dstp);
icculus@1047
   891
                vd = vec_perm(vd, v0, vsdstPermute);
icculus@1047
   892
                vdstalpha = vec_and(vd, valphamask);
icculus@1047
   893
icculus@1047
   894
                VEC_MULTIPLY_ALPHA(vs, vd, valpha, mergePermute, v1, v8);
icculus@1047
   895
icculus@1047
   896
                /* set the alpha to the dest alpha */
icculus@1047
   897
                vd = vec_and(vd, vpixelmask);
icculus@1047
   898
                vd = vec_or(vd, vdstalpha);
icculus@1047
   899
                vd = vec_perm(vd, v0, vdstPermute);
icculus@1047
   900
icculus@1047
   901
                /* *dstp = res */
icculus@1047
   902
                vec_st((vector unsigned int)vd, 0, dstp);
icculus@1047
   903
                
icculus@1047
   904
                srcp += 4;
icculus@1047
   905
                dstp += 4;
icculus@1047
   906
                width -= 4;
icculus@1047
   907
                vs = voverflow;
icculus@1047
   908
icculus@1047
   909
            }
icculus@1047
   910
            ONE_PIXEL_BLEND((extrawidth), extrawidth);
icculus@1047
   911
        }
icculus@1047
   912
	    srcp += srcskip;
icculus@1047
   913
	    dstp += dstskip;
icculus@1047
   914
#undef ONE_PIXEL_BLEND
icculus@1047
   915
	}
icculus@1047
   916
}
icculus@1047
   917
icculus@1047
   918
/* fast ARGB888->(A)RGB888 blending with pixel alpha */
icculus@1047
   919
static void BlitRGBtoRGBPixelAlphaAltivec(SDL_BlitInfo *info)
icculus@1047
   920
{
icculus@1047
   921
	int width = info->d_width;
icculus@1047
   922
	int height = info->d_height;
icculus@1047
   923
	Uint32 *srcp = (Uint32 *)info->s_pixels;
icculus@1047
   924
	int srcskip = info->s_skip >> 2;
icculus@1047
   925
	Uint32 *dstp = (Uint32 *)info->d_pixels;
icculus@1047
   926
	int dstskip = info->d_skip >> 2;
icculus@1047
   927
    vector unsigned char mergePermute;
icculus@1047
   928
    vector unsigned char valphaPermute;
icculus@1047
   929
    vector unsigned char valphamask;
icculus@1047
   930
    vector unsigned char vpixelmask;
icculus@1047
   931
    vector unsigned char v0;
icculus@1047
   932
    vector unsigned short v1;
icculus@1047
   933
    vector unsigned short v8;
icculus@1047
   934
    v0 = vec_splat_u8(0);
icculus@1047
   935
    v1 = vec_splat_u16(1);
icculus@1047
   936
    v8 = vec_splat_u16(8);
icculus@1047
   937
    mergePermute = VEC_MERGE_PERMUTE();
icculus@1047
   938
    valphamask = VEC_ALPHA_MASK();
icculus@1047
   939
    valphaPermute = vec_and(vec_lvsl(0, (int *)NULL), vec_splat_u8(0xC));
icculus@1047
   940
    
icculus@1047
   941
 
icculus@1047
   942
    vpixelmask = vec_nor(valphamask, v0);
icculus@1047
   943
	while(height--) {
icculus@1047
   944
        width = info->d_width;
icculus@1047
   945
#define ONE_PIXEL_BLEND(condition, widthvar) \
icculus@1047
   946
        while ((condition)) { \
icculus@1047
   947
            Uint32 dalpha; \
icculus@1047
   948
            Uint32 d; \
icculus@1047
   949
            Uint32 s1; \
icculus@1047
   950
            Uint32 d1; \
icculus@1047
   951
            Uint32 s = *srcp; \
icculus@1047
   952
            Uint32 alpha = s >> 24; \
icculus@1047
   953
            if(alpha) { \
icculus@1047
   954
              if(alpha == SDL_ALPHA_OPAQUE) { \
icculus@1047
   955
                *dstp = (s & 0x00ffffff) | (*dstp & 0xff000000); \
icculus@1047
   956
              } else { \
icculus@1047
   957
                d = *dstp; \
icculus@1047
   958
                dalpha = d & 0xff000000; \
icculus@1047
   959
                s1 = s & 0xff00ff; \
icculus@1047
   960
                d1 = d & 0xff00ff; \
icculus@1047
   961
                d1 = (d1 + ((s1 - d1) * alpha >> 8)) & 0xff00ff; \
icculus@1047
   962
                s &= 0xff00; \
icculus@1047
   963
                d &= 0xff00; \
icculus@1047
   964
                d = (d + ((s - d) * alpha >> 8)) & 0xff00; \
icculus@1047
   965
                *dstp = d1 | d | dalpha; \
icculus@1047
   966
              } \
icculus@1047
   967
            } \
icculus@1047
   968
            ++srcp; \
icculus@1047
   969
            ++dstp; \
icculus@1047
   970
            widthvar--; \
icculus@1047
   971
	    }
icculus@1047
   972
        ONE_PIXEL_BLEND((UNALIGNED_PTR(dstp)) && (width), width);
icculus@1047
   973
        if (width > 0) {
icculus@1047
   974
            int extrawidth = (width % 4);
icculus@1047
   975
            vector unsigned char valigner = VEC_ALIGNER(srcp);
icculus@1047
   976
            vector unsigned char vs = (vector unsigned char)vec_ld(0, srcp);
icculus@1047
   977
            width -= extrawidth;
icculus@1047
   978
            while (width) {
icculus@1047
   979
                vector unsigned char voverflow;
icculus@1047
   980
                vector unsigned char vd;
icculus@1047
   981
                vector unsigned char valpha;
icculus@1047
   982
                vector unsigned char vdstalpha;
icculus@1047
   983
                /* s = *srcp */
icculus@1047
   984
                voverflow = (vector unsigned char)vec_ld(15, srcp);
icculus@1047
   985
                vs = vec_perm(vs, voverflow, valigner);
icculus@1047
   986
icculus@1047
   987
                valpha = vec_perm(vs, v0, valphaPermute);
icculus@1047
   988
                
icculus@1047
   989
                /* d = *dstp */
icculus@1047
   990
                vd = (vector unsigned char)vec_ld(0, dstp);
icculus@1047
   991
                vdstalpha = vec_and(vd, valphamask);
icculus@1047
   992
icculus@1047
   993
                VEC_MULTIPLY_ALPHA(vs, vd, valpha, mergePermute, v1, v8);
icculus@1047
   994
icculus@1047
   995
                /* set the alpha to the dest alpha */
icculus@1047
   996
                vd = vec_and(vd, vpixelmask);
icculus@1047
   997
                vd = vec_or(vd, vdstalpha);
icculus@1047
   998
icculus@1047
   999
                /* *dstp = res */
icculus@1047
  1000
                vec_st((vector unsigned int)vd, 0, dstp);
icculus@1047
  1001
                
icculus@1047
  1002
                srcp += 4;
icculus@1047
  1003
                dstp += 4;
icculus@1047
  1004
                width -= 4;
icculus@1047
  1005
                vs = voverflow;
icculus@1047
  1006
            }
icculus@1047
  1007
            ONE_PIXEL_BLEND((extrawidth), extrawidth);
icculus@1047
  1008
        }
icculus@1047
  1009
	    srcp += srcskip;
icculus@1047
  1010
	    dstp += dstskip;
icculus@1047
  1011
	}
icculus@1047
  1012
#undef ONE_PIXEL_BLEND
icculus@1047
  1013
}
icculus@1047
  1014
icculus@1047
  1015
static void Blit32to32SurfaceAlphaAltivec(SDL_BlitInfo *info)
icculus@1047
  1016
{
icculus@1047
  1017
    /* XXX : 6 */
icculus@1047
  1018
	unsigned alpha = info->src->alpha;
icculus@1047
  1019
    int height = info->d_height;
icculus@1047
  1020
    Uint32 *srcp = (Uint32 *)info->s_pixels;
icculus@1047
  1021
    int srcskip = info->s_skip >> 2;
icculus@1047
  1022
    Uint32 *dstp = (Uint32 *)info->d_pixels;
icculus@1047
  1023
    int dstskip = info->d_skip >> 2;
icculus@1047
  1024
    SDL_PixelFormat *srcfmt = info->src;
icculus@1047
  1025
    SDL_PixelFormat *dstfmt = info->dst;
icculus@1047
  1026
	unsigned sA = srcfmt->alpha;
icculus@1047
  1027
	unsigned dA = dstfmt->Amask ? SDL_ALPHA_OPAQUE : 0;
icculus@1047
  1028
    vector unsigned char mergePermute;
icculus@1047
  1029
    vector unsigned char vsrcPermute;
icculus@1047
  1030
    vector unsigned char vdstPermute;
icculus@1047
  1031
    vector unsigned char vsdstPermute;
icculus@1047
  1032
    vector unsigned char valpha;
icculus@1047
  1033
    vector unsigned char valphamask;
icculus@1047
  1034
    vector unsigned char vbits;
icculus@1047
  1035
    vector unsigned short v1;
icculus@1047
  1036
    vector unsigned short v8;
icculus@1047
  1037
icculus@1047
  1038
    mergePermute = VEC_MERGE_PERMUTE();
icculus@1047
  1039
    v1 = vec_splat_u16(1);
icculus@1047
  1040
    v8 = vec_splat_u16(8);
icculus@1047
  1041
icculus@1047
  1042
    /* set the alpha to 255 on the destination surf */
icculus@1047
  1043
    valphamask = VEC_ALPHA_MASK();
icculus@1047
  1044
icculus@1047
  1045
    vsrcPermute = calc_swizzle32(srcfmt, NULL);
icculus@1047
  1046
    vdstPermute = calc_swizzle32(NULL, dstfmt);
icculus@1047
  1047
    vsdstPermute = calc_swizzle32(dstfmt, NULL);
icculus@1047
  1048
icculus@1047
  1049
    /* set a vector full of alpha and 255-alpha */
icculus@1047
  1050
    ((unsigned char *)&valpha)[0] = alpha;
icculus@1047
  1051
    valpha = vec_splat(valpha, 0);
icculus@1047
  1052
    vbits = (vector unsigned char)vec_splat_s8(-1);
icculus@1047
  1053
icculus@1047
  1054
    while(height--) {
icculus@1047
  1055
        int width = info->d_width;
icculus@1047
  1056
#define ONE_PIXEL_BLEND(condition, widthvar) while ((condition)) { \
icculus@1162
  1057
            Uint32 Pixel; \
icculus@1047
  1058
            unsigned sR, sG, sB, dR, dG, dB; \
icculus@1162
  1059
            DISEMBLE_RGB(((Uint8 *)srcp), 4, srcfmt, Pixel, sR, sG, sB); \
icculus@1162
  1060
            DISEMBLE_RGB(((Uint8 *)dstp), 4, dstfmt, Pixel, dR, dG, dB); \
icculus@1047
  1061
            ACCURATE_ALPHA_BLEND(sR, sG, sB, sA, dR, dG, dB); \
icculus@1047
  1062
            ASSEMBLE_RGBA(((Uint8 *)dstp), 4, dstfmt, dR, dG, dB, dA); \
icculus@1047
  1063
            ++srcp; \
icculus@1047
  1064
            ++dstp; \
icculus@1047
  1065
            widthvar--; \
icculus@1047
  1066
        }
icculus@1047
  1067
        ONE_PIXEL_BLEND((UNALIGNED_PTR(dstp)) && (width), width);
icculus@1047
  1068
        if (width > 0) {
icculus@1047
  1069
            int extrawidth = (width % 4);
icculus@1047
  1070
            vector unsigned char valigner = vec_lvsl(0, srcp);
icculus@1047
  1071
            vector unsigned char vs = (vector unsigned char)vec_ld(0, srcp);
icculus@1047
  1072
            width -= extrawidth;
icculus@1047
  1073
            while (width) {
icculus@1047
  1074
                vector unsigned char voverflow;
icculus@1047
  1075
                vector unsigned char vd;
icculus@1047
  1076
icculus@1047
  1077
                /* s = *srcp */
icculus@1047
  1078
                voverflow = (vector unsigned char)vec_ld(15, srcp);
icculus@1047
  1079
                vs = vec_perm(vs, voverflow, valigner);
icculus@1047
  1080
                vs = vec_perm(vs, valpha, vsrcPermute);
icculus@1047
  1081
                
icculus@1047
  1082
                /* d = *dstp */
icculus@1047
  1083
                vd = (vector unsigned char)vec_ld(0, dstp);
icculus@1047
  1084
                vd = vec_perm(vd, vd, vsdstPermute);
icculus@1047
  1085
icculus@1047
  1086
                VEC_MULTIPLY_ALPHA(vs, vd, valpha, mergePermute, v1, v8);
icculus@1047
  1087
icculus@1047
  1088
                /* set the alpha channel to full on */
icculus@1047
  1089
                vd = vec_or(vd, valphamask);
icculus@1047
  1090
                vd = vec_perm(vd, vbits, vdstPermute);
icculus@1047
  1091
icculus@1047
  1092
                /* *dstp = res */
icculus@1047
  1093
                vec_st((vector unsigned int)vd, 0, dstp);
icculus@1047
  1094
                
icculus@1047
  1095
                srcp += 4;
icculus@1047
  1096
                dstp += 4;
icculus@1047
  1097
                width -= 4;
icculus@1047
  1098
                vs = voverflow;
icculus@1047
  1099
            }
icculus@1047
  1100
            ONE_PIXEL_BLEND((extrawidth), extrawidth);
icculus@1047
  1101
        }
icculus@1047
  1102
#undef ONE_PIXEL_BLEND
icculus@1047
  1103
 
icculus@1047
  1104
        srcp += srcskip;
icculus@1047
  1105
        dstp += dstskip;
icculus@1047
  1106
    }
icculus@1047
  1107
icculus@1047
  1108
}
icculus@1047
  1109
icculus@1047
  1110
icculus@1047
  1111
/* fast RGB888->(A)RGB888 blending */
icculus@1047
  1112
static void BlitRGBtoRGBSurfaceAlphaAltivec(SDL_BlitInfo *info)
icculus@1047
  1113
{
icculus@1047
  1114
	unsigned alpha = info->src->alpha;
icculus@1047
  1115
    int height = info->d_height;
icculus@1047
  1116
    Uint32 *srcp = (Uint32 *)info->s_pixels;
icculus@1047
  1117
    int srcskip = info->s_skip >> 2;
icculus@1047
  1118
    Uint32 *dstp = (Uint32 *)info->d_pixels;
icculus@1047
  1119
    int dstskip = info->d_skip >> 2;
icculus@1047
  1120
    vector unsigned char mergePermute;
icculus@1047
  1121
    vector unsigned char valpha;
icculus@1047
  1122
    vector unsigned char valphamask;
icculus@1047
  1123
    vector unsigned short v1;
icculus@1047
  1124
    vector unsigned short v8;
icculus@1047
  1125
icculus@1047
  1126
    mergePermute = VEC_MERGE_PERMUTE();
icculus@1047
  1127
    v1 = vec_splat_u16(1);
icculus@1047
  1128
    v8 = vec_splat_u16(8);
icculus@1047
  1129
icculus@1047
  1130
    /* set the alpha to 255 on the destination surf */
icculus@1047
  1131
    valphamask = VEC_ALPHA_MASK();
icculus@1047
  1132
icculus@1047
  1133
    /* set a vector full of alpha and 255-alpha */
icculus@1047
  1134
    ((unsigned char *)&valpha)[0] = alpha;
icculus@1047
  1135
    valpha = vec_splat(valpha, 0);
icculus@1047
  1136
icculus@1047
  1137
    while(height--) {
icculus@1047
  1138
        int width = info->d_width;
icculus@1047
  1139
#define ONE_PIXEL_BLEND(condition, widthvar) while ((condition)) { \
icculus@1047
  1140
            Uint32 s = *srcp; \
icculus@1047
  1141
            Uint32 d = *dstp; \
icculus@1047
  1142
            Uint32 s1 = s & 0xff00ff; \
icculus@1047
  1143
            Uint32 d1 = d & 0xff00ff; \
icculus@1047
  1144
            d1 = (d1 + ((s1 - d1) * alpha >> 8)) \
icculus@1047
  1145
                 & 0xff00ff; \
icculus@1047
  1146
            s &= 0xff00; \
icculus@1047
  1147
            d &= 0xff00; \
icculus@1047
  1148
            d = (d + ((s - d) * alpha >> 8)) & 0xff00; \
icculus@1047
  1149
            *dstp = d1 | d | 0xff000000; \
icculus@1047
  1150
            ++srcp; \
icculus@1047
  1151
            ++dstp; \
icculus@1047
  1152
            widthvar--; \
icculus@1047
  1153
        }
icculus@1047
  1154
        ONE_PIXEL_BLEND((UNALIGNED_PTR(dstp)) && (width), width);
icculus@1047
  1155
        if (width > 0) {
icculus@1047
  1156
            int extrawidth = (width % 4);
icculus@1047
  1157
            vector unsigned char valigner = VEC_ALIGNER(srcp);
icculus@1047
  1158
            vector unsigned char vs = (vector unsigned char)vec_ld(0, srcp);
icculus@1047
  1159
            width -= extrawidth;
icculus@1047
  1160
            while (width) {
icculus@1047
  1161
                vector unsigned char voverflow;
icculus@1047
  1162
                vector unsigned char vd;
icculus@1047
  1163
icculus@1047
  1164
                /* s = *srcp */
icculus@1047
  1165
                voverflow = (vector unsigned char)vec_ld(15, srcp);
icculus@1047
  1166
                vs = vec_perm(vs, voverflow, valigner);
icculus@1047
  1167
                
icculus@1047
  1168
                /* d = *dstp */
icculus@1047
  1169
                vd = (vector unsigned char)vec_ld(0, dstp);
icculus@1047
  1170
icculus@1047
  1171
                VEC_MULTIPLY_ALPHA(vs, vd, valpha, mergePermute, v1, v8);
icculus@1047
  1172
icculus@1047
  1173
                /* set the alpha channel to full on */
icculus@1047
  1174
                vd = vec_or(vd, valphamask);
icculus@1047
  1175
icculus@1047
  1176
                /* *dstp = res */
icculus@1047
  1177
                vec_st((vector unsigned int)vd, 0, dstp);
icculus@1047
  1178
                
icculus@1047
  1179
                srcp += 4;
icculus@1047
  1180
                dstp += 4;
icculus@1047
  1181
                width -= 4;
icculus@1047
  1182
                vs = voverflow;
icculus@1047
  1183
            }
icculus@1047
  1184
            ONE_PIXEL_BLEND((extrawidth), extrawidth);
icculus@1047
  1185
        }
icculus@1047
  1186
#undef ONE_PIXEL_BLEND
icculus@1047
  1187
 
icculus@1047
  1188
        srcp += srcskip;
icculus@1047
  1189
        dstp += dstskip;
icculus@1047
  1190
    }
icculus@1047
  1191
}
icculus@1047
  1192
#endif /* USE_ALTIVEC_BLITTERS */
icculus@1047
  1193
slouken@1
  1194
/* fast RGB888->(A)RGB888 blending with surface alpha=128 special case */
slouken@1
  1195
static void BlitRGBtoRGBSurfaceAlpha128(SDL_BlitInfo *info)
slouken@0
  1196
{
slouken@0
  1197
	int width = info->d_width;
slouken@0
  1198
	int height = info->d_height;
slouken@0
  1199
	Uint32 *srcp = (Uint32 *)info->s_pixels;
slouken@0
  1200
	int srcskip = info->s_skip >> 2;
slouken@0
  1201
	Uint32 *dstp = (Uint32 *)info->d_pixels;
slouken@0
  1202
	int dstskip = info->d_skip >> 2;
slouken@0
  1203
slouken@0
  1204
	while(height--) {
slouken@0
  1205
	    DUFFS_LOOP4({
slouken@1
  1206
		    Uint32 s = *srcp++;
slouken@1
  1207
		    Uint32 d = *dstp;
slouken@1
  1208
		    *dstp++ = ((((s & 0x00fefefe) + (d & 0x00fefefe)) >> 1)
slouken@1
  1209
			       + (s & d & 0x00010101)) | 0xff000000;
slouken@0
  1210
	    }, width);
slouken@0
  1211
	    srcp += srcskip;
slouken@0
  1212
	    dstp += dstskip;
slouken@0
  1213
	}
slouken@0
  1214
}
slouken@0
  1215
slouken@1
  1216
/* fast RGB888->(A)RGB888 blending with surface alpha */
slouken@1
  1217
static void BlitRGBtoRGBSurfaceAlpha(SDL_BlitInfo *info)
slouken@1
  1218
{
slouken@1
  1219
	unsigned alpha = info->src->alpha;
slouken@1
  1220
	if(alpha == 128) {
slouken@1
  1221
		BlitRGBtoRGBSurfaceAlpha128(info);
slouken@1
  1222
	} else {
slouken@1
  1223
		int width = info->d_width;
slouken@1
  1224
		int height = info->d_height;
slouken@1
  1225
		Uint32 *srcp = (Uint32 *)info->s_pixels;
slouken@1
  1226
		int srcskip = info->s_skip >> 2;
slouken@1
  1227
		Uint32 *dstp = (Uint32 *)info->d_pixels;
slouken@1
  1228
		int dstskip = info->d_skip >> 2;
slouken@689
  1229
		Uint32 s;
slouken@689
  1230
		Uint32 d;
slouken@689
  1231
		Uint32 s1;
slouken@689
  1232
		Uint32 d1;
slouken@1
  1233
slouken@1
  1234
		while(height--) {
slouken@689
  1235
			DUFFS_LOOP_DOUBLE2({
slouken@689
  1236
				/* One Pixel Blend */
slouken@1
  1237
				s = *srcp;
slouken@1
  1238
				d = *dstp;
slouken@1
  1239
				s1 = s & 0xff00ff;
slouken@1
  1240
				d1 = d & 0xff00ff;
slouken@1
  1241
				d1 = (d1 + ((s1 - d1) * alpha >> 8))
slouken@1
  1242
				     & 0xff00ff;
slouken@1
  1243
				s &= 0xff00;
slouken@1
  1244
				d &= 0xff00;
slouken@1
  1245
				d = (d + ((s - d) * alpha >> 8)) & 0xff00;
slouken@1
  1246
				*dstp = d1 | d | 0xff000000;
slouken@1
  1247
				++srcp;
slouken@1
  1248
				++dstp;
slouken@689
  1249
			},{
slouken@689
  1250
			        /* Two Pixels Blend */
slouken@689
  1251
				s = *srcp;
slouken@689
  1252
				d = *dstp;
slouken@689
  1253
				s1 = s & 0xff00ff;
slouken@689
  1254
				d1 = d & 0xff00ff;
slouken@689
  1255
				d1 += (s1 - d1) * alpha >> 8;
slouken@689
  1256
				d1 &= 0xff00ff;
slouken@689
  1257
				     
slouken@689
  1258
				s = ((s & 0xff00) >> 8) | 
slouken@689
  1259
					((srcp[1] & 0xff00) << 8);
slouken@689
  1260
				d = ((d & 0xff00) >> 8) |
slouken@689
  1261
					((dstp[1] & 0xff00) << 8);
slouken@689
  1262
				d += (s - d) * alpha >> 8;
slouken@689
  1263
				d &= 0x00ff00ff;
slouken@689
  1264
				
slouken@689
  1265
				*dstp++ = d1 | ((d << 8) & 0xff00) | 0xff000000;
slouken@689
  1266
				++srcp;
slouken@689
  1267
				
slouken@689
  1268
			        s1 = *srcp;
slouken@689
  1269
				d1 = *dstp;
slouken@689
  1270
				s1 &= 0xff00ff;
slouken@689
  1271
				d1 &= 0xff00ff;
slouken@689
  1272
				d1 += (s1 - d1) * alpha >> 8;
slouken@689
  1273
				d1 &= 0xff00ff;
slouken@689
  1274
				
slouken@689
  1275
				*dstp = d1 | ((d >> 8) & 0xff00) | 0xff000000;
slouken@689
  1276
				++srcp;
slouken@689
  1277
				++dstp;
slouken@1
  1278
			}, width);
slouken@1
  1279
			srcp += srcskip;
slouken@1
  1280
			dstp += dstskip;
slouken@1
  1281
		}
slouken@1
  1282
	}
slouken@1
  1283
}
slouken@1
  1284
slouken@0
  1285
/* fast ARGB888->(A)RGB888 blending with pixel alpha */
slouken@0
  1286
static void BlitRGBtoRGBPixelAlpha(SDL_BlitInfo *info)
slouken@0
  1287
{
slouken@0
  1288
	int width = info->d_width;
slouken@0
  1289
	int height = info->d_height;
slouken@0
  1290
	Uint32 *srcp = (Uint32 *)info->s_pixels;
slouken@0
  1291
	int srcskip = info->s_skip >> 2;
slouken@0
  1292
	Uint32 *dstp = (Uint32 *)info->d_pixels;
slouken@0
  1293
	int dstskip = info->d_skip >> 2;
slouken@0
  1294
slouken@0
  1295
	while(height--) {
slouken@0
  1296
	    DUFFS_LOOP4({
slouken@0
  1297
		Uint32 dalpha;
slouken@0
  1298
		Uint32 d;
slouken@0
  1299
		Uint32 s1;
slouken@0
  1300
		Uint32 d1;
slouken@0
  1301
		Uint32 s = *srcp;
slouken@0
  1302
		Uint32 alpha = s >> 24;
slouken@0
  1303
		/* FIXME: Here we special-case opaque alpha since the
slouken@0
  1304
		   compositioning used (>>8 instead of /255) doesn't handle
slouken@0
  1305
		   it correctly. Also special-case alpha=0 for speed?
slouken@0
  1306
		   Benchmark this! */
slouken@689
  1307
		if(alpha) {   
slouken@689
  1308
		  if(alpha == SDL_ALPHA_OPAQUE) {
slouken@0
  1309
		    *dstp = (s & 0x00ffffff) | (*dstp & 0xff000000);
slouken@689
  1310
		  } else {
slouken@0
  1311
		    /*
slouken@0
  1312
		     * take out the middle component (green), and process
slouken@0
  1313
		     * the other two in parallel. One multiply less.
slouken@0
  1314
		     */
slouken@0
  1315
		    d = *dstp;
slouken@0
  1316
		    dalpha = d & 0xff000000;
slouken@0
  1317
		    s1 = s & 0xff00ff;
slouken@0
  1318
		    d1 = d & 0xff00ff;
slouken@0
  1319
		    d1 = (d1 + ((s1 - d1) * alpha >> 8)) & 0xff00ff;
slouken@0
  1320
		    s &= 0xff00;
slouken@0
  1321
		    d &= 0xff00;
slouken@0
  1322
		    d = (d + ((s - d) * alpha >> 8)) & 0xff00;
slouken@0
  1323
		    *dstp = d1 | d | dalpha;
slouken@689
  1324
		  }
slouken@0
  1325
		}
slouken@0
  1326
		++srcp;
slouken@0
  1327
		++dstp;
slouken@0
  1328
	    }, width);
slouken@0
  1329
	    srcp += srcskip;
slouken@0
  1330
	    dstp += dstskip;
slouken@0
  1331
	}
slouken@0
  1332
}
slouken@0
  1333
slouken@880
  1334
#ifdef MMX_ASMBLIT
slouken@689
  1335
/* fast (as in MMX with prefetch) ARGB888->(A)RGB888 blending with pixel alpha */
slouken@689
  1336
inline static void BlitRGBtoRGBPixelAlphaMMX3DNOW(SDL_BlitInfo *info)
slouken@689
  1337
{
slouken@689
  1338
	int width = info->d_width;
slouken@689
  1339
	int height = info->d_height;
slouken@689
  1340
	Uint32 *srcp = (Uint32 *)info->s_pixels;
slouken@689
  1341
	int srcskip = info->s_skip >> 2;
slouken@689
  1342
	Uint32 *dstp = (Uint32 *)info->d_pixels;
slouken@689
  1343
	int dstskip = info->d_skip >> 2;
slouken@689
  1344
slouken@689
  1345
	Uint32 s;
slouken@689
  1346
	Uint32 alpha;
slouken@689
  1347
slouken@689
  1348
	__asm__ (
slouken@689
  1349
	/* make mm6 all zeros. */
slouken@689
  1350
	"pxor       %%mm6, %%mm6\n"
slouken@689
  1351
	
slouken@689
  1352
	/* Make a mask to preserve the alpha. */
slouken@689
  1353
	"pcmpeqb   %%mm7, %%mm7\n\t"            /* mm7(s) = FF FF FF FF | FF FF FF FF */
slouken@689
  1354
	"psrlq     $16, %%mm7\n\t"		    /* mm7(s) = 00 00 FF FF | FF FF FF FF */
slouken@689
  1355
slouken@689
  1356
		: );
slouken@689
  1357
slouken@689
  1358
	while(height--) {
slouken@689
  1359
slouken@689
  1360
	    DUFFS_LOOP4({
slouken@689
  1361
slouken@689
  1362
		__asm__ (
slouken@689
  1363
		"prefetch 64(%0)\n"
slouken@689
  1364
		"prefetch 64(%1)\n"
slouken@689
  1365
			: : "r" (srcp), "r" (dstp) );
slouken@689
  1366
slouken@689
  1367
		s = *srcp;
slouken@689
  1368
		alpha = s >> 24;
slouken@689
  1369
		/* FIXME: Here we special-case opaque alpha since the
slouken@689
  1370
		   compositioning used (>>8 instead of /255) doesn't handle
slouken@689
  1371
		   it correctly. Also special-case alpha=0 for speed?
slouken@689
  1372
		   Benchmark this! */
slouken@689
  1373
		
slouken@689
  1374
		if(alpha == SDL_ALPHA_OPAQUE) {
slouken@689
  1375
		    *dstp = (s & 0x00ffffff) | (*dstp & 0xff000000);
slouken@689
  1376
		} 
slouken@689
  1377
slouken@689
  1378
		else {
slouken@689
  1379
			    __asm__ (
slouken@689
  1380
		    /* load in the source, and dst. */
slouken@689
  1381
		    "movd      (%0), %%mm0\n"		    /* mm0(s) = 0 0 0 0 | As Rs Gs Bs */
slouken@689
  1382
		    "movd      (%1), %%mm1\n"		    /* mm1(d) = 0 0 0 0 | Ad Rd Gd Bd */
slouken@689
  1383
slouken@689
  1384
		    /* Move the src alpha into mm2 */
slouken@689
  1385
slouken@689
  1386
		    /* if supporting pshufw */
slouken@689
  1387
		    /*"pshufw     $0x55, %%mm0, %%mm2\n" */ /* mm2 = 0 As 0 As |  0 As  0  As */
slouken@689
  1388
		    /*"psrlw     $8, %%mm2\n" */
slouken@689
  1389
		    
slouken@689
  1390
		    /* else: */
slouken@689
  1391
		    "movq      %%mm0, %%mm2\n"
slouken@689
  1392
		    "psrld     $24, %%mm2\n"                /* mm2 = 0 0 0 0 | 0  0  0  As */
slouken@689
  1393
		    "punpcklwd	%%mm2, %%mm2\n"	            /* mm2 = 0 0 0 0 |  0 As  0  As */
slouken@689
  1394
		    "punpckldq	%%mm2, %%mm2\n"             /* mm2 = 0 As 0 As |  0 As  0  As */
slouken@689
  1395
slouken@689
  1396
		    /* move the colors into words. */
slouken@689
  1397
		    "punpcklbw %%mm6, %%mm0\n"		    /* mm0 = 0 As 0 Rs | 0 Gs 0 Bs */
slouken@689
  1398
		    "punpcklbw %%mm6, %%mm1\n"              /* mm0 = 0 Ad 0 Rd | 0 Gd 0 Bd */
slouken@689
  1399
slouken@689
  1400
		    /* src - dst */
slouken@689
  1401
		    "psubw    %%mm1, %%mm0\n"		    /* mm0 = As-Ad Rs-Rd | Gs-Gd  Bs-Bd */
slouken@689
  1402
slouken@689
  1403
		    /* A * (src-dst) */
slouken@689
  1404
		    "pmullw    %%mm2, %%mm0\n"		    /* mm0 = As*As-d As*Rs-d | As*Gs-d  As*Bs-d */
slouken@689
  1405
		    "pand      %%mm7, %%mm0\n"              /* to preserve dest alpha */
slouken@689
  1406
		    "psrlw     $8,    %%mm0\n"		    /* mm0 = Ac>>8 Rc>>8 | Gc>>8  Bc>>8 */
slouken@689
  1407
		    "paddb     %%mm1, %%mm0\n"		    /* mm0 = Ac+Ad Rc+Rd | Gc+Gd  Bc+Bd */
slouken@689
  1408
slouken@689
  1409
		    "packuswb  %%mm0, %%mm0\n"              /* mm0 =             | Ac Rc Gc Bc */
slouken@689
  1410
		    
slouken@689
  1411
		    "movd      %%mm0, (%1)\n"               /* result in mm0 */
slouken@689
  1412
slouken@689
  1413
		     : : "r" (srcp), "r" (dstp) );
slouken@689
  1414
slouken@689
  1415
		}
slouken@689
  1416
		++srcp;
slouken@689
  1417
		++dstp;
slouken@689
  1418
	    }, width);
slouken@689
  1419
	    srcp += srcskip;
slouken@689
  1420
	    dstp += dstskip;
slouken@689
  1421
	}
slouken@689
  1422
slouken@689
  1423
	__asm__ (
slouken@689
  1424
	"emms\n"
slouken@689
  1425
		:   );
slouken@689
  1426
}
slouken@689
  1427
#endif
slouken@689
  1428
slouken@1
  1429
/* 16bpp special case for per-surface alpha=50%: blend 2 pixels in parallel */
slouken@1
  1430
slouken@1
  1431
/* blend a single 16 bit pixel at 50% */
slouken@1
  1432
#define BLEND16_50(d, s, mask)						\
slouken@1
  1433
	((((s & mask) + (d & mask)) >> 1) + (s & d & (~mask & 0xffff)))
slouken@1
  1434
slouken@1
  1435
/* blend two 16 bit pixels at 50% */
slouken@1
  1436
#define BLEND2x16_50(d, s, mask)					     \
slouken@1
  1437
	(((s & (mask | mask << 16)) >> 1) + ((d & (mask | mask << 16)) >> 1) \
slouken@1
  1438
	 + (s & d & (~(mask | mask << 16))))
slouken@1
  1439
slouken@1
  1440
static void Blit16to16SurfaceAlpha128(SDL_BlitInfo *info, Uint16 mask)
slouken@0
  1441
{
slouken@0
  1442
	int width = info->d_width;
slouken@0
  1443
	int height = info->d_height;
slouken@0
  1444
	Uint16 *srcp = (Uint16 *)info->s_pixels;
slouken@0
  1445
	int srcskip = info->s_skip >> 1;
slouken@0
  1446
	Uint16 *dstp = (Uint16 *)info->d_pixels;
slouken@0
  1447
	int dstskip = info->d_skip >> 1;
slouken@0
  1448
slouken@0
  1449
	while(height--) {
slouken@1
  1450
		if(((unsigned long)srcp ^ (unsigned long)dstp) & 2) {
slouken@1
  1451
			/*
slouken@1
  1452
			 * Source and destination not aligned, pipeline it.
slouken@1
  1453
			 * This is mostly a win for big blits but no loss for
slouken@1
  1454
			 * small ones
slouken@1
  1455
			 */
slouken@1
  1456
			Uint32 prev_sw;
slouken@1
  1457
			int w = width;
slouken@1
  1458
slouken@1
  1459
			/* handle odd destination */
slouken@1
  1460
			if((unsigned long)dstp & 2) {
slouken@1
  1461
				Uint16 d = *dstp, s = *srcp;
slouken@1
  1462
				*dstp = BLEND16_50(d, s, mask);
slouken@1
  1463
				dstp++;
slouken@1
  1464
				srcp++;
slouken@1
  1465
				w--;
slouken@1
  1466
			}
slouken@1
  1467
			srcp++;	/* srcp is now 32-bit aligned */
slouken@1
  1468
slouken@1
  1469
			/* bootstrap pipeline with first halfword */
slouken@1
  1470
			prev_sw = ((Uint32 *)srcp)[-1];
slouken@1
  1471
slouken@1
  1472
			while(w > 1) {
slouken@1
  1473
				Uint32 sw, dw, s;
slouken@1
  1474
				sw = *(Uint32 *)srcp;
slouken@1
  1475
				dw = *(Uint32 *)dstp;
slouken@1
  1476
				if(SDL_BYTEORDER == SDL_BIG_ENDIAN)
slouken@1
  1477
					s = (prev_sw << 16) + (sw >> 16);
slouken@1
  1478
				else
slouken@1
  1479
					s = (prev_sw >> 16) + (sw << 16);
slouken@1
  1480
				prev_sw = sw;
slouken@1
  1481
				*(Uint32 *)dstp = BLEND2x16_50(dw, s, mask);
slouken@1
  1482
				dstp += 2;
slouken@1
  1483
				srcp += 2;
slouken@1
  1484
				w -= 2;
slouken@1
  1485
			}
slouken@1
  1486
slouken@1
  1487
			/* final pixel if any */
slouken@1
  1488
			if(w) {
slouken@1
  1489
				Uint16 d = *dstp, s;
slouken@1
  1490
				if(SDL_BYTEORDER == SDL_BIG_ENDIAN)
slouken@1
  1491
					s = prev_sw;
slouken@1
  1492
				else
slouken@1
  1493
					s = prev_sw >> 16;
slouken@1
  1494
				*dstp = BLEND16_50(d, s, mask);
slouken@1
  1495
				srcp++;
slouken@1
  1496
				dstp++;
slouken@1
  1497
			}
slouken@1
  1498
			srcp += srcskip - 1;
slouken@1
  1499
			dstp += dstskip;
slouken@1
  1500
		} else {
slouken@1
  1501
			/* source and destination are aligned */
slouken@1
  1502
			int w = width;
slouken@1
  1503
slouken@1
  1504
			/* first odd pixel? */
slouken@1
  1505
			if((unsigned long)srcp & 2) {
slouken@1
  1506
				Uint16 d = *dstp, s = *srcp;
slouken@1
  1507
				*dstp = BLEND16_50(d, s, mask);
slouken@1
  1508
				srcp++;
slouken@1
  1509
				dstp++;
slouken@1
  1510
				w--;
slouken@1
  1511
			}
slouken@1
  1512
			/* srcp and dstp are now 32-bit aligned */
slouken@1
  1513
slouken@1
  1514
			while(w > 1) {
slouken@1
  1515
				Uint32 sw = *(Uint32 *)srcp;
slouken@1
  1516
				Uint32 dw = *(Uint32 *)dstp;
slouken@1
  1517
				*(Uint32 *)dstp = BLEND2x16_50(dw, sw, mask);
slouken@1
  1518
				srcp += 2;
slouken@1
  1519
				dstp += 2;
slouken@1
  1520
				w -= 2;
slouken@1
  1521
			}
slouken@1
  1522
slouken@1
  1523
			/* last odd pixel? */
slouken@1
  1524
			if(w) {
slouken@1
  1525
				Uint16 d = *dstp, s = *srcp;
slouken@1
  1526
				*dstp = BLEND16_50(d, s, mask);
slouken@1
  1527
				srcp++;
slouken@1
  1528
				dstp++;
slouken@1
  1529
			}
slouken@1
  1530
			srcp += srcskip;
slouken@1
  1531
			dstp += dstskip;
slouken@1
  1532
		}
slouken@1
  1533
	}
slouken@1
  1534
}
slouken@1
  1535
slouken@880
  1536
#ifdef MMX_ASMBLIT
slouken@689
  1537
/* fast RGB565->RGB565 blending with surface alpha */
slouken@689
  1538
static void Blit565to565SurfaceAlphaMMX(SDL_BlitInfo *info)
slouken@689
  1539
{
slouken@689
  1540
	unsigned alpha = info->src->alpha; /* downscale alpha to 5 bits */
slouken@689
  1541
	if(alpha == 128) {
slouken@689
  1542
		Blit16to16SurfaceAlpha128(info, 0xf7de);
slouken@689
  1543
	} else {
slouken@689
  1544
		int width = info->d_width;
slouken@689
  1545
		int height = info->d_height;
slouken@689
  1546
		Uint16 *srcp = (Uint16 *)info->s_pixels;
slouken@689
  1547
		int srcskip = info->s_skip >> 1;
slouken@689
  1548
		Uint16 *dstp = (Uint16 *)info->d_pixels;
slouken@689
  1549
		int dstskip = info->d_skip >> 1;
slouken@689
  1550
	        Uint32 s, d;
slouken@689
  1551
	        Uint8 load[8];
slouken@689
  1552
	  
slouken@689
  1553
		alpha &= ~(1+2+4);		/* cut alpha to get the exact same behaviour */
slouken@689
  1554
	        *(Uint64 *)load = alpha;
slouken@689
  1555
		alpha >>= 3;		/* downscale alpha to 5 bits */
slouken@689
  1556
slouken@689
  1557
                movq_m2r(*load, mm0); /* alpha(0000000A) -> mm0 */
slouken@689
  1558
                punpcklwd_r2r(mm0, mm0); /* 00000A0A -> mm0 */
slouken@689
  1559
                punpcklwd_r2r(mm0, mm0); /* 0A0A0A0A -> mm0 */
slouken@689
  1560
	  
slouken@689
  1561
 	        /* Setup the 565 color channel masks */
slouken@720
  1562
	        *(Uint64 *)load = 0xF800F800F800F800ULL;
slouken@689
  1563
		movq_m2r(*load, mm1); /* MASKRED -> mm1 */
slouken@720
  1564
		*(Uint64 *)load = 0x07E007E007E007E0ULL;
slouken@689
  1565
		movq_m2r(*load, mm4); /* MASKGREEN -> mm4 */
slouken@720
  1566
		*(Uint64 *)load = 0x001F001F001F001FULL;
slouken@689
  1567
		movq_m2r(*load, mm7); /* MASKBLUE -> mm7 */
slouken@689
  1568
		while(height--) {
slouken@689
  1569
                        DUFFS_LOOP_QUATRO2(
slouken@689
  1570
                        {
slouken@689
  1571
	                        s = *srcp++;
slouken@689
  1572
				d = *dstp;
slouken@689
  1573
				/*
slouken@689
  1574
				 * shift out the middle component (green) to
slouken@689
  1575
				 * the high 16 bits, and process all three RGB
slouken@689
  1576
				 * components at the same time.
slouken@689
  1577
				 */
slouken@689
  1578
				s = (s | s << 16) & 0x07e0f81f;
slouken@689
  1579
				d = (d | d << 16) & 0x07e0f81f;
slouken@689
  1580
				d += (s - d) * alpha >> 5;
slouken@689
  1581
				d &= 0x07e0f81f;
slouken@689
  1582
				*dstp++ = d | d >> 16;
slouken@689
  1583
                        },{
slouken@689
  1584
	                        s = *srcp++;
slouken@689
  1585
				d = *dstp;
slouken@689
  1586
				/*
slouken@689
  1587
				 * shift out the middle component (green) to
slouken@689
  1588
				 * the high 16 bits, and process all three RGB
slouken@689
  1589
				 * components at the same time.
slouken@689
  1590
				 */
slouken@689
  1591
				s = (s | s << 16) & 0x07e0f81f;
slouken@689
  1592
				d = (d | d << 16) & 0x07e0f81f;
slouken@689
  1593
				d += (s - d) * alpha >> 5;
slouken@689
  1594
				d &= 0x07e0f81f;
slouken@689
  1595
				*dstp++ = d | d >> 16;
slouken@689
  1596
			        s = *srcp++;
slouken@689
  1597
				d = *dstp;
slouken@689
  1598
				/*
slouken@689
  1599
				 * shift out the middle component (green) to
slouken@689
  1600
				 * the high 16 bits, and process all three RGB
slouken@689
  1601
				 * components at the same time.
slouken@689
  1602
				 */
slouken@689
  1603
				s = (s | s << 16) & 0x07e0f81f;
slouken@689
  1604
				d = (d | d << 16) & 0x07e0f81f;
slouken@689
  1605
				d += (s - d) * alpha >> 5;
slouken@689
  1606
				d &= 0x07e0f81f;
slouken@689
  1607
				*dstp++ = d | d >> 16;
slouken@689
  1608
                        },{
slouken@689
  1609
	                        movq_m2r((*dstp), mm3);/* 4 dst pixels -> mm3 */
slouken@689
  1610
	                        movq_m2r((*srcp), mm2);/* 4 src pixels -> mm2 */
slouken@689
  1611
			  
slouken@689
  1612
	                        /* RED */
slouken@689
  1613
	                        movq_r2r(mm2, mm5); /* src -> mm5 */
slouken@689
  1614
	                        pand_r2r(mm1 , mm5); /* src & MASKRED -> mm5 */
slouken@689
  1615
	                        psrlq_i2r(11, mm5); /* mm5 >> 11 -> mm5 [000r 000r 000r 000r] */
slouken@689
  1616
	
slouken@689
  1617
	                        movq_r2r(mm3, mm6); /* dst -> mm6 */
slouken@689
  1618
	                        pand_r2r(mm1 , mm6); /* dst & MASKRED -> mm6 */
slouken@689
  1619
	                        psrlq_i2r(11, mm6); /* mm6 >> 11 -> mm6 [000r 000r 000r 000r] */
slouken@689
  1620
	
slouken@689
  1621
	                        /* blend */
slouken@689
  1622
	                        psubw_r2r(mm6, mm5);/* src - dst -> mm5 */
slouken@689
  1623
	                        pmullw_r2r(mm0, mm5); /* mm5 * alpha -> mm5 */
slouken@689
  1624
	                        psrlw_i2r(8, mm5); /* mm5 >> 8 -> mm5 */
slouken@689
  1625
	                        paddw_r2r(mm5, mm6); /* mm5 + mm6(dst) -> mm6 */
slouken@689
  1626
	                        psllq_i2r(11, mm6); /* mm6 << 11 -> mm6 */
slouken@689
  1627
	                        pand_r2r(mm1, mm6); /* mm6 & MASKRED -> mm6 */
slouken@689
  1628
	
slouken@689
  1629
	                        movq_r2r(mm4, mm5); /* MASKGREEN -> mm5 */
slouken@689
  1630
	                        por_r2r(mm7, mm5);  /* MASKBLUE | mm5 -> mm5 */
slouken@689
  1631
	                        pand_r2r(mm5, mm3); /* mm3 & mm5(!MASKRED) -> mm3 */
slouken@689
  1632
	                        por_r2r(mm6, mm3); /* save new reds in dsts */
slouken@689
  1633
	
slouken@689
  1634
	                        /* green */
slouken@689
  1635
	                        movq_r2r(mm2, mm5); /* src -> mm5 */
slouken@689
  1636
	                        pand_r2r(mm4 , mm5); /* src & MASKGREEN -> mm5 */
slouken@689
  1637
	                        psrlq_i2r(5, mm5); /* mm5 >> 5 -> mm5 [000g 000g 000g 000g] */
slouken@689
  1638
	
slouken@689
  1639
	                        movq_r2r(mm3, mm6); /* dst -> mm6 */
slouken@689
  1640
	                        pand_r2r(mm4 , mm6); /* dst & MASKGREEN -> mm6 */
slouken@689
  1641
	                        psrlq_i2r(5, mm6); /* mm6 >> 5 -> mm6 [000g 000g 000g 000g] */
slouken@689
  1642
	
slouken@689
  1643
	                        /* blend */
slouken@689
  1644
	                        psubw_r2r(mm6, mm5);/* src - dst -> mm5 */
slouken@689
  1645
	                        pmullw_r2r(mm0, mm5); /* mm5 * alpha -> mm5 */
slouken@689
  1646
	                        psrlw_i2r(8, mm5); /* mm5 >> 8 -> mm5 */
slouken@689
  1647
	                        paddw_r2r(mm5, mm6); /* mm5 + mm6(dst) -> mm6 */
slouken@689
  1648
	                        psllq_i2r(5, mm6); /* mm6 << 5 -> mm6 */
slouken@689
  1649
	                        pand_r2r(mm4, mm6); /* mm6 & MASKGREEN -> mm6 */
slouken@689
  1650
	
slouken@689
  1651
	                        movq_r2r(mm1, mm5); /* MASKRED -> mm5 */
slouken@689
  1652
	                        por_r2r(mm7, mm5);  /* MASKBLUE | mm5 -> mm5 */
slouken@689
  1653
	                        pand_r2r(mm5, mm3); /* mm3 & mm5(!MASKGREEN) -> mm3 */
slouken@689
  1654
	                        por_r2r(mm6, mm3); /* save new greens in dsts */
slouken@689
  1655
	
slouken@689
  1656
	                        /* blue */
slouken@689
  1657
	                        movq_r2r(mm2, mm5); /* src -> mm5 */
slouken@689
  1658
	                        pand_r2r(mm7 , mm5); /* src & MASKRED -> mm5[000b 000b 000b 000b] */
slouken@689
  1659
		
slouken@689
  1660
	                        movq_r2r(mm3, mm6); /* dst -> mm6 */
slouken@689
  1661
	                        pand_r2r(mm7 , mm6); /* dst & MASKBLUE -> mm6[000b 000b 000b 000b] */
slouken@689
  1662
	
slouken@689
  1663
	                        /* blend */
slouken@689
  1664
	                        psubw_r2r(mm6, mm5);/* src - dst -> mm5 */
slouken@689
  1665
	                        pmullw_r2r(mm0, mm5); /* mm5 * alpha -> mm5 */
slouken@689
  1666
	                        psrlw_i2r(8, mm5); /* mm5 >> 8 -> mm5 */
slouken@689
  1667
	                        paddw_r2r(mm5, mm6); /* mm5 + mm6(dst) -> mm6 */
slouken@689
  1668
	                        pand_r2r(mm7, mm6); /* mm6 & MASKBLUE -> mm6 */
slouken@689
  1669
	
slouken@689
  1670
	                        movq_r2r(mm1, mm5); /* MASKRED -> mm5 */
slouken@689
  1671
	                        por_r2r(mm4, mm5);  /* MASKGREEN | mm5 -> mm5 */
slouken@689
  1672
	                        pand_r2r(mm5, mm3); /* mm3 & mm5(!MASKBLUE) -> mm3 */
slouken@689
  1673
	                        por_r2r(mm6, mm3); /* save new blues in dsts */
slouken@689
  1674
	
slouken@689
  1675
	                        movq_r2m(mm3, *dstp);/* mm3 -> 4 dst pixels */
slouken@689
  1676
	
slouken@689
  1677
	                        srcp += 4;
slouken@689
  1678
	                        dstp += 4;
slouken@689
  1679
                        }, width);			
slouken@689
  1680
			srcp += srcskip;
slouken@689
  1681
			dstp += dstskip;
slouken@689
  1682
		}
slouken@689
  1683
		emms();
slouken@689
  1684
	}
slouken@689
  1685
}
slouken@689
  1686
slouken@689
  1687
/* fast RGB555->RGB555 blending with surface alpha */
slouken@689
  1688
static void Blit555to555SurfaceAlphaMMX(SDL_BlitInfo *info)
slouken@689
  1689
{
slouken@689
  1690
	unsigned alpha = info->src->alpha; /* downscale alpha to 5 bits */
slouken@689
  1691
	if(alpha == 128) {
slouken@689
  1692
		Blit16to16SurfaceAlpha128(info, 0xfbde);
slouken@689
  1693
	} else {
slouken@689
  1694
		int width = info->d_width;
slouken@689
  1695
		int height = info->d_height;
slouken@689
  1696
		Uint16 *srcp = (Uint16 *)info->s_pixels;
slouken@689
  1697
		int srcskip = info->s_skip >> 1;
slouken@689
  1698
		Uint16 *dstp = (Uint16 *)info->d_pixels;
slouken@689
  1699
		int dstskip = info->d_skip >> 1;
slouken@689
  1700
	        Uint32 s, d;
slouken@689
  1701
	        Uint8 load[8];
slouken@689
  1702
	  
slouken@689
  1703
		alpha &= ~(1+2+4);		/* cut alpha to get the exact same behaviour */
slouken@689
  1704
	        *(Uint64 *)load = alpha;
slouken@689
  1705
		alpha >>= 3;		/* downscale alpha to 5 bits */
slouken@689
  1706
slouken@689
  1707
                movq_m2r(*load, mm0); /* alpha(0000000A) -> mm0 */
slouken@689
  1708
                punpcklwd_r2r(mm0, mm0); /* 00000A0A -> mm0 */
slouken@689
  1709
                punpcklwd_r2r(mm0, mm0); /* 0A0A0A0A -> mm0 */
slouken@689
  1710
	  
slouken@689
  1711
 	        /* Setup the 555 color channel masks */
slouken@720
  1712
	        *(Uint64 *)load = 0x7C007C007C007C00ULL;
slouken@689
  1713
		movq_m2r(*load, mm1); /* MASKRED -> mm1 */
slouken@720
  1714
		*(Uint64 *)load = 0x03E003E003E003E0ULL;
slouken@689
  1715
		movq_m2r(*load, mm4); /* MASKGREEN -> mm4 */
slouken@720
  1716
		*(Uint64 *)load = 0x001F001F001F001FULL;
slouken@689
  1717
		movq_m2r(*load, mm7); /* MASKBLUE -> mm7 */
slouken@689
  1718
		while(height--) {
slouken@689
  1719
                        DUFFS_LOOP_QUATRO2(
slouken@689
  1720
                        {
slouken@689
  1721
	                        s = *srcp++;
slouken@689
  1722
				d = *dstp;
slouken@689
  1723
				/*
slouken@689
  1724
				 * shift out the middle component (green) to
slouken@689
  1725
				 * the high 16 bits, and process all three RGB
slouken@689
  1726
				 * components at the same time.
slouken@689
  1727
				 */
slouken@689
  1728
				s = (s | s << 16) & 0x03e07c1f;
slouken@689
  1729
				d = (d | d << 16) & 0x03e07c1f;
slouken@689
  1730
				d += (s - d) * alpha >> 5;
slouken@689
  1731
				d &= 0x03e07c1f;
slouken@689
  1732
				*dstp++ = d | d >> 16;
slouken@689
  1733
                        },{
slouken@689
  1734
	                        s = *srcp++;
slouken@689
  1735
				d = *dstp;
slouken@689
  1736
				/*
slouken@689
  1737
				 * shift out the middle component (green) to
slouken@689
  1738
				 * the high 16 bits, and process all three RGB
slouken@689
  1739
				 * components at the same time.
slouken@689
  1740
				 */
slouken@689
  1741
				s = (s | s << 16) & 0x03e07c1f;
slouken@689
  1742
				d = (d | d << 16) & 0x03e07c1f;
slouken@689
  1743
				d += (s - d) * alpha >> 5;
slouken@689
  1744
				d &= 0x03e07c1f;
slouken@689
  1745
				*dstp++ = d | d >> 16;
slouken@689
  1746
			        s = *srcp++;
slouken@689
  1747
				d = *dstp;
slouken@689
  1748
				/*
slouken@689
  1749
				 * shift out the middle component (green) to
slouken@689
  1750
				 * the high 16 bits, and process all three RGB
slouken@689
  1751
				 * components at the same time.
slouken@689
  1752
				 */
slouken@689
  1753
				s = (s | s << 16) & 0x03e07c1f;
slouken@689
  1754
				d = (d | d << 16) & 0x03e07c1f;
slouken@689
  1755
				d += (s - d) * alpha >> 5;
slouken@689
  1756
				d &= 0x03e07c1f;
slouken@689
  1757
				*dstp++ = d | d >> 16;
slouken@689
  1758
                        },{
slouken@689
  1759
	                        movq_m2r((*dstp), mm3);/* 4 dst pixels -> mm3 */
slouken@689
  1760
	                        movq_m2r((*srcp), mm2);/* 4 src pixels -> mm2 */
slouken@689
  1761
			  
slouken@689
  1762
	                        /* RED */
slouken@689
  1763
	                        movq_r2r(mm2, mm5); /* src -> mm5 */
slouken@689
  1764
	                        pand_r2r(mm1 , mm5); /* src & MASKRED -> mm5 */
slouken@689
  1765
	                        psrlq_i2r(10, mm5); /* mm5 >> 10 -> mm5 [000r 000r 000r 000r] */
slouken@689
  1766
	
slouken@689
  1767
	                        movq_r2r(mm3, mm6); /* dst -> mm6 */
slouken@689
  1768
	                        pand_r2r(mm1 , mm6); /* dst & MASKRED -> mm6 */
slouken@689
  1769
	                        psrlq_i2r(10, mm6); /* mm6 >> 10 -> mm6 [000r 000r 000r 000r] */
slouken@689
  1770
	
slouken@689
  1771
	                        /* blend */
slouken@689
  1772
	                        psubw_r2r(mm6, mm5);/* src - dst -> mm5 */
slouken@689
  1773
	                        pmullw_r2r(mm0, mm5); /* mm5 * alpha -> mm5 */
slouken@689
  1774
	                        psrlw_i2r(8, mm5); /* mm5 >> 8 -> mm5 */
slouken@689
  1775
	                        paddw_r2r(mm5, mm6); /* mm5 + mm6(dst) -> mm6 */
slouken@689
  1776
	                        psllq_i2r(10, mm6); /* mm6 << 10 -> mm6 */
slouken@689
  1777
	                        pand_r2r(mm1, mm6); /* mm6 & MASKRED -> mm6 */
slouken@689
  1778
	
slouken@689
  1779
	                        movq_r2r(mm4, mm5); /* MASKGREEN -> mm5 */
slouken@689
  1780
	                        por_r2r(mm7, mm5);  /* MASKBLUE | mm5 -> mm5 */
slouken@689
  1781
	                        pand_r2r(mm5, mm3); /* mm3 & mm5(!MASKRED) -> mm3 */
slouken@689
  1782
	                        por_r2r(mm6, mm3); /* save new reds in dsts */
slouken@689
  1783
	
slouken@689
  1784
	                        /* green */
slouken@689
  1785
	                        movq_r2r(mm2, mm5); /* src -> mm5 */
slouken@689
  1786
	                        pand_r2r(mm4 , mm5); /* src & MASKGREEN -> mm5 */
slouken@689
  1787
	                        psrlq_i2r(5, mm5); /* mm5 >> 5 -> mm5 [000g 000g 000g 000g] */
slouken@689
  1788
	
slouken@689
  1789
	                        movq_r2r(mm3, mm6); /* dst -> mm6 */
slouken@689
  1790
	                        pand_r2r(mm4 , mm6); /* dst & MASKGREEN -> mm6 */
slouken@689
  1791
	                        psrlq_i2r(5, mm6); /* mm6 >> 5 -> mm6 [000g 000g 000g 000g] */
slouken@689
  1792
	
slouken@689
  1793
	                        /* blend */
slouken@689
  1794
	                        psubw_r2r(mm6, mm5);/* src - dst -> mm5 */
slouken@689
  1795
	                        pmullw_r2r(mm0, mm5); /* mm5 * alpha -> mm5 */
slouken@689
  1796
	                        psrlw_i2r(8, mm5); /* mm5 >> 8 -> mm5 */
slouken@689
  1797
	                        paddw_r2r(mm5, mm6); /* mm5 + mm6(dst) -> mm6 */
slouken@689
  1798
	                        psllq_i2r(5, mm6); /* mm6 << 5 -> mm6 */
slouken@689
  1799
	                        pand_r2r(mm4, mm6); /* mm6 & MASKGREEN -> mm6 */
slouken@689
  1800
	
slouken@689
  1801
	                        movq_r2r(mm1, mm5); /* MASKRED -> mm5 */
slouken@689
  1802
	                        por_r2r(mm7, mm5);  /* MASKBLUE | mm5 -> mm5 */
slouken@689
  1803
	                        pand_r2r(mm5, mm3); /* mm3 & mm5(!MASKGREEN) -> mm3 */
slouken@689
  1804
	                        por_r2r(mm6, mm3); /* save new greens in dsts */
slouken@689
  1805
	
slouken@689
  1806
	                        /* blue */
slouken@689
  1807
	                        movq_r2r(mm2, mm5); /* src -> mm5 */
slouken@689
  1808
	                        pand_r2r(mm7 , mm5); /* src & MASKRED -> mm5[000b 000b 000b 000b] */
slouken@689
  1809
		
slouken@689
  1810
	                        movq_r2r(mm3, mm6); /* dst -> mm6 */
slouken@689
  1811
	                        pand_r2r(mm7 , mm6); /* dst & MASKBLUE -> mm6[000b 000b 000b 000b] */
slouken@689
  1812
	
slouken@689
  1813
	                        /* blend */
slouken@689
  1814
	                        psubw_r2r(mm6, mm5);/* src - dst -> mm5 */
slouken@689
  1815
	                        pmullw_r2r(mm0, mm5); /* mm5 * alpha -> mm5 */
slouken@689
  1816
	                        psrlw_i2r(8, mm5); /* mm5 >> 8 -> mm5 */
slouken@689
  1817
	                        paddw_r2r(mm5, mm6); /* mm5 + mm6(dst) -> mm6 */
slouken@689
  1818
	                        pand_r2r(mm7, mm6); /* mm6 & MASKBLUE -> mm6 */
slouken@689
  1819
	
slouken@689
  1820
	                        movq_r2r(mm1, mm5); /* MASKRED -> mm5 */
slouken@689
  1821
	                        por_r2r(mm4, mm5);  /* MASKGREEN | mm5 -> mm5 */
slouken@689
  1822
	                        pand_r2r(mm5, mm3); /* mm3 & mm5(!MASKBLUE) -> mm3 */
slouken@689
  1823
	                        por_r2r(mm6, mm3); /* save new blues in dsts */
slouken@689
  1824
	
slouken@689
  1825
	                        movq_r2m(mm3, *dstp);/* mm3 -> 4 dst pixels */
slouken@689
  1826
	
slouken@689
  1827
	                        srcp += 4;
slouken@689
  1828
	                        dstp += 4;
slouken@689
  1829
                        }, width);			
slouken@689
  1830
			srcp += srcskip;
slouken@689
  1831
			dstp += dstskip;
slouken@689
  1832
		}
slouken@689
  1833
		emms();
slouken@689
  1834
	}
slouken@689
  1835
}
slouken@689
  1836
#endif
slouken@689
  1837
slouken@1
  1838
/* fast RGB565->RGB565 blending with surface alpha */
slouken@1
  1839
static void Blit565to565SurfaceAlpha(SDL_BlitInfo *info)
slouken@1
  1840
{
slouken@1
  1841
	unsigned alpha = info->src->alpha;
slouken@1
  1842
	if(alpha == 128) {
slouken@1
  1843
		Blit16to16SurfaceAlpha128(info, 0xf7de);
slouken@1
  1844
	} else {
slouken@1
  1845
		int width = info->d_width;
slouken@1
  1846
		int height = info->d_height;
slouken@1
  1847
		Uint16 *srcp = (Uint16 *)info->s_pixels;
slouken@1
  1848
		int srcskip = info->s_skip >> 1;
slouken@1
  1849
		Uint16 *dstp = (Uint16 *)info->d_pixels;
slouken@1
  1850
		int dstskip = info->d_skip >> 1;
slouken@1
  1851
		alpha >>= 3;	/* downscale alpha to 5 bits */
slouken@1
  1852
slouken@1
  1853
		while(height--) {
slouken@1
  1854
			DUFFS_LOOP4({
slouken@1
  1855
				Uint32 s = *srcp++;
slouken@1
  1856
				Uint32 d = *dstp;
slouken@1
  1857
				/*
slouken@1
  1858
				 * shift out the middle component (green) to
slouken@1
  1859
				 * the high 16 bits, and process all three RGB
slouken@1
  1860
				 * components at the same time.
slouken@1
  1861
				 */
slouken@1
  1862
				s = (s | s << 16) & 0x07e0f81f;
slouken@1
  1863
				d = (d | d << 16) & 0x07e0f81f;
slouken@1
  1864
				d += (s - d) * alpha >> 5;
slouken@1
  1865
				d &= 0x07e0f81f;
slouken@1
  1866
				*dstp++ = d | d >> 16;
slouken@1
  1867
			}, width);
slouken@1
  1868
			srcp += srcskip;
slouken@1
  1869
			dstp += dstskip;
slouken@1
  1870
		}
slouken@0
  1871
	}
slouken@0
  1872
}
slouken@0
  1873
slouken@0
  1874
/* fast RGB555->RGB555 blending with surface alpha */
slouken@0
  1875
static void Blit555to555SurfaceAlpha(SDL_BlitInfo *info)
slouken@0
  1876
{
slouken@1
  1877
	unsigned alpha = info->src->alpha; /* downscale alpha to 5 bits */
slouken@1
  1878
	if(alpha == 128) {
slouken@1
  1879
		Blit16to16SurfaceAlpha128(info, 0xfbde);
slouken@1
  1880
	} else {
slouken@1
  1881
		int width = info->d_width;
slouken@1
  1882
		int height = info->d_height;
slouken@1
  1883
		Uint16 *srcp = (Uint16 *)info->s_pixels;
slouken@1
  1884
		int srcskip = info->s_skip >> 1;
slouken@1
  1885
		Uint16 *dstp = (Uint16 *)info->d_pixels;
slouken@1
  1886
		int dstskip = info->d_skip >> 1;
slouken@1
  1887
		alpha >>= 3;		/* downscale alpha to 5 bits */
slouken@0
  1888
slouken@1
  1889
		while(height--) {
slouken@1
  1890
			DUFFS_LOOP4({
slouken@1
  1891
				Uint32 s = *srcp++;
slouken@1
  1892
				Uint32 d = *dstp;
slouken@1
  1893
				/*
slouken@1
  1894
				 * shift out the middle component (green) to
slouken@1
  1895
				 * the high 16 bits, and process all three RGB
slouken@1
  1896
				 * components at the same time.
slouken@1
  1897
				 */
slouken@1
  1898
				s = (s | s << 16) & 0x03e07c1f;
slouken@1
  1899
				d = (d | d << 16) & 0x03e07c1f;
slouken@1
  1900
				d += (s - d) * alpha >> 5;
slouken@1
  1901
				d &= 0x03e07c1f;
slouken@1
  1902
				*dstp++ = d | d >> 16;
slouken@1
  1903
			}, width);
slouken@1
  1904
			srcp += srcskip;
slouken@1
  1905
			dstp += dstskip;
slouken@1
  1906
		}
slouken@0
  1907
	}
slouken@0
  1908
}
slouken@0
  1909
slouken@0
  1910
/* fast ARGB8888->RGB565 blending with pixel alpha */
slouken@0
  1911
static void BlitARGBto565PixelAlpha(SDL_BlitInfo *info)
slouken@0
  1912
{
slouken@0
  1913
	int width = info->d_width;
slouken@0
  1914
	int height = info->d_height;
slouken@0
  1915
	Uint32 *srcp = (Uint32 *)info->s_pixels;
slouken@0
  1916
	int srcskip = info->s_skip >> 2;
slouken@0
  1917
	Uint16 *dstp = (Uint16 *)info->d_pixels;
slouken@0
  1918
	int dstskip = info->d_skip >> 1;
slouken@0
  1919
slouken@0
  1920
	while(height--) {
slouken@0
  1921
	    DUFFS_LOOP4({
slouken@0
  1922
		Uint32 s = *srcp;
slouken@0
  1923
		unsigned alpha = s >> 27; /* downscale alpha to 5 bits */
slouken@0
  1924
		/* FIXME: Here we special-case opaque alpha since the
slouken@0
  1925
		   compositioning used (>>8 instead of /255) doesn't handle
slouken@0
  1926
		   it correctly. Also special-case alpha=0 for speed?
slouken@0
  1927
		   Benchmark this! */
slouken@689
  1928
		if(alpha) {   
slouken@689
  1929
		  if(alpha == (SDL_ALPHA_OPAQUE >> 3)) {
slouken@0
  1930
		    *dstp = (s >> 8 & 0xf800) + (s >> 5 & 0x7e0)
slouken@0
  1931
			  + (s >> 3  & 0x1f);
slouken@689
  1932
		  } else {
slouken@0
  1933
		    Uint32 d = *dstp;
slouken@0
  1934
		    /*
slouken@0
  1935
		     * convert source and destination to G0RAB65565
slouken@0
  1936
		     * and blend all components at the same time
slouken@0
  1937
		     */
slouken@0
  1938
		    s = ((s & 0xfc00) << 11) + (s >> 8 & 0xf800)
slouken@0
  1939
		      + (s >> 3 & 0x1f);
slouken@0
  1940
		    d = (d | d << 16) & 0x07e0f81f;
slouken@0
  1941
		    d += (s - d) * alpha >> 5;
slouken@0
  1942
		    d &= 0x07e0f81f;
slouken@0
  1943
		    *dstp = d | d >> 16;
slouken@689
  1944
		  }
slouken@0
  1945
		}
slouken@0
  1946
		srcp++;
slouken@0
  1947
		dstp++;
slouken@0
  1948
	    }, width);
slouken@0
  1949
	    srcp += srcskip;
slouken@0
  1950
	    dstp += dstskip;
slouken@0
  1951
	}
slouken@0
  1952
}
slouken@0
  1953
slouken@0
  1954
/* fast ARGB8888->RGB555 blending with pixel alpha */
slouken@0
  1955
static void BlitARGBto555PixelAlpha(SDL_BlitInfo *info)
slouken@0
  1956
{
slouken@0
  1957
	int width = info->d_width;
slouken@0
  1958
	int height = info->d_height;
slouken@0
  1959
	Uint32 *srcp = (Uint32 *)info->s_pixels;
slouken@0
  1960
	int srcskip = info->s_skip >> 2;
slouken@0
  1961
	Uint16 *dstp = (Uint16 *)info->d_pixels;
slouken@0
  1962
	int dstskip = info->d_skip >> 1;
slouken@0
  1963
slouken@0
  1964
	while(height--) {
slouken@0
  1965
	    DUFFS_LOOP4({
slouken@0
  1966
		unsigned alpha;
slouken@0
  1967
		Uint32 s = *srcp;
slouken@0
  1968
		alpha = s >> 27; /* downscale alpha to 5 bits */
slouken@0
  1969
		/* FIXME: Here we special-case opaque alpha since the
slouken@0
  1970
		   compositioning used (>>8 instead of /255) doesn't handle
slouken@0
  1971
		   it correctly. Also special-case alpha=0 for speed?
slouken@0
  1972
		   Benchmark this! */
slouken@689
  1973
		if(alpha) {   
slouken@689
  1974
		  if(alpha == (SDL_ALPHA_OPAQUE >> 3)) {
slouken@0
  1975
		    *dstp = (s >> 9 & 0x7c00) + (s >> 6 & 0x3e0)
slouken@0
  1976
			  + (s >> 3  & 0x1f);
slouken@689
  1977
		  } else {
slouken@0
  1978
		    Uint32 d = *dstp;
slouken@0
  1979
		    /*
slouken@0
  1980
		     * convert source and destination to G0RAB65565
slouken@0
  1981
		     * and blend all components at the same time
slouken@0
  1982
		     */
slouken@0
  1983
		    s = ((s & 0xf800) << 10) + (s >> 9 & 0x7c00)
slouken@0
  1984
		      + (s >> 3 & 0x1f);
slouken@0
  1985
		    d = (d | d << 16) & 0x03e07c1f;
slouken@0
  1986
		    d += (s - d) * alpha >> 5;
slouken@0
  1987
		    d &= 0x03e07c1f;
slouken@0
  1988
		    *dstp = d | d >> 16;
slouken@689
  1989
		  }
slouken@0
  1990
		}
slouken@0
  1991
		srcp++;
slouken@0
  1992
		dstp++;
slouken@0
  1993
	    }, width);
slouken@0
  1994
	    srcp += srcskip;
slouken@0
  1995
	    dstp += dstskip;
slouken@0
  1996
	}
slouken@0
  1997
}
slouken@0
  1998
slouken@0
  1999
/* General (slow) N->N blending with per-surface alpha */
slouken@0
  2000
static void BlitNtoNSurfaceAlpha(SDL_BlitInfo *info)
slouken@0
  2001
{
slouken@0
  2002
	int width = info->d_width;
slouken@0
  2003
	int height = info->d_height;
slouken@0
  2004
	Uint8 *src = info->s_pixels;
slouken@0
  2005
	int srcskip = info->s_skip;
slouken@0
  2006
	Uint8 *dst = info->d_pixels;
slouken@0
  2007
	int dstskip = info->d_skip;
slouken@0
  2008
	SDL_PixelFormat *srcfmt = info->src;
slouken@0
  2009
	SDL_PixelFormat *dstfmt = info->dst;
slouken@0
  2010
	int srcbpp = srcfmt->BytesPerPixel;
slouken@0
  2011
	int dstbpp = dstfmt->BytesPerPixel;
slouken@0
  2012
	unsigned sA = srcfmt->alpha;
slouken@0
  2013
	unsigned dA = dstfmt->Amask ? SDL_ALPHA_OPAQUE : 0;
slouken@0
  2014
slouken@689
  2015
	if(sA) {
slouken@689
  2016
	  while ( height-- ) {
slouken@0
  2017
	    DUFFS_LOOP4(
slouken@0
  2018
	    {
icculus@1162
  2019
		Uint32 Pixel;
slouken@0
  2020
		unsigned sR;
slouken@0
  2021
		unsigned sG;
slouken@0
  2022
		unsigned sB;
slouken@0
  2023
		unsigned dR;
slouken@0
  2024
		unsigned dG;
slouken@0
  2025
		unsigned dB;
icculus@1162
  2026
		DISEMBLE_RGB(src, srcbpp, srcfmt, Pixel, sR, sG, sB);
icculus@1162
  2027
		DISEMBLE_RGB(dst, dstbpp, dstfmt, Pixel, dR, dG, dB);
slouken@0
  2028
		ALPHA_BLEND(sR, sG, sB, sA, dR, dG, dB);
slouken@0
  2029
		ASSEMBLE_RGBA(dst, dstbpp, dstfmt, dR, dG, dB, dA);
slouken@0
  2030
		src += srcbpp;
slouken@0
  2031
		dst += dstbpp;
slouken@0
  2032
	    },
slouken@0
  2033
	    width);
slouken@0
  2034
	    src += srcskip;
slouken@0
  2035
	    dst += dstskip;
slouken@689
  2036
	  }
slouken@0
  2037
	}
slouken@0
  2038
}
slouken@0
  2039
slouken@0
  2040
/* General (slow) colorkeyed N->N blending with per-surface alpha */
slouken@0
  2041
static void BlitNtoNSurfaceAlphaKey(SDL_BlitInfo *info)
slouken@0
  2042
{
slouken@0
  2043
	int width = info->d_width;
slouken@0
  2044
	int height = info->d_height;
slouken@0
  2045
	Uint8 *src = info->s_pixels;
slouken@0
  2046
	int srcskip = info->s_skip;
slouken@0
  2047
	Uint8 *dst = info->d_pixels;
slouken@0
  2048
	int dstskip = info->d_skip;
slouken@0
  2049
	SDL_PixelFormat *srcfmt = info->src;
slouken@0
  2050
	SDL_PixelFormat *dstfmt = info->dst;
slouken@0
  2051
	Uint32 ckey = srcfmt->colorkey;
slouken@0
  2052
	int srcbpp = srcfmt->BytesPerPixel;
slouken@0
  2053
	int dstbpp = dstfmt->BytesPerPixel;
slouken@0
  2054
	unsigned sA = srcfmt->alpha;
slouken@0
  2055
	unsigned dA = dstfmt->Amask ? SDL_ALPHA_OPAQUE : 0;
slouken@0
  2056
slouken@0
  2057
	while ( height-- ) {
slouken@0
  2058
	    DUFFS_LOOP4(
slouken@0
  2059
	    {
icculus@1162
  2060
		Uint32 Pixel;
slouken@0
  2061
		unsigned sR;
slouken@0
  2062
		unsigned sG;
slouken@0
  2063
		unsigned sB;
slouken@0
  2064
		unsigned dR;
slouken@0
  2065
		unsigned dG;
slouken@0
  2066
		unsigned dB;
icculus@1162
  2067
		RETRIEVE_RGB_PIXEL(src, srcbpp, Pixel);
icculus@1162
  2068
		if(sA && Pixel != ckey) {
icculus@1162
  2069
		    RGB_FROM_PIXEL(Pixel, srcfmt, sR, sG, sB);
icculus@1162
  2070
		    DISEMBLE_RGB(dst, dstbpp, dstfmt, Pixel, dR, dG, dB);
slouken@0
  2071
		    ALPHA_BLEND(sR, sG, sB, sA, dR, dG, dB);
slouken@0
  2072
		    ASSEMBLE_RGBA(dst, dstbpp, dstfmt, dR, dG, dB, dA);
slouken@0
  2073
		}
slouken@0
  2074
		src += srcbpp;
slouken@0
  2075
		dst += dstbpp;
slouken@0
  2076
	    },
slouken@0
  2077
	    width);
slouken@0
  2078
	    src += srcskip;
slouken@0
  2079
	    dst += dstskip;
slouken@0
  2080
	}
slouken@0
  2081
}
slouken@0
  2082
slouken@0
  2083
/* General (slow) N->N blending with pixel alpha */
slouken@0
  2084
static void BlitNtoNPixelAlpha(SDL_BlitInfo *info)
slouken@0
  2085
{
slouken@0
  2086
	int width = info->d_width;
slouken@0
  2087
	int height = info->d_height;
slouken@0
  2088
	Uint8 *src = info->s_pixels;
slouken@0
  2089
	int srcskip = info->s_skip;
slouken@0
  2090
	Uint8 *dst = info->d_pixels;
slouken@0
  2091
	int dstskip = info->d_skip;
slouken@0
  2092
	SDL_PixelFormat *srcfmt = info->src;
slouken@0
  2093
	SDL_PixelFormat *dstfmt = info->dst;
slouken@0
  2094
slouken@0
  2095
	int  srcbpp;
slouken@0
  2096
	int  dstbpp;
slouken@0
  2097
slouken@0
  2098
	/* Set up some basic variables */
slouken@0
  2099
	srcbpp = srcfmt->BytesPerPixel;
slouken@0
  2100
	dstbpp = dstfmt->BytesPerPixel;
slouken@0
  2101
slouken@0
  2102
	/* FIXME: for 8bpp source alpha, this doesn't get opaque values
slouken@0
  2103
	   quite right. for <8bpp source alpha, it gets them very wrong
slouken@0
  2104
	   (check all macros!)
slouken@0
  2105
	   It is unclear whether there is a good general solution that doesn't
slouken@0
  2106
	   need a branch (or a divide). */
slouken@0
  2107
	while ( height-- ) {
slouken@0
  2108
	    DUFFS_LOOP4(
slouken@0
  2109
	    {
icculus@1162
  2110
		Uint32 Pixel;
slouken@0
  2111
		unsigned sR;
slouken@0
  2112
		unsigned sG;
slouken@0
  2113
		unsigned sB;
slouken@0
  2114
		unsigned dR;
slouken@0
  2115
		unsigned dG;
slouken@0
  2116
		unsigned dB;
slouken@0
  2117
		unsigned sA;
slouken@0
  2118
		unsigned dA;
icculus@1162
  2119
		DISEMBLE_RGBA(src, srcbpp, srcfmt, Pixel, sR, sG, sB, sA);
slouken@689
  2120
		if(sA) {
icculus@1162
  2121
		  DISEMBLE_RGBA(dst, dstbpp, dstfmt, Pixel, dR, dG, dB, dA);
slouken@689
  2122
		  ALPHA_BLEND(sR, sG, sB, sA, dR, dG, dB);
slouken@689
  2123
		  ASSEMBLE_RGBA(dst, dstbpp, dstfmt, dR, dG, dB, dA);
slouken@689
  2124
		}
slouken@0
  2125
		src += srcbpp;
slouken@0
  2126
		dst += dstbpp;
slouken@0
  2127
	    },
slouken@0
  2128
	    width);
slouken@0
  2129
	    src += srcskip;
slouken@0
  2130
	    dst += dstskip;
slouken@0
  2131
	}
slouken@0
  2132
}
slouken@0
  2133
slouken@0
  2134
slouken@0
  2135
SDL_loblit SDL_CalculateAlphaBlit(SDL_Surface *surface, int blit_index)
slouken@0
  2136
{
slouken@0
  2137
    SDL_PixelFormat *sf = surface->format;
slouken@0
  2138
    SDL_PixelFormat *df = surface->map->dst->format;
slouken@0
  2139
slouken@0
  2140
    if(sf->Amask == 0) {
slouken@0
  2141
	if((surface->flags & SDL_SRCCOLORKEY) == SDL_SRCCOLORKEY) {
slouken@0
  2142
	    if(df->BytesPerPixel == 1)
slouken@0
  2143
		return BlitNto1SurfaceAlphaKey;
slouken@0
  2144
	    else
icculus@1047
  2145
#ifdef USE_ALTIVEC_BLITTERS
icculus@1047
  2146
        if (sf->BytesPerPixel == 4 && df->BytesPerPixel == 4 && SDL_HasAltiVec())
icculus@1047
  2147
            return Blit32to32SurfaceAlphaKeyAltivec;
icculus@1047
  2148
        else
icculus@1047
  2149
#endif
icculus@1047
  2150
            return BlitNtoNSurfaceAlphaKey;
slouken@0
  2151
	} else {
slouken@0
  2152
	    /* Per-surface alpha blits */
slouken@0
  2153
	    switch(df->BytesPerPixel) {
slouken@0
  2154
	    case 1:
slouken@0
  2155
		return BlitNto1SurfaceAlpha;
slouken@0
  2156
slouken@0
  2157
	    case 2:
slouken@0
  2158
		if(surface->map->identity) {
slouken@0
  2159
		    if(df->Gmask == 0x7e0)
slouken@689
  2160
		    {
slouken@880
  2161
#ifdef MMX_ASMBLIT
slouken@739
  2162
		if(SDL_HasMMX())
slouken@689
  2163
			return Blit565to565SurfaceAlphaMMX;
slouken@689
  2164
		else
slouken@689
  2165
#endif
slouken@0
  2166
			return Blit565to565SurfaceAlpha;
slouken@689
  2167
		    }
slouken@0
  2168
		    else if(df->Gmask == 0x3e0)
slouken@689
  2169
		    {
slouken@880
  2170
#ifdef MMX_ASMBLIT
slouken@739
  2171
		if(SDL_HasMMX())
slouken@689
  2172
			return Blit555to555SurfaceAlphaMMX;
slouken@689
  2173
		else
slouken@689
  2174
#endif
slouken@0
  2175
			return Blit555to555SurfaceAlpha;
slouken@689
  2176
		    }
slouken@0
  2177
		}
slouken@0
  2178
		return BlitNtoNSurfaceAlpha;
slouken@0
  2179
slouken@0
  2180
	    case 4:
slouken@0
  2181
		if(sf->Rmask == df->Rmask
slouken@0
  2182
		   && sf->Gmask == df->Gmask
slouken@0
  2183
		   && sf->Bmask == df->Bmask
slouken@0
  2184
		   && (sf->Rmask | sf->Gmask | sf->Bmask) == 0xffffff
slouken@0
  2185
		   && sf->BytesPerPixel == 4)
slouken@689
  2186
		{
slouken@880
  2187
#ifdef MMX_ASMBLIT
slouken@739
  2188
		if(SDL_HasMMX())
slouken@689
  2189
		    return BlitRGBtoRGBSurfaceAlphaMMX;
slouken@689
  2190
		else
slouken@689
  2191
#endif
icculus@1047
  2192
#ifdef USE_ALTIVEC_BLITTERS
icculus@1047
  2193
        if(SDL_HasAltiVec())
icculus@1047
  2194
            return BlitRGBtoRGBSurfaceAlphaAltivec;
icculus@1047
  2195
        else
icculus@1047
  2196
#endif
slouken@0
  2197
		    return BlitRGBtoRGBSurfaceAlpha;
slouken@689
  2198
		}
slouken@0
  2199
		else
icculus@1047
  2200
#ifdef USE_ALTIVEC_BLITTERS
icculus@1047
  2201
        if((sf->BytesPerPixel == 4) && SDL_HasAltiVec())
icculus@1047
  2202
            return Blit32to32SurfaceAlphaAltivec;
icculus@1047
  2203
        else
icculus@1047
  2204
#endif
slouken@0
  2205
		    return BlitNtoNSurfaceAlpha;
slouken@0
  2206
slouken@0
  2207
	    case 3:
slouken@0
  2208
	    default:
slouken@0
  2209
		return BlitNtoNSurfaceAlpha;
slouken@0
  2210
	    }
slouken@0
  2211
	}
slouken@0
  2212
    } else {
slouken@0
  2213
	/* Per-pixel alpha blits */
slouken@0
  2214
	switch(df->BytesPerPixel) {
slouken@0
  2215
	case 1:
slouken@0
  2216
	    return BlitNto1PixelAlpha;
slouken@0
  2217
slouken@0
  2218
	case 2:
icculus@1047
  2219
#ifdef USE_ALTIVEC_BLITTERS
icculus@1047
  2220
        if(sf->BytesPerPixel == 4 && 
icculus@1047
  2221
           df->Gmask == 0x7e0 &&
icculus@1047
  2222
           df->Bmask == 0x1f)
icculus@1047
  2223
            return Blit32to565PixelAlphaAltivec;
icculus@1047
  2224
        else
icculus@1047
  2225
#endif
slouken@0
  2226
	    if(sf->BytesPerPixel == 4 && sf->Amask == 0xff000000
slouken@0
  2227
	       && sf->Gmask == 0xff00
slouken@0
  2228
	       && ((sf->Rmask == 0xff && df->Rmask == 0x1f)
slouken@0
  2229
		   || (sf->Bmask == 0xff && df->Bmask == 0x1f))) {
slouken@0
  2230
		if(df->Gmask == 0x7e0)
slouken@0
  2231
		    return BlitARGBto565PixelAlpha;
slouken@0
  2232
		else if(df->Gmask == 0x3e0)
slouken@0
  2233
		    return BlitARGBto555PixelAlpha;
slouken@0
  2234
	    }
slouken@0
  2235
	    return BlitNtoNPixelAlpha;
slouken@0
  2236
slouken@0
  2237
	case 4:
slouken@0
  2238
	    if(sf->Amask == 0xff000000
slouken@0
  2239
	       && sf->Rmask == df->Rmask
slouken@0
  2240
	       && sf->Gmask == df->Gmask
slouken@0
  2241
	       && sf->Bmask == df->Bmask
slouken@0
  2242
	       && sf->BytesPerPixel == 4)
slouken@689
  2243
	    {
slouken@880
  2244
#ifdef MMX_ASMBLIT
slouken@739
  2245
		if(SDL_Has3DNow())
slouken@689
  2246
		    return BlitRGBtoRGBPixelAlphaMMX3DNOW;
slouken@689
  2247
		else
slouken@739
  2248
		if(SDL_HasMMX())
slouken@689
  2249
		    return BlitRGBtoRGBPixelAlphaMMX;
slouken@689
  2250
		else
slouken@689
  2251
#endif
icculus@1047
  2252
#ifdef USE_ALTIVEC_BLITTERS
icculus@1047
  2253
        if(SDL_HasAltiVec())
icculus@1047
  2254
            return BlitRGBtoRGBPixelAlphaAltivec;
icculus@1047
  2255
        else
icculus@1047
  2256
#endif
slouken@689
  2257
		    return BlitRGBtoRGBPixelAlpha;
slouken@689
  2258
	    }
icculus@1047
  2259
#ifdef USE_ALTIVEC_BLITTERS
icculus@1047
  2260
        if (sf->Amask && sf->BytesPerPixel == 4 && SDL_HasAltiVec())
icculus@1047
  2261
            return Blit32to32PixelAlphaAltivec;
icculus@1047
  2262
        else
icculus@1047
  2263
#endif
slouken@0
  2264
	    return BlitNtoNPixelAlpha;
slouken@0
  2265
slouken@0
  2266
	case 3:
slouken@0
  2267
	default:
slouken@0
  2268
	    return BlitNtoNPixelAlpha;
slouken@0
  2269
	}
slouken@0
  2270
    }
slouken@0
  2271
}
slouken@0
  2272