Skip to content

Commit

Permalink
popcount: fix incorrect result when not on GNU/Clang
Browse files Browse the repository at this point in the history
  • Loading branch information
XPhyro committed Aug 23, 2024
1 parent 7c76910 commit 6277c8b
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/c/util/math/popcount.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,9 @@ int main(int argc, char *argv[])
#ifdef USE_BUILTIN
popcount += __builtin_popcount(c & 0xff);
#else
popcount += (c & 0x01) + (c & 0x02) + (c & 0x04) + (c & 0x08) + (c & 0x10) +
(c & 0x20) + (c & 0x40) + (c & 0x80);
popcount += ((c & (1 << 0)) >> 0) + ((c & (1 << 1)) >> 1) + ((c & (1 << 2)) >> 2) +
((c & (1 << 3)) >> 3) + ((c & (1 << 4)) >> 4) + ((c & (1 << 5)) >> 5) +
((c & (1 << 6)) >> 6) + ((c & (1 << 7)) >> 7);
#endif
}
}
Expand Down

0 comments on commit 6277c8b

Please sign in to comment.