SDL_blit_N.c: Move ppc64le swizzle outside of loop

An in-place swizzle mutation was erroneously inside of a loop, which
caused each consecutive 4-pixel vector to alternate between correct and
incorrect endianness.

The bug was introduced in 715e070d29.

Thanks to RobbieAB for reporting the bug.

Fixes https://github.com/libsdl-org/SDL/issues/3428
main
Jeremy Rand 2023-05-06 03:24:02 +00:00 committed by Ryan C. Gordon
parent 26903f237f
commit 9142292f4a
1 changed files with 15 additions and 12 deletions

View File

@ -618,6 +618,11 @@ static void Blit32to32KeyAltivec(SDL_BlitInfo *info)
((unsigned int *)(char *)&vrgbmask)[0] = rgbmask;
vrgbmask = vec_splat(vrgbmask, 0);
#if defined(__powerpc__) && (SDL_BYTEORDER == SDL_LIL_ENDIAN)
/* reorder bytes for PowerPC little endian */
vpermute = reorder_ppc64le_vec(vpermute);
#endif
while (height--) {
#define ONE_PIXEL_BLEND(condition, widthvar) \
if (copy_alpha) { \
@ -667,10 +672,6 @@ static void Blit32to32KeyAltivec(SDL_BlitInfo *info)
/* vsel is set for items that match the key */
vsel = (vector unsigned char)vec_and(vs, vrgbmask);
vsel = (vector unsigned char)vec_cmpeq(vs, vckey);
#if defined(__powerpc__) && (SDL_BYTEORDER == SDL_LIL_ENDIAN)
/* reorder bytes for PowerPC little endian */
vpermute = reorder_ppc64le_vec(vpermute);
#endif
/* permute the src vec to the dest format */
vs = vec_perm(vs, valpha, vpermute);
/* load the destination vec */
@ -718,6 +719,11 @@ static void ConvertAltivec32to32_noprefetch(SDL_BlitInfo *info)
SDL_assert(srcfmt->BytesPerPixel == 4);
SDL_assert(dstfmt->BytesPerPixel == 4);
#if defined(__powerpc__) && (SDL_BYTEORDER == SDL_LIL_ENDIAN)
/* reorder bytes for PowerPC little endian */
vpermute = reorder_ppc64le_vec(vpermute);
#endif
while (height--) {
vector unsigned char valigner;
vector unsigned int vbits;
@ -749,10 +755,6 @@ static void ConvertAltivec32to32_noprefetch(SDL_BlitInfo *info)
src += 4;
width -= 4;
vbits = vec_perm(vbits, voverflow, valigner); /* src is ready. */
#if defined(__powerpc__) && (SDL_BYTEORDER == SDL_LIL_ENDIAN)
/* reorder bytes for PowerPC little endian */
vpermute = reorder_ppc64le_vec(vpermute);
#endif
vbits = vec_perm(vbits, vzero, vpermute); /* swizzle it. */
vec_st(vbits, 0, dst); /* store it back out. */
dst += 4;
@ -803,6 +805,11 @@ static void ConvertAltivec32to32_prefetch(SDL_BlitInfo *info)
SDL_assert(srcfmt->BytesPerPixel == 4);
SDL_assert(dstfmt->BytesPerPixel == 4);
#if defined(__powerpc__) && (SDL_BYTEORDER == SDL_LIL_ENDIAN)
/* reorder bytes for PowerPC little endian */
vpermute = reorder_ppc64le_vec(vpermute);
#endif
while (height--) {
vector unsigned char valigner;
vector unsigned int vbits;
@ -842,10 +849,6 @@ static void ConvertAltivec32to32_prefetch(SDL_BlitInfo *info)
src += 4;
width -= 4;
vbits = vec_perm(vbits, voverflow, valigner); /* src is ready. */
#if defined(__powerpc__) && (SDL_BYTEORDER == SDL_LIL_ENDIAN)
/* reorder bytes for PowerPC little endian */
vpermute = reorder_ppc64le_vec(vpermute);
#endif
vbits = vec_perm(vbits, vzero, vpermute); /* swizzle it. */
vec_st(vbits, 0, dst); /* store it back out. */
dst += 4;