Skip to content

Commit

Permalink
Fixed a couple compilation errors for MSVC 64-bit (#475)
Browse files Browse the repository at this point in the history
  • Loading branch information
marler8997 authored and andrewrk committed Sep 14, 2017
1 parent d9eabde commit bb44e4b
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 16 deletions.
2 changes: 1 addition & 1 deletion src/quadmath.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
34 changes: 19 additions & 15 deletions src/util.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<int>(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

Expand All @@ -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<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>
ATTRIBUTE_RETURNS_NOALIAS static inline T *allocate_nonzero(size_t count) {
T *ptr = reinterpret_cast<T*>(malloc(count * sizeof(T)));
Expand Down

0 comments on commit bb44e4b

Please sign in to comment.