From a008f1c098df0fe6262e3456a3ead20bcea8a778 Mon Sep 17 00:00:00 2001 From: startewho Date: Sat, 15 Jun 2024 21:04:42 +0800 Subject: [PATCH] Fix the Windows x86 MSVC build Fixes: https://github.com/quickjs-ng/quickjs/issues/430 --- cutils.h | 7 +++++++ tests/test_conv.c | 8 +++++++- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/cutils.h b/cutils.h index a5da60d..26436d4 100644 --- a/cutils.h +++ b/cutils.h @@ -203,9 +203,16 @@ static inline int clz32(unsigned int a) static inline int clz64(uint64_t a) { #if defined(_MSC_VER) && !defined(__clang__) +#if INTPTR_MAX == INT64_MAX unsigned long index; _BitScanReverse64(&index, a); return 63 - index; +#else + if (a >> 32) + return clz32((unsigned)(a >> 32)); + else + return clz32((unsigned)a) + 32; +#endif #else return __builtin_clzll(a); #endif diff --git a/tests/test_conv.c b/tests/test_conv.c index 9761b30..b0678ae 100644 --- a/tests/test_conv.c +++ b/tests/test_conv.c @@ -94,14 +94,20 @@ static inline int clz32(unsigned int a) static inline int clz64(uint64_t a) { #if defined(_MSC_VER) && !defined(__clang__) +#if INTPTR_MAX == INT64_MAX unsigned long index; _BitScanReverse64(&index, a); return 63 - index; +#else + if (a >> 32) + return clz32((unsigned)(a >> 32)); + else + return clz32((unsigned)a) + 32; +#endif #else return __builtin_clzll(a); #endif } - // prototypes for final functions extern char const digits36[36]; size_t u32toa(char buf[minimum_length(11)], uint32_t n);