diff options
| author | gingerBill <bill@gingerbill.org> | 2021-07-12 11:03:12 +0100 |
|---|---|---|
| committer | gingerBill <bill@gingerbill.org> | 2021-07-12 11:03:12 +0100 |
| commit | 76707e1d2f3a33bc5dabf367318ccd76ce242b6a (patch) | |
| tree | f8858e15dba0312f85e0b25f7be12a97fd420c9b /src/big_int.cpp | |
| parent | ff2e5c3efe931e6a088c2368b0ce5d5c21f03c65 (diff) | |
Add sanity casts for 32/64 bit correctness
Diffstat (limited to 'src/big_int.cpp')
| -rw-r--r-- | src/big_int.cpp | 20 |
1 files changed, 19 insertions, 1 deletions
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 |