From 5b92eeb2859ed8cda7cb479aae85563b15c4cfd2 Mon Sep 17 00:00:00 2001 From: BorisMansencal Date: Sat, 6 May 2017 20:36:16 +0200 Subject: [PATCH] correct utils::nextHighestPowerOf2 The bit shift was done as int and not as current type (size_t for example), thus the computed next highest power of 2 was wrong on large numbers. --- gpu/utils/StaticUtils.h | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/gpu/utils/StaticUtils.h b/gpu/utils/StaticUtils.h index e53b42118..1fe4eeac3 100644 --- a/gpu/utils/StaticUtils.h +++ b/gpu/utils/StaticUtils.h @@ -61,7 +61,7 @@ static_assert(!isPowerOf2(3333), "isPowerOf2"); template constexpr __host__ __device__ T nextHighestPowerOf2(T v) { - return (isPowerOf2(v) ? (T) 2 * v : (1 << (log2(v) + 1))); + return (isPowerOf2(v) ? (T) 2 * v : ((T)1 << (log2(v) + 1))); } static_assert(nextHighestPowerOf2(1) == 2, "nextHighestPowerOf2"); @@ -73,4 +73,7 @@ static_assert(nextHighestPowerOf2(15) == 16, "nextHighestPowerOf2"); static_assert(nextHighestPowerOf2(16) == 32, "nextHighestPowerOf2"); static_assert(nextHighestPowerOf2(17) == 32, "nextHighestPowerOf2"); +static_assert(nextHighestPowerOf2(1536000000u) == 2147483648u, "nextHighestPowerOf2"); +static_assert(nextHighestPowerOf2(2147483648) == (size_t)4294967296, "nextHighestPowerOf2"); + } } } // namespace