From 7f6a4107708a1a68f787929198a4fd5f2a258eae Mon Sep 17 00:00:00 2001 From: Nekotekina Date: Wed, 27 Feb 2019 23:10:40 +0300 Subject: [PATCH] Add dummy __has_builtin macro, use rotate builtins if possible --- Utilities/asm.h | 32 ++++++++++++++++++++++++++++++++ Utilities/types.h | 4 ++++ rpcs3/Emu/Cell/PPUThread.cpp | 11 ----------- 3 files changed, 36 insertions(+), 11 deletions(-) diff --git a/Utilities/asm.h b/Utilities/asm.h index 61999060ba..564fa6de99 100644 --- a/Utilities/asm.h +++ b/Utilities/asm.h @@ -71,58 +71,90 @@ namespace utils inline u8 rol8(u8 x, u8 n) { +#if __has_builtin(__builtin_rotateleft8) + return __builtin_rotateleft8(x, n); +#else u8 result = x; __asm__("rolb %[n], %[result]" : [result] "+g"(result) : [n] "c"(n)); return result; +#endif } inline u8 ror8(u8 x, u8 n) { +#if __has_builtin(__builtin_rotateright8) + return __builtin_rotateright8(x, n); +#else u8 result = x; __asm__("rorb %[n], %[result]" : [result] "+g"(result) : [n] "c"(n)); return result; +#endif } inline u16 rol16(u16 x, u16 n) { +#if __has_builtin(__builtin_rotateleft16) + return __builtin_rotateleft16(x, n); +#else u16 result = x; __asm__("rolw %b[n], %[result]" : [result] "+g"(result) : [n] "c"(n)); return result; +#endif } inline u16 ror16(u16 x, u16 n) { +#if __has_builtin(__builtin_rotateright16) + return __builtin_rotateright16(x, n); +#else u16 result = x; __asm__("rorw %b[n], %[result]" : [result] "+g"(result) : [n] "c"(n)); return result; +#endif } inline u32 rol32(u32 x, u32 n) { +#if __has_builtin(__builtin_rotateleft32) + return __builtin_rotateleft32(x, n); +#else u32 result = x; __asm__("roll %b[n], %[result]" : [result] "+g"(result) : [n] "c"(n)); return result; +#endif } inline u32 ror32(u32 x, u32 n) { +#if __has_builtin(__builtin_rotateright32) + return __builtin_rotateright32(x, n); +#else u32 result = x; __asm__("rorl %b[n], %[result]" : [result] "+g"(result) : [n] "c"(n)); return result; +#endif } inline u64 rol64(u64 x, u64 n) { +#if __has_builtin(__builtin_rotateleft64) + return __builtin_rotateleft64(x, n); +#else u64 result = x; __asm__("rolq %b[n], %[result]" : [result] "+g"(result) : [n] "c"(n)); return result; +#endif } inline u64 ror64(u64 x, u64 n) { +#if __has_builtin(__builtin_rotateright64) + return __builtin_rotateright64(x, n); +#else u64 result = x; __asm__("rorq %b[n], %[result]" : [result] "+g"(result) : [n] "c"(n)); return result; +#endif } inline u64 umulh64(u64 a, u64 b) diff --git a/Utilities/types.h b/Utilities/types.h index d40ee68fb4..5f31d636eb 100644 --- a/Utilities/types.h +++ b/Utilities/types.h @@ -20,6 +20,10 @@ #define IS_LE_MACHINE 1 #define IS_BE_MACHINE 0 +#ifndef __has_builtin + #define __has_builtin(x) 0 +#endif + #ifdef _MSC_VER #define ASSUME(...) __assume(__VA_ARGS__) // MSVC __assume ignores side-effects diff --git a/rpcs3/Emu/Cell/PPUThread.cpp b/rpcs3/Emu/Cell/PPUThread.cpp index 843f819e01..9bdd987f5c 100644 --- a/rpcs3/Emu/Cell/PPUThread.cpp +++ b/rpcs3/Emu/Cell/PPUThread.cpp @@ -1205,17 +1205,6 @@ extern bool ppu_stdcx(ppu_thread& ppu, u32 addr, u64 reg_value) return result; } -static bool adde_carry(u64 a, u64 b, bool c) -{ -#ifdef _MSC_VER - return _addcarry_u64(c, a, b, nullptr) != 0; -#else - bool result; - __asm__("addb $0xff, %[c] \n adcq %[a], %[b] \n setb %[result]" : [a] "+&r" (a), [b] "+&r" (b), [c] "+&r" (c), [result] "=r" (result)); - return result; -#endif -} - extern void ppu_initialize() { const auto _main = fxm::get();