From 87b42f299dd05809494161c485555ab4af9a4a9f Mon Sep 17 00:00:00 2001 From: Max Wash Date: Fri, 6 Dec 2024 15:10:41 +0000 Subject: [PATCH] core: add support for compiling bitops on 32-bit platforms --- core/sys/windows/bitop.c | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/core/sys/windows/bitop.c b/core/sys/windows/bitop.c index 60921d4..b5778d4 100644 --- a/core/sys/windows/bitop.c +++ b/core/sys/windows/bitop.c @@ -23,7 +23,11 @@ int b_popcountl(long v) } if (cpu_supports_popcnt == CPU_FEATURE_YES) { +#if _M_AMD64 == 100 return __popcnt64(v); +#else + return __popcnt(v); +#endif } assert(0 && "CPU does not support popcount!"); @@ -34,7 +38,13 @@ int b_ctzl(long v) { unsigned long trailing_zero = 0; - if (_BitScanForward64(&trailing_zero, v)) { +#if _M_AMD64 == 100 + int x = _BitScanForward64(&trailing_zero, v); +#else + int x = _BitScanForward(&trailing_zero, v); +#endif + + if (x) { return trailing_zero; } else { return 64; @@ -45,7 +55,13 @@ int b_clzl(long v) { unsigned long leading_zero = 0; - if (_BitScanReverse64(&leading_zero, v)) { +#if _M_AMD64 == 100 + int x = _BitScanReverse64(&leading_zero, v); +#else + int x = _BitScanReverse(&leading_zero, v); +#endif + + if (x) { return 64 - leading_zero; } else { // Same remarks as above