From patchwork Mon May 27 11:18: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: 90953 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 B92EF386D621 for ; Mon, 27 May 2024 11:21:48 +0000 (GMT) X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-lj1-x231.google.com (mail-lj1-x231.google.com [IPv6:2a00:1450:4864:20::231]) by sourceware.org (Postfix) with ESMTPS id 055C83858CDB for ; Mon, 27 May 2024 11:19:37 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 055C83858CDB 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 055C83858CDB Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2a00:1450:4864:20::231 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1716808780; cv=none; b=QMlU3oFMopaT2dq5ZroZo3dG4zEIJNkV92wIYtHBBEw44tH88doKALXF9rZyaRiZv5IK+efc/N8afyYo7nD/Cu4KKvMShXRrkeMMT2f7ZhFkELBnHrGSH7Q2yxhEpT4a8VDKYbMBg5Fq3rC4Uvj0Rh2bh0h3P9FL1VqYXTPD9vQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1716808780; c=relaxed/simple; bh=TW0/51b2VyhFcIZMaKDWmmwCD48akQKcdunlQ5dovRw=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=vZ7YfpY5M/F4yLozF4I18m/X4wriYs7wlk7RjuZtbec2c8cgz8Ln+FRTksxNKykVhNs7qsZBwcRsMmIppTtjSz0Jw0KOrSFRw0BCs1bOVGgMCu9G9RNR3STcpXm199VSfqaBhNVYVI489moLfYLoYZx5IFfzKEZqEL3P5zq4NiU= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-lj1-x231.google.com with SMTP id 38308e7fff4ca-2e95a1eff78so40475651fa.0 for ; Mon, 27 May 2024 04:19:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=vrull.eu; s=google; t=1716808775; x=1717413575; 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=6dubrFx0Pywo6re2s1o/23KWXa6P1IlggaUtN7zGpHA=; b=p8zAvOKfM99R+5w/NuXu+KuGOhnmsMWUzhX9FEE8UZfm4tjl2z7nhS1GdgXNf6WKuE WrIkRx6vUdAoTOHXHSri96f2YIk48VokOGK97GuNUNIZUEzHWogXDOubaV4lGHou/WoK WF5V0f354+pyvjhqr2h+Yzo7V/UEfg8VP00JZk9DRmuCf0a49MIdC7gV0x0B9e1GXAfw RpgI0/5wcEba9FH/gHif1+iqRNDXy8qcvWuMUXb/prRrWvHNqF6vUxqGFGxEtfQTRMrc jCulXh0FxZB6Pe4AF0hKTlqKpJhs3IZjb9Oxtuu7hYKaXZPKQFJBrK3pubTP9K0g3s+W 3Bzg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1716808775; x=1717413575; 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=6dubrFx0Pywo6re2s1o/23KWXa6P1IlggaUtN7zGpHA=; b=DX+fvBLbZn9fo/y7mGpp9Cbu52eOkKDoFOrET2HxiorukusnBc2Ak6xJsY4ywQi2tO pHRQU3sDId9vMHQ4m8rNUfnH4RD8zWQA1EGEXF+m0KKmiqKJLqZzmhLG1Vhp5z9sGCKP 6Dd46thEuSz4BC9Scw3t5dSmHsJvgauioea1wDOgN7B3RftK97Mql+Xvt4iqxuW/aUYk PMIlxInLcO5rVIZSr9Xo9VR4opH1wrtdt54VZH0ugUJg8Pzo52g3Gq+SX00xA6eYYpwN pln5qGrq+PWlWCEpITkqrj2ga/gAGvpk5uzM4gEQZLaraqlo/Vm9di6uf4r3p06MThvP iZsg== X-Gm-Message-State: AOJu0YzUoKGNoqHPyXSIXWAHaNe7dAnJrsyU3TRyyxwsHb6MuxNfUtIc a5VeTDSPJfjgznOvcHztYd3/5xnsxcvNjxESgq/rLZgHhzmPqf2ah1AYf7/mufrFaqb8i2OwoSV d7FsNng== X-Google-Smtp-Source: AGHT+IFH/Vhg8gC+IBR/LK26QeeoyuSyTcoZ8o4bh0Zthi7lVpULu9sW6r8I5IKdrqa2sfgHsl+kdg== X-Received: by 2002:a19:5e12:0:b0:51d:9ef1:7c62 with SMTP id 2adb3069b0e04-52964ea97f8mr6926575e87.6.1716808775096; Mon, 27 May 2024 04:19:35 -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.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 27 May 2024 04:19:34 -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 14/15] RISC-V: Add Zbb optimized strlen as ifunc Date: Mon, 27 May 2024 13:18:59 +0200 Message-ID: <20240527111900.1060546-15-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+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 | 24 ++++++++ sysdeps/riscv/multiarch/strlen-zbb.c | 23 ++++++++ .../unix/sysv/linux/riscv/multiarch/Makefile | 3 + .../linux/riscv/multiarch/ifunc-impl-list.c | 6 ++ .../unix/sysv/linux/riscv/multiarch/strlen.c | 59 +++++++++++++++++++ 5 files changed, 115 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..e2d59bd4ef --- /dev/null +++ b/sysdeps/riscv/multiarch/strlen-generic.c @@ -0,0 +1,24 @@ +/* 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 +#endif +#include diff --git a/sysdeps/riscv/multiarch/strlen-zbb.c b/sysdeps/riscv/multiarch/strlen-zbb.c new file mode 100644 index 0000000000..3be9e78556 --- /dev/null +++ b/sysdeps/riscv/multiarch/strlen-zbb.c @@ -0,0 +1,23 @@ +/* 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 + . */ + +/* Build with Zbb enabled. */ +#define __CODEGEN_ATTRIBUTES __attribute__((target("arch=+zbb"))) +#define USE_ZBB_ORCB 1 +#define STRLEN __strlen_zbb +#include diff --git a/sysdeps/unix/sysv/linux/riscv/multiarch/Makefile b/sysdeps/unix/sysv/linux/riscv/multiarch/Makefile index 69c4dd2d07..e48ca11149 100644 --- a/sysdeps/unix/sysv/linux/riscv/multiarch/Makefile +++ b/sysdeps/unix/sysv/linux/riscv/multiarch/Makefile @@ -11,6 +11,8 @@ sysdep_routines += \ strchrnul-generic \ strcmp \ strcmp-generic \ + strlen \ + strlen-generic \ # sysdep_routines ifeq ($(have-fattribute-zbb-support),yes) @@ -19,6 +21,7 @@ sysdep_routines += \ memrchr-zbb \ strchrnul-zbb \ strcmp-zbb \ + strlen-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 c761807a7a..9b4ae40941 100644 --- a/sysdeps/unix/sysv/linux/riscv/multiarch/ifunc-impl-list.c +++ b/sysdeps/unix/sysv/linux/riscv/multiarch/ifunc-impl-list.c @@ -84,5 +84,11 @@ __libc_ifunc_impl_list (const char *name, struct libc_ifunc_impl *array, #endif IFUNC_IMPL_ADD (array, i, strcmp, 1, __strcmp_generic)) + IFUNC_IMPL (i, name, strlen, +#if HAVE_RISCV_FATTRIBUTE_ZBB + IFUNC_IMPL_ADD (array, i, strlen, has_zbb, __strlen_zbb) +#endif + 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..dec274af18 --- /dev/null +++ b/sysdeps/unix/sysv/linux/riscv/multiarch/strlen.c @@ -0,0 +1,59 @@ +/* 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) +{ +#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 __strlen_zbb; +#endif + + 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