From: Jakub Jelinek <jakub@redhat.com>
To: Ulrich Drepper <drepper@redhat.com>
Cc: Glibc hackers <libc-hacker@sources.redhat.com>,
Richard Henderson <rth@redhat.com>,
Steven Munroe <munroesj@us.ibm.com>
Subject: [PATCH] Optimized __sched_cpucount for alphaev67, power5 and above and ia64
Date: Tue, 17 Jul 2007 20:43:00 -0000 [thread overview]
Message-ID: <20070717204719.GY4603@sunsite.mff.cuni.cz> (raw)
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
next reply other threads:[~2007-07-17 20:43 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-07-17 20:43 Jakub Jelinek [this message]
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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20070717204719.GY4603@sunsite.mff.cuni.cz \
--to=jakub@redhat.com \
--cc=drepper@redhat.com \
--cc=libc-hacker@sources.redhat.com \
--cc=munroesj@us.ibm.com \
--cc=rth@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).