From a45d90b03f29f766081498ca8263b3b386615c0f Mon Sep 17 00:00:00 2001 From: Tyge Løvset Date: Tue, 13 Oct 2020 14:06:32 +0200 Subject: Tweaks. --- stc/cbitset.h | 27 ++++++++++++++------------- stc/cqueue.h | 4 ++-- stc/cstack.h | 4 ++-- 3 files changed, 18 insertions(+), 17 deletions(-) diff --git a/stc/cbitset.h b/stc/cbitset.h index 859865a2..7af3f6a9 100644 --- a/stc/cbitset.h +++ b/stc/cbitset.h @@ -30,13 +30,15 @@ int main() { cbitset_t bset = cbitset_with_size(23, true); cbitset_reset(&bset, 9); cbitset_resize(&bset, 43, false); - printf("%4zu: ", bset.size); for (int i=0; i - #define c_popcount64(x) __popcnt64(x) + STC_INLINE uint64_t cpopcount64(uint64_t x) {return __popcnt64(x);} #else -/* http://en.wikipedia.org/wiki/Hamming_weight#Efficient_implementation */ -static inline uint64_t c_popcount64(uint64_t x) { - x -= (x >> 1) & 0x5555555555555555; - x = (x & 0x3333333333333333) + ((x >> 2) & 0x3333333333333333); - x = (x + (x >> 4)) & 0x0f0f0f0f0f0f0f0f; - return (x * 0x0101010101010101) >> 56; -} + STC_INLINE uint64_t cpopcount64(uint64_t x) { /* http://en.wikipedia.org/wiki/Hamming_weight */ + x -= (x >> 1) & 0x5555555555555555; + x = (x & 0x3333333333333333) + ((x >> 2) & 0x3333333333333333); + x = (x + (x >> 4)) & 0x0f0f0f0f0f0f0f0f; + return (x * 0x0101010101010101) >> 56; + } #endif STC_API size_t cbitset_count(cbitset_t s) { size_t count = 0, n = ((s.size + 63) >> 6) - 1; if (s.size > 0) { - for (size_t i=0; i