From bb44e4b479c89f029fef44aac11a8202a457c1b2 Mon Sep 17 00:00:00 2001 From: Jonathan Marler Date: Wed, 13 Sep 2017 21:59:09 -0600 Subject: [PATCH] Fixed a couple compilation errors for MSVC 64-bit (#475) --- src/quadmath.hpp | 2 +- src/util.hpp | 34 +++++++++++++++++++--------------- 2 files changed, 20 insertions(+), 16 deletions(-) diff --git a/src/quadmath.hpp b/src/quadmath.hpp index 4fefda228..3a7662567 100644 --- a/src/quadmath.hpp +++ b/src/quadmath.hpp @@ -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, ...) { va_list args; - va_start(format, args); + va_start(args, format); int result = vsnprintf(s, size, format, args); va_end(args); return result; diff --git a/src/util.hpp b/src/util.hpp index 5ef63bed4..b4f90bc79 100644 --- a/src/util.hpp +++ b/src/util.hpp @@ -24,27 +24,12 @@ #define ATTRIBUTE_RETURNS_NOALIAS __declspec(restrict) #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(63-lz); - zig_unreachable(); -#else - if (_BitScanReverse(&lz, mask >> 32)) - lz += 32; - else - _BitScanReverse(&lz, mask & 0xffffffff); - return 63 - lz; -#endif -} #else #define ATTRIBUTE_COLD __attribute__((cold)) #define ATTRIBUTE_PRINTF(a, b) __attribute__((format(printf, a, b))) #define ATTRIBUTE_RETURNS_NOALIAS __attribute__((__malloc__)) #define ATTRIBUTE_NORETURN __attribute__((noreturn)) -#define clzll(x) __builtin_clzll(x) #endif @@ -61,6 +46,25 @@ static inline void zig_unreachable(void) { 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(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 ATTRIBUTE_RETURNS_NOALIAS static inline T *allocate_nonzero(size_t count) { T *ptr = reinterpret_cast(malloc(count * sizeof(T)));