Fix NextPowerOfTwo for 64-bit MSVC

This test was failing consistently on win-msvc-dbg and occasionally
on win-msvc-rel. It's suspected the hardware does not properly
support __lzcnt64 so the function is implemented with _BitScanReverse64.

Bug: dawn:213
Change-Id: I0712f87787aad4aad7233bfb72846ec3dba96239
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/10481
Reviewed-by: Corentin Wallez <cwallez@chromium.org>
Reviewed-by: Kai Ninomiya <kainino@chromium.org>
Commit-Queue: Austin Eng <enga@chromium.org>
This commit is contained in:
Austin Eng 2019-08-26 16:50:05 +00:00 committed by Commit Bot service account
parent 25cc723823
commit f19c328b5b
1 changed files with 8 additions and 1 deletions

View File

@ -61,7 +61,14 @@ uint32_t Log2(uint64_t value) {
uint64_t NextPowerOfTwo(uint64_t n) { uint64_t NextPowerOfTwo(uint64_t n) {
#if defined(DAWN_COMPILER_MSVC) #if defined(DAWN_COMPILER_MSVC)
return n <= 1 ? 1 : 1ull << (64 - __lzcnt64(n - 1)); if (n <= 1) {
return 1;
}
unsigned long firstBitIndex = 0ul;
unsigned char ret = _BitScanReverse64(&firstBitIndex, n - 1);
ASSERT(ret != 0);
return 1ull << (firstBitIndex + 1);
#else #else
return n <= 1 ? 1 : 1ull << (64 - __builtin_clzll(n - 1)); return n <= 1 ? 1 : 1ull << (64 - __builtin_clzll(n - 1));
#endif #endif