From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 6231 invoked by alias); 17 Jul 2007 20:43:53 -0000 Received: (qmail 6215 invoked by uid 22791); 17 Jul 2007 20:43:53 -0000 X-Spam-Check-By: sourceware.org Received: from sunsite.ms.mff.cuni.cz (HELO sunsite.mff.cuni.cz) (195.113.15.26) by sourceware.org (qpsmtpd/0.31) with ESMTP; Tue, 17 Jul 2007 20:43:49 +0000 Received: from sunsite.mff.cuni.cz (localhost.localdomain [127.0.0.1]) by sunsite.mff.cuni.cz (8.13.8/8.13.8) with ESMTP id l6HKlKrc011647; Tue, 17 Jul 2007 22:47:20 +0200 Received: (from jakub@localhost) by sunsite.mff.cuni.cz (8.13.8/8.13.8/Submit) id l6HKlJNa011646; Tue, 17 Jul 2007 22:47:19 +0200 Date: Tue, 17 Jul 2007 20:43:00 -0000 From: Jakub Jelinek To: Ulrich Drepper Cc: Glibc hackers , Richard Henderson , Steven Munroe Subject: [PATCH] Optimized __sched_cpucount for alphaev67, power5 and above and ia64 Message-ID: <20070717204719.GY4603@sunsite.mff.cuni.cz> Reply-To: Jakub Jelinek Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.4.2.2i Mailing-List: contact libc-hacker-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: libc-hacker-owner@sourceware.org X-SW-Source: 2007-07/txt/msg00028.txt.bz2 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 * 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 --- 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 --- 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 Jakub