* posix/sched_cpucount.c (__sched_cpucount): Allow using special
authorUlrich Drepper <drepper@redhat.com>
Fri, 8 Jun 2007 19:23:19 +0000 (19:23 +0000)
committerUlrich Drepper <drepper@redhat.com>
Fri, 8 Jun 2007 19:23:19 +0000 (19:23 +0000)
instruction for counting bits.
* sysdeps/x86_64/sched_cpucount.c: New file.

ChangeLog
posix/sched_cpucount.c
sysdeps/x86_64/sched_cpucount.c [new file with mode: 0644]

index f7fff22..f2ae899 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2007-06-08  Ulrich Drepper  <drepper@redhat.com>
+
+       * posix/sched_cpucount.c (__sched_cpucount): Allow using special
+       instruction for counting bits.
+       * sysdeps/x86_64/sched_cpucount.c: New file.
+
 2007-06-07  Ulrich Drepper  <drepper@redhat.com>
 
        * configure.in: Avoid variable named BASH.
index fd2687d..331c0b8 100644 (file)
 
 
 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);
diff --git a/sysdeps/x86_64/sched_cpucount.c b/sysdeps/x86_64/sched_cpucount.c
new file mode 100644 (file)
index 0000000..63d84a6
--- /dev/null
@@ -0,0 +1,26 @@
+/* Copyright (C) 2007 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library; if not, write to the Free
+   Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+   02111-1307 USA.  */
+
+#ifdef __amdfam10
+# define POPCNT(l) \
+  ({ __cpu_mask r;                                                           \
+     asm ("popcntq %1, %0" : "=r" (r) : "0" (l));                            \
+     r; })
+#endif
+
+#include <posix/sched_cpucount.c>