Math: Fix [l/t]zcnt intrinsics on GCC

X64Context: Surround with architecture ifdef
This commit is contained in:
Dr. Chat 2017-05-11 10:32:13 -05:00
parent 5fde9fa720
commit 254fd3631f
2 changed files with 13 additions and 8 deletions

View File

@ -151,12 +151,12 @@ inline uint8_t tzcnt(uint64_t v) {
return static_cast<uint8_t>(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<uint8_t>(__builtin_clzs(v) - 8);
return v == 0 ? 8 : static_cast<uint8_t>(__builtin_clz(v) - 24);
}
inline uint8_t lzcnt(uint16_t v) {
return v == 0 ? 16 : static_cast<uint8_t>(__builtin_clzs(v));
return v == 0 ? 16 : static_cast<uint8_t>(__builtin_clz(v) - 16);
}
inline uint8_t lzcnt(uint32_t v) {
return v == 0 ? 32 : static_cast<uint8_t>(__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<uint8_t>(__builtin_ctzs(v) - 8) ^ 0x7;
return v == 0 ? 8 : static_cast<uint8_t>(__builtin_ctz(v));
}
inline uint8_t tzcnt(uint16_t v) {
return v == 0 ? 16 : static_cast<uint8_t>(__builtin_ctzs(v)) ^ 0xF;
return v == 0 ? 16 : static_cast<uint8_t>(__builtin_ctz(v));
}
inline uint8_t tzcnt(uint32_t v) {
return v == 0 ? 32 : static_cast<uint8_t>(__builtin_ctz(v)) ^ 0x1F;
return v == 0 ? 32 : static_cast<uint8_t>(__builtin_ctz(v));
}
inline uint8_t tzcnt(uint64_t v) {
return v == 0 ? 64 : static_cast<uint8_t>(__builtin_ctzll(v)) ^ 0x3F;
return v == 0 ? 64 : static_cast<uint8_t>(__builtin_ctzll(v));
}
#endif // XE_PLATFORM_WIN32
#endif
inline uint8_t lzcnt(int8_t v) { return lzcnt(static_cast<uint8_t>(v)); }
inline uint8_t lzcnt(int16_t v) { return lzcnt(static_cast<uint16_t>(v)); }
inline uint8_t lzcnt(int32_t v) { return lzcnt(static_cast<uint32_t>(v)); }

View File

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