diff options
author | Alon Zakai <alonzakai@gmail.com> | 2015-12-23 15:58:19 -0800 |
---|---|---|
committer | Alon Zakai <alonzakai@gmail.com> | 2015-12-23 15:58:19 -0800 |
commit | cef89df8e5ad80a0fb881af31804eef854909552 (patch) | |
tree | 56fc76af34903fea89cbd85397b0fc257ff06669 /src/wasm-interpreter.h | |
parent | b055995ff2cb99d10d5be3ffd9ed3757b499ede9 (diff) | |
parent | a40e154b2cfc9eaf0b55c1a478f848e4f851dbd0 (diff) | |
download | binaryen-cef89df8e5ad80a0fb881af31804eef854909552.tar.gz binaryen-cef89df8e5ad80a0fb881af31804eef854909552.tar.bz2 binaryen-cef89df8e5ad80a0fb881af31804eef854909552.zip |
Merge pull request #41 from WebAssembly/use-bits
Use the new bit functions
Diffstat (limited to 'src/wasm-interpreter.h')
-rw-r--r-- | src/wasm-interpreter.h | 50 |
1 files changed, 9 insertions, 41 deletions
diff --git a/src/wasm-interpreter.h b/src/wasm-interpreter.h index 0de094ca2..0d32dcf52 100644 --- a/src/wasm-interpreter.h +++ b/src/wasm-interpreter.h @@ -25,6 +25,7 @@ #include <limits.h> +#include "bits.h" #include "wasm.h" namespace wasm { @@ -35,39 +36,6 @@ using namespace cashew; IString WASM("wasm"); - -#ifdef WIN32 -#include <intrin.h> - -int32_t safe_clz(int32_t v) { - unsigned long result; - return _BitScanReverse(&result,v) ? result : 32; -} - -int32_t safe_ctz(int32_t v) { - unsigned long result; - return _BitScanForward(&result,v) ? result : 32; -} - -int32_t platform_popcount(int32_t v) { - return __popcnt(v); -} -#else -int32_t safe_clz(int32_t v) { - if (v == 0) return 32; - return __builtin_clz(v); -} - -int32_t safe_ctz(int32_t v) { - if (v == 0) return 32; - return __builtin_ctz(v); -} - -int32_t platform_popcount(int32_t v) { - return __builtin_popcount(v); -} -#endif - enum { pageSize = 64*1024, maxCallDepth = 250 @@ -392,12 +360,12 @@ private: if (value.type == i32) { int32_t v = value.geti32(); switch (curr->op) { - case Clz: return Literal(safe_clz(v)); + case Clz: return Literal(CountLeadingZeroes((uint32_t)v)); case Ctz: { if (v == 0) return Literal(32); - return Literal((int32_t)safe_ctz(v)); + return Literal(CountTrailingZeroes((uint32_t)v)); } - case Popcnt: return Literal((int32_t)platform_popcount(v)); + case Popcnt: return Literal(PopCount((uint32_t)v)); case ReinterpretInt: { float v = value.reinterpretf32(); if (isnan(v)) { @@ -418,15 +386,15 @@ private: switch (curr->op) { case Clz: { if (v == 0) return Literal((int64_t)64); - if (high == 0) return Literal(32+(int64_t)safe_clz(low)); - return Literal((int64_t)safe_clz(high)); + if (high == 0) return Literal(32+(int64_t)CountLeadingZeroes((uint32_t)low)); + return Literal((int64_t)CountLeadingZeroes((uint32_t)high)); } case Ctz: { if (v == 0) return Literal((int64_t)64); - if (low == 0) return Literal(32+(int64_t)safe_ctz(high)); - return Literal((int64_t)safe_ctz(low)); + if (low == 0) return Literal(32+(int64_t)CountTrailingZeroes((uint32_t)high)); + return Literal((int64_t)CountTrailingZeroes((uint32_t)low)); } - case Popcnt: return Literal(int64_t(platform_popcount(low) + platform_popcount(high))); + case Popcnt: return Literal(PopCount((uint64_t)v)); case WrapInt64: return Literal(int32_t(value.geti64())); case ReinterpretInt: { return Literal(value.reinterpretf64()); |