From 254fd3631f4214109e2c0c27a1a43760cc8ff81a Mon Sep 17 00:00:00 2001 From: "Dr. Chat" Date: Thu, 11 May 2017 10:32:13 -0500 Subject: [PATCH] Math: Fix [l/t]zcnt intrinsics on GCC X64Context: Surround with architecture ifdef --- src/xenia/base/math.h | 16 ++++++++-------- src/xenia/base/x64_context.cc | 5 +++++ 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/src/xenia/base/math.h b/src/xenia/base/math.h index aa969768f..539a98b3c 100644 --- a/src/xenia/base/math.h +++ b/src/xenia/base/math.h @@ -151,12 +151,12 @@ inline uint8_t tzcnt(uint64_t v) { return static_cast(is_nonzero ? int8_t(index) ^ 0x3F : 64); } -#else +#else // XE_PLATFORM_WIN32 inline uint8_t lzcnt(uint8_t v) { - return v == 0 ? 8 : static_cast(__builtin_clzs(v) - 8); + return v == 0 ? 8 : static_cast(__builtin_clz(v) - 24); } inline uint8_t lzcnt(uint16_t v) { - return v == 0 ? 16 : static_cast(__builtin_clzs(v)); + return v == 0 ? 16 : static_cast(__builtin_clz(v) - 16); } inline uint8_t lzcnt(uint32_t v) { return v == 0 ? 32 : static_cast(__builtin_clz(v)); @@ -166,18 +166,18 @@ inline uint8_t lzcnt(uint64_t v) { } inline uint8_t tzcnt(uint8_t v) { - return v == 0 ? 8 : static_cast(__builtin_ctzs(v) - 8) ^ 0x7; + return v == 0 ? 8 : static_cast(__builtin_ctz(v)); } inline uint8_t tzcnt(uint16_t v) { - return v == 0 ? 16 : static_cast(__builtin_ctzs(v)) ^ 0xF; + return v == 0 ? 16 : static_cast(__builtin_ctz(v)); } inline uint8_t tzcnt(uint32_t v) { - return v == 0 ? 32 : static_cast(__builtin_ctz(v)) ^ 0x1F; + return v == 0 ? 32 : static_cast(__builtin_ctz(v)); } inline uint8_t tzcnt(uint64_t v) { - return v == 0 ? 64 : static_cast(__builtin_ctzll(v)) ^ 0x3F; + return v == 0 ? 64 : static_cast(__builtin_ctzll(v)); } -#endif // XE_PLATFORM_WIN32 +#endif inline uint8_t lzcnt(int8_t v) { return lzcnt(static_cast(v)); } inline uint8_t lzcnt(int16_t v) { return lzcnt(static_cast(v)); } inline uint8_t lzcnt(int32_t v) { return lzcnt(static_cast(v)); } diff --git a/src/xenia/base/x64_context.cc b/src/xenia/base/x64_context.cc index 77f595461..fc6027aeb 100644 --- a/src/xenia/base/x64_context.cc +++ b/src/xenia/base/x64_context.cc @@ -10,10 +10,13 @@ #include "xenia/base/x64_context.h" #include "xenia/base/assert.h" +#include "xenia/base/platform.h" #include "xenia/base/string_util.h" namespace xe { +#if XE_ARCH_AMD64 + // NOTE: this order matches 1:1 with the X64Register enum. static const char* kRegisterNames[] = { "rip", "eflags", "rax", "rcx", "rdx", "rbx", "rsp", @@ -59,4 +62,6 @@ void X64Context::SetValueFromString(X64Register reg, std::string value, assert_always(false); } +#endif // XE_ARCH_AMD64 + } // namespace xe