From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-qk1-x72d.google.com (mail-qk1-x72d.google.com [IPv6:2607:f8b0:4864:20::72d]) by sourceware.org (Postfix) with ESMTPS id 88CBC3857C59 for ; Wed, 5 May 2021 16:53:02 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 88CBC3857C59 Received: by mail-qk1-x72d.google.com with SMTP id 76so2146839qkn.13 for ; Wed, 05 May 2021 09:53:02 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:from:to:references:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=dhRjW+gMf5266GjQ+GCDt9f6C7MJtoOR9XzkwyleKqY=; b=qj6rp2ppK/GAl2zDp7glfpajG1abvnyw5sPN5YVRo2Sg+VE/7Zd43YQty00ZvQgcb0 ogMlKv/fWRoiNdCuw9MNeWjY+oPkc5Id7yep1lNURRD+/98PBFGcRn0wHTVD7pTdL0q5 6Qlul1ioKclphGTbGqN/MBcwIULk0azyrV6vkdGkm3Y6Fv5WBz2X/yu4YplrmRES4p73 MbWgymnodCabuCAmZo8a3wQknuGJmgRORv4qW7IZ26Q02MXaHO5wyohuwZACC1DREfp+ u7NuTgZMoO7Pudx/pjABfiMeL8ovESJcLH5ysKB/Spxj+wnmoy5ge5sws8q+Kd53Frag bbuQ== X-Gm-Message-State: AOAM533rG3jQd4mB6HLQaxK+MqhmZ/PATfjl9s6C69UkH7vsZBeFZy9n M/SxQFcGfPZvlyP6diMRXx4fmls+In79xQ== X-Google-Smtp-Source: ABdhPJxGEKEsBl+WXTeqMXVKhkEJob4Rvtq5NdO2LNma6VCSO691gPNcGmLSb3vZAs4DdV+0c2TCaQ== X-Received: by 2002:a37:270d:: with SMTP id n13mr28201348qkn.146.1620233581463; Wed, 05 May 2021 09:53:01 -0700 (PDT) Received: from [192.168.1.4] ([177.194.37.86]) by smtp.gmail.com with ESMTPSA id r5sm5254744qtp.75.2021.05.05.09.53.00 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 05 May 2021 09:53:01 -0700 (PDT) Subject: Re: [PATCH 1/4] Remove architecture specific sched_cpucount optimizations From: Adhemerval Zanella To: libc-alpha@sourceware.org References: <20210329182520.323665-1-adhemerval.zanella@linaro.org> Message-ID: Date: Wed, 5 May 2021 13:52:58 -0300 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.8.1 MIME-Version: 1.0 In-Reply-To: <20210329182520.323665-1-adhemerval.zanella@linaro.org> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-12.8 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_SHORT, NICE_REPLY_A, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 05 May 2021 16:53:04 -0000 Ping. On 29/03/2021 15:25, Adhemerval Zanella wrote: > And replace the generic algorithm with the Brian Kernighan’s one. > GCC optimize it with popcnt if the architecture supports, so there > is no need to add the extra POPCNT define to enable it. > > This is really a micro-optimization that only adds complexity: > recent ABIs already support it (x86-64-v2 or power64le) and it > simplifies the code for internal usage, since i686 does not allow an > internal iFUNC call. > > Checked on x86_64-linux-gnu, aarch64-linux-gnu, and > powerpc64le-linux-gnu. > --- > posix/sched_cpucount.c | 28 +++------------ > sysdeps/i386/i686/multiarch/sched_cpucount.c | 1 - > sysdeps/ia64/sched_cpucount.c | 20 ----------- > sysdeps/powerpc/sched_cpucount.c | 22 ------------ > sysdeps/x86_64/multiarch/sched_cpucount.c | 36 -------------------- > sysdeps/x86_64/sched_cpucount.c | 25 -------------- > 6 files changed, 4 insertions(+), 128 deletions(-) > delete mode 100644 sysdeps/i386/i686/multiarch/sched_cpucount.c > delete mode 100644 sysdeps/ia64/sched_cpucount.c > delete mode 100644 sysdeps/powerpc/sched_cpucount.c > delete mode 100644 sysdeps/x86_64/multiarch/sched_cpucount.c > delete mode 100644 sysdeps/x86_64/sched_cpucount.c > > diff --git a/posix/sched_cpucount.c b/posix/sched_cpucount.c > index b0ca4ea7bc..529286e777 100644 > --- a/posix/sched_cpucount.c > +++ b/posix/sched_cpucount.c > @@ -22,31 +22,11 @@ int > __sched_cpucount (size_t setsize, const cpu_set_t *setp) > { > int s = 0; > - const __cpu_mask *p = setp->__bits; > - const __cpu_mask *end = &setp->__bits[setsize / sizeof (__cpu_mask)]; > - > - while (p < end) > + for (int i = 0; i < setsize / sizeof (__cpu_mask); i++) > { > - __cpu_mask l = *p++; > - > -#ifdef POPCNT > - s += POPCNT (l); > -#else > - if (l == 0) > - continue; > - > - _Static_assert (sizeof (l) == sizeof (unsigned int) > - || sizeof (l) == sizeof (unsigned long) > - || sizeof (l) == sizeof (unsigned long long), > - "sizeof (__cpu_mask"); > - if (sizeof (__cpu_mask) == sizeof (unsigned int)) > - s += __builtin_popcount (l); > - else if (sizeof (__cpu_mask) == sizeof (unsigned long)) > - s += __builtin_popcountl (l); > - else > - s += __builtin_popcountll (l); > -#endif > + __cpu_mask si = setp->__bits[i]; > + /* Clear the least significant bit set. */ > + for (; si != 0; si &= si - 1, s++); > } > - > return s; > } > diff --git a/sysdeps/i386/i686/multiarch/sched_cpucount.c b/sysdeps/i386/i686/multiarch/sched_cpucount.c > deleted file mode 100644 > index 7db31b02f8..0000000000 > --- a/sysdeps/i386/i686/multiarch/sched_cpucount.c > +++ /dev/null > @@ -1 +0,0 @@ > -#include > diff --git a/sysdeps/ia64/sched_cpucount.c b/sysdeps/ia64/sched_cpucount.c > deleted file mode 100644 > index 8440864b02..0000000000 > --- a/sysdeps/ia64/sched_cpucount.c > +++ /dev/null > @@ -1,20 +0,0 @@ > -/* Copyright (C) 2007-2021 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, see > - . */ > - > -#define POPCNT(l) __builtin_popcountl (l) > - > -#include > diff --git a/sysdeps/powerpc/sched_cpucount.c b/sysdeps/powerpc/sched_cpucount.c > deleted file mode 100644 > index 8f00e3dbc8..0000000000 > --- a/sysdeps/powerpc/sched_cpucount.c > +++ /dev/null > @@ -1,22 +0,0 @@ > -/* Copyright (C) 2007-2021 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, see > - . */ > - > -#ifdef _ARCH_PWR5 > -# define POPCNT(l) __builtin_popcountl (l) > -#endif > - > -#include > diff --git a/sysdeps/x86_64/multiarch/sched_cpucount.c b/sysdeps/x86_64/multiarch/sched_cpucount.c > deleted file mode 100644 > index 5180a11434..0000000000 > --- a/sysdeps/x86_64/multiarch/sched_cpucount.c > +++ /dev/null > @@ -1,36 +0,0 @@ > -/* Count bits in CPU set. x86-64 multi-arch version. > - This file is part of the GNU C Library. > - Copyright (C) 2008-2021 Free Software Foundation, Inc. > - Contributed by Ulrich Drepper . > - > - 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, see > - . */ > - > -#include > -#include "init-arch.h" > - > -#define __sched_cpucount static generic_cpucount > -#include > -#undef __sched_cpucount > - > -#define POPCNT(l) \ > - ({ __cpu_mask r; \ > - asm ("popcnt %1, %0" : "=r" (r) : "0" (l));\ > - r; }) > -#define __sched_cpucount static popcount_cpucount > -#include > -#undef __sched_cpucount > - > -libc_ifunc (__sched_cpucount, > - CPU_FEATURE_USABLE (POPCNT) ? popcount_cpucount : generic_cpucount); > diff --git a/sysdeps/x86_64/sched_cpucount.c b/sysdeps/x86_64/sched_cpucount.c > deleted file mode 100644 > index 5a27336d6d..0000000000 > --- a/sysdeps/x86_64/sched_cpucount.c > +++ /dev/null > @@ -1,25 +0,0 @@ > -/* Copyright (C) 2007-2021 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, see > - . */ > - > -#ifdef __amdfam10 > -# define POPCNT(l) \ > - ({ __cpu_mask r; \ > - asm ("popcntq %1, %0" : "=r" (r) : "0" (l)); \ > - r; }) > -#endif > - > -#include >