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