summaryrefslogtreecommitdiff
path: root/src/support/bits.h
diff options
context:
space:
mode:
authorMax Graey <maxgraey@gmail.com>2020-09-17 23:05:55 +0300
committerGitHub <noreply@github.com>2020-09-17 13:05:55 -0700
commit2d47c0b8ae7b72e710b982abce83429c50c6de30 (patch)
tree45eb34e10b508f6f5d1585b53345776cdde26a07 /src/support/bits.h
parent6116553a91b5da4fd877480bb27fc88b264b737f (diff)
downloadbinaryen-2d47c0b8ae7b72e710b982abce83429c50c6de30.tar.gz
binaryen-2d47c0b8ae7b72e710b982abce83429c50c6de30.tar.bz2
binaryen-2d47c0b8ae7b72e710b982abce83429c50c6de30.zip
Implement more cases for getMaxBits (#2879)
- Complete 64-bit cases in range `AddInt64` ... `ShrSInt64` - `ExtendSInt32` and `ExtendUInt32` for unary cases - For binary cases - `AddInt32` / `AddInt64` - `MulInt32` / `MulInt64` - `RemUInt32` / `RemUInt64` - `RemSInt32` / `RemSInt64` - `DivUInt32` / `DivUInt64` - `DivSInt32` / `DivSInt64` - and more Also more fast paths for some getMaxBits calculations
Diffstat (limited to 'src/support/bits.h')
-rw-r--r--src/support/bits.h6
1 files changed, 6 insertions, 0 deletions
diff --git a/src/support/bits.h b/src/support/bits.h
index bd91fdec6..a927a2832 100644
--- a/src/support/bits.h
+++ b/src/support/bits.h
@@ -40,6 +40,7 @@ template<typename T> int PopCount(T);
template<typename T> uint32_t BitReverse(T);
template<typename T> int CountTrailingZeroes(T);
template<typename T> int CountLeadingZeroes(T);
+template<typename T> int CeilLog2(T);
#ifndef wasm_support_bits_definitions
// The template specializations are provided elsewhere.
@@ -52,6 +53,8 @@ extern template int CountTrailingZeroes(uint32_t);
extern template int CountTrailingZeroes(uint64_t);
extern template int CountLeadingZeroes(uint32_t);
extern template int CountLeadingZeroes(uint64_t);
+extern template int CeilLog2(uint32_t);
+extern template int CeilLog2(uint64_t);
#endif
// Convenience signed -> unsigned. It usually doesn't make much sense to use bit
@@ -65,6 +68,9 @@ template<typename T> int CountTrailingZeroes(T v) {
template<typename T> int CountLeadingZeroes(T v) {
return CountLeadingZeroes(typename std::make_unsigned<T>::type(v));
}
+template<typename T> int CeilLog2(T v) {
+ return CeilLog2(typename std::make_unsigned<T>::type(v));
+}
template<typename T> bool IsPowerOf2(T v) {
return v != 0 && (v & (v - 1)) == 0;
}