diff options
Diffstat (limited to 'posix/sched_cpucount.c')
-rw-r--r-- | posix/sched_cpucount.c | 14 |
1 files changed, 9 insertions, 5 deletions
diff --git a/posix/sched_cpucount.c b/posix/sched_cpucount.c index fd2687d8af..331c0b8dfc 100644 --- a/posix/sched_cpucount.c +++ b/posix/sched_cpucount.c @@ -21,18 +21,22 @@ int -__sched_cpucount (size_t setsize, cpu_set_t *setp) +__sched_cpucount (size_t setsize, const cpu_set_t *setp) { int s = 0; - for (unsigned int j = 0; j < setsize / sizeof (__cpu_mask); ++j) + const __cpu_mask *p = setp->__bits; + const __cpu_mask *end = &setp->__bits[setsize / sizeof (__cpu_mask)]; + + while (p < end) { - __cpu_mask l = setp->__bits[j]; - if (l == 0) - continue; + __cpu_mask l = *p++; #ifdef POPCNT s += POPCNT (l); #else + if (l == 0) + continue; + # if LONG_BIT > 32 l = (l & 0x5555555555555555ul) + ((l >> 1) & 0x5555555555555555ul); l = (l & 0x3333333333333333ul) + ((l >> 2) & 0x3333333333333333ul); |