Fix compilation on Windows

There are still a bunch of warning that we should remove.
This commit is contained in:
Corentin Wallez
2017-05-29 11:33:33 -07:00
committed by Corentin Wallez
parent 583e9a8f3c
commit 944b60fb75
6 changed files with 34 additions and 11 deletions

View File

@@ -16,6 +16,7 @@
#include "Math.h"
#include <algorithm>
#include <cassert>
#include <climits>
#include <cstdlib>

View File

@@ -14,23 +14,34 @@
#include "Math.h"
#include <intrin.h>
#include "Forward.h"
namespace backend {
unsigned long ScanForward(unsigned long bits) {
uint32_t ScanForward(uint32_t bits) {
ASSERT(bits != 0);
// TODO(cwallez@chromium.org): handle non-posix platforms
// unsigned long firstBitIndex = 0ul;
// unsigned char ret = _BitScanForward(&firstBitIndex, bits);
// ASSERT(ret != 0);
// return firstBitIndex;
return static_cast<unsigned long>(__builtin_ctzl(bits));
#if defined(_WIN32) || defined(_WIN64)
unsigned long firstBitIndex = 0ul;
unsigned char ret = _BitScanForward(&firstBitIndex, bits);
ASSERT(ret != 0);
return firstBitIndex;
#else
return static_cast<unsigned long>(__builtin_ctz(bits));
#endif
}
uint32_t Log2(uint32_t value) {
ASSERT(value != 0);
return 31 - __builtin_clz(value);
#if defined(_WIN32) || defined(_WIN64)
unsigned long firstBitIndex = 0ul;
unsigned char ret = _BitScanReverse(&firstBitIndex, value);
ASSERT(ret != 0);
return firstBitIndex;
#else
return 31 - __builtin_clz(value);
#endif
}
bool IsPowerOfTwo(size_t n) {

View File

@@ -21,7 +21,7 @@
namespace backend {
// The following are not valid for 0
unsigned long ScanForward(unsigned long bits);
uint32_t ScanForward(uint32_t bits);
uint32_t Log2(uint32_t value);
bool IsPowerOfTwo(size_t n);