From patchwork Mon Mar 29 18:25:17 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Adhemerval Zanella X-Patchwork-Id: 42798 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id E1D563861031; Mon, 29 Mar 2021 18:25:28 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org E1D563861031 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1617042328; bh=L0vXJoXYexsKYz2SzkD2dVuT1wu35/3ZXFjzOYizygg=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:Cc:From; b=Mqw09eJrUYdaPMxNVafu+AFM/tf/6ODW5a3TNUV/2gBCMLNicfiukQGXRPK/xpvIq 6S3aPyVLy6a/cJBJPHKuuTrB2Y/FCzVU30lZjC/99ooMg+OKpWRkkQFmfsAShd2wbw 3vKmkzdO7fuCHfb0wSRXx+jNe3/LuDXKLudUxhUQ= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-qt1-x832.google.com (mail-qt1-x832.google.com [IPv6:2607:f8b0:4864:20::832]) by sourceware.org (Postfix) with ESMTPS id 41E0D3851C3E for ; Mon, 29 Mar 2021 18:25:26 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 41E0D3851C3E Received: by mail-qt1-x832.google.com with SMTP id x9so9980099qto.8 for ; Mon, 29 Mar 2021 11:25:26 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=L0vXJoXYexsKYz2SzkD2dVuT1wu35/3ZXFjzOYizygg=; b=GzCoVVTwS33p5xt8ISvs/+ArtE2DaNA7COeSFKekVftzPNtBxTRgERF1rO3iciEHMs JLLT9GiqVOq0b/DWb8k7rt5TzbU3eEPcWOWwz1xxr7TUQV/hBBkBYqeATf0P3u+1WPhQ xGib6wfeR9uEGlvJJQ0b+mWZ9oq5nFid1MyQkk3G0DBdcbDV3GCsRwQP0NLOt+G3ge7t swqGn8TlQDp6CATCmlHkFJkAF4UZdoMDBiL83QDooEpEswZ2Ap9yTTp65GF4CLTHOGwf tQq0x5UBcH0JpNr7jVkBiLTa/Z6V57ZnpS9YbInOEgIYaTfjVm3mT39w62CeVQYpWsEc 9DXA== X-Gm-Message-State: AOAM531JDSTSWgumJcShLZ2ACD2tm/DtPBN2blD/qOgkz+Ae/tStPAzh 7ll2wj2FMw2KPbjejcgm6D2j5n8KmDAl2vvq X-Google-Smtp-Source: ABdhPJxO2rfP1Jj9jQ0VlVxnLYtABmEheaEDUKZsajvJCH7LmPDLv0Mmli7ENfxrzz44hgLeYSB4Sg== X-Received: by 2002:ac8:5716:: with SMTP id 22mr24518782qtw.212.1617042325350; Mon, 29 Mar 2021 11:25:25 -0700 (PDT) Received: from localhost.localdomain ([177.194.41.149]) by smtp.googlemail.com with ESMTPSA id o7sm14009565qkb.104.2021.03.29.11.25.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 29 Mar 2021 11:25:24 -0700 (PDT) To: libc-alpha@sourceware.org Subject: [PATCH 1/4] Remove architecture specific sched_cpucount optimizations Date: Mon, 29 Mar 2021 15:25:17 -0300 Message-Id: <20210329182520.323665-1-adhemerval.zanella@linaro.org> X-Mailer: git-send-email 2.27.0 MIME-Version: 1.0 X-Spam-Status: No, score=-12.5 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_SHORT, 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-Patchwork-Original-From: Adhemerval Zanella via Libc-alpha From: Adhemerval Zanella Reply-To: Adhemerval Zanella Cc: crrodriguez@opensuse.org Errors-To: libc-alpha-bounces@sourceware.org Sender: "Libc-alpha" 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