From 76707e1d2f3a33bc5dabf367318ccd76ce242b6a Mon Sep 17 00:00:00 2001 From: gingerBill Date: Mon, 12 Jul 2021 11:03:12 +0100 Subject: Add sanity casts for 32/64 bit correctness --- src/big_int.cpp | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) (limited to 'src/big_int.cpp') diff --git a/src/big_int.cpp b/src/big_int.cpp index 9cb1ec586..6386b1d6f 100644 --- a/src/big_int.cpp +++ b/src/big_int.cpp @@ -281,7 +281,25 @@ void big_int_mul(BigInt *dst, BigInt const *x, BigInt const *y) { u64 leading_zeros_u64(u64 x) { #if defined(GB_COMPILER_MSVC) - return __lzcnt64(x); + #if defined(GB_ARCH_64_BIT) + return __lzcnt64(x); + #else + u64 y, n; + + n = 0; + y = x; + L: + if (x < 0) { + return n; + } + if (y == 0) { + return 64-n; + } + n++; + x <<= 1; + y >>= 1; + goto L; + #endif #else return cast(u64)__builtin_clzll(cast(unsigned long long)x); #endif -- cgit v1.2.3