diff options
Diffstat (limited to 'posix')
-rw-r--r-- | posix/sched_cpucount.c | 27 |
1 files changed, 10 insertions, 17 deletions
diff --git a/posix/sched_cpucount.c b/posix/sched_cpucount.c index eaddf61b1b..ab1ff49383 100644 --- a/posix/sched_cpucount.c +++ b/posix/sched_cpucount.c @@ -15,7 +15,6 @@ License along with the GNU C Library; if not, see <http://www.gnu.org/licenses/>. */ -#include <limits.h> #include <sched.h> @@ -36,22 +35,16 @@ __sched_cpucount (size_t setsize, const cpu_set_t *setp) if (l == 0) continue; -# 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 - 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 - - s += l; + _Static_assert (sizeof (l) == sizeof (unsigned int) + || sizeof (l) == sizeof (unsigned long) + || sizeof (l) == sizeof (unsigned long long), + "sizeof (__cpu_mask"); + if (sizeof (__cpu_mask) == sizeof (unsigned int)) + s += __builtin_popcount (l); + else if (sizeof (__cpu_mask) == sizeof (unsigned long)) + s += __builtin_popcountl (l); + else + s += __builtin_popcountll (l); #endif } |