Skip to content

Commit

Permalink
Math: Fix [l/t]zcnt intrinsics on GCC
Browse files Browse the repository at this point in the history
X64Context: Surround with architecture ifdef
  • Loading branch information
DrChat committed May 11, 2017
1 parent 5fde9fa commit 254fd36
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 8 deletions.
16 changes: 8 additions & 8 deletions src/xenia/base/math.h
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand All @@ -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)); }
Expand Down
5 changes: 5 additions & 0 deletions src/xenia/base/x64_context.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -59,4 +62,6 @@ void X64Context::SetValueFromString(X64Register reg, std::string value,
assert_always(false);
}

#endif // XE_ARCH_AMD64

} // namespace xe

0 comments on commit 254fd36

Please sign in to comment.