From patchwork Mon May 27 11:19: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: 1939871 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=vrull.eu header.i=@vrull.eu header.a=rsa-sha256 header.s=google header.b=OwynvhHw; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=sourceware.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=server2.sourceware.org; envelope-from=libc-alpha-bounces+incoming=patchwork.ozlabs.org@sourceware.org; receiver=patchwork.ozlabs.org) Received: from server2.sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4VntWt3bm2z20PT for ; Mon, 27 May 2024 21:21:46 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id C3AC638432F1 for ; Mon, 27 May 2024 11:21:44 +0000 (GMT) X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-lf1-x12b.google.com (mail-lf1-x12b.google.com [IPv6:2a00:1450:4864:20::12b]) by sourceware.org (Postfix) with ESMTPS id BEB49385B50B for ; Mon, 27 May 2024 11:19:38 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org BEB49385B50B 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 BEB49385B50B Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2a00:1450:4864:20::12b ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1716808781; cv=none; b=HkhhE9oU8EAUpm1BLDxYQwQQF8B82stHoYepe64T9JdsZ4rkG3bkvHdxhF8XENXfkt9myuuyi1/sGFAuoo4Glm4EYptweJSUU0DRwbU1d/WbAV/hrWO98CzWuDMMnGmGJWyHgRDB3L5DwzuiyhPXPtAKu9xg48cxdfxPmRkGbmY= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1716808781; c=relaxed/simple; bh=Zru5tRfky7uUI5nlmSnY9wXgMOaIF6JeZRZLN1THwLI=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=WVTA8091Qr7vxXAAceWgV0nDgxlSt4dHTozVvszzWsGSc9zGxWLM+YB4CmhqmUmiklkEgqN/Lo6V4+jgan1JvB5jMoJViOLCC5qxgAsFiAXs86v1fWwxRAZ5a1zDQ1gVq8htL0Df69Q3b13/C+ySsst0jxNheM4OB7JN49T/Oto= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-lf1-x12b.google.com with SMTP id 2adb3069b0e04-529597d77b4so3065776e87.0 for ; Mon, 27 May 2024 04:19:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=vrull.eu; s=google; t=1716808777; x=1717413577; 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=1YnX/TTTXRmXP6brc268dqfpbYWjVPFASzcNmzenlFo=; b=OwynvhHw2rGaJd8HE+ydop7UajEwxVPgbhrbn20twpe0wQDOwbQzqXkRPBai3LveM7 1rcUEwZA0kNEn2X3YGaNbV10281PFNjGRcOzcdUlatNnVugkN3U0dqB78yKUQv+rk9dd Oa/qkYqULYduJMolAB8OQpw8RG7SLWqjpRKHZCH3Qezzt1W76TZP/sBWBNjOWtPdqx09 VpdnfFl0I2PjnkTsx1cLUp4k6IEmw02oZnYpXGjMG9BLUZBEljnIvm/WPURNz8N0xT0S m0yxVXaXXZoKk41nbrbMbSrKssLSWzprjGOlmFkLZl3LZopYJOjxxMglHddpv/OgfUwj Lcng== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1716808777; x=1717413577; 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=1YnX/TTTXRmXP6brc268dqfpbYWjVPFASzcNmzenlFo=; b=R8IVobmo5ca1aDtVLX5X7UQin2/BPF2cf8DlByg6Ivpkdyxp8s8w3JGqGm2Cj7Cs5c 1Ho31RcfnojTYgqI+GV3T3kA395FyRdEDIDEjBk8QF6DrHsuHtmaVjztbUEDLtX0lzJj Ke84nADmHbf2U0ylcYs+uB0TQjmkNvDhJsI8NULbG9+S14YLSUfVG3et0u83H54s0eNB lqRFHPnJr2NTJjW8ySsyzb8lHyl45GA+NrrWjuKdi9hxN4yqzP4osLhflmcoPbs3NQPm lvkrkmXVEVWWm66+JtlPrCd4n9cn5HJTeOLdanf4gzZR35jPWQxufE0xW2VpDSdhXJ/q nQZA== X-Gm-Message-State: AOJu0YyXE7oEMv80iZhmo839VMYPEzMcQObjjO+yxDrO4+iv57eF3NbR hvCqlHBpbhJO81MShdha/BEGgBlaXgMAN84Brk7XvHe/cDN55xEQ+IrdxYfoDXjkWMjMDxefrNV j/wLf+g== X-Google-Smtp-Source: AGHT+IHu3Mgv7S6qY8A+j+1p6C+4cYHTUNUaI9hsot9RZZYwyoPSe4ya/qYbD2TP2+bTSXlPueEtRA== X-Received: by 2002:a19:a401:0:b0:523:b7ec:a222 with SMTP id 2adb3069b0e04-529667cfceemr5180307e87.51.1716808776922; Mon, 27 May 2024 04:19:36 -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 2adb3069b0e04-5296e887b1asm519861e87.32.2024.05.27.04.19.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 27 May 2024 04:19:36 -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 v2 15/15] RISC-V: Add Zbb optimized strncmp as ifunc Date: Mon, 27 May 2024 13:19:00 +0200 Message-ID: <20240527111900.1060546-16-christoph.muellner@vrull.eu> X-Mailer: git-send-email 2.45.1 In-Reply-To: <20240527111900.1060546-1-christoph.muellner@vrull.eu> References: <20240527111900.1060546-1-christoph.muellner@vrull.eu> MIME-Version: 1.0 X-Spam-Status: No, score=-12.7 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, T_SCC_BODY_TEXT_LINE 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+incoming=patchwork.ozlabs.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 | 25 ++++++++ .../unix/sysv/linux/riscv/multiarch/Makefile | 3 + .../linux/riscv/multiarch/ifunc-impl-list.c | 6 ++ .../unix/sysv/linux/riscv/multiarch/strncmp.c | 59 +++++++++++++++++++ 5 files changed, 119 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..8485bdecb1 --- /dev/null +++ b/sysdeps/riscv/multiarch/strncmp-zbb.c @@ -0,0 +1,25 @@ +/* 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 + . */ + +/* Build with Zbb enabled. */ +#define __CODEGEN_ATTRIBUTES __attribute__((target("arch=+zbb"))) +#define USE_ZBB_ORCB 1 +#define STRNCMP __strncmp_zbb +#undef libc_hidden_builtin_def +#define libc_hidden_builtin_def(x) +#include diff --git a/sysdeps/unix/sysv/linux/riscv/multiarch/Makefile b/sysdeps/unix/sysv/linux/riscv/multiarch/Makefile index e48ca11149..a4320d6419 100644 --- a/sysdeps/unix/sysv/linux/riscv/multiarch/Makefile +++ b/sysdeps/unix/sysv/linux/riscv/multiarch/Makefile @@ -13,6 +13,8 @@ sysdep_routines += \ strcmp-generic \ strlen \ strlen-generic \ + strncmp \ + strncmp-generic \ # sysdep_routines ifeq ($(have-fattribute-zbb-support),yes) @@ -22,6 +24,7 @@ sysdep_routines += \ strchrnul-zbb \ strcmp-zbb \ strlen-zbb \ + strncmp-zbb \ # Zbb sysdep_routines endif 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 9b4ae40941..a19d88fcf8 100644 --- a/sysdeps/unix/sysv/linux/riscv/multiarch/ifunc-impl-list.c +++ b/sysdeps/unix/sysv/linux/riscv/multiarch/ifunc-impl-list.c @@ -90,5 +90,11 @@ __libc_ifunc_impl_list (const char *name, struct libc_ifunc_impl *array, #endif IFUNC_IMPL_ADD (array, i, strlen, 1, __strlen_generic)) + IFUNC_IMPL (i, name, strncmp, +#if HAVE_RISCV_FATTRIBUTE_ZBB + IFUNC_IMPL_ADD (array, i, strncmp, has_zbb, __strncmp_zbb) +#endif + 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..31a91adcac --- /dev/null +++ b/sysdeps/unix/sysv/linux/riscv/multiarch/strncmp.c @@ -0,0 +1,59 @@ +/* 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) +{ +#if HAVE_RISCV_FATTRIBUTE_ZBB + 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; +#endif + + 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