From 7d0e41cebe87f807c70c65b9b8cb001edca66465 Mon Sep 17 00:00:00 2001 From: Ulrich Drepper Date: Fri, 8 Jun 2007 18:29:24 +0000 Subject: (__sched_cpucount): Allow using special instruction for counting bits. --- posix/sched_cpucount.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/posix/sched_cpucount.c b/posix/sched_cpucount.c index d7f6b7b49f..fd2687d8af 100644 --- a/posix/sched_cpucount.c +++ b/posix/sched_cpucount.c @@ -30,22 +30,26 @@ __sched_cpucount (size_t setsize, cpu_set_t *setp) if (l == 0) continue; -#if LONG_BIT > 32 +#ifdef POPCNT + s += POPCNT (l); +#else +# if LONG_BIT > 32 l = (l & 0x5555555555555555ul) + ((l >> 1) & 0x5555555555555555ul); l = (l & 0x3333333333333333ul) + ((l >> 2) & 0x3333333333333333ul); l = (l & 0x0f0f0f0f0f0f0f0ful) + ((l >> 4) & 0x0f0f0f0f0f0f0f0ful); l = (l & 0x00ff00ff00ff00fful) + ((l >> 8) & 0x00ff00ff00ff00fful); l = (l & 0x0000ffff0000fffful) + ((l >> 16) & 0x0000ffff0000fffful); l = (l & 0x00000000fffffffful) + ((l >> 32) & 0x00000000fffffffful); -#else +# else l = (l & 0x55555555ul) + ((l >> 1) & 0x55555555ul); l = (l & 0x33333333ul) + ((l >> 2) & 0x33333333ul); l = (l & 0x0f0f0f0ful) + ((l >> 4) & 0x0f0f0f0ful); l = (l & 0x00ff00fful) + ((l >> 8) & 0x00ff00fful); l = (l & 0x0000fffful) + ((l >> 16) & 0x0000fffful); -#endif +# endif s += l; +#endif } return s; -- cgit 1.4.1