cpu: ext_reg switch bug FIX by markus
[calu.git] / 2_isa / src / bittwiddling.c
1 #define B0 (0x55555555)
2 #define B1 (0x33333333)
3 #define B2 (0x0F0F0F0F)
4 #define B3 (0x001F001F)
5 #define B4 (0x0000003F)
6
7 int countbits(int x) {
8         x = (x & B0) + ((x >>  1) & B0);
9         x = (x & B1) + ((x >>  2) & B1);
10
11         x = (x + (x >>  4)) & B2;
12         x = (x + (x >>  8)) /*& B3 */
13         x = (x + (x >> 16)) & B4;
14         return x;
15 }