src/video/SDL_blit_A.c
author Sam Lantinga <slouken@libsdl.org>
Wed, 12 Apr 2006 14:19:11 +0000
changeset 1617 b255b4058d37
parent 1546 4b835e36633d
child 1659 14717b52abc0
permissions -rw-r--r--
Patch from Alex to fix reverted code
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
     1
/*
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
     2
    SDL - Simple DirectMedia Layer
1312
c9b51268668f Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents: 1240
diff changeset
     3
    Copyright (C) 1997-2006 Sam Lantinga
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
     4
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
     5
    This library is free software; you can redistribute it and/or
1312
c9b51268668f Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents: 1240
diff changeset
     6
    modify it under the terms of the GNU Lesser General Public
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
     7
    License as published by the Free Software Foundation; either
1312
c9b51268668f Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents: 1240
diff changeset
     8
    version 2.1 of the License, or (at your option) any later version.
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
     9
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    10
    This library is distributed in the hope that it will be useful,
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    11
    but WITHOUT ANY WARRANTY; without even the implied warranty of
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    12
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
1312
c9b51268668f Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents: 1240
diff changeset
    13
    Lesser General Public License for more details.
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    14
1312
c9b51268668f Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents: 1240
diff changeset
    15
    You should have received a copy of the GNU Lesser General Public
c9b51268668f Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents: 1240
diff changeset
    16
    License along with this library; if not, write to the Free Software
c9b51268668f Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents: 1240
diff changeset
    17
    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    18
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    19
    Sam Lantinga
252
e8157fcb3114 Updated the source with the correct e-mail address
Sam Lantinga <slouken@libsdl.org>
parents: 1
diff changeset
    20
    slouken@libsdl.org
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    21
*/
1402
d910939febfa Use consistent identifiers for the various platforms we support.
Sam Lantinga <slouken@libsdl.org>
parents: 1361
diff changeset
    22
#include "SDL_config.h"
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    23
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    24
#include "SDL_video.h"
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    25
#include "SDL_blit.h"
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    26
1542
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
    27
#if SDL_ASSEMBLY_ROUTINES
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
    28
#if defined(__GNUC__) && (defined(__i386__) || defined(__x86_64__))
1361
19418e4422cb New configure-based build system. Still work in progress, but much improved
Sam Lantinga <slouken@libsdl.org>
parents: 1358
diff changeset
    29
#define MMX_ASMBLIT 1
1542
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
    30
#define GCC_ASMBLIT 1
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
    31
#elif defined(_MSC_VER) && (_MSC_VER >= 1200) && defined(_M_IX86)
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
    32
#define MMX_ASMBLIT 1
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
    33
#define MSVC_ASMBLIT 1
880
9ef41050100c Date: Tue, 30 Mar 2004 21:26:47 -0600
Sam Lantinga <slouken@libsdl.org>
parents: 769
diff changeset
    34
#endif
1542
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
    35
#endif /* SDL_ASSEMBLY_ROUTINES */
880
9ef41050100c Date: Tue, 30 Mar 2004 21:26:47 -0600
Sam Lantinga <slouken@libsdl.org>
parents: 769
diff changeset
    36
739
22dbf364c017 Added SDL_HasMMX(), SDL_Has3DNow(), SDL_HasSSE() in SDL_cpuinfo.h
Sam Lantinga <slouken@libsdl.org>
parents: 720
diff changeset
    37
/* Function to check the CPU flags */
22dbf364c017 Added SDL_HasMMX(), SDL_Has3DNow(), SDL_HasSSE() in SDL_cpuinfo.h
Sam Lantinga <slouken@libsdl.org>
parents: 720
diff changeset
    38
#include "SDL_cpuinfo.h"
1542
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
    39
#if GCC_ASMBLIT
689
5bb080d35049 Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
    40
#include "mmx.h"
1542
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
    41
#elif MSVC_ASMBLIT
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
    42
#include <mmintrin.h>
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
    43
#include <mm3dnow.h>
689
5bb080d35049 Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
    44
#endif
5bb080d35049 Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
    45
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    46
/* Functions to perform alpha blended blitting */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    47
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    48
/* N->1 blending with per-surface alpha */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    49
static void BlitNto1SurfaceAlpha(SDL_BlitInfo *info)
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    50
{
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    51
	int width = info->d_width;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    52
	int height = info->d_height;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    53
	Uint8 *src = info->s_pixels;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    54
	int srcskip = info->s_skip;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    55
	Uint8 *dst = info->d_pixels;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    56
	int dstskip = info->d_skip;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    57
	Uint8 *palmap = info->table;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    58
	SDL_PixelFormat *srcfmt = info->src;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    59
	SDL_PixelFormat *dstfmt = info->dst;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    60
	int srcbpp = srcfmt->BytesPerPixel;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    61
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    62
	const unsigned A = srcfmt->alpha;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    63
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    64
	while ( height-- ) {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    65
	    DUFFS_LOOP4(
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    66
	    {
1162
2651158f59b8 Enable altivec blitters on PowerPC Linux, and some fixes for recent
Ryan C. Gordon <icculus@icculus.org>
parents: 1047
diff changeset
    67
		Uint32 Pixel;
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    68
		unsigned sR;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    69
		unsigned sG;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    70
		unsigned sB;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    71
		unsigned dR;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    72
		unsigned dG;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    73
		unsigned dB;
1162
2651158f59b8 Enable altivec blitters on PowerPC Linux, and some fixes for recent
Ryan C. Gordon <icculus@icculus.org>
parents: 1047
diff changeset
    74
		DISEMBLE_RGB(src, srcbpp, srcfmt, Pixel, sR, sG, sB);
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    75
		dR = dstfmt->palette->colors[*dst].r;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    76
		dG = dstfmt->palette->colors[*dst].g;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    77
		dB = dstfmt->palette->colors[*dst].b;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    78
		ALPHA_BLEND(sR, sG, sB, A, dR, dG, dB);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    79
		dR &= 0xff;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    80
		dG &= 0xff;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    81
		dB &= 0xff;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    82
		/* Pack RGB into 8bit pixel */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    83
		if ( palmap == NULL ) {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    84
		    *dst =((dR>>5)<<(3+2))|
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    85
			  ((dG>>5)<<(2))|
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    86
			  ((dB>>6)<<(0));
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    87
		} else {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    88
		    *dst = palmap[((dR>>5)<<(3+2))|
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    89
				  ((dG>>5)<<(2))  |
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    90
				  ((dB>>6)<<(0))];
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    91
		}
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    92
		dst++;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    93
		src += srcbpp;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    94
	    },
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    95
	    width);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    96
	    src += srcskip;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    97
	    dst += dstskip;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    98
	}
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    99
}
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   100
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   101
/* N->1 blending with pixel alpha */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   102
static void BlitNto1PixelAlpha(SDL_BlitInfo *info)
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   103
{
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   104
	int width = info->d_width;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   105
	int height = info->d_height;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   106
	Uint8 *src = info->s_pixels;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   107
	int srcskip = info->s_skip;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   108
	Uint8 *dst = info->d_pixels;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   109
	int dstskip = info->d_skip;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   110
	Uint8 *palmap = info->table;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   111
	SDL_PixelFormat *srcfmt = info->src;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   112
	SDL_PixelFormat *dstfmt = info->dst;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   113
	int srcbpp = srcfmt->BytesPerPixel;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   114
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   115
	/* FIXME: fix alpha bit field expansion here too? */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   116
	while ( height-- ) {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   117
	    DUFFS_LOOP4(
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   118
	    {
1162
2651158f59b8 Enable altivec blitters on PowerPC Linux, and some fixes for recent
Ryan C. Gordon <icculus@icculus.org>
parents: 1047
diff changeset
   119
		Uint32 Pixel;
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   120
		unsigned sR;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   121
		unsigned sG;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   122
		unsigned sB;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   123
		unsigned sA;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   124
		unsigned dR;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   125
		unsigned dG;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   126
		unsigned dB;
1162
2651158f59b8 Enable altivec blitters on PowerPC Linux, and some fixes for recent
Ryan C. Gordon <icculus@icculus.org>
parents: 1047
diff changeset
   127
		DISEMBLE_RGBA(src,srcbpp,srcfmt,Pixel,sR,sG,sB,sA);
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   128
		dR = dstfmt->palette->colors[*dst].r;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   129
		dG = dstfmt->palette->colors[*dst].g;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   130
		dB = dstfmt->palette->colors[*dst].b;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   131
		ALPHA_BLEND(sR, sG, sB, sA, dR, dG, dB);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   132
		dR &= 0xff;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   133
		dG &= 0xff;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   134
		dB &= 0xff;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   135
		/* Pack RGB into 8bit pixel */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   136
		if ( palmap == NULL ) {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   137
		    *dst =((dR>>5)<<(3+2))|
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   138
			  ((dG>>5)<<(2))|
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   139
			  ((dB>>6)<<(0));
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   140
		} else {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   141
		    *dst = palmap[((dR>>5)<<(3+2))|
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   142
				  ((dG>>5)<<(2))  |
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   143
				  ((dB>>6)<<(0))  ];
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   144
		}
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   145
		dst++;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   146
		src += srcbpp;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   147
	    },
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   148
	    width);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   149
	    src += srcskip;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   150
	    dst += dstskip;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   151
	}
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   152
}
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   153
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   154
/* colorkeyed N->1 blending with per-surface alpha */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   155
static void BlitNto1SurfaceAlphaKey(SDL_BlitInfo *info)
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   156
{
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   157
	int width = info->d_width;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   158
	int height = info->d_height;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   159
	Uint8 *src = info->s_pixels;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   160
	int srcskip = info->s_skip;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   161
	Uint8 *dst = info->d_pixels;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   162
	int dstskip = info->d_skip;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   163
	Uint8 *palmap = info->table;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   164
	SDL_PixelFormat *srcfmt = info->src;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   165
	SDL_PixelFormat *dstfmt = info->dst;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   166
	int srcbpp = srcfmt->BytesPerPixel;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   167
	Uint32 ckey = srcfmt->colorkey;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   168
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   169
	const int A = srcfmt->alpha;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   170
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   171
	while ( height-- ) {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   172
	    DUFFS_LOOP(
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   173
	    {
1162
2651158f59b8 Enable altivec blitters on PowerPC Linux, and some fixes for recent
Ryan C. Gordon <icculus@icculus.org>
parents: 1047
diff changeset
   174
		Uint32 Pixel;
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   175
		unsigned sR;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   176
		unsigned sG;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   177
		unsigned sB;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   178
		unsigned dR;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   179
		unsigned dG;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   180
		unsigned dB;
1162
2651158f59b8 Enable altivec blitters on PowerPC Linux, and some fixes for recent
Ryan C. Gordon <icculus@icculus.org>
parents: 1047
diff changeset
   181
		DISEMBLE_RGB(src, srcbpp, srcfmt, Pixel, sR, sG, sB);
2651158f59b8 Enable altivec blitters on PowerPC Linux, and some fixes for recent
Ryan C. Gordon <icculus@icculus.org>
parents: 1047
diff changeset
   182
		if ( Pixel != ckey ) {
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   183
		    dR = dstfmt->palette->colors[*dst].r;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   184
		    dG = dstfmt->palette->colors[*dst].g;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   185
		    dB = dstfmt->palette->colors[*dst].b;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   186
		    ALPHA_BLEND(sR, sG, sB, A, dR, dG, dB);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   187
		    dR &= 0xff;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   188
		    dG &= 0xff;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   189
		    dB &= 0xff;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   190
		    /* Pack RGB into 8bit pixel */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   191
		    if ( palmap == NULL ) {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   192
			*dst =((dR>>5)<<(3+2))|
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   193
			      ((dG>>5)<<(2)) |
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   194
			      ((dB>>6)<<(0));
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   195
		    } else {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   196
			*dst = palmap[((dR>>5)<<(3+2))|
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   197
				      ((dG>>5)<<(2))  |
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   198
				      ((dB>>6)<<(0))  ];
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   199
		    }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   200
		}
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   201
		dst++;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   202
		src += srcbpp;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   203
	    },
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   204
	    width);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   205
	    src += srcskip;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   206
	    dst += dstskip;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   207
	}
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   208
}
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   209
1542
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   210
#if GCC_ASMBLIT
689
5bb080d35049 Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
   211
/* fast RGB888->(A)RGB888 blending with surface alpha=128 special case */
5bb080d35049 Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
   212
static void BlitRGBtoRGBSurfaceAlpha128MMX(SDL_BlitInfo *info)
5bb080d35049 Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
   213
{
5bb080d35049 Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
   214
	int width = info->d_width;
5bb080d35049 Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
   215
	int height = info->d_height;
5bb080d35049 Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
   216
	Uint32 *srcp = (Uint32 *)info->s_pixels;
5bb080d35049 Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
   217
	int srcskip = info->s_skip >> 2;
5bb080d35049 Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
   218
	Uint32 *dstp = (Uint32 *)info->d_pixels;
5bb080d35049 Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
   219
	int dstskip = info->d_skip >> 2;
1542
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   220
	Uint32 dalpha = info->dst->Amask;
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   221
	Uint8 load[8];
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   222
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   223
	*(Uint64 *)load = 0x00fefefe00fefefeULL;/* alpha128 mask */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   224
	movq_m2r(*load, mm4); /* alpha128 mask -> mm4 */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   225
	*(Uint64 *)load = 0x0001010100010101ULL;/* !alpha128 mask */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   226
	movq_m2r(*load, mm3); /* !alpha128 mask -> mm3 */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   227
	movd_m2r(dalpha, mm7); /* dst alpha mask */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   228
	punpckldq_r2r(mm7, mm7); /* dst alpha mask | dst alpha mask -> mm7 */
689
5bb080d35049 Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
   229
	while(height--) {
1542
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   230
		DUFFS_LOOP_DOUBLE2(
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   231
		{
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   232
			Uint32 s = *srcp++;
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   233
			Uint32 d = *dstp;
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   234
			*dstp++ = ((((s & 0x00fefefe) + (d & 0x00fefefe)) >> 1)
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   235
				   + (s & d & 0x00010101)) | dalpha;
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   236
		},{
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   237
			movq_m2r((*dstp), mm2);/* 2 x dst -> mm2(ARGBARGB) */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   238
			movq_r2r(mm2, mm6); /* 2 x dst -> mm6(ARGBARGB) */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   239
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   240
			movq_m2r((*srcp), mm1);/* 2 x src -> mm1(ARGBARGB) */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   241
			movq_r2r(mm1, mm5); /* 2 x src -> mm5(ARGBARGB) */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   242
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   243
			pand_r2r(mm4, mm6); /* dst & mask -> mm6 */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   244
			pand_r2r(mm4, mm5); /* src & mask -> mm5 */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   245
			paddd_r2r(mm6, mm5); /* mm6 + mm5 -> mm5 */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   246
			pand_r2r(mm1, mm2); /* src & dst -> mm2 */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   247
			psrld_i2r(1, mm5); /* mm5 >> 1 -> mm5 */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   248
			pand_r2r(mm3, mm2); /* mm2 & !mask -> mm2 */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   249
			paddd_r2r(mm5, mm2); /* mm5 + mm2 -> mm2 */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   250
			
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   251
			por_r2r(mm7, mm2); /* mm7(full alpha) | mm2 -> mm2 */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   252
			movq_r2m(mm2, (*dstp));/* mm2 -> 2 x dst pixels */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   253
			dstp += 2;
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   254
			srcp += 2;
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   255
		}, width);
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   256
		srcp += srcskip;
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   257
		dstp += dstskip;
689
5bb080d35049 Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
   258
	}
5bb080d35049 Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
   259
	emms();
5bb080d35049 Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
   260
}
5bb080d35049 Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
   261
5bb080d35049 Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
   262
/* fast RGB888->(A)RGB888 blending with surface alpha */
5bb080d35049 Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
   263
static void BlitRGBtoRGBSurfaceAlphaMMX(SDL_BlitInfo *info)
5bb080d35049 Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
   264
{
1542
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   265
	SDL_PixelFormat* df = info->dst;
689
5bb080d35049 Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
   266
	unsigned alpha = info->src->alpha;
1542
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   267
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   268
	if (alpha == 128 && (df->Rmask | df->Gmask | df->Bmask) == 0x00FFFFFF) {
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   269
			/* only call a128 version when R,G,B occupy lower bits */
689
5bb080d35049 Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
   270
		BlitRGBtoRGBSurfaceAlpha128MMX(info);
5bb080d35049 Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
   271
	} else {
5bb080d35049 Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
   272
		int width = info->d_width;
5bb080d35049 Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
   273
		int height = info->d_height;
5bb080d35049 Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
   274
		Uint32 *srcp = (Uint32 *)info->s_pixels;
5bb080d35049 Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
   275
		int srcskip = info->s_skip >> 2;
5bb080d35049 Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
   276
		Uint32 *dstp = (Uint32 *)info->d_pixels;
5bb080d35049 Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
   277
		int dstskip = info->d_skip >> 2;
1542
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   278
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   279
		pxor_r2r(mm5, mm5); /* 0 -> mm5 */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   280
		/* form the alpha mult */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   281
		movd_m2r(alpha, mm4); /* 0000000A -> mm4 */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   282
		punpcklwd_r2r(mm4, mm4); /* 00000A0A -> mm4 */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   283
		punpckldq_r2r(mm4, mm4); /* 0A0A0A0A -> mm4 */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   284
		alpha = (0xff << df->Rshift) | (0xff << df->Gshift) | (0xff << df->Bshift);
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   285
		movd_m2r(alpha, mm0); /* 00000FFF -> mm0 */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   286
		punpcklbw_r2r(mm0, mm0); /* 00FFFFFF -> mm0 */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   287
		pand_r2r(mm0, mm4); /* 0A0A0A0A -> mm4, minus 1 chan */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   288
			/* at this point mm4 can be 000A0A0A or 0A0A0A00 or another combo */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   289
		movd_m2r(df->Amask, mm7); /* dst alpha mask */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   290
		punpckldq_r2r(mm7, mm7); /* dst alpha mask | dst alpha mask -> mm7 */
689
5bb080d35049 Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
   291
		
5bb080d35049 Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
   292
		while(height--) {
5bb080d35049 Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
   293
			DUFFS_LOOP_DOUBLE2({
5bb080d35049 Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
   294
				/* One Pixel Blend */
1542
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   295
				movd_m2r((*srcp), mm1);/* src(ARGB) -> mm1 (0000ARGB)*/
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   296
				movd_m2r((*dstp), mm2);/* dst(ARGB) -> mm2 (0000ARGB)*/
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   297
				punpcklbw_r2r(mm5, mm1); /* 0A0R0G0B -> mm1(src) */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   298
				punpcklbw_r2r(mm5, mm2); /* 0A0R0G0B -> mm2(dst) */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   299
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   300
				psubw_r2r(mm2, mm1);/* src - dst -> mm1 */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   301
				pmullw_r2r(mm4, mm1); /* mm1 * alpha -> mm1 */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   302
				psrlw_i2r(8, mm1); /* mm1 >> 8 -> mm1 */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   303
				paddb_r2r(mm1, mm2); /* mm1 + mm2(dst) -> mm2 */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   304
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   305
				packuswb_r2r(mm5, mm2);  /* ARGBARGB -> mm2 */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   306
				por_r2r(mm7, mm2); /* mm7(full alpha) | mm2 -> mm2 */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   307
				movd_r2m(mm2, *dstp);/* mm2 -> pixel */
689
5bb080d35049 Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
   308
				++srcp;
5bb080d35049 Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
   309
				++dstp;
5bb080d35049 Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
   310
			},{
1542
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   311
				/* Two Pixels Blend */
689
5bb080d35049 Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
   312
				movq_m2r((*srcp), mm0);/* 2 x src -> mm0(ARGBARGB)*/
1542
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   313
				movq_m2r((*dstp), mm2);/* 2 x dst -> mm2(ARGBARGB) */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   314
				movq_r2r(mm0, mm1); /* 2 x src -> mm1(ARGBARGB) */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   315
				movq_r2r(mm2, mm6); /* 2 x dst -> mm6(ARGBARGB) */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   316
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   317
				punpcklbw_r2r(mm5, mm0); /* low - 0A0R0G0B -> mm0(src1) */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   318
				punpckhbw_r2r(mm5, mm1); /* high - 0A0R0G0B -> mm1(src2) */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   319
				punpcklbw_r2r(mm5, mm2); /* low - 0A0R0G0B -> mm2(dst1) */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   320
				punpckhbw_r2r(mm5, mm6); /* high - 0A0R0G0B -> mm6(dst2) */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   321
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   322
				psubw_r2r(mm2, mm0);/* src1 - dst1 -> mm0 */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   323
				pmullw_r2r(mm4, mm0); /* mm0 * alpha -> mm0 */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   324
				psrlw_i2r(8, mm0); /* mm0 >> 8 -> mm1 */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   325
				paddb_r2r(mm0, mm2); /* mm0 + mm2(dst1) -> mm2 */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   326
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   327
				psubw_r2r(mm6, mm1);/* src2 - dst2 -> mm1 */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   328
				pmullw_r2r(mm4, mm1); /* mm1 * alpha -> mm1 */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   329
				psrlw_i2r(8, mm1); /* mm1 >> 8 -> mm1 */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   330
				paddb_r2r(mm1, mm6); /* mm1 + mm6(dst2) -> mm6 */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   331
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   332
				packuswb_r2r(mm6, mm2);  /* ARGBARGB -> mm2 */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   333
				por_r2r(mm7, mm2); /* mm7(dst alpha) | mm2 -> mm2 */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   334
				
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   335
				movq_r2m(mm2, *dstp);/* mm2 -> 2 x pixel */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   336
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   337
  				srcp += 2;
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   338
  				dstp += 2;
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   339
  			}, width);
689
5bb080d35049 Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
   340
			srcp += srcskip;
5bb080d35049 Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
   341
			dstp += dstskip;
5bb080d35049 Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
   342
		}
5bb080d35049 Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
   343
		emms();
5bb080d35049 Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
   344
	}
5bb080d35049 Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
   345
}
5bb080d35049 Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
   346
5bb080d35049 Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
   347
/* fast ARGB888->(A)RGB888 blending with pixel alpha */
5bb080d35049 Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
   348
static void BlitRGBtoRGBPixelAlphaMMX(SDL_BlitInfo *info)
5bb080d35049 Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
   349
{
5bb080d35049 Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
   350
	int width = info->d_width;
5bb080d35049 Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
   351
	int height = info->d_height;
5bb080d35049 Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
   352
	Uint32 *srcp = (Uint32 *)info->s_pixels;
5bb080d35049 Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
   353
	int srcskip = info->s_skip >> 2;
5bb080d35049 Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
   354
	Uint32 *dstp = (Uint32 *)info->d_pixels;
5bb080d35049 Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
   355
	int dstskip = info->d_skip >> 2;
1542
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   356
	SDL_PixelFormat* sf = info->src;
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   357
	Uint32 amask = sf->Amask;
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   358
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   359
	pxor_r2r(mm6, mm6); /* 0 -> mm6 */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   360
	/* form multiplication mask */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   361
	movd_m2r(sf->Amask, mm7); /* 0000F000 -> mm7 */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   362
	punpcklbw_r2r(mm7, mm7); /* FF000000 -> mm7 */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   363
	pcmpeqb_r2r(mm0, mm0); /* FFFFFFFF -> mm0 */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   364
	movq_r2r(mm0, mm3); /* FFFFFFFF -> mm3 (for later) */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   365
	pxor_r2r(mm0, mm7); /* 00FFFFFF -> mm7 (mult mask) */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   366
	/* form channel masks */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   367
	movq_r2r(mm7, mm0); /* 00FFFFFF -> mm0 */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   368
	packsswb_r2r(mm6, mm0); /* 00000FFF -> mm0 (channel mask) */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   369
	packsswb_r2r(mm6, mm3); /* 0000FFFF -> mm3 */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   370
	pxor_r2r(mm0, mm3); /* 0000F000 -> mm3 (~channel mask) */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   371
	/* get alpha channel shift */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   372
	movd_m2r(sf->Ashift, mm5); /* Ashift -> mm5 */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   373
689
5bb080d35049 Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
   374
	while(height--) {
5bb080d35049 Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
   375
	    DUFFS_LOOP4({
1542
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   376
		Uint32 alpha = *srcp & amask;
689
5bb080d35049 Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
   377
		/* FIXME: Here we special-case opaque alpha since the
1542
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   378
			compositioning used (>>8 instead of /255) doesn't handle
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   379
			it correctly. Also special-case alpha=0 for speed?
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   380
			Benchmark this! */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   381
		if(alpha == 0) {
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   382
			/* do nothing */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   383
		} else if(alpha == amask) {
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   384
			/* opaque alpha -- copy RGB, keep dst alpha */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   385
			/* using MMX here to free up regular registers for other things */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   386
			movd_m2r((*srcp), mm1);/* src(ARGB) -> mm1 (0000ARGB)*/
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   387
			movd_m2r((*dstp), mm2);/* dst(ARGB) -> mm2 (0000ARGB)*/
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   388
			pand_r2r(mm0, mm1); /* src & chanmask -> mm1 */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   389
			pand_r2r(mm3, mm2); /* dst & ~chanmask -> mm2 */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   390
			por_r2r(mm1, mm2); /* src | dst -> mm2 */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   391
			movd_r2m(mm2, (*dstp)); /* mm2 -> dst */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   392
		} else {
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   393
			movd_m2r((*srcp), mm1);/* src(ARGB) -> mm1 (0000ARGB)*/
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   394
			punpcklbw_r2r(mm6, mm1); /* 0A0R0G0B -> mm1 */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   395
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   396
			movd_m2r((*dstp), mm2);/* dst(ARGB) -> mm2 (0000ARGB)*/
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   397
			punpcklbw_r2r(mm6, mm2); /* 0A0R0G0B -> mm2 */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   398
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   399
			__asm__ __volatile__ (
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   400
				"movd %0, %%mm4"
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   401
				: : "r" (alpha) ); /* 0000A000 -> mm4 */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   402
			psrld_r2r(mm5, mm4); /* mm4 >> mm5 -> mm4 (0000000A) */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   403
			punpcklwd_r2r(mm4, mm4); /* 00000A0A -> mm4 */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   404
			punpcklwd_r2r(mm4, mm4); /* 0A0A0A0A -> mm4 */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   405
			pand_r2r(mm7, mm4); /* 000A0A0A -> mm4, preserve dst alpha on add */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   406
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   407
			/* blend */		    
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   408
			psubw_r2r(mm2, mm1);/* src - dst -> mm1 */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   409
			pmullw_r2r(mm4, mm1); /* mm1 * alpha -> mm1 */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   410
			psrlw_i2r(8, mm1); /* mm1 >> 8 -> mm1(000R0G0B) */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   411
			paddb_r2r(mm1, mm2); /* mm1 + mm2(dst) -> mm2 */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   412
			
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   413
			packuswb_r2r(mm6, mm2);  /* 0000ARGB -> mm2 */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   414
			movd_r2m(mm2, *dstp);/* mm2 -> dst */
689
5bb080d35049 Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
   415
		}
5bb080d35049 Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
   416
		++srcp;
5bb080d35049 Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
   417
		++dstp;
5bb080d35049 Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
   418
	    }, width);
5bb080d35049 Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
   419
	    srcp += srcskip;
5bb080d35049 Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
   420
	    dstp += dstskip;
5bb080d35049 Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
   421
	}
5bb080d35049 Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
   422
	emms();
5bb080d35049 Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
   423
}
1542
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   424
/* End GCC_ASMBLIT */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   425
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   426
#elif MSVC_ASMBLIT
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   427
/* fast RGB888->(A)RGB888 blending with surface alpha=128 special case */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   428
static void BlitRGBtoRGBSurfaceAlpha128MMX(SDL_BlitInfo *info)
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   429
{
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   430
	int width = info->d_width;
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   431
	int height = info->d_height;
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   432
	Uint32 *srcp = (Uint32 *)info->s_pixels;
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   433
	int srcskip = info->s_skip >> 2;
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   434
	Uint32 *dstp = (Uint32 *)info->d_pixels;
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   435
	int dstskip = info->d_skip >> 2;
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   436
	Uint32 dalpha = info->dst->Amask;
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   437
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   438
	__m64 src1, src2, dst1, dst2, lmask, hmask, dsta;
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   439
	
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   440
	hmask = _mm_set_pi32(0x00fefefe, 0x00fefefe); /* alpha128 mask -> hmask */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   441
	lmask = _mm_set_pi32(0x00010101, 0x00010101); /* !alpha128 mask -> lmask */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   442
	dsta = _mm_set_pi32(dalpha, dalpha); /* dst alpha mask -> dsta */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   443
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   444
	while (height--) {
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   445
		int n = width;
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   446
		if ( n & 1 ) {
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   447
			Uint32 s = *srcp++;
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   448
			Uint32 d = *dstp;
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   449
			*dstp++ = ((((s & 0x00fefefe) + (d & 0x00fefefe)) >> 1)
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   450
				   + (s & d & 0x00010101)) | dalpha;
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   451
			n--;
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   452
		}
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   453
		
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   454
		for (n >>= 1; n > 0; --n) {
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   455
			dst1 = *(__m64*)dstp; /* 2 x dst -> dst1(ARGBARGB) */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   456
			dst2 = dst1;   /* 2 x dst -> dst2(ARGBARGB) */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   457
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   458
			src1 = *(__m64*)srcp; /* 2 x src -> src1(ARGBARGB) */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   459
			src2 = src1; /* 2 x src -> src2(ARGBARGB) */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   460
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   461
			dst2 = _mm_and_si64(dst2, hmask); /* dst & mask -> dst2 */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   462
			src2 = _mm_and_si64(src2, hmask); /* src & mask -> src2 */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   463
			src2 = _mm_add_pi32(src2, dst2); /* dst2 + src2 -> src2 */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   464
			src2 = _mm_srli_pi32(src2, 1); /* src2 >> 1 -> src2 */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   465
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   466
			dst1 = _mm_and_si64(dst1, src1); /* src & dst -> dst1 */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   467
			dst1 = _mm_and_si64(dst1, lmask); /* dst1 & !mask -> dst1 */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   468
			dst1 = _mm_add_pi32(dst1, src2); /* src2 + dst1 -> dst1 */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   469
			dst1 = _mm_or_si64(dst1, dsta); /* dsta(full alpha) | dst1 -> dst1 */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   470
			
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   471
			*(__m64*)dstp = dst1; /* dst1 -> 2 x dst pixels */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   472
			dstp += 2;
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   473
			srcp += 2;
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   474
		}
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   475
		
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   476
		srcp += srcskip;
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   477
		dstp += dstskip;
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   478
	}
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   479
	_mm_empty();
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   480
}
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   481
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   482
/* fast RGB888->(A)RGB888 blending with surface alpha */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   483
static void BlitRGBtoRGBSurfaceAlphaMMX(SDL_BlitInfo *info)
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   484
{
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   485
	SDL_PixelFormat* df = info->dst;
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   486
	Uint32 chanmask = df->Rmask | df->Gmask | df->Bmask;
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   487
	unsigned alpha = info->src->alpha;
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   488
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   489
	if (alpha == 128 && (df->Rmask | df->Gmask | df->Bmask) == 0x00FFFFFF) {
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   490
			/* only call a128 version when R,G,B occupy lower bits */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   491
		BlitRGBtoRGBSurfaceAlpha128MMX(info);
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   492
	} else {
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   493
		int width = info->d_width;
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   494
		int height = info->d_height;
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   495
		Uint32 *srcp = (Uint32 *)info->s_pixels;
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   496
		int srcskip = info->s_skip >> 2;
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   497
		Uint32 *dstp = (Uint32 *)info->d_pixels;
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   498
		int dstskip = info->d_skip >> 2;
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   499
		Uint32 dalpha = df->Amask;
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   500
		Uint32 amult;
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   501
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   502
		__m64 src1, src2, dst1, dst2, mm_alpha, mm_zero, dsta;
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   503
		
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   504
		mm_zero = _mm_setzero_si64(); /* 0 -> mm_zero */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   505
		/* form the alpha mult */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   506
		amult = alpha | (alpha << 8);
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   507
		amult = amult | (amult << 16);
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   508
		chanmask = (0xff << df->Rshift) | (0xff << df->Gshift) | (0xff << df->Bshift);
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   509
		mm_alpha = _mm_set_pi32(0, amult & chanmask); /* 0000AAAA -> mm_alpha, minus 1 chan */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   510
		mm_alpha = _mm_unpacklo_pi8(mm_alpha, mm_zero); /* 0A0A0A0A -> mm_alpha, minus 1 chan */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   511
			/* at this point mm_alpha can be 000A0A0A or 0A0A0A00 or another combo */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   512
		dsta = _mm_set_pi32(dalpha, dalpha); /* dst alpha mask -> dsta */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   513
		
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   514
		while (height--) {
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   515
			int n = width;
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   516
			if (n & 1) {
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   517
				/* One Pixel Blend */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   518
				src2 = _mm_cvtsi32_si64(*srcp); /* src(ARGB) -> src2 (0000ARGB)*/
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   519
				src2 = _mm_unpacklo_pi8(src2, mm_zero); /* 0A0R0G0B -> src2 */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   520
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   521
				dst1 = _mm_cvtsi32_si64(*dstp); /* dst(ARGB) -> dst1 (0000ARGB)*/
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   522
				dst1 = _mm_unpacklo_pi8(dst1, mm_zero); /* 0A0R0G0B -> dst1 */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   523
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   524
				src2 = _mm_sub_pi16(src2, dst1); /* src2 - dst2 -> src2 */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   525
				src2 = _mm_mullo_pi16(src2, mm_alpha); /* src2 * alpha -> src2 */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   526
				src2 = _mm_srli_pi16(src2, 8); /* src2 >> 8 -> src2 */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   527
				dst1 = _mm_add_pi8(src2, dst1); /* src2 + dst1 -> dst1 */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   528
				
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   529
				dst1 = _mm_packs_pu16(dst1, mm_zero);  /* 0000ARGB -> dst1 */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   530
				dst1 = _mm_or_si64(dst1, dsta); /* dsta | dst1 -> dst1 */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   531
				*dstp = _mm_cvtsi64_si32(dst1); /* dst1 -> pixel */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   532
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   533
				++srcp;
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   534
				++dstp;
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   535
				
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   536
				n--;
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   537
			}
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   538
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   539
			for (n >>= 1; n > 0; --n) {
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   540
				/* Two Pixels Blend */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   541
				src1 = *(__m64*)srcp; /* 2 x src -> src1(ARGBARGB)*/
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   542
				src2 = src1; /* 2 x src -> src2(ARGBARGB) */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   543
				src1 = _mm_unpacklo_pi8(src1, mm_zero); /* low - 0A0R0G0B -> src1 */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   544
				src2 = _mm_unpackhi_pi8(src2, mm_zero); /* high - 0A0R0G0B -> src2 */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   545
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   546
				dst1 = *(__m64*)dstp;/* 2 x dst -> dst1(ARGBARGB) */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   547
				dst2 = dst1; /* 2 x dst -> dst2(ARGBARGB) */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   548
				dst1 = _mm_unpacklo_pi8(dst1, mm_zero); /* low - 0A0R0G0B -> dst1 */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   549
				dst2 = _mm_unpackhi_pi8(dst2, mm_zero); /* high - 0A0R0G0B -> dst2 */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   550
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   551
				src1 = _mm_sub_pi16(src1, dst1);/* src1 - dst1 -> src1 */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   552
				src1 = _mm_mullo_pi16(src1, mm_alpha); /* src1 * alpha -> src1 */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   553
				src1 = _mm_srli_pi16(src1, 8); /* src1 >> 8 -> src1 */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   554
				dst1 = _mm_add_pi8(src1, dst1); /* src1 + dst1(dst1) -> dst1 */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   555
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   556
				src2 = _mm_sub_pi16(src2, dst2);/* src2 - dst2 -> src2 */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   557
				src2 = _mm_mullo_pi16(src2, mm_alpha); /* src2 * alpha -> src2 */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   558
				src2 = _mm_srli_pi16(src2, 8); /* src2 >> 8 -> src2 */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   559
				dst2 = _mm_add_pi8(src2, dst2); /* src2 + dst2(dst2) -> dst2 */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   560
				
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   561
				dst1 = _mm_packs_pu16(dst1, dst2); /* 0A0R0G0B(res1), 0A0R0G0B(res2) -> dst1(ARGBARGB) */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   562
				dst1 = _mm_or_si64(dst1, dsta); /* dsta | dst1 -> dst1 */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   563
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   564
				*(__m64*)dstp = dst1; /* dst1 -> 2 x pixel */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   565
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   566
				srcp += 2;
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   567
				dstp += 2;
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   568
			}
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   569
			srcp += srcskip;
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   570
			dstp += dstskip;
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   571
		}
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   572
		_mm_empty();
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   573
	}
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   574
}
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   575
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   576
/* fast ARGB888->(A)RGB888 blending with pixel alpha */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   577
static void BlitRGBtoRGBPixelAlphaMMX(SDL_BlitInfo *info)
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   578
{
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   579
	int width = info->d_width;
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   580
	int height = info->d_height;
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   581
	Uint32 *srcp = (Uint32 *)info->s_pixels;
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   582
	int srcskip = info->s_skip >> 2;
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   583
	Uint32 *dstp = (Uint32 *)info->d_pixels;
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   584
	int dstskip = info->d_skip >> 2;
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   585
	SDL_PixelFormat* sf = info->src;
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   586
	Uint32 chanmask = sf->Rmask | sf->Gmask | sf->Bmask;
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   587
	Uint32 amask = sf->Amask;
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   588
	Uint32 ashift = sf->Ashift;
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   589
	Uint64 multmask;
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   590
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   591
	__m64 src1, dst1, mm_alpha, mm_zero, dmask;
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   592
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   593
	mm_zero = _mm_setzero_si64(); /* 0 -> mm_zero */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   594
	multmask = ~(0xFFFFi64 << (ashift * 2));
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   595
	dmask = *(__m64*) &multmask; /* dst alpha mask -> dmask */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   596
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   597
	while(height--) {
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   598
		DUFFS_LOOP4({
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   599
		Uint32 alpha = *srcp & amask;
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   600
		if (alpha == 0) {
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   601
			/* do nothing */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   602
		} else if (alpha == amask) {
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   603
			/* opaque alpha -- copy RGB, keep dst alpha */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   604
			*dstp = (*srcp & chanmask) | (*dstp & ~chanmask);
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   605
		} else {
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   606
			src1 = _mm_cvtsi32_si64(*srcp); /* src(ARGB) -> src1 (0000ARGB)*/
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   607
			src1 = _mm_unpacklo_pi8(src1, mm_zero); /* 0A0R0G0B -> src1 */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   608
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   609
			dst1 = _mm_cvtsi32_si64(*dstp); /* dst(ARGB) -> dst1 (0000ARGB)*/
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   610
			dst1 = _mm_unpacklo_pi8(dst1, mm_zero); /* 0A0R0G0B -> dst1 */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   611
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   612
			mm_alpha = _mm_cvtsi32_si64(alpha); /* alpha -> mm_alpha (0000000A) */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   613
			mm_alpha = _mm_srli_si64(mm_alpha, ashift); /* mm_alpha >> ashift -> mm_alpha(0000000A) */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   614
			mm_alpha = _mm_unpacklo_pi16(mm_alpha, mm_alpha); /* 00000A0A -> mm_alpha */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   615
			mm_alpha = _mm_unpacklo_pi32(mm_alpha, mm_alpha); /* 0A0A0A0A -> mm_alpha */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   616
			mm_alpha = _mm_and_si64(mm_alpha, dmask); /* 000A0A0A -> mm_alpha, preserve dst alpha on add */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   617
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   618
			/* blend */		    
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   619
			src1 = _mm_sub_pi16(src1, dst1);/* src1 - dst1 -> src1 */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   620
			src1 = _mm_mullo_pi16(src1, mm_alpha); /* (src1 - dst1) * alpha -> src1 */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   621
			src1 = _mm_srli_pi16(src1, 8); /* src1 >> 8 -> src1(000R0G0B) */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   622
			dst1 = _mm_add_pi8(src1, dst1); /* src1 + dst1 -> dst1(0A0R0G0B) */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   623
			dst1 = _mm_packs_pu16(dst1, mm_zero);  /* 0000ARGB -> dst1 */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   624
			
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   625
			*dstp = _mm_cvtsi64_si32(dst1); /* dst1 -> pixel */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   626
		}
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   627
		++srcp;
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   628
		++dstp;
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   629
	    }, width);
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   630
	    srcp += srcskip;
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   631
	    dstp += dstskip;
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   632
	}
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   633
	_mm_empty();
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   634
}
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   635
/* End MSVC_ASMBLIT */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   636
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   637
#endif /* GCC_ASMBLIT, MSVC_ASMBLIT */
689
5bb080d35049 Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
   638
1361
19418e4422cb New configure-based build system. Still work in progress, but much improved
Sam Lantinga <slouken@libsdl.org>
parents: 1358
diff changeset
   639
#if SDL_ALTIVEC_BLITTERS
19418e4422cb New configure-based build system. Still work in progress, but much improved
Sam Lantinga <slouken@libsdl.org>
parents: 1358
diff changeset
   640
#if HAVE_ALTIVEC_H
1162
2651158f59b8 Enable altivec blitters on PowerPC Linux, and some fixes for recent
Ryan C. Gordon <icculus@icculus.org>
parents: 1047
diff changeset
   641
#include <altivec.h>
1175
867f521591e5 Fixed Altivec support on Mac OS X.
Ryan C. Gordon <icculus@icculus.org>
parents: 1162
diff changeset
   642
#endif
1047
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
   643
#include <assert.h>
1162
2651158f59b8 Enable altivec blitters on PowerPC Linux, and some fixes for recent
Ryan C. Gordon <icculus@icculus.org>
parents: 1047
diff changeset
   644
1402
d910939febfa Use consistent identifiers for the various platforms we support.
Sam Lantinga <slouken@libsdl.org>
parents: 1361
diff changeset
   645
#if (defined(__MACOSX__) && (__GNUC__ < 4))
1162
2651158f59b8 Enable altivec blitters on PowerPC Linux, and some fixes for recent
Ryan C. Gordon <icculus@icculus.org>
parents: 1047
diff changeset
   646
    #define VECUINT8_LITERAL(a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p) \
2651158f59b8 Enable altivec blitters on PowerPC Linux, and some fixes for recent
Ryan C. Gordon <icculus@icculus.org>
parents: 1047
diff changeset
   647
        (vector unsigned char) ( a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p )
2651158f59b8 Enable altivec blitters on PowerPC Linux, and some fixes for recent
Ryan C. Gordon <icculus@icculus.org>
parents: 1047
diff changeset
   648
    #define VECUINT16_LITERAL(a,b,c,d,e,f,g,h) \
2651158f59b8 Enable altivec blitters on PowerPC Linux, and some fixes for recent
Ryan C. Gordon <icculus@icculus.org>
parents: 1047
diff changeset
   649
        (vector unsigned short) ( a,b,c,d,e,f,g,h )
2651158f59b8 Enable altivec blitters on PowerPC Linux, and some fixes for recent
Ryan C. Gordon <icculus@icculus.org>
parents: 1047
diff changeset
   650
#else
2651158f59b8 Enable altivec blitters on PowerPC Linux, and some fixes for recent
Ryan C. Gordon <icculus@icculus.org>
parents: 1047
diff changeset
   651
    #define VECUINT8_LITERAL(a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p) \
2651158f59b8 Enable altivec blitters on PowerPC Linux, and some fixes for recent
Ryan C. Gordon <icculus@icculus.org>
parents: 1047
diff changeset
   652
        (vector unsigned char) { a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p }
2651158f59b8 Enable altivec blitters on PowerPC Linux, and some fixes for recent
Ryan C. Gordon <icculus@icculus.org>
parents: 1047
diff changeset
   653
    #define VECUINT16_LITERAL(a,b,c,d,e,f,g,h) \
2651158f59b8 Enable altivec blitters on PowerPC Linux, and some fixes for recent
Ryan C. Gordon <icculus@icculus.org>
parents: 1047
diff changeset
   654
        (vector unsigned short) { a,b,c,d,e,f,g,h }
2651158f59b8 Enable altivec blitters on PowerPC Linux, and some fixes for recent
Ryan C. Gordon <icculus@icculus.org>
parents: 1047
diff changeset
   655
#endif
2651158f59b8 Enable altivec blitters on PowerPC Linux, and some fixes for recent
Ryan C. Gordon <icculus@icculus.org>
parents: 1047
diff changeset
   656
1047
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
   657
#define UNALIGNED_PTR(x) (((size_t) x) & 0x0000000F)
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
   658
#define VECPRINT(msg, v) do { \
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
   659
    vector unsigned int tmpvec = (vector unsigned int)(v); \
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
   660
    unsigned int *vp = (unsigned int *)&tmpvec; \
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
   661
    printf("%s = %08X %08X %08X %08X\n", msg, vp[0], vp[1], vp[2], vp[3]); \
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
   662
} while (0)
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
   663
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
   664
/* the permuation vector that takes the high bytes out of all the appropriate shorts 
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
   665
    (vector unsigned char)(
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
   666
        0x00, 0x10, 0x02, 0x12,
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
   667
        0x04, 0x14, 0x06, 0x16,
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
   668
        0x08, 0x18, 0x0A, 0x1A,
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
   669
        0x0C, 0x1C, 0x0E, 0x1E );
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
   670
*/
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
   671
#define VEC_MERGE_PERMUTE() (vec_add(vec_lvsl(0, (int*)NULL), (vector unsigned char)vec_splat_u16(0x0F)))
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
   672
#define VEC_U32_24() (vec_add(vec_splat_u32(12), vec_splat_u32(12)))
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
   673
#define VEC_ALPHA_MASK() ((vector unsigned char)vec_sl((vector unsigned int)vec_splat_s8(-1), VEC_U32_24()))
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
   674
#define VEC_ALIGNER(src) ((UNALIGNED_PTR(src)) \
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
   675
    ? vec_lvsl(0, src) \
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
   676
    : vec_add(vec_lvsl(8, src), vec_splat_u8(8)))
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
   677
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
   678
   
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
   679
#define VEC_MULTIPLY_ALPHA(vs, vd, valpha, mergePermute, v1_16, v8_16) do { \
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
   680
    /* vtemp1 contains source AAGGAAGGAAGGAAGG */ \
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
   681
    vector unsigned short vtemp1 = vec_mule(vs, valpha); \
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
   682
    /* vtemp2 contains source RRBBRRBBRRBBRRBB */ \
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
   683
    vector unsigned short vtemp2 = vec_mulo(vs, valpha); \
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
   684
    /* valpha2 is 255-alpha */ \
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
   685
    vector unsigned char valpha2 = vec_nor(valpha, valpha); \
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
   686
    /* vtemp3 contains dest AAGGAAGGAAGGAAGG */ \
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
   687
    vector unsigned short vtemp3 = vec_mule(vd, valpha2); \
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
   688
    /* vtemp4 contains dest RRBBRRBBRRBBRRBB */ \
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
   689
    vector unsigned short vtemp4 = vec_mulo(vd, valpha2); \
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
   690
    /* add source and dest */ \
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
   691
    vtemp1 = vec_add(vtemp1, vtemp3); \
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
   692
    vtemp2 = vec_add(vtemp2, vtemp4); \
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
   693
    /* vtemp1 = (vtemp1 + 1) + ((vtemp1 + 1) >> 8) */ \
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
   694
    vtemp1 = vec_add(vtemp1, v1_16); \
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
   695
    vtemp3 = vec_sr(vtemp1, v8_16); \
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
   696
    vtemp1 = vec_add(vtemp1, vtemp3); \
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
   697
    /* vtemp2 = (vtemp2 + 1) + ((vtemp2 + 1) >> 8) */ \
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
   698
    vtemp2 = vec_add(vtemp2, v1_16); \
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
   699
    vtemp4 = vec_sr(vtemp2, v8_16); \
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
   700
    vtemp2 = vec_add(vtemp2, vtemp4); \
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
   701
    /* (>>8) and get ARGBARGBARGBARGB */ \
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
   702
    vd = (vector unsigned char)vec_perm(vtemp1, vtemp2, mergePermute); \
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
   703
} while (0)
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
   704
 
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
   705
/* Calculate the permute vector used for 32->32 swizzling */
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
   706
static vector unsigned char calc_swizzle32(const SDL_PixelFormat *srcfmt,
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
   707
                                  const SDL_PixelFormat *dstfmt)
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
   708
{
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
   709
    /*
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
   710
     * We have to assume that the bits that aren't used by other
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
   711
     *  colors is alpha, and it's one complete byte, since some formats
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
   712
     *  leave alpha with a zero mask, but we should still swizzle the bits.
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
   713
     */
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
   714
    /* ARGB */
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
   715
    const static struct SDL_PixelFormat default_pixel_format = {
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
   716
        NULL, 0, 0,
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
   717
        0, 0, 0, 0,
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
   718
        16, 8, 0, 24,
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
   719
        0x00FF0000, 0x0000FF00, 0x000000FF, 0xFF000000,
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
   720
        0, 0};
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
   721
    if (!srcfmt) {
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
   722
        srcfmt = &default_pixel_format;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
   723
    }
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
   724
    if (!dstfmt) {
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
   725
        dstfmt = &default_pixel_format;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
   726
    }
1487
dc6b59e925a2 Cleaning up warnings on MacOS X
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
   727
    const vector unsigned char plus = VECUINT8_LITERAL
1047
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
   728
                                            ( 0x00, 0x00, 0x00, 0x00,
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
   729
                                              0x04, 0x04, 0x04, 0x04,
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
   730
                                              0x08, 0x08, 0x08, 0x08,
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
   731
                                              0x0C, 0x0C, 0x0C, 0x0C );
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
   732
    vector unsigned char vswiz;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
   733
    vector unsigned int srcvec;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
   734
#define RESHIFT(X) (3 - ((X) >> 3))
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
   735
    Uint32 rmask = RESHIFT(srcfmt->Rshift) << (dstfmt->Rshift);
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
   736
    Uint32 gmask = RESHIFT(srcfmt->Gshift) << (dstfmt->Gshift);
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
   737
    Uint32 bmask = RESHIFT(srcfmt->Bshift) << (dstfmt->Bshift);
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
   738
    Uint32 amask;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
   739
    /* Use zero for alpha if either surface doesn't have alpha */
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
   740
    if (dstfmt->Amask) {
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
   741
        amask = ((srcfmt->Amask) ? RESHIFT(srcfmt->Ashift) : 0x10) << (dstfmt->Ashift);
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
   742
    } else {
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
   743
        amask = 0x10101010 & ((dstfmt->Rmask | dstfmt->Gmask | dstfmt->Bmask) ^ 0xFFFFFFFF);
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
   744
    }
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
   745
#undef RESHIFT  
1162
2651158f59b8 Enable altivec blitters on PowerPC Linux, and some fixes for recent
Ryan C. Gordon <icculus@icculus.org>
parents: 1047
diff changeset
   746
    ((unsigned int *)(char*)&srcvec)[0] = (rmask | gmask | bmask | amask);
1047
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
   747
    vswiz = vec_add(plus, (vector unsigned char)vec_splat(srcvec, 0));
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
   748
    return(vswiz);
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
   749
}
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
   750
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
   751
static void Blit32to565PixelAlphaAltivec(SDL_BlitInfo *info)
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
   752
{
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
   753
    int height = info->d_height;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
   754
    Uint8 *src = (Uint8 *)info->s_pixels;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
   755
    int srcskip = info->s_skip;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
   756
    Uint8 *dst = (Uint8 *)info->d_pixels;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
   757
    int dstskip = info->d_skip;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
   758
    SDL_PixelFormat *srcfmt = info->src;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
   759
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
   760
    vector unsigned char v0 = vec_splat_u8(0);
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
   761
    vector unsigned short v8_16 = vec_splat_u16(8);
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
   762
    vector unsigned short v1_16 = vec_splat_u16(1);
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
   763
    vector unsigned short v2_16 = vec_splat_u16(2);
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
   764
    vector unsigned short v3_16 = vec_splat_u16(3);
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
   765
    vector unsigned int v8_32 = vec_splat_u32(8);
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
   766
    vector unsigned int v16_32 = vec_add(v8_32, v8_32);
1162
2651158f59b8 Enable altivec blitters on PowerPC Linux, and some fixes for recent
Ryan C. Gordon <icculus@icculus.org>
parents: 1047
diff changeset
   767
    vector unsigned short v3f = VECUINT16_LITERAL(
1047
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
   768
        0x003f, 0x003f, 0x003f, 0x003f,
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
   769
        0x003f, 0x003f, 0x003f, 0x003f);
1162
2651158f59b8 Enable altivec blitters on PowerPC Linux, and some fixes for recent
Ryan C. Gordon <icculus@icculus.org>
parents: 1047
diff changeset
   770
    vector unsigned short vfc = VECUINT16_LITERAL(
1047
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
   771
        0x00fc, 0x00fc, 0x00fc, 0x00fc,
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
   772
        0x00fc, 0x00fc, 0x00fc, 0x00fc);
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
   773
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
   774
    /* 
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
   775
        0x10 - 0x1f is the alpha
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
   776
        0x00 - 0x0e evens are the red
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
   777
        0x01 - 0x0f odds are zero
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
   778
    */
1162
2651158f59b8 Enable altivec blitters on PowerPC Linux, and some fixes for recent
Ryan C. Gordon <icculus@icculus.org>
parents: 1047
diff changeset
   779
    vector unsigned char vredalpha1 = VECUINT8_LITERAL(
1047
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
   780
        0x10, 0x00, 0x01, 0x01,
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
   781
        0x10, 0x02, 0x01, 0x01,
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
   782
        0x10, 0x04, 0x01, 0x01,
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
   783
        0x10, 0x06, 0x01, 0x01
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
   784
    );
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
   785
    vector unsigned char vredalpha2 = (vector unsigned char)(
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
   786
        vec_add((vector unsigned int)vredalpha1, vec_sl(v8_32, v16_32))
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
   787
    );
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
   788
    /*
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
   789
        0x00 - 0x0f is ARxx ARxx ARxx ARxx
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
   790
        0x11 - 0x0f odds are blue
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
   791
    */
1162
2651158f59b8 Enable altivec blitters on PowerPC Linux, and some fixes for recent
Ryan C. Gordon <icculus@icculus.org>
parents: 1047
diff changeset
   792
    vector unsigned char vblue1 = VECUINT8_LITERAL(
1047
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
   793
        0x00, 0x01, 0x02, 0x11,
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
   794
        0x04, 0x05, 0x06, 0x13,
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
   795
        0x08, 0x09, 0x0a, 0x15,
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
   796
        0x0c, 0x0d, 0x0e, 0x17
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
   797
    );
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
   798
    vector unsigned char vblue2 = (vector unsigned char)(
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
   799
        vec_add((vector unsigned int)vblue1, v8_32)
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
   800
    );
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
   801
    /*
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
   802
        0x00 - 0x0f is ARxB ARxB ARxB ARxB
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
   803
        0x10 - 0x0e evens are green
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
   804
    */
1162
2651158f59b8 Enable altivec blitters on PowerPC Linux, and some fixes for recent
Ryan C. Gordon <icculus@icculus.org>
parents: 1047
diff changeset
   805
    vector unsigned char vgreen1 = VECUINT8_LITERAL(
1047
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
   806
        0x00, 0x01, 0x10, 0x03,
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
   807
        0x04, 0x05, 0x12, 0x07,
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
   808
        0x08, 0x09, 0x14, 0x0b,
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
   809
        0x0c, 0x0d, 0x16, 0x0f
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
   810
    );
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
   811
    vector unsigned char vgreen2 = (vector unsigned char)(
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
   812
        vec_add((vector unsigned int)vgreen1, vec_sl(v8_32, v8_32))
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
   813
    );
1162
2651158f59b8 Enable altivec blitters on PowerPC Linux, and some fixes for recent
Ryan C. Gordon <icculus@icculus.org>
parents: 1047
diff changeset
   814
    vector unsigned char vgmerge = VECUINT8_LITERAL(
1047
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
   815
        0x00, 0x02, 0x00, 0x06,
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
   816
        0x00, 0x0a, 0x00, 0x0e,
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
   817
        0x00, 0x12, 0x00, 0x16,
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
   818
        0x00, 0x1a, 0x00, 0x1e);
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
   819
    vector unsigned char mergePermute = VEC_MERGE_PERMUTE();
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
   820
    vector unsigned char vpermute = calc_swizzle32(srcfmt, NULL);
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
   821
    vector unsigned char valphaPermute = vec_and(vec_lvsl(0, (int *)NULL), vec_splat_u8(0xC));
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
   822
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
   823
    vector unsigned short vf800 = (vector unsigned short)vec_splat_u8(-7);
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
   824
    vf800 = vec_sl(vf800, vec_splat_u16(8));
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
   825
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
   826
    while(height--) {
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
   827
        int extrawidth;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
   828
        vector unsigned char valigner;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
   829
        vector unsigned char vsrc;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
   830
        vector unsigned char voverflow;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
   831
        int width = info->d_width;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
   832
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
   833
#define ONE_PIXEL_BLEND(condition, widthvar) \
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
   834
        while (condition) { \
1162
2651158f59b8 Enable altivec blitters on PowerPC Linux, and some fixes for recent
Ryan C. Gordon <icculus@icculus.org>
parents: 1047
diff changeset
   835
            Uint32 Pixel; \
1047
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
   836
            unsigned sR, sG, sB, dR, dG, dB, sA; \
1162
2651158f59b8 Enable altivec blitters on PowerPC Linux, and some fixes for recent
Ryan C. Gordon <icculus@icculus.org>
parents: 1047
diff changeset
   837
            DISEMBLE_RGBA(src, 4, srcfmt, Pixel, sR, sG, sB, sA); \
1047
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
   838
            if(sA) { \
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
   839
                unsigned short dstpixel = *((unsigned short *)dst); \
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
   840
                dR = (dstpixel >> 8) & 0xf8; \
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
   841
                dG = (dstpixel >> 3) & 0xfc; \
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
   842
                dB = (dstpixel << 3) & 0xf8; \
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
   843
                ACCURATE_ALPHA_BLEND(sR, sG, sB, sA, dR, dG, dB); \
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
   844
                *((unsigned short *)dst) = ( \
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
   845
                    ((dR & 0xf8) << 8) | ((dG & 0xfc) << 3) | (dB >> 3) \
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
   846
                ); \
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
   847
            } \
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
   848
            src += 4; \
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
   849
            dst += 2; \
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
   850
            widthvar--; \
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
   851
        }
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
   852
        ONE_PIXEL_BLEND((UNALIGNED_PTR(dst)) && (width), width);
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
   853
        extrawidth = (width % 8);
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
   854
        valigner = VEC_ALIGNER(src);
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
   855
        vsrc = (vector unsigned char)vec_ld(0, src);
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
   856
        width -= extrawidth;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
   857
        while (width) {
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
   858
            vector unsigned char valpha;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
   859
            vector unsigned char vsrc1, vsrc2;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
   860
            vector unsigned char vdst1, vdst2;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
   861
            vector unsigned short vR, vG, vB;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
   862
            vector unsigned short vpixel, vrpixel, vgpixel, vbpixel;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
   863
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
   864
            /* Load 8 pixels from src as ARGB */
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
   865
            voverflow = (vector unsigned char)vec_ld(15, src);
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
   866
            vsrc = vec_perm(vsrc, voverflow, valigner);
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
   867
            vsrc1 = vec_perm(vsrc, vsrc, vpermute);
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
   868
            src += 16;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
   869
            vsrc = (vector unsigned char)vec_ld(15, src);
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
   870
            voverflow = vec_perm(voverflow, vsrc, valigner);
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
   871
            vsrc2 = vec_perm(voverflow, voverflow, vpermute);
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
   872
            src += 16;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
   873
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
   874
            /* Load 8 pixels from dst as XRGB */
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
   875
            voverflow = vec_ld(0, dst);
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
   876
            vR = vec_and((vector unsigned short)voverflow, vf800);
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
   877
            vB = vec_sl((vector unsigned short)voverflow, v3_16);
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
   878
            vG = vec_sl(vB, v2_16);
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
   879
            vdst1 = (vector unsigned char)vec_perm((vector unsigned char)vR, (vector unsigned char)vR, vredalpha1);
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
   880
            vdst1 = vec_perm(vdst1, (vector unsigned char)vB, vblue1);
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
   881
            vdst1 = vec_perm(vdst1, (vector unsigned char)vG, vgreen1);
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
   882
            vdst2 = (vector unsigned char)vec_perm((vector unsigned char)vR, (vector unsigned char)vR, vredalpha2);
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
   883
            vdst2 = vec_perm(vdst2, (vector unsigned char)vB, vblue2);
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
   884
            vdst2 = vec_perm(vdst2, (vector unsigned char)vG, vgreen2);
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
   885
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
   886
            /* Alpha blend 8 pixels as ARGB */
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
   887
            valpha = vec_perm(vsrc1, v0, valphaPermute);
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
   888
            VEC_MULTIPLY_ALPHA(vsrc1, vdst1, valpha, mergePermute, v1_16, v8_16);
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
   889
            valpha = vec_perm(vsrc2, v0, valphaPermute);
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
   890
            VEC_MULTIPLY_ALPHA(vsrc2, vdst2, valpha, mergePermute, v1_16, v8_16);
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
   891
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
   892
            /* Convert 8 pixels to 565 */
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
   893
            vpixel = (vector unsigned short)vec_packpx((vector unsigned int)vdst1, (vector unsigned int)vdst2);
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
   894
            vgpixel = (vector unsigned short)vec_perm(vdst1, vdst2, vgmerge);
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
   895
            vgpixel = vec_and(vgpixel, vfc);
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
   896
            vgpixel = vec_sl(vgpixel, v3_16);
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
   897
            vrpixel = vec_sl(vpixel, v1_16);
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
   898
            vrpixel = vec_and(vrpixel, vf800);
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
   899
            vbpixel = vec_and(vpixel, v3f);
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
   900
            vdst1 = vec_or((vector unsigned char)vrpixel, (vector unsigned char)vgpixel);
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
   901
            vdst1 = vec_or(vdst1, (vector unsigned char)vbpixel);
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
   902
            
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
   903
            /* Store 8 pixels */
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
   904
            vec_st(vdst1, 0, dst);
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
   905
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
   906
            width -= 8;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
   907
            dst += 16;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
   908
        }
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
   909
        ONE_PIXEL_BLEND((extrawidth), extrawidth);
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
   910
#undef ONE_PIXEL_BLEND
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
   911
        src += srcskip;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
   912
        dst += dstskip;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
   913
    }
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
   914
}
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
   915
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
   916
static void Blit32to32SurfaceAlphaKeyAltivec(SDL_BlitInfo *info)
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
   917
{
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
   918
    unsigned alpha = info->src->alpha;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
   919
    int height = info->d_height;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
   920
    Uint32 *srcp = (Uint32 *)info->s_pixels;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
   921
    int srcskip = info->s_skip >> 2;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
   922
    Uint32 *dstp = (Uint32 *)info->d_pixels;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
   923
    int dstskip = info->d_skip >> 2;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
   924
    SDL_PixelFormat *srcfmt = info->src;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
   925
    SDL_PixelFormat *dstfmt = info->dst;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
   926
    unsigned sA = srcfmt->alpha;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
   927
    unsigned dA = dstfmt->Amask ? SDL_ALPHA_OPAQUE : 0;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
   928
    Uint32 rgbmask = srcfmt->Rmask | srcfmt->Gmask | srcfmt->Bmask;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
   929
    Uint32 ckey = info->src->colorkey;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
   930
    vector unsigned char mergePermute;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
   931
    vector unsigned char vsrcPermute;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
   932
    vector unsigned char vdstPermute;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
   933
    vector unsigned char vsdstPermute;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
   934
    vector unsigned char valpha;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
   935
    vector unsigned char valphamask;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
   936
    vector unsigned char vbits;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
   937
    vector unsigned char v0;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
   938
    vector unsigned short v1;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
   939
    vector unsigned short v8;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
   940
    vector unsigned int vckey;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
   941
    vector unsigned int vrgbmask;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
   942
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
   943
    mergePermute = VEC_MERGE_PERMUTE();
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
   944
    v0 = vec_splat_u8(0);
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
   945
    v1 = vec_splat_u16(1);
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
   946
    v8 = vec_splat_u16(8);
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
   947
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
   948
    /* set the alpha to 255 on the destination surf */
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
   949
    valphamask = VEC_ALPHA_MASK();
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
   950
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
   951
    vsrcPermute = calc_swizzle32(srcfmt, NULL);
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
   952
    vdstPermute = calc_swizzle32(NULL, dstfmt);
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
   953
    vsdstPermute = calc_swizzle32(dstfmt, NULL);
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
   954
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
   955
    /* set a vector full of alpha and 255-alpha */
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
   956
    ((unsigned char *)&valpha)[0] = alpha;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
   957
    valpha = vec_splat(valpha, 0);
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
   958
    vbits = (vector unsigned char)vec_splat_s8(-1);
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
   959
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
   960
    ckey &= rgbmask;
1162
2651158f59b8 Enable altivec blitters on PowerPC Linux, and some fixes for recent
Ryan C. Gordon <icculus@icculus.org>
parents: 1047
diff changeset
   961
    ((unsigned int *)(char*)&vckey)[0] = ckey;
1047
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
   962
    vckey = vec_splat(vckey, 0);
1162
2651158f59b8 Enable altivec blitters on PowerPC Linux, and some fixes for recent
Ryan C. Gordon <icculus@icculus.org>
parents: 1047
diff changeset
   963
    ((unsigned int *)(char*)&vrgbmask)[0] = rgbmask;
1047
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
   964
    vrgbmask = vec_splat(vrgbmask, 0);
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
   965
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
   966
    while(height--) {
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
   967
        int width = info->d_width;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
   968
#define ONE_PIXEL_BLEND(condition, widthvar) \
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
   969
        while (condition) { \
1162
2651158f59b8 Enable altivec blitters on PowerPC Linux, and some fixes for recent
Ryan C. Gordon <icculus@icculus.org>
parents: 1047
diff changeset
   970
            Uint32 Pixel; \
1047
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
   971
            unsigned sR, sG, sB, dR, dG, dB; \
1162
2651158f59b8 Enable altivec blitters on PowerPC Linux, and some fixes for recent
Ryan C. Gordon <icculus@icculus.org>
parents: 1047
diff changeset
   972
            RETRIEVE_RGB_PIXEL(((Uint8 *)srcp), 4, Pixel); \
2651158f59b8 Enable altivec blitters on PowerPC Linux, and some fixes for recent
Ryan C. Gordon <icculus@icculus.org>
parents: 1047
diff changeset
   973
            if(sA && Pixel != ckey) { \
2651158f59b8 Enable altivec blitters on PowerPC Linux, and some fixes for recent
Ryan C. Gordon <icculus@icculus.org>
parents: 1047
diff changeset
   974
                RGB_FROM_PIXEL(Pixel, srcfmt, sR, sG, sB); \
2651158f59b8 Enable altivec blitters on PowerPC Linux, and some fixes for recent
Ryan C. Gordon <icculus@icculus.org>
parents: 1047
diff changeset
   975
                DISEMBLE_RGB(((Uint8 *)dstp), 4, dstfmt, Pixel, dR, dG, dB); \
1047
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
   976
                ACCURATE_ALPHA_BLEND(sR, sG, sB, sA, dR, dG, dB); \
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
   977
                ASSEMBLE_RGBA(((Uint8 *)dstp), 4, dstfmt, dR, dG, dB, dA); \
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
   978
            } \
1162
2651158f59b8 Enable altivec blitters on PowerPC Linux, and some fixes for recent
Ryan C. Gordon <icculus@icculus.org>
parents: 1047
diff changeset
   979
            dstp++; \
2651158f59b8 Enable altivec blitters on PowerPC Linux, and some fixes for recent
Ryan C. Gordon <icculus@icculus.org>
parents: 1047
diff changeset
   980
            srcp++; \
1047
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
   981
            widthvar--; \
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
   982
        }
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
   983
        ONE_PIXEL_BLEND((UNALIGNED_PTR(dstp)) && (width), width);
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
   984
        if (width > 0) {
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
   985
            int extrawidth = (width % 4);
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
   986
            vector unsigned char valigner = VEC_ALIGNER(srcp);
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
   987
            vector unsigned char vs = (vector unsigned char)vec_ld(0, srcp);
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
   988
            width -= extrawidth;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
   989
            while (width) {
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
   990
                vector unsigned char vsel;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
   991
                vector unsigned char voverflow;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
   992
                vector unsigned char vd;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
   993
                vector unsigned char vd_orig;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
   994
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
   995
                /* s = *srcp */
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
   996
                voverflow = (vector unsigned char)vec_ld(15, srcp);
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
   997
                vs = vec_perm(vs, voverflow, valigner);
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
   998
                
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
   999
                /* vsel is set for items that match the key */
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
  1000
                vsel = (vector unsigned char)vec_and((vector unsigned int)vs, vrgbmask);
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
  1001
                vsel = (vector unsigned char)vec_cmpeq((vector unsigned int)vsel, vckey);
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
  1002
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
  1003
                /* permute to source format */
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
  1004
                vs = vec_perm(vs, valpha, vsrcPermute);
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
  1005
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
  1006
                /* d = *dstp */
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
  1007
                vd = (vector unsigned char)vec_ld(0, dstp);
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
  1008
                vd_orig = vd = vec_perm(vd, v0, vsdstPermute);
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
  1009
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
  1010
                VEC_MULTIPLY_ALPHA(vs, vd, valpha, mergePermute, v1, v8);
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
  1011
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
  1012
                /* set the alpha channel to full on */
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
  1013
                vd = vec_or(vd, valphamask);
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
  1014
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
  1015
                /* mask out color key */
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
  1016
                vd = vec_sel(vd, vd_orig, vsel);
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
  1017
                
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
  1018
                /* permute to dest format */
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
  1019
                vd = vec_perm(vd, vbits, vdstPermute);
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
  1020
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
  1021
                /* *dstp = res */
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
  1022
                vec_st((vector unsigned int)vd, 0, dstp);
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
  1023
                
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
  1024
                srcp += 4;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
  1025
                dstp += 4;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
  1026
                width -= 4;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
  1027
                vs = voverflow;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
  1028
            }
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
  1029
            ONE_PIXEL_BLEND((extrawidth), extrawidth);
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
  1030
        }
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
  1031
#undef ONE_PIXEL_BLEND
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
  1032
 
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
  1033
        srcp += srcskip;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
  1034
        dstp += dstskip;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
  1035
    }
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
  1036
}
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
  1037
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
  1038
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
  1039
static void Blit32to32PixelAlphaAltivec(SDL_BlitInfo *info)
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
  1040
{
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
  1041
    int width = info->d_width;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
  1042
    int height = info->d_height;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
  1043
    Uint32 *srcp = (Uint32 *)info->s_pixels;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
  1044
    int srcskip = info->s_skip >> 2;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
  1045
    Uint32 *dstp = (Uint32 *)info->d_pixels;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
  1046
    int dstskip = info->d_skip >> 2;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
  1047
    SDL_PixelFormat *srcfmt = info->src;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
  1048
    SDL_PixelFormat *dstfmt = info->dst;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
  1049
    vector unsigned char mergePermute;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
  1050
    vector unsigned char valphaPermute;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
  1051
    vector unsigned char vsrcPermute;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
  1052
    vector unsigned char vdstPermute;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
  1053
    vector unsigned char vsdstPermute;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
  1054
    vector unsigned char valphamask;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
  1055
    vector unsigned char vpixelmask;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
  1056
    vector unsigned char v0;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
  1057
    vector unsigned short v1;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
  1058
    vector unsigned short v8;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
  1059
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
  1060
    v0 = vec_splat_u8(0);
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
  1061
    v1 = vec_splat_u16(1);
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
  1062
    v8 = vec_splat_u16(8);
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
  1063
    mergePermute = VEC_MERGE_PERMUTE();
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
  1064
    valphamask = VEC_ALPHA_MASK();
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
  1065
    valphaPermute = vec_and(vec_lvsl(0, (int *)NULL), vec_splat_u8(0xC));
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
  1066
    vpixelmask = vec_nor(valphamask, v0);
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
  1067
    vsrcPermute = calc_swizzle32(srcfmt, NULL);
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
  1068
    vdstPermute = calc_swizzle32(NULL, dstfmt);
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
  1069
    vsdstPermute = calc_swizzle32(dstfmt, NULL);
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
  1070
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
  1071
	while ( height-- ) {
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
  1072
        width = info->d_width;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
  1073
#define ONE_PIXEL_BLEND(condition, widthvar) while ((condition)) { \
1162
2651158f59b8 Enable altivec blitters on PowerPC Linux, and some fixes for recent
Ryan C. Gordon <icculus@icculus.org>
parents: 1047
diff changeset
  1074
            Uint32 Pixel; \
1047
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
  1075
            unsigned sR, sG, sB, dR, dG, dB, sA, dA; \
1162
2651158f59b8 Enable altivec blitters on PowerPC Linux, and some fixes for recent
Ryan C. Gordon <icculus@icculus.org>
parents: 1047
diff changeset
  1076
            DISEMBLE_RGBA((Uint8 *)srcp, 4, srcfmt, Pixel, sR, sG, sB, sA); \
1047
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
  1077
            if(sA) { \
1162
2651158f59b8 Enable altivec blitters on PowerPC Linux, and some fixes for recent
Ryan C. Gordon <icculus@icculus.org>
parents: 1047
diff changeset
  1078
              DISEMBLE_RGBA((Uint8 *)dstp, 4, dstfmt, Pixel, dR, dG, dB, dA); \
1047
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
  1079
              ACCURATE_ALPHA_BLEND(sR, sG, sB, sA, dR, dG, dB); \
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
  1080
              ASSEMBLE_RGBA((Uint8 *)dstp, 4, dstfmt, dR, dG, dB, dA); \
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
  1081
            } \
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
  1082
            ++srcp; \
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
  1083
            ++dstp; \
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
  1084
            widthvar--; \
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
  1085
        }
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
  1086
        ONE_PIXEL_BLEND((UNALIGNED_PTR(dstp)) && (width), width);
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
  1087
        if (width > 0) {
1487
dc6b59e925a2 Cleaning up warnings on MacOS X
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
  1088
            /* vsrcPermute */
dc6b59e925a2 Cleaning up warnings on MacOS X
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
  1089
            /* vdstPermute */
1047
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
  1090
            int extrawidth = (width % 4);
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
  1091
            vector unsigned char valigner = VEC_ALIGNER(srcp);
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
  1092
            vector unsigned char vs = (vector unsigned char)vec_ld(0, srcp);
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
  1093
            width -= extrawidth;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
  1094
            while (width) {
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
  1095
                vector unsigned char voverflow;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
  1096
                vector unsigned char vd;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
  1097
                vector unsigned char valpha;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
  1098
                vector unsigned char vdstalpha;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
  1099
                /* s = *srcp */
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
  1100
                voverflow = (vector unsigned char)vec_ld(15, srcp);
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
  1101
                vs = vec_perm(vs, voverflow, valigner);
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
  1102
                vs = vec_perm(vs, v0, vsrcPermute);
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
  1103
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
  1104
                valpha = vec_perm(vs, v0, valphaPermute);
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
  1105
                
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880
diff changeset
  1106
                /* d = *dstp */
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 880