Util: ppc64 byteswap access fixes

This commit is contained in:
Vicki Pfau 2020-08-15 21:04:32 -07:00
parent 48bab99ad5
commit 9403a02481
1 changed files with 20 additions and 6 deletions

View File

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