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
This commit is contained in:
John Baldwin 2015-02-09 21:03:23 +00:00
parent 4c918926cd
commit 070b490323
2 changed files with 11 additions and 0 deletions

View File

@ -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_ */

View File

@ -60,6 +60,7 @@
#define CPU_OR_ATOMIC(d, s) BIT_OR_ATOMIC(CPU_SETSIZE, d, s)
#define CPU_COPY_STORE_REL(f, t) BIT_COPY_STORE_REL(CPU_SETSIZE, f, t)
#define CPU_FFS(p) BIT_FFS(CPU_SETSIZE, p)
#define CPU_COUNT(p) BIT_COUNT(CPU_SETSIZE, p)
/*
* Valid cpulevel_t values.