From 6fee099cae58644ea49ca0f470e9cb00a7da8f29 Mon Sep 17 00:00:00 2001 From: Damien George Date: Sat, 14 Jun 2025 22:22:30 +1000 Subject: [PATCH] py/misc: Fix fallback implementation of mp_popcount. Tested using gcc 7.3.1 which does not have the popcount built-in and uses this fallback version. Without the fix, mpy-cross produces mpy files with corrupt RISC-V machine code. With the fix, mpy-cross output is correct. Signed-off-by: Damien George --- py/misc.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/py/misc.h b/py/misc.h index 49f2f8711..1cf582456 100644 --- a/py/misc.h +++ b/py/misc.h @@ -390,7 +390,7 @@ static inline uint32_t mp_popcount(uint32_t x) { x = x - ((x >> 1) & 0x55555555); x = (x & 0x33333333) + ((x >> 2) & 0x33333333); x = (x + (x >> 4)) & 0x0F0F0F0F; - return x * 0x01010101; + return (x * 0x01010101) >> 24; } #endif #endif