From: Paul Cercueil Date: Thu, 26 May 2022 13:07:41 +0000 (+0100) Subject: misc: Use GCC builtins for byte-swap operations X-Git-Tag: r24l~454^2~3 X-Git-Url: https://notaz.gp2x.de/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=0a2601833173a2516afb4d87f1157b59e55e96f1;p=pcsx_rearmed.git misc: Use GCC builtins for byte-swap operations Instead of using custom code to byte-swap values, use the built-in function provided by GCC. Signed-off-by: Paul Cercueil --- diff --git a/libpcsxcore/misc.c b/libpcsxcore/misc.c index 85402fc2..e3d227ab 100644 --- a/libpcsxcore/misc.c +++ b/libpcsxcore/misc.c @@ -58,14 +58,7 @@ struct iso_directory_record { void mmssdd( char *b, char *p ) { int m, s, d; -#if defined(__arm__) - unsigned char *u = (void *)b; - int block = (u[3] << 24) | (u[2] << 16) | (u[1] << 8) | u[0]; -#elif __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__ - int block = (b[0] & 0xff) | ((b[1] & 0xff) << 8) | ((b[2] & 0xff) << 16) | (b[3] << 24); -#else - int block = *((int*)b); -#endif + int block = SWAP32(*((uint32_t*) b)); block += 150; m = block / 4500; // minutes diff --git a/libpcsxcore/psxmem.h b/libpcsxcore/psxmem.h index a7c6dd16..c51aebe0 100644 --- a/libpcsxcore/psxmem.h +++ b/libpcsxcore/psxmem.h @@ -28,11 +28,8 @@ extern "C" { #if __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__ -#define _SWAP16(b) ((((unsigned char *)&(b))[0] & 0xff) | (((unsigned char *)&(b))[1] & 0xff) << 8) -#define _SWAP32(b) ((((unsigned char *)&(b))[0] & 0xff) | ((((unsigned char *)&(b))[1] & 0xff) << 8) | ((((unsigned char *)&(b))[2] & 0xff) << 16) | (((unsigned char *)&(b))[3] << 24)) - -#define SWAP16(v) ((((v) & 0xff00) >> 8) +(((v) & 0xff) << 8)) -#define SWAP32(v) ((((v) & 0xff000000ul) >> 24) + (((v) & 0xff0000ul) >> 8) + (((v) & 0xff00ul)<<8) +(((v) & 0xfful) << 24)) +#define SWAP16(v) __builtin_bswap16(v) +#define SWAP32(v) __builtin_bswap32(v) #define SWAPu32(v) SWAP32((u32)(v)) #define SWAPs32(v) SWAP32((s32)(v))