From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: 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=20M=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=20M=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 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 List-Id: 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 -- 2.44.0