From 3f098657707e3bef37b62dcd8c9b0cc08135af57 Mon Sep 17 00:00:00 2001 From: icculus Date: Sat, 9 Feb 2008 18:39:58 -0500 Subject: [PATCH] [svn] Implemented byteswapping. --HG-- branch : trunk --- parse.c | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/parse.c b/parse.c index f93035e0..3114cd21 100644 --- a/parse.c +++ b/parse.c @@ -11,11 +11,26 @@ static int FAIL(const char *reason) } // FAIL -#define SWAP32(x) (x) typedef unsigned int uint; // this is a printf() helper. don't use for code. typedef uint8_t uint8; typedef uint32_t uint32; +#if ((defined __GNUC__) && (defined __POWERPC__)) + static inline uint32 SWAP32(uint32 x) + { + __asm__ __volatile__("lwbrx %0,0,%1" : "=r" (x) : "r" (&x)); + return x; + } // SWAP32 +#elif defined(__POWERPC__) + static inline uint32 SWAP32(uint32 x) + { + return ( (((x) >> 24) & 0x000000FF) | (((x) >> 8) & 0x0000FF00) | + (((x) << 8) & 0x00FF0000) | (((x) << 24) & 0xFF000000) ); + } // SWAP32 +#else +# define SWAP32(x) (x) +#endif + typedef int (*parse_instruction_function)(const uint32 *argtokens); static int parse_NOP(const uint32 *argtokens)