From 2d47c0b8ae7b72e710b982abce83429c50c6de30 Mon Sep 17 00:00:00 2001 From: Max Graey Date: Thu, 17 Sep 2020 23:05:55 +0300 Subject: 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 --- src/support/bits.h | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'src/support/bits.h') 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 int PopCount(T); template uint32_t BitReverse(T); template int CountTrailingZeroes(T); template int CountLeadingZeroes(T); +template 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 int CountTrailingZeroes(T v) { template int CountLeadingZeroes(T v) { return CountLeadingZeroes(typename std::make_unsigned::type(v)); } +template int CeilLog2(T v) { + return CeilLog2(typename std::make_unsigned::type(v)); +} template bool IsPowerOf2(T v) { return v != 0 && (v & (v - 1)) == 0; } -- cgit v1.2.3