From patchwork Tue Feb 7 00:16:16 2023 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: 64402 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 57577382E688 for ; Tue, 7 Feb 2023 00:22:36 +0000 (GMT) X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-wr1-x434.google.com (mail-wr1-x434.google.com [IPv6:2a00:1450:4864:20::434]) by sourceware.org (Postfix) with ESMTPS id C62FD3858430 for ; Tue, 7 Feb 2023 00:16:56 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org C62FD3858430 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=vrull.eu Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=vrull.eu Received: by mail-wr1-x434.google.com with SMTP id y1so12068015wru.2 for ; Mon, 06 Feb 2023 16:16:56 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=vrull.eu; s=google; 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=6IOSk+1OxTjwROsP2LPHyxBPTrBBo4Xcs3vLgCYTDR8=; b=JvCz0Re60d1+u+Rn3r2Mcg9wi53ckaiFU/3yVmLyYK68lHEFSV22One7l+FaNeEZH9 r4s23zpaDHz8iLTeygeAyzzLMtw5TVfbeGKdTVU0puZmeuxnhTcut62GZqlWAzAEydV0 Ac3sRl3YO04Db3SGqSeFah1mwQrGQ1EN2p2FiO/pvhsl3z3kjweMwBxiByMpb5PsZEuy O15syyUnSowFKABgv9HZaAE9haLO24K18ZHwLRBPSQZ/2r3ImQGcOEI/XsHYxleyjzs4 eAu7N1ZfLaH9WpITMRI8ojxpVrUj/9wvSyCQ3fxEgOHZ+njwHm9e3/pODlwPDCiZ37JU GtWQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; 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=6IOSk+1OxTjwROsP2LPHyxBPTrBBo4Xcs3vLgCYTDR8=; b=sTzX7W9lWYK2YmF/OBbpK3szoM+AS80k+Ppt/oijpfjxk5fRy18O4QCqSD3XYF+9Oa XfGXYrH1GRtl3O7EoOK3LaafCrfOFHv0qmcaBh08diSNUnf3jWJ1BBmOTpbqfdY0kCgf VWJQ8y7FIDFh1beyORhN6oX8Hn2NLkgk4fDFDP23CrjFGAYnuyD99iX+WkOepcUGfo6o fuMkFlSp7773KFi2GmsUNxPOlUU0nXLgJ8zABNPCVQL4f/82M0slQrgUy6FTnJmotgAd B6K8U4ca/AbxEi7/SRLGRnIQaun7wpUxOyB9//ogR+qvyk6hgvayf5n6w08NYk5q951H ykEQ== X-Gm-Message-State: AO0yUKXpdQj+heextPzfQoWaZDGx4RFMx5Q4xRCoQT2B1J5PwNe94R8P Ei6BG2wPZzyaljZktE81kT0SitW3cx2UOhFE X-Google-Smtp-Source: AK7set8dru0OK3DG0olbD17nhax2OsTtl3e4ni0JasA8t3MGXbolRdOc9rEduIUE47lvtuJd1FIihw== X-Received: by 2002:a5d:6d82:0:b0:2c3:c138:e52d with SMTP id l2-20020a5d6d82000000b002c3c138e52dmr12491631wrs.4.1675729015202; Mon, 06 Feb 2023 16:16:55 -0800 (PST) Received: from beast.fritz.box (62-178-148-172.cable.dynamic.surfer.at. [62.178.148.172]) by smtp.gmail.com with ESMTPSA id f1-20020a1cc901000000b003df14531724sm16862050wmb.21.2023.02.06.16.16.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 06 Feb 2023 16:16:54 -0800 (PST) From: Christoph Muellner To: libc-alpha@sourceware.org, Palmer Dabbelt , Darius Rad , Andrew Waterman , DJ Delorie , Vineet Gupta , Kito Cheng , Jeff Law , Philipp Tomsich , Heiko Stuebner Cc: =?utf-8?q?Christoph_M=C3=BCllner?= Subject: [RFC PATCH 17/19] riscv: Add ifunc support for strncmp Date: Tue, 7 Feb 2023 01:16:16 +0100 Message-Id: <20230207001618.458947-18-christoph.muellner@vrull.eu> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230207001618.458947-1-christoph.muellner@vrull.eu> References: <20230207001618.458947-1-christoph.muellner@vrull.eu> MIME-Version: 1.0 X-Spam-Status: No, score=-12.8 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, JMQ_SPF_NEUTRAL, 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.29 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 Sender: "Libc-alpha" From: Christoph Müllner This patch adds ifunc support for calls to strncmp to the RISC-V code. No optimized code is added as part of this patch. Signed-off-by: Christoph Müllner --- sysdeps/riscv/multiarch/Makefile | 3 +- sysdeps/riscv/multiarch/ifunc-impl-list.c | 2 ++ sysdeps/riscv/multiarch/strncmp.c | 40 +++++++++++++++++++++++ sysdeps/riscv/multiarch/strncmp_generic.c | 32 ++++++++++++++++++ 4 files changed, 76 insertions(+), 1 deletion(-) create mode 100644 sysdeps/riscv/multiarch/strncmp.c create mode 100644 sysdeps/riscv/multiarch/strncmp_generic.c diff --git a/sysdeps/riscv/multiarch/Makefile b/sysdeps/riscv/multiarch/Makefile index 73a62be85d..056ce2ffc0 100644 --- a/sysdeps/riscv/multiarch/Makefile +++ b/sysdeps/riscv/multiarch/Makefile @@ -13,5 +13,6 @@ sysdep_routines += \ \ strcmp_generic \ strcmp_zbb \ - strcmp_zbb_unaligned + strcmp_zbb_unaligned \ + strncmp_generic endif diff --git a/sysdeps/riscv/multiarch/ifunc-impl-list.c b/sysdeps/riscv/multiarch/ifunc-impl-list.c index d354aa1178..eb37ed6017 100644 --- a/sysdeps/riscv/multiarch/ifunc-impl-list.c +++ b/sysdeps/riscv/multiarch/ifunc-impl-list.c @@ -63,5 +63,7 @@ __libc_ifunc_impl_list (const char *name, struct libc_ifunc_impl *array, IFUNC_IMPL_ADD (array, i, strcmp, 1, __strcmp_zbb) IFUNC_IMPL_ADD (array, i, strcmp, 1, __strcmp_generic)) + IFUNC_IMPL (i, name, strncmp, + IFUNC_IMPL_ADD (array, i, strncmp, 1, __strncmp_generic)) return i; } diff --git a/sysdeps/riscv/multiarch/strncmp.c b/sysdeps/riscv/multiarch/strncmp.c new file mode 100644 index 0000000000..970aeb8b85 --- /dev/null +++ b/sysdeps/riscv/multiarch/strncmp.c @@ -0,0 +1,40 @@ +/* Multiple versions of strncmp. RISC-V version. + Copyright (C) 2022 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, see + . */ + +/* Define multiple versions only for the definition in libc. */ + +#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 + +extern __typeof (__redirect_strncmp) __libc_strncmp; +extern __typeof (__redirect_strncmp) __strncmp_generic attribute_hidden; + +libc_ifunc (__libc_strncmp, __strncmp_generic); + +# undef strncmp +strong_alias (__libc_strncmp, strncmp); +#else +# include +#endif diff --git a/sysdeps/riscv/multiarch/strncmp_generic.c b/sysdeps/riscv/multiarch/strncmp_generic.c new file mode 100644 index 0000000000..9d8cdf2f1a --- /dev/null +++ b/sysdeps/riscv/multiarch/strncmp_generic.c @@ -0,0 +1,32 @@ +/* strncmp for RISC-V, default version for internal use. + Copyright (C) 2022 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 + +#define STRNCMP __strncmp_generic + +#ifdef SHARED +# undef libc_hidden_builtin_def +# define libc_hidden_builtin_def(name) \ + __hidden_ver1(__strncmp_generic, __GI_strncmp, __strncmp_generic); +#endif + +extern int __strncmp_generic(const char *s1, const char *s2, size_t n); + +#include