From 0d22184ec9e5b1e958c031ac92c7f053de3a13a2 Mon Sep 17 00:00:00 2001 From: Nicolas Geoffray Date: Mon, 27 Apr 2015 08:53:46 +0000 Subject: Revert "Revert "[optimizing] Replace FP divide by power of 2"" This reverts commit 067cae2c86627d2edcf01b918ee601774bc76aeb. Change-Id: Iaaa8772500ea7d3dce6ae0829dc0dc3bbc9c14ca --- runtime/utils.h | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'runtime/utils.h') 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 static constexpr int POPCOUNT(T x) { return (sizeof(T) == sizeof(uint32_t)) -- cgit v1.2.3-59-g8ed1b