summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorTyge Løvset <[email protected]>2020-10-13 14:06:32 +0200
committerTyge Løvset <[email protected]>2020-10-13 14:06:32 +0200
commita45d90b03f29f766081498ca8263b3b386615c0f (patch)
treeafdc83d85ca77b2f1236a57d1e31ea6b39f403a5
parent88605737db66987689349abf9d685f0acb6653c4 (diff)
downloadSTC-modified-a45d90b03f29f766081498ca8263b3b386615c0f.tar.gz
STC-modified-a45d90b03f29f766081498ca8263b3b386615c0f.zip
Tweaks.
-rw-r--r--stc/cbitset.h27
-rw-r--r--stc/cqueue.h4
-rw-r--r--stc/cstack.h4
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<bset.size; ++i) printf("%d", cbitset_test(&bset, i)); puts("");
+ printf("%4zu: ", bset.size); c_forrange (i, bset.size) printf("%d", cbitset_test(&bset, i));
+ puts("");
cbitset_set(&bset, 28);
cbitset_resize(&bset, 77, true);
cbitset_resize(&bset, 93, false);
cbitset_resize(&bset, 102, true);
cbitset_set_value(&bset, 99, false);
- printf("%4zu: ", bset.size); for (int i=0; i<bset.size; ++i) printf("%d", cbitset_test(&bset, i)); puts("");
+ printf("%4zu: ", bset.size); c_forrange (i, bset.size) printf("%d", cbitset_test(&bset, i));
+ puts("");
cbitset_del(&bset);
}
*/
@@ -182,25 +184,24 @@ STC_API void cbitset_resize(cbitset_t* self, size_t size, bool value) {
}
#if defined(__GNUC__) || defined(__clang__)
- #define c_popcount64(x) __builtin_popcountll(x)
+ STC_INLINE uint64_t cpopcount64(uint64_t x) {return __builtin_popcountll(x);}
#elif defined(_MSC_VER) && defined(_WIN64)
#include <intrin.h>
- #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<n; ++i) count += c_popcount64(s._arr[i]);
- count += c_popcount64(s._arr[n] & ((1ull << (s.size & 63)) - 1));
+ for (size_t i=0; i<n; ++i) count += cpopcount64(s._arr[i]);
+ count += cpopcount64(s._arr[n] & ((1ull << (s.size & 63)) - 1));
}
return count;
}
diff --git a/stc/cqueue.h b/stc/cqueue.h
index 42f2be67..42c0e99e 100644
--- a/stc/cqueue.h
+++ b/stc/cqueue.h
@@ -78,7 +78,7 @@
cqueue_##X##_back(cqueue_##X* self) {return ctype##_back(self);} \
STC_INLINE void \
cqueue_##X##_pop(cqueue_##X* self) {ctype##_pop_front(self);} \
- STC_API void \
+ STC_INLINE void \
cqueue_##X##_push(cqueue_##X* self, ctype##_value_t value) { \
ctype##_push_back(self, value); \
} \
@@ -86,7 +86,7 @@
cqueue_##X##_emplace(cqueue_##X* self, cqueue_##X##_rawvalue_t rawValue) { \
ctype##_emplace_back(self, rawValue); \
} \
- STC_API void \
+ STC_INLINE void \
cqueue_##X##_push_n(cqueue_##X *self, const cqueue_##X##_input_t in[], size_t size) { \
ctype##_push_n(self, in, size); \
} \
diff --git a/stc/cstack.h b/stc/cstack.h
index ae37b859..336218f3 100644
--- a/stc/cstack.h
+++ b/stc/cstack.h
@@ -65,7 +65,7 @@
cstack_##X##_top(cstack_##X* self) {return ctype##_back(self);} \
STC_INLINE void \
cstack_##X##_pop(cstack_##X* self) {ctype##_pop_back(self);} \
- STC_API void \
+ STC_INLINE void \
cstack_##X##_push(cstack_##X* self, ctype##_value_t value) { \
ctype##_push_back(self, value); \
} \
@@ -73,7 +73,7 @@
cstack_##X##_emplace(cstack_##X* self, cstack_##X##_rawvalue_t rawValue) { \
ctype##_emplace_back(self, rawValue); \
} \
- STC_API void \
+ STC_INLINE void \
cstack_##X##_push_n(cstack_##X *self, const cstack_##X##_input_t in[], size_t size) { \
ctype##_push_n(self, in, size); \
} \