diff options
| -rw-r--r-- | examples/prime.c | 2 | ||||
| -rw-r--r-- | stc/cbitset.h | 9 |
2 files changed, 5 insertions, 6 deletions
diff --git a/examples/prime.c b/examples/prime.c index f04c71a3..ef2af591 100644 --- a/examples/prime.c +++ b/examples/prime.c @@ -31,7 +31,7 @@ int main(void) printf("number of primes: %zu\n", np);
for (uint32_t i = 2; i <= 1000; ++i)
- if (cbitset_test(primes, i)) printf("%zu ", i);
+ if (cbitset_test(primes, i)) printf("%u ", i);
puts("");
cbitset_destroy(&primes);
}
\ No newline at end of file diff --git a/stc/cbitset.h b/stc/cbitset.h index acd86994..b26853c3 100644 --- a/stc/cbitset.h +++ b/stc/cbitset.h @@ -151,11 +151,7 @@ STC_API void cbitset_resize(cbitset_t* self, size_t size, bool value) { }
}
-#if defined(__GNUC__)
- #define c_popcount64(x) __builtin_popcountll(x)
-#elif defined(_MSC_VER)
- #define c_popcount64(x) _mm_popcnt_u64(x)
-#else
+#if defined(__TINYC__) // and other popcount-unsupporting compilers
/* http://en.wikipedia.org/wiki/Hamming_weight#Efficient_implementation */
static inline uint64_t c_popcount64(uint64_t x) {
const uint64_t m1 = 0x5555555555555555, m2 = 0x3333333333333333,
@@ -165,6 +161,9 @@ static inline uint64_t c_popcount64(uint64_t x) { x = (x + (x >> 4)) & m4;
return (x * h01) >> 56;
}
+#else
+ #include <nmmintrin.h>
+ #define c_popcount64(x) _mm_popcnt_u64(x)
#endif
STC_API size_t cbitset_count(cbitset_t set) {
|
