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>
This commit is contained in:
Damien George 2025-06-14 22:22:30 +10:00
parent e57aa7e70a
commit 6fee099cae

View file

@ -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