diff options
author | Alon Zakai <alonzakai@gmail.com> | 2016-03-16 18:01:39 -0700 |
---|---|---|
committer | Alon Zakai <alonzakai@gmail.com> | 2016-03-16 18:01:39 -0700 |
commit | a3312f5f2390bf3fe515c99d29d22dff201eeaf9 (patch) | |
tree | d3707a6dce139b0ebd78dc8ff2c5b6e470b589b0 /src/support/bits.cpp | |
parent | 2e2cbb4e5349fe20209a9e8f4ca740eea6fb9f6f (diff) | |
parent | b25d38b20934cd22955fd86438703139659a3360 (diff) | |
download | binaryen-a3312f5f2390bf3fe515c99d29d22dff201eeaf9.tar.gz binaryen-a3312f5f2390bf3fe515c99d29d22dff201eeaf9.tar.bz2 binaryen-a3312f5f2390bf3fe515c99d29d22dff201eeaf9.zip |
Merge pull request #254 from WebAssembly/spec-binary
More spec binary updates
Diffstat (limited to 'src/support/bits.cpp')
-rw-r--r-- | src/support/bits.cpp | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/src/support/bits.cpp b/src/support/bits.cpp index c1de4da8b..3d03b100c 100644 --- a/src/support/bits.cpp +++ b/src/support/bits.cpp @@ -15,6 +15,7 @@ */ #define wasm_support_bits_definitions +#include "../compiler-support.h" #include "support/bits.h" namespace wasm { @@ -99,4 +100,28 @@ int CountLeadingZeroes<uint64_t>(uint64_t v) { : 32 + CountLeadingZeroes((uint32_t)v); } +uint32_t Log2(uint32_t v) { + switch (v) { + default: WASM_UNREACHABLE(); + case 1: return 0; + case 2: return 1; + case 4: return 2; + case 8: return 3; + case 16: return 4; + case 32: return 5; + } +} + +uint32_t Pow2(uint32_t v) { + switch (v) { + default: WASM_UNREACHABLE(); + case 0: return 1; + case 1: return 2; + case 2: return 4; + case 3: return 8; + case 4: return 16; + case 5: return 32; + } +} + } // namespace wasm |