diff options
| author | 2015-04-28 10:29:17 +0000 | |
|---|---|---|
| committer | 2015-04-28 10:29:19 +0000 | |
| commit | a94fb1f99ee3390bca9531b2512f8fc65f13ceee (patch) | |
| tree | f1234e6d003873e4720d591a84cdedde6e7b399f /runtime/utils.h | |
| parent | 64db01714f91bf255a79c0a88813641c240c9857 (diff) | |
| parent | 0d22184ec9e5b1e958c031ac92c7f053de3a13a2 (diff) | |
Merge "Revert "Revert "[optimizing] Replace FP divide by power of 2"""
Diffstat (limited to 'runtime/utils.h')
| -rw-r--r-- | runtime/utils.h | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/runtime/utils.h b/runtime/utils.h index 853fa08251..eaafcf0a64 100644 --- a/runtime/utils.h +++ b/runtime/utils.h @@ -300,6 +300,18 @@ static inline int WhichPowerOf2(T x) { return CTZ(x); } +// Return whether x / divisor == x * (1.0f / divisor), for every float x. +static constexpr bool CanDivideByReciprocalMultiplyFloat(int32_t divisor) { + // True, if the most significant bits of divisor are 0. + return ((divisor & 0x7fffff) == 0); +} + +// Return whether x / divisor == x * (1.0 / divisor), for every double x. +static constexpr bool CanDivideByReciprocalMultiplyDouble(int64_t divisor) { + // True, if the most significant bits of divisor are 0. + return ((divisor & ((UINT64_C(1) << 52) - 1)) == 0); +} + template<typename T> static constexpr int POPCOUNT(T x) { return (sizeof(T) == sizeof(uint32_t)) |