summaryrefslogtreecommitdiff
path: root/py
diff options
context:
space:
mode:
authorDamien George <damien@micropython.org>2025-06-14 22:22:30 +1000
committerDamien George <damien@micropython.org>2025-06-25 11:36:28 +1000
commit6fee099cae58644ea49ca0f470e9cb00a7da8f29 (patch)
treea4666198d149e8dce5dca7572eba7dee3ef9ad61 /py
parente57aa7e70a326659529d02891abb9a57b055fc0c (diff)
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 <damien@micropython.org>
Diffstat (limited to 'py')
-rw-r--r--py/misc.h2
1 files changed, 1 insertions, 1 deletions
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