Add function bitset_popcount

This commit is contained in:
Patrick Pelissier committed 2021-02-22 12:06:46 +01:00
1 parent 5fd6352a4e
commit 7b2e242c94
2 files changed
+41

No files matched your search

+11
View File
@@ -366,6 +366,17 @@ static void test_clz(void)
bitset_set_at(s1, 0, false);
assert (bitset_clz(s1) == 64+620+1);
}
M_LET(s1, bitset_t) {
bitset_set_str(s1, "[00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000]");
assert(bitset_popcount(s1) == 0);
bitset_set_str(s1, "[10000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000]");
assert(bitset_popcount(s1) == 1);
bitset_set_str(s1, "[00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001]");
assert(bitset_popcount(s1) == 1);
bitset_set_str(s1, "[10000011100000110010101010110000011111111111111110000001110001110001110001110000]");
assert(bitset_popcount(s1) == 40);
}
}
int main(void)