Skip to content

Commit 6fee099

Browse files
committed
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 <[email protected]>
1 parent e57aa7e commit 6fee099

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

py/misc.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -390,7 +390,7 @@ static inline uint32_t mp_popcount(uint32_t x) {
390390
x = x - ((x >> 1) & 0x55555555);
391391
x = (x & 0x33333333) + ((x >> 2) & 0x33333333);
392392
x = (x + (x >> 4)) & 0x0F0F0F0F;
393-
return x * 0x01010101;
393+
return (x * 0x01010101) >> 24;
394394
}
395395
#endif
396396
#endif

0 commit comments

Comments
 (0)