src/video/SDL_blit_A.c
author Sam Lantinga <slouken@libsdl.org>
Sat, 07 Jan 2012 01:25:55 -0500
changeset 6165 b7347e716ab6
parent 6138 4c64952a58fb
child 6281 e46d6f4b469e
permissions -rwxr-xr-x
Fixed bug 1225 - Altivec blitters broken due to SDL_PixelFormat bastien.bouclet@gmail.com 2011-06-13 05:50:58 PDT Static pixel format initialization has not been updated to reflect header changes in SDL_blit_N.c The attached patch fixes Altivec support for me. altivec.h is needed for some systems.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
     1
/*
5535
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5439
diff changeset
     2
  Simple DirectMedia Layer
6138
4c64952a58fb Happy New Year!
Sam Lantinga <slouken@libsdl.org>
parents: 5535
diff changeset
     3
  Copyright (C) 1997-2012 Sam Lantinga <slouken@libsdl.org>
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
     4
5535
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5439
diff changeset
     5
  This software is provided 'as-is', without any express or implied
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5439
diff changeset
     6
  warranty.  In no event will the authors be held liable for any damages
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5439
diff changeset
     7
  arising from the use of this software.
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
     8
5535
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5439
diff changeset
     9
  Permission is granted to anyone to use this software for any purpose,
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5439
diff changeset
    10
  including commercial applications, and to alter it and redistribute it
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5439
diff changeset
    11
  freely, subject to the following restrictions:
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    12
5535
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5439
diff changeset
    13
  1. The origin of this software must not be misrepresented; you must not
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5439
diff changeset
    14
     claim that you wrote the original software. If you use this software
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5439
diff changeset
    15
     in a product, an acknowledgment in the product documentation would be
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5439
diff changeset
    16
     appreciated but is not required.
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5439
diff changeset
    17
  2. Altered source versions must be plainly marked as such, and must not be
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5439
diff changeset
    18
     misrepresented as being the original software.
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5439
diff changeset
    19
  3. This notice may not be removed or altered from any source distribution.
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    20
*/
1402
d910939febfa Use consistent identifiers for the various platforms we support.
Sam Lantinga <slouken@libsdl.org>
parents: 1361
diff changeset
    21
#include "SDL_config.h"
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    22
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    23
#include "SDL_video.h"
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    24
#include "SDL_blit.h"
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    25
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    26
/* Functions to perform alpha blended blitting */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    27
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    28
/* N->1 blending with per-surface alpha */
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1795
diff changeset
    29
static void
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1795
diff changeset
    30
BlitNto1SurfaceAlpha(SDL_BlitInfo * info)
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    31
{
2262
bee005ace1bf Work in progress: merging new texture features into SDL blit system
Sam Lantinga <slouken@libsdl.org>
parents: 2261
diff changeset
    32
    int width = info->dst_w;
bee005ace1bf Work in progress: merging new texture features into SDL blit system
Sam Lantinga <slouken@libsdl.org>
parents: 2261
diff changeset
    33
    int height = info->dst_h;
bee005ace1bf Work in progress: merging new texture features into SDL blit system
Sam Lantinga <slouken@libsdl.org>
parents: 2261
diff changeset
    34
    Uint8 *src = info->src;
2267
c785543d1843 Okay, still some bugs, but everything builds again...
Sam Lantinga <slouken@libsdl.org>
parents: 2262
diff changeset
    35
    int srcskip = info->src_skip;
2262
bee005ace1bf Work in progress: merging new texture features into SDL blit system
Sam Lantinga <slouken@libsdl.org>
parents: 2261
diff changeset
    36
    Uint8 *dst = info->dst;
2267
c785543d1843 Okay, still some bugs, but everything builds again...
Sam Lantinga <slouken@libsdl.org>
parents: 2262
diff changeset
    37
    int dstskip = info->dst_skip;
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1795
diff changeset
    38
    Uint8 *palmap = info->table;
2267
c785543d1843 Okay, still some bugs, but everything builds again...
Sam Lantinga <slouken@libsdl.org>
parents: 2262
diff changeset
    39
    SDL_PixelFormat *srcfmt = info->src_fmt;
c785543d1843 Okay, still some bugs, but everything builds again...
Sam Lantinga <slouken@libsdl.org>
parents: 2262
diff changeset
    40
    SDL_PixelFormat *dstfmt = info->dst_fmt;
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1795
diff changeset
    41
    int srcbpp = srcfmt->BytesPerPixel;
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    42
2267
c785543d1843 Okay, still some bugs, but everything builds again...
Sam Lantinga <slouken@libsdl.org>
parents: 2262
diff changeset
    43
    const unsigned A = info->a;
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    44
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1795
diff changeset
    45
    while (height--) {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1795
diff changeset
    46
	    /* *INDENT-OFF* */
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    47
	    DUFFS_LOOP4(
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    48
	    {
1162
2651158f59b8 Enable altivec blitters on PowerPC Linux, and some fixes for recent
Ryan C. Gordon <icculus@icculus.org>
parents: 1047
diff changeset
    49
		Uint32 Pixel;
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    50
		unsigned sR;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    51
		unsigned sG;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    52
		unsigned sB;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    53
		unsigned dR;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    54
		unsigned dG;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    55
		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
    56
		DISEMBLE_RGB(src, srcbpp, srcfmt, Pixel, sR, sG, sB);
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    57
		dR = dstfmt->palette->colors[*dst].r;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    58
		dG = dstfmt->palette->colors[*dst].g;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    59
		dB = dstfmt->palette->colors[*dst].b;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    60
		ALPHA_BLEND(sR, sG, sB, A, dR, dG, dB);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    61
		dR &= 0xff;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    62
		dG &= 0xff;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    63
		dB &= 0xff;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    64
		/* Pack RGB into 8bit pixel */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    65
		if ( palmap == NULL ) {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    66
		    *dst =((dR>>5)<<(3+2))|
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    67
			  ((dG>>5)<<(2))|
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    68
			  ((dB>>6)<<(0));
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    69
		} else {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    70
		    *dst = palmap[((dR>>5)<<(3+2))|
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    71
				  ((dG>>5)<<(2))  |
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    72
				  ((dB>>6)<<(0))];
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    73
		}
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    74
		dst++;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    75
		src += srcbpp;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    76
	    },
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    77
	    width);
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1795
diff changeset
    78
	    /* *INDENT-ON* */
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1795
diff changeset
    79
        src += srcskip;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1795
diff changeset
    80
        dst += dstskip;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1795
diff changeset
    81
    }
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    82
}
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    83
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    84
/* N->1 blending with pixel alpha */
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1795
diff changeset
    85
static void
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1795
diff changeset
    86
BlitNto1PixelAlpha(SDL_BlitInfo * info)
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    87
{
2262
bee005ace1bf Work in progress: merging new texture features into SDL blit system
Sam Lantinga <slouken@libsdl.org>
parents: 2261
diff changeset
    88
    int width = info->dst_w;
bee005ace1bf Work in progress: merging new texture features into SDL blit system
Sam Lantinga <slouken@libsdl.org>
parents: 2261
diff changeset
    89
    int height = info->dst_h;
bee005ace1bf Work in progress: merging new texture features into SDL blit system
Sam Lantinga <slouken@libsdl.org>
parents: 2261
diff changeset
    90
    Uint8 *src = info->src;
2267
c785543d1843 Okay, still some bugs, but everything builds again...
Sam Lantinga <slouken@libsdl.org>
parents: 2262
diff changeset
    91
    int srcskip = info->src_skip;
2262
bee005ace1bf Work in progress: merging new texture features into SDL blit system
Sam Lantinga <slouken@libsdl.org>
parents: 2261
diff changeset
    92
    Uint8 *dst = info->dst;
2267
c785543d1843 Okay, still some bugs, but everything builds again...
Sam Lantinga <slouken@libsdl.org>
parents: 2262
diff changeset
    93
    int dstskip = info->dst_skip;
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1795
diff changeset
    94
    Uint8 *palmap = info->table;
2267
c785543d1843 Okay, still some bugs, but everything builds again...
Sam Lantinga <slouken@libsdl.org>
parents: 2262
diff changeset
    95
    SDL_PixelFormat *srcfmt = info->src_fmt;
c785543d1843 Okay, still some bugs, but everything builds again...
Sam Lantinga <slouken@libsdl.org>
parents: 2262
diff changeset
    96
    SDL_PixelFormat *dstfmt = info->dst_fmt;
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1795
diff changeset
    97
    int srcbpp = srcfmt->BytesPerPixel;
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    98
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1795
diff changeset
    99
    while (height--) {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1795
diff changeset
   100
	    /* *INDENT-OFF* */
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   101
	    DUFFS_LOOP4(
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   102
	    {
1162
2651158f59b8 Enable altivec blitters on PowerPC Linux, and some fixes for recent
Ryan C. Gordon <icculus@icculus.org>
parents: 1047
diff changeset
   103
		Uint32 Pixel;
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   104
		unsigned sR;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   105
		unsigned sG;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   106
		unsigned sB;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   107
		unsigned sA;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   108
		unsigned dR;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   109
		unsigned dG;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   110
		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
   111
		DISEMBLE_RGBA(src,srcbpp,srcfmt,Pixel,sR,sG,sB,sA);
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   112
		dR = dstfmt->palette->colors[*dst].r;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   113
		dG = dstfmt->palette->colors[*dst].g;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   114
		dB = dstfmt->palette->colors[*dst].b;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   115
		ALPHA_BLEND(sR, sG, sB, sA, dR, dG, dB);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   116
		dR &= 0xff;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   117
		dG &= 0xff;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   118
		dB &= 0xff;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   119
		/* Pack RGB into 8bit pixel */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   120
		if ( palmap == NULL ) {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   121
		    *dst =((dR>>5)<<(3+2))|
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   122
			  ((dG>>5)<<(2))|
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   123
			  ((dB>>6)<<(0));
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   124
		} else {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   125
		    *dst = palmap[((dR>>5)<<(3+2))|
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   126
				  ((dG>>5)<<(2))  |
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   127
				  ((dB>>6)<<(0))  ];
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   128
		}
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   129
		dst++;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   130
		src += srcbpp;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   131
	    },
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   132
	    width);
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1795
diff changeset
   133
	    /* *INDENT-ON* */
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1795
diff changeset
   134
        src += srcskip;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1795
diff changeset
   135
        dst += dstskip;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1795
diff changeset
   136
    }
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   137
}
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   138
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   139
/* colorkeyed N->1 blending with per-surface alpha */
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1795
diff changeset
   140
static void
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1795
diff changeset
   141
BlitNto1SurfaceAlphaKey(SDL_BlitInfo * info)
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   142
{
2262
bee005ace1bf Work in progress: merging new texture features into SDL blit system
Sam Lantinga <slouken@libsdl.org>
parents: 2261
diff changeset
   143
    int width = info->dst_w;
bee005ace1bf Work in progress: merging new texture features into SDL blit system
Sam Lantinga <slouken@libsdl.org>
parents: 2261
diff changeset
   144
    int height = info->dst_h;
bee005ace1bf Work in progress: merging new texture features into SDL blit system
Sam Lantinga <slouken@libsdl.org>
parents: 2261
diff changeset
   145
    Uint8 *src = info->src;
2267
c785543d1843 Okay, still some bugs, but everything builds again...
Sam Lantinga <slouken@libsdl.org>
parents: 2262
diff changeset
   146
    int srcskip = info->src_skip;
2262
bee005ace1bf Work in progress: merging new texture features into SDL blit system
Sam Lantinga <slouken@libsdl.org>
parents: 2261
diff changeset
   147
    Uint8 *dst = info->dst;
2267
c785543d1843 Okay, still some bugs, but everything builds again...
Sam Lantinga <slouken@libsdl.org>
parents: 2262
diff changeset
   148
    int dstskip = info->dst_skip;
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1795
diff changeset
   149
    Uint8 *palmap = info->table;
2267
c785543d1843 Okay, still some bugs, but everything builds again...
Sam Lantinga <slouken@libsdl.org>
parents: 2262
diff changeset
   150
    SDL_PixelFormat *srcfmt = info->src_fmt;
c785543d1843 Okay, still some bugs, but everything builds again...
Sam Lantinga <slouken@libsdl.org>
parents: 2262
diff changeset
   151
    SDL_PixelFormat *dstfmt = info->dst_fmt;
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1795
diff changeset
   152
    int srcbpp = srcfmt->BytesPerPixel;
2267
c785543d1843 Okay, still some bugs, but everything builds again...
Sam Lantinga <slouken@libsdl.org>
parents: 2262
diff changeset
   153
    Uint32 ckey = info->colorkey;
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   154
2267
c785543d1843 Okay, still some bugs, but everything builds again...
Sam Lantinga <slouken@libsdl.org>
parents: 2262
diff changeset
   155
    const int A = info->a;
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   156
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1795
diff changeset
   157
    while (height--) {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1795
diff changeset
   158
	    /* *INDENT-OFF* */
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   159
	    DUFFS_LOOP(
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   160
	    {
1162
2651158f59b8 Enable altivec blitters on PowerPC Linux, and some fixes for recent
Ryan C. Gordon <icculus@icculus.org>
parents: 1047
diff changeset
   161
		Uint32 Pixel;
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   162
		unsigned sR;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   163
		unsigned sG;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   164
		unsigned sB;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   165
		unsigned dR;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   166
		unsigned dG;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   167
		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
   168
		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
   169
		if ( Pixel != ckey ) {
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   170
		    dR = dstfmt->palette->colors[*dst].r;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   171
		    dG = dstfmt->palette->colors[*dst].g;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   172
		    dB = dstfmt->palette->colors[*dst].b;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   173
		    ALPHA_BLEND(sR, sG, sB, A, dR, dG, dB);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   174
		    dR &= 0xff;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   175
		    dG &= 0xff;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   176
		    dB &= 0xff;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   177
		    /* Pack RGB into 8bit pixel */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   178
		    if ( palmap == NULL ) {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   179
			*dst =((dR>>5)<<(3+2))|
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   180
			      ((dG>>5)<<(2)) |
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   181
			      ((dB>>6)<<(0));
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   182
		    } else {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   183
			*dst = palmap[((dR>>5)<<(3+2))|
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   184
				      ((dG>>5)<<(2))  |
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   185
				      ((dB>>6)<<(0))  ];
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   186
		    }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   187
		}
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   188
		dst++;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   189
		src += srcbpp;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   190
	    },
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   191
	    width);
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1795
diff changeset
   192
	    /* *INDENT-ON* */
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1795
diff changeset
   193
        src += srcskip;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1795
diff changeset
   194
        dst += dstskip;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1795
diff changeset
   195
    }
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   196
}
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   197
2255
17b2369756be Use MMX intrinsics over GCC inline assembly
Sam Lantinga <slouken@libsdl.org>
parents: 2232
diff changeset
   198
#ifdef __MMX__
1542
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   199
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   200
/* fast RGB888->(A)RGB888 blending with surface alpha=128 special case */
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1795
diff changeset
   201
static void
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1795
diff changeset
   202
BlitRGBtoRGBSurfaceAlpha128MMX(SDL_BlitInfo * info)
1542
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   203
{
2262
bee005ace1bf Work in progress: merging new texture features into SDL blit system
Sam Lantinga <slouken@libsdl.org>
parents: 2261
diff changeset
   204
    int width = info->dst_w;
bee005ace1bf Work in progress: merging new texture features into SDL blit system
Sam Lantinga <slouken@libsdl.org>
parents: 2261
diff changeset
   205
    int height = info->dst_h;
bee005ace1bf Work in progress: merging new texture features into SDL blit system
Sam Lantinga <slouken@libsdl.org>
parents: 2261
diff changeset
   206
    Uint32 *srcp = (Uint32 *) info->src;
2267
c785543d1843 Okay, still some bugs, but everything builds again...
Sam Lantinga <slouken@libsdl.org>
parents: 2262
diff changeset
   207
    int srcskip = info->src_skip >> 2;
2262
bee005ace1bf Work in progress: merging new texture features into SDL blit system
Sam Lantinga <slouken@libsdl.org>
parents: 2261
diff changeset
   208
    Uint32 *dstp = (Uint32 *) info->dst;
2267
c785543d1843 Okay, still some bugs, but everything builds again...
Sam Lantinga <slouken@libsdl.org>
parents: 2262
diff changeset
   209
    int dstskip = info->dst_skip >> 2;
c785543d1843 Okay, still some bugs, but everything builds again...
Sam Lantinga <slouken@libsdl.org>
parents: 2262
diff changeset
   210
    Uint32 dalpha = info->dst_fmt->Amask;
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1795
diff changeset
   211
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1795
diff changeset
   212
    __m64 src1, src2, dst1, dst2, lmask, hmask, dsta;
1542
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   213
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1795
diff changeset
   214
    hmask = _mm_set_pi32(0x00fefefe, 0x00fefefe);       /* alpha128 mask -> hmask */
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1795
diff changeset
   215
    lmask = _mm_set_pi32(0x00010101, 0x00010101);       /* !alpha128 mask -> lmask */
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1795
diff changeset
   216
    dsta = _mm_set_pi32(dalpha, dalpha);        /* dst alpha mask -> dsta */
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1795
diff changeset
   217
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1795
diff changeset
   218
    while (height--) {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1795
diff changeset
   219
        int n = width;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1795
diff changeset
   220
        if (n & 1) {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1795
diff changeset
   221
            Uint32 s = *srcp++;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1795
diff changeset
   222
            Uint32 d = *dstp;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1795
diff changeset
   223
            *dstp++ = ((((s & 0x00fefefe) + (d & 0x00fefefe)) >> 1)
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1795
diff changeset
   224
                       + (s & d & 0x00010101)) | dalpha;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1795
diff changeset
   225
            n--;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1795
diff changeset
   226
        }
1542
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   227
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1795
diff changeset
   228
        for (n >>= 1; n > 0; --n) {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1795
diff changeset
   229
            dst1 = *(__m64 *) dstp;     /* 2 x dst -> dst1(ARGBARGB) */
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1795
diff changeset
   230
            dst2 = dst1;        /* 2 x dst -> dst2(ARGBARGB) */
1542
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   231
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1795
diff changeset
   232
            src1 = *(__m64 *) srcp;     /* 2 x src -> src1(ARGBARGB) */
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1795
diff changeset
   233
            src2 = src1;        /* 2 x src -> src2(ARGBARGB) */
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1795
diff changeset
   234
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1795
diff changeset
   235
            dst2 = _mm_and_si64(dst2, hmask);   /* dst & mask -> dst2 */
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1795
diff changeset
   236
            src2 = _mm_and_si64(src2, hmask);   /* src & mask -> src2 */
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1795
diff changeset
   237
            src2 = _mm_add_pi32(src2, dst2);    /* dst2 + src2 -> src2 */
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1795
diff changeset
   238
            src2 = _mm_srli_pi32(src2, 1);      /* src2 >> 1 -> src2 */
1542
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   239
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1795
diff changeset
   240
            dst1 = _mm_and_si64(dst1, src1);    /* src & dst -> dst1 */
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1795
diff changeset
   241
            dst1 = _mm_and_si64(dst1, lmask);   /* dst1 & !mask -> dst1 */
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1795
diff changeset
   242
            dst1 = _mm_add_pi32(dst1, src2);    /* src2 + dst1 -> dst1 */
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1795
diff changeset
   243
            dst1 = _mm_or_si64(dst1, dsta);     /* dsta(full alpha) | dst1 -> dst1 */
1542
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   244
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1795
diff changeset
   245
            *(__m64 *) dstp = dst1;     /* dst1 -> 2 x dst pixels */
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1795
diff changeset
   246
            dstp += 2;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1795
diff changeset
   247
            srcp += 2;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1795
diff changeset
   248
        }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1795
diff changeset
   249
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1795
diff changeset
   250
        srcp += srcskip;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1795
diff changeset
   251
        dstp += dstskip;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1795
diff changeset
   252
    }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1795
diff changeset
   253
    _mm_empty();
1542
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   254
}
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   255
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   256
/* fast RGB888->(A)RGB888 blending with surface alpha */
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1795
diff changeset
   257
static void
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1795
diff changeset
   258
BlitRGBtoRGBSurfaceAlphaMMX(SDL_BlitInfo * info)
1542
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   259
{
2267
c785543d1843 Okay, still some bugs, but everything builds again...
Sam Lantinga <slouken@libsdl.org>
parents: 2262
diff changeset
   260
    SDL_PixelFormat *df = info->dst_fmt;
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1795
diff changeset
   261
    Uint32 chanmask = df->Rmask | df->Gmask | df->Bmask;
2267
c785543d1843 Okay, still some bugs, but everything builds again...
Sam Lantinga <slouken@libsdl.org>
parents: 2262
diff changeset
   262
    unsigned alpha = info->a;
1542
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   263
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1795
diff changeset
   264
    if (alpha == 128 && (df->Rmask | df->Gmask | df->Bmask) == 0x00FFFFFF) {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1795
diff changeset
   265
        /* only call a128 version when R,G,B occupy lower bits */
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1795
diff changeset
   266
        BlitRGBtoRGBSurfaceAlpha128MMX(info);
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1795
diff changeset
   267
    } else {
2262
bee005ace1bf Work in progress: merging new texture features into SDL blit system
Sam Lantinga <slouken@libsdl.org>
parents: 2261
diff changeset
   268
        int width = info->dst_w;
bee005ace1bf Work in progress: merging new texture features into SDL blit system
Sam Lantinga <slouken@libsdl.org>
parents: 2261
diff changeset
   269
        int height = info->dst_h;
bee005ace1bf Work in progress: merging new texture features into SDL blit system
Sam Lantinga <slouken@libsdl.org>
parents: 2261
diff changeset
   270
        Uint32 *srcp = (Uint32 *) info->src;
2267
c785543d1843 Okay, still some bugs, but everything builds again...
Sam Lantinga <slouken@libsdl.org>
parents: 2262
diff changeset
   271
        int srcskip = info->src_skip >> 2;
2262
bee005ace1bf Work in progress: merging new texture features into SDL blit system
Sam Lantinga <slouken@libsdl.org>
parents: 2261
diff changeset
   272
        Uint32 *dstp = (Uint32 *) info->dst;
2267
c785543d1843 Okay, still some bugs, but everything builds again...
Sam Lantinga <slouken@libsdl.org>
parents: 2262
diff changeset
   273
        int dstskip = info->dst_skip >> 2;
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1795
diff changeset
   274
        Uint32 dalpha = df->Amask;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1795
diff changeset
   275
        Uint32 amult;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1795
diff changeset
   276
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1795
diff changeset
   277
        __m64 src1, src2, dst1, dst2, mm_alpha, mm_zero, dsta;
1542
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   278
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1795
diff changeset
   279
        mm_zero = _mm_setzero_si64();   /* 0 -> mm_zero */
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1795
diff changeset
   280
        /* form the alpha mult */
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1795
diff changeset
   281
        amult = alpha | (alpha << 8);
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1795
diff changeset
   282
        amult = amult | (amult << 16);
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1795
diff changeset
   283
        chanmask =
3013
8cc00819c8d6 Reverted Bob's indent checkin
Sam Lantinga <slouken@libsdl.org>
parents: 3011
diff changeset
   284
            (0xff << df->Rshift) | (0xff << df->
8cc00819c8d6 Reverted Bob's indent checkin
Sam Lantinga <slouken@libsdl.org>
parents: 3011
diff changeset
   285
                                    Gshift) | (0xff << df->Bshift);
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1795
diff changeset
   286
        mm_alpha = _mm_set_pi32(0, amult & chanmask);   /* 0000AAAA -> mm_alpha, minus 1 chan */
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1795
diff changeset
   287
        mm_alpha = _mm_unpacklo_pi8(mm_alpha, mm_zero); /* 0A0A0A0A -> mm_alpha, minus 1 chan */
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1795
diff changeset
   288
        /* at this point mm_alpha can be 000A0A0A or 0A0A0A00 or another combo */
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1795
diff changeset
   289
        dsta = _mm_set_pi32(dalpha, dalpha);    /* dst alpha mask -> dsta */
1542
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   290
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1795
diff changeset
   291
        while (height--) {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1795
diff changeset
   292
            int n = width;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1795
diff changeset
   293
            if (n & 1) {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1795
diff changeset
   294
                /* One Pixel Blend */
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1795
diff changeset
   295
                src2 = _mm_cvtsi32_si64(*srcp); /* src(ARGB) -> src2 (0000ARGB) */
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1795
diff changeset
   296
                src2 = _mm_unpacklo_pi8(src2, mm_zero); /* 0A0R0G0B -> src2 */
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1795
diff changeset
   297
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1795
diff changeset
   298
                dst1 = _mm_cvtsi32_si64(*dstp); /* dst(ARGB) -> dst1 (0000ARGB) */
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1795
diff changeset
   299
                dst1 = _mm_unpacklo_pi8(dst1, mm_zero); /* 0A0R0G0B -> dst1 */
1542
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   300
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1795
diff changeset
   301
                src2 = _mm_sub_pi16(src2, dst1);        /* src2 - dst2 -> src2 */
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1795
diff changeset
   302
                src2 = _mm_mullo_pi16(src2, mm_alpha);  /* src2 * alpha -> src2 */
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1795
diff changeset
   303
                src2 = _mm_srli_pi16(src2, 8);  /* src2 >> 8 -> src2 */
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1795
diff changeset
   304
                dst1 = _mm_add_pi8(src2, dst1); /* src2 + dst1 -> dst1 */
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1795
diff changeset
   305
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1795
diff changeset
   306
                dst1 = _mm_packs_pu16(dst1, mm_zero);   /* 0000ARGB -> dst1 */
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1795
diff changeset
   307
                dst1 = _mm_or_si64(dst1, dsta); /* dsta | dst1 -> dst1 */
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1795
diff changeset
   308
                *dstp = _mm_cvtsi64_si32(dst1); /* dst1 -> pixel */
1542
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   309
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1795
diff changeset
   310
                ++srcp;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1795
diff changeset
   311
                ++dstp;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1795
diff changeset
   312
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1795
diff changeset
   313
                n--;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1795
diff changeset
   314
            }
1542
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   315
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1795
diff changeset
   316
            for (n >>= 1; n > 0; --n) {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1795
diff changeset
   317
                /* Two Pixels Blend */
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1795
diff changeset
   318
                src1 = *(__m64 *) srcp; /* 2 x src -> src1(ARGBARGB) */
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1795
diff changeset
   319
                src2 = src1;    /* 2 x src -> src2(ARGBARGB) */
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1795
diff changeset
   320
                src1 = _mm_unpacklo_pi8(src1, mm_zero); /* low - 0A0R0G0B -> src1 */
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1795
diff changeset
   321
                src2 = _mm_unpackhi_pi8(src2, mm_zero); /* high - 0A0R0G0B -> src2 */
1542
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   322
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1795
diff changeset
   323
                dst1 = *(__m64 *) dstp; /* 2 x dst -> dst1(ARGBARGB) */
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1795
diff changeset
   324
                dst2 = dst1;    /* 2 x dst -> dst2(ARGBARGB) */
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1795
diff changeset
   325
                dst1 = _mm_unpacklo_pi8(dst1, mm_zero); /* low - 0A0R0G0B -> dst1 */
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1795
diff changeset
   326
                dst2 = _mm_unpackhi_pi8(dst2, mm_zero); /* high - 0A0R0G0B -> dst2 */
1542
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   327
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1795
diff changeset
   328
                src1 = _mm_sub_pi16(src1, dst1);        /* src1 - dst1 -> src1 */
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1795
diff changeset
   329
                src1 = _mm_mullo_pi16(src1, mm_alpha);  /* src1 * alpha -> src1 */
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1795
diff changeset
   330
                src1 = _mm_srli_pi16(src1, 8);  /* src1 >> 8 -> src1 */
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1795
diff changeset
   331
                dst1 = _mm_add_pi8(src1, dst1); /* src1 + dst1(dst1) -> dst1 */
1542
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   332
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1795
diff changeset
   333
                src2 = _mm_sub_pi16(src2, dst2);        /* src2 - dst2 -> src2 */
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1795
diff changeset
   334
                src2 = _mm_mullo_pi16(src2, mm_alpha);  /* src2 * alpha -> src2 */
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1795
diff changeset
   335
                src2 = _mm_srli_pi16(src2, 8);  /* src2 >> 8 -> src2 */
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1795
diff changeset
   336
                dst2 = _mm_add_pi8(src2, dst2); /* src2 + dst2(dst2) -> dst2 */
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1795
diff changeset
   337
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1795
diff changeset
   338
                dst1 = _mm_packs_pu16(dst1, dst2);      /* 0A0R0G0B(res1), 0A0R0G0B(res2) -> dst1(ARGBARGB) */
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1795
diff changeset
   339
                dst1 = _mm_or_si64(dst1, dsta); /* dsta | dst1 -> dst1 */
1542
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   340
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1795
diff changeset
   341
                *(__m64 *) dstp = dst1; /* dst1 -> 2 x pixel */
1542
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   342
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1795
diff changeset
   343
                srcp += 2;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1795
diff changeset
   344
                dstp += 2;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1795
diff changeset
   345
            }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1795
diff changeset
   346
            srcp += srcskip;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1795
diff changeset
   347
            dstp += dstskip;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1795
diff changeset
   348
        }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1795
diff changeset
   349
        _mm_empty();
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1795
diff changeset
   350
    }
1542
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   351
}
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   352
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   353
/* fast ARGB888->(A)RGB888 blending with pixel alpha */
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1795
diff changeset
   354
static void
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1795
diff changeset
   355
BlitRGBtoRGBPixelAlphaMMX(SDL_BlitInfo * info)
1542
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   356
{
2262
bee005ace1bf Work in progress: merging new texture features into SDL blit system
Sam Lantinga <slouken@libsdl.org>
parents: 2261
diff changeset
   357
    int width = info->dst_w;
bee005ace1bf Work in progress: merging new texture features into SDL blit system
Sam Lantinga <slouken@libsdl.org>
parents: 2261
diff changeset
   358
    int height = info->dst_h;
bee005ace1bf Work in progress: merging new texture features into SDL blit system
Sam Lantinga <slouken@libsdl.org>
parents: 2261
diff changeset
   359
    Uint32 *srcp = (Uint32 *) info->src;
2267
c785543d1843 Okay, still some bugs, but everything builds again...
Sam Lantinga <slouken@libsdl.org>
parents: 2262
diff changeset
   360
    int srcskip = info->src_skip >> 2;
2262
bee005ace1bf Work in progress: merging new texture features into SDL blit system
Sam Lantinga <slouken@libsdl.org>
parents: 2261
diff changeset
   361
    Uint32 *dstp = (Uint32 *) info->dst;
2267
c785543d1843 Okay, still some bugs, but everything builds again...
Sam Lantinga <slouken@libsdl.org>
parents: 2262
diff changeset
   362
    int dstskip = info->dst_skip >> 2;
c785543d1843 Okay, still some bugs, but everything builds again...
Sam Lantinga <slouken@libsdl.org>
parents: 2262
diff changeset
   363
    SDL_PixelFormat *sf = info->src_fmt;
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1795
diff changeset
   364
    Uint32 chanmask = sf->Rmask | sf->Gmask | sf->Bmask;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1795
diff changeset
   365
    Uint32 amask = sf->Amask;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1795
diff changeset
   366
    Uint32 ashift = sf->Ashift;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1795
diff changeset
   367
    Uint64 multmask;
1542
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   368
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1795
diff changeset
   369
    __m64 src1, dst1, mm_alpha, mm_zero, dmask;
1542
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   370
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1795
diff changeset
   371
    mm_zero = _mm_setzero_si64();       /* 0 -> mm_zero */
2260
Sam Lantinga <slouken@libsdl.org>
parents: 2257
diff changeset
   372
    multmask = 0xFFFF;
2255
17b2369756be Use MMX intrinsics over GCC inline assembly
Sam Lantinga <slouken@libsdl.org>
parents: 2232
diff changeset
   373
    multmask <<= (ashift * 2);
17b2369756be Use MMX intrinsics over GCC inline assembly
Sam Lantinga <slouken@libsdl.org>
parents: 2232
diff changeset
   374
    multmask = ~multmask;
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1795
diff changeset
   375
    dmask = *(__m64 *) & multmask;      /* dst alpha mask -> dmask */
1542
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   376
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1795
diff changeset
   377
    while (height--) {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1795
diff changeset
   378
		/* *INDENT-OFF* */
1542
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   379
		DUFFS_LOOP4({
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   380
		Uint32 alpha = *srcp & amask;
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
			*dstp = (*srcp & chanmask) | (*dstp & ~chanmask);
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   386
		} else {
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   387
			src1 = _mm_cvtsi32_si64(*srcp); /* src(ARGB) -> src1 (0000ARGB)*/
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   388
			src1 = _mm_unpacklo_pi8(src1, mm_zero); /* 0A0R0G0B -> src1 */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   389
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   390
			dst1 = _mm_cvtsi32_si64(*dstp); /* dst(ARGB) -> dst1 (0000ARGB)*/
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   391
			dst1 = _mm_unpacklo_pi8(dst1, mm_zero); /* 0A0R0G0B -> dst1 */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   392
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   393
			mm_alpha = _mm_cvtsi32_si64(alpha); /* alpha -> mm_alpha (0000000A) */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   394
			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
   395
			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
   396
			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
   397
			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
   398
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   399
			/* blend */		    
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   400
			src1 = _mm_sub_pi16(src1, dst1);/* src1 - dst1 -> src1 */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   401
			src1 = _mm_mullo_pi16(src1, mm_alpha); /* (src1 - dst1) * alpha -> src1 */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   402
			src1 = _mm_srli_pi16(src1, 8); /* src1 >> 8 -> src1(000R0G0B) */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   403
			dst1 = _mm_add_pi8(src1, dst1); /* src1 + dst1 -> dst1(0A0R0G0B) */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   404
			dst1 = _mm_packs_pu16(dst1, mm_zero);  /* 0000ARGB -> dst1 */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   405
			
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   406
			*dstp = _mm_cvtsi64_si32(dst1); /* dst1 -> pixel */
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   407
		}
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   408
		++srcp;
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   409
		++dstp;
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   410
	    }, width);
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1795
diff changeset
   411
		/* *INDENT-ON* */
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1795
diff changeset
   412
        srcp += srcskip;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1795
diff changeset
   413
        dstp += dstskip;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1795
diff changeset
   414
    }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1795
diff changeset
   415
    _mm_empty();
1542
a8bf1aa21020 Fixed bug #15
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   416
}
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1795
diff changeset
   417
2255
17b2369756be Use MMX intrinsics over GCC inline assembly
Sam Lantinga <slouken@libsdl.org>
parents: 2232
diff changeset
   418
#endif /* __MMX__ */
689
5bb080d35049 Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
   419
5389
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   420
#if SDL_ALTIVEC_BLITTERS
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   421
#if __MWERKS__
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   422
#pragma altivec_model on
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   423
#endif
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   424
#if HAVE_ALTIVEC_H
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   425
#include <altivec.h>
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   426
#endif
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   427
#include <assert.h>
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   428
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   429
#if (defined(__MACOSX__) && (__GNUC__ < 4))
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   430
#define VECUINT8_LITERAL(a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p) \
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   431
        (vector unsigned char) ( a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p )
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   432
#define VECUINT16_LITERAL(a,b,c,d,e,f,g,h) \
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   433
        (vector unsigned short) ( a,b,c,d,e,f,g,h )
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   434
#else
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   435
#define VECUINT8_LITERAL(a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p) \
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   436
        (vector unsigned char) { a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p }
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   437
#define VECUINT16_LITERAL(a,b,c,d,e,f,g,h) \
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   438
        (vector unsigned short) { a,b,c,d,e,f,g,h }
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   439
#endif
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   440
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   441
#define UNALIGNED_PTR(x) (((size_t) x) & 0x0000000F)
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   442
#define VECPRINT(msg, v) do { \
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   443
    vector unsigned int tmpvec = (vector unsigned int)(v); \
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   444
    unsigned int *vp = (unsigned int *)&tmpvec; \
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   445
    printf("%s = %08X %08X %08X %08X\n", msg, vp[0], vp[1], vp[2], vp[3]); \
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   446
} while (0)
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   447
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   448
/* the permuation vector that takes the high bytes out of all the appropriate shorts 
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   449
    (vector unsigned char)(
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   450
        0x00, 0x10, 0x02, 0x12,
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   451
        0x04, 0x14, 0x06, 0x16,
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   452
        0x08, 0x18, 0x0A, 0x1A,
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   453
        0x0C, 0x1C, 0x0E, 0x1E );
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   454
*/
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   455
#define VEC_MERGE_PERMUTE() (vec_add(vec_lvsl(0, (int*)NULL), (vector unsigned char)vec_splat_u16(0x0F)))
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   456
#define VEC_U32_24() (vec_add(vec_splat_u32(12), vec_splat_u32(12)))
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   457
#define VEC_ALPHA_MASK() ((vector unsigned char)vec_sl((vector unsigned int)vec_splat_s8(-1), VEC_U32_24()))
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   458
#define VEC_ALIGNER(src) ((UNALIGNED_PTR(src)) \
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   459
    ? vec_lvsl(0, src) \
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   460
    : vec_add(vec_lvsl(8, src), vec_splat_u8(8)))
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   461
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   462
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   463
#define VEC_MULTIPLY_ALPHA(vs, vd, valpha, mergePermute, v1_16, v8_16) do { \
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   464
    /* vtemp1 contains source AAGGAAGGAAGGAAGG */ \
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   465
    vector unsigned short vtemp1 = vec_mule(vs, valpha); \
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   466
    /* vtemp2 contains source RRBBRRBBRRBBRRBB */ \
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   467
    vector unsigned short vtemp2 = vec_mulo(vs, valpha); \
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   468
    /* valpha2 is 255-alpha */ \
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   469
    vector unsigned char valpha2 = vec_nor(valpha, valpha); \
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   470
    /* vtemp3 contains dest AAGGAAGGAAGGAAGG */ \
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   471
    vector unsigned short vtemp3 = vec_mule(vd, valpha2); \
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   472
    /* vtemp4 contains dest RRBBRRBBRRBBRRBB */ \
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   473
    vector unsigned short vtemp4 = vec_mulo(vd, valpha2); \
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   474
    /* add source and dest */ \
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   475
    vtemp1 = vec_add(vtemp1, vtemp3); \
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   476
    vtemp2 = vec_add(vtemp2, vtemp4); \
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   477
    /* vtemp1 = (vtemp1 + 1) + ((vtemp1 + 1) >> 8) */ \
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   478
    vtemp1 = vec_add(vtemp1, v1_16); \
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   479
    vtemp3 = vec_sr(vtemp1, v8_16); \
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   480
    vtemp1 = vec_add(vtemp1, vtemp3); \
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   481
    /* vtemp2 = (vtemp2 + 1) + ((vtemp2 + 1) >> 8) */ \
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   482
    vtemp2 = vec_add(vtemp2, v1_16); \
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   483
    vtemp4 = vec_sr(vtemp2, v8_16); \
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   484
    vtemp2 = vec_add(vtemp2, vtemp4); \
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   485
    /* (>>8) and get ARGBARGBARGBARGB */ \
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   486
    vd = (vector unsigned char)vec_perm(vtemp1, vtemp2, mergePermute); \
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   487
} while (0)
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   488
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   489
/* Calculate the permute vector used for 32->32 swizzling */
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   490
static vector unsigned char
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   491
calc_swizzle32(const SDL_PixelFormat * srcfmt, const SDL_PixelFormat * dstfmt)
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   492
{
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   493
    /*
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   494
     * We have to assume that the bits that aren't used by other
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   495
     *  colors is alpha, and it's one complete byte, since some formats
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   496
     *  leave alpha with a zero mask, but we should still swizzle the bits.
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   497
     */
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   498
    /* ARGB */
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   499
    const static struct SDL_PixelFormat default_pixel_format = {
5407
40c9d744e595 Fixed compiling AltiVec blitters
Sam Lantinga <slouken@libsdl.org>
parents: 5389
diff changeset
   500
        0, NULL, 0, 0,
6165
b7347e716ab6 Fixed bug 1225 - Altivec blitters broken due to SDL_PixelFormat
Sam Lantinga <slouken@libsdl.org>
parents: 6138
diff changeset
   501
        {0, 0},
b7347e716ab6 Fixed bug 1225 - Altivec blitters broken due to SDL_PixelFormat
Sam Lantinga <slouken@libsdl.org>
parents: 6138
diff changeset
   502
        0x00FF0000, 0x0000FF00, 0x000000FF, 0xFF000000,
5389
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   503
        0, 0, 0, 0,
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   504
        16, 8, 0, 24,
5407
40c9d744e595 Fixed compiling AltiVec blitters
Sam Lantinga <slouken@libsdl.org>
parents: 5389
diff changeset
   505
        0, NULL
5389
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   506
    };
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   507
    if (!srcfmt) {
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   508
        srcfmt = &default_pixel_format;
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   509
    }
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   510
    if (!dstfmt) {
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   511
        dstfmt = &default_pixel_format;
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   512
    }
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   513
    const vector unsigned char plus = VECUINT8_LITERAL(0x00, 0x00, 0x00, 0x00,
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   514
                                                       0x04, 0x04, 0x04, 0x04,
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   515
                                                       0x08, 0x08, 0x08, 0x08,
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   516
                                                       0x0C, 0x0C, 0x0C,
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   517
                                                       0x0C);
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   518
    vector unsigned char vswiz;
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   519
    vector unsigned int srcvec;
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   520
#define RESHIFT(X) (3 - ((X) >> 3))
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   521
    Uint32 rmask = RESHIFT(srcfmt->Rshift) << (dstfmt->Rshift);
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   522
    Uint32 gmask = RESHIFT(srcfmt->Gshift) << (dstfmt->Gshift);
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   523
    Uint32 bmask = RESHIFT(srcfmt->Bshift) << (dstfmt->Bshift);
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   524
    Uint32 amask;
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   525
    /* Use zero for alpha if either surface doesn't have alpha */
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   526
    if (dstfmt->Amask) {
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   527
        amask =
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   528
            ((srcfmt->Amask) ? RESHIFT(srcfmt->
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   529
                                       Ashift) : 0x10) << (dstfmt->Ashift);
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   530
    } else {
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   531
        amask =
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   532
            0x10101010 & ((dstfmt->Rmask | dstfmt->Gmask | dstfmt->Bmask) ^
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   533
                          0xFFFFFFFF);
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   534
    }
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   535
#undef RESHIFT
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   536
    ((unsigned int *) (char *) &srcvec)[0] = (rmask | gmask | bmask | amask);
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   537
    vswiz = vec_add(plus, (vector unsigned char) vec_splat(srcvec, 0));
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   538
    return (vswiz);
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   539
}
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   540
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   541
static void
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   542
Blit32to565PixelAlphaAltivec(SDL_BlitInfo * info)
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   543
{
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   544
    int height = info->dst_h;
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   545
    Uint8 *src = (Uint8 *) info->src;
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   546
    int srcskip = info->src_skip;
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   547
    Uint8 *dst = (Uint8 *) info->dst;
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   548
    int dstskip = info->dst_skip;
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   549
    SDL_PixelFormat *srcfmt = info->src_fmt;
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   550
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   551
    vector unsigned char v0 = vec_splat_u8(0);
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   552
    vector unsigned short v8_16 = vec_splat_u16(8);
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   553
    vector unsigned short v1_16 = vec_splat_u16(1);
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   554
    vector unsigned short v2_16 = vec_splat_u16(2);
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   555
    vector unsigned short v3_16 = vec_splat_u16(3);
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   556
    vector unsigned int v8_32 = vec_splat_u32(8);
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   557
    vector unsigned int v16_32 = vec_add(v8_32, v8_32);
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   558
    vector unsigned short v3f =
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   559
        VECUINT16_LITERAL(0x003f, 0x003f, 0x003f, 0x003f,
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   560
                          0x003f, 0x003f, 0x003f, 0x003f);
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   561
    vector unsigned short vfc =
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   562
        VECUINT16_LITERAL(0x00fc, 0x00fc, 0x00fc, 0x00fc,
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   563
                          0x00fc, 0x00fc, 0x00fc, 0x00fc);
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   564
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   565
    /* 
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   566
       0x10 - 0x1f is the alpha
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   567
       0x00 - 0x0e evens are the red
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   568
       0x01 - 0x0f odds are zero
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   569
     */
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   570
    vector unsigned char vredalpha1 = VECUINT8_LITERAL(0x10, 0x00, 0x01, 0x01,
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   571
                                                       0x10, 0x02, 0x01, 0x01,
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   572
                                                       0x10, 0x04, 0x01, 0x01,
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   573
                                                       0x10, 0x06, 0x01,
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   574
                                                       0x01);
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   575
    vector unsigned char vredalpha2 =
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   576
        (vector unsigned char) (vec_add((vector unsigned int) vredalpha1,
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   577
                                        vec_sl(v8_32, v16_32))
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   578
        );
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   579
    /*
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   580
       0x00 - 0x0f is ARxx ARxx ARxx ARxx
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   581
       0x11 - 0x0f odds are blue
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   582
     */
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   583
    vector unsigned char vblue1 = VECUINT8_LITERAL(0x00, 0x01, 0x02, 0x11,
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   584
                                                   0x04, 0x05, 0x06, 0x13,
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   585
                                                   0x08, 0x09, 0x0a, 0x15,
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   586
                                                   0x0c, 0x0d, 0x0e, 0x17);
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   587
    vector unsigned char vblue2 =
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   588
        (vector unsigned char) (vec_add((vector unsigned int) vblue1, v8_32)
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   589
        );
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   590
    /*
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   591
       0x00 - 0x0f is ARxB ARxB ARxB ARxB
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   592
       0x10 - 0x0e evens are green
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   593
     */
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   594
    vector unsigned char vgreen1 = VECUINT8_LITERAL(0x00, 0x01, 0x10, 0x03,
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   595
                                                    0x04, 0x05, 0x12, 0x07,
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   596
                                                    0x08, 0x09, 0x14, 0x0b,
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   597
                                                    0x0c, 0x0d, 0x16, 0x0f);
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   598
    vector unsigned char vgreen2 =
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   599
        (vector unsigned
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   600
         char) (vec_add((vector unsigned int) vgreen1, vec_sl(v8_32, v8_32))
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   601
        );
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   602
    vector unsigned char vgmerge = VECUINT8_LITERAL(0x00, 0x02, 0x00, 0x06,
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   603
                                                    0x00, 0x0a, 0x00, 0x0e,
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   604
                                                    0x00, 0x12, 0x00, 0x16,
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   605
                                                    0x00, 0x1a, 0x00, 0x1e);
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   606
    vector unsigned char mergePermute = VEC_MERGE_PERMUTE();
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   607
    vector unsigned char vpermute = calc_swizzle32(srcfmt, NULL);
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   608
    vector unsigned char valphaPermute =
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   609
        vec_and(vec_lvsl(0, (int *) NULL), vec_splat_u8(0xC));
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   610
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   611
    vector unsigned short vf800 = (vector unsigned short) vec_splat_u8(-7);
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   612
    vf800 = vec_sl(vf800, vec_splat_u16(8));
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   613
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   614
    while (height--) {
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   615
        int extrawidth;
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   616
        vector unsigned char valigner;
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   617
        vector unsigned char vsrc;
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   618
        vector unsigned char voverflow;
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   619
        int width = info->dst_w;
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   620
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   621
#define ONE_PIXEL_BLEND(condition, widthvar) \
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   622
        while (condition) { \
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   623
            Uint32 Pixel; \
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   624
            unsigned sR, sG, sB, dR, dG, dB, sA; \
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   625
            DISEMBLE_RGBA(src, 4, srcfmt, Pixel, sR, sG, sB, sA); \
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   626
            if(sA) { \
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   627
                unsigned short dstpixel = *((unsigned short *)dst); \
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   628
                dR = (dstpixel >> 8) & 0xf8; \
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   629
                dG = (dstpixel >> 3) & 0xfc; \
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   630
                dB = (dstpixel << 3) & 0xf8; \
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   631
                ALPHA_BLEND(sR, sG, sB, sA, dR, dG, dB); \
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   632
                *((unsigned short *)dst) = ( \
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   633
                    ((dR & 0xf8) << 8) | ((dG & 0xfc) << 3) | (dB >> 3) \
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   634
                ); \
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   635
            } \
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   636
            src += 4; \
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   637
            dst += 2; \
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   638
            widthvar--; \
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   639
        }
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   640
        ONE_PIXEL_BLEND((UNALIGNED_PTR(dst)) && (width), width);
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   641
        extrawidth = (width % 8);
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   642
        valigner = VEC_ALIGNER(src);
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   643
        vsrc = (vector unsigned char) vec_ld(0, src);
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   644
        width -= extrawidth;
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   645
        while (width) {
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   646
            vector unsigned char valpha;
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   647
            vector unsigned char vsrc1, vsrc2;
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   648
            vector unsigned char vdst1, vdst2;
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   649
            vector unsigned short vR, vG, vB;
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   650
            vector unsigned short vpixel, vrpixel, vgpixel, vbpixel;
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   651
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   652
            /* Load 8 pixels from src as ARGB */
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   653
            voverflow = (vector unsigned char) vec_ld(15, src);
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   654
            vsrc = vec_perm(vsrc, voverflow, valigner);
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   655
            vsrc1 = vec_perm(vsrc, vsrc, vpermute);
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   656
            src += 16;
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   657
            vsrc = (vector unsigned char) vec_ld(15, src);
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   658
            voverflow = vec_perm(voverflow, vsrc, valigner);
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   659
            vsrc2 = vec_perm(voverflow, voverflow, vpermute);
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   660
            src += 16;
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   661
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   662
            /* Load 8 pixels from dst as XRGB */
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   663
            voverflow = vec_ld(0, dst);
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   664
            vR = vec_and((vector unsigned short) voverflow, vf800);
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   665
            vB = vec_sl((vector unsigned short) voverflow, v3_16);
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   666
            vG = vec_sl(vB, v2_16);
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   667
            vdst1 =
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   668
                (vector unsigned char) vec_perm((vector unsigned char) vR,
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   669
                                                (vector unsigned char) vR,
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   670
                                                vredalpha1);
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   671
            vdst1 = vec_perm(vdst1, (vector unsigned char) vB, vblue1);
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   672
            vdst1 = vec_perm(vdst1, (vector unsigned char) vG, vgreen1);
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   673
            vdst2 =
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   674
                (vector unsigned char) vec_perm((vector unsigned char) vR,
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   675
                                                (vector unsigned char) vR,
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   676
                                                vredalpha2);
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   677
            vdst2 = vec_perm(vdst2, (vector unsigned char) vB, vblue2);
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   678
            vdst2 = vec_perm(vdst2, (vector unsigned char) vG, vgreen2);
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   679
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   680
            /* Alpha blend 8 pixels as ARGB */
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   681
            valpha = vec_perm(vsrc1, v0, valphaPermute);
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   682
            VEC_MULTIPLY_ALPHA(vsrc1, vdst1, valpha, mergePermute, v1_16,
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   683
                               v8_16);
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   684
            valpha = vec_perm(vsrc2, v0, valphaPermute);
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   685
            VEC_MULTIPLY_ALPHA(vsrc2, vdst2, valpha, mergePermute, v1_16,
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   686
                               v8_16);
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   687
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   688
            /* Convert 8 pixels to 565 */
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   689
            vpixel = (vector unsigned short) vec_packpx((vector unsigned int)
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   690
                                                        vdst1,
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   691
                                                        (vector unsigned int)
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   692
                                                        vdst2);
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   693
            vgpixel = (vector unsigned short) vec_perm(vdst1, vdst2, vgmerge);
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   694
            vgpixel = vec_and(vgpixel, vfc);
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   695
            vgpixel = vec_sl(vgpixel, v3_16);
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   696
            vrpixel = vec_sl(vpixel, v1_16);
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   697
            vrpixel = vec_and(vrpixel, vf800);
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   698
            vbpixel = vec_and(vpixel, v3f);
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   699
            vdst1 =
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   700
                vec_or((vector unsigned char) vrpixel,
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   701
                       (vector unsigned char) vgpixel);
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   702
            vdst1 = vec_or(vdst1, (vector unsigned char) vbpixel);
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   703
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   704
            /* Store 8 pixels */
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   705
            vec_st(vdst1, 0, dst);
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   706
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   707
            width -= 8;
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   708
            dst += 16;
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   709
        }
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   710
        ONE_PIXEL_BLEND((extrawidth), extrawidth);
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   711
#undef ONE_PIXEL_BLEND
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   712
        src += srcskip;
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   713
        dst += dstskip;
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   714
    }
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   715
}
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   716
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   717
static void
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   718
Blit32to32SurfaceAlphaKeyAltivec(SDL_BlitInfo * info)
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   719
{
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   720
    int height = info->dst_h;
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   721
    Uint32 *srcp = (Uint32 *) info->src;
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   722
    int srcskip = info->src_skip >> 2;
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   723
    Uint32 *dstp = (Uint32 *) info->dst;
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   724
    int dstskip = info->dst_skip >> 2;
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   725
    SDL_PixelFormat *srcfmt = info->src_fmt;
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   726
    SDL_PixelFormat *dstfmt = info->dst_fmt;
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   727
    unsigned sA = info->a;
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   728
    unsigned dA = dstfmt->Amask ? SDL_ALPHA_OPAQUE : 0;
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   729
    Uint32 rgbmask = srcfmt->Rmask | srcfmt->Gmask | srcfmt->Bmask;
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   730
    Uint32 ckey = info->colorkey;
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   731
    vector unsigned char mergePermute;
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   732
    vector unsigned char vsrcPermute;
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   733
    vector unsigned char vdstPermute;
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   734
    vector unsigned char vsdstPermute;
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   735
    vector unsigned char valpha;
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   736
    vector unsigned char valphamask;
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   737
    vector unsigned char vbits;
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   738
    vector unsigned char v0;
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   739
    vector unsigned short v1;
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   740
    vector unsigned short v8;
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   741
    vector unsigned int vckey;
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   742
    vector unsigned int vrgbmask;
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   743
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   744
    mergePermute = VEC_MERGE_PERMUTE();
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   745
    v0 = vec_splat_u8(0);
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   746
    v1 = vec_splat_u16(1);
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   747
    v8 = vec_splat_u16(8);
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   748
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   749
    /* set the alpha to 255 on the destination surf */
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   750
    valphamask = VEC_ALPHA_MASK();
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   751
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   752
    vsrcPermute = calc_swizzle32(srcfmt, NULL);
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   753
    vdstPermute = calc_swizzle32(NULL, dstfmt);
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   754
    vsdstPermute = calc_swizzle32(dstfmt, NULL);
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   755
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   756
    /* set a vector full of alpha and 255-alpha */
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   757
    ((unsigned char *) &valpha)[0] = sA;
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   758
    valpha = vec_splat(valpha, 0);
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   759
    vbits = (vector unsigned char) vec_splat_s8(-1);
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   760
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   761
    ckey &= rgbmask;
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   762
    ((unsigned int *) (char *) &vckey)[0] = ckey;
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   763
    vckey = vec_splat(vckey, 0);
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   764
    ((unsigned int *) (char *) &vrgbmask)[0] = rgbmask;
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   765
    vrgbmask = vec_splat(vrgbmask, 0);
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   766
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   767
    while (height--) {
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   768
        int width = info->dst_w;
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   769
#define ONE_PIXEL_BLEND(condition, widthvar) \
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   770
        while (condition) { \
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   771
            Uint32 Pixel; \
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   772
            unsigned sR, sG, sB, dR, dG, dB; \
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   773
            RETRIEVE_RGB_PIXEL(((Uint8 *)srcp), 4, Pixel); \
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   774
            if(sA && Pixel != ckey) { \
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   775
                RGB_FROM_PIXEL(Pixel, srcfmt, sR, sG, sB); \
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   776
                DISEMBLE_RGB(((Uint8 *)dstp), 4, dstfmt, Pixel, dR, dG, dB); \
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   777
                ALPHA_BLEND(sR, sG, sB, sA, dR, dG, dB); \
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   778
                ASSEMBLE_RGBA(((Uint8 *)dstp), 4, dstfmt, dR, dG, dB, dA); \
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   779
            } \
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   780
            dstp++; \
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   781
            srcp++; \
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   782
            widthvar--; \
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   783
        }
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   784
        ONE_PIXEL_BLEND((UNALIGNED_PTR(dstp)) && (width), width);
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   785
        if (width > 0) {
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   786
            int extrawidth = (width % 4);
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   787
            vector unsigned char valigner = VEC_ALIGNER(srcp);
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   788
            vector unsigned char vs = (vector unsigned char) vec_ld(0, srcp);
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   789
            width -= extrawidth;
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   790
            while (width) {
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   791
                vector unsigned char vsel;
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   792
                vector unsigned char voverflow;
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   793
                vector unsigned char vd;
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   794
                vector unsigned char vd_orig;
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   795
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   796
                /* s = *srcp */
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   797
                voverflow = (vector unsigned char) vec_ld(15, srcp);
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   798
                vs = vec_perm(vs, voverflow, valigner);
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   799
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   800
                /* vsel is set for items that match the key */
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   801
                vsel =
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   802
                    (vector unsigned char) vec_and((vector unsigned int) vs,
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   803
                                                   vrgbmask);
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   804
                vsel = (vector unsigned char) vec_cmpeq((vector unsigned int)
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   805
                                                        vsel, vckey);
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   806
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   807
                /* permute to source format */
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   808
                vs = vec_perm(vs, valpha, vsrcPermute);
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   809
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   810
                /* d = *dstp */
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   811
                vd = (vector unsigned char) vec_ld(0, dstp);
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   812
                vd_orig = vd = vec_perm(vd, v0, vsdstPermute);
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   813
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   814
                VEC_MULTIPLY_ALPHA(vs, vd, valpha, mergePermute, v1, v8);
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   815
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   816
                /* set the alpha channel to full on */
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   817
                vd = vec_or(vd, valphamask);
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   818
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   819
                /* mask out color key */
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   820
                vd = vec_sel(vd, vd_orig, vsel);
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   821
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   822
                /* permute to dest format */
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   823
                vd = vec_perm(vd, vbits, vdstPermute);
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   824
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   825
                /* *dstp = res */
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   826
                vec_st((vector unsigned int) vd, 0, dstp);
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   827
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   828
                srcp += 4;
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   829
                dstp += 4;
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   830
                width -= 4;
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   831
                vs = voverflow;
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   832
            }
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   833
            ONE_PIXEL_BLEND((extrawidth), extrawidth);
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   834
        }
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   835
#undef ONE_PIXEL_BLEND
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   836
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   837
        srcp += srcskip;
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   838
        dstp += dstskip;
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   839
    }
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   840
}
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   841
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   842
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   843
static void
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   844
Blit32to32PixelAlphaAltivec(SDL_BlitInfo * info)
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   845
{
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   846
    int width = info->dst_w;
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   847
    int height = info->dst_h;
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   848
    Uint32 *srcp = (Uint32 *) info->src;
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   849
    int srcskip = info->src_skip >> 2;
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   850
    Uint32 *dstp = (Uint32 *) info->dst;
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   851
    int dstskip = info->dst_skip >> 2;
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   852
    SDL_PixelFormat *srcfmt = info->src_fmt;
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   853
    SDL_PixelFormat *dstfmt = info->dst_fmt;
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   854
    vector unsigned char mergePermute;
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   855
    vector unsigned char valphaPermute;
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   856
    vector unsigned char vsrcPermute;
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   857
    vector unsigned char vdstPermute;
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   858
    vector unsigned char vsdstPermute;
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   859
    vector unsigned char valphamask;
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   860
    vector unsigned char vpixelmask;
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   861
    vector unsigned char v0;
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   862
    vector unsigned short v1;
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   863
    vector unsigned short v8;
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   864
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   865
    v0 = vec_splat_u8(0);
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   866
    v1 = vec_splat_u16(1);
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   867
    v8 = vec_splat_u16(8);
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   868
    mergePermute = VEC_MERGE_PERMUTE();
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   869
    valphamask = VEC_ALPHA_MASK();
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   870
    valphaPermute = vec_and(vec_lvsl(0, (int *) NULL), vec_splat_u8(0xC));
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   871
    vpixelmask = vec_nor(valphamask, v0);
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   872
    vsrcPermute = calc_swizzle32(srcfmt, NULL);
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   873
    vdstPermute = calc_swizzle32(NULL, dstfmt);
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   874
    vsdstPermute = calc_swizzle32(dstfmt, NULL);
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   875
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   876
    while (height--) {
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   877
        width = info->dst_w;
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   878
#define ONE_PIXEL_BLEND(condition, widthvar) while ((condition)) { \
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   879
            Uint32 Pixel; \
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   880
            unsigned sR, sG, sB, dR, dG, dB, sA, dA; \
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   881
            DISEMBLE_RGBA((Uint8 *)srcp, 4, srcfmt, Pixel, sR, sG, sB, sA); \
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   882
            if(sA) { \
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   883
              DISEMBLE_RGBA((Uint8 *)dstp, 4, dstfmt, Pixel, dR, dG, dB, dA); \
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   884
              ALPHA_BLEND(sR, sG, sB, sA, dR, dG, dB); \
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   885
              ASSEMBLE_RGBA((Uint8 *)dstp, 4, dstfmt, dR, dG, dB, dA); \
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   886
            } \
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   887
            ++srcp; \
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   888
            ++dstp; \
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   889
            widthvar--; \
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   890
        }
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   891
        ONE_PIXEL_BLEND((UNALIGNED_PTR(dstp)) && (width), width);
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   892
        if (width > 0) {
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   893
            /* vsrcPermute */
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   894
            /* vdstPermute */
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   895
            int extrawidth = (width % 4);
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   896
            vector unsigned char valigner = VEC_ALIGNER(srcp);
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   897
            vector unsigned char vs = (vector unsigned char) vec_ld(0, srcp);
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   898
            width -= extrawidth;
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   899
            while (width) {
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   900
                vector unsigned char voverflow;
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   901
                vector unsigned char vd;
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   902
                vector unsigned char valpha;
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   903
                vector unsigned char vdstalpha;
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   904
                /* s = *srcp */
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   905
                voverflow = (vector unsigned char) vec_ld(15, srcp);
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   906
                vs = vec_perm(vs, voverflow, valigner);
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   907
                vs = vec_perm(vs, v0, vsrcPermute);
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   908
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   909
                valpha = vec_perm(vs, v0, valphaPermute);
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   910
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   911
                /* d = *dstp */
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   912
                vd = (vector unsigned char) vec_ld(0, dstp);
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   913
                vd = vec_perm(vd, v0, vsdstPermute);
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   914
                vdstalpha = vec_and(vd, valphamask);
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   915
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   916
                VEC_MULTIPLY_ALPHA(vs, vd, valpha, mergePermute, v1, v8);
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   917
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   918
                /* set the alpha to the dest alpha */
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   919
                vd = vec_and(vd, vpixelmask);
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   920
                vd = vec_or(vd, vdstalpha);
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   921
                vd = vec_perm(vd, v0, vdstPermute);
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   922
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   923
                /* *dstp = res */
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   924
                vec_st((vector unsigned int) vd, 0, dstp);
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   925
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   926
                srcp += 4;
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   927
                dstp += 4;
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   928
                width -= 4;
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   929
                vs = voverflow;
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   930
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   931
            }
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   932
            ONE_PIXEL_BLEND((extrawidth), extrawidth);
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   933
        }
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   934
        srcp += srcskip;
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   935
        dstp += dstskip;
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   936
#undef ONE_PIXEL_BLEND
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   937
    }
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   938
}
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   939
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   940
/* fast ARGB888->(A)RGB888 blending with pixel alpha */
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   941
static void
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   942
BlitRGBtoRGBPixelAlphaAltivec(SDL_BlitInfo * info)
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   943
{
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   944
    int width = info->dst_w;
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   945
    int height = info->dst_h;
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   946
    Uint32 *srcp = (Uint32 *) info->src;
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   947
    int srcskip = info->src_skip >> 2;
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   948
    Uint32 *dstp = (Uint32 *) info->dst;
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   949
    int dstskip = info->dst_skip >> 2;
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   950
    vector unsigned char mergePermute;
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   951
    vector unsigned char valphaPermute;
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   952
    vector unsigned char valphamask;
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   953
    vector unsigned char vpixelmask;
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   954
    vector unsigned char v0;
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   955
    vector unsigned short v1;
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   956
    vector unsigned short v8;
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   957
    v0 = vec_splat_u8(0);
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   958
    v1 = vec_splat_u16(1);
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   959
    v8 = vec_splat_u16(8);
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   960
    mergePermute = VEC_MERGE_PERMUTE();
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   961
    valphamask = VEC_ALPHA_MASK();
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   962
    valphaPermute = vec_and(vec_lvsl(0, (int *) NULL), vec_splat_u8(0xC));
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   963
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   964
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   965
    vpixelmask = vec_nor(valphamask, v0);
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   966
    while (height--) {
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   967
        width = info->dst_w;
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   968
#define ONE_PIXEL_BLEND(condition, widthvar) \
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   969
        while ((condition)) { \
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   970
            Uint32 dalpha; \
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   971
            Uint32 d; \
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   972
            Uint32 s1; \
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   973
            Uint32 d1; \
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   974
            Uint32 s = *srcp; \
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   975
            Uint32 alpha = s >> 24; \
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   976
            if(alpha) { \
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   977
              if(alpha == SDL_ALPHA_OPAQUE) { \
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   978
                *dstp = (s & 0x00ffffff) | (*dstp & 0xff000000); \
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   979
              } else { \
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   980
                d = *dstp; \
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   981
                dalpha = d & 0xff000000; \
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   982
                s1 = s & 0xff00ff; \
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   983
                d1 = d & 0xff00ff; \
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   984
                d1 = (d1 + ((s1 - d1) * alpha >> 8)) & 0xff00ff; \
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   985
                s &= 0xff00; \
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   986
                d &= 0xff00; \
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   987
                d = (d + ((s - d) * alpha >> 8)) & 0xff00; \
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   988
                *dstp = d1 | d | dalpha; \
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   989
              } \
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   990
            } \
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   991
            ++srcp; \
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   992
            ++dstp; \
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   993
            widthvar--; \
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   994
	    }
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   995
        ONE_PIXEL_BLEND((UNALIGNED_PTR(dstp)) && (width), width);
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   996
        if (width > 0) {
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   997
            int extrawidth = (width % 4);
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   998
            vector unsigned char valigner = VEC_ALIGNER(srcp);
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   999
            vector unsigned char vs = (vector unsigned char) vec_ld(0, srcp);
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
  1000
            width -= extrawidth;
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
  1001
            while (width) {
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
  1002
                vector unsigned char voverflow;
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
  1003
                vector unsigned char vd;
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
  1004
                vector unsigned char valpha;
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
  1005
                vector unsigned char vdstalpha;
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
  1006
                /* s = *srcp */
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
  1007
                voverflow = (vector unsigned char) vec_ld(15, srcp);
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
  1008
                vs = vec_perm(vs, voverflow, valigner);
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
  1009
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
  1010
                valpha = vec_perm(vs, v0, valphaPermute);
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
  1011
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
  1012
                /* d = *dstp */
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
  1013
                vd = (vector unsigned char) vec_ld(0, dstp);
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
  1014
                vdstalpha = vec_and(vd, valphamask);
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
  1015
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
  1016
                VEC_MULTIPLY_ALPHA(vs, vd, valpha, mergePermute, v1, v8);
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
  1017
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
  1018
                /* set the alpha to the dest alpha */
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
  1019
                vd = vec_and(vd, vpixelmask);
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
  1020
                vd = vec_or(vd, vdstalpha);
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
  1021
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
  1022
                /* *dstp = res */
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
  1023
                vec_st((vector unsigned int) vd, 0, dstp);
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
  1024
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
  1025
                srcp += 4;
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
  1026
                dstp += 4;
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
  1027
                width -= 4;
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
  1028
                vs = voverflow;
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
  1029
            }
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
  1030
            ONE_PIXEL_BLEND((extrawidth), extrawidth);
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
  1031
        }
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
  1032
        srcp += srcskip;
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
  1033
        dstp += dstskip;
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
  1034
    }
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
  1035
#undef ONE_PIXEL_BLEND
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
  1036
}
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
  1037
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
  1038
static void
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
  1039
Blit32to32SurfaceAlphaAltivec(SDL_BlitInfo * info)
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
  1040
{
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
  1041
    /* XXX : 6 */
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
  1042
    int height = info->dst_h;
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
  1043
    Uint32 *srcp = (Uint32 *) info->src;
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
  1044
    int srcskip = info->src_skip >> 2;
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
  1045
    Uint32 *dstp = (Uint32 *) info->dst;
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
  1046
    int dstskip = info->dst_skip >> 2;
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
  1047
    SDL_PixelFormat *srcfmt = info->src_fmt;
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
  1048
    SDL_PixelFormat *dstfmt = info->dst_fmt;
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
  1049
    unsigned sA = info->a;
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
  1050
    unsigned dA = dstfmt->Amask ? SDL_ALPHA_OPAQUE : 0;
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
  1051
    vector unsigned char mergePermute;
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
  1052
    vector unsigned char vsrcPermute;
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
  1053
    vector unsigned char vdstPermute;
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
  1054
    vector unsigned char vsdstPermute;
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
  1055
    vector unsigned char valpha;
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
  1056
    vector unsigned char valphamask;
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
  1057
    vector unsigned char vbits;
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
  1058
    vector unsigned short v1;
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
  1059
    vector unsigned short v8;
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
  1060
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
  1061
    mergePermute = VEC_MERGE_PERMUTE();
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
  1062
    v1 = vec_splat_u16(1);
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
  1063
    v8 = vec_splat_u16(8);
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
  1064
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
  1065
    /* set the alpha to 255 on the destination surf */
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
  1066
    valphamask = VEC_ALPHA_MASK();
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
  1067
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
  1068
    vsrcPermute = calc_swizzle32(srcfmt, NULL);
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
  1069
    vdstPermute = calc_swizzle32(NULL, dstfmt);
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
  1070
    vsdstPermute = calc_swizzle32(dstfmt, NULL);
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
  1071
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
  1072
    /* set a vector full of alpha and 255-alpha */
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
  1073
    ((unsigned char *) &valpha)[0] = sA;
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
  1074
    valpha = vec_splat(valpha, 0);
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
  1075
    vbits = (vector unsigned char) vec_splat_s8(-1);