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:
parent
25cc723823
commit
f19c328b5b
|
@ -61,7 +61,14 @@ uint32_t Log2(uint64_t value) {
|
|||
|
||||
uint64_t NextPowerOfTwo(uint64_t n) {
|
||||
#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
|
||||
return n <= 1 ? 1 : 1ull << (64 - __builtin_clzll(n - 1));
|
||||
#endif
|
||||
|
|
Loading…
Reference in New Issue