src/video/SDL_blit_N.c
author Ryan C. Gordon <icculus@icculus.org>
Thu, 20 Oct 2005 06:55:26 +0000
changeset 1162 2651158f59b8
parent 1139 d0ae4dff7208
child 1175 867f521591e5
permissions -rw-r--r--
Enable altivec blitters on PowerPC Linux, and some fixes for recent GCCs versions.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
     1
/*
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
     2
    SDL - Simple DirectMedia Layer
769
b8d311d90021 Updated copyright information for 2004 (Happy New Year!)
Sam Lantinga <slouken@libsdl.org>
parents: 739
diff changeset
     3
    Copyright (C) 1997-2004 Sam Lantinga
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
     4
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
     5
    This library is free software; you can redistribute it and/or
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
     6
    modify it under the terms of the GNU Library General Public
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
     7
    License as published by the Free Software Foundation; either
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
     8
    version 2 of the License, or (at your option) any later version.
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
     9
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    10
    This library is distributed in the hope that it will be useful,
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    11
    but WITHOUT ANY WARRANTY; without even the implied warranty of
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    12
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    13
    Library General Public License for more details.
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    14
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    15
    You should have received a copy of the GNU Library General Public
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    16
    License along with this library; if not, write to the Free
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    17
    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    18
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    19
    Sam Lantinga
252
e8157fcb3114 Updated the source with the correct e-mail address
Sam Lantinga <slouken@libsdl.org>
parents: 91
diff changeset
    20
    slouken@libsdl.org
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    21
*/
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    22
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    23
#ifdef SAVE_RCSID
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    24
static char rcsid =
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    25
 "@(#) $Id$";
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    26
#endif
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    27
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    28
#include <stdio.h>
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    29
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    30
#include "SDL_types.h"
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    31
#include "SDL_video.h"
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    32
#include "SDL_blit.h"
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    33
#include "SDL_byteorder.h"
739
22dbf364c017 Added SDL_HasMMX(), SDL_Has3DNow(), SDL_HasSSE() in SDL_cpuinfo.h
Sam Lantinga <slouken@libsdl.org>
parents: 431
diff changeset
    34
#include "SDL_cpuinfo.h"
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    35
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    36
/* Functions to blit from N-bit surfaces to other surfaces */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    37
1047
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
    38
#ifdef USE_ALTIVEC_BLITTERS
1162
2651158f59b8 Enable altivec blitters on PowerPC Linux, and some fixes for recent
Ryan C. Gordon <icculus@icculus.org>
parents: 1139
diff changeset
    39
#include <altivec.h>
1047
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
    40
#include <assert.h>
1162
2651158f59b8 Enable altivec blitters on PowerPC Linux, and some fixes for recent
Ryan C. Gordon <icculus@icculus.org>
parents: 1139
diff changeset
    41
#include <stdlib.h>
1047
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
    42
#ifdef MACOSX
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
    43
#include <sys/sysctl.h>
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
    44
static size_t GetL3CacheSize( void )
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
    45
{
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
    46
    const char key[] = "hw.l3cachesize";
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
    47
    u_int64_t result = 0;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
    48
    size_t typeSize = sizeof( result );
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
    49
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
    50
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
    51
    int err = sysctlbyname( key, &result, &typeSize, NULL, 0 );
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
    52
    if( 0 != err ) return 0;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
    53
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
    54
    return result;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
    55
}
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
    56
#else
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
    57
static size_t GetL3CacheSize( void )
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
    58
{
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
    59
    /* XXX: Just guess G4 */
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
    60
    return 2097152;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
    61
}
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
    62
#endif /* MACOSX */
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
    63
1162
2651158f59b8 Enable altivec blitters on PowerPC Linux, and some fixes for recent
Ryan C. Gordon <icculus@icculus.org>
parents: 1139
diff changeset
    64
#if ((defined MACOSX) && (__GNUC__ < 4))
2651158f59b8 Enable altivec blitters on PowerPC Linux, and some fixes for recent
Ryan C. Gordon <icculus@icculus.org>
parents: 1139
diff changeset
    65
    #define VECUINT8_LITERAL(a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p) \
2651158f59b8 Enable altivec blitters on PowerPC Linux, and some fixes for recent
Ryan C. Gordon <icculus@icculus.org>
parents: 1139
diff changeset
    66
        (vector unsigned char) ( a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p )
2651158f59b8 Enable altivec blitters on PowerPC Linux, and some fixes for recent
Ryan C. Gordon <icculus@icculus.org>
parents: 1139
diff changeset
    67
    #define VECUINT16_LITERAL(a,b,c,d,e,f,g,h) \
2651158f59b8 Enable altivec blitters on PowerPC Linux, and some fixes for recent
Ryan C. Gordon <icculus@icculus.org>
parents: 1139
diff changeset
    68
        (vector unsigned short) ( a,b,c,d,e,f,g,h )
2651158f59b8 Enable altivec blitters on PowerPC Linux, and some fixes for recent
Ryan C. Gordon <icculus@icculus.org>
parents: 1139
diff changeset
    69
#else
2651158f59b8 Enable altivec blitters on PowerPC Linux, and some fixes for recent
Ryan C. Gordon <icculus@icculus.org>
parents: 1139
diff changeset
    70
    #define VECUINT8_LITERAL(a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p) \
2651158f59b8 Enable altivec blitters on PowerPC Linux, and some fixes for recent
Ryan C. Gordon <icculus@icculus.org>
parents: 1139
diff changeset
    71
        (vector unsigned char) { a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p }
2651158f59b8 Enable altivec blitters on PowerPC Linux, and some fixes for recent
Ryan C. Gordon <icculus@icculus.org>
parents: 1139
diff changeset
    72
    #define VECUINT16_LITERAL(a,b,c,d,e,f,g,h) \
2651158f59b8 Enable altivec blitters on PowerPC Linux, and some fixes for recent
Ryan C. Gordon <icculus@icculus.org>
parents: 1139
diff changeset
    73
        (vector unsigned short) { a,b,c,d,e,f,g,h }
2651158f59b8 Enable altivec blitters on PowerPC Linux, and some fixes for recent
Ryan C. Gordon <icculus@icculus.org>
parents: 1139
diff changeset
    74
#endif
2651158f59b8 Enable altivec blitters on PowerPC Linux, and some fixes for recent
Ryan C. Gordon <icculus@icculus.org>
parents: 1139
diff changeset
    75
1047
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
    76
#define UNALIGNED_PTR(x) (((size_t) x) & 0x0000000F)
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
    77
#define VSWIZZLE32(a,b,c,d) (vector unsigned char) \
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
    78
                               ( 0x00+a, 0x00+b, 0x00+c, 0x00+d, \
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
    79
                                 0x04+a, 0x04+b, 0x04+c, 0x04+d, \
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
    80
                                 0x08+a, 0x08+b, 0x08+c, 0x08+d, \
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
    81
                                 0x0C+a, 0x0C+b, 0x0C+c, 0x0C+d )
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
    82
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
    83
#define MAKE8888(dstfmt, r, g, b, a)  \
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
    84
    ( ((r<<dstfmt->Rshift)&dstfmt->Rmask) | \
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
    85
      ((g<<dstfmt->Gshift)&dstfmt->Gmask) | \
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
    86
      ((b<<dstfmt->Bshift)&dstfmt->Bmask) | \
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
    87
      ((a<<dstfmt->Ashift)&dstfmt->Amask) )
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
    88
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
    89
/*
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
    90
 * Data Stream Touch...Altivec cache prefetching.
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
    91
 *
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
    92
 *  Don't use this on a G5...however, the speed boost is very significant
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
    93
 *   on a G4.
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
    94
 */
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
    95
#define DST_CHAN_SRC 1
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
    96
#define DST_CHAN_DEST 2
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
    97
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
    98
/* macro to set DST control word value... */
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
    99
#define DST_CTRL(size, count, stride) \
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   100
    (((size) << 24) | ((count) << 16) | (stride))
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   101
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   102
#define VEC_ALIGNER(src) ((UNALIGNED_PTR(src)) \
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   103
    ? vec_lvsl(0, src) \
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   104
    : vec_add(vec_lvsl(8, src), vec_splat_u8(8)))
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   105
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   106
/* Calculate the permute vector used for 32->32 swizzling */
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   107
static vector unsigned char calc_swizzle32(const SDL_PixelFormat *srcfmt,
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   108
                                  const SDL_PixelFormat *dstfmt)
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   109
{
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   110
    /*
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   111
    * We have to assume that the bits that aren't used by other
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   112
     *  colors is alpha, and it's one complete byte, since some formats
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   113
     *  leave alpha with a zero mask, but we should still swizzle the bits.
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   114
     */
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   115
    /* ARGB */
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   116
    const static struct SDL_PixelFormat default_pixel_format = {
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   117
        NULL, 0, 0,
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   118
        0, 0, 0, 0,
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   119
        16, 8, 0, 24,
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   120
        0x00FF0000, 0x0000FF00, 0x000000FF, 0xFF000000,
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   121
        0, 0};
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   122
    if (!srcfmt) {
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   123
        srcfmt = &default_pixel_format;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   124
    }
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   125
    if (!dstfmt) {
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   126
        dstfmt = &default_pixel_format;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   127
    }
1162
2651158f59b8 Enable altivec blitters on PowerPC Linux, and some fixes for recent
Ryan C. Gordon <icculus@icculus.org>
parents: 1139
diff changeset
   128
    vector unsigned char plus = VECUINT8_LITERAL(
2651158f59b8 Enable altivec blitters on PowerPC Linux, and some fixes for recent
Ryan C. Gordon <icculus@icculus.org>
parents: 1139
diff changeset
   129
                                      0x00, 0x00, 0x00, 0x00,
1047
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   130
                                      0x04, 0x04, 0x04, 0x04,
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   131
                                      0x08, 0x08, 0x08, 0x08,
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   132
                                      0x0C, 0x0C, 0x0C, 0x0C );
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   133
    vector unsigned char vswiz;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   134
    vector unsigned int srcvec;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   135
#define RESHIFT(X) (3 - ((X) >> 3))
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   136
    Uint32 rmask = RESHIFT(srcfmt->Rshift) << (dstfmt->Rshift);
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   137
    Uint32 gmask = RESHIFT(srcfmt->Gshift) << (dstfmt->Gshift);
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   138
    Uint32 bmask = RESHIFT(srcfmt->Bshift) << (dstfmt->Bshift);
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   139
    Uint32 amask;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   140
    /* Use zero for alpha if either surface doesn't have alpha */
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   141
    if (dstfmt->Amask) {
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   142
        amask = ((srcfmt->Amask) ? RESHIFT(srcfmt->Ashift) : 0x10) << (dstfmt->Ashift);
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   143
    } else {    
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   144
        amask = 0x10101010 & ((dstfmt->Rmask | dstfmt->Gmask | dstfmt->Bmask) ^ 0xFFFFFFFF);
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   145
    }           
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   146
#undef RESHIFT  
1162
2651158f59b8 Enable altivec blitters on PowerPC Linux, and some fixes for recent
Ryan C. Gordon <icculus@icculus.org>
parents: 1139
diff changeset
   147
    ((unsigned int *)(char*)&srcvec)[0] = (rmask | gmask | bmask | amask);
1047
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   148
    vswiz = vec_add(plus, (vector unsigned char)vec_splat(srcvec, 0));
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   149
    return(vswiz);
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   150
}
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   151
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   152
static void Blit_RGB888_RGB565(SDL_BlitInfo *info);
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   153
static void Blit_RGB888_RGB565Altivec(SDL_BlitInfo *info) {
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   154
    int height = info->d_height;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   155
    Uint8 *src = (Uint8 *) info->s_pixels;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   156
    int srcskip = info->s_skip;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   157
    Uint8 *dst = (Uint8 *) info->d_pixels;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   158
    int dstskip = info->d_skip;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   159
    SDL_PixelFormat *srcfmt = info->src;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   160
    vector unsigned char valpha = vec_splat_u8(0);
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   161
    vector unsigned char vpermute = calc_swizzle32(srcfmt, NULL);
1162
2651158f59b8 Enable altivec blitters on PowerPC Linux, and some fixes for recent
Ryan C. Gordon <icculus@icculus.org>
parents: 1139
diff changeset
   162
    vector unsigned char vgmerge = VECUINT8_LITERAL(
1047
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   163
        0x00, 0x02, 0x00, 0x06,
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   164
        0x00, 0x0a, 0x00, 0x0e,
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   165
        0x00, 0x12, 0x00, 0x16,
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   166
        0x00, 0x1a, 0x00, 0x1e);
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   167
    vector unsigned short v1 = vec_splat_u16(1);
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   168
    vector unsigned short v3 = vec_splat_u16(3);
1162
2651158f59b8 Enable altivec blitters on PowerPC Linux, and some fixes for recent
Ryan C. Gordon <icculus@icculus.org>
parents: 1139
diff changeset
   169
    vector unsigned short v3f = VECUINT16_LITERAL(
1047
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   170
        0x003f, 0x003f, 0x003f, 0x003f,
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   171
        0x003f, 0x003f, 0x003f, 0x003f);
1162
2651158f59b8 Enable altivec blitters on PowerPC Linux, and some fixes for recent
Ryan C. Gordon <icculus@icculus.org>
parents: 1139
diff changeset
   172
    vector unsigned short vfc = VECUINT16_LITERAL(
1047
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   173
        0x00fc, 0x00fc, 0x00fc, 0x00fc,
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   174
        0x00fc, 0x00fc, 0x00fc, 0x00fc);
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   175
    vector unsigned short vf800 = (vector unsigned short)vec_splat_u8(-7);
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   176
    vf800 = vec_sl(vf800, vec_splat_u16(8));
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   177
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   178
    while (height--) {
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   179
        vector unsigned char valigner;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   180
        vector unsigned char voverflow;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   181
        vector unsigned char vsrc;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   182
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   183
        int width = info->d_width;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   184
        int extrawidth;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   185
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   186
        /* do scalar until we can align... */
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   187
#define ONE_PIXEL_BLEND(condition, widthvar) \
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   188
        while (condition) { \
1162
2651158f59b8 Enable altivec blitters on PowerPC Linux, and some fixes for recent
Ryan C. Gordon <icculus@icculus.org>
parents: 1139
diff changeset
   189
            Uint32 Pixel; \
1047
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   190
            unsigned sR, sG, sB, sA; \
1162
2651158f59b8 Enable altivec blitters on PowerPC Linux, and some fixes for recent
Ryan C. Gordon <icculus@icculus.org>
parents: 1139
diff changeset
   191
            DISEMBLE_RGBA((Uint8 *)src, 4, srcfmt, Pixel, \
1047
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   192
                          sR, sG, sB, sA); \
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   193
            *(Uint16 *)(dst) = (((sR << 8) & 0x0000F800) | \
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   194
                                ((sG << 3) & 0x000007E0) | \
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   195
                                ((sB >> 3) & 0x0000001F)); \
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   196
            dst += 2; \
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   197
            src += 4; \
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   198
            widthvar--; \
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   199
        }
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   200
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   201
        ONE_PIXEL_BLEND(((UNALIGNED_PTR(dst)) && (width)), width);
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   202
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   203
        /* After all that work, here's the vector part! */
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   204
        extrawidth = (width % 8);  /* trailing unaligned stores */
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   205
        width -= extrawidth;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   206
        vsrc = vec_ld(0, src);
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   207
        valigner = VEC_ALIGNER(src);
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   208
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   209
        while (width) {
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   210
            vector unsigned short vpixel, vrpixel, vgpixel, vbpixel;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   211
            vector unsigned int vsrc1, vsrc2;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   212
            vector unsigned char vdst;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   213
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   214
            voverflow = vec_ld(15, src);
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   215
            vsrc = vec_perm(vsrc, voverflow, valigner);
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   216
            vsrc1 = (vector unsigned int)vec_perm(vsrc, valpha, vpermute);
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   217
            src += 16;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   218
            vsrc = voverflow;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   219
            voverflow = vec_ld(15, src);
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   220
            vsrc = vec_perm(vsrc, voverflow, valigner);
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   221
            vsrc2 = (vector unsigned int)vec_perm(vsrc, valpha, vpermute);
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   222
            /* 1555 */
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   223
            vpixel = (vector unsigned short)vec_packpx(vsrc1, vsrc2);
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   224
            vgpixel = (vector unsigned short)vec_perm(vsrc1, vsrc2, vgmerge);
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   225
            vgpixel = vec_and(vgpixel, vfc);
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   226
            vgpixel = vec_sl(vgpixel, v3);
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   227
            vrpixel = vec_sl(vpixel, v1);
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   228
            vrpixel = vec_and(vrpixel, vf800);
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   229
            vbpixel = vec_and(vpixel, v3f);
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   230
            vdst = vec_or((vector unsigned char)vrpixel, (vector unsigned char)vgpixel);
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   231
            /* 565 */
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   232
            vdst = vec_or(vdst, (vector unsigned char)vbpixel);
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   233
            vec_st(vdst, 0, dst);
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   234
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   235
            width -= 8;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   236
            src += 16;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   237
            dst += 16;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   238
            vsrc = voverflow;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   239
        }
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   240
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   241
        assert(width == 0);
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   242
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   243
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   244
        /* do scalar until we can align... */
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   245
        ONE_PIXEL_BLEND((extrawidth), extrawidth);
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   246
#undef ONE_PIXEL_BLEND
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   247
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   248
        src += srcskip;  /* move to next row, accounting for pitch. */
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   249
        dst += dstskip;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   250
    }
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   251
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   252
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   253
}
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   254
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   255
static void Blit_RGB565_32Altivec(SDL_BlitInfo *info) {
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   256
    int height = info->d_height;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   257
    Uint8 *src = (Uint8 *) info->s_pixels;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   258
    int srcskip = info->s_skip;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   259
    Uint8 *dst = (Uint8 *) info->d_pixels;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   260
    int dstskip = info->d_skip;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   261
    SDL_PixelFormat *srcfmt = info->src;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   262
    SDL_PixelFormat *dstfmt = info->dst;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   263
    unsigned alpha;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   264
    vector unsigned char valpha;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   265
    vector unsigned char vpermute;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   266
    vector unsigned short vf800;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   267
    vector unsigned int v8 = vec_splat_u32(8);
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   268
    vector unsigned int v16 = vec_add(v8, v8);
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   269
    vector unsigned short v2 = vec_splat_u16(2);
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   270
    vector unsigned short v3 = vec_splat_u16(3);
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   271
    /* 
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   272
        0x10 - 0x1f is the alpha
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   273
        0x00 - 0x0e evens are the red
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   274
        0x01 - 0x0f odds are zero
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   275
    */
1162
2651158f59b8 Enable altivec blitters on PowerPC Linux, and some fixes for recent
Ryan C. Gordon <icculus@icculus.org>
parents: 1139
diff changeset
   276
    vector unsigned char vredalpha1 = VECUINT8_LITERAL(
1047
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   277
        0x10, 0x00, 0x01, 0x01,
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   278
        0x10, 0x02, 0x01, 0x01,
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   279
        0x10, 0x04, 0x01, 0x01,
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   280
        0x10, 0x06, 0x01, 0x01
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   281
    );
1162
2651158f59b8 Enable altivec blitters on PowerPC Linux, and some fixes for recent
Ryan C. Gordon <icculus@icculus.org>
parents: 1139
diff changeset
   282
    vector unsigned char vredalpha2 = (vector unsigned char) (
1047
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   283
        vec_add((vector unsigned int)vredalpha1, vec_sl(v8, v16))
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   284
    );
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   285
    /*
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   286
        0x00 - 0x0f is ARxx ARxx ARxx ARxx
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   287
        0x11 - 0x0f odds are blue
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   288
    */
1162
2651158f59b8 Enable altivec blitters on PowerPC Linux, and some fixes for recent
Ryan C. Gordon <icculus@icculus.org>
parents: 1139
diff changeset
   289
    vector unsigned char vblue1 = VECUINT8_LITERAL(
1047
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   290
        0x00, 0x01, 0x02, 0x11,
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   291
        0x04, 0x05, 0x06, 0x13,
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   292
        0x08, 0x09, 0x0a, 0x15,
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   293
        0x0c, 0x0d, 0x0e, 0x17
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   294
    );
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   295
    vector unsigned char vblue2 = (vector unsigned char)(
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   296
        vec_add((vector unsigned int)vblue1, v8)
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   297
    );
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   298
    /*
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   299
        0x00 - 0x0f is ARxB ARxB ARxB ARxB
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   300
        0x10 - 0x0e evens are green
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   301
    */
1162
2651158f59b8 Enable altivec blitters on PowerPC Linux, and some fixes for recent
Ryan C. Gordon <icculus@icculus.org>
parents: 1139
diff changeset
   302
    vector unsigned char vgreen1 = VECUINT8_LITERAL(
1047
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   303
        0x00, 0x01, 0x10, 0x03,
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   304
        0x04, 0x05, 0x12, 0x07,
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   305
        0x08, 0x09, 0x14, 0x0b,
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   306
        0x0c, 0x0d, 0x16, 0x0f
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   307
    );
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   308
    vector unsigned char vgreen2 = (vector unsigned char)(
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   309
        vec_add((vector unsigned int)vgreen1, vec_sl(v8, v8))
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   310
    );
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   311
    
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   312
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   313
    assert(srcfmt->BytesPerPixel == 2);
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   314
    assert(dstfmt->BytesPerPixel == 4);
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   315
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   316
    vf800 = (vector unsigned short)vec_splat_u8(-7);
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   317
    vf800 = vec_sl(vf800, vec_splat_u16(8));
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   318
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   319
    if (dstfmt->Amask && srcfmt->alpha) {
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   320
        ((unsigned char *)&valpha)[0] = alpha = srcfmt->alpha;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   321
        valpha = vec_splat(valpha, 0);
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   322
    } else {
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   323
        alpha = 0;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   324
        valpha = vec_splat_u8(0);
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   325
    }
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   326
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   327
    vpermute = calc_swizzle32(NULL, dstfmt);
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   328
    while (height--) {
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   329
        vector unsigned char valigner;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   330
        vector unsigned char voverflow;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   331
        vector unsigned char vsrc;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   332
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   333
        int width = info->d_width;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   334
        int extrawidth;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   335
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   336
        /* do scalar until we can align... */
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   337
#define ONE_PIXEL_BLEND(condition, widthvar) \
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   338
        while (condition) { \
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   339
            unsigned sR, sG, sB; \
1162
2651158f59b8 Enable altivec blitters on PowerPC Linux, and some fixes for recent
Ryan C. Gordon <icculus@icculus.org>
parents: 1139
diff changeset
   340
            unsigned short Pixel = *((unsigned short *)src); \
2651158f59b8 Enable altivec blitters on PowerPC Linux, and some fixes for recent
Ryan C. Gordon <icculus@icculus.org>
parents: 1139
diff changeset
   341
            sR = (Pixel >> 8) & 0xf8; \
2651158f59b8 Enable altivec blitters on PowerPC Linux, and some fixes for recent
Ryan C. Gordon <icculus@icculus.org>
parents: 1139
diff changeset
   342
            sG = (Pixel >> 3) & 0xfc; \
2651158f59b8 Enable altivec blitters on PowerPC Linux, and some fixes for recent
Ryan C. Gordon <icculus@icculus.org>
parents: 1139
diff changeset
   343
            sB = (Pixel << 3) & 0xf8; \
1047
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   344
            ASSEMBLE_RGBA(dst, 4, dstfmt, sR, sG, sB, alpha); \
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   345
            src += 2; \
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   346
            dst += 4; \
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   347
            widthvar--; \
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   348
        }
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   349
        ONE_PIXEL_BLEND(((UNALIGNED_PTR(dst)) && (width)), width);
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   350
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   351
        /* After all that work, here's the vector part! */
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   352
        extrawidth = (width % 8);  /* trailing unaligned stores */
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   353
        width -= extrawidth;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   354
        vsrc = vec_ld(0, src);
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   355
        valigner = VEC_ALIGNER(src);
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   356
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   357
        while (width) {
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   358
            vector unsigned short vR, vG, vB;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   359
            vector unsigned char vdst1, vdst2;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   360
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   361
            voverflow = vec_ld(15, src);
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   362
            vsrc = vec_perm(vsrc, voverflow, valigner);
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   363
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   364
            vR = vec_and((vector unsigned short)vsrc, vf800);
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   365
            vB = vec_sl((vector unsigned short)vsrc, v3);
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   366
            vG = vec_sl(vB, v2);
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   367
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   368
            vdst1 = (vector unsigned char)vec_perm((vector unsigned char)vR, valpha, vredalpha1);
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   369
            vdst1 = vec_perm(vdst1, (vector unsigned char)vB, vblue1);
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   370
            vdst1 = vec_perm(vdst1, (vector unsigned char)vG, vgreen1);
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   371
            vdst1 = vec_perm(vdst1, valpha, vpermute);
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   372
            vec_st(vdst1, 0, dst);
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   373
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   374
            vdst2 = (vector unsigned char)vec_perm((vector unsigned char)vR, valpha, vredalpha2);
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   375
            vdst2 = vec_perm(vdst2, (vector unsigned char)vB, vblue2);
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   376
            vdst2 = vec_perm(vdst2, (vector unsigned char)vG, vgreen2);
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   377
            vdst2 = vec_perm(vdst2, valpha, vpermute);
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   378
            vec_st(vdst2, 16, dst);
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   379
            
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   380
            width -= 8;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   381
            dst += 32;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   382
            src += 16;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   383
            vsrc = voverflow;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   384
        }
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   385
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   386
        assert(width == 0);
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   387
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   388
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   389
        /* do scalar until we can align... */
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   390
        ONE_PIXEL_BLEND((extrawidth), extrawidth);
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   391
#undef ONE_PIXEL_BLEND
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   392
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   393
        src += srcskip;  /* move to next row, accounting for pitch. */
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   394
        dst += dstskip;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   395
    }
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   396
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   397
}
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   398
1139
d0ae4dff7208 Altivec blitter for 555 -> 8888 surface, written by me.
Ryan C. Gordon <icculus@icculus.org>
parents: 1053
diff changeset
   399
d0ae4dff7208 Altivec blitter for 555 -> 8888 surface, written by me.
Ryan C. Gordon <icculus@icculus.org>
parents: 1053
diff changeset
   400
static void Blit_RGB555_32Altivec(SDL_BlitInfo *info) {
d0ae4dff7208 Altivec blitter for 555 -> 8888 surface, written by me.
Ryan C. Gordon <icculus@icculus.org>
parents: 1053
diff changeset
   401
    int height = info->d_height;
d0ae4dff7208 Altivec blitter for 555 -> 8888 surface, written by me.
Ryan C. Gordon <icculus@icculus.org>
parents: 1053
diff changeset
   402
    Uint8 *src = (Uint8 *) info->s_pixels;
d0ae4dff7208 Altivec blitter for 555 -> 8888 surface, written by me.
Ryan C. Gordon <icculus@icculus.org>
parents: 1053
diff changeset
   403
    int srcskip = info->s_skip;
d0ae4dff7208 Altivec blitter for 555 -> 8888 surface, written by me.
Ryan C. Gordon <icculus@icculus.org>
parents: 1053
diff changeset
   404
    Uint8 *dst = (Uint8 *) info->d_pixels;
d0ae4dff7208 Altivec blitter for 555 -> 8888 surface, written by me.
Ryan C. Gordon <icculus@icculus.org>
parents: 1053
diff changeset
   405
    int dstskip = info->d_skip;
d0ae4dff7208 Altivec blitter for 555 -> 8888 surface, written by me.
Ryan C. Gordon <icculus@icculus.org>
parents: 1053
diff changeset
   406
    SDL_PixelFormat *srcfmt = info->src;
d0ae4dff7208 Altivec blitter for 555 -> 8888 surface, written by me.
Ryan C. Gordon <icculus@icculus.org>
parents: 1053
diff changeset
   407
    SDL_PixelFormat *dstfmt = info->dst;
d0ae4dff7208 Altivec blitter for 555 -> 8888 surface, written by me.
Ryan C. Gordon <icculus@icculus.org>
parents: 1053
diff changeset
   408
    unsigned alpha;
d0ae4dff7208 Altivec blitter for 555 -> 8888 surface, written by me.
Ryan C. Gordon <icculus@icculus.org>
parents: 1053
diff changeset
   409
    vector unsigned char valpha;
d0ae4dff7208 Altivec blitter for 555 -> 8888 surface, written by me.
Ryan C. Gordon <icculus@icculus.org>
parents: 1053
diff changeset
   410
    vector unsigned char vpermute;
d0ae4dff7208 Altivec blitter for 555 -> 8888 surface, written by me.
Ryan C. Gordon <icculus@icculus.org>
parents: 1053
diff changeset
   411
    vector unsigned short vf800;
d0ae4dff7208 Altivec blitter for 555 -> 8888 surface, written by me.
Ryan C. Gordon <icculus@icculus.org>
parents: 1053
diff changeset
   412
    vector unsigned int v8 = vec_splat_u32(8);
d0ae4dff7208 Altivec blitter for 555 -> 8888 surface, written by me.
Ryan C. Gordon <icculus@icculus.org>
parents: 1053
diff changeset
   413
    vector unsigned int v16 = vec_add(v8, v8);
d0ae4dff7208 Altivec blitter for 555 -> 8888 surface, written by me.
Ryan C. Gordon <icculus@icculus.org>
parents: 1053
diff changeset
   414
    vector unsigned short v1 = vec_splat_u16(1);
d0ae4dff7208 Altivec blitter for 555 -> 8888 surface, written by me.
Ryan C. Gordon <icculus@icculus.org>
parents: 1053
diff changeset
   415
    vector unsigned short v3 = vec_splat_u16(3);
d0ae4dff7208 Altivec blitter for 555 -> 8888 surface, written by me.
Ryan C. Gordon <icculus@icculus.org>
parents: 1053
diff changeset
   416
    /* 
d0ae4dff7208 Altivec blitter for 555 -> 8888 surface, written by me.
Ryan C. Gordon <icculus@icculus.org>
parents: 1053
diff changeset
   417
        0x10 - 0x1f is the alpha
d0ae4dff7208 Altivec blitter for 555 -> 8888 surface, written by me.
Ryan C. Gordon <icculus@icculus.org>
parents: 1053
diff changeset
   418
        0x00 - 0x0e evens are the red
d0ae4dff7208 Altivec blitter for 555 -> 8888 surface, written by me.
Ryan C. Gordon <icculus@icculus.org>
parents: 1053
diff changeset
   419
        0x01 - 0x0f odds are zero
d0ae4dff7208 Altivec blitter for 555 -> 8888 surface, written by me.
Ryan C. Gordon <icculus@icculus.org>
parents: 1053
diff changeset
   420
    */
1162
2651158f59b8 Enable altivec blitters on PowerPC Linux, and some fixes for recent
Ryan C. Gordon <icculus@icculus.org>
parents: 1139
diff changeset
   421
    vector unsigned char vredalpha1 = VECUINT8_LITERAL(
1139
d0ae4dff7208 Altivec blitter for 555 -> 8888 surface, written by me.
Ryan C. Gordon <icculus@icculus.org>
parents: 1053
diff changeset
   422
        0x10, 0x00, 0x01, 0x01,
d0ae4dff7208 Altivec blitter for 555 -> 8888 surface, written by me.
Ryan C. Gordon <icculus@icculus.org>
parents: 1053
diff changeset
   423
        0x10, 0x02, 0x01, 0x01,
d0ae4dff7208 Altivec blitter for 555 -> 8888 surface, written by me.
Ryan C. Gordon <icculus@icculus.org>
parents: 1053
diff changeset
   424
        0x10, 0x04, 0x01, 0x01,
d0ae4dff7208 Altivec blitter for 555 -> 8888 surface, written by me.
Ryan C. Gordon <icculus@icculus.org>
parents: 1053
diff changeset
   425
        0x10, 0x06, 0x01, 0x01
d0ae4dff7208 Altivec blitter for 555 -> 8888 surface, written by me.
Ryan C. Gordon <icculus@icculus.org>
parents: 1053
diff changeset
   426
    );
d0ae4dff7208 Altivec blitter for 555 -> 8888 surface, written by me.
Ryan C. Gordon <icculus@icculus.org>
parents: 1053
diff changeset
   427
    vector unsigned char vredalpha2 = (vector unsigned char)(
d0ae4dff7208 Altivec blitter for 555 -> 8888 surface, written by me.
Ryan C. Gordon <icculus@icculus.org>
parents: 1053
diff changeset
   428
        vec_add((vector unsigned int)vredalpha1, vec_sl(v8, v16))
d0ae4dff7208 Altivec blitter for 555 -> 8888 surface, written by me.
Ryan C. Gordon <icculus@icculus.org>
parents: 1053
diff changeset
   429
    );
d0ae4dff7208 Altivec blitter for 555 -> 8888 surface, written by me.
Ryan C. Gordon <icculus@icculus.org>
parents: 1053
diff changeset
   430
    /*
d0ae4dff7208 Altivec blitter for 555 -> 8888 surface, written by me.
Ryan C. Gordon <icculus@icculus.org>
parents: 1053
diff changeset
   431
        0x00 - 0x0f is ARxx ARxx ARxx ARxx
d0ae4dff7208 Altivec blitter for 555 -> 8888 surface, written by me.
Ryan C. Gordon <icculus@icculus.org>
parents: 1053
diff changeset
   432
        0x11 - 0x0f odds are blue
d0ae4dff7208 Altivec blitter for 555 -> 8888 surface, written by me.
Ryan C. Gordon <icculus@icculus.org>
parents: 1053
diff changeset
   433
    */
1162
2651158f59b8 Enable altivec blitters on PowerPC Linux, and some fixes for recent
Ryan C. Gordon <icculus@icculus.org>
parents: 1139
diff changeset
   434
    vector unsigned char vblue1 = VECUINT8_LITERAL(
1139
d0ae4dff7208 Altivec blitter for 555 -> 8888 surface, written by me.
Ryan C. Gordon <icculus@icculus.org>
parents: 1053
diff changeset
   435
        0x00, 0x01, 0x02, 0x11,
d0ae4dff7208 Altivec blitter for 555 -> 8888 surface, written by me.
Ryan C. Gordon <icculus@icculus.org>
parents: 1053
diff changeset
   436
        0x04, 0x05, 0x06, 0x13,
d0ae4dff7208 Altivec blitter for 555 -> 8888 surface, written by me.
Ryan C. Gordon <icculus@icculus.org>
parents: 1053
diff changeset
   437
        0x08, 0x09, 0x0a, 0x15,
d0ae4dff7208 Altivec blitter for 555 -> 8888 surface, written by me.
Ryan C. Gordon <icculus@icculus.org>
parents: 1053
diff changeset
   438
        0x0c, 0x0d, 0x0e, 0x17
d0ae4dff7208 Altivec blitter for 555 -> 8888 surface, written by me.
Ryan C. Gordon <icculus@icculus.org>
parents: 1053
diff changeset
   439
    );
d0ae4dff7208 Altivec blitter for 555 -> 8888 surface, written by me.
Ryan C. Gordon <icculus@icculus.org>
parents: 1053
diff changeset
   440
    vector unsigned char vblue2 = (vector unsigned char)(
d0ae4dff7208 Altivec blitter for 555 -> 8888 surface, written by me.
Ryan C. Gordon <icculus@icculus.org>
parents: 1053
diff changeset
   441
        vec_add((vector unsigned int)vblue1, v8)
d0ae4dff7208 Altivec blitter for 555 -> 8888 surface, written by me.
Ryan C. Gordon <icculus@icculus.org>
parents: 1053
diff changeset
   442
    );
d0ae4dff7208 Altivec blitter for 555 -> 8888 surface, written by me.
Ryan C. Gordon <icculus@icculus.org>
parents: 1053
diff changeset
   443
    /*
d0ae4dff7208 Altivec blitter for 555 -> 8888 surface, written by me.
Ryan C. Gordon <icculus@icculus.org>
parents: 1053
diff changeset
   444
        0x00 - 0x0f is ARxB ARxB ARxB ARxB
d0ae4dff7208 Altivec blitter for 555 -> 8888 surface, written by me.
Ryan C. Gordon <icculus@icculus.org>
parents: 1053
diff changeset
   445
        0x10 - 0x0e evens are green
d0ae4dff7208 Altivec blitter for 555 -> 8888 surface, written by me.
Ryan C. Gordon <icculus@icculus.org>
parents: 1053
diff changeset
   446
    */
1162
2651158f59b8 Enable altivec blitters on PowerPC Linux, and some fixes for recent
Ryan C. Gordon <icculus@icculus.org>
parents: 1139
diff changeset
   447
    vector unsigned char vgreen1 = VECUINT8_LITERAL(
1139
d0ae4dff7208 Altivec blitter for 555 -> 8888 surface, written by me.
Ryan C. Gordon <icculus@icculus.org>
parents: 1053
diff changeset
   448
        0x00, 0x01, 0x10, 0x03,
d0ae4dff7208 Altivec blitter for 555 -> 8888 surface, written by me.
Ryan C. Gordon <icculus@icculus.org>
parents: 1053
diff changeset
   449
        0x04, 0x05, 0x12, 0x07,
d0ae4dff7208 Altivec blitter for 555 -> 8888 surface, written by me.
Ryan C. Gordon <icculus@icculus.org>
parents: 1053
diff changeset
   450
        0x08, 0x09, 0x14, 0x0b,
d0ae4dff7208 Altivec blitter for 555 -> 8888 surface, written by me.
Ryan C. Gordon <icculus@icculus.org>
parents: 1053
diff changeset
   451
        0x0c, 0x0d, 0x16, 0x0f
d0ae4dff7208 Altivec blitter for 555 -> 8888 surface, written by me.
Ryan C. Gordon <icculus@icculus.org>
parents: 1053
diff changeset
   452
    );
d0ae4dff7208 Altivec blitter for 555 -> 8888 surface, written by me.
Ryan C. Gordon <icculus@icculus.org>
parents: 1053
diff changeset
   453
    vector unsigned char vgreen2 = (vector unsigned char)(
d0ae4dff7208 Altivec blitter for 555 -> 8888 surface, written by me.
Ryan C. Gordon <icculus@icculus.org>
parents: 1053
diff changeset
   454
        vec_add((vector unsigned int)vgreen1, vec_sl(v8, v8))
d0ae4dff7208 Altivec blitter for 555 -> 8888 surface, written by me.
Ryan C. Gordon <icculus@icculus.org>
parents: 1053
diff changeset
   455
    );
d0ae4dff7208 Altivec blitter for 555 -> 8888 surface, written by me.
Ryan C. Gordon <icculus@icculus.org>
parents: 1053
diff changeset
   456
    
d0ae4dff7208 Altivec blitter for 555 -> 8888 surface, written by me.
Ryan C. Gordon <icculus@icculus.org>
parents: 1053
diff changeset
   457
d0ae4dff7208 Altivec blitter for 555 -> 8888 surface, written by me.
Ryan C. Gordon <icculus@icculus.org>
parents: 1053
diff changeset
   458
    assert(srcfmt->BytesPerPixel == 2);
d0ae4dff7208 Altivec blitter for 555 -> 8888 surface, written by me.
Ryan C. Gordon <icculus@icculus.org>
parents: 1053
diff changeset
   459
    assert(dstfmt->BytesPerPixel == 4);
d0ae4dff7208 Altivec blitter for 555 -> 8888 surface, written by me.
Ryan C. Gordon <icculus@icculus.org>
parents: 1053
diff changeset
   460
d0ae4dff7208 Altivec blitter for 555 -> 8888 surface, written by me.
Ryan C. Gordon <icculus@icculus.org>
parents: 1053
diff changeset
   461
    vf800 = (vector unsigned short)vec_splat_u8(-7);
d0ae4dff7208 Altivec blitter for 555 -> 8888 surface, written by me.
Ryan C. Gordon <icculus@icculus.org>
parents: 1053
diff changeset
   462
    vf800 = vec_sl(vf800, vec_splat_u16(8));
d0ae4dff7208 Altivec blitter for 555 -> 8888 surface, written by me.
Ryan C. Gordon <icculus@icculus.org>
parents: 1053
diff changeset
   463
d0ae4dff7208 Altivec blitter for 555 -> 8888 surface, written by me.
Ryan C. Gordon <icculus@icculus.org>
parents: 1053
diff changeset
   464
    if (dstfmt->Amask && srcfmt->alpha) {
d0ae4dff7208 Altivec blitter for 555 -> 8888 surface, written by me.
Ryan C. Gordon <icculus@icculus.org>
parents: 1053
diff changeset
   465
        ((unsigned char *)&valpha)[0] = alpha = srcfmt->alpha;
d0ae4dff7208 Altivec blitter for 555 -> 8888 surface, written by me.
Ryan C. Gordon <icculus@icculus.org>
parents: 1053
diff changeset
   466
        valpha = vec_splat(valpha, 0);
d0ae4dff7208 Altivec blitter for 555 -> 8888 surface, written by me.
Ryan C. Gordon <icculus@icculus.org>
parents: 1053
diff changeset
   467
    } else {
d0ae4dff7208 Altivec blitter for 555 -> 8888 surface, written by me.
Ryan C. Gordon <icculus@icculus.org>
parents: 1053
diff changeset
   468
        alpha = 0;
d0ae4dff7208 Altivec blitter for 555 -> 8888 surface, written by me.
Ryan C. Gordon <icculus@icculus.org>
parents: 1053
diff changeset
   469
        valpha = vec_splat_u8(0);
d0ae4dff7208 Altivec blitter for 555 -> 8888 surface, written by me.
Ryan C. Gordon <icculus@icculus.org>
parents: 1053
diff changeset
   470
    }
d0ae4dff7208 Altivec blitter for 555 -> 8888 surface, written by me.
Ryan C. Gordon <icculus@icculus.org>
parents: 1053
diff changeset
   471
d0ae4dff7208 Altivec blitter for 555 -> 8888 surface, written by me.
Ryan C. Gordon <icculus@icculus.org>
parents: 1053
diff changeset
   472
    vpermute = calc_swizzle32(NULL, dstfmt);
d0ae4dff7208 Altivec blitter for 555 -> 8888 surface, written by me.
Ryan C. Gordon <icculus@icculus.org>
parents: 1053
diff changeset
   473
    while (height--) {
d0ae4dff7208 Altivec blitter for 555 -> 8888 surface, written by me.
Ryan C. Gordon <icculus@icculus.org>
parents: 1053
diff changeset
   474
        vector unsigned char valigner;
d0ae4dff7208 Altivec blitter for 555 -> 8888 surface, written by me.
Ryan C. Gordon <icculus@icculus.org>
parents: 1053
diff changeset
   475
        vector unsigned char voverflow;
d0ae4dff7208 Altivec blitter for 555 -> 8888 surface, written by me.
Ryan C. Gordon <icculus@icculus.org>
parents: 1053
diff changeset
   476
        vector unsigned char vsrc;
d0ae4dff7208 Altivec blitter for 555 -> 8888 surface, written by me.
Ryan C. Gordon <icculus@icculus.org>
parents: 1053
diff changeset
   477
d0ae4dff7208 Altivec blitter for 555 -> 8888 surface, written by me.
Ryan C. Gordon <icculus@icculus.org>
parents: 1053
diff changeset
   478
        int width = info->d_width;
d0ae4dff7208 Altivec blitter for 555 -> 8888 surface, written by me.
Ryan C. Gordon <icculus@icculus.org>
parents: 1053
diff changeset
   479
        int extrawidth;
d0ae4dff7208 Altivec blitter for 555 -> 8888 surface, written by me.
Ryan C. Gordon <icculus@icculus.org>
parents: 1053
diff changeset
   480
d0ae4dff7208 Altivec blitter for 555 -> 8888 surface, written by me.
Ryan C. Gordon <icculus@icculus.org>
parents: 1053
diff changeset
   481
        /* do scalar until we can align... */
d0ae4dff7208 Altivec blitter for 555 -> 8888 surface, written by me.
Ryan C. Gordon <icculus@icculus.org>
parents: 1053
diff changeset
   482
#define ONE_PIXEL_BLEND(condition, widthvar) \
d0ae4dff7208 Altivec blitter for 555 -> 8888 surface, written by me.
Ryan C. Gordon <icculus@icculus.org>
parents: 1053
diff changeset
   483
        while (condition) { \
d0ae4dff7208 Altivec blitter for 555 -> 8888 surface, written by me.
Ryan C. Gordon <icculus@icculus.org>
parents: 1053
diff changeset
   484
            unsigned sR, sG, sB; \
1162
2651158f59b8 Enable altivec blitters on PowerPC Linux, and some fixes for recent
Ryan C. Gordon <icculus@icculus.org>
parents: 1139
diff changeset
   485
            unsigned short Pixel = *((unsigned short *)src); \
2651158f59b8 Enable altivec blitters on PowerPC Linux, and some fixes for recent
Ryan C. Gordon <icculus@icculus.org>
parents: 1139
diff changeset
   486
            sR = (Pixel >> 7) & 0xf8; \
2651158f59b8 Enable altivec blitters on PowerPC Linux, and some fixes for recent
Ryan C. Gordon <icculus@icculus.org>
parents: 1139
diff changeset
   487
            sG = (Pixel >> 2) & 0xf8; \
2651158f59b8 Enable altivec blitters on PowerPC Linux, and some fixes for recent
Ryan C. Gordon <icculus@icculus.org>
parents: 1139
diff changeset
   488
            sB = (Pixel << 3) & 0xf8; \
1139
d0ae4dff7208 Altivec blitter for 555 -> 8888 surface, written by me.
Ryan C. Gordon <icculus@icculus.org>
parents: 1053
diff changeset
   489
            ASSEMBLE_RGBA(dst, 4, dstfmt, sR, sG, sB, alpha); \
d0ae4dff7208 Altivec blitter for 555 -> 8888 surface, written by me.
Ryan C. Gordon <icculus@icculus.org>
parents: 1053
diff changeset
   490
            src += 2; \
d0ae4dff7208 Altivec blitter for 555 -> 8888 surface, written by me.
Ryan C. Gordon <icculus@icculus.org>
parents: 1053
diff changeset
   491
            dst += 4; \
d0ae4dff7208 Altivec blitter for 555 -> 8888 surface, written by me.
Ryan C. Gordon <icculus@icculus.org>
parents: 1053
diff changeset
   492
            widthvar--; \
d0ae4dff7208 Altivec blitter for 555 -> 8888 surface, written by me.
Ryan C. Gordon <icculus@icculus.org>
parents: 1053
diff changeset
   493
        }
d0ae4dff7208 Altivec blitter for 555 -> 8888 surface, written by me.
Ryan C. Gordon <icculus@icculus.org>
parents: 1053
diff changeset
   494
        ONE_PIXEL_BLEND(((UNALIGNED_PTR(dst)) && (width)), width);
d0ae4dff7208 Altivec blitter for 555 -> 8888 surface, written by me.
Ryan C. Gordon <icculus@icculus.org>
parents: 1053
diff changeset
   495
d0ae4dff7208 Altivec blitter for 555 -> 8888 surface, written by me.
Ryan C. Gordon <icculus@icculus.org>
parents: 1053
diff changeset
   496
        /* After all that work, here's the vector part! */
d0ae4dff7208 Altivec blitter for 555 -> 8888 surface, written by me.
Ryan C. Gordon <icculus@icculus.org>
parents: 1053
diff changeset
   497
        extrawidth = (width % 8);  /* trailing unaligned stores */
d0ae4dff7208 Altivec blitter for 555 -> 8888 surface, written by me.
Ryan C. Gordon <icculus@icculus.org>
parents: 1053
diff changeset
   498
        width -= extrawidth;
d0ae4dff7208 Altivec blitter for 555 -> 8888 surface, written by me.
Ryan C. Gordon <icculus@icculus.org>
parents: 1053
diff changeset
   499
        vsrc = vec_ld(0, src);
d0ae4dff7208 Altivec blitter for 555 -> 8888 surface, written by me.
Ryan C. Gordon <icculus@icculus.org>
parents: 1053
diff changeset
   500
        valigner = VEC_ALIGNER(src);
d0ae4dff7208 Altivec blitter for 555 -> 8888 surface, written by me.
Ryan C. Gordon <icculus@icculus.org>
parents: 1053
diff changeset
   501
d0ae4dff7208 Altivec blitter for 555 -> 8888 surface, written by me.
Ryan C. Gordon <icculus@icculus.org>
parents: 1053
diff changeset
   502
        while (width) {
d0ae4dff7208 Altivec blitter for 555 -> 8888 surface, written by me.
Ryan C. Gordon <icculus@icculus.org>
parents: 1053
diff changeset
   503
            vector unsigned short vR, vG, vB;
d0ae4dff7208 Altivec blitter for 555 -> 8888 surface, written by me.
Ryan C. Gordon <icculus@icculus.org>
parents: 1053
diff changeset
   504
            vector unsigned char vdst1, vdst2;
d0ae4dff7208 Altivec blitter for 555 -> 8888 surface, written by me.
Ryan C. Gordon <icculus@icculus.org>
parents: 1053
diff changeset
   505
d0ae4dff7208 Altivec blitter for 555 -> 8888 surface, written by me.
Ryan C. Gordon <icculus@icculus.org>
parents: 1053
diff changeset
   506
            voverflow = vec_ld(15, src);
d0ae4dff7208 Altivec blitter for 555 -> 8888 surface, written by me.
Ryan C. Gordon <icculus@icculus.org>
parents: 1053
diff changeset
   507
            vsrc = vec_perm(vsrc, voverflow, valigner);
d0ae4dff7208 Altivec blitter for 555 -> 8888 surface, written by me.
Ryan C. Gordon <icculus@icculus.org>
parents: 1053
diff changeset
   508
d0ae4dff7208 Altivec blitter for 555 -> 8888 surface, written by me.
Ryan C. Gordon <icculus@icculus.org>
parents: 1053
diff changeset
   509
            vR = vec_and(vec_sl((vector unsigned short)vsrc,v1), vf800);
d0ae4dff7208 Altivec blitter for 555 -> 8888 surface, written by me.
Ryan C. Gordon <icculus@icculus.org>
parents: 1053
diff changeset
   510
            vB = vec_sl((vector unsigned short)vsrc, v3);
d0ae4dff7208 Altivec blitter for 555 -> 8888 surface, written by me.
Ryan C. Gordon <icculus@icculus.org>
parents: 1053
diff changeset
   511
            vG = vec_sl(vB, v3);
d0ae4dff7208 Altivec blitter for 555 -> 8888 surface, written by me.
Ryan C. Gordon <icculus@icculus.org>
parents: 1053
diff changeset
   512
d0ae4dff7208 Altivec blitter for 555 -> 8888 surface, written by me.
Ryan C. Gordon <icculus@icculus.org>
parents: 1053
diff changeset
   513
            vdst1 = (vector unsigned char)vec_perm((vector unsigned char)vR, valpha, vredalpha1);
d0ae4dff7208 Altivec blitter for 555 -> 8888 surface, written by me.
Ryan C. Gordon <icculus@icculus.org>
parents: 1053
diff changeset
   514
            vdst1 = vec_perm(vdst1, (vector unsigned char)vB, vblue1);
d0ae4dff7208 Altivec blitter for 555 -> 8888 surface, written by me.
Ryan C. Gordon <icculus@icculus.org>
parents: 1053
diff changeset
   515
            vdst1 = vec_perm(vdst1, (vector unsigned char)vG, vgreen1);
d0ae4dff7208 Altivec blitter for 555 -> 8888 surface, written by me.
Ryan C. Gordon <icculus@icculus.org>
parents: 1053
diff changeset
   516
            vdst1 = vec_perm(vdst1, valpha, vpermute);
d0ae4dff7208 Altivec blitter for 555 -> 8888 surface, written by me.
Ryan C. Gordon <icculus@icculus.org>
parents: 1053
diff changeset
   517
            vec_st(vdst1, 0, dst);
d0ae4dff7208 Altivec blitter for 555 -> 8888 surface, written by me.
Ryan C. Gordon <icculus@icculus.org>
parents: 1053
diff changeset
   518
d0ae4dff7208 Altivec blitter for 555 -> 8888 surface, written by me.
Ryan C. Gordon <icculus@icculus.org>
parents: 1053
diff changeset
   519
            vdst2 = (vector unsigned char)vec_perm((vector unsigned char)vR, valpha, vredalpha2);
d0ae4dff7208 Altivec blitter for 555 -> 8888 surface, written by me.
Ryan C. Gordon <icculus@icculus.org>
parents: 1053
diff changeset
   520
            vdst2 = vec_perm(vdst2, (vector unsigned char)vB, vblue2);
d0ae4dff7208 Altivec blitter for 555 -> 8888 surface, written by me.
Ryan C. Gordon <icculus@icculus.org>
parents: 1053
diff changeset
   521
            vdst2 = vec_perm(vdst2, (vector unsigned char)vG, vgreen2);
d0ae4dff7208 Altivec blitter for 555 -> 8888 surface, written by me.
Ryan C. Gordon <icculus@icculus.org>
parents: 1053
diff changeset
   522
            vdst2 = vec_perm(vdst2, valpha, vpermute);
d0ae4dff7208 Altivec blitter for 555 -> 8888 surface, written by me.
Ryan C. Gordon <icculus@icculus.org>
parents: 1053
diff changeset
   523
            vec_st(vdst2, 16, dst);
d0ae4dff7208 Altivec blitter for 555 -> 8888 surface, written by me.
Ryan C. Gordon <icculus@icculus.org>
parents: 1053
diff changeset
   524
            
d0ae4dff7208 Altivec blitter for 555 -> 8888 surface, written by me.
Ryan C. Gordon <icculus@icculus.org>
parents: 1053
diff changeset
   525
            width -= 8;
d0ae4dff7208 Altivec blitter for 555 -> 8888 surface, written by me.
Ryan C. Gordon <icculus@icculus.org>
parents: 1053
diff changeset
   526
            dst += 32;
d0ae4dff7208 Altivec blitter for 555 -> 8888 surface, written by me.
Ryan C. Gordon <icculus@icculus.org>
parents: 1053
diff changeset
   527
            src += 16;
d0ae4dff7208 Altivec blitter for 555 -> 8888 surface, written by me.
Ryan C. Gordon <icculus@icculus.org>
parents: 1053
diff changeset
   528
            vsrc = voverflow;
d0ae4dff7208 Altivec blitter for 555 -> 8888 surface, written by me.
Ryan C. Gordon <icculus@icculus.org>
parents: 1053
diff changeset
   529
        }
d0ae4dff7208 Altivec blitter for 555 -> 8888 surface, written by me.
Ryan C. Gordon <icculus@icculus.org>
parents: 1053
diff changeset
   530
d0ae4dff7208 Altivec blitter for 555 -> 8888 surface, written by me.
Ryan C. Gordon <icculus@icculus.org>
parents: 1053
diff changeset
   531
        assert(width == 0);
d0ae4dff7208 Altivec blitter for 555 -> 8888 surface, written by me.
Ryan C. Gordon <icculus@icculus.org>
parents: 1053
diff changeset
   532
d0ae4dff7208 Altivec blitter for 555 -> 8888 surface, written by me.
Ryan C. Gordon <icculus@icculus.org>
parents: 1053
diff changeset
   533
d0ae4dff7208 Altivec blitter for 555 -> 8888 surface, written by me.
Ryan C. Gordon <icculus@icculus.org>
parents: 1053
diff changeset
   534
        /* do scalar until we can align... */
d0ae4dff7208 Altivec blitter for 555 -> 8888 surface, written by me.
Ryan C. Gordon <icculus@icculus.org>
parents: 1053
diff changeset
   535
        ONE_PIXEL_BLEND((extrawidth), extrawidth);
d0ae4dff7208 Altivec blitter for 555 -> 8888 surface, written by me.
Ryan C. Gordon <icculus@icculus.org>
parents: 1053
diff changeset
   536
#undef ONE_PIXEL_BLEND
d0ae4dff7208 Altivec blitter for 555 -> 8888 surface, written by me.
Ryan C. Gordon <icculus@icculus.org>
parents: 1053
diff changeset
   537
d0ae4dff7208 Altivec blitter for 555 -> 8888 surface, written by me.
Ryan C. Gordon <icculus@icculus.org>
parents: 1053
diff changeset
   538
        src += srcskip;  /* move to next row, accounting for pitch. */
d0ae4dff7208 Altivec blitter for 555 -> 8888 surface, written by me.
Ryan C. Gordon <icculus@icculus.org>
parents: 1053
diff changeset
   539
        dst += dstskip;
d0ae4dff7208 Altivec blitter for 555 -> 8888 surface, written by me.
Ryan C. Gordon <icculus@icculus.org>
parents: 1053
diff changeset
   540
    }
d0ae4dff7208 Altivec blitter for 555 -> 8888 surface, written by me.
Ryan C. Gordon <icculus@icculus.org>
parents: 1053
diff changeset
   541
d0ae4dff7208 Altivec blitter for 555 -> 8888 surface, written by me.
Ryan C. Gordon <icculus@icculus.org>
parents: 1053
diff changeset
   542
}
d0ae4dff7208 Altivec blitter for 555 -> 8888 surface, written by me.
Ryan C. Gordon <icculus@icculus.org>
parents: 1053
diff changeset
   543
1047
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   544
static void BlitNtoNKey(SDL_BlitInfo *info);
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   545
static void BlitNtoNKeyCopyAlpha(SDL_BlitInfo *info);
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   546
static void Blit32to32KeyAltivec(SDL_BlitInfo *info)
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   547
{
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   548
    int height = info->d_height;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   549
    Uint32 *srcp = (Uint32 *) info->s_pixels;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   550
    int srcskip = info->s_skip;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   551
    Uint32 *dstp = (Uint32 *) info->d_pixels;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   552
    int dstskip = info->d_skip;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   553
    SDL_PixelFormat *srcfmt = info->src;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   554
    int srcbpp = srcfmt->BytesPerPixel;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   555
    SDL_PixelFormat *dstfmt = info->dst;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   556
    int dstbpp = dstfmt->BytesPerPixel;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   557
    int copy_alpha = (srcfmt->Amask && dstfmt->Amask);
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   558
	unsigned alpha = dstfmt->Amask ? srcfmt->alpha : 0;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   559
    Uint32 rgbmask = srcfmt->Rmask | srcfmt->Gmask | srcfmt->Bmask;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   560
	Uint32 ckey = info->src->colorkey;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   561
    vector unsigned int valpha;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   562
    vector unsigned char vpermute;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   563
    vector unsigned char vzero;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   564
    vector unsigned int vckey;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   565
    vector unsigned int vrgbmask;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   566
    vpermute = calc_swizzle32(srcfmt, dstfmt);
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   567
    if (info->d_width < 16) {
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   568
        if(copy_alpha) {
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   569
            return BlitNtoNKeyCopyAlpha(info);
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   570
        } else {
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   571
            return BlitNtoNKey(info);
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   572
        }
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   573
    }
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   574
    vzero = vec_splat_u8(0);
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   575
    if (alpha) {
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   576
        ((unsigned char *)&valpha)[0] = (unsigned char)alpha;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   577
        valpha = (vector unsigned int)vec_splat((vector unsigned char)valpha, 0);
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   578
    } else {
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   579
        valpha = (vector unsigned int)vzero;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   580
    }
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   581
    ckey &= rgbmask;
1162
2651158f59b8 Enable altivec blitters on PowerPC Linux, and some fixes for recent
Ryan C. Gordon <icculus@icculus.org>
parents: 1139
diff changeset
   582
    ((unsigned int *)(char*)&vckey)[0] = ckey;
1047
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   583
    vckey = vec_splat(vckey, 0);
1162
2651158f59b8 Enable altivec blitters on PowerPC Linux, and some fixes for recent
Ryan C. Gordon <icculus@icculus.org>
parents: 1139
diff changeset
   584
    ((unsigned int *)(char*)&vrgbmask)[0] = rgbmask;
1047
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   585
    vrgbmask = vec_splat(vrgbmask, 0);
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   586
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   587
    while (height--) {
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   588
#define ONE_PIXEL_BLEND(condition, widthvar) \
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   589
        if (copy_alpha) { \
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   590
            while (condition) { \
1162
2651158f59b8 Enable altivec blitters on PowerPC Linux, and some fixes for recent
Ryan C. Gordon <icculus@icculus.org>
parents: 1139
diff changeset
   591
                Uint32 Pixel; \
1047
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   592
                unsigned sR, sG, sB, sA; \
1162
2651158f59b8 Enable altivec blitters on PowerPC Linux, and some fixes for recent
Ryan C. Gordon <icculus@icculus.org>
parents: 1139
diff changeset
   593
                DISEMBLE_RGBA((Uint8 *)srcp, srcbpp, srcfmt, Pixel, \
1047
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   594
                          sR, sG, sB, sA); \
1162
2651158f59b8 Enable altivec blitters on PowerPC Linux, and some fixes for recent
Ryan C. Gordon <icculus@icculus.org>
parents: 1139
diff changeset
   595
                if ( (Pixel & rgbmask) != ckey ) { \
1047
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   596
                      ASSEMBLE_RGBA((Uint8 *)dstp, dstbpp, dstfmt, \
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   597
                            sR, sG, sB, sA); \
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   598
                } \
1162
2651158f59b8 Enable altivec blitters on PowerPC Linux, and some fixes for recent
Ryan C. Gordon <icculus@icculus.org>
parents: 1139
diff changeset
   599
                dstp = (Uint32 *) (((Uint8 *) dstp) + dstbpp); \
2651158f59b8 Enable altivec blitters on PowerPC Linux, and some fixes for recent
Ryan C. Gordon <icculus@icculus.org>
parents: 1139
diff changeset
   600
                srcp = (Uint32 *) (((Uint8 *) srcp) + srcbpp); \
1047
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   601
                widthvar--; \
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   602
            } \
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   603
        } else { \
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   604
            while (condition) { \
1162
2651158f59b8 Enable altivec blitters on PowerPC Linux, and some fixes for recent
Ryan C. Gordon <icculus@icculus.org>
parents: 1139
diff changeset
   605
                Uint32 Pixel; \
1047
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   606
                unsigned sR, sG, sB; \
1162
2651158f59b8 Enable altivec blitters on PowerPC Linux, and some fixes for recent
Ryan C. Gordon <icculus@icculus.org>
parents: 1139
diff changeset
   607
                RETRIEVE_RGB_PIXEL((Uint8 *)srcp, srcbpp, Pixel); \
2651158f59b8 Enable altivec blitters on PowerPC Linux, and some fixes for recent
Ryan C. Gordon <icculus@icculus.org>
parents: 1139
diff changeset
   608
                if ( Pixel != ckey ) { \
2651158f59b8 Enable altivec blitters on PowerPC Linux, and some fixes for recent
Ryan C. Gordon <icculus@icculus.org>
parents: 1139
diff changeset
   609
                    RGB_FROM_PIXEL(Pixel, srcfmt, sR, sG, sB); \
1047
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   610
                    ASSEMBLE_RGBA((Uint8 *)dstp, dstbpp, dstfmt, \
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   611
                              sR, sG, sB, alpha); \
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   612
                } \
1162
2651158f59b8 Enable altivec blitters on PowerPC Linux, and some fixes for recent
Ryan C. Gordon <icculus@icculus.org>
parents: 1139
diff changeset
   613
                dstp = (Uint32 *) (((Uint8 *)dstp) + dstbpp); \
2651158f59b8 Enable altivec blitters on PowerPC Linux, and some fixes for recent
Ryan C. Gordon <icculus@icculus.org>
parents: 1139
diff changeset
   614
                srcp = (Uint32 *) (((Uint8 *)srcp) + srcbpp); \
1047
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   615
                widthvar--; \
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   616
            } \
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   617
        }
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   618
        int width = info->d_width;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   619
        ONE_PIXEL_BLEND((UNALIGNED_PTR(dstp)) && (width), width);
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   620
        assert(width > 0);
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   621
        if (width > 0) {
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   622
            int extrawidth = (width % 4);
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   623
            vector unsigned char valigner = VEC_ALIGNER(srcp);
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   624
            vector unsigned int vs = vec_ld(0, srcp);
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   625
            width -= extrawidth;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   626
            assert(width >= 4);
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   627
            while (width) {
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   628
                vector unsigned char vsel;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   629
                vector unsigned int vd;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   630
                vector unsigned int voverflow = vec_ld(15, srcp);
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   631
                /* load the source vec */
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   632
                vs = vec_perm(vs, voverflow, valigner);
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   633
                /* vsel is set for items that match the key */
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   634
                vsel = (vector unsigned char)vec_and(vs, vrgbmask);
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   635
                vsel = (vector unsigned char)vec_cmpeq(vs, vckey);
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   636
                /* permute the src vec to the dest format */
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   637
                vs = vec_perm(vs, valpha, vpermute);
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   638
                /* load the destination vec */
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   639
                vd = vec_ld(0, dstp);
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   640
                /* select the source and dest into vs */
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   641
                vd = (vector unsigned int)vec_sel((vector unsigned char)vs, (vector unsigned char)vd, vsel);
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   642
                
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   643
                vec_st(vd, 0, dstp);
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   644
                srcp += 4;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   645
                width -= 4;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   646
                dstp += 4;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   647
                vs = voverflow;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   648
            }
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   649
            ONE_PIXEL_BLEND((extrawidth), extrawidth);
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   650
#undef ONE_PIXEL_BLEND
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   651
            srcp += srcskip >> 2;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   652
            dstp += dstskip >> 2;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   653
        }
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   654
    }
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   655
}
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   656
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   657
/* Altivec code to swizzle one 32-bit surface to a different 32-bit format. */
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   658
/* Use this on a G5 */
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   659
static void ConvertAltivec32to32_noprefetch(SDL_BlitInfo *info)
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   660
{
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   661
    int height = info->d_height;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   662
    Uint32 *src = (Uint32 *) info->s_pixels;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   663
    int srcskip = info->s_skip;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   664
    Uint32 *dst = (Uint32 *) info->d_pixels;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   665
    int dstskip = info->d_skip;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   666
    SDL_PixelFormat *srcfmt = info->src;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   667
    int srcbpp = srcfmt->BytesPerPixel;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   668
    SDL_PixelFormat *dstfmt = info->dst;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   669
    int dstbpp = dstfmt->BytesPerPixel;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   670
    vector unsigned int vzero = vec_splat_u32(0);
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   671
    vector unsigned char vpermute = calc_swizzle32(srcfmt, dstfmt);
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   672
    if (dstfmt->Amask && !srcfmt->Amask) {
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   673
        if (srcfmt->alpha) {
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   674
            vector unsigned char valpha;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   675
            ((unsigned char *)&valpha)[0] = srcfmt->alpha;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   676
            vzero = (vector unsigned int)vec_splat(valpha, 0);
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   677
        }
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   678
    }
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   679
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   680
    assert(srcbpp == 4);
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   681
    assert(dstbpp == 4);
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   682
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   683
    while (height--) {
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   684
        vector unsigned char valigner;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   685
        vector unsigned int vbits;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   686
        vector unsigned int voverflow;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   687
        Uint32 bits;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   688
        Uint8 r, g, b, a;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   689
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   690
        int width = info->d_width;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   691
        int extrawidth;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   692
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   693
        /* do scalar until we can align... */
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   694
        while ((UNALIGNED_PTR(dst)) && (width)) {
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   695
            bits = *(src++);
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   696
            RGBA_FROM_8888(bits, srcfmt, r, g, b, a);
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   697
            *(dst++) = MAKE8888(dstfmt, r, g, b, a);
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   698
            width--;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   699
        }
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   700
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   701
        /* After all that work, here's the vector part! */
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   702
        extrawidth = (width % 4);
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   703
        width -= extrawidth;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   704
        valigner = VEC_ALIGNER(src);
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   705
        vbits = vec_ld(0, src);
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   706
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   707
       while (width) {
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   708
            voverflow = vec_ld(15, src);
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   709
            src += 4;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   710
            width -= 4;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   711
            vbits = vec_perm(vbits, voverflow, valigner);  /* src is ready. */
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   712
            vbits = vec_perm(vbits, vzero, vpermute);  /* swizzle it. */
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   713
            vec_st(vbits, 0, dst);  /* store it back out. */
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   714
            dst += 4;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   715
            vbits = voverflow;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   716
        }
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   717
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   718
        assert(width == 0);
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   719
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   720
        /* cover pixels at the end of the row that didn't fit in 16 bytes. */
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   721
        while (extrawidth) {
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   722
            bits = *(src++);  /* max 7 pixels, don't bother with prefetch. */
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   723
            RGBA_FROM_8888(bits, srcfmt, r, g, b, a);
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   724
            *(dst++) = MAKE8888(dstfmt, r, g, b, a);
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   725
            extrawidth--;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   726
        }
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   727
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   728
        src += srcskip >> 2;  /* move to next row, accounting for pitch. */
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   729
        dst += dstskip >> 2;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   730
    }
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   731
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   732
}
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   733
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   734
/* Altivec code to swizzle one 32-bit surface to a different 32-bit format. */
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   735
/* Use this on a G4 */
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   736
static void ConvertAltivec32to32_prefetch(SDL_BlitInfo *info)
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   737
{
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   738
    const int scalar_dst_lead = sizeof (Uint32) * 4;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   739
    const int vector_dst_lead = sizeof (Uint32) * 16;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   740
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   741
    int height = info->d_height;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   742
    Uint32 *src = (Uint32 *) info->s_pixels;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   743
    int srcskip = info->s_skip;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   744
    Uint32 *dst = (Uint32 *) info->d_pixels;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   745
    int dstskip = info->d_skip;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   746
    SDL_PixelFormat *srcfmt = info->src;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   747
    int srcbpp = srcfmt->BytesPerPixel;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   748
    SDL_PixelFormat *dstfmt = info->dst;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   749
    int dstbpp = dstfmt->BytesPerPixel;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   750
    vector unsigned int vzero = vec_splat_u32(0);
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   751
    vector unsigned char vpermute = calc_swizzle32(srcfmt, dstfmt);
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   752
    if (dstfmt->Amask && !srcfmt->Amask) {
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   753
        if (srcfmt->alpha) {
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   754
            vector unsigned char valpha;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   755
            ((unsigned char *)&valpha)[0] = srcfmt->alpha;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   756
            vzero = (vector unsigned int)vec_splat(valpha, 0);
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   757
        }
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   758
    }
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   759
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   760
    assert(srcbpp == 4);
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   761
    assert(dstbpp == 4);
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   762
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   763
    while (height--) {
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   764
        vector unsigned char valigner;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   765
        vector unsigned int vbits;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   766
        vector unsigned int voverflow;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   767
        Uint32 bits;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   768
        Uint8 r, g, b, a;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   769
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   770
        int width = info->d_width;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   771
        int extrawidth;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   772
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   773
        /* do scalar until we can align... */
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   774
        while ((UNALIGNED_PTR(dst)) && (width)) {
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   775
            vec_dstt(src+scalar_dst_lead, DST_CTRL(2,32,1024), DST_CHAN_SRC);
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   776
            vec_dstst(dst+scalar_dst_lead, DST_CTRL(2,32,1024), DST_CHAN_DEST);
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   777
            bits = *(src++);
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   778
            RGBA_FROM_8888(bits, srcfmt, r, g, b, a);
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   779
            *(dst++) = MAKE8888(dstfmt, r, g, b, a);
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   780
            width--;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   781
        }
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   782
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   783
        /* After all that work, here's the vector part! */
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   784
        extrawidth = (width % 4);
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   785
        width -= extrawidth;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   786
        valigner = VEC_ALIGNER(src);
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   787
        vbits = vec_ld(0, src);
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   788
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   789
        while (width) {
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   790
            vec_dstt(src+vector_dst_lead, DST_CTRL(2,32,1024), DST_CHAN_SRC);
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   791
            vec_dstst(dst+vector_dst_lead, DST_CTRL(2,32,1024), DST_CHAN_DEST);
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   792
            voverflow = vec_ld(15, src);
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   793
            src += 4;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   794
            width -= 4;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   795
            vbits = vec_perm(vbits, voverflow, valigner);  /* src is ready. */
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   796
            vbits = vec_perm(vbits, vzero, vpermute);  /* swizzle it. */
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   797
            vec_st(vbits, 0, dst);  /* store it back out. */
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   798
            dst += 4;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   799
            vbits = voverflow;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   800
        }
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   801
        
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   802
        assert(width == 0);
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   803
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   804
        /* cover pixels at the end of the row that didn't fit in 16 bytes. */
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   805
        while (extrawidth) {
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   806
            bits = *(src++);  /* max 7 pixels, don't bother with prefetch. */
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   807
            RGBA_FROM_8888(bits, srcfmt, r, g, b, a);
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   808
            *(dst++) = MAKE8888(dstfmt, r, g, b, a);
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   809
            extrawidth--;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   810
        }
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   811
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   812
        src += srcskip >> 2;  /* move to next row, accounting for pitch. */
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   813
        dst += dstskip >> 2;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   814
    }
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   815
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   816
    vec_dss(DST_CHAN_SRC);
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   817
    vec_dss(DST_CHAN_DEST);
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   818
}
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   819
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   820
static Uint32 GetBlitFeatures( void )
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   821
{
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   822
    static Uint32 features = 0xffffffff;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   823
    if (features == 0xffffffff) {
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   824
        /* Provide an override for testing .. */
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   825
        char *override = getenv("SDL_ALTIVEC_BLIT_FEATURES");
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   826
        if (override) {
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   827
            features = 0;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   828
            sscanf(override, "%u", &features);
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   829
        } else {
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   830
            features = ( 0
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   831
                /* Feature 1 is has-MMX */
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   832
                | ((SDL_HasMMX()) ? 1 : 0)
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   833
                /* Feature 2 is has-AltiVec */
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   834
                | ((SDL_HasAltiVec()) ? 2 : 0)
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   835
                /* Feature 4 is dont-use-prefetch */
1162
2651158f59b8 Enable altivec blitters on PowerPC Linux, and some fixes for recent
Ryan C. Gordon <icculus@icculus.org>
parents: 1139
diff changeset
   836
                /* !!!! FIXME: Check for G5 or later, not the cache size! Always prefetch on a G4. */
1047
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   837
                | ((GetL3CacheSize() == 0) ? 4 : 0)
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   838
            );
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   839
        }
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   840
    }
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   841
    return features;
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   842
}
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   843
#else
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   844
/* Feature 1 is has-MMX */
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   845
#define GetBlitFeatures() ((Uint32)(SDL_HasMMX() ? 1 : 0))
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   846
#endif
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   847
1053
f596fa4f17a6 Patched to compile again on x86 systems that use the assembly blitters.
Ryan C. Gordon <icculus@icculus.org>
parents: 1047
diff changeset
   848
/* This is now endian dependent */
f596fa4f17a6 Patched to compile again on x86 systems that use the assembly blitters.
Ryan C. Gordon <icculus@icculus.org>
parents: 1047
diff changeset
   849
#if ( SDL_BYTEORDER == SDL_LIL_ENDIAN )
f596fa4f17a6 Patched to compile again on x86 systems that use the assembly blitters.
Ryan C. Gordon <icculus@icculus.org>
parents: 1047
diff changeset
   850
#define HI	1
f596fa4f17a6 Patched to compile again on x86 systems that use the assembly blitters.
Ryan C. Gordon <icculus@icculus.org>
parents: 1047
diff changeset
   851
#define LO	0
f596fa4f17a6 Patched to compile again on x86 systems that use the assembly blitters.
Ryan C. Gordon <icculus@icculus.org>
parents: 1047
diff changeset
   852
#else /* ( SDL_BYTEORDER == SDL_BIG_ENDIAN ) */
f596fa4f17a6 Patched to compile again on x86 systems that use the assembly blitters.
Ryan C. Gordon <icculus@icculus.org>
parents: 1047
diff changeset
   853
#define HI	0
f596fa4f17a6 Patched to compile again on x86 systems that use the assembly blitters.
Ryan C. Gordon <icculus@icculus.org>
parents: 1047
diff changeset
   854
#define LO	1
f596fa4f17a6 Patched to compile again on x86 systems that use the assembly blitters.
Ryan C. Gordon <icculus@icculus.org>
parents: 1047
diff changeset
   855
#endif
f596fa4f17a6 Patched to compile again on x86 systems that use the assembly blitters.
Ryan C. Gordon <icculus@icculus.org>
parents: 1047
diff changeset
   856
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   857
#ifdef USE_ASMBLIT
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   858
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   859
/* Heheheh, we coerce Hermes into using SDL blit information */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   860
#define X86_ASSEMBLER
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   861
#define HermesConverterInterface	SDL_BlitInfo
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   862
#define HermesClearInterface		void
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   863
#define STACKCALL
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   864
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   865
#include "HeadMMX.h"
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   866
#include "HeadX86.h"
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   867
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   868
#else
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   869
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   870
/* Special optimized blit for RGB 8-8-8 --> RGB 3-3-2 */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   871
#define RGB888_RGB332(dst, src) { \
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   872
	dst = (((src)&0x00E00000)>>16)| \
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   873
	      (((src)&0x0000E000)>>11)| \
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   874
	      (((src)&0x000000C0)>>6); \
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   875
}
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   876
static void Blit_RGB888_index8(SDL_BlitInfo *info)
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   877
{
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   878
#ifndef USE_DUFFS_LOOP
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   879
	int c;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   880
#endif
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   881
	int width, height;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   882
	Uint32 *src;
91
e85e03f195b4 From: "Markus F.X.J. Oberhumer"
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
   883
	const Uint8 *map;
e85e03f195b4 From: "Markus F.X.J. Oberhumer"
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
   884
	Uint8 *dst;
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   885
	int srcskip, dstskip;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   886
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   887
	/* Set up some basic variables */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   888
	width = info->d_width;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   889
	height = info->d_height;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   890
	src = (Uint32 *)info->s_pixels;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   891
	srcskip = info->s_skip/4;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   892
	dst = info->d_pixels;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   893
	dstskip = info->d_skip;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   894
	map = info->table;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   895
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   896
	if ( map == NULL ) {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   897
		while ( height-- ) {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   898
#ifdef USE_DUFFS_LOOP
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   899
			DUFFS_LOOP(
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   900
				RGB888_RGB332(*dst++, *src);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   901
			, width);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   902
#else
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   903
			for ( c=width/4; c; --c ) {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   904
				/* Pack RGB into 8bit pixel */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   905
				++src;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   906
				RGB888_RGB332(*dst++, *src);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   907
				++src;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   908
				RGB888_RGB332(*dst++, *src);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   909
				++src;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   910
				RGB888_RGB332(*dst++, *src);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   911
				++src;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   912
			}
91
e85e03f195b4 From: "Markus F.X.J. Oberhumer"
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
   913
			switch ( width & 3 ) {
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   914
				case 3:
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   915
					RGB888_RGB332(*dst++, *src);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   916
					++src;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   917
				case 2:
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   918
					RGB888_RGB332(*dst++, *src);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   919
					++src;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   920
				case 1:
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   921
					RGB888_RGB332(*dst++, *src);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   922
					++src;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   923
			}
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   924
#endif /* USE_DUFFS_LOOP */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   925
			src += srcskip;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   926
			dst += dstskip;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   927
		}
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   928
	} else {
1162
2651158f59b8 Enable altivec blitters on PowerPC Linux, and some fixes for recent
Ryan C. Gordon <icculus@icculus.org>
parents: 1139
diff changeset
   929
		int Pixel;
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   930
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   931
		while ( height-- ) {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   932
#ifdef USE_DUFFS_LOOP
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   933
			DUFFS_LOOP(
1162
2651158f59b8 Enable altivec blitters on PowerPC Linux, and some fixes for recent
Ryan C. Gordon <icculus@icculus.org>
parents: 1139
diff changeset
   934
				RGB888_RGB332(Pixel, *src);
2651158f59b8 Enable altivec blitters on PowerPC Linux, and some fixes for recent
Ryan C. Gordon <icculus@icculus.org>
parents: 1139
diff changeset
   935
				*dst++ = map[Pixel];
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   936
				++src;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   937
			, width);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   938
#else
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   939
			for ( c=width/4; c; --c ) {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   940
				/* Pack RGB into 8bit pixel */
1162
2651158f59b8 Enable altivec blitters on PowerPC Linux, and some fixes for recent
Ryan C. Gordon <icculus@icculus.org>
parents: 1139
diff changeset
   941
				RGB888_RGB332(Pixel, *src);
2651158f59b8 Enable altivec blitters on PowerPC Linux, and some fixes for recent
Ryan C. Gordon <icculus@icculus.org>
parents: 1139
diff changeset
   942
				*dst++ = map[Pixel];
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   943
				++src;
1162
2651158f59b8 Enable altivec blitters on PowerPC Linux, and some fixes for recent
Ryan C. Gordon <icculus@icculus.org>
parents: 1139
diff changeset
   944
				RGB888_RGB332(Pixel, *src);
2651158f59b8 Enable altivec blitters on PowerPC Linux, and some fixes for recent
Ryan C. Gordon <icculus@icculus.org>
parents: 1139
diff changeset
   945
				*dst++ = map[Pixel];
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   946
				++src;
1162
2651158f59b8 Enable altivec blitters on PowerPC Linux, and some fixes for recent
Ryan C. Gordon <icculus@icculus.org>
parents: 1139
diff changeset
   947
				RGB888_RGB332(Pixel, *src);
2651158f59b8 Enable altivec blitters on PowerPC Linux, and some fixes for recent
Ryan C. Gordon <icculus@icculus.org>
parents: 1139
diff changeset
   948
				*dst++ = map[Pixel];
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   949
				++src;
1162
2651158f59b8 Enable altivec blitters on PowerPC Linux, and some fixes for recent
Ryan C. Gordon <icculus@icculus.org>
parents: 1139
diff changeset
   950
				RGB888_RGB332(Pixel, *src);
2651158f59b8 Enable altivec blitters on PowerPC Linux, and some fixes for recent
Ryan C. Gordon <icculus@icculus.org>
parents: 1139
diff changeset
   951
				*dst++ = map[Pixel];
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   952
				++src;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   953
			}
91
e85e03f195b4 From: "Markus F.X.J. Oberhumer"
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
   954
			switch ( width & 3 ) {
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   955
				case 3:
1162
2651158f59b8 Enable altivec blitters on PowerPC Linux, and some fixes for recent
Ryan C. Gordon <icculus@icculus.org>
parents: 1139
diff changeset
   956
					RGB888_RGB332(Pixel, *src);
2651158f59b8 Enable altivec blitters on PowerPC Linux, and some fixes for recent
Ryan C. Gordon <icculus@icculus.org>
parents: 1139
diff changeset
   957
					*dst++ = map[Pixel];
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   958
					++src;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   959
				case 2:
1162
2651158f59b8 Enable altivec blitters on PowerPC Linux, and some fixes for recent
Ryan C. Gordon <icculus@icculus.org>
parents: 1139
diff changeset
   960
					RGB888_RGB332(Pixel, *src);
2651158f59b8 Enable altivec blitters on PowerPC Linux, and some fixes for recent
Ryan C. Gordon <icculus@icculus.org>
parents: 1139
diff changeset
   961
					*dst++ = map[Pixel];
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   962
					++src;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   963
				case 1:
1162
2651158f59b8 Enable altivec blitters on PowerPC Linux, and some fixes for recent
Ryan C. Gordon <icculus@icculus.org>
parents: 1139
diff changeset
   964
					RGB888_RGB332(Pixel, *src);
2651158f59b8 Enable altivec blitters on PowerPC Linux, and some fixes for recent
Ryan C. Gordon <icculus@icculus.org>
parents: 1139
diff changeset
   965
					*dst++ = map[Pixel];
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   966
					++src;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   967
			}
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   968
#endif /* USE_DUFFS_LOOP */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   969
			src += srcskip;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   970
			dst += dstskip;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   971
		}
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   972
	}
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   973
}
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   974
/* Special optimized blit for RGB 8-8-8 --> RGB 5-5-5 */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   975
#define RGB888_RGB555(dst, src) { \
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   976
	*(Uint16 *)(dst) = (((*src)&0x00F80000)>>9)| \
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   977
	                   (((*src)&0x0000F800)>>6)| \
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   978
	                   (((*src)&0x000000F8)>>3); \
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   979
}
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   980
#define RGB888_RGB555_TWO(dst, src) { \
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   981
	*(Uint32 *)(dst) = (((((src[HI])&0x00F80000)>>9)| \
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   982
	                     (((src[HI])&0x0000F800)>>6)| \
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   983
	                     (((src[HI])&0x000000F8)>>3))<<16)| \
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   984
	                     (((src[LO])&0x00F80000)>>9)| \
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   985
	                     (((src[LO])&0x0000F800)>>6)| \
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   986
	                     (((src[LO])&0x000000F8)>>3); \
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   987
}
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   988
static void Blit_RGB888_RGB555(SDL_BlitInfo *info)
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   989
{
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   990
#ifndef USE_DUFFS_LOOP
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   991
	int c;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   992
#endif
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   993
	int width, height;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   994
	Uint32 *src;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   995
	Uint16 *dst;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   996
	int srcskip, dstskip;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   997
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   998
	/* Set up some basic variables */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   999
	width = info->d_width;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
  1000
	height = info->d_height;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
  1001
	src = (Uint32 *)info->s_pixels;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
  1002
	srcskip = info->s_skip/4;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
  1003
	dst = (Uint16 *)info->d_pixels;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
  1004
	dstskip = info->d_skip/2;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
  1005
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
  1006
#ifdef USE_DUFFS_LOOP
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
  1007
	while ( height-- ) {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
  1008
		DUFFS_LOOP(
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
  1009
			RGB888_RGB555(dst, src);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
  1010
			++src;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
  1011
			++dst;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
  1012
		, width);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
  1013
		src += srcskip;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
  1014
		dst += dstskip;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
  1015
	}
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
  1016
#else
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
  1017
	/* Memory align at 4-byte boundary, if necessary */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
  1018
	if ( (long)dst & 0x03 ) {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
  1019
		/* Don't do anything if width is 0 */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
  1020
		if ( width == 0 ) {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
  1021
			return;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
  1022
		}
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
  1023
		--width;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
  1024
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
  1025
		while ( height-- ) {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
  1026
			/* Perform copy alignment */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
  1027
			RGB888_RGB555(dst, src);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
  1028
			++src;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
  1029
			++dst;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
  1030
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
  1031
			/* Copy in 4 pixel chunks */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
  1032
			for ( c=width/4; c; --c ) {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
  1033
				RGB888_RGB555_TWO(dst, src);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
  1034
				src += 2;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
  1035
				dst += 2;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
  1036
				RGB888_RGB555_TWO(dst, src);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
  1037
				src += 2;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
  1038
				dst += 2;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
  1039
			}
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
  1040
			/* Get any leftovers */
91
e85e03f195b4 From: "Markus F.X.J. Oberhumer"
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
  1041
			switch (width & 3) {
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
  1042
				case 3:
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
  1043
					RGB888_RGB555(dst, src);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
  1044
					++src;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
  1045
					++dst;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
  1046
				case 2:
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
  1047
					RGB888_RGB555_TWO(dst, src);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
  1048
					src += 2;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
  1049
					dst += 2;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
  1050
					break;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
  1051
				case 1:
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
  1052
					RGB888_RGB555(dst, src);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
  1053
					++src;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
  1054
					++dst;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
  1055
					break;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
  1056
			}
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
  1057
			src += srcskip;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
  1058
			dst += dstskip;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
  1059
		}
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
  1060
	} else { 
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
  1061
		while ( height-- ) {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
  1062
			/* Copy in 4 pixel chunks */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
  1063
			for ( c=width/4; c; --c ) {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
  1064
				RGB888_RGB555_TWO(dst, src);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
  1065
				src += 2;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
  1066
				dst += 2;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
  1067
				RGB888_RGB555_TWO(dst, src);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
  1068
				src += 2;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
  1069
				dst += 2;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
  1070
			}
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
  1071
			/* Get any leftovers */
91
e85e03f195b4 From: "Markus F.X.J. Oberhumer"
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
  1072
			switch (width & 3) {
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
  1073
				case 3:
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
  1074
					RGB888_RGB555(dst, src);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
  1075
					++src;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
  1076
					++dst;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
  1077
				case 2:
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
  1078
					RGB888_RGB555_TWO(dst, src);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
  1079
					src += 2;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
  1080
					dst += 2;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
  1081
					break;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
  1082
				case 1:
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
  1083
					RGB888_RGB555(dst, src);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
  1084
					++src;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
  1085
					++dst;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
  1086
					break;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
  1087
			}
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
  1088
			src += srcskip;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
  1089
			dst += dstskip;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
  1090
		}
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
  1091
	}
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
  1092
#endif /* USE_DUFFS_LOOP */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
  1093
}
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
  1094
/* Special optimized blit for RGB 8-8-8 --> RGB 5-6-5 */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
  1095
#define RGB888_RGB565(dst, src) { \
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
  1096
	*(Uint16 *)(dst) = (((*src)&0x00F80000)>>8)| \
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
  1097
	                   (((*src)&0x0000FC00)>>5)| \
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
  1098
	                   (((*src)&0x000000F8)>>3); \
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
  1099
}
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
  1100
#define RGB888_RGB565_TWO(dst, src) { \
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
  1101
	*(Uint32 *)(dst) = (((((src[HI])&0x00F80000)>>8)| \
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
  1102
	                     (((src[HI])&0x0000FC00)>>5)| \
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
  1103
	                     (((src[HI])&0x000000F8)>>3))<<16)| \
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
  1104
	                     (((src[LO])&0x00F80000)>>8)| \
74212992fb08 Initial revision
Sam Lantinga <slouken