diff options
author | jhb <jhb@FreeBSD.org> | 2015-02-09 21:03:23 +0000 |
---|---|---|
committer | jhb <jhb@FreeBSD.org> | 2015-02-09 21:03:23 +0000 |
commit | dbdaac6f208389f7cacab9fe319360b0f6e9095e (patch) | |
tree | 10fd6f8c5d3a008dd9724d177805fe95f87a6d69 /sys/sys/bitset.h | |
parent | 0754f0eac9d97737274d7b77cb519abb250362b3 (diff) | |
download | FreeBSD-src-dbdaac6f208389f7cacab9fe319360b0f6e9095e.zip FreeBSD-src-dbdaac6f208389f7cacab9fe319360b0f6e9095e.tar.gz |
Use __builtin_popcnt() to implement a BIT_COUNT() operation for bitsets and
use this to implement CPU_COUNT() to count the number of CPUs in a cpuset.
MFC after: 2 weeks
Diffstat (limited to 'sys/sys/bitset.h')
-rw-r--r-- | sys/sys/bitset.h | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/sys/sys/bitset.h b/sys/sys/bitset.h index e6c4dc3..9871c24 100644 --- a/sys/sys/bitset.h +++ b/sys/sys/bitset.h @@ -176,4 +176,14 @@ __bit; \ }) +#define BIT_COUNT(_s, p) __extension__ ({ \ + __size_t __i; \ + int __count; \ + \ + __count = 0; \ + for (__i = 0; __i < __bitset_words((_s)); __i++) \ + __count += __builtin_popcount((p)->__bits[__i]); \ + __count; \ +}) + #endif /* !_SYS_BITSET_H_ */ |