From 506ce9bba43beca3ba6416b93f6c43ef7df0c5d3 Mon Sep 17 00:00:00 2001 From: Bryan Bernhart Date: Fri, 26 Jul 2019 11:20:08 +0000 Subject: [PATCH] Fix MSVC builder failure with NextPowerOfTwo. Define behavior of n=0 when compiling on MSVC. BUG=dawn:27 Change-Id: If9d454833f5b3d8f0183eba2bc5a54f9ca6e56a2 Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/9440 Commit-Queue: Corentin Wallez Reviewed-by: Corentin Wallez --- src/common/Math.cpp | 6 +++--- src/common/Math.h | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/common/Math.cpp b/src/common/Math.cpp index e0de2ce2eb..aab0e451ce 100644 --- a/src/common/Math.cpp +++ b/src/common/Math.cpp @@ -59,11 +59,11 @@ uint32_t Log2(uint64_t value) { #endif } -uint64_t NextPowerOfTwo(uint64_t x) { +uint64_t NextPowerOfTwo(uint64_t n) { #if defined(DAWN_COMPILER_MSVC) - return x == 1 ? 1 : 1ull << (64 - __lzcnt64(x - 1)); + return n <= 1 ? 1 : 1ull << (64 - __lzcnt64(n - 1)); #else - return x == 1 ? 1 : 1ull << (64 - __builtin_clzll(x - 1)); + return n == 1 ? 1 : 1ull << (64 - __builtin_clzll(n - 1)); #endif } diff --git a/src/common/Math.h b/src/common/Math.h index 777edba961..80b8792eb1 100644 --- a/src/common/Math.h +++ b/src/common/Math.h @@ -28,7 +28,7 @@ uint32_t Log2(uint32_t value); uint32_t Log2(uint64_t value); bool IsPowerOfTwo(size_t n); -uint64_t NextPowerOfTwo(uint64_t x); +uint64_t NextPowerOfTwo(uint64_t n); bool IsPtrAligned(const void* ptr, size_t alignment); void* AlignVoidPtr(void* ptr, size_t alignment); bool IsAligned(uint32_t value, size_t alignment);