public inbox for libc-hacker@sourceware.org
 help / color / mirror / Atom feed
* [PATCH] Optimized __sched_cpucount for alphaev67, power5 and above and ia64
@ 2007-07-17 20:43 Jakub Jelinek
  2007-07-17 20:53 ` Roland McGrath
                   ` (2 more replies)
  0 siblings, 3 replies; 7+ messages in thread
From: Jakub Jelinek @ 2007-07-17 20:43 UTC (permalink / raw)
  To: Ulrich Drepper; +Cc: Glibc hackers, Richard Henderson, Steven Munroe

Hi!

alpha (ev67), ia64 and powerpc (power5 and later) implement popcount
in hardware.  For alpha I have used inline assembly, because
__builtin_popcount would only expand to ctpop if the selected gcc
arch is ev67, which isn't sure.  Calling libgcc function there is not a good
idea.  On ia64 we can use it unconditionally, for ppc only for power5 and
later, but inline asm would be larger there, so I use the builtin guarded
with predefined macro for power5 and later.
glibc build supports only GCC 3.4 and later, so __builtin_popcountl
is supported.

2007-07-17  Jakub Jelinek  <jakub@redhat.com>

	* sysdeps/alpha/alphaev67/sched_cpucount.c: New file.
	* sysdeps/ia64/sched_cpucount.c: New file.
	* sysdeps/powerpc/sched_cpucount.c: New file.

--- libc/sysdeps/alpha/alphaev67/sched_cpucount.c.jj	2007-07-17 22:21:33.000000000 +0200
+++ libc/sysdeps/alpha/alphaev67/sched_cpucount.c	2007-07-17 22:22:37.000000000 +0200
@@ -0,0 +1,24 @@
+/* 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.  */
+
+#define POPCNT(l) \
+  ({ __cpu_mask r;							      \
+     asm ("ctpop %1, %0" : "=r" (r) : "0" (l));				      \
+     r; })
+
+#include <posix/sched_cpucount.c>
--- libc/sysdeps/ia64/sched_cpucount.c.jj	2007-07-17 22:21:33.000000000 +0200
+++ libc/sysdeps/ia64/sched_cpucount.c	2007-07-17 22:25:50.000000000 +0200
@@ -0,0 +1,21 @@
+/* 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.  */
+
+#define POPCNT(l) __builtin_popcountl (l)
+
+#include <posix/sched_cpucount.c>
--- libc/sysdeps/powerpc/sched_cpucount.c.jj	2007-07-17 22:21:33.000000000 +0200
+++ libc/sysdeps/powerpc/sched_cpucount.c	2007-07-17 22:34:26.000000000 +0200
@@ -0,0 +1,23 @@
+/* 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 _ARCH_PWR5
+# define POPCNT(l) __builtin_popcountl (l)
+#endif
+
+#include <posix/sched_cpucount.c>

	Jakub

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2007-07-19 17:26 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-07-17 20:43 [PATCH] Optimized __sched_cpucount for alphaev67, power5 and above and ia64 Jakub Jelinek
2007-07-17 20:53 ` Roland McGrath
2007-07-18  9:01   ` Jakub Jelinek
2007-07-18  9:05     ` Roland McGrath
2007-07-18 14:52   ` Ulrich Drepper
2007-07-18 16:17 ` Richard Henderson
2007-07-19 17:26 ` Ulrich Drepper

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).