summaryrefslogtreecommitdiff
path: root/posix
diff options
context:
space:
mode:
authorUlrich Drepper <drepper@redhat.com>2007-06-08 19:23:19 +0000
committerUlrich Drepper <drepper@redhat.com>2007-06-08 19:23:19 +0000
commit36dffb2256f4ad8fa45feaf0617d8c5570a92cdb (patch)
treec51054851ca82b4bc708c71252d8ba36ebbc5f51 /posix
parent7d0e41cebe87f807c70c65b9b8cb001edca66465 (diff)
downloadglibc-36dffb2256f4ad8fa45feaf0617d8c5570a92cdb.tar.gz
* posix/sched_cpucount.c (__sched_cpucount): Allow using special
instruction for counting bits. * sysdeps/x86_64/sched_cpucount.c: New file.
Diffstat (limited to 'posix')
-rw-r--r--posix/sched_cpucount.c14
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);