Fixed a couple compilation errors for MSVC 64-bit (#475)

This commit is contained in:
Jonathan Marler 2017-09-13 21:59:09 -06:00 committed by Andrew Kelley
parent d9eabde319
commit bb44e4b479
2 changed files with 20 additions and 16 deletions

View File

@ -32,7 +32,7 @@ static inline __float128 strtoflt128(const char *s, char **sp) {
static inline int quadmath_snprintf(char *s, size_t size, const char *format, ...) { static inline int quadmath_snprintf(char *s, size_t size, const char *format, ...) {
va_list args; va_list args;
va_start(format, args); va_start(args, format);
int result = vsnprintf(s, size, format, args); int result = vsnprintf(s, size, format, args);
va_end(args); va_end(args);
return result; return result;

View File

@ -24,27 +24,12 @@
#define ATTRIBUTE_RETURNS_NOALIAS __declspec(restrict) #define ATTRIBUTE_RETURNS_NOALIAS __declspec(restrict)
#define ATTRIBUTE_NORETURN __declspec(noreturn) #define ATTRIBUTE_NORETURN __declspec(noreturn)
static inline int clzll(unsigned long long mask) {
unsigned long lz;
#if defined(_WIN64)
if (_BitScanReverse64(&lz, mask))
return static_cast<int>(63-lz);
zig_unreachable();
#else
if (_BitScanReverse(&lz, mask >> 32))
lz += 32;
else
_BitScanReverse(&lz, mask & 0xffffffff);
return 63 - lz;
#endif
}
#else #else
#define ATTRIBUTE_COLD __attribute__((cold)) #define ATTRIBUTE_COLD __attribute__((cold))
#define ATTRIBUTE_PRINTF(a, b) __attribute__((format(printf, a, b))) #define ATTRIBUTE_PRINTF(a, b) __attribute__((format(printf, a, b)))
#define ATTRIBUTE_RETURNS_NOALIAS __attribute__((__malloc__)) #define ATTRIBUTE_RETURNS_NOALIAS __attribute__((__malloc__))
#define ATTRIBUTE_NORETURN __attribute__((noreturn)) #define ATTRIBUTE_NORETURN __attribute__((noreturn))
#define clzll(x) __builtin_clzll(x)
#endif #endif
@ -61,6 +46,25 @@ static inline void zig_unreachable(void) {
zig_panic("unreachable"); zig_panic("unreachable");
} }
#if defined(_MSC_VER)
static inline int clzll(unsigned long long mask) {
unsigned long lz;
#if defined(_WIN64)
if (_BitScanReverse64(&lz, mask))
return static_cast<int>(63 - lz);
zig_unreachable();
#else
if (_BitScanReverse(&lz, mask >> 32))
lz += 32;
else
_BitScanReverse(&lz, mask & 0xffffffff);
return 63 - lz;
#endif
}
#else
#define clzll(x) __builtin_clzll(x)
#endif
template<typename T> template<typename T>
ATTRIBUTE_RETURNS_NOALIAS static inline T *allocate_nonzero(size_t count) { ATTRIBUTE_RETURNS_NOALIAS static inline T *allocate_nonzero(size_t count) {
T *ptr = reinterpret_cast<T*>(malloc(count * sizeof(T))); T *ptr = reinterpret_cast<T*>(malloc(count * sizeof(T)));