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

* Re: [PATCH] Optimized __sched_cpucount for alphaev67, power5 and above and ia64
  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 14:52   ` Ulrich Drepper
  2007-07-18 16:17 ` Richard Henderson
  2007-07-19 17:26 ` Ulrich Drepper
  2 siblings, 2 replies; 7+ messages in thread
From: Roland McGrath @ 2007-07-17 20:53 UTC (permalink / raw)
  To: Jakub Jelinek
  Cc: Ulrich Drepper, Glibc hackers, Richard Henderson, Steven Munroe

Seems like this might come up somewhere else.  I'd be inclined to add a
sysdeps header file for POPCNT alone (or rename it).


Thanks,
Roland

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

* Re: [PATCH] Optimized __sched_cpucount for alphaev67, power5 and above and ia64
  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
  1 sibling, 1 reply; 7+ messages in thread
From: Jakub Jelinek @ 2007-07-18  9:01 UTC (permalink / raw)
  To: Roland McGrath
  Cc: Ulrich Drepper, Glibc hackers, Richard Henderson, Steven Munroe

On Tue, Jul 17, 2007 at 01:53:04PM -0700, Roland McGrath wrote:
> Seems like this might come up somewhere else.  I'd be inclined to add a
> sysdeps header file for POPCNT alone (or rename it).

Maybe, though I'm not sure if we need one sysdep header for each such a
macro, that might be an overkill.

	Jakub

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

* Re: [PATCH] Optimized __sched_cpucount for alphaev67, power5 and above and ia64
  2007-07-18  9:01   ` Jakub Jelinek
@ 2007-07-18  9:05     ` Roland McGrath
  0 siblings, 0 replies; 7+ messages in thread
From: Roland McGrath @ 2007-07-18  9:05 UTC (permalink / raw)
  To: Jakub Jelinek
  Cc: Ulrich Drepper, Glibc hackers, Richard Henderson, Steven Munroe

> Maybe, though I'm not sure if we need one sysdep header for each such a
> macro, that might be an overkill.

No, one header for all macros of the ilk that come along would be fine.  
At a stretch, sysdeps/CPU/sysdep.h might even do.  

I almost suggested just adding it to bits/atomic.h, but it is probably
preferable to segregate miscellanea from atomic/lock stuff in particular.


Thanks,
Roland

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

* Re: [PATCH] Optimized __sched_cpucount for alphaev67, power5 and above and ia64
  2007-07-17 20:53 ` Roland McGrath
  2007-07-18  9:01   ` Jakub Jelinek
@ 2007-07-18 14:52   ` Ulrich Drepper
  1 sibling, 0 replies; 7+ messages in thread
From: Ulrich Drepper @ 2007-07-18 14:52 UTC (permalink / raw)
  To: Roland McGrath; +Cc: Jakub Jelinek, Glibc hackers

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Roland McGrath wrote:
> Seems like this might come up somewhere else.  I'd be inclined to add a
> sysdeps header file for POPCNT alone (or rename it).

Seems like a lot of work with questionable benefit.  In all the years we
have found one single place in glibc for this operation.  I'm happy with
the current patch.  We cann always change it later if the assumption
that it is not widely needed turns out wrong.

- --
➧ Ulrich Drepper ➧ Red Hat, Inc. ➧ 444 Castro St ➧ Mountain View, CA ❖
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.7 (GNU/Linux)

iD8DBQFGnikz2ijCOnn/RHQRAjaIAJ0VGVBv71Pq2ykQ6U1NWLnfJyfJMQCeIlbH
l16AM6WUGDRd0cOXY+9LSq8=
=X5of
-----END PGP SIGNATURE-----

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

* Re: [PATCH] Optimized __sched_cpucount for alphaev67, power5 and above and ia64
  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 16:17 ` Richard Henderson
  2007-07-19 17:26 ` Ulrich Drepper
  2 siblings, 0 replies; 7+ messages in thread
From: Richard Henderson @ 2007-07-18 16:17 UTC (permalink / raw)
  To: Jakub Jelinek
  Cc: Ulrich Drepper, Glibc hackers, Richard Henderson, Steven Munroe

On Tue, Jul 17, 2007 at 10:47:19PM +0200, Jakub Jelinek wrote:
> 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.

#ifdef __alpha_cix__
# define POPCNT(l) __builtin_popcountl (l)
#endif


r~

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

* Re: [PATCH] Optimized __sched_cpucount for alphaev67, power5 and above and ia64
  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 16:17 ` Richard Henderson
@ 2007-07-19 17:26 ` Ulrich Drepper
  2 siblings, 0 replies; 7+ messages in thread
From: Ulrich Drepper @ 2007-07-19 17:26 UTC (permalink / raw)
  To: Jakub Jelinek; +Cc: Glibc hackers, Richard Henderson

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

I left out the Alpha version since after rth's comment I don't know
where in the alpha hierarchy the file should be placed.  Richard, please
check in an appropriate file.

- --
➧ Ulrich Drepper ➧ Red Hat, Inc. ➧ 444 Castro St ➧ Mountain View, CA ❖
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.7 (GNU/Linux)

iD8DBQFGn56b2ijCOnn/RHQRAg7DAJ9r/Y2LhdEqZxsr0ULwy/YRiTqxoQCgxWtX
zmSXaozH3EYgAvQ50OXAV5I=
=/xEI
-----END PGP SIGNATURE-----

^ 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).