From patchwork Mon Apr 22 07:43:57 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Christoph_M=C3=BCllner?= X-Patchwork-Id: 88835 X-Patchwork-Delegate: carlos@redhat.com 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 60FD2384AB51 for ; Mon, 22 Apr 2024 07:47:32 +0000 (GMT) X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-lf1-x12e.google.com (mail-lf1-x12e.google.com [IPv6:2a00:1450:4864:20::12e]) by sourceware.org (Postfix) with ESMTPS id 9A7DD3858C60 for ; Mon, 22 Apr 2024 07:44:14 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 9A7DD3858C60 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=vrull.eu Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=vrull.eu ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 9A7DD3858C60 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2a00:1450:4864:20::12e ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1713771856; cv=none; b=QKD5aKSKDlOzv73jN3m4OVHlUc66SyZ4MoCvUFVjlwpPI3fn3pwi/MoLbb5iAu4jdp2yNgz/n64HCZ7rCyE3q53BK78/73NSMScfTqh8BWpg8ZLefv33L+DBeDhlWXVBXDMXXu3+LIflKU5A9TSPOqTt5ya2yDdwVjHPidxYHFg= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1713771856; c=relaxed/simple; bh=3/fxpelQ2Av16MCnMuagbkqAnXGWINVcQDTDTABqfk0=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=BMyptg/icU368WZmky/k3v/z1ES0f31hJyaXaNiUO0InpCauG3nlJIrpiHNiyublF2i2MZqSXVWTokcRXUYfNwfq6Wjwpml/BbuOc5UsKBX7yXcn0ZuGyUuu69m0KZuqCGKspXZkNfXi7eHiKHh/mu7TaeINrCknmQ7Vkj5+7mA= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-lf1-x12e.google.com with SMTP id 2adb3069b0e04-51abd580902so2419835e87.1 for ; Mon, 22 Apr 2024 00:44:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=vrull.eu; s=google; t=1713771852; x=1714376652; darn=sourceware.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=416+1tdsIRVXk6pQDrXQE9MfDyfmuQt9MJ051c/pATA=; b=aUlQyhJ2ACPcSe7FE766jY9/BwkX7lOB9Y8b7Mcd9RFIYSZhsUAuaEkqChuPzqIkLr +T/VQugL306BNPjZ+VUmxHaojOXAU38WkYVbozldEHCMA0S/IjHP1macQFK19geuItJp 3JRtL5KJ/8d8k8nw77IcDsdJQR49xEPPMHJ3r9DMhrLfxT+dA/kAA3hvQ2SluDJcFWJ7 b2tLQPTFmoJDqSCeUxzB3iXgrZHO3kSF3mZVhgv0UuSJvRfoXx6xOfw6Z7dOpOSS17Vf PK1uWvrIEHtTYyQSEdEjyLKfKywqX1jRgizoKk9IbQ5HitToFYZlTBoclya5HI8tuo86 8/RA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1713771852; x=1714376652; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=416+1tdsIRVXk6pQDrXQE9MfDyfmuQt9MJ051c/pATA=; b=VoCYN2Qc8wWGr87mG5v16u0osMA0poCCNqysFjbormag4uQTm9MHgac/BioIALRIBf IBCWttPHAoFcK1ASdLJ+cK0ZBCFNsbhZu6C2JJYPac5ixAGLBz6v3TNlGTRQPQaqZ0vK oe5Bxn4Oikqo02yy9At+PxrDJw4gw7qpMCUcQr0Rj0hBMdt9LuKr6lO+e4TyiSfZFlzZ l75ozUbXoGw++mcKsMboGGJt2JnLAvT5owYdMAZLqHwYQNlKAUH8FBtDKcsyqXD8zSsn qoiAvLAeIM5rIqRJ7aH9c2TRe1gAishTgpzA0z3ao4wP8z4eJ/1ZSDOviyJE7QeE3zBR opIQ== X-Gm-Message-State: AOJu0YwDnTPoH1OLWcIGGb6HCC8Qc08cStxXS17wz8PvCo3S5k+a0nb5 l0CPz1KpV2HdAfZsuwsIUy9fcL+8swYZhxiXMEw3oUjllh+4kJkPl6TdaNyT0fAOvhOtrzqOZ49 jXe4= X-Google-Smtp-Source: AGHT+IF73LqkgYV4C2mjzX2On6T697wY3IBRkqzEmRYjvMctLU6NIr3MkDeNv0ovXqBP2Tl5LgR7eA== X-Received: by 2002:ac2:4a84:0:b0:51a:cd25:4383 with SMTP id l4-20020ac24a84000000b0051acd254383mr2159631lfp.4.1713771852089; Mon, 22 Apr 2024 00:44:12 -0700 (PDT) Received: from beast.fritz.box (static.239.130.217.95.clients.your-server.de. [95.217.130.239]) by smtp.gmail.com with ESMTPSA id v24-20020a197418000000b0051920234d6dsm1656756lfe.273.2024.04.22.00.44.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 22 Apr 2024 00:44:11 -0700 (PDT) From: =?utf-8?q?Christoph_M=C3=BCllner?= To: libc-alpha@sourceware.org, Adhemerval Zanella , Palmer Dabbelt , Darius Rad , Andrew Waterman , Philipp Tomsich , Evan Green , DJ Delorie , Vineet Gupta , Kito Cheng , Jeff Law Cc: =?utf-8?q?Christoph_M=C3=BCllner?= Subject: [PATCH 1/7] RISC-V: Use .insn directive form for orc.b Date: Mon, 22 Apr 2024 09:43:57 +0200 Message-ID: <20240422074403.2399529-2-christoph.muellner@vrull.eu> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240422074403.2399529-1-christoph.muellner@vrull.eu> References: <20240422074403.2399529-1-christoph.muellner@vrull.eu> MIME-Version: 1.0 X-Spam-Status: No, score=-12.4 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_MANYTO, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libc-alpha-bounces+patchwork=sourceware.org@sourceware.org The orc.b instruction is part of the Zbb extension, which was ratified in 2021. GAS releases older than that won't know of the instruction. Newer GAS releases accepted orc.b only if Zbb is enabled in the -march string. This patch changes the inline asm for orc.b to the '.insn' directive form, which allows (future changes) to build orc.b-optimized routines by defining the Zbb feature test macro (__riscv_zbb). Building optimized routines this way is compatible with releases of GAS with and without Zbb support. Signed-off-by: Christoph Müllner --- sysdeps/riscv/string-fza.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/sysdeps/riscv/string-fza.h b/sysdeps/riscv/string-fza.h index ee5c31317f..47b1fd152f 100644 --- a/sysdeps/riscv/string-fza.h +++ b/sysdeps/riscv/string-fza.h @@ -36,7 +36,8 @@ find_zero_all (op_t x) asm ("th.tstnbz %0, %1" : "=r" (r) : "r" (x)); return r; #else - asm ("orc.b %0, %1" : "=r" (r) : "r" (x)); + /* orc.b using the .insn directive (supported by older Binutils releases). */ + asm (".insn i 0x13, 0x5, %0, %1, 0x287" : "=r" (r) : "r" (x)); return ~r; #endif } From patchwork Mon Apr 22 07:43:58 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Christoph_M=C3=BCllner?= X-Patchwork-Id: 88831 X-Patchwork-Delegate: carlos@redhat.com 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 855A0384AB50 for ; Mon, 22 Apr 2024 07:44:55 +0000 (GMT) X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-lf1-x12f.google.com (mail-lf1-x12f.google.com [IPv6:2a00:1450:4864:20::12f]) by sourceware.org (Postfix) with ESMTPS id EA709384AB61 for ; Mon, 22 Apr 2024 07:44:15 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org EA709384AB61 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=vrull.eu Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=vrull.eu ARC-Filter: OpenARC Filter v1.0.0 sourceware.org EA709384AB61 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2a00:1450:4864:20::12f ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1713771858; cv=none; b=b38T9xahP/ISTcGVFGgcqtrOhAlLgnxhtls+17Xw/E0GiMl5yEe3KS3yQ4JgRCyCiylB2DcnuKuUOmlcDanFkyK5gTVBvEaGbp8h07JcbndV6ssL/4+i+9pjN8venGJmRgpp6ML0Apdj7KZ4Qia0oWDlUD7SKKdkkALTd/xnhj4= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1713771858; c=relaxed/simple; bh=xfxG74dcwYHPuac+l6Z7D3z7QOsCPn6nNqy4bv1cT4w=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=AaWC/bTE5g25tF4c8u6txKrjv2Kg+nSNZsggBmnUgUpAxvTx440oTM6h546fxzpZzG/u6y/mpQtkj5/7FzAluDYTdeg/Ydb073pQ+6Up8JD+0TA6cNLvnDuL0uW0YByTe2OLmL+1YKq2+66y5rUZ3YlE+BSMgi9Re90piH174Ew= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-lf1-x12f.google.com with SMTP id 2adb3069b0e04-518931f8d23so4137329e87.3 for ; Mon, 22 Apr 2024 00:44:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=vrull.eu; s=google; t=1713771854; x=1714376654; darn=sourceware.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=UYhvnRUeQ3CrcEfjA4ORCLHqyO9rIzqltCntHPasd9o=; b=Zb/DBFykiBL6sDZLmDbeWrrlbx+/FwEchvbdZkI2nMGB6xv+L42UyfbGJEjy/bEi5j RKB5DFIRkW6zb2mOGspIga8ZoCuPGxn3jttJYlvvYqHZP+7bJJBIzrv05zRttpzAp/u5 ao1ENelj6EfEq9RxMxhNCHK0qsTvcNqg+hFc9cUIHMbXvuc7ktBr9m7dGE12ranBV0IC 4KhnQVxeKaa2k4HlyVcTgWgmFJd8/5UYimP71tt2RDk2vKVxxw/dzFlnJQHRLl3GjJol fP9GkTQeFZoicFcUhiyngfb1s3PlYDlst+eDsEDGKBz9FOngTKG+S7JcFzWM7K33gj7/ Pnnw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1713771854; x=1714376654; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=UYhvnRUeQ3CrcEfjA4ORCLHqyO9rIzqltCntHPasd9o=; b=fCt7NSpjDaQTspkNs1kwe+MutXs3Lkf04fu8KH0xX/LItuoFmj8mH7QutHHOifRkig XRdQvJQNC8L8lovjBI1L55Y7vZeKwoKusUFIj0zAKq7QrFKxdf2u4mZW0yHBGQUSooZM jegO5PltBwdePrXNvS6WE6P7MMdMm/3z5FYnQw6POu7h+srxk3KA+LKWYZBysHSXRRzz WBctnzYZ1t00cA8QuVgTDaHLiKfMaTid9GJUjjxyhaMygwPrEUC1yarecuNlgkL1/k2p Vm+pxFaowLyupQmPlDFzPYc2fwXhvt5K++DytQKZUhVDNDFRvQG0PutrkioLVPeiK8Fz mhjw== X-Gm-Message-State: AOJu0YylKcWuxUT4gKKAXwQsNDCrnhIo9Br/apwBX9RBn4PmriKLbOOv 5mNWexEndKYEW2+8/M8f2LMwmXvHqxJ+kEnptcbIB3r4V35cZLkXvVhk+/534EXWVj+lS4R/3+I O+4E= X-Google-Smtp-Source: AGHT+IEfJB8xJnETtyhgOzZO8bw3q/rO3rwIa37lNVLuHuHymcIUrM7MulZiqFgdaHTH6cSiaQ/Xrw== X-Received: by 2002:ac2:57ce:0:b0:516:d1bd:7743 with SMTP id k14-20020ac257ce000000b00516d1bd7743mr4639463lfo.64.1713771853744; Mon, 22 Apr 2024 00:44:13 -0700 (PDT) Received: from beast.fritz.box (static.239.130.217.95.clients.your-server.de. [95.217.130.239]) by smtp.gmail.com with ESMTPSA id v24-20020a197418000000b0051920234d6dsm1656756lfe.273.2024.04.22.00.44.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 22 Apr 2024 00:44:13 -0700 (PDT) From: =?utf-8?q?Christoph_M=C3=BCllner?= To: libc-alpha@sourceware.org, Adhemerval Zanella , Palmer Dabbelt , Darius Rad , Andrew Waterman , Philipp Tomsich , Evan Green , DJ Delorie , Vineet Gupta , Kito Cheng , Jeff Law Cc: =?utf-8?q?Christoph_M=C3=BCllner?= Subject: [PATCH 2/7] RISC-V: Add Zbb optimized memchr as ifunc Date: Mon, 22 Apr 2024 09:43:58 +0200 Message-ID: <20240422074403.2399529-3-christoph.muellner@vrull.eu> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240422074403.2399529-1-christoph.muellner@vrull.eu> References: <20240422074403.2399529-1-christoph.muellner@vrull.eu> 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_MANYTO, KAM_SHORT, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libc-alpha-bounces+patchwork=sourceware.org@sourceware.org When building with Zbb enabled, memchr benefits from using orc.b in find_zero_all(). This patch changes the build system such, that a non-Zbb version as well as a Zbb version of this routine is built. Further, a ifunc resolver is provided that selects the right routine based on the outcome of extension probing via hwprobe(). Signed-off-by: Christoph Müllner --- sysdeps/riscv/multiarch/memchr-generic.c | 26 +++++++++ sysdeps/riscv/multiarch/memchr-zbb.c | 30 ++++++++++ .../unix/sysv/linux/riscv/multiarch/Makefile | 3 + .../linux/riscv/multiarch/ifunc-impl-list.c | 31 ++++++++-- .../unix/sysv/linux/riscv/multiarch/memchr.c | 57 +++++++++++++++++++ 5 files changed, 142 insertions(+), 5 deletions(-) create mode 100644 sysdeps/riscv/multiarch/memchr-generic.c create mode 100644 sysdeps/riscv/multiarch/memchr-zbb.c create mode 100644 sysdeps/unix/sysv/linux/riscv/multiarch/memchr.c diff --git a/sysdeps/riscv/multiarch/memchr-generic.c b/sysdeps/riscv/multiarch/memchr-generic.c new file mode 100644 index 0000000000..a96c36398b --- /dev/null +++ b/sysdeps/riscv/multiarch/memchr-generic.c @@ -0,0 +1,26 @@ +/* Re-include the default memchr implementation. + Copyright (C) 2024 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 + . */ + +#include + +#if IS_IN(libc) +# define MEMCHR __memchr_generic +# undef libc_hidden_builtin_def +# define libc_hidden_builtin_def(x) +#endif +#include diff --git a/sysdeps/riscv/multiarch/memchr-zbb.c b/sysdeps/riscv/multiarch/memchr-zbb.c new file mode 100644 index 0000000000..bead0335ae --- /dev/null +++ b/sysdeps/riscv/multiarch/memchr-zbb.c @@ -0,0 +1,30 @@ +/* Re-include the default memchr implementation for Zbb. + Copyright (C) 2024 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 + . */ + +#include + +#if IS_IN(libc) +# define MEMCHR __memchr_zbb +# undef libc_hidden_builtin_def +# define libc_hidden_builtin_def(x) +#endif +/* Convince preprocessor to have Zbb instructions. */ +#ifndef __riscv_zbb +# define __riscv_zbb +#endif +#include diff --git a/sysdeps/unix/sysv/linux/riscv/multiarch/Makefile b/sysdeps/unix/sysv/linux/riscv/multiarch/Makefile index fcef5659d4..5586d11c89 100644 --- a/sysdeps/unix/sysv/linux/riscv/multiarch/Makefile +++ b/sysdeps/unix/sysv/linux/riscv/multiarch/Makefile @@ -1,5 +1,8 @@ ifeq ($(subdir),string) sysdep_routines += \ + memchr \ + memchr-generic \ + memchr-zbb \ memcpy \ memcpy-generic \ memcpy_noalignment \ diff --git a/sysdeps/unix/sysv/linux/riscv/multiarch/ifunc-impl-list.c b/sysdeps/unix/sysv/linux/riscv/multiarch/ifunc-impl-list.c index 9f806d7a9e..7321144a32 100644 --- a/sysdeps/unix/sysv/linux/riscv/multiarch/ifunc-impl-list.c +++ b/sysdeps/unix/sysv/linux/riscv/multiarch/ifunc-impl-list.c @@ -20,19 +20,40 @@ #include #include +#define ARRAY_SIZE(A) (sizeof (A) / sizeof ((A)[0])) + size_t __libc_ifunc_impl_list (const char *name, struct libc_ifunc_impl *array, size_t max) { size_t i = max; + struct riscv_hwprobe pairs[] = { + { .key = RISCV_HWPROBE_KEY_IMA_EXT_0 }, + { .key = RISCV_HWPROBE_KEY_CPUPERF_0 }, + }; + bool has_zbb = false; bool fast_unaligned = false; - struct riscv_hwprobe pair = { .key = RISCV_HWPROBE_KEY_CPUPERF_0 }; - if (__riscv_hwprobe (&pair, 1, 0, NULL, 0) == 0 - && (pair.value & RISCV_HWPROBE_MISALIGNED_MASK) - == RISCV_HWPROBE_MISALIGNED_FAST) - fast_unaligned = true; + if (__riscv_hwprobe (pairs, ARRAY_SIZE (pairs), 0, NULL, 0) == 0) + { + struct riscv_hwprobe *pair; + + /* RISCV_HWPROBE_KEY_IMA_EXT_0 */ + pair = &pairs[0]; + if (pair->value & RISCV_HWPROBE_EXT_ZBB) + has_zbb = true; + + /* RISCV_HWPROBE_KEY_CPUPERF_0 */ + pair = &pairs[1]; + if ((pair->value & RISCV_HWPROBE_MISALIGNED_MASK) + == RISCV_HWPROBE_MISALIGNED_FAST) + fast_unaligned = true; + } + + IFUNC_IMPL (i, name, memchr, + IFUNC_IMPL_ADD (array, i, memchr, has_zbb, __memchr_zbb) + IFUNC_IMPL_ADD (array, i, memchr, 1, __memchr_generic)) IFUNC_IMPL (i, name, memcpy, IFUNC_IMPL_ADD (array, i, memcpy, fast_unaligned, diff --git a/sysdeps/unix/sysv/linux/riscv/multiarch/memchr.c b/sysdeps/unix/sysv/linux/riscv/multiarch/memchr.c new file mode 100644 index 0000000000..bc076cbf24 --- /dev/null +++ b/sysdeps/unix/sysv/linux/riscv/multiarch/memchr.c @@ -0,0 +1,57 @@ +/* Multiple versions of memchr. + All versions must be listed in ifunc-impl-list.c. + Copyright (C) 2017-2024 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 + . */ + +#if IS_IN (libc) +/* Redefine memchr so that the compiler won't complain about the type + mismatch with the IFUNC selector in strong_alias, below. */ +# undef memchr +# define memchr __redirect_memchr +# include +# include +# include +# include +# include + +extern __typeof (__redirect_memchr) __libc_memchr; + +extern __typeof (__redirect_memchr) __memchr_generic attribute_hidden; +extern __typeof (__redirect_memchr) __memchr_zbb attribute_hidden; + +static inline __typeof (__redirect_memchr) * +select_memchr_ifunc (uint64_t dl_hwcap, __riscv_hwprobe_t hwprobe_func) +{ + unsigned long long int v; + if (__riscv_hwprobe_one (hwprobe_func, RISCV_HWPROBE_KEY_IMA_EXT_0, &v) == 0 + && (v & RISCV_HWPROBE_EXT_ZBB)) + return __memchr_zbb; + + return __memchr_generic; +} + +riscv_libc_ifunc (__libc_memchr, select_memchr_ifunc); + +# undef memchr +strong_alias (__libc_memchr, memchr); +# ifdef SHARED +__hidden_ver1 (memchr, __GI_memchr, __redirect_memchr) + __attribute__ ((visibility ("hidden"))) __attribute_copy__ (memchr); +# endif +#else +# include +#endif From patchwork Mon Apr 22 07:43:59 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Christoph_M=C3=BCllner?= X-Patchwork-Id: 88836 X-Patchwork-Delegate: carlos@redhat.com 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 823F43858C66 for ; Mon, 22 Apr 2024 07:48:16 +0000 (GMT) X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-lf1-x12a.google.com (mail-lf1-x12a.google.com [IPv6:2a00:1450:4864:20::12a]) by sourceware.org (Postfix) with ESMTPS id 79EA9384AB51 for ; Mon, 22 Apr 2024 07:44:17 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 79EA9384AB51 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=vrull.eu Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=vrull.eu ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 79EA9384AB51 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2a00:1450:4864:20::12a ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1713771859; cv=none; b=PmdoKpSkRki8AgKGpCy+NUedUaYZnTlruioVSnU6LujP1OdFcSzYqWA+O5ucJMPeWjkTnfp6BOYMj3KuwxIPZBTfwTOwSR9NwJpym4l4id1gIZJWBJeTk6738LvlkNqF+WsmoQ04Ryf+STavrt2a7rHzrmJg0ZT+J74YvDxcN6s= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1713771859; c=relaxed/simple; bh=tmUgkM2rzq/f5IaXrXLMLR/lS18skn27dbtqZtJVEUQ=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=WNXO7tY5UjEADbgLXS7UTkRlhzhRLskhJMSILrEpYVfj4Grwt++Nz5Cx3j9+fKqJ8DMDpoo1Yzyq5D0aD68A1dTrJugAIkLMgQBbiwePmDXZiAVh6yO1cxFItXHAWVEM6S9013bQlMYT+LWdovI9ILMs2DI592zHoldODts85Os= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-lf1-x12a.google.com with SMTP id 2adb3069b0e04-516d2600569so5084242e87.0 for ; Mon, 22 Apr 2024 00:44:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=vrull.eu; s=google; t=1713771855; x=1714376655; darn=sourceware.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=SU8FBAiXzAb2KnaoarGGG4WXVqvRI5juh0tAbV5EEAQ=; b=MxwIsxYGlqOKqQTguBut+ZaJfsV9dln4xm03eXKcq1wvZvtIpelZx4rA13CJ557nS9 74QAebG/cdIwD0tHoQaMyhAe67Mmrud4s4Uo9hsOxR2pTJzCiBMFJKYN7LnBT78/2F7E DhkEFra41SAwNoCTUd+qyU0+Z0xgMsDi/t0jadbMpPUVZ7h1dZCh3KTCrH9z08yQvJ1F L9bHYQGEokKqqyQkd33ppRfSdjKf4Zq2RajI2uv/zKCR3hHLXBX6NzxMVfAEpGBPsOSz qZ/JN3lehwvCkyNH7736M+42bTZFrRSAlDgFcExNRXU0JKM1Fq/blQhM/c1boaTgcnT2 yz2Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1713771855; x=1714376655; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=SU8FBAiXzAb2KnaoarGGG4WXVqvRI5juh0tAbV5EEAQ=; b=K1aaz57i7QO1s1R5amZ8niYIJb56tBYIuhhq9/wUNU9jlG5ft5Wo1Un7DE+5vkYhMu xrX6Qq8j+ToYlIrMAzyrD3rtKFlxE8t9bNDlx9ayRnA/R7Yhmynaug0PSUT3lPbXEujp BsZhxOQVec17oXXcTk7Fyq5Vfx/WVjYXtp/RbkDt0o+eogmlo0TDCbJeH7n/z9zQgkmp MbgdWEzzFBQpnWScEzC77AFx8vq8m+vhJNfeQFpZBlupcyLFI7v4VTNXtDOS3xGmwd1w ONu340xJuRdq/Vn8Vsq5Sg/axtfT3+D3a/G3ZtJ26out//w2bRVaOBdpjximUrk/JiG3 uTrg== X-Gm-Message-State: AOJu0YxuMLDGpPtI+ord/DsqMQMacsnW6MVqACTZpD0dBwMHiw2hX8Xo jYwQhBNQuClamb9ygG7/LJEtUg5pi5jBv0FALqKXxgkK1Hfrha2MfF2Q3REAwUiepDj6ZQ62OFM tKeY= X-Google-Smtp-Source: AGHT+IEkvNyhGV4prdebKttXoGjIt5rk5cafthWUW6DLCv5IHiRJMrNrETX09lrAsf30+cBvivDaCA== X-Received: by 2002:ac2:41da:0:b0:51a:c8ba:d908 with SMTP id d26-20020ac241da000000b0051ac8bad908mr4908012lfi.62.1713771855337; Mon, 22 Apr 2024 00:44:15 -0700 (PDT) Received: from beast.fritz.box (static.239.130.217.95.clients.your-server.de. [95.217.130.239]) by smtp.gmail.com with ESMTPSA id v24-20020a197418000000b0051920234d6dsm1656756lfe.273.2024.04.22.00.44.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 22 Apr 2024 00:44:14 -0700 (PDT) From: =?utf-8?q?Christoph_M=C3=BCllner?= To: libc-alpha@sourceware.org, Adhemerval Zanella , Palmer Dabbelt , Darius Rad , Andrew Waterman , Philipp Tomsich , Evan Green , DJ Delorie , Vineet Gupta , Kito Cheng , Jeff Law Cc: =?utf-8?q?Christoph_M=C3=BCllner?= Subject: [PATCH 3/7] RISC-V: Add Zbb optimized memrchr as ifunc Date: Mon, 22 Apr 2024 09:43:59 +0200 Message-ID: <20240422074403.2399529-4-christoph.muellner@vrull.eu> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240422074403.2399529-1-christoph.muellner@vrull.eu> References: <20240422074403.2399529-1-christoph.muellner@vrull.eu> 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_MANYTO, KAM_SHORT, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libc-alpha-bounces+patchwork=sourceware.org@sourceware.org When building with Zbb enabled, memrchr benefits from using orc.b in find_zero_all(). This patch changes the build system such, that a non-Zbb version as well as a Zbb version of this routine is built. Further, a ifunc resolver is provided that selects the right routine based on the outcome of extension probing via hwprobe(). Signed-off-by: Christoph Müllner --- sysdeps/riscv/multiarch/memrchr-generic.c | 26 ++++++++ sysdeps/riscv/multiarch/memrchr-zbb.c | 30 +++++++++ .../unix/sysv/linux/riscv/multiarch/Makefile | 3 + .../linux/riscv/multiarch/ifunc-impl-list.c | 4 ++ .../unix/sysv/linux/riscv/multiarch/memrchr.c | 61 +++++++++++++++++++ 5 files changed, 124 insertions(+) create mode 100644 sysdeps/riscv/multiarch/memrchr-generic.c create mode 100644 sysdeps/riscv/multiarch/memrchr-zbb.c create mode 100644 sysdeps/unix/sysv/linux/riscv/multiarch/memrchr.c diff --git a/sysdeps/riscv/multiarch/memrchr-generic.c b/sysdeps/riscv/multiarch/memrchr-generic.c new file mode 100644 index 0000000000..7c1286cb60 --- /dev/null +++ b/sysdeps/riscv/multiarch/memrchr-generic.c @@ -0,0 +1,26 @@ +/* Re-include the default memrchr implementation. + Copyright (C) 2024 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 + . */ + +#include + +#if IS_IN(libc) +# define MEMRCHR __memrchr_generic +# undef libc_hidden_builtin_def +# define libc_hidden_builtin_def(x) +#endif +#include diff --git a/sysdeps/riscv/multiarch/memrchr-zbb.c b/sysdeps/riscv/multiarch/memrchr-zbb.c new file mode 100644 index 0000000000..c074c7607c --- /dev/null +++ b/sysdeps/riscv/multiarch/memrchr-zbb.c @@ -0,0 +1,30 @@ +/* Re-include the default memrchr implementation for Zbb. + Copyright (C) 2024 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 + . */ + +#include + +#if IS_IN(libc) +# define MEMRCHR __memrchr_zbb +# undef libc_hidden_builtin_def +# define libc_hidden_builtin_def(x) +#endif +/* Convince preprocessor to have Zbb instructions. */ +#ifndef __riscv_zbb +# define __riscv_zbb +#endif +#include diff --git a/sysdeps/unix/sysv/linux/riscv/multiarch/Makefile b/sysdeps/unix/sysv/linux/riscv/multiarch/Makefile index 5586d11c89..d36d0bd6dd 100644 --- a/sysdeps/unix/sysv/linux/riscv/multiarch/Makefile +++ b/sysdeps/unix/sysv/linux/riscv/multiarch/Makefile @@ -6,6 +6,9 @@ sysdep_routines += \ memcpy \ memcpy-generic \ memcpy_noalignment \ + memrchr \ + memrchr-generic \ + memrchr-zbb \ # sysdep_routines CFLAGS-memcpy_noalignment.c += -mno-strict-align diff --git a/sysdeps/unix/sysv/linux/riscv/multiarch/ifunc-impl-list.c b/sysdeps/unix/sysv/linux/riscv/multiarch/ifunc-impl-list.c index 7321144a32..f4ec58b9d8 100644 --- a/sysdeps/unix/sysv/linux/riscv/multiarch/ifunc-impl-list.c +++ b/sysdeps/unix/sysv/linux/riscv/multiarch/ifunc-impl-list.c @@ -60,5 +60,9 @@ __libc_ifunc_impl_list (const char *name, struct libc_ifunc_impl *array, __memcpy_noalignment) IFUNC_IMPL_ADD (array, i, memcpy, 1, __memcpy_generic)) + IFUNC_IMPL (i, name, memrchr, + IFUNC_IMPL_ADD (array, i, memrchr, has_zbb, __memrchr_zbb) + IFUNC_IMPL_ADD (array, i, memrchr, 1, __memrchr_generic)) + return 0; } diff --git a/sysdeps/unix/sysv/linux/riscv/multiarch/memrchr.c b/sysdeps/unix/sysv/linux/riscv/multiarch/memrchr.c new file mode 100644 index 0000000000..e19ac471c1 --- /dev/null +++ b/sysdeps/unix/sysv/linux/riscv/multiarch/memrchr.c @@ -0,0 +1,61 @@ +/* Multiple versions of memrchr. + All versions must be listed in ifunc-impl-list.c. + Copyright (C) 2017-2024 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 + . */ + +#if IS_IN (libc) +/* Redefine memrchr so that the compiler won't complain about the type + mismatch with the IFUNC selector in strong_alias, below. */ +# undef memrchr +# undef __memrchr +# define memrchr __redirect_memrchr +# define __memrchr __redirect___memrchr +# include +# include +# include +# include +# include + +extern __typeof (__redirect_memrchr) __libc_memrchr; + +extern __typeof (__redirect_memrchr) __memrchr_generic attribute_hidden; +extern __typeof (__redirect_memrchr) __memrchr_zbb attribute_hidden; + +static inline __typeof (__redirect_memrchr) * +select_memrchr_ifunc (uint64_t dl_hwcap, __riscv_hwprobe_t hwprobe_func) +{ + unsigned long long int v; + if (__riscv_hwprobe_one (hwprobe_func, RISCV_HWPROBE_KEY_IMA_EXT_0, &v) == 0 + && (v & RISCV_HWPROBE_EXT_ZBB)) + return __memrchr_zbb; + + return __memrchr_generic; +} + +riscv_libc_ifunc (__libc_memrchr, select_memrchr_ifunc); + +# undef memrchr +# undef __memrchr +strong_alias (__libc_memrchr, __memrchr); +weak_alias (__memrchr, memrchr) +# ifdef SHARED +__hidden_ver1 (memrchr, __GI___memrchr, __redirect_memrchr) + __attribute__ ((visibility ("hidden"))) __attribute_copy__ (memrchr); +# endif +#else +# include +#endif From patchwork Mon Apr 22 07:44:00 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Christoph_M=C3=BCllner?= X-Patchwork-Id: 88837 X-Patchwork-Delegate: carlos@redhat.com 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 B2637384AB5A for ; Mon, 22 Apr 2024 07:49:04 +0000 (GMT) X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-lf1-x12c.google.com (mail-lf1-x12c.google.com [IPv6:2a00:1450:4864:20::12c]) by sourceware.org (Postfix) with ESMTPS id 3DD0A385841E for ; Mon, 22 Apr 2024 07:44:19 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 3DD0A385841E Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=vrull.eu Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=vrull.eu ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 3DD0A385841E Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2a00:1450:4864:20::12c ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1713771862; cv=none; b=d59M/7rMQaebCkTOJronT2od7WWUvaXHSrub398kW699/25pYLPFFmUcAOOcz35IQn6UNEoYemDw3PNQkewjEcuB/IGYdudR43+cFJM3Bew9XnuliqNPHmXelVmQUl7XIKC8TMIhpCZvkbHrNsHDYmDiUdh5C54J2K/WLxReIm8= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1713771862; c=relaxed/simple; bh=/cPzskJE/LqKLibOoBbZ5MWFdhzcIvd5h28O+OV0nWQ=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=DSXnCRC8ASMDuYm2Nll3+s6+8jLHaOJ9G2bYEnjHJnO9gjAjaQDFzgartCYXxinq+Q5bSeUZZzaDtnhGLnXBh2S1UshqsVLjL8gExtwLqflS5PqwBDa8IyZMvxS7AqPw3HS1Vb7Ku6jDbw0882+88pLsWXsUZYOH000b2RiztGA= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-lf1-x12c.google.com with SMTP id 2adb3069b0e04-51abd9fcbf6so4821868e87.1 for ; Mon, 22 Apr 2024 00:44:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=vrull.eu; s=google; t=1713771857; x=1714376657; darn=sourceware.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=y342bLmBlIfMG7iqwFmizSjgI+HyOrcl6/JLOiOi8kA=; b=ESIpGK5vIerwctYnqAd+zh7OO3YzSAIjzAbNO+rCmKoWEifD9wk9/TF6F8ks0S0GOJ HbmHtb1JQcWbm96beClsBgnwMiAge8oOlnGvHe8dSdLG8km9dbUIq5kWI1UhLOUsguIz 0x+/hsFybwiPvpoyMIyWs0gzMF29157sT50bXe/V/K9h8WiG4n35YnYWGDJWfrsbs/oL USJv2fTYh0GXbp561WeL6vVPvKYDC7BPE03SndADJXo9AZ4T0vz0HVdYLZxvuLaaQ6+i CLwDok0cUBm5sIOjpQrMykuVDV4b4H/+AJqGKOujjB5u0cloF8kQFTwnF9l6kU9dLOhb k8dA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1713771857; x=1714376657; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=y342bLmBlIfMG7iqwFmizSjgI+HyOrcl6/JLOiOi8kA=; b=R9nXI3aBmxFFaXDvIYh7KGhO1qCOdsQbDXNSZCrcfoVDoSO8eNcS2bGkp0ynPb5l/D X6AP/F6w1gRkJsrW9Wh8v1zq2M5nny0K+LIIsaW2Al66kK4T0xC0pJXzjxfrGrlRq9i8 BbrQI28BMebUOK2yx2hv4S/vNyk8uJl5+0gjEBbXd8uRnpzaORyGEBboQLsCO4KNT7FM ijTP+b4c/UD1NKPa8Pe8PPZvdvR1b3sqcqFhJ9ASNZVgI9GA0IaRpQ82LeSPxfQB8bi8 Am5wFYJ3TWEH4WjGO9nO4UEoAXlJJ921j0ZdQmZg/qo/iKvZr7a/tyoDx/YyCn6uHiTY yKMw== X-Gm-Message-State: AOJu0YxZMrMLLUapTuF7Rs1W4+9k/PMKWMSMp5GVq1XbjPtZZQhq220v P6l29J6+cz5zMWO9VVf9AUeu3EBylAkMwtK8VpU6UYIvJXhQmZATKHB26fotfyUVs6pw3SMElGP ZObw= X-Google-Smtp-Source: AGHT+IE8mwhYJh6MLFfp1n39O2i0M2Y/3wfbY8Ivul/6ihkl9loJl3NFNgOtR5GY6vFLgz9JnLss5Q== X-Received: by 2002:a19:e00f:0:b0:51a:bd7c:2194 with SMTP id x15-20020a19e00f000000b0051abd7c2194mr6287470lfg.23.1713771857128; Mon, 22 Apr 2024 00:44:17 -0700 (PDT) Received: from beast.fritz.box (static.239.130.217.95.clients.your-server.de. [95.217.130.239]) by smtp.gmail.com with ESMTPSA id v24-20020a197418000000b0051920234d6dsm1656756lfe.273.2024.04.22.00.44.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 22 Apr 2024 00:44:16 -0700 (PDT) From: =?utf-8?q?Christoph_M=C3=BCllner?= To: libc-alpha@sourceware.org, Adhemerval Zanella , Palmer Dabbelt , Darius Rad , Andrew Waterman , Philipp Tomsich , Evan Green , DJ Delorie , Vineet Gupta , Kito Cheng , Jeff Law Cc: =?utf-8?q?Christoph_M=C3=BCllner?= Subject: [PATCH 4/7] RISC-V: Add Zbb optimized strchrnul as ifunc Date: Mon, 22 Apr 2024 09:44:00 +0200 Message-ID: <20240422074403.2399529-5-christoph.muellner@vrull.eu> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240422074403.2399529-1-christoph.muellner@vrull.eu> References: <20240422074403.2399529-1-christoph.muellner@vrull.eu> 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_MANYTO, KAM_SHORT, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libc-alpha-bounces+patchwork=sourceware.org@sourceware.org When building with Zbb enabled, strchrnul benefits from using orc.b in find_zero_all(). This patch changes the build system such, that a non-Zbb version as well as a Zbb version of this routine is built. Further, a ifunc resolver is provided that selects the right routine based on the outcome of extension probing via hwprobe(). Signed-off-by: Christoph Müllner --- sysdeps/riscv/multiarch/strchrnul-generic.c | 26 ++++++++ sysdeps/riscv/multiarch/strchrnul-zbb.c | 30 +++++++++ .../unix/sysv/linux/riscv/multiarch/Makefile | 3 + .../linux/riscv/multiarch/ifunc-impl-list.c | 4 ++ .../sysv/linux/riscv/multiarch/strchrnul.c | 61 +++++++++++++++++++ 5 files changed, 124 insertions(+) create mode 100644 sysdeps/riscv/multiarch/strchrnul-generic.c create mode 100644 sysdeps/riscv/multiarch/strchrnul-zbb.c create mode 100644 sysdeps/unix/sysv/linux/riscv/multiarch/strchrnul.c diff --git a/sysdeps/riscv/multiarch/strchrnul-generic.c b/sysdeps/riscv/multiarch/strchrnul-generic.c new file mode 100644 index 0000000000..0b64273ebf --- /dev/null +++ b/sysdeps/riscv/multiarch/strchrnul-generic.c @@ -0,0 +1,26 @@ +/* Re-include the default strchrnul implementation. + Copyright (C) 2024 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 + . */ + +#include + +#if IS_IN(libc) +# define STRCHRNUL __strchrnul_generic +# undef libc_hidden_builtin_def +# define libc_hidden_builtin_def(x) +#endif +#include diff --git a/sysdeps/riscv/multiarch/strchrnul-zbb.c b/sysdeps/riscv/multiarch/strchrnul-zbb.c new file mode 100644 index 0000000000..f12fba7709 --- /dev/null +++ b/sysdeps/riscv/multiarch/strchrnul-zbb.c @@ -0,0 +1,30 @@ +/* Re-include the default strchrnul implementation for Zbb. + Copyright (C) 2024 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 + . */ + +#include + +#if IS_IN(libc) +# define STRCHRNUL __strchrnul_zbb +# undef libc_hidden_builtin_def +# define libc_hidden_builtin_def(x) +#endif +/* Convince preprocessor to have Zbb instructions. */ +#ifndef __riscv_zbb +# define __riscv_zbb +#endif +#include diff --git a/sysdeps/unix/sysv/linux/riscv/multiarch/Makefile b/sysdeps/unix/sysv/linux/riscv/multiarch/Makefile index d36d0bd6dd..242c2527d2 100644 --- a/sysdeps/unix/sysv/linux/riscv/multiarch/Makefile +++ b/sysdeps/unix/sysv/linux/riscv/multiarch/Makefile @@ -9,6 +9,9 @@ sysdep_routines += \ memrchr \ memrchr-generic \ memrchr-zbb \ + strchrnul \ + strchrnul-generic \ + strchrnul-zbb \ # sysdep_routines CFLAGS-memcpy_noalignment.c += -mno-strict-align diff --git a/sysdeps/unix/sysv/linux/riscv/multiarch/ifunc-impl-list.c b/sysdeps/unix/sysv/linux/riscv/multiarch/ifunc-impl-list.c index f4ec58b9d8..97cc821a56 100644 --- a/sysdeps/unix/sysv/linux/riscv/multiarch/ifunc-impl-list.c +++ b/sysdeps/unix/sysv/linux/riscv/multiarch/ifunc-impl-list.c @@ -64,5 +64,9 @@ __libc_ifunc_impl_list (const char *name, struct libc_ifunc_impl *array, IFUNC_IMPL_ADD (array, i, memrchr, has_zbb, __memrchr_zbb) IFUNC_IMPL_ADD (array, i, memrchr, 1, __memrchr_generic)) + IFUNC_IMPL (i, name, strchrnul, + IFUNC_IMPL_ADD (array, i, strchrnul, has_zbb, __strchrnul_zbb) + IFUNC_IMPL_ADD (array, i, strchrnul, 1, __strchrnul_generic)) + return 0; } diff --git a/sysdeps/unix/sysv/linux/riscv/multiarch/strchrnul.c b/sysdeps/unix/sysv/linux/riscv/multiarch/strchrnul.c new file mode 100644 index 0000000000..c3f245678e --- /dev/null +++ b/sysdeps/unix/sysv/linux/riscv/multiarch/strchrnul.c @@ -0,0 +1,61 @@ +/* Multiple versions of strchrnul. + All versions must be listed in ifunc-impl-list.c. + Copyright (C) 2017-2024 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 + . */ + +#if IS_IN (libc) +/* Redefine strchrnul so that the compiler won't complain about the type + mismatch with the IFUNC selector in strong_alias, below. */ +# undef strchrnul +# undef __strchrnul +# define strchrnul __redirect_strchrnul +# define __strchrnul __redirect_strchrnul +# include +# include +# include +# include +# include + +extern __typeof (__redirect_strchrnul) __libc_strchrnul; + +extern __typeof (__redirect_strchrnul) __strchrnul_generic attribute_hidden; +extern __typeof (__redirect_strchrnul) __strchrnul_zbb attribute_hidden; + +static inline __typeof (__redirect_strchrnul) * +select_strchrnul_ifunc (uint64_t dl_hwcap, __riscv_hwprobe_t hwprobe_func) +{ + unsigned long long int v; + if (__riscv_hwprobe_one (hwprobe_func, RISCV_HWPROBE_KEY_IMA_EXT_0, &v) == 0 + && (v & RISCV_HWPROBE_EXT_ZBB)) + return __strchrnul_zbb; + + return __strchrnul_generic; +} + +riscv_libc_ifunc (__libc_strchrnul, select_strchrnul_ifunc); + +# undef strchrnul +# undef __strchrnul +strong_alias (__libc_strchrnul, __strchrnul); +weak_alias (__strchrnul, strchrnul) +# ifdef SHARED +__hidden_ver1 (strchrnul, __GI___strchrnul, __redirect_strchrnul) + __attribute__ ((visibility ("hidden"))) __attribute_copy__ (strchrnul); +# endif +#else +# include +#endif From patchwork Mon Apr 22 07:44:01 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Christoph_M=C3=BCllner?= X-Patchwork-Id: 88834 X-Patchwork-Delegate: carlos@redhat.com 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 BC5F9385841E for ; Mon, 22 Apr 2024 07:46:58 +0000 (GMT) X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-lf1-x133.google.com (mail-lf1-x133.google.com [IPv6:2a00:1450:4864:20::133]) by sourceware.org (Postfix) with ESMTPS id B6292384AB5D for ; Mon, 22 Apr 2024 07:44:20 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org B6292384AB5D Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=vrull.eu Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=vrull.eu ARC-Filter: OpenARC Filter v1.0.0 sourceware.org B6292384AB5D Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2a00:1450:4864:20::133 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1713771863; cv=none; b=dx7rKCNAcMZqZ0m2/PCwGQ5K/0uX7k59u81PqpKtXGrNL7sbpEqkl3ZO0s9KZkwHdH6JE/GQ+c2RvDiKJvZMjaVsQEh2LUQTFtaGjFkr3IddU9+ENskoBRUqdH+0ktKT/YSBwGrRa0TOFnGUa9MOxoHReRtLjCuaMCXODqo+4bU= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1713771863; c=relaxed/simple; bh=2D+xEFtuzCesMXBmkmbHumbJ6Nzbyj9ZtoU5qX2VD/I=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=Uv4tu/So3mtgjpXfEFF4zUfd+xPcN6qxp8F2wQOUxbOEb4xH2yEa+/Hrqhbkf6LvMM5+jDuPxGVbnqtMsEC+z/D3B6UBYd0prvcFpeP7KGedeULvK5Fzm3AO1x7Q6apSOjXloKW3LFmaK9AuJPp7Qk8z5qAbXPCNSEPDk0DZXq4= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-lf1-x133.google.com with SMTP id 2adb3069b0e04-516d2b9cd69so4836885e87.2 for ; Mon, 22 Apr 2024 00:44:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=vrull.eu; s=google; t=1713771859; x=1714376659; darn=sourceware.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=dJQoK+bL7k2VySwtCV1JxxINqRU9fVYa0Z7Mq3xQHV4=; b=ht+nWX6VVI4rXKOl+Dc0jCY8s0dydcqR6q/+OCdAOpI33nBgdSX9dBw2xv+vYTXnV6 Zc7KLRieaL9SA8lqV/4kwhNkhtTvz2sqHSgb6oeepgmWJbE8p0LUIGdB7k+mQ3I4PXBy lh4chzxbmtAFsFciRHt1eOWdKAb4kEQHPwm/+mVo6pv9Mc9odfr/i98pkQyhnLCcu50+ qXgIHmcJ5stKr/kxSCCqX2T998naF80/zxMKNwLOj9O5aPiTRrYhBiSwvf/O2mxqMy6d IC4PmSLSS7PmzD+0p5uLd1DGX033b/bSBEi1Se44vgQw3qL5bFzdPe/OoaOyJgw2xbqn xBMw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1713771859; x=1714376659; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=dJQoK+bL7k2VySwtCV1JxxINqRU9fVYa0Z7Mq3xQHV4=; b=PHn0k0OZxVj9kPp0bZ/3dG/WAfurp6qIsIuCuNMRkFEfyogendc2kUYKfHBhJrm6Ko UoZYPWoVmJD2reNEPykj2nmMXxNDEeMYnpOCpJd6XpTKKwsOLDZsm2qI+8vYtAEEZrZl Ne2DSqVQCF1qFInImW1IOOK9zwlAvZk6sGk2b/3yFlyFex1rbD/een4ROMXgRMAvRJuC TYd5JphPxj4rYo9kAmpKDmwZ92LIbEd54EzooQIT/lHrYyY4kuJeVnH2lyUPBOj0zald KVQDrjg7VYGnNXX7m7ybSBAYDY5NlVN+ZWy7OyULSORdfuDtXwXgn34lbIyJB+AXDb2X 6GEw== X-Gm-Message-State: AOJu0Yxs9U6Ouq5xVPmMFkokp5MOwyC+SLHj8BtF6fKGQgA9KnielrP1 1tfb21lUVSE8l+1U+q9PhEbHMB7a2kHMdcEkv5LqLmmEZE1tVbco5es84d6MVLvtgqjEtCbIQBF pgUw= X-Google-Smtp-Source: AGHT+IEY3OgOcc7Qd+PMuxOErF3H0AG2JNIv/y5NmijMTspF5o8dGTVDGNMTe22U7qa5P0k/4ClcEA== X-Received: by 2002:a05:6512:517:b0:516:a6ff:2467 with SMTP id o23-20020a056512051700b00516a6ff2467mr5805586lfb.0.1713771858797; Mon, 22 Apr 2024 00:44:18 -0700 (PDT) Received: from beast.fritz.box (static.239.130.217.95.clients.your-server.de. [95.217.130.239]) by smtp.gmail.com with ESMTPSA id v24-20020a197418000000b0051920234d6dsm1656756lfe.273.2024.04.22.00.44.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 22 Apr 2024 00:44:18 -0700 (PDT) From: =?utf-8?q?Christoph_M=C3=BCllner?= To: libc-alpha@sourceware.org, Adhemerval Zanella , Palmer Dabbelt , Darius Rad , Andrew Waterman , Philipp Tomsich , Evan Green , DJ Delorie , Vineet Gupta , Kito Cheng , Jeff Law Cc: =?utf-8?q?Christoph_M=C3=BCllner?= Subject: [PATCH 5/7] RISC-V: Add Zbb optimized strcmp as ifunc Date: Mon, 22 Apr 2024 09:44:01 +0200 Message-ID: <20240422074403.2399529-6-christoph.muellner@vrull.eu> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240422074403.2399529-1-christoph.muellner@vrull.eu> References: <20240422074403.2399529-1-christoph.muellner@vrull.eu> MIME-Version: 1.0 X-Spam-Status: No, score=-12.6 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_MANYTO, KAM_SHORT, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libc-alpha-bounces+patchwork=sourceware.org@sourceware.org When building with Zbb enabled, strcmp benefits from using orc.b in find_zero_all(). This patch changes the build system such, that a non-Zbb version as well as a Zbb version of this routine is built. Further, a ifunc resolver is provided that selects the right routine based on the outcome of extension probing via hwprobe(). Signed-off-by: Christoph Müllner --- sysdeps/riscv/multiarch/strcmp-generic.c | 26 +++++++++ sysdeps/riscv/multiarch/strcmp-zbb.c | 30 ++++++++++ .../unix/sysv/linux/riscv/multiarch/Makefile | 3 + .../linux/riscv/multiarch/ifunc-impl-list.c | 4 ++ .../unix/sysv/linux/riscv/multiarch/strcmp.c | 57 +++++++++++++++++++ 5 files changed, 120 insertions(+) create mode 100644 sysdeps/riscv/multiarch/strcmp-generic.c create mode 100644 sysdeps/riscv/multiarch/strcmp-zbb.c create mode 100644 sysdeps/unix/sysv/linux/riscv/multiarch/strcmp.c diff --git a/sysdeps/riscv/multiarch/strcmp-generic.c b/sysdeps/riscv/multiarch/strcmp-generic.c new file mode 100644 index 0000000000..5da954d426 --- /dev/null +++ b/sysdeps/riscv/multiarch/strcmp-generic.c @@ -0,0 +1,26 @@ +/* Re-include the default strcmp implementation. + Copyright (C) 2024 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 + . */ + +#include + +#if IS_IN(libc) +# define STRCMP __strcmp_generic +# undef libc_hidden_builtin_def +# define libc_hidden_builtin_def(x) +#endif +#include diff --git a/sysdeps/riscv/multiarch/strcmp-zbb.c b/sysdeps/riscv/multiarch/strcmp-zbb.c new file mode 100644 index 0000000000..2ccde14f53 --- /dev/null +++ b/sysdeps/riscv/multiarch/strcmp-zbb.c @@ -0,0 +1,30 @@ +/* Re-include the default strcmp implementation for Zbb. + Copyright (C) 2024 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 + . */ + +#include + +#if IS_IN(libc) +# define STRCMP __strcmp_zbb +# undef libc_hidden_builtin_def +# define libc_hidden_builtin_def(x) +#endif +/* Convince preprocessor to have Zbb instructions. */ +#ifndef __riscv_zbb +# define __riscv_zbb +#endif +#include diff --git a/sysdeps/unix/sysv/linux/riscv/multiarch/Makefile b/sysdeps/unix/sysv/linux/riscv/multiarch/Makefile index 242c2527d2..8aef9f1638 100644 --- a/sysdeps/unix/sysv/linux/riscv/multiarch/Makefile +++ b/sysdeps/unix/sysv/linux/riscv/multiarch/Makefile @@ -12,6 +12,9 @@ sysdep_routines += \ strchrnul \ strchrnul-generic \ strchrnul-zbb \ + strcmp \ + strcmp-generic \ + strcmp-zbb \ # sysdep_routines CFLAGS-memcpy_noalignment.c += -mno-strict-align diff --git a/sysdeps/unix/sysv/linux/riscv/multiarch/ifunc-impl-list.c b/sysdeps/unix/sysv/linux/riscv/multiarch/ifunc-impl-list.c index 97cc821a56..f4df7a2b0b 100644 --- a/sysdeps/unix/sysv/linux/riscv/multiarch/ifunc-impl-list.c +++ b/sysdeps/unix/sysv/linux/riscv/multiarch/ifunc-impl-list.c @@ -68,5 +68,9 @@ __libc_ifunc_impl_list (const char *name, struct libc_ifunc_impl *array, IFUNC_IMPL_ADD (array, i, strchrnul, has_zbb, __strchrnul_zbb) IFUNC_IMPL_ADD (array, i, strchrnul, 1, __strchrnul_generic)) + IFUNC_IMPL (i, name, strcmp, + IFUNC_IMPL_ADD (array, i, strcmp, has_zbb, __strcmp_zbb) + IFUNC_IMPL_ADD (array, i, strcmp, 1, __strcmp_generic)) + return 0; } diff --git a/sysdeps/unix/sysv/linux/riscv/multiarch/strcmp.c b/sysdeps/unix/sysv/linux/riscv/multiarch/strcmp.c new file mode 100644 index 0000000000..47b3277e77 --- /dev/null +++ b/sysdeps/unix/sysv/linux/riscv/multiarch/strcmp.c @@ -0,0 +1,57 @@ +/* Multiple versions of strcmp. + All versions must be listed in ifunc-impl-list.c. + Copyright (C) 2017-2024 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 + . */ + +#if IS_IN (libc) +/* Redefine strcmp so that the compiler won't complain about the type + mismatch with the IFUNC selector in strong_alias, below. */ +# undef strcmp +# define strcmp __redirect_strcmp +# include +# include +# include +# include +# include + +extern __typeof (__redirect_strcmp) __libc_strcmp; + +extern __typeof (__redirect_strcmp) __strcmp_generic attribute_hidden; +extern __typeof (__redirect_strcmp) __strcmp_zbb attribute_hidden; + +static inline __typeof (__redirect_strcmp) * +select_strcmp_ifunc (uint64_t dl_hwcap, __riscv_hwprobe_t hwprobe_func) +{ + unsigned long long int v; + if (__riscv_hwprobe_one (hwprobe_func, RISCV_HWPROBE_KEY_IMA_EXT_0, &v) == 0 + && (v & RISCV_HWPROBE_EXT_ZBB)) + return __strcmp_zbb; + + return __strcmp_generic; +} + +riscv_libc_ifunc (__libc_strcmp, select_strcmp_ifunc); + +# undef strcmp +strong_alias (__libc_strcmp, strcmp); +# ifdef SHARED +__hidden_ver1 (strcmp, __GI_strcmp, __redirect_strcmp) + __attribute__ ((visibility ("hidden"))) __attribute_copy__ (strcmp); +# endif +#else +# include +#endif From patchwork Mon Apr 22 07:44:02 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Christoph_M=C3=BCllner?= X-Patchwork-Id: 88832 X-Patchwork-Delegate: carlos@redhat.com 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 571BC3858D38 for ; Mon, 22 Apr 2024 07:45:51 +0000 (GMT) X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-lf1-x12f.google.com (mail-lf1-x12f.google.com [IPv6:2a00:1450:4864:20::12f]) by sourceware.org (Postfix) with ESMTPS id A54E2384AB49 for ; Mon, 22 Apr 2024 07:44:22 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org A54E2384AB49 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=vrull.eu Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=vrull.eu ARC-Filter: OpenARC Filter v1.0.0 sourceware.org A54E2384AB49 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2a00:1450:4864:20::12f ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1713771867; cv=none; b=uonPsvFtEGitU7ETL4vuiZPyHDxFCZGI1Uhhje044hP6Vv2rf2OpnNO3OBWdlAIk8qFddg55tGHkluF/pJcldSt0k6wsgoPJa7JARkxc9MiVITMGk+MygZv9bidq7MYENQ8F3qPw7jP4F8AI+GPa3TBSLb8BX6RHGZlp9saDTzQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1713771867; c=relaxed/simple; bh=Hhi5WUrmev5CjiuZxm/+ANu/o6HirEN7kpYCEYdHwfY=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=vMbaCM9uKZ4zTNRxgaFaT0cKF5rPd2RMRuDgTWgkzKWE7brUeta1G8ZmBpU7pGqabuEoRdc3oyp2Lgww/3WGj6nnn1Mi9x7xwsk2hU4MQm+qAGTiutJ5Ppm6Xcp+vJWfNb4GoMNwdO3W7yncAphqQoUvVkmZT7cjd2DZWgtmRZM= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-lf1-x12f.google.com with SMTP id 2adb3069b0e04-516ef30b16eso5049212e87.3 for ; Mon, 22 Apr 2024 00:44:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=vrull.eu; s=google; t=1713771860; x=1714376660; darn=sourceware.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=3kGcoFEtufc6eGj4vXR+QF3gxcrVtLYf62WDDpeK78E=; b=UVuXnxNnkfjwOsILxwKvby0r+idtXwAjs7gsV6xc19mj8bftBwcYe/7djpdyRNRezu OGXzaNpb9JMTWALG+leNxlRYkWBiG+G/wq7H9T0dBeW9uh/NhrHkP87GDbS55lulZh1j a2bASIFYp3DqtxXnGjaYRNEvKPBWr1tNkkHUppnMqu9kT8cc/EsK9ol01B3pcbT0YpDj aqjfwXTdh6WmRBoI99RnwXXeYjLkO+rsIHc9yxhmCBjfMa/GWKnfxFn1CqtH8bDsPOju /QgwcawHlCylx7WrEq+j+kK9QEQoeqIPmZYpeMcal2WrcqvG5qcD0VjTODd7ebqdmv4C ayHg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1713771860; x=1714376660; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=3kGcoFEtufc6eGj4vXR+QF3gxcrVtLYf62WDDpeK78E=; b=GY7SvTAesnMLBfVSzfzgtyxyBMIYrGTiZKebdZwQOk3UQirZJCc7TFKKRpwr54m9x/ ftM1RQlpFWMZ4W92zrygq6cVDZRAF0g6FXIuqvI2tf5sORpNnKAu+prKgXGVhj5+D/nK RBc7WehOMJn+6sBk0GumYL7k+aEQ6OK+iAmkoreiyeEZ2oazqmgdnXTa5UiJVFiKrYXb 7pWL3WhWV3SIVh+d59V5VxDyxXCtQb+pkav48KdvwRT2aRL0uAip0QuDgdgDJnH4qVK9 IfbhVxfsrL4GEOyAUILRk463mdVRqLRnKrC9BzsDs4jh9Lk0JqsivmWKzOPx+W/MbmXx DdpA== X-Gm-Message-State: AOJu0YwDgO2dZra+UqSqnupK9rdGlyIh+u9ZRJ5bbC6IdtnLoPVeDOdq Z7TgV3gLqrFhEyrEj38ZiHwEP5NaKVDSd8NPHGd4Qe7bcj389R6s9UDWasiQjixpVKfoN9m50iw 3vMA= X-Google-Smtp-Source: AGHT+IEUv3M22Gn024rsgFNzoBgkXasq+NW86wW1wHvLbRqZxoLDRh46p4wu6g1p5N0W39WQSO26vg== X-Received: by 2002:a05:6512:1101:b0:518:91c9:fc20 with SMTP id l1-20020a056512110100b0051891c9fc20mr6672368lfg.41.1713771860497; Mon, 22 Apr 2024 00:44:20 -0700 (PDT) Received: from beast.fritz.box (static.239.130.217.95.clients.your-server.de. [95.217.130.239]) by smtp.gmail.com with ESMTPSA id v24-20020a197418000000b0051920234d6dsm1656756lfe.273.2024.04.22.00.44.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 22 Apr 2024 00:44:19 -0700 (PDT) From: =?utf-8?q?Christoph_M=C3=BCllner?= To: libc-alpha@sourceware.org, Adhemerval Zanella , Palmer Dabbelt , Darius Rad , Andrew Waterman , Philipp Tomsich , Evan Green , DJ Delorie , Vineet Gupta , Kito Cheng , Jeff Law Cc: =?utf-8?q?Christoph_M=C3=BCllner?= Subject: [PATCH 6/7] RISC-V: Add Zbb optimized strlen as ifunc Date: Mon, 22 Apr 2024 09:44:02 +0200 Message-ID: <20240422074403.2399529-7-christoph.muellner@vrull.eu> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240422074403.2399529-1-christoph.muellner@vrull.eu> References: <20240422074403.2399529-1-christoph.muellner@vrull.eu> MIME-Version: 1.0 X-Spam-Status: No, score=-12.6 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_MANYTO, KAM_SHORT, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libc-alpha-bounces+patchwork=sourceware.org@sourceware.org When building with Zbb enabled, strlen benefits from using orc.b in find_zero_all(). This patch changes the build system such, that a non-Zbb version as well as a Zbb version of this routine is built. Further, a ifunc resolver is provided that selects the right routine based on the outcome of extension probing via hwprobe(). Signed-off-by: Christoph Müllner --- sysdeps/riscv/multiarch/strlen-generic.c | 26 +++++++++ sysdeps/riscv/multiarch/strlen-zbb.c | 30 ++++++++++ .../unix/sysv/linux/riscv/multiarch/Makefile | 3 + .../linux/riscv/multiarch/ifunc-impl-list.c | 4 ++ .../unix/sysv/linux/riscv/multiarch/strlen.c | 57 +++++++++++++++++++ 5 files changed, 120 insertions(+) create mode 100644 sysdeps/riscv/multiarch/strlen-generic.c create mode 100644 sysdeps/riscv/multiarch/strlen-zbb.c create mode 100644 sysdeps/unix/sysv/linux/riscv/multiarch/strlen.c diff --git a/sysdeps/riscv/multiarch/strlen-generic.c b/sysdeps/riscv/multiarch/strlen-generic.c new file mode 100644 index 0000000000..e057409278 --- /dev/null +++ b/sysdeps/riscv/multiarch/strlen-generic.c @@ -0,0 +1,26 @@ +/* Re-include the default strlen implementation. + Copyright (C) 2024 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 + . */ + +#include + +#if IS_IN(libc) +# define STRLEN __strlen_generic +# undef libc_hidden_builtin_def +# define libc_hidden_builtin_def(x) +#endif +#include diff --git a/sysdeps/riscv/multiarch/strlen-zbb.c b/sysdeps/riscv/multiarch/strlen-zbb.c new file mode 100644 index 0000000000..81ef16bb4a --- /dev/null +++ b/sysdeps/riscv/multiarch/strlen-zbb.c @@ -0,0 +1,30 @@ +/* Re-include the default strlen implementation for Zbb. + Copyright (C) 2024 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 + . */ + +#include + +#if IS_IN(libc) +# define STRLEN __strlen_zbb +# undef libc_hidden_builtin_def +# define libc_hidden_builtin_def(x) +#endif +/* Convince preprocessor to have Zbb instructions. */ +#ifndef __riscv_zbb +# define __riscv_zbb +#endif +#include diff --git a/sysdeps/unix/sysv/linux/riscv/multiarch/Makefile b/sysdeps/unix/sysv/linux/riscv/multiarch/Makefile index 8aef9f1638..daf5af9608 100644 --- a/sysdeps/unix/sysv/linux/riscv/multiarch/Makefile +++ b/sysdeps/unix/sysv/linux/riscv/multiarch/Makefile @@ -15,6 +15,9 @@ sysdep_routines += \ strcmp \ strcmp-generic \ strcmp-zbb \ + strlen \ + strlen-generic \ + strlen-zbb \ # sysdep_routines CFLAGS-memcpy_noalignment.c += -mno-strict-align diff --git a/sysdeps/unix/sysv/linux/riscv/multiarch/ifunc-impl-list.c b/sysdeps/unix/sysv/linux/riscv/multiarch/ifunc-impl-list.c index f4df7a2b0b..f5f34818ed 100644 --- a/sysdeps/unix/sysv/linux/riscv/multiarch/ifunc-impl-list.c +++ b/sysdeps/unix/sysv/linux/riscv/multiarch/ifunc-impl-list.c @@ -72,5 +72,9 @@ __libc_ifunc_impl_list (const char *name, struct libc_ifunc_impl *array, IFUNC_IMPL_ADD (array, i, strcmp, has_zbb, __strcmp_zbb) IFUNC_IMPL_ADD (array, i, strcmp, 1, __strcmp_generic)) + IFUNC_IMPL (i, name, strlen, + IFUNC_IMPL_ADD (array, i, strlen, has_zbb, __strlen_zbb) + IFUNC_IMPL_ADD (array, i, strlen, 1, __strlen_generic)) + return 0; } diff --git a/sysdeps/unix/sysv/linux/riscv/multiarch/strlen.c b/sysdeps/unix/sysv/linux/riscv/multiarch/strlen.c new file mode 100644 index 0000000000..6833d05bc8 --- /dev/null +++ b/sysdeps/unix/sysv/linux/riscv/multiarch/strlen.c @@ -0,0 +1,57 @@ +/* Multiple versions of strlen. + All versions must be listed in ifunc-impl-list.c. + Copyright (C) 2017-2024 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 + . */ + +#if IS_IN (libc) +/* Redefine strlen so that the compiler won't complain about the type + mismatch with the IFUNC selector in strong_alias, below. */ +# undef strlen +# define strlen __redirect_strlen +# include +# include +# include +# include +# include + +extern __typeof (__redirect_strlen) __libc_strlen; + +extern __typeof (__redirect_strlen) __strlen_generic attribute_hidden; +extern __typeof (__redirect_strlen) __strlen_zbb attribute_hidden; + +static inline __typeof (__redirect_strlen) * +select_strlen_ifunc (uint64_t dl_hwcap, __riscv_hwprobe_t hwprobe_func) +{ + unsigned long long int v; + if (__riscv_hwprobe_one (hwprobe_func, RISCV_HWPROBE_KEY_IMA_EXT_0, &v) == 0 + && (v & RISCV_HWPROBE_EXT_ZBB)) + return __strlen_zbb; + + return __strlen_generic; +} + +riscv_libc_ifunc (__libc_strlen, select_strlen_ifunc); + +# undef strlen +strong_alias (__libc_strlen, strlen); +# ifdef SHARED +__hidden_ver1 (strlen, __GI_strlen, __redirect_strlen) + __attribute__ ((visibility ("hidden"))) __attribute_copy__ (strlen); +# endif +#else +# include +#endif From patchwork Mon Apr 22 07:44:03 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Christoph_M=C3=BCllner?= X-Patchwork-Id: 88833 X-Patchwork-Delegate: carlos@redhat.com 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 E82EC3849ADB for ; Mon, 22 Apr 2024 07:45:52 +0000 (GMT) X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-lf1-x132.google.com (mail-lf1-x132.google.com [IPv6:2a00:1450:4864:20::132]) by sourceware.org (Postfix) with ESMTPS id 33AE9384AB52 for ; Mon, 22 Apr 2024 07:44:24 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 33AE9384AB52 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=vrull.eu Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=vrull.eu ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 33AE9384AB52 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2a00:1450:4864:20::132 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1713771868; cv=none; b=JSBsxJsNN1XkYbW8V5ox64PKz14Q/RS508vsKlzpaj4IWY7Ov/+PLduhxEU+zzEs8cASoDj7zTj3RBal42Ge4TsBFaekdBblbqnP2DBB1W844g+Xd/63F8UK21b+Zj1JvTyIZ2ggaILhWO/C1Vsu9wPNe39KRUwp5MFPg1v3Yl8= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1713771868; c=relaxed/simple; bh=6iF33XWSVoihuBZD3D5bZNKztTT3dbkRmflxVrumRVc=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=nEnJaeHCbGWuxfZ+jGIUode36LuF0CslB5swXHmr/9aLLbIO8XiH/wRUBP2zIQph/x622fgGRdksJzJy6JHu2wOZ4mjQltxxuoOVE2hPDnYHihiI5CucpMGE6d/8GyLxtVpKKyuKs4pq0Od+lflgZZSA9zHOGL4NVj0RM1n2qdE= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-lf1-x132.google.com with SMTP id 2adb3069b0e04-5193363d255so5371248e87.3 for ; Mon, 22 Apr 2024 00:44:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=vrull.eu; s=google; t=1713771862; x=1714376662; darn=sourceware.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=xZPbJx/WkECjq7/xpoERaJqUeuVBgTPRfoxg+UfBj5M=; b=ZExXmKV6pgXGh2x7foGwXrsRNsw8PdGBSwH28XJ/eB642s1r7Wa1ITDls+Qfsdr9AJ BNBwfL5LadeK+lr7VFieNABuHkax9lIZ0Tszvi+co6m6eYZVM1KGLhI7rIINTG2bPmsf OODxQCsbTNCrJGPq+hq/qOgd+aJQydkZowHIAwvADfIuCN+3w0QmgBJc+Zj8r7TL885x +XjwnU8SHpLmWYZO8DWZIr0RwebwI+m7/7ZfKireTJjOE2Dij6n5pvuxru+E8KO9vq2t 7AY6IVrcN2unLh1FqZnslM104dPDTv9pxPCmQiyztvVYK3d66KFpYqFvlm0J3ftADZBd /GTw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1713771862; x=1714376662; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=xZPbJx/WkECjq7/xpoERaJqUeuVBgTPRfoxg+UfBj5M=; b=BPn+Sauz6ujqhZGo+9PjtzlMY9FEopdvTRJ/d6J6dASEdUO+4rieJRFyess+lNepim vIyVgroD2WYgLCf4AqNZfGaIyIJM9EUie7r0kjkf6+NHIoUin0FwYmG2Hjuj3Nw2HWkn YLMu+kbaKMxGLzoLhIrKWcm8+aEQ/cD/qouIdfysY62qbfhTBoVGnjsgmhu2WtQbGgJe SC/EyV9PRcx5cmsUKmZohYqj/eKTFeRqCa07tUmE671Xzwj1Nkb8YuxIsr0JWAVXjlHf BmoEdTWt7hKCr5+i3B8naT2m2DjmCAUB1BU6j4IKF4uabyKW/RuLC67oCpcFBaBSWZWW dd+Q== X-Gm-Message-State: AOJu0YzBFkMWkT+9KUjK9TRDpPxDcwLs8GZLrCS3gersoSvu/Kv49lSc y3CuBCuPgRbhH+dfClt1DSOl1IWSW64eXrg/wPf9Z+7rbAi6Is8czSv2TzofYKUyFRk2EJNJfc7 6SE4= X-Google-Smtp-Source: AGHT+IFxvYKLCPjXyDguKPBRw03yKRNH/svhTPSbYRpoP2tVlUbspZ7rRva8jCW9sAinbIWn8k0cvw== X-Received: by 2002:a19:640e:0:b0:519:6691:4135 with SMTP id y14-20020a19640e000000b0051966914135mr5754746lfb.67.1713771862097; Mon, 22 Apr 2024 00:44:22 -0700 (PDT) Received: from beast.fritz.box (static.239.130.217.95.clients.your-server.de. [95.217.130.239]) by smtp.gmail.com with ESMTPSA id v24-20020a197418000000b0051920234d6dsm1656756lfe.273.2024.04.22.00.44.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 22 Apr 2024 00:44:21 -0700 (PDT) From: =?utf-8?q?Christoph_M=C3=BCllner?= To: libc-alpha@sourceware.org, Adhemerval Zanella , Palmer Dabbelt , Darius Rad , Andrew Waterman , Philipp Tomsich , Evan Green , DJ Delorie , Vineet Gupta , Kito Cheng , Jeff Law Cc: =?utf-8?q?Christoph_M=C3=BCllner?= Subject: [PATCH 7/7] RISC-V: Add Zbb optimized strncmp as ifunc Date: Mon, 22 Apr 2024 09:44:03 +0200 Message-ID: <20240422074403.2399529-8-christoph.muellner@vrull.eu> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240422074403.2399529-1-christoph.muellner@vrull.eu> References: <20240422074403.2399529-1-christoph.muellner@vrull.eu> MIME-Version: 1.0 X-Spam-Status: No, score=-12.6 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_MANYTO, KAM_SHORT, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libc-alpha-bounces+patchwork=sourceware.org@sourceware.org When building with Zbb enabled, strncmp benefits from using orc.b in find_zero_all(). This patch changes the build system such, that a non-Zbb version as well as a Zbb version of this routine is built. Further, a ifunc resolver is provided that selects the right routine based on the outcome of extension probing via hwprobe(). Signed-off-by: Christoph Müllner --- sysdeps/riscv/multiarch/strncmp-generic.c | 26 +++++++++ sysdeps/riscv/multiarch/strncmp-zbb.c | 30 ++++++++++ .../unix/sysv/linux/riscv/multiarch/Makefile | 3 + .../linux/riscv/multiarch/ifunc-impl-list.c | 4 ++ .../unix/sysv/linux/riscv/multiarch/strncmp.c | 57 +++++++++++++++++++ 5 files changed, 120 insertions(+) create mode 100644 sysdeps/riscv/multiarch/strncmp-generic.c create mode 100644 sysdeps/riscv/multiarch/strncmp-zbb.c create mode 100644 sysdeps/unix/sysv/linux/riscv/multiarch/strncmp.c diff --git a/sysdeps/riscv/multiarch/strncmp-generic.c b/sysdeps/riscv/multiarch/strncmp-generic.c new file mode 100644 index 0000000000..67eb89e62e --- /dev/null +++ b/sysdeps/riscv/multiarch/strncmp-generic.c @@ -0,0 +1,26 @@ +/* Re-include the default strncmp implementation. + Copyright (C) 2024 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 + . */ + +#include + +#if IS_IN(libc) +# define STRNCMP __strncmp_generic +# undef libc_hidden_builtin_def +# define libc_hidden_builtin_def(x) +#endif +#include diff --git a/sysdeps/riscv/multiarch/strncmp-zbb.c b/sysdeps/riscv/multiarch/strncmp-zbb.c new file mode 100644 index 0000000000..993b494d8b --- /dev/null +++ b/sysdeps/riscv/multiarch/strncmp-zbb.c @@ -0,0 +1,30 @@ +/* Re-include the default strncmp implementation for Zbb. + Copyright (C) 2024 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 + . */ + +#include + +#if IS_IN(libc) +# define STRNCMP __strncmp_zbb +# undef libc_hidden_builtin_def +# define libc_hidden_builtin_def(x) +#endif +/* Convince preprocessor to have Zbb instructions. */ +#ifndef __riscv_zbb +# define __riscv_zbb +#endif +#include diff --git a/sysdeps/unix/sysv/linux/riscv/multiarch/Makefile b/sysdeps/unix/sysv/linux/riscv/multiarch/Makefile index daf5af9608..4a34eab00c 100644 --- a/sysdeps/unix/sysv/linux/riscv/multiarch/Makefile +++ b/sysdeps/unix/sysv/linux/riscv/multiarch/Makefile @@ -18,6 +18,9 @@ sysdep_routines += \ strlen \ strlen-generic \ strlen-zbb \ + strncmp \ + strncmp-generic \ + strncmp-zbb \ # sysdep_routines CFLAGS-memcpy_noalignment.c += -mno-strict-align diff --git a/sysdeps/unix/sysv/linux/riscv/multiarch/ifunc-impl-list.c b/sysdeps/unix/sysv/linux/riscv/multiarch/ifunc-impl-list.c index f5f34818ed..583c77934e 100644 --- a/sysdeps/unix/sysv/linux/riscv/multiarch/ifunc-impl-list.c +++ b/sysdeps/unix/sysv/linux/riscv/multiarch/ifunc-impl-list.c @@ -76,5 +76,9 @@ __libc_ifunc_impl_list (const char *name, struct libc_ifunc_impl *array, IFUNC_IMPL_ADD (array, i, strlen, has_zbb, __strlen_zbb) IFUNC_IMPL_ADD (array, i, strlen, 1, __strlen_generic)) + IFUNC_IMPL (i, name, strncmp, + IFUNC_IMPL_ADD (array, i, strncmp, has_zbb, __strncmp_zbb) + IFUNC_IMPL_ADD (array, i, strncmp, 1, __strncmp_generic)) + return 0; } diff --git a/sysdeps/unix/sysv/linux/riscv/multiarch/strncmp.c b/sysdeps/unix/sysv/linux/riscv/multiarch/strncmp.c new file mode 100644 index 0000000000..9bc026681f --- /dev/null +++ b/sysdeps/unix/sysv/linux/riscv/multiarch/strncmp.c @@ -0,0 +1,57 @@ +/* Multiple versions of strncmp. + All versions must be listed in ifunc-impl-list.c. + Copyright (C) 2017-2024 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 + . */ + +#if IS_IN (libc) +/* Redefine strncmp so that the compiler won't complain about the type + mismatch with the IFUNC selector in strong_alias, below. */ +# undef strncmp +# define strncmp __redirect_strncmp +# include +# include +# include +# include +# include + +extern __typeof (__redirect_strncmp) __libc_strncmp; + +extern __typeof (__redirect_strncmp) __strncmp_generic attribute_hidden; +extern __typeof (__redirect_strncmp) __strncmp_zbb attribute_hidden; + +static inline __typeof (__redirect_strncmp) * +select_strncmp_ifunc (uint64_t dl_hwcap, __riscv_hwprobe_t hwprobe_func) +{ + unsigned long long int v; + if (__riscv_hwprobe_one (hwprobe_func, RISCV_HWPROBE_KEY_IMA_EXT_0, &v) == 0 + && (v & RISCV_HWPROBE_EXT_ZBB)) + return __strncmp_zbb; + + return __strncmp_generic; +} + +riscv_libc_ifunc (__libc_strncmp, select_strncmp_ifunc); + +# undef strncmp +strong_alias (__libc_strncmp, strncmp); +# ifdef SHARED +__hidden_ver1 (strncmp, __GI_strncmp, __redirect_strncmp) + __attribute__ ((visibility ("hidden"))) __attribute_copy__ (strncmp); +# endif +#else +# include +#endif