diff options
| author | Tyge Løvset <[email protected]> | 2020-08-02 13:45:04 +0200 |
|---|---|---|
| committer | Tyge Løvset <[email protected]> | 2020-08-02 13:45:04 +0200 |
| commit | b99217051dad72cac7424160460154c3e4c0ea79 (patch) | |
| tree | 14344e69264065cd43b354f3682032fabfac881c | |
| parent | 13393d3cbc81e5c5d3ea8335694280ef16a5a84f (diff) | |
| download | STC-modified-b99217051dad72cac7424160460154c3e4c0ea79.tar.gz STC-modified-b99217051dad72cac7424160460154c3e4c0ea79.zip | |
Minor.
| -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) {
|
