src/video/SDL_blit_N.c
changeset 5259 6a65c1fc07af
parent 3697 f7b03b6838cb
child 5262 b530ef003506
     1.1 --- a/src/video/SDL_blit_N.c	Fri Feb 11 14:42:58 2011 -0800
     1.2 +++ b/src/video/SDL_blit_N.c	Fri Feb 11 14:51:04 2011 -0800
     1.3 @@ -28,846 +28,8 @@
     1.4  
     1.5  /* Functions to blit from N-bit surfaces to other surfaces */
     1.6  
     1.7 -#if SDL_ALTIVEC_BLITTERS
     1.8 -#if __MWERKS__
     1.9 -#pragma altivec_model on
    1.10 -#endif
    1.11 -#ifdef HAVE_ALTIVEC_H
    1.12 -#include <altivec.h>
    1.13 -#endif
    1.14 -#define assert(X)
    1.15 -#ifdef __MACOSX__
    1.16 -#include <sys/sysctl.h>
    1.17 -static size_t
    1.18 -GetL3CacheSize(void)
    1.19 -{
    1.20 -    const char key[] = "hw.l3cachesize";
    1.21 -    u_int64_t result = 0;
    1.22 -    size_t typeSize = sizeof(result);
    1.23 -
    1.24 -
    1.25 -    int err = sysctlbyname(key, &result, &typeSize, NULL, 0);
    1.26 -    if (0 != err)
    1.27 -        return 0;
    1.28 -
    1.29 -    return result;
    1.30 -}
    1.31 -#else
    1.32 -static size_t
    1.33 -GetL3CacheSize(void)
    1.34 -{
    1.35 -    /* XXX: Just guess G4 */
    1.36 -    return 2097152;
    1.37 -}
    1.38 -#endif /* __MACOSX__ */
    1.39 -
    1.40 -#if (defined(__MACOSX__) && (__GNUC__ < 4))
    1.41 -#define VECUINT8_LITERAL(a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p) \
    1.42 -        (vector unsigned char) ( a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p )
    1.43 -#define VECUINT16_LITERAL(a,b,c,d,e,f,g,h) \
    1.44 -        (vector unsigned short) ( a,b,c,d,e,f,g,h )
    1.45 -#else
    1.46 -#define VECUINT8_LITERAL(a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p) \
    1.47 -        (vector unsigned char) { a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p }
    1.48 -#define VECUINT16_LITERAL(a,b,c,d,e,f,g,h) \
    1.49 -        (vector unsigned short) { a,b,c,d,e,f,g,h }
    1.50 -#endif
    1.51 -
    1.52 -#define UNALIGNED_PTR(x) (((size_t) x) & 0x0000000F)
    1.53 -#define VSWIZZLE32(a,b,c,d) (vector unsigned char) \
    1.54 -                               ( 0x00+a, 0x00+b, 0x00+c, 0x00+d, \
    1.55 -                                 0x04+a, 0x04+b, 0x04+c, 0x04+d, \
    1.56 -                                 0x08+a, 0x08+b, 0x08+c, 0x08+d, \
    1.57 -                                 0x0C+a, 0x0C+b, 0x0C+c, 0x0C+d )
    1.58 -
    1.59 -#define MAKE8888(dstfmt, r, g, b, a)  \
    1.60 -    ( ((r<<dstfmt->Rshift)&dstfmt->Rmask) | \
    1.61 -      ((g<<dstfmt->Gshift)&dstfmt->Gmask) | \
    1.62 -      ((b<<dstfmt->Bshift)&dstfmt->Bmask) | \
    1.63 -      ((a<<dstfmt->Ashift)&dstfmt->Amask) )
    1.64 -
    1.65 -/*
    1.66 - * Data Stream Touch...Altivec cache prefetching.
    1.67 - *
    1.68 - *  Don't use this on a G5...however, the speed boost is very significant
    1.69 - *   on a G4.
    1.70 - */
    1.71 -#define DST_CHAN_SRC 1
    1.72 -#define DST_CHAN_DEST 2
    1.73 -
    1.74 -/* macro to set DST control word value... */
    1.75 -#define DST_CTRL(size, count, stride) \
    1.76 -    (((size) << 24) | ((count) << 16) | (stride))
    1.77 -
    1.78 -#define VEC_ALIGNER(src) ((UNALIGNED_PTR(src)) \
    1.79 -    ? vec_lvsl(0, src) \
    1.80 -    : vec_add(vec_lvsl(8, src), vec_splat_u8(8)))
    1.81 -
    1.82 -/* Calculate the permute vector used for 32->32 swizzling */
    1.83 -static vector unsigned char
    1.84 -calc_swizzle32(const SDL_PixelFormat * srcfmt, const SDL_PixelFormat * dstfmt)
    1.85 -{
    1.86 -    /*
    1.87 -     * We have to assume that the bits that aren't used by other
    1.88 -     *  colors is alpha, and it's one complete byte, since some formats
    1.89 -     *  leave alpha with a zero mask, but we should still swizzle the bits.
    1.90 -     */
    1.91 -    /* ARGB */
    1.92 -    const static const struct SDL_PixelFormat default_pixel_format = {
    1.93 -        NULL, 32, 4,
    1.94 -        0, 0, 0, 0,
    1.95 -        16, 8, 0, 24,
    1.96 -        0x00FF0000, 0x0000FF00, 0x000000FF, 0xFF000000
    1.97 -    };
    1.98 -    if (!srcfmt) {
    1.99 -        srcfmt = &default_pixel_format;
   1.100 -    }
   1.101 -    if (!dstfmt) {
   1.102 -        dstfmt = &default_pixel_format;
   1.103 -    }
   1.104 -    const vector unsigned char plus = VECUINT8_LITERAL(0x00, 0x00, 0x00, 0x00,
   1.105 -                                                       0x04, 0x04, 0x04, 0x04,
   1.106 -                                                       0x08, 0x08, 0x08, 0x08,
   1.107 -                                                       0x0C, 0x0C, 0x0C,
   1.108 -                                                       0x0C);
   1.109 -    vector unsigned char vswiz;
   1.110 -    vector unsigned int srcvec;
   1.111 -#define RESHIFT(X) (3 - ((X) >> 3))
   1.112 -    Uint32 rmask = RESHIFT(srcfmt->Rshift) << (dstfmt->Rshift);
   1.113 -    Uint32 gmask = RESHIFT(srcfmt->Gshift) << (dstfmt->Gshift);
   1.114 -    Uint32 bmask = RESHIFT(srcfmt->Bshift) << (dstfmt->Bshift);
   1.115 -    Uint32 amask;
   1.116 -    /* Use zero for alpha if either surface doesn't have alpha */
   1.117 -    if (dstfmt->Amask) {
   1.118 -        amask =
   1.119 -            ((srcfmt->Amask) ? RESHIFT(srcfmt->
   1.120 -                                       Ashift) : 0x10) << (dstfmt->Ashift);
   1.121 -    } else {
   1.122 -        amask =
   1.123 -            0x10101010 & ((dstfmt->Rmask | dstfmt->Gmask | dstfmt->Bmask) ^
   1.124 -                          0xFFFFFFFF);
   1.125 -    }
   1.126 -#undef RESHIFT
   1.127 -    ((unsigned int *) (char *) &srcvec)[0] = (rmask | gmask | bmask | amask);
   1.128 -    vswiz = vec_add(plus, (vector unsigned char) vec_splat(srcvec, 0));
   1.129 -    return (vswiz);
   1.130 -}
   1.131 -
   1.132 -static void Blit_RGB888_RGB565(SDL_BlitInfo * info);
   1.133 -static void
   1.134 -Blit_RGB888_RGB565Altivec(SDL_BlitInfo * info)
   1.135 -{
   1.136 -    int height = info->dst_h;
   1.137 -    Uint8 *src = (Uint8 *) info->src;
   1.138 -    int srcskip = info->src_skip;
   1.139 -    Uint8 *dst = (Uint8 *) info->dst;
   1.140 -    int dstskip = info->dst_skip;
   1.141 -    SDL_PixelFormat *srcfmt = info->src_fmt;
   1.142 -    vector unsigned char valpha = vec_splat_u8(0);
   1.143 -    vector unsigned char vpermute = calc_swizzle32(srcfmt, NULL);
   1.144 -    vector unsigned char vgmerge = VECUINT8_LITERAL(0x00, 0x02, 0x00, 0x06,
   1.145 -                                                    0x00, 0x0a, 0x00, 0x0e,
   1.146 -                                                    0x00, 0x12, 0x00, 0x16,
   1.147 -                                                    0x00, 0x1a, 0x00, 0x1e);
   1.148 -    vector unsigned short v1 = vec_splat_u16(1);
   1.149 -    vector unsigned short v3 = vec_splat_u16(3);
   1.150 -    vector unsigned short v3f =
   1.151 -        VECUINT16_LITERAL(0x003f, 0x003f, 0x003f, 0x003f,
   1.152 -                          0x003f, 0x003f, 0x003f, 0x003f);
   1.153 -    vector unsigned short vfc =
   1.154 -        VECUINT16_LITERAL(0x00fc, 0x00fc, 0x00fc, 0x00fc,
   1.155 -                          0x00fc, 0x00fc, 0x00fc, 0x00fc);
   1.156 -    vector unsigned short vf800 = (vector unsigned short) vec_splat_u8(-7);
   1.157 -    vf800 = vec_sl(vf800, vec_splat_u16(8));
   1.158 -
   1.159 -    while (height--) {
   1.160 -        vector unsigned char valigner;
   1.161 -        vector unsigned char voverflow;
   1.162 -        vector unsigned char vsrc;
   1.163 -
   1.164 -        int width = info->dst_w;
   1.165 -        int extrawidth;
   1.166 -
   1.167 -        /* do scalar until we can align... */
   1.168 -#define ONE_PIXEL_BLEND(condition, widthvar) \
   1.169 -        while (condition) { \
   1.170 -            Uint32 Pixel; \
   1.171 -            unsigned sR, sG, sB, sA; \
   1.172 -            DISEMBLE_RGBA((Uint8 *)src, 4, srcfmt, Pixel, \
   1.173 -                          sR, sG, sB, sA); \
   1.174 -            *(Uint16 *)(dst) = (((sR << 8) & 0x0000F800) | \
   1.175 -                                ((sG << 3) & 0x000007E0) | \
   1.176 -                                ((sB >> 3) & 0x0000001F)); \
   1.177 -            dst += 2; \
   1.178 -            src += 4; \
   1.179 -            widthvar--; \
   1.180 -        }
   1.181 -
   1.182 -        ONE_PIXEL_BLEND(((UNALIGNED_PTR(dst)) && (width)), width);
   1.183 -
   1.184 -        /* After all that work, here's the vector part! */
   1.185 -        extrawidth = (width % 8);       /* trailing unaligned stores */
   1.186 -        width -= extrawidth;
   1.187 -        vsrc = vec_ld(0, src);
   1.188 -        valigner = VEC_ALIGNER(src);
   1.189 -
   1.190 -        while (width) {
   1.191 -            vector unsigned short vpixel, vrpixel, vgpixel, vbpixel;
   1.192 -            vector unsigned int vsrc1, vsrc2;
   1.193 -            vector unsigned char vdst;
   1.194 -
   1.195 -            voverflow = vec_ld(15, src);
   1.196 -            vsrc = vec_perm(vsrc, voverflow, valigner);
   1.197 -            vsrc1 = (vector unsigned int) vec_perm(vsrc, valpha, vpermute);
   1.198 -            src += 16;
   1.199 -            vsrc = voverflow;
   1.200 -            voverflow = vec_ld(15, src);
   1.201 -            vsrc = vec_perm(vsrc, voverflow, valigner);
   1.202 -            vsrc2 = (vector unsigned int) vec_perm(vsrc, valpha, vpermute);
   1.203 -            /* 1555 */
   1.204 -            vpixel = (vector unsigned short) vec_packpx(vsrc1, vsrc2);
   1.205 -            vgpixel = (vector unsigned short) vec_perm(vsrc1, vsrc2, vgmerge);
   1.206 -            vgpixel = vec_and(vgpixel, vfc);
   1.207 -            vgpixel = vec_sl(vgpixel, v3);
   1.208 -            vrpixel = vec_sl(vpixel, v1);
   1.209 -            vrpixel = vec_and(vrpixel, vf800);
   1.210 -            vbpixel = vec_and(vpixel, v3f);
   1.211 -            vdst =
   1.212 -                vec_or((vector unsigned char) vrpixel,
   1.213 -                       (vector unsigned char) vgpixel);
   1.214 -            /* 565 */
   1.215 -            vdst = vec_or(vdst, (vector unsigned char) vbpixel);
   1.216 -            vec_st(vdst, 0, dst);
   1.217 -
   1.218 -            width -= 8;
   1.219 -            src += 16;
   1.220 -            dst += 16;
   1.221 -            vsrc = voverflow;
   1.222 -        }
   1.223 -
   1.224 -        assert(width == 0);
   1.225 -
   1.226 -        /* do scalar until we can align... */
   1.227 -        ONE_PIXEL_BLEND((extrawidth), extrawidth);
   1.228 -#undef ONE_PIXEL_BLEND
   1.229 -
   1.230 -        src += srcskip;         /* move to next row, accounting for pitch. */
   1.231 -        dst += dstskip;
   1.232 -    }
   1.233 -
   1.234 -
   1.235 -}
   1.236 -
   1.237 -static void
   1.238 -Blit_RGB565_32Altivec(SDL_BlitInfo * info)
   1.239 -{
   1.240 -    int height = info->dst_h;
   1.241 -    Uint8 *src = (Uint8 *) info->src;
   1.242 -    int srcskip = info->src_skip;
   1.243 -    Uint8 *dst = (Uint8 *) info->dst;
   1.244 -    int dstskip = info->dst_skip;
   1.245 -    SDL_PixelFormat *srcfmt = info->src_fmt;
   1.246 -    SDL_PixelFormat *dstfmt = info->dst_fmt;
   1.247 -    unsigned alpha;
   1.248 -    vector unsigned char valpha;
   1.249 -    vector unsigned char vpermute;
   1.250 -    vector unsigned short vf800;
   1.251 -    vector unsigned int v8 = vec_splat_u32(8);
   1.252 -    vector unsigned int v16 = vec_add(v8, v8);
   1.253 -    vector unsigned short v2 = vec_splat_u16(2);
   1.254 -    vector unsigned short v3 = vec_splat_u16(3);
   1.255 -    /* 
   1.256 -       0x10 - 0x1f is the alpha
   1.257 -       0x00 - 0x0e evens are the red
   1.258 -       0x01 - 0x0f odds are zero
   1.259 -     */
   1.260 -    vector unsigned char vredalpha1 = VECUINT8_LITERAL(0x10, 0x00, 0x01, 0x01,
   1.261 -                                                       0x10, 0x02, 0x01, 0x01,
   1.262 -                                                       0x10, 0x04, 0x01, 0x01,
   1.263 -                                                       0x10, 0x06, 0x01,
   1.264 -                                                       0x01);
   1.265 -    vector unsigned char vredalpha2 =
   1.266 -        (vector unsigned
   1.267 -         char) (vec_add((vector unsigned int) vredalpha1, vec_sl(v8, v16))
   1.268 -        );
   1.269 -    /*
   1.270 -       0x00 - 0x0f is ARxx ARxx ARxx ARxx
   1.271 -       0x11 - 0x0f odds are blue
   1.272 -     */
   1.273 -    vector unsigned char vblue1 = VECUINT8_LITERAL(0x00, 0x01, 0x02, 0x11,
   1.274 -                                                   0x04, 0x05, 0x06, 0x13,
   1.275 -                                                   0x08, 0x09, 0x0a, 0x15,
   1.276 -                                                   0x0c, 0x0d, 0x0e, 0x17);
   1.277 -    vector unsigned char vblue2 =
   1.278 -        (vector unsigned char) (vec_add((vector unsigned int) vblue1, v8)
   1.279 -        );
   1.280 -    /*
   1.281 -       0x00 - 0x0f is ARxB ARxB ARxB ARxB
   1.282 -       0x10 - 0x0e evens are green
   1.283 -     */
   1.284 -    vector unsigned char vgreen1 = VECUINT8_LITERAL(0x00, 0x01, 0x10, 0x03,
   1.285 -                                                    0x04, 0x05, 0x12, 0x07,
   1.286 -                                                    0x08, 0x09, 0x14, 0x0b,
   1.287 -                                                    0x0c, 0x0d, 0x16, 0x0f);
   1.288 -    vector unsigned char vgreen2 =
   1.289 -        (vector unsigned
   1.290 -         char) (vec_add((vector unsigned int) vgreen1, vec_sl(v8, v8))
   1.291 -        );
   1.292 -
   1.293 -
   1.294 -    assert(srcfmt->BytesPerPixel == 2);
   1.295 -    assert(dstfmt->BytesPerPixel == 4);
   1.296 -
   1.297 -    vf800 = (vector unsigned short) vec_splat_u8(-7);
   1.298 -    vf800 = vec_sl(vf800, vec_splat_u16(8));
   1.299 -
   1.300 -    if (dstfmt->Amask && info->a) {
   1.301 -        ((unsigned char *) &valpha)[0] = alpha = info->a;
   1.302 -        valpha = vec_splat(valpha, 0);
   1.303 -    } else {
   1.304 -        alpha = 0;
   1.305 -        valpha = vec_splat_u8(0);
   1.306 -    }
   1.307 -
   1.308 -    vpermute = calc_swizzle32(NULL, dstfmt);
   1.309 -    while (height--) {
   1.310 -        vector unsigned char valigner;
   1.311 -        vector unsigned char voverflow;
   1.312 -        vector unsigned char vsrc;
   1.313 -
   1.314 -        int width = info->dst_w;
   1.315 -        int extrawidth;
   1.316 -
   1.317 -        /* do scalar until we can align... */
   1.318 -#define ONE_PIXEL_BLEND(condition, widthvar) \
   1.319 -        while (condition) { \
   1.320 -            unsigned sR, sG, sB; \
   1.321 -            unsigned short Pixel = *((unsigned short *)src); \
   1.322 -            sR = (Pixel >> 8) & 0xf8; \
   1.323 -            sG = (Pixel >> 3) & 0xfc; \
   1.324 -            sB = (Pixel << 3) & 0xf8; \
   1.325 -            ASSEMBLE_RGBA(dst, 4, dstfmt, sR, sG, sB, alpha); \
   1.326 -            src += 2; \
   1.327 -            dst += 4; \
   1.328 -            widthvar--; \
   1.329 -        }
   1.330 -        ONE_PIXEL_BLEND(((UNALIGNED_PTR(dst)) && (width)), width);
   1.331 -
   1.332 -        /* After all that work, here's the vector part! */
   1.333 -        extrawidth = (width % 8);       /* trailing unaligned stores */
   1.334 -        width -= extrawidth;
   1.335 -        vsrc = vec_ld(0, src);
   1.336 -        valigner = VEC_ALIGNER(src);
   1.337 -
   1.338 -        while (width) {
   1.339 -            vector unsigned short vR, vG, vB;
   1.340 -            vector unsigned char vdst1, vdst2;
   1.341 -
   1.342 -            voverflow = vec_ld(15, src);
   1.343 -            vsrc = vec_perm(vsrc, voverflow, valigner);
   1.344 -
   1.345 -            vR = vec_and((vector unsigned short) vsrc, vf800);
   1.346 -            vB = vec_sl((vector unsigned short) vsrc, v3);
   1.347 -            vG = vec_sl(vB, v2);
   1.348 -
   1.349 -            vdst1 =
   1.350 -                (vector unsigned char) vec_perm((vector unsigned char) vR,
   1.351 -                                                valpha, vredalpha1);
   1.352 -            vdst1 = vec_perm(vdst1, (vector unsigned char) vB, vblue1);
   1.353 -            vdst1 = vec_perm(vdst1, (vector unsigned char) vG, vgreen1);
   1.354 -            vdst1 = vec_perm(vdst1, valpha, vpermute);
   1.355 -            vec_st(vdst1, 0, dst);
   1.356 -
   1.357 -            vdst2 =
   1.358 -                (vector unsigned char) vec_perm((vector unsigned char) vR,
   1.359 -                                                valpha, vredalpha2);
   1.360 -            vdst2 = vec_perm(vdst2, (vector unsigned char) vB, vblue2);
   1.361 -            vdst2 = vec_perm(vdst2, (vector unsigned char) vG, vgreen2);
   1.362 -            vdst2 = vec_perm(vdst2, valpha, vpermute);
   1.363 -            vec_st(vdst2, 16, dst);
   1.364 -
   1.365 -            width -= 8;
   1.366 -            dst += 32;
   1.367 -            src += 16;
   1.368 -            vsrc = voverflow;
   1.369 -        }
   1.370 -
   1.371 -        assert(width == 0);
   1.372 -
   1.373 -
   1.374 -        /* do scalar until we can align... */
   1.375 -        ONE_PIXEL_BLEND((extrawidth), extrawidth);
   1.376 -#undef ONE_PIXEL_BLEND
   1.377 -
   1.378 -        src += srcskip;         /* move to next row, accounting for pitch. */
   1.379 -        dst += dstskip;
   1.380 -    }
   1.381 -
   1.382 -}
   1.383 -
   1.384 -
   1.385 -static void
   1.386 -Blit_RGB555_32Altivec(SDL_BlitInfo * info)
   1.387 -{
   1.388 -    int height = info->dst_h;
   1.389 -    Uint8 *src = (Uint8 *) info->src;
   1.390 -    int srcskip = info->src_skip;
   1.391 -    Uint8 *dst = (Uint8 *) info->dst;
   1.392 -    int dstskip = info->dst_skip;
   1.393 -    SDL_PixelFormat *srcfmt = info->src_fmt;
   1.394 -    SDL_PixelFormat *dstfmt = info->dst_fmt;
   1.395 -    unsigned alpha;
   1.396 -    vector unsigned char valpha;
   1.397 -    vector unsigned char vpermute;
   1.398 -    vector unsigned short vf800;
   1.399 -    vector unsigned int v8 = vec_splat_u32(8);
   1.400 -    vector unsigned int v16 = vec_add(v8, v8);
   1.401 -    vector unsigned short v1 = vec_splat_u16(1);
   1.402 -    vector unsigned short v3 = vec_splat_u16(3);
   1.403 -    /* 
   1.404 -       0x10 - 0x1f is the alpha
   1.405 -       0x00 - 0x0e evens are the red
   1.406 -       0x01 - 0x0f odds are zero
   1.407 -     */
   1.408 -    vector unsigned char vredalpha1 = VECUINT8_LITERAL(0x10, 0x00, 0x01, 0x01,
   1.409 -                                                       0x10, 0x02, 0x01, 0x01,
   1.410 -                                                       0x10, 0x04, 0x01, 0x01,
   1.411 -                                                       0x10, 0x06, 0x01,
   1.412 -                                                       0x01);
   1.413 -    vector unsigned char vredalpha2 =
   1.414 -        (vector unsigned
   1.415 -         char) (vec_add((vector unsigned int) vredalpha1, vec_sl(v8, v16))
   1.416 -        );
   1.417 -    /*
   1.418 -       0x00 - 0x0f is ARxx ARxx ARxx ARxx
   1.419 -       0x11 - 0x0f odds are blue
   1.420 -     */
   1.421 -    vector unsigned char vblue1 = VECUINT8_LITERAL(0x00, 0x01, 0x02, 0x11,
   1.422 -                                                   0x04, 0x05, 0x06, 0x13,
   1.423 -                                                   0x08, 0x09, 0x0a, 0x15,
   1.424 -                                                   0x0c, 0x0d, 0x0e, 0x17);
   1.425 -    vector unsigned char vblue2 =
   1.426 -        (vector unsigned char) (vec_add((vector unsigned int) vblue1, v8)
   1.427 -        );
   1.428 -    /*
   1.429 -       0x00 - 0x0f is ARxB ARxB ARxB ARxB
   1.430 -       0x10 - 0x0e evens are green
   1.431 -     */
   1.432 -    vector unsigned char vgreen1 = VECUINT8_LITERAL(0x00, 0x01, 0x10, 0x03,
   1.433 -                                                    0x04, 0x05, 0x12, 0x07,
   1.434 -                                                    0x08, 0x09, 0x14, 0x0b,
   1.435 -                                                    0x0c, 0x0d, 0x16, 0x0f);
   1.436 -    vector unsigned char vgreen2 =
   1.437 -        (vector unsigned
   1.438 -         char) (vec_add((vector unsigned int) vgreen1, vec_sl(v8, v8))
   1.439 -        );
   1.440 -
   1.441 -
   1.442 -    assert(srcfmt->BytesPerPixel == 2);
   1.443 -    assert(dstfmt->BytesPerPixel == 4);
   1.444 -
   1.445 -    vf800 = (vector unsigned short) vec_splat_u8(-7);
   1.446 -    vf800 = vec_sl(vf800, vec_splat_u16(8));
   1.447 -
   1.448 -    if (dstfmt->Amask && info->a) {
   1.449 -        ((unsigned char *) &valpha)[0] = alpha = info->a;
   1.450 -        valpha = vec_splat(valpha, 0);
   1.451 -    } else {
   1.452 -        alpha = 0;
   1.453 -        valpha = vec_splat_u8(0);
   1.454 -    }
   1.455 -
   1.456 -    vpermute = calc_swizzle32(NULL, dstfmt);
   1.457 -    while (height--) {
   1.458 -        vector unsigned char valigner;
   1.459 -        vector unsigned char voverflow;
   1.460 -        vector unsigned char vsrc;
   1.461 -
   1.462 -        int width = info->dst_w;
   1.463 -        int extrawidth;
   1.464 -
   1.465 -        /* do scalar until we can align... */
   1.466 -#define ONE_PIXEL_BLEND(condition, widthvar) \
   1.467 -        while (condition) { \
   1.468 -            unsigned sR, sG, sB; \
   1.469 -            unsigned short Pixel = *((unsigned short *)src); \
   1.470 -            sR = (Pixel >> 7) & 0xf8; \
   1.471 -            sG = (Pixel >> 2) & 0xf8; \
   1.472 -            sB = (Pixel << 3) & 0xf8; \
   1.473 -            ASSEMBLE_RGBA(dst, 4, dstfmt, sR, sG, sB, alpha); \
   1.474 -            src += 2; \
   1.475 -            dst += 4; \
   1.476 -            widthvar--; \
   1.477 -        }
   1.478 -        ONE_PIXEL_BLEND(((UNALIGNED_PTR(dst)) && (width)), width);
   1.479 -
   1.480 -        /* After all that work, here's the vector part! */
   1.481 -        extrawidth = (width % 8);       /* trailing unaligned stores */
   1.482 -        width -= extrawidth;
   1.483 -        vsrc = vec_ld(0, src);
   1.484 -        valigner = VEC_ALIGNER(src);
   1.485 -
   1.486 -        while (width) {
   1.487 -            vector unsigned short vR, vG, vB;
   1.488 -            vector unsigned char vdst1, vdst2;
   1.489 -
   1.490 -            voverflow = vec_ld(15, src);
   1.491 -            vsrc = vec_perm(vsrc, voverflow, valigner);
   1.492 -
   1.493 -            vR = vec_and(vec_sl((vector unsigned short) vsrc, v1), vf800);
   1.494 -            vB = vec_sl((vector unsigned short) vsrc, v3);
   1.495 -            vG = vec_sl(vB, v3);
   1.496 -
   1.497 -            vdst1 =
   1.498 -                (vector unsigned char) vec_perm((vector unsigned char) vR,
   1.499 -                                                valpha, vredalpha1);
   1.500 -            vdst1 = vec_perm(vdst1, (vector unsigned char) vB, vblue1);
   1.501 -            vdst1 = vec_perm(vdst1, (vector unsigned char) vG, vgreen1);
   1.502 -            vdst1 = vec_perm(vdst1, valpha, vpermute);
   1.503 -            vec_st(vdst1, 0, dst);
   1.504 -
   1.505 -            vdst2 =
   1.506 -                (vector unsigned char) vec_perm((vector unsigned char) vR,
   1.507 -                                                valpha, vredalpha2);
   1.508 -            vdst2 = vec_perm(vdst2, (vector unsigned char) vB, vblue2);
   1.509 -            vdst2 = vec_perm(vdst2, (vector unsigned char) vG, vgreen2);
   1.510 -            vdst2 = vec_perm(vdst2, valpha, vpermute);
   1.511 -            vec_st(vdst2, 16, dst);
   1.512 -
   1.513 -            width -= 8;
   1.514 -            dst += 32;
   1.515 -            src += 16;
   1.516 -            vsrc = voverflow;
   1.517 -        }
   1.518 -
   1.519 -        assert(width == 0);
   1.520 -
   1.521 -
   1.522 -        /* do scalar until we can align... */
   1.523 -        ONE_PIXEL_BLEND((extrawidth), extrawidth);
   1.524 -#undef ONE_PIXEL_BLEND
   1.525 -
   1.526 -        src += srcskip;         /* move to next row, accounting for pitch. */
   1.527 -        dst += dstskip;
   1.528 -    }
   1.529 -
   1.530 -}
   1.531 -
   1.532 -static void BlitNtoNKey(SDL_BlitInfo * info);
   1.533 -static void BlitNtoNKeyCopyAlpha(SDL_BlitInfo * info);
   1.534 -static void
   1.535 -Blit32to32KeyAltivec(SDL_BlitInfo * info)
   1.536 -{
   1.537 -    int height = info->dst_h;
   1.538 -    Uint32 *srcp = (Uint32 *) info->src;
   1.539 -    int srcskip = info->src_skip / 4;
   1.540 -    Uint32 *dstp = (Uint32 *) info->dst;
   1.541 -    int dstskip = info->dst_skip / 4;
   1.542 -    SDL_PixelFormat *srcfmt = info->src_fmt;
   1.543 -    int srcbpp = srcfmt->BytesPerPixel;
   1.544 -    SDL_PixelFormat *dstfmt = info->dst_fmt;
   1.545 -    int dstbpp = dstfmt->BytesPerPixel;
   1.546 -    int copy_alpha = (srcfmt->Amask && dstfmt->Amask);
   1.547 -    unsigned alpha = dstfmt->Amask ? info->a : 0;
   1.548 -    Uint32 rgbmask = srcfmt->Rmask | srcfmt->Gmask | srcfmt->Bmask;
   1.549 -    Uint32 ckey = info->colorkey;
   1.550 -    vector unsigned int valpha;
   1.551 -    vector unsigned char vpermute;
   1.552 -    vector unsigned char vzero;
   1.553 -    vector unsigned int vckey;
   1.554 -    vector unsigned int vrgbmask;
   1.555 -    vpermute = calc_swizzle32(srcfmt, dstfmt);
   1.556 -    if (info->dst_w < 16) {
   1.557 -        if (copy_alpha) {
   1.558 -            BlitNtoNKeyCopyAlpha(info);
   1.559 -        } else {
   1.560 -            BlitNtoNKey(info);
   1.561 -        }
   1.562 -        return;
   1.563 -    }
   1.564 -    vzero = vec_splat_u8(0);
   1.565 -    if (alpha) {
   1.566 -        ((unsigned char *) &valpha)[0] = (unsigned char) alpha;
   1.567 -        valpha =
   1.568 -            (vector unsigned int) vec_splat((vector unsigned char) valpha, 0);
   1.569 -    } else {
   1.570 -        valpha = (vector unsigned int) vzero;
   1.571 -    }
   1.572 -    ckey &= rgbmask;
   1.573 -    ((unsigned int *) (char *) &vckey)[0] = ckey;
   1.574 -    vckey = vec_splat(vckey, 0);
   1.575 -    ((unsigned int *) (char *) &vrgbmask)[0] = rgbmask;
   1.576 -    vrgbmask = vec_splat(vrgbmask, 0);
   1.577 -
   1.578 -    while (height--) {
   1.579 -#define ONE_PIXEL_BLEND(condition, widthvar) \
   1.580 -        if (copy_alpha) { \
   1.581 -            while (condition) { \
   1.582 -                Uint32 Pixel; \
   1.583 -                unsigned sR, sG, sB, sA; \
   1.584 -                DISEMBLE_RGBA((Uint8 *)srcp, srcbpp, srcfmt, Pixel, \
   1.585 -                          sR, sG, sB, sA); \
   1.586 -                if ( (Pixel & rgbmask) != ckey ) { \
   1.587 -                      ASSEMBLE_RGBA((Uint8 *)dstp, dstbpp, dstfmt, \
   1.588 -                            sR, sG, sB, sA); \
   1.589 -                } \
   1.590 -                dstp = (Uint32 *) (((Uint8 *) dstp) + dstbpp); \
   1.591 -                srcp = (Uint32 *) (((Uint8 *) srcp) + srcbpp); \
   1.592 -                widthvar--; \
   1.593 -            } \
   1.594 -        } else { \
   1.595 -            while (condition) { \
   1.596 -                Uint32 Pixel; \
   1.597 -                unsigned sR, sG, sB; \
   1.598 -                RETRIEVE_RGB_PIXEL((Uint8 *)srcp, srcbpp, Pixel); \
   1.599 -                if ( Pixel != ckey ) { \
   1.600 -                    RGB_FROM_PIXEL(Pixel, srcfmt, sR, sG, sB); \
   1.601 -                    ASSEMBLE_RGBA((Uint8 *)dstp, dstbpp, dstfmt, \
   1.602 -                              sR, sG, sB, alpha); \
   1.603 -                } \
   1.604 -                dstp = (Uint32 *) (((Uint8 *)dstp) + dstbpp); \
   1.605 -                srcp = (Uint32 *) (((Uint8 *)srcp) + srcbpp); \
   1.606 -                widthvar--; \
   1.607 -            } \
   1.608 -        }
   1.609 -        int width = info->dst_w;
   1.610 -        ONE_PIXEL_BLEND((UNALIGNED_PTR(dstp)) && (width), width);
   1.611 -        assert(width > 0);
   1.612 -        if (width > 0) {
   1.613 -            int extrawidth = (width % 4);
   1.614 -            vector unsigned char valigner = VEC_ALIGNER(srcp);
   1.615 -            vector unsigned int vs = vec_ld(0, srcp);
   1.616 -            width -= extrawidth;
   1.617 -            assert(width >= 4);
   1.618 -            while (width) {
   1.619 -                vector unsigned char vsel;
   1.620 -                vector unsigned int vd;
   1.621 -                vector unsigned int voverflow = vec_ld(15, srcp);
   1.622 -                /* load the source vec */
   1.623 -                vs = vec_perm(vs, voverflow, valigner);
   1.624 -                /* vsel is set for items that match the key */
   1.625 -                vsel = (vector unsigned char) vec_and(vs, vrgbmask);
   1.626 -                vsel = (vector unsigned char) vec_cmpeq(vs, vckey);
   1.627 -                /* permute the src vec to the dest format */
   1.628 -                vs = vec_perm(vs, valpha, vpermute);
   1.629 -                /* load the destination vec */
   1.630 -                vd = vec_ld(0, dstp);
   1.631 -                /* select the source and dest into vs */
   1.632 -                vd = (vector unsigned int) vec_sel((vector unsigned char) vs,
   1.633 -                                                   (vector unsigned char) vd,
   1.634 -                                                   vsel);
   1.635 -
   1.636 -                vec_st(vd, 0, dstp);
   1.637 -                srcp += 4;
   1.638 -                width -= 4;
   1.639 -                dstp += 4;
   1.640 -                vs = voverflow;
   1.641 -            }
   1.642 -            ONE_PIXEL_BLEND((extrawidth), extrawidth);
   1.643 -#undef ONE_PIXEL_BLEND
   1.644 -            srcp += srcskip;
   1.645 -            dstp += dstskip;
   1.646 -        }
   1.647 -    }
   1.648 -}
   1.649 -
   1.650 -/* Altivec code to swizzle one 32-bit surface to a different 32-bit format. */
   1.651 -/* Use this on a G5 */
   1.652 -static void
   1.653 -ConvertAltivec32to32_noprefetch(SDL_BlitInfo * info)
   1.654 -{
   1.655 -    int height = info->dst_h;
   1.656 -    Uint32 *src = (Uint32 *) info->src;
   1.657 -    int srcskip = info->src_skip / 4;
   1.658 -    Uint32 *dst = (Uint32 *) info->dst;
   1.659 -    int dstskip = info->dst_skip / 4;
   1.660 -    SDL_PixelFormat *srcfmt = info->src_fmt;
   1.661 -    SDL_PixelFormat *dstfmt = info->dst_fmt;
   1.662 -    vector unsigned int vzero = vec_splat_u32(0);
   1.663 -    vector unsigned char vpermute = calc_swizzle32(srcfmt, dstfmt);
   1.664 -    if (dstfmt->Amask && !srcfmt->Amask) {
   1.665 -        if (info->a) {
   1.666 -            vector unsigned char valpha;
   1.667 -            ((unsigned char *) &valpha)[0] = info->a;
   1.668 -            vzero = (vector unsigned int) vec_splat(valpha, 0);
   1.669 -        }
   1.670 -    }
   1.671 -
   1.672 -    assert(srcfmt->BytesPerPixel == 4);
   1.673 -    assert(dstfmt->BytesPerPixel == 4);
   1.674 -
   1.675 -    while (height--) {
   1.676 -        vector unsigned char valigner;
   1.677 -        vector unsigned int vbits;
   1.678 -        vector unsigned int voverflow;
   1.679 -        Uint32 bits;
   1.680 -        Uint8 r, g, b, a;
   1.681 -
   1.682 -        int width = info->dst_w;
   1.683 -        int extrawidth;
   1.684 -
   1.685 -        /* do scalar until we can align... */
   1.686 -        while ((UNALIGNED_PTR(dst)) && (width)) {
   1.687 -            bits = *(src++);
   1.688 -            RGBA_FROM_8888(bits, srcfmt, r, g, b, a);
   1.689 -            *(dst++) = MAKE8888(dstfmt, r, g, b, a);
   1.690 -            width--;
   1.691 -        }
   1.692 -
   1.693 -        /* After all that work, here's the vector part! */
   1.694 -        extrawidth = (width % 4);
   1.695 -        width -= extrawidth;
   1.696 -        valigner = VEC_ALIGNER(src);
   1.697 -        vbits = vec_ld(0, src);
   1.698 -
   1.699 -        while (width) {
   1.700 -            voverflow = vec_ld(15, src);
   1.701 -            src += 4;
   1.702 -            width -= 4;
   1.703 -            vbits = vec_perm(vbits, voverflow, valigner);       /* src is ready. */
   1.704 -            vbits = vec_perm(vbits, vzero, vpermute);   /* swizzle it. */
   1.705 -            vec_st(vbits, 0, dst);      /* store it back out. */
   1.706 -            dst += 4;
   1.707 -            vbits = voverflow;
   1.708 -        }
   1.709 -
   1.710 -        assert(width == 0);
   1.711 -
   1.712 -        /* cover pixels at the end of the row that didn't fit in 16 bytes. */
   1.713 -        while (extrawidth) {
   1.714 -            bits = *(src++);    /* max 7 pixels, don't bother with prefetch. */
   1.715 -            RGBA_FROM_8888(bits, srcfmt, r, g, b, a);
   1.716 -            *(dst++) = MAKE8888(dstfmt, r, g, b, a);
   1.717 -            extrawidth--;
   1.718 -        }
   1.719 -
   1.720 -        src += srcskip;
   1.721 -        dst += dstskip;
   1.722 -    }
   1.723 -
   1.724 -}
   1.725 -
   1.726 -/* Altivec code to swizzle one 32-bit surface to a different 32-bit format. */
   1.727 -/* Use this on a G4 */
   1.728 -static void
   1.729 -ConvertAltivec32to32_prefetch(SDL_BlitInfo * info)
   1.730 -{
   1.731 -    const int scalar_dst_lead = sizeof(Uint32) * 4;
   1.732 -    const int vector_dst_lead = sizeof(Uint32) * 16;
   1.733 -
   1.734 -    int height = info->dst_h;
   1.735 -    Uint32 *src = (Uint32 *) info->src;
   1.736 -    int srcskip = info->src_skip / 4;
   1.737 -    Uint32 *dst = (Uint32 *) info->dst;
   1.738 -    int dstskip = info->dst_skip / 4;
   1.739 -    SDL_PixelFormat *srcfmt = info->src_fmt;
   1.740 -    SDL_PixelFormat *dstfmt = info->dst_fmt;
   1.741 -    vector unsigned int vzero = vec_splat_u32(0);
   1.742 -    vector unsigned char vpermute = calc_swizzle32(srcfmt, dstfmt);
   1.743 -    if (dstfmt->Amask && !srcfmt->Amask) {
   1.744 -        if (info->a) {
   1.745 -            vector unsigned char valpha;
   1.746 -            ((unsigned char *) &valpha)[0] = info->a;
   1.747 -            vzero = (vector unsigned int) vec_splat(valpha, 0);
   1.748 -        }
   1.749 -    }
   1.750 -
   1.751 -    assert(srcfmt->BytesPerPixel == 4);
   1.752 -    assert(dstfmt->BytesPerPixel == 4);
   1.753 -
   1.754 -    while (height--) {
   1.755 -        vector unsigned char valigner;
   1.756 -        vector unsigned int vbits;
   1.757 -        vector unsigned int voverflow;
   1.758 -        Uint32 bits;
   1.759 -        Uint8 r, g, b, a;
   1.760 -
   1.761 -        int width = info->dst_w;
   1.762 -        int extrawidth;
   1.763 -
   1.764 -        /* do scalar until we can align... */
   1.765 -        while ((UNALIGNED_PTR(dst)) && (width)) {
   1.766 -            vec_dstt(src + scalar_dst_lead, DST_CTRL(2, 32, 1024),
   1.767 -                     DST_CHAN_SRC);
   1.768 -            vec_dstst(dst + scalar_dst_lead, DST_CTRL(2, 32, 1024),
   1.769 -                      DST_CHAN_DEST);
   1.770 -            bits = *(src++);
   1.771 -            RGBA_FROM_8888(bits, srcfmt, r, g, b, a);
   1.772 -            *(dst++) = MAKE8888(dstfmt, r, g, b, a);
   1.773 -            width--;
   1.774 -        }
   1.775 -
   1.776 -        /* After all that work, here's the vector part! */
   1.777 -        extrawidth = (width % 4);
   1.778 -        width -= extrawidth;
   1.779 -        valigner = VEC_ALIGNER(src);
   1.780 -        vbits = vec_ld(0, src);
   1.781 -
   1.782 -        while (width) {
   1.783 -            vec_dstt(src + vector_dst_lead, DST_CTRL(2, 32, 1024),
   1.784 -                     DST_CHAN_SRC);
   1.785 -            vec_dstst(dst + vector_dst_lead, DST_CTRL(2, 32, 1024),
   1.786 -                      DST_CHAN_DEST);
   1.787 -            voverflow = vec_ld(15, src);
   1.788 -            src += 4;
   1.789 -            width -= 4;
   1.790 -            vbits = vec_perm(vbits, voverflow, valigner);       /* src is ready. */
   1.791 -            vbits = vec_perm(vbits, vzero, vpermute);   /* swizzle it. */
   1.792 -            vec_st(vbits, 0, dst);      /* store it back out. */
   1.793 -            dst += 4;
   1.794 -            vbits = voverflow;
   1.795 -        }
   1.796 -
   1.797 -        assert(width == 0);
   1.798 -
   1.799 -        /* cover pixels at the end of the row that didn't fit in 16 bytes. */
   1.800 -        while (extrawidth) {
   1.801 -            bits = *(src++);    /* max 7 pixels, don't bother with prefetch. */
   1.802 -            RGBA_FROM_8888(bits, srcfmt, r, g, b, a);
   1.803 -            *(dst++) = MAKE8888(dstfmt, r, g, b, a);
   1.804 -            extrawidth--;
   1.805 -        }
   1.806 -
   1.807 -        src += srcskip;
   1.808 -        dst += dstskip;
   1.809 -    }
   1.810 -
   1.811 -    vec_dss(DST_CHAN_SRC);
   1.812 -    vec_dss(DST_CHAN_DEST);
   1.813 -}
   1.814 -
   1.815 -static Uint32
   1.816 -GetBlitFeatures(void)
   1.817 -{
   1.818 -    static Uint32 features = 0xffffffff;
   1.819 -    if (features == 0xffffffff) {
   1.820 -        /* Provide an override for testing .. */
   1.821 -        char *override = SDL_getenv("SDL_ALTIVEC_BLIT_FEATURES");
   1.822 -        if (override) {
   1.823 -            features = 0;
   1.824 -            SDL_sscanf(override, "%u", &features);
   1.825 -        } else {
   1.826 -            features = (0
   1.827 -                        /* Feature 1 is has-MMX */
   1.828 -                        | ((SDL_HasMMX())? 1 : 0)
   1.829 -                        /* Feature 2 is has-AltiVec */
   1.830 -                        | ((SDL_HasAltiVec())? 2 : 0)
   1.831 -                        /* Feature 4 is dont-use-prefetch */
   1.832 -                        /* !!!! FIXME: Check for G5 or later, not the cache size! Always prefetch on a G4. */
   1.833 -                        | ((GetL3CacheSize() == 0) ? 4 : 0)
   1.834 -                );
   1.835 -        }
   1.836 -    }
   1.837 -    return features;
   1.838 -}
   1.839 -
   1.840 -#if __MWERKS__
   1.841 -#pragma altivec_model off
   1.842 -#endif
   1.843 -#else
   1.844  /* Feature 1 is has-MMX */
   1.845  #define GetBlitFeatures() ((Uint32)(SDL_HasMMX() ? 1 : 0))
   1.846 -#endif
   1.847  
   1.848  /* This is now endian dependent */
   1.849  #if SDL_BYTEORDER == SDL_LIL_ENDIAN
   1.850 @@ -2346,15 +1508,6 @@
   1.851  };
   1.852  
   1.853  static const struct blit_table normal_blit_2[] = {
   1.854 -#if SDL_ALTIVEC_BLITTERS
   1.855 -    /* has-altivec */
   1.856 -    {0x0000F800, 0x000007E0, 0x0000001F, 4, 0x00000000, 0x00000000,
   1.857 -     0x00000000,
   1.858 -     2, Blit_RGB565_32Altivec, NO_ALPHA | COPY_ALPHA | SET_ALPHA},
   1.859 -    {0x00007C00, 0x000003E0, 0x0000001F, 4, 0x00000000, 0x00000000,
   1.860 -     0x00000000,
   1.861 -     2, Blit_RGB555_32Altivec, NO_ALPHA | COPY_ALPHA | SET_ALPHA},
   1.862 -#endif
   1.863      {0x0000F800, 0x000007E0, 0x0000001F, 4, 0x00FF0000, 0x0000FF00,
   1.864       0x000000FF,
   1.865       0, Blit_RGB565_ARGB8888, SET_ALPHA},
   1.866 @@ -2378,22 +1531,6 @@
   1.867  };
   1.868  
   1.869  static const struct blit_table normal_blit_4[] = {
   1.870 -#if SDL_ALTIVEC_BLITTERS
   1.871 -    /* has-altivec | dont-use-prefetch */
   1.872 -    {0x00000000, 0x00000000, 0x00000000, 4, 0x00000000, 0x00000000,
   1.873 -     0x00000000,
   1.874 -     6, ConvertAltivec32to32_noprefetch,
   1.875 -     NO_ALPHA | COPY_ALPHA | SET_ALPHA},
   1.876 -    /* has-altivec */
   1.877 -    {0x00000000, 0x00000000, 0x00000000, 4, 0x00000000, 0x00000000,
   1.878 -     0x00000000,
   1.879 -     2, ConvertAltivec32to32_prefetch,
   1.880 -     NO_ALPHA | COPY_ALPHA | SET_ALPHA},
   1.881 -    /* has-altivec */
   1.882 -    {0x00000000, 0x00000000, 0x00000000, 2, 0x0000F800, 0x000007E0,
   1.883 -     0x0000001F,
   1.884 -     2, Blit_RGB888_RGB565Altivec, NO_ALPHA},
   1.885 -#endif
   1.886      {0x00FF0000, 0x0000FF00, 0x000000FF, 2, 0x0000F800, 0x000007E0,
   1.887       0x0000001F,
   1.888       0, Blit_RGB888_RGB565, NO_ALPHA},
   1.889 @@ -2491,12 +1628,6 @@
   1.890          else if (dstfmt->BytesPerPixel == 1)
   1.891              return BlitNto1Key;
   1.892          else {
   1.893 -#if SDL_ALTIVEC_BLITTERS
   1.894 -            if ((srcfmt->BytesPerPixel == 4) && (dstfmt->BytesPerPixel == 4)
   1.895 -                && SDL_HasAltiVec()) {
   1.896 -                return Blit32to32KeyAltivec;
   1.897 -            } else
   1.898 -#endif
   1.899              if (srcfmt->Amask && dstfmt->Amask) {
   1.900                  return BlitNtoNKeyCopyAlpha;
   1.901              } else {