Fix compilation of Log2(uint64_t) on MSVC
The _BitScanReverse64 intrinsic only exists when compiling for 64bit. Replace it by two calls to _BitScanReverse (the 32bit one) when on 32bit. Bug: Change-Id: Ie294327ec914b0ca4a73732e4b78c1f2a08f100f Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/15321 Commit-Queue: Corentin Wallez <cwallez@chromium.org> Reviewed-by: Kai Ninomiya <kainino@chromium.org>
This commit is contained in:
parent
80880ee998
commit
6b66b67f69
|
@ -15,6 +15,7 @@
|
||||||
#include "common/Math.h"
|
#include "common/Math.h"
|
||||||
|
|
||||||
#include "common/Assert.h"
|
#include "common/Assert.h"
|
||||||
|
#include "common/Platform.h"
|
||||||
|
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <cmath>
|
#include <cmath>
|
||||||
|
@ -50,28 +51,31 @@ uint32_t Log2(uint32_t value) {
|
||||||
uint32_t Log2(uint64_t value) {
|
uint32_t Log2(uint64_t value) {
|
||||||
ASSERT(value != 0);
|
ASSERT(value != 0);
|
||||||
#if defined(DAWN_COMPILER_MSVC)
|
#if defined(DAWN_COMPILER_MSVC)
|
||||||
|
# if defined(DAWN_PLATFORM_64_BIT)
|
||||||
unsigned long firstBitIndex = 0ul;
|
unsigned long firstBitIndex = 0ul;
|
||||||
unsigned char ret = _BitScanReverse64(&firstBitIndex, value);
|
unsigned char ret = _BitScanReverse64(&firstBitIndex, value);
|
||||||
ASSERT(ret != 0);
|
ASSERT(ret != 0);
|
||||||
return firstBitIndex;
|
return firstBitIndex;
|
||||||
#else
|
# else // defined(DAWN_PLATFORM_64_BIT)
|
||||||
|
unsigned long firstBitIndex = 0ul;
|
||||||
|
if (_BitScanReverse(&firstBitIndex, value >> 32)) {
|
||||||
|
return firstBitIndex + 32;
|
||||||
|
}
|
||||||
|
unsigned char ret = _BitScanReverse(&firstBitIndex, value & 0xFFFFFFFF);
|
||||||
|
ASSERT(ret != 0);
|
||||||
|
return firstBitIndex;
|
||||||
|
# endif // defined(DAWN_PLATFORM_64_BIT)
|
||||||
|
#else // defined(DAWN_COMPILER_MSVC)
|
||||||
return 63 - static_cast<uint32_t>(__builtin_clzll(value));
|
return 63 - static_cast<uint32_t>(__builtin_clzll(value));
|
||||||
#endif
|
#endif // defined(DAWN_COMPILER_MSVC)
|
||||||
}
|
}
|
||||||
|
|
||||||
uint64_t NextPowerOfTwo(uint64_t n) {
|
uint64_t NextPowerOfTwo(uint64_t n) {
|
||||||
#if defined(DAWN_COMPILER_MSVC)
|
|
||||||
if (n <= 1) {
|
if (n <= 1) {
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned long firstBitIndex = 0ul;
|
return 1ull << (Log2(n - 1) + 1);
|
||||||
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
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool IsPowerOfTwo(uint64_t n) {
|
bool IsPowerOfTwo(uint64_t n) {
|
||||||
|
|
Loading…
Reference in New Issue