summaryrefslogtreecommitdiff
path: root/src/support
diff options
context:
space:
mode:
authorMax Graey <maxgraey@gmail.com>2020-10-02 09:12:36 +0300
committerGitHub <noreply@github.com>2020-10-01 23:12:36 -0700
commit42aec827c2233eb4adbb56c6d1b23d70399bfac1 (patch)
tree0e580f9f87b43cb8129ee162bd6015bab3f73e58 /src/support
parent2959218552a202b2b1d983ffcff68b015b9a94bd (diff)
downloadbinaryen-42aec827c2233eb4adbb56c6d1b23d70399bfac1.tar.gz
binaryen-42aec827c2233eb4adbb56c6d1b23d70399bfac1.tar.bz2
binaryen-42aec827c2233eb4adbb56c6d1b23d70399bfac1.zip
Simplify some numeric code (#3186)
Diffstat (limited to 'src/support')
-rw-r--r--src/support/bits.cpp18
-rw-r--r--src/support/json.h2
2 files changed, 4 insertions, 16 deletions
diff --git a/src/support/bits.cpp b/src/support/bits.cpp
index 7e22466d8..03fb66252 100644
--- a/src/support/bits.cpp
+++ b/src/support/bits.cpp
@@ -158,22 +158,10 @@ int ceilLog2(uint32_t v) { return 32 - countLeadingZeroes(v - 1); }
int ceilLog2(uint64_t v) { return 64 - countLeadingZeroes(v - 1); }
uint32_t log2(uint32_t v) {
- switch (v) {
- default:
- WASM_UNREACHABLE("invalid value");
- case 1:
- return 0;
- case 2:
- return 1;
- case 4:
- return 2;
- case 8:
- return 3;
- case 16:
- return 4;
- case 32:
- return 5;
+ if (!isPowerOf2(v)) {
+ WASM_UNREACHABLE("value should be a power of two");
}
+ return 31 - countLeadingZeroes(v);
}
uint32_t pow2(uint32_t v) { return 1 << v; }
diff --git a/src/support/json.h b/src/support/json.h
index d31fcf59b..be4a6c250 100644
--- a/src/support/json.h
+++ b/src/support/json.h
@@ -193,7 +193,7 @@ struct Value {
}
int32_t getInteger() { // convenience function to get a known integer
- assert(fmod(getNumber(), 1) == 0);
+ assert(wasm::isInteger(getNumber()));
int32_t ret = getNumber();
assert(double(ret) == getNumber()); // no loss in conversion
return ret;