From 9403a02481633f473e1e409dc8a8c9a8ebef7721 Mon Sep 17 00:00:00 2001 From: Vicki Pfau Date: Sat, 15 Aug 2020 21:04:32 -0700 Subject: [PATCH] Util: ppc64 byteswap access fixes --- include/mgba-util/common.h | 26 ++++++++++++++++++++------ 1 file changed, 20 insertions(+), 6 deletions(-) diff --git a/include/mgba-util/common.h b/include/mgba-util/common.h index 00193f6ff..49f32fa88 100644 --- a/include/mgba-util/common.h +++ b/include/mgba-util/common.h @@ -129,31 +129,32 @@ typedef intptr_t ssize_t; #define LOAD_32BE(DEST, ADDR, ARR) DEST = *(uint32_t*) ((uintptr_t) (ARR) + (size_t) (ADDR)) #if defined(__PPC__) || defined(__POWERPC__) #define LOAD_32LE(DEST, ADDR, ARR) { \ - uint32_t _addr = (ADDR); \ + off_t _addr = (ADDR); \ const void* _ptr = (ARR); \ __asm__("lwbrx %0, %1, %2" : "=r"(DEST) : "b"(_ptr), "r"(_addr)); \ } #define LOAD_16LE(DEST, ADDR, ARR) { \ - uint32_t _addr = (ADDR); \ + off_t _addr = (ADDR); \ const void* _ptr = (ARR); \ __asm__("lhbrx %0, %1, %2" : "=r"(DEST) : "b"(_ptr), "r"(_addr)); \ } #define STORE_32LE(SRC, ADDR, ARR) { \ - uint32_t _addr = (ADDR); \ + off_t _addr = (ADDR); \ void* _ptr = (ARR); \ __asm__("stwbrx %0, %1, %2" : : "r"(SRC), "b"(_ptr), "r"(_addr) : "memory"); \ } #define STORE_16LE(SRC, ADDR, ARR) { \ - uint32_t _addr = (ADDR); \ + off_t _addr = (ADDR); \ void* _ptr = (ARR); \ __asm__("sthbrx %0, %1, %2" : : "r"(SRC), "b"(_ptr), "r"(_addr) : "memory"); \ } +#ifndef _ARCH_PWR7 #define LOAD_64LE(DEST, ADDR, ARR) { \ - uint32_t _addr = (ADDR); \ + off_t _addr = (ADDR); \ union { \ struct { \ uint32_t hi; \ @@ -170,7 +171,7 @@ typedef intptr_t ssize_t; } #define STORE_64LE(SRC, ADDR, ARR) { \ - uint32_t _addr = (ADDR); \ + off_t _addr = (ADDR); \ union { \ struct { \ uint32_t hi; \ @@ -184,6 +185,19 @@ typedef intptr_t ssize_t; "stwbrx %1, %2, %4 \n" \ : : "r"(bswap.hi), "r"(bswap.lo), "b"(_ptr), "r"(_addr), "r"(_addr + 4) : "memory"); \ } +#else +#define LOAD_64LE(DEST, ADDR, ARR) { \ + off_t _addr = (ADDR); \ + const void* _ptr = (ARR); \ + __asm__("ldbrx %0, %1, %2" : "=r"(DEST) : "b"(_ptr), "r"(_addr)); \ +} + +#define STORE_64LE(SRC, ADDR, ARR) { \ + off_t _addr = (ADDR); \ + void* _ptr = (ARR); \ + __asm__("stdbrx %0, %1, %2" : : "r"(SRC), "b"(_ptr), "r"(_addr) : "memory"); \ +} +#endif #elif defined(__llvm__) || (__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 8) #define LOAD_64LE(DEST, ADDR, ARR) DEST = __builtin_bswap64(((uint64_t*) ARR)[(ADDR) >> 3])