all repos — mgba @ 9403a02481633f473e1e409dc8a8c9a8ebef7721

mGBA Game Boy Advance Emulator

Util: ppc64 byteswap access fixes
Vicki Pfau vi@endrift.com
Sat, 15 Aug 2020 21:04:32 -0700
commit

9403a02481633f473e1e409dc8a8c9a8ebef7721

parent

48bab99ad57d5ba53673359a6a57fb493c9ce7fc

1 files changed, 20 insertions(+), 6 deletions(-)

jump to
M include/mgba-util/common.hinclude/mgba-util/common.h

@@ -129,31 +129,32 @@ #if defined __BIG_ENDIAN__

#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 @@ DEST = bswap.b64; \

} #define STORE_64LE(SRC, ADDR, ARR) { \ - uint32_t _addr = (ADDR); \ + off_t _addr = (ADDR); \ union { \ struct { \ uint32_t hi; \

@@ -184,6 +185,19 @@ "stwbrx %0, %2, %3 \n" \

"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])