From patchwork Wed Feb 1 17:03:38 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adhemerval Zanella Netto X-Patchwork-Id: 64088 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 8DB793858031 for ; Wed, 1 Feb 2023 17:04:44 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 8DB793858031 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1675271084; bh=AjKGR2n03+tuVqqBGNtzj55eB24LbWfBk9DVbP0bD/k=; h=To:Subject:Date:In-Reply-To:References:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=kHNlPKQ/+YBkMIwE0s3deUOveOQ5j3LcbPhHMpscy3IZ1nm7Uue4iveNk98RxX3QE /Q7IWbROAc2hBfqAbwWXPBOspV9A2Y9Zhx9dPj8JWS+56Uf8Cw9ZVaCcGU7OtGog9t +c/Q554FgsTPeKHUv+l4HFMO08ZlGbcNkVF4CGWs= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-ot1-x330.google.com (mail-ot1-x330.google.com [IPv6:2607:f8b0:4864:20::330]) by sourceware.org (Postfix) with ESMTPS id 8C0D43858D35 for ; Wed, 1 Feb 2023 17:04:17 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 8C0D43858D35 Received: by mail-ot1-x330.google.com with SMTP id 14-20020a9d010e000000b0068bdddfa263so2005306otu.2 for ; Wed, 01 Feb 2023 09:04:17 -0800 (PST) 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:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=AjKGR2n03+tuVqqBGNtzj55eB24LbWfBk9DVbP0bD/k=; b=XzzJeFVIWLZDk85YaaA0fLVeI7cT+p9+jSujATOSOQooolp/zRA0LYkDj/snnsu96S iHWCEfMJSKddBzFygJktg4LYGNi4dXKwaHWJ+DeeNzeJTWED5JUoh+TS/8xwYJcc3g8Y zsOiLPKI7sq770gLVfYDjN+qYyc4s9x5ORCdtUt55WwsVYxpQxMO1BU8siKcYQwJnKuD RJSjgLJ5E2pV+FdS3JgG6gAD45iA63js7J2FxCDwruDxspeoUaovBYEhSFf4IRWSWtGt 3LaqUwNiJItfQdjaFGdpnhSxJK86x5VPmeMrwQLLLPNOS+7mfnT0l9MkzU/R14DFQeDl 0Qlg== X-Gm-Message-State: AO0yUKX0J8/Nr3i0jBTLI6B+f0bnOgVZjSOXw/WGZE3VRAHbecS6y2We nKdRIyz7E96eTurRh/uQkRg9dtlHo5vKiODQwxs= X-Google-Smtp-Source: AK7set/BvhTC0queHzG6xyeU4yXbcX7Z7tGEQlty7PxFk7g44MZPVe1O0h2R+fPJdjiQxEeTonFL5w== X-Received: by 2002:a05:6830:348a:b0:68c:34ae:be12 with SMTP id c10-20020a056830348a00b0068c34aebe12mr2194414otu.25.1675271055918; Wed, 01 Feb 2023 09:04:15 -0800 (PST) Received: from mandiga.. ([2804:1b3:a7c2:1887:d2ed:98c2:d2cc:bf06]) by smtp.gmail.com with ESMTPSA id b17-20020a056830311100b006863ccbf067sm8077090ots.74.2023.02.01.09.04.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 01 Feb 2023 09:04:15 -0800 (PST) To: libc-alpha@sourceware.org, Richard Henderson , Noah Goldstein , Jeff Law , Xi Ruoyao Subject: [PATCH v11 01/29] Parameterize op_t from memcopy.h Date: Wed, 1 Feb 2023 14:03:38 -0300 Message-Id: <20230201170406.303978-2-adhemerval.zanella@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230201170406.303978-1-adhemerval.zanella@linaro.org> References: <20230201170406.303978-1-adhemerval.zanella@linaro.org> MIME-Version: 1.0 X-Spam-Status: No, score=-12.1 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, 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: , X-Patchwork-Original-From: Adhemerval Zanella via Libc-alpha From: Adhemerval Zanella Netto Reply-To: Adhemerval Zanella Errors-To: libc-alpha-bounces+patchwork=sourceware.org@sourceware.org Sender: "Libc-alpha" It moves the op_t definition out to an specific header, adds the attribute 'may-alias', and cleanup its duplicated definitions. Checked with a build and check with run-built-tests=no for all major Linux ABIs. Reviewed-by: Richard Henderson --- string/memcmp.c | 1 - sysdeps/generic/memcopy.h | 6 ++---- sysdeps/generic/string-optype.h | 24 ++++++++++++++++++++++++ sysdeps/x86_64/x32/string-optype.h | 24 ++++++++++++++++++++++++ 4 files changed, 50 insertions(+), 5 deletions(-) create mode 100644 sysdeps/generic/string-optype.h create mode 100644 sysdeps/x86_64/x32/string-optype.h diff --git a/string/memcmp.c b/string/memcmp.c index 067b2e6a42..ea0fa03e1c 100644 --- a/string/memcmp.c +++ b/string/memcmp.c @@ -46,7 +46,6 @@ /* Type to use for aligned memory operations. This should normally be the biggest type supported by a single load and store. Must be an unsigned type. */ -# define op_t unsigned long int # define OPSIZ (sizeof (op_t)) /* Threshold value for when to enter the unrolled loops. */ diff --git a/sysdeps/generic/memcopy.h b/sysdeps/generic/memcopy.h index 9f3ffb5d30..b5ffa4d114 100644 --- a/sysdeps/generic/memcopy.h +++ b/sysdeps/generic/memcopy.h @@ -55,10 +55,8 @@ [I fail to understand. I feel stupid. --roland] */ -/* Type to use for aligned memory operations. - This should normally be the biggest type supported by a single load - and store. */ -#define op_t unsigned long int +/* Type to use for aligned memory operations. */ +#include #define OPSIZ (sizeof (op_t)) /* Type to use for unaligned operations. */ diff --git a/sysdeps/generic/string-optype.h b/sysdeps/generic/string-optype.h new file mode 100644 index 0000000000..42bdd2a145 --- /dev/null +++ b/sysdeps/generic/string-optype.h @@ -0,0 +1,24 @@ +/* Define a type to use for word access. Generic version. + Copyright (C) 2023 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 + . */ + +#ifndef _STRING_OPTYPE_H +#define _STRING_OPTYPE_H 1 + +typedef unsigned long int __attribute__ ((__may_alias__)) op_t; + +#endif /* string-optype.h */ diff --git a/sysdeps/x86_64/x32/string-optype.h b/sysdeps/x86_64/x32/string-optype.h new file mode 100644 index 0000000000..e7679f934f --- /dev/null +++ b/sysdeps/x86_64/x32/string-optype.h @@ -0,0 +1,24 @@ +/* Define a type to use for word access. Generic version. + Copyright (C) 2023 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 + . */ + +#ifndef _STRING_OPTYPE_H +#define _STRING_OPTYPE_H 1 + +typedef unsigned long long int __attribute__ ((__may_alias__)) op_t; + +#endif /* string-optype.h */ From patchwork Wed Feb 1 17:03:39 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adhemerval Zanella Netto X-Patchwork-Id: 64089 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 55583385B511 for ; Wed, 1 Feb 2023 17:04:47 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 55583385B511 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1675271087; bh=/LjTbCox23HHYKAX4OyMh7S0k4Sa3TD0XJRzyxBSxpo=; h=To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From:Reply-To:From; b=mLpIMvTEU3vkdY6yI4rsl9c9sQiC96YCIyRftHIp4TNLr9jY3lTLbQL9uX1+nDhLl bpq1DqRar3LRKXx1Z+wNjtCFO22QSB4aQfYVQbaUS40PCYukEtyT0u73Noqq5FygA/ bW2QBbnEPr746apfDr9gwC4t3NSPIkeGZRZ5MKAQ= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-ot1-x32b.google.com (mail-ot1-x32b.google.com [IPv6:2607:f8b0:4864:20::32b]) by sourceware.org (Postfix) with ESMTPS id 4DF4F385840D for ; Wed, 1 Feb 2023 17:04:20 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 4DF4F385840D Received: by mail-ot1-x32b.google.com with SMTP id e21-20020a9d5615000000b006884e5dce99so6595648oti.5 for ; Wed, 01 Feb 2023 09:04:20 -0800 (PST) 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=/LjTbCox23HHYKAX4OyMh7S0k4Sa3TD0XJRzyxBSxpo=; b=uOmmwcdcc7YfNVTKTzJrzYZRW+JOPeHx5hoJI8gdAvgrE6RAR6cuTxPO++V9TT1smp yqf0uqZMt/A1e7KaS1JSnWgc/yXtF4EJFdVkLNIhNBee3S5ykDEHOyx2HBHffeD3In5h BZeRHt8WSLLDD+v/nA0xSDd1rwWM9324vh0qdrYdVD0/ORMfElGoYLCkitlmHV61Yy6+ pcsL6oJnYvBOQpV+9KAEuFdcGZswZEnQipdIJZxrADwrYYkHqIhft1bwiMejiniB7MN5 YFi6+l/C5NTspP/V4v9wblsd9S0EDq5/ZufATY6CqPviyXAJRUb1kwa96L5bRddxDOCF zCyA== X-Gm-Message-State: AO0yUKUXpvhyP3Ncj+/09ZuWs21D02Pc4X3mZuC+UdEvUGpeGFXyYxfe JJG3cdLvQmqoj4rJx+P82/k7XD3CF48PkCbTwws= X-Google-Smtp-Source: AK7set+c4iAQysVO6EakAbjJAw2PtklHfuClzRRLLl/2oFICJ6FWkJRWiAQENKaaYh4KBzwSO43NKg== X-Received: by 2002:a9d:1791:0:b0:68b:cbcd:f7c9 with SMTP id j17-20020a9d1791000000b0068bcbcdf7c9mr6782495otj.33.1675271058907; Wed, 01 Feb 2023 09:04:18 -0800 (PST) Received: from mandiga.. ([2804:1b3:a7c2:1887:d2ed:98c2:d2cc:bf06]) by smtp.gmail.com with ESMTPSA id b17-20020a056830311100b006863ccbf067sm8077090ots.74.2023.02.01.09.04.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 01 Feb 2023 09:04:17 -0800 (PST) To: libc-alpha@sourceware.org, Richard Henderson , Noah Goldstein , Jeff Law , Xi Ruoyao Cc: Carlos O'Donell Subject: [PATCH v11 02/29] Parameterize OP_T_THRES from memcopy.h Date: Wed, 1 Feb 2023 14:03:39 -0300 Message-Id: <20230201170406.303978-3-adhemerval.zanella@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230201170406.303978-1-adhemerval.zanella@linaro.org> References: <20230201170406.303978-1-adhemerval.zanella@linaro.org> 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_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: , X-Patchwork-Original-From: Adhemerval Zanella via Libc-alpha From: Adhemerval Zanella Netto Reply-To: Adhemerval Zanella Errors-To: libc-alpha-bounces+patchwork=sourceware.org@sourceware.org Sender: "Libc-alpha" From: Richard Henderson It moves OP_T_THRES out of memcopy.h to its own header and adjust each architecture that redefines it. Checked with a build and check with run-built-tests=no for all major Linux ABIs. Co-authored-by: Adhemerval Zanella Reviewed-by: Carlos O'Donell Reviewed-by: Richard Henderson --- string/memcmp.c | 3 --- sysdeps/generic/memcopy.h | 4 +--- sysdeps/generic/string-opthr.h | 25 ++++++++++++++++++++++ sysdeps/i386/memcopy.h | 3 --- sysdeps/i386/string-opthr.h | 25 ++++++++++++++++++++++ sysdeps/m68k/memcopy.h | 3 --- sysdeps/powerpc/powerpc32/power4/memcopy.h | 5 ----- 7 files changed, 51 insertions(+), 17 deletions(-) create mode 100644 sysdeps/generic/string-opthr.h create mode 100644 sysdeps/i386/string-opthr.h diff --git a/string/memcmp.c b/string/memcmp.c index ea0fa03e1c..047ca4f98e 100644 --- a/string/memcmp.c +++ b/string/memcmp.c @@ -48,9 +48,6 @@ and store. Must be an unsigned type. */ # define OPSIZ (sizeof (op_t)) -/* Threshold value for when to enter the unrolled loops. */ -# define OP_T_THRES 16 - /* Type to use for unaligned operations. */ typedef unsigned char byte; diff --git a/sysdeps/generic/memcopy.h b/sysdeps/generic/memcopy.h index b5ffa4d114..e9b3f227b2 100644 --- a/sysdeps/generic/memcopy.h +++ b/sysdeps/generic/memcopy.h @@ -57,6 +57,7 @@ /* Type to use for aligned memory operations. */ #include +#include #define OPSIZ (sizeof (op_t)) /* Type to use for unaligned operations. */ @@ -188,9 +189,6 @@ extern void _wordcopy_bwd_dest_aligned (long int, long int, size_t) #endif -/* Threshold value for when to enter the unrolled loops. */ -#define OP_T_THRES 16 - /* Set to 1 if memcpy is safe to use for forward-copying memmove with overlapping addresses. This is 0 by default because memcpy implementations are generally not safe for overlapping addresses. */ diff --git a/sysdeps/generic/string-opthr.h b/sysdeps/generic/string-opthr.h new file mode 100644 index 0000000000..6f10a98edd --- /dev/null +++ b/sysdeps/generic/string-opthr.h @@ -0,0 +1,25 @@ +/* Define a threshold for word access. Generic version. + Copyright (C) 2023 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 + . */ + +#ifndef _STRING_OPTHR_H +#define _STRING_OPTHR_H 1 + +/* Threshold value for when to enter the unrolled loops. */ +#define OP_T_THRES 16 + +#endif /* string-opthr.h */ diff --git a/sysdeps/i386/memcopy.h b/sysdeps/i386/memcopy.h index 4f82689b84..1aa7c3a850 100644 --- a/sysdeps/i386/memcopy.h +++ b/sysdeps/i386/memcopy.h @@ -18,9 +18,6 @@ #include -#undef OP_T_THRES -#define OP_T_THRES 8 - #undef BYTE_COPY_FWD #define BYTE_COPY_FWD(dst_bp, src_bp, nbytes) \ do { \ diff --git a/sysdeps/i386/string-opthr.h b/sysdeps/i386/string-opthr.h new file mode 100644 index 0000000000..ed3e4b2ddb --- /dev/null +++ b/sysdeps/i386/string-opthr.h @@ -0,0 +1,25 @@ +/* Define a threshold for word access. i386 version. + Copyright (C) 2018 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 + . */ + +#ifndef I386_STRING_OPTHR_H +#define I386_STRING_OPTHR_H 1 + +/* Threshold value for when to enter the unrolled loops. */ +#define OP_T_THRES 8 + +#endif /* I386_STRING_OPTHR_H */ diff --git a/sysdeps/m68k/memcopy.h b/sysdeps/m68k/memcopy.h index accd81c1c3..610577071d 100644 --- a/sysdeps/m68k/memcopy.h +++ b/sysdeps/m68k/memcopy.h @@ -20,9 +20,6 @@ #if defined(__mc68020__) || defined(mc68020) -#undef OP_T_THRES -#define OP_T_THRES 16 - /* WORD_COPY_FWD and WORD_COPY_BWD are not symmetric on the 68020, because of its weird instruction overlap characteristics. */ diff --git a/sysdeps/powerpc/powerpc32/power4/memcopy.h b/sysdeps/powerpc/powerpc32/power4/memcopy.h index 384f33b029..872157e485 100644 --- a/sysdeps/powerpc/powerpc32/power4/memcopy.h +++ b/sysdeps/powerpc/powerpc32/power4/memcopy.h @@ -50,11 +50,6 @@ [I fail to understand. I feel stupid. --roland] */ - -/* Threshold value for when to enter the unrolled loops. */ -#undef OP_T_THRES -#define OP_T_THRES 16 - /* Copy exactly NBYTES bytes from SRC_BP to DST_BP, without any assumptions about alignment of the pointers. */ #undef BYTE_COPY_FWD From patchwork Wed Feb 1 17:03:40 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adhemerval Zanella Netto X-Patchwork-Id: 64092 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 B4DD13839DF2 for ; Wed, 1 Feb 2023 17:05:34 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org B4DD13839DF2 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1675271134; bh=LkBuyLP0sOoxDn4wxkTUVOGoOVk76bq7qy7crcPg9ZA=; h=To:Subject:Date:In-Reply-To:References:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=mgzmWvoBR6TDwO34sde3dwCRMKfQ/+VejLknzmD3q4rVFIOVfbq15K5esUChWNYhq mRFo4EzxIs02N7cwjl1cWFYKlerr28Ec8WruDWpOOfTyOCBMYjwjNi8oW91uBTmEpz 8hb6J1UtskrfyJAQ1wwuxOa7t34dmRKfGCJBC168= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-ot1-x332.google.com (mail-ot1-x332.google.com [IPv6:2607:f8b0:4864:20::332]) by sourceware.org (Postfix) with ESMTPS id 142633858407 for ; Wed, 1 Feb 2023 17:04:23 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 142633858407 Received: by mail-ot1-x332.google.com with SMTP id v24-20020a05683011d800b0068bdd29b160so2165649otq.13 for ; Wed, 01 Feb 2023 09:04:23 -0800 (PST) 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:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=LkBuyLP0sOoxDn4wxkTUVOGoOVk76bq7qy7crcPg9ZA=; b=un+S+AgQW0VWKtfVllSR9YJizwyOcwl2iCqX2s/TTwommRwVRLeLq4mor3YaAQvItJ pC3SO+wIHbloJ4jmMsMX1IAB17gj/WOzyQoWkIcLu7KCeBVqNvbEazMaDnKMTZXNl49I kRXowZp8oVFvL79LZNC6acYw52eoZxZf0HYNiXIHs70b7fGiuShc0ZuKiQ97/PFh4m6q 1XXjvkDxWUIgzIYNUPZ7jg//e/D9iw9LPPlV/KqtaH16ejA/REUzrJeF9UrOcbWYYCh6 M+FZbrwEKDPLAsDTW91yohvfI5KE2BJ7I1GMYwtgxDEKIysGCqTCWWDN689VHLRs7DBw 0pEQ== X-Gm-Message-State: AO0yUKVhw0qldpVj+4BGIVeOt+HZoYc39RVb4Na04jBdKTBVCnPyqS7h vI4gU/L3GOf+8OWJ3xu4s8uS0S5PMMnkPcFdg98= X-Google-Smtp-Source: AK7set/MCVovEg0HSPg543GElmCBxL8PUcu7ifUTfdoX/TDJNRe9fassCv+0yuFr8q/n231JqBhtTQ== X-Received: by 2002:a05:6830:3378:b0:68b:d0bf:99ec with SMTP id l56-20020a056830337800b0068bd0bf99ecmr1577702ott.31.1675271061355; Wed, 01 Feb 2023 09:04:21 -0800 (PST) Received: from mandiga.. ([2804:1b3:a7c2:1887:d2ed:98c2:d2cc:bf06]) by smtp.gmail.com with ESMTPSA id b17-20020a056830311100b006863ccbf067sm8077090ots.74.2023.02.01.09.04.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 01 Feb 2023 09:04:20 -0800 (PST) To: libc-alpha@sourceware.org, Richard Henderson , Noah Goldstein , Jeff Law , Xi Ruoyao Subject: [PATCH v11 03/29] Add string vectorized find and detection functions Date: Wed, 1 Feb 2023 14:03:40 -0300 Message-Id: <20230201170406.303978-4-adhemerval.zanella@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230201170406.303978-1-adhemerval.zanella@linaro.org> References: <20230201170406.303978-1-adhemerval.zanella@linaro.org> 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_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: , X-Patchwork-Original-From: Adhemerval Zanella via Libc-alpha From: Adhemerval Zanella Netto Reply-To: Adhemerval Zanella Errors-To: libc-alpha-bounces+patchwork=sourceware.org@sourceware.org Sender: "Libc-alpha" This patch adds generic string find and detection meant to be used in generic vectorized string implementation. The idea is to decompose the basic string operation so each architecture can reimplement if it provides any specialized hardware instruction. The 'string-misc.h' provides miscellaneous functions: - extractbyte: extracts the byte from an specific index. - repeat_bytes: setup an word by replicate the argument on each byte. The 'string-fza.h' provides zero byte detection functions: - find_zero_low, find_zero_all, find_eq_low, find_eq_all, find_zero_eq_low, find_zero_eq_all, find_zero_ne_low, and find_zero_ne_all The 'string-fzb.h' provides boolean zero byte detection functions: - has_zero: determine if any byte within a word is zero. - has_eq: determine byte equality between two words. - has_zero_eq: determine if any byte within a word is zero along with byte equality between two words. The 'string-fzi.h' provides positions for string-fza.h results: - index_first: return index of first zero byte within a word. - index_last: return index of first byte different between two words. The 'string-fzc.h' provides a combined version of fza and fzi: - index_first_zero_eq: return index of first zero byte within a word or first byte different between two words. - index_first_zero_ne: return index of first zero byte within a word or first byte equal between two words. - index_last_zero: return index of last zero byte within a word. - index_last_eq: return index of last byte different between two words. The 'string-shift.h' provides a way to mask off parts of a work based on some alignmnet (to handle unaligned arguments): - shift_find, shift_find_last. Co-authored-by: Richard Henderson --- sysdeps/generic/string-fza.h | 104 +++++++++++++++++++++++++++++++++ sysdeps/generic/string-fzb.h | 49 ++++++++++++++++ sysdeps/generic/string-fzc.h | 91 +++++++++++++++++++++++++++++ sysdeps/generic/string-fzi.h | 71 ++++++++++++++++++++++ sysdeps/generic/string-misc.h | 45 ++++++++++++++ sysdeps/generic/string-shift.h | 52 +++++++++++++++++ 6 files changed, 412 insertions(+) create mode 100644 sysdeps/generic/string-fza.h create mode 100644 sysdeps/generic/string-fzb.h create mode 100644 sysdeps/generic/string-fzc.h create mode 100644 sysdeps/generic/string-fzi.h create mode 100644 sysdeps/generic/string-misc.h create mode 100644 sysdeps/generic/string-shift.h diff --git a/sysdeps/generic/string-fza.h b/sysdeps/generic/string-fza.h new file mode 100644 index 0000000000..b5a5536f73 --- /dev/null +++ b/sysdeps/generic/string-fza.h @@ -0,0 +1,104 @@ +/* Basic zero byte detection. Generic C version. + Copyright (C) 2023 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 + . */ + +#ifndef _STRING_FZA_H +#define _STRING_FZA_H 1 + +#include +#include + +/* The function return a byte mask. */ +typedef op_t find_t; + +/* This function returns non-zero if any byte in X is zero. + More specifically, at least one bit set within the least significant + byte that was zero; other bytes within the word are indeterminate. */ +static __always_inline find_t +find_zero_low (op_t x) +{ + /* This expression comes from + https://graphics.stanford.edu/~seander/bithacks.html#ZeroInWord + Subtracting 1 sets 0x80 in a byte that was 0; anding ~x clears + 0x80 in a byte that was >= 128; anding 0x80 isolates that test bit. */ + op_t lsb = repeat_bytes (0x01); + op_t msb = repeat_bytes (0x80); + return (x - lsb) & ~x & msb; +} + +/* This function returns at least one bit set within every byte of X that + is zero. The result is exact in that, unlike find_zero_low, all bytes + are determinate. This is usually used for finding the index of the + most significant byte that was zero. */ +static __always_inline find_t +find_zero_all (op_t x) +{ + /* For each byte, find not-zero by + (0) And 0x7f so that we cannot carry between bytes, + (1) Add 0x7f so that non-zero carries into 0x80, + (2) Or in the original byte (which might have had 0x80 set). + Then invert and mask such that 0x80 is set iff that byte was zero. */ + op_t m = repeat_bytes (0x7f); + return ~(((x & m) + m) | x | m); +} + +/* With similar caveats, identify bytes that are equal between X1 and X2. */ +static __always_inline find_t +find_eq_low (op_t x1, op_t x2) +{ + return find_zero_low (x1 ^ x2); +} + +static __always_inline find_t +find_eq_all (op_t x1, op_t x2) +{ + return find_zero_all (x1 ^ x2); +} + +/* With similar caveats, identify zero bytes in X1 and bytes that are + equal between in X1 and X2. */ +static __always_inline find_t +find_zero_eq_low (op_t x1, op_t x2) +{ + return find_zero_low (x1) | find_zero_low (x1 ^ x2); +} + +static __always_inline find_t +find_zero_eq_all (op_t x1, op_t x2) +{ + return find_zero_all (x1) | find_zero_all (x1 ^ x2); +} + +/* With similar caveats, identify zero bytes in X1 and bytes that are + not equal between in X1 and X2. */ +static __always_inline find_t +find_zero_ne_low (op_t x1, op_t x2) +{ + return (~find_zero_eq_low (x1, x2)) + 1; +} + +static __always_inline find_t +find_zero_ne_all (op_t x1, op_t x2) +{ + op_t m = repeat_bytes (0x7f); + op_t eq = x1 ^ x2; + op_t nz1 = ((x1 & m) + m) | x1; + op_t ne2 = ((eq & m) + m) | eq; + return (ne2 | ~nz1) & ~m; +} + +#endif /* _STRING_FZA_H */ diff --git a/sysdeps/generic/string-fzb.h b/sysdeps/generic/string-fzb.h new file mode 100644 index 0000000000..42de500d67 --- /dev/null +++ b/sysdeps/generic/string-fzb.h @@ -0,0 +1,49 @@ +/* Zero byte detection, boolean. Generic C version. + Copyright (C) 2023 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 + . */ + +#ifndef _STRING_FZB_H +#define _STRING_FZB_H 1 + +#include +#include + +/* Determine if any byte within X is zero. This is a pure boolean test. */ + +static __always_inline _Bool +has_zero (op_t x) +{ + return find_zero_low (x) != 0; +} + +/* Likewise, but for byte equality between X1 and X2. */ + +static __always_inline _Bool +has_eq (op_t x1, op_t x2) +{ + return find_eq_low (x1, x2) != 0; +} + +/* Likewise, but for zeros in X1 and equal bytes between X1 and X2. */ + +static __always_inline _Bool +has_zero_eq (op_t x1, op_t x2) +{ + return find_zero_eq_low (x1, x2); +} + +#endif /* _STRING_FZB_H */ diff --git a/sysdeps/generic/string-fzc.h b/sysdeps/generic/string-fzc.h new file mode 100644 index 0000000000..f159254535 --- /dev/null +++ b/sysdeps/generic/string-fzc.h @@ -0,0 +1,91 @@ +/* Zero byte detection; indexes. Generic C version. + Copyright (C) 2023 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 + . */ + +#ifndef _STRING_FZC_H +#define _STRING_FZC_H 1 + +#include +#include +#include + + +/* Given a word X that is known to contain a zero byte, return the index of + the first such within the word in memory order. */ +static __always_inline unsigned int +index_first_zero (op_t x) +{ + if (__BYTE_ORDER == __LITTLE_ENDIAN) + x = find_zero_low (x); + else + x = find_zero_all (x); + return index_first (x); +} + +/* Similarly, but perform the search for byte equality between X1 and X2. */ +static __always_inline unsigned int +index_first_eq (op_t x1, op_t x2) +{ + if (__BYTE_ORDER == __LITTLE_ENDIAN) + x1 = find_eq_low (x1, x2); + else + x1 = find_eq_all (x1, x2); + return index_first (x1); +} + +/* Similarly, but perform the search for zero within X1 or equality between + X1 and X2. */ +static __always_inline unsigned int +index_first_zero_eq (op_t x1, op_t x2) +{ + if (__BYTE_ORDER == __LITTLE_ENDIAN) + x1 = find_zero_eq_low (x1, x2); + else + x1 = find_zero_eq_all (x1, x2); + return index_first (x1); +} + +/* Similarly, but perform the search for zero within X1 or inequality between + X1 and X2. */ +static __always_inline unsigned int +index_first_zero_ne (op_t x1, op_t x2) +{ + if (__BYTE_ORDER == __LITTLE_ENDIAN) + x1 = find_zero_ne_low (x1, x2); + else + x1 = find_zero_ne_all (x1, x2); + return index_first (x1); +} + +/* Similarly, but search for the last zero within X. */ +static __always_inline unsigned int +index_last_zero (op_t x) +{ + if (__BYTE_ORDER == __LITTLE_ENDIAN) + x = find_zero_all (x); + else + x = find_zero_low (x); + return index_last (x); +} + +static __always_inline unsigned int +index_last_eq (op_t x1, op_t x2) +{ + return index_last_zero (x1 ^ x2); +} + +#endif /* STRING_FZC_H */ diff --git a/sysdeps/generic/string-fzi.h b/sysdeps/generic/string-fzi.h new file mode 100644 index 0000000000..2deecefc23 --- /dev/null +++ b/sysdeps/generic/string-fzi.h @@ -0,0 +1,71 @@ +/* Zero byte detection; indexes. Generic C version. + Copyright (C) 2023 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 + . */ + +#ifndef _STRING_FZI_H +#define _STRING_FZI_H 1 + +#include +#include +#include + +static __always_inline int +clz (find_t c) +{ + if (sizeof (find_t) == sizeof (unsigned long)) + return __builtin_clzl (c); + else + return __builtin_clzll (c); +} + +static __always_inline int +ctz (find_t c) +{ + if (sizeof (find_t) == sizeof (unsigned long)) + return __builtin_ctzl (c); + else + return __builtin_ctzll (c); +} + +/* A subroutine for the index_zero functions. Given a test word C, return + the (memory order) index of the first byte (in memory order) that is + non-zero. */ +static __always_inline unsigned int +index_first (find_t c) +{ + int r; + if (__BYTE_ORDER == __LITTLE_ENDIAN) + r = ctz (c); + else + r = clz (c); + return r / CHAR_BIT; +} + +/* Similarly, but return the (memory order) index of the last byte that is + non-zero. */ +static __always_inline unsigned int +index_last (find_t c) +{ + int r; + if (__BYTE_ORDER == __LITTLE_ENDIAN) + r = clz (c); + else + r = ctz (c); + return sizeof (find_t) - 1 - (r / CHAR_BIT); +} + +#endif /* STRING_FZI_H */ diff --git a/sysdeps/generic/string-misc.h b/sysdeps/generic/string-misc.h new file mode 100644 index 0000000000..a119646957 --- /dev/null +++ b/sysdeps/generic/string-misc.h @@ -0,0 +1,45 @@ +/* Miscellaneous functions used in string implementations. Generic C version. + Copyright (C) 2023 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 + . */ + +#ifndef _STRING_MISC_H +#define _STRING_MISC_H 1 + +#include +#include +#include + +/* Extract the byte at index IDX from word X, with index 0 being the + least significant byte. */ +static __always_inline unsigned char +extractbyte (op_t x, unsigned int idx) +{ + if (__BYTE_ORDER == __LITTLE_ENDIAN) + return x >> (idx * CHAR_BIT); + else + return x >> (sizeof (x) - 1 - idx) * CHAR_BIT; +} + +/* Setup an word with each byte being c_in. For instance, on a 64 bits + machine with input as 0xce the functions returns 0xcececececececece. */ +static __always_inline op_t +repeat_bytes (unsigned char c_in) +{ + return ((op_t)-1 / 0xff) * c_in; +} + +#endif /* _STRING_MISC_H */ diff --git a/sysdeps/generic/string-shift.h b/sysdeps/generic/string-shift.h new file mode 100644 index 0000000000..9491e8b580 --- /dev/null +++ b/sysdeps/generic/string-shift.h @@ -0,0 +1,52 @@ +/* Shift unaligned word read Generic C version. + Copyright (C) 2023 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 + . */ + +#ifndef _STRING_SHIFT_H +#define _STRING_SHIFT_H 1 + +#include +#include +#include +#include + +/* Return the mask WORD shifted based on S_INT address value, to ignore + values not presented in the aligned word read. */ +static __always_inline find_t +shift_find (find_t word, uintptr_t s) +{ + if (__BYTE_ORDER == __LITTLE_ENDIAN) + return word >> (CHAR_BIT * (s % sizeof (op_t))); + else + return word << (CHAR_BIT * (s % sizeof (op_t))); +} + +/* Mask off the bits defined for the S alignment value, or return WORD if + S is 0. */ +static __always_inline find_t +shift_find_last (find_t word, uintptr_t s) +{ + s = s % sizeof (op_t); + if (s == 0) + return word; + if (__BYTE_ORDER == __LITTLE_ENDIAN) + return word & ~(((op_t)-1) << (s * CHAR_BIT)); + else + return word & ~(((op_t)-1) >> (s * CHAR_BIT)); +} + +#endif /* _STRING_SHIFT_H */ From patchwork Wed Feb 1 17:03:41 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adhemerval Zanella Netto X-Patchwork-Id: 64093 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 77BC538493CD for ; Wed, 1 Feb 2023 17:05:38 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 77BC538493CD DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1675271138; bh=v0Sm1CAMqISIDo3nZ3nOiwklWvA5gNWemviyMGtw4kE=; h=To:Subject:Date:In-Reply-To:References:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=laeoKvNMAjtfyZn4hlG44exCbyVnQ47ypl1k4BvzPhT+0a8Bp6c9mKtwjGX1wLJnj lW/a1y+ZRvTu67F/Xk+mrZyeKpPgQcG+wXFSYPAw9cQmca2TCw6T2cx/pklC+bcSWh QUTwNw0ln3lU2ugqOvUcM92saieQc+m4ecamTNbs= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-oi1-x232.google.com (mail-oi1-x232.google.com [IPv6:2607:f8b0:4864:20::232]) by sourceware.org (Postfix) with ESMTPS id 7067C38582BE for ; Wed, 1 Feb 2023 17:04:25 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 7067C38582BE Received: by mail-oi1-x232.google.com with SMTP id bg12so9637973oib.5 for ; Wed, 01 Feb 2023 09:04:25 -0800 (PST) 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:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=v0Sm1CAMqISIDo3nZ3nOiwklWvA5gNWemviyMGtw4kE=; b=rFqQDFJXcADuGUViOxah5+W3hpyiwLvrVEu4N8VvSHeaqMDsuhsbcWOrUXRkj/1lAH au/3kZD3CBTOv0VOv4Kf5nnikDPHZAoHxPFIZQrTsPwslDAPjNtz1EpGr3gAEhu+qlev 4zH4nHeAH1ANam8fP9ixikNhOcW28UzTxG5oCi5La9L04qi6t84Wlp6OT8Rg/fE7p0si /WTD1oCZWYFs+qKOznktUCUnJ5kyNTf44cnuM2LRgGhy8WWRFpBH8EYmuya3HQfstdlR ECGo56RwnNDZ8dxML5Z9OdAFECGMph3H1EhxPPeIXMAaSYkI4xOqCUzQ7nnSbu+O7uGc J3Sg== X-Gm-Message-State: AO0yUKV15qBnzq6u2bceB60F/rxo4KJTc++W4bf0kkCNXzBhuUKp0743 JzX4Nq7b62e4KwgqQfQwua4k9hXgeHoVe9xVA5Y= X-Google-Smtp-Source: AK7set92P1Mlc/8jrolv4CusOmvimcIrFM20VI6AL3e0nthrpPnw1h4MSW90/sPEdEPMV7P+67mhLg== X-Received: by 2002:a05:6808:1521:b0:378:7986:d8d with SMTP id u33-20020a056808152100b0037879860d8dmr1614051oiw.15.1675271063725; Wed, 01 Feb 2023 09:04:23 -0800 (PST) Received: from mandiga.. ([2804:1b3:a7c2:1887:d2ed:98c2:d2cc:bf06]) by smtp.gmail.com with ESMTPSA id b17-20020a056830311100b006863ccbf067sm8077090ots.74.2023.02.01.09.04.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 01 Feb 2023 09:04:23 -0800 (PST) To: libc-alpha@sourceware.org, Richard Henderson , Noah Goldstein , Jeff Law , Xi Ruoyao Subject: [PATCH v11 04/29] string: Improve generic strlen Date: Wed, 1 Feb 2023 14:03:41 -0300 Message-Id: <20230201170406.303978-5-adhemerval.zanella@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230201170406.303978-1-adhemerval.zanella@linaro.org> References: <20230201170406.303978-1-adhemerval.zanella@linaro.org> 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_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: , X-Patchwork-Original-From: Adhemerval Zanella via Libc-alpha From: Adhemerval Zanella Netto Reply-To: Adhemerval Zanella Errors-To: libc-alpha-bounces+patchwork=sourceware.org@sourceware.org Sender: "Libc-alpha" New algorithm read the first aligned address and mask off the unwanted bytes (this strategy is similar to arch-specific implementations used on powerpc, sparc, and sh). The loop now read word-aligned address and check using the has_zero macro. Checked on x86_64-linux-gnu, i686-linux-gnu, powerpc-linux-gnu, and powercp64-linux-gnu by removing the arch-specific assembly implementation and disabling multi-arch (it covers both LE and BE for 64 and 32 bits). Co-authored-by: Richard Henderson Reviewed-by: Noah Goldstein --- string/strlen.c | 92 ++++++++++------------------------------- sysdeps/s390/strlen-c.c | 10 +++-- 2 files changed, 28 insertions(+), 74 deletions(-) diff --git a/string/strlen.c b/string/strlen.c index ee1aae0fff..5a4424f9a5 100644 --- a/string/strlen.c +++ b/string/strlen.c @@ -15,86 +15,38 @@ License along with the GNU C Library; if not, see . */ +#include +#include +#include +#include +#include #include -#include -#undef strlen - -#ifndef STRLEN -# define STRLEN strlen +#ifdef STRLEN +# define __strlen STRLEN #endif /* Return the length of the null-terminated string STR. Scan for the null terminator quickly by testing four bytes at a time. */ size_t -STRLEN (const char *str) +__strlen (const char *str) { - const char *char_ptr; - const unsigned long int *longword_ptr; - unsigned long int longword, himagic, lomagic; - - /* Handle the first few characters by reading one character at a time. - Do this until CHAR_PTR is aligned on a longword boundary. */ - for (char_ptr = str; ((unsigned long int) char_ptr - & (sizeof (longword) - 1)) != 0; - ++char_ptr) - if (*char_ptr == '\0') - return char_ptr - str; - - /* All these elucidatory comments refer to 4-byte longwords, - but the theory applies equally well to 8-byte longwords. */ - - longword_ptr = (unsigned long int *) char_ptr; + /* Align pointer to sizeof op_t. */ + const uintptr_t s_int = (uintptr_t) str; + const op_t *word_ptr = (const op_t*) PTR_ALIGN_DOWN (str, sizeof (op_t)); - /* Computing (longword - lomagic) sets the high bit of any corresponding - byte that is either zero or greater than 0x80. The latter case can be - filtered out by computing (~longword & himagic). The final result - will always be non-zero if one of the bytes of longword is zero. */ - himagic = 0x80808080L; - lomagic = 0x01010101L; - if (sizeof (longword) > 4) - { - /* 64-bit version of the magic. */ - /* Do the shift in two steps to avoid a warning if long has 32 bits. */ - himagic = ((himagic << 16) << 16) | himagic; - lomagic = ((lomagic << 16) << 16) | lomagic; - } - if (sizeof (longword) > 8) - abort (); + op_t word = *word_ptr; + find_t mask = shift_find (find_zero_all (word), s_int); + if (mask != 0) + return index_first (mask); - /* Instead of the traditional loop which tests each character, - we will test a longword at a time. The tricky part is testing - if *any of the four* bytes in the longword in question are zero. */ - for (;;) - { - longword = *longword_ptr++; + do + word = *++word_ptr; + while (! has_zero (word)); - if (((longword - lomagic) & ~longword & himagic) != 0) - { - /* Which of the bytes was the zero? */ - - const char *cp = (const char *) (longword_ptr - 1); - - if (cp[0] == 0) - return cp - str; - if (cp[1] == 0) - return cp - str + 1; - if (cp[2] == 0) - return cp - str + 2; - if (cp[3] == 0) - return cp - str + 3; - if (sizeof (longword) > 4) - { - if (cp[4] == 0) - return cp - str + 4; - if (cp[5] == 0) - return cp - str + 5; - if (cp[6] == 0) - return cp - str + 6; - if (cp[7] == 0) - return cp - str + 7; - } - } - } + return ((const char *) word_ptr) + index_first_zero (word) - str; } +#ifndef STRLEN +weak_alias (__strlen, strlen) libc_hidden_builtin_def (strlen) +#endif diff --git a/sysdeps/s390/strlen-c.c b/sysdeps/s390/strlen-c.c index b829ef2452..0a33a6f8e5 100644 --- a/sysdeps/s390/strlen-c.c +++ b/sysdeps/s390/strlen-c.c @@ -21,12 +21,14 @@ #if HAVE_STRLEN_C # if HAVE_STRLEN_IFUNC # define STRLEN STRLEN_C +# endif + +# include + +# if HAVE_STRLEN_IFUNC # if defined SHARED && IS_IN (libc) -# undef libc_hidden_builtin_def -# define libc_hidden_builtin_def(name) \ - __hidden_ver1 (__strlen_c, __GI_strlen, __strlen_c); +__hidden_ver1 (__strlen_c, __GI_strlen, __strlen_c); # endif # endif -# include #endif From patchwork Wed Feb 1 17:03:42 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adhemerval Zanella Netto X-Patchwork-Id: 64097 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 5A503385AC39 for ; Wed, 1 Feb 2023 17:06:22 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 5A503385AC39 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1675271182; bh=2SEyxvOct6zIJZeVHDT2AF+/dzL/v9yC+T5860BjCpA=; h=To:Subject:Date:In-Reply-To:References:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=EjUGsB4dcdMS6v0aIPHIc9cylHmLwYW+XbNZckIdQD2SPnNSyQXyQ4b63Qj6eV02C kVl1Cub0bpCgxg0HbjxaSjezDt+ArqCqy8MW2pXiAQPE3SEFnGPvCI2d4mOJiY5q1N 09gxPEqUcILMWIr4yy2mM29KMgYv/+0xPDYUJDXk= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-ot1-x329.google.com (mail-ot1-x329.google.com [IPv6:2607:f8b0:4864:20::329]) by sourceware.org (Postfix) with ESMTPS id E4F623858D39 for ; Wed, 1 Feb 2023 17:04:27 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org E4F623858D39 Received: by mail-ot1-x329.google.com with SMTP id g21-20020a9d6495000000b0068bb336141dso4742638otl.11 for ; Wed, 01 Feb 2023 09:04:27 -0800 (PST) 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:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=2SEyxvOct6zIJZeVHDT2AF+/dzL/v9yC+T5860BjCpA=; b=V3swTFqAUuA4p5KWDrV6+6tEVS/opT45hQ3LEMQak230Kmzj+cVbo8bwiULBd/WD9e wMtO5/7tWoxYAOFrPWe7L0CCu34mucLtjtErKT+w4lIasog2gRvqOzi70OI+FKWhM68C Hlmk37SSzhw7jekUBryn6oF+7UXG+nS1Neu4+8ZThpOma7LMHCdXTYepUjCCyeNCuHFE WWcAywkHhLEwjgjk+j8JSgudj1PAdp2g0jnK0AYZs4llER1PFBB6+f7u/oW289B/28Wk BoGdg3uptEHqaZXJ7w4yB+o5cPSuGbLlFTOCNocNoqjaTYHFjB0Ck9mBvg9MCLObFM4/ Bjbw== X-Gm-Message-State: AO0yUKXVoq+K2ukOtynRfK/vRlAUxGEldvTWbesve1pEc+pOqevVYCmQ S3IDK6/RIjp91r/vpSPktKTo2FJzUFRRwyUB8L8= X-Google-Smtp-Source: AK7set8Jx3Q4MtKVrtnNGtMNJivVqPhZ+egGncMYDR6Mu2UWvpx9Pwx684XO81MkJzeckpDr8M3eCA== X-Received: by 2002:a9d:4783:0:b0:68b:e2cd:9362 with SMTP id b3-20020a9d4783000000b0068be2cd9362mr1331633otf.33.1675271066323; Wed, 01 Feb 2023 09:04:26 -0800 (PST) Received: from mandiga.. ([2804:1b3:a7c2:1887:d2ed:98c2:d2cc:bf06]) by smtp.gmail.com with ESMTPSA id b17-20020a056830311100b006863ccbf067sm8077090ots.74.2023.02.01.09.04.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 01 Feb 2023 09:04:25 -0800 (PST) To: libc-alpha@sourceware.org, Richard Henderson , Noah Goldstein , Jeff Law , Xi Ruoyao Subject: [PATCH v11 05/29] string: Improve generic strnlen with memchr Date: Wed, 1 Feb 2023 14:03:42 -0300 Message-Id: <20230201170406.303978-6-adhemerval.zanella@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230201170406.303978-1-adhemerval.zanella@linaro.org> References: <20230201170406.303978-1-adhemerval.zanella@linaro.org> 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_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: , X-Patchwork-Original-From: Adhemerval Zanella via Libc-alpha From: Adhemerval Zanella Netto Reply-To: Adhemerval Zanella Errors-To: libc-alpha-bounces+patchwork=sourceware.org@sourceware.org Sender: "Libc-alpha" It also cleanups the multiple inclusion by leaving the ifunc implementation to undef the weak_alias and libc_hidden_def. Co-authored-by: Richard Henderson --- string/strnlen.c | 137 +----------------- sysdeps/i386/i686/multiarch/strnlen-c.c | 14 +- .../power4/multiarch/strnlen-ppc32.c | 14 +- sysdeps/s390/strnlen-c.c | 14 +- 4 files changed, 27 insertions(+), 152 deletions(-) diff --git a/string/strnlen.c b/string/strnlen.c index 6ff294eab1..dc23354ec8 100644 --- a/string/strnlen.c +++ b/string/strnlen.c @@ -1,10 +1,6 @@ /* Find the length of STRING, but scan at most MAXLEN characters. Copyright (C) 1991-2023 Free Software Foundation, Inc. - Based on strlen written by Torbjorn Granlund (tege@sics.se), - with help from Dan Sahlin (dan@sics.se); - commentary by Jim Blandy (jimb@ai.mit.edu). - 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 @@ -20,7 +16,6 @@ not, see . */ #include -#include /* Find the length of S, but scan at most MAXLEN characters. If no '\0' terminator is found in that many characters, return MAXLEN. */ @@ -32,134 +27,12 @@ size_t __strnlen (const char *str, size_t maxlen) { - const char *char_ptr, *end_ptr = str + maxlen; - const unsigned long int *longword_ptr; - unsigned long int longword, himagic, lomagic; - - if (maxlen == 0) - return 0; - - if (__glibc_unlikely (end_ptr < str)) - end_ptr = (const char *) ~0UL; - - /* Handle the first few characters by reading one character at a time. - Do this until CHAR_PTR is aligned on a longword boundary. */ - for (char_ptr = str; ((unsigned long int) char_ptr - & (sizeof (longword) - 1)) != 0; - ++char_ptr) - if (*char_ptr == '\0') - { - if (char_ptr > end_ptr) - char_ptr = end_ptr; - return char_ptr - str; - } - - /* All these elucidatory comments refer to 4-byte longwords, - but the theory applies equally well to 8-byte longwords. */ - - longword_ptr = (unsigned long int *) char_ptr; - - /* Bits 31, 24, 16, and 8 of this number are zero. Call these bits - the "holes." Note that there is a hole just to the left of - each byte, with an extra at the end: - - bits: 01111110 11111110 11111110 11111111 - bytes: AAAAAAAA BBBBBBBB CCCCCCCC DDDDDDDD - - The 1-bits make sure that carries propagate to the next 0-bit. - The 0-bits provide holes for carries to fall into. */ - himagic = 0x80808080L; - lomagic = 0x01010101L; - if (sizeof (longword) > 4) - { - /* 64-bit version of the magic. */ - /* Do the shift in two steps to avoid a warning if long has 32 bits. */ - himagic = ((himagic << 16) << 16) | himagic; - lomagic = ((lomagic << 16) << 16) | lomagic; - } - if (sizeof (longword) > 8) - abort (); - - /* Instead of the traditional loop which tests each character, - we will test a longword at a time. The tricky part is testing - if *any of the four* bytes in the longword in question are zero. */ - while (longword_ptr < (unsigned long int *) end_ptr) - { - /* We tentatively exit the loop if adding MAGIC_BITS to - LONGWORD fails to change any of the hole bits of LONGWORD. - - 1) Is this safe? Will it catch all the zero bytes? - Suppose there is a byte with all zeros. Any carry bits - propagating from its left will fall into the hole at its - least significant bit and stop. Since there will be no - carry from its most significant bit, the LSB of the - byte to the left will be unchanged, and the zero will be - detected. - - 2) Is this worthwhile? Will it ignore everything except - zero bytes? Suppose every byte of LONGWORD has a bit set - somewhere. There will be a carry into bit 8. If bit 8 - is set, this will carry into bit 16. If bit 8 is clear, - one of bits 9-15 must be set, so there will be a carry - into bit 16. Similarly, there will be a carry into bit - 24. If one of bits 24-30 is set, there will be a carry - into bit 31, so all of the hole bits will be changed. - - The one misfire occurs when bits 24-30 are clear and bit - 31 is set; in this case, the hole at bit 31 is not - changed. If we had access to the processor carry flag, - we could close this loophole by putting the fourth hole - at bit 32! - - So it ignores everything except 128's, when they're aligned - properly. */ - - longword = *longword_ptr++; - - if ((longword - lomagic) & himagic) - { - /* Which of the bytes was the zero? If none of them were, it was - a misfire; continue the search. */ - - const char *cp = (const char *) (longword_ptr - 1); - - char_ptr = cp; - if (cp[0] == 0) - break; - char_ptr = cp + 1; - if (cp[1] == 0) - break; - char_ptr = cp + 2; - if (cp[2] == 0) - break; - char_ptr = cp + 3; - if (cp[3] == 0) - break; - if (sizeof (longword) > 4) - { - char_ptr = cp + 4; - if (cp[4] == 0) - break; - char_ptr = cp + 5; - if (cp[5] == 0) - break; - char_ptr = cp + 6; - if (cp[6] == 0) - break; - char_ptr = cp + 7; - if (cp[7] == 0) - break; - } - } - char_ptr = end_ptr; - } - - if (char_ptr > end_ptr) - char_ptr = end_ptr; - return char_ptr - str; + const char *found = memchr (str, '\0', maxlen); + return found ? found - str : maxlen; } + #ifndef STRNLEN -libc_hidden_def (__strnlen) weak_alias (__strnlen, strnlen) -#endif +libc_hidden_def (__strnlen) libc_hidden_def (strnlen) +#endif diff --git a/sysdeps/i386/i686/multiarch/strnlen-c.c b/sysdeps/i386/i686/multiarch/strnlen-c.c index 351e939a93..beb0350d53 100644 --- a/sysdeps/i386/i686/multiarch/strnlen-c.c +++ b/sysdeps/i386/i686/multiarch/strnlen-c.c @@ -1,10 +1,10 @@ #define STRNLEN __strnlen_ia32 +#include + #ifdef SHARED -# undef libc_hidden_def -# define libc_hidden_def(name) \ - __hidden_ver1 (__strnlen_ia32, __GI_strnlen, __strnlen_ia32); \ - strong_alias (__strnlen_ia32, __strnlen_ia32_1); \ - __hidden_ver1 (__strnlen_ia32_1, __GI___strnlen, __strnlen_ia32_1); +/* Alias for internal symbol to avoid PLT generation, it redirects the + libc_hidden_def (__strnlen/strlen) to default implementation. */ +__hidden_ver1 (__strnlen_ia32, __GI_strnlen, __strnlen_ia32); +strong_alias (__strnlen_ia32, __strnlen_ia32_1); +__hidden_ver1 (__strnlen_ia32_1, __GI___strnlen, __strnlen_ia32_1); #endif - -#include "string/strnlen.c" diff --git a/sysdeps/powerpc/powerpc32/power4/multiarch/strnlen-ppc32.c b/sysdeps/powerpc/powerpc32/power4/multiarch/strnlen-ppc32.c index 957b9b99e8..2ca1cd7181 100644 --- a/sysdeps/powerpc/powerpc32/power4/multiarch/strnlen-ppc32.c +++ b/sysdeps/powerpc/powerpc32/power4/multiarch/strnlen-ppc32.c @@ -17,12 +17,12 @@ . */ #define STRNLEN __strnlen_ppc +#include + #ifdef SHARED -# undef libc_hidden_def -# define libc_hidden_def(name) \ - __hidden_ver1 (__strnlen_ppc, __GI_strnlen, __strnlen_ppc); \ - strong_alias (__strnlen_ppc, __strnlen_ppc_1); \ - __hidden_ver1 (__strnlen_ppc_1, __GI___strnlen, __strnlen_ppc_1); +/* Alias for internal symbol to avoid PLT generation, it redirects the + libc_hidden_def (__strnlen/strlen) to default implementation. */ +__hidden_ver1 (__strnlen_ppc, __GI_strnlen, __strnlen_ppc); \ +strong_alias (__strnlen_ppc, __strnlen_ppc_1); \ +__hidden_ver1 (__strnlen_ppc_1, __GI___strnlen, __strnlen_ppc_1); #endif - -#include diff --git a/sysdeps/s390/strnlen-c.c b/sysdeps/s390/strnlen-c.c index 172fcc7caa..95156a0ff5 100644 --- a/sysdeps/s390/strnlen-c.c +++ b/sysdeps/s390/strnlen-c.c @@ -21,14 +21,16 @@ #if HAVE_STRNLEN_C # if HAVE_STRNLEN_IFUNC # define STRNLEN STRNLEN_C +# endif + +# include + +# if HAVE_STRNLEN_IFUNC # if defined SHARED && IS_IN (libc) -# undef libc_hidden_def -# define libc_hidden_def(name) \ - __hidden_ver1 (__strnlen_c, __GI_strnlen, __strnlen_c); \ - strong_alias (__strnlen_c, __strnlen_c_1); \ - __hidden_ver1 (__strnlen_c_1, __GI___strnlen, __strnlen_c_1); +__hidden_ver1 (__strnlen_c, __GI_strnlen, __strnlen_c); +strong_alias (__strnlen_c, __strnlen_c_1); +__hidden_ver1 (__strnlen_c_1, __GI___strnlen, __strnlen_c_1); # endif # endif -# include #endif From patchwork Wed Feb 1 17:03:43 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adhemerval Zanella Netto X-Patchwork-Id: 64091 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 ED3BF3881D19 for ; Wed, 1 Feb 2023 17:05:33 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org ED3BF3881D19 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1675271134; bh=9NAPzBLwSQ8PToT9tN0pnM5UqowDNGsD7uyHlOdKXeo=; h=To:Subject:Date:In-Reply-To:References:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=qWlsApDKiacXHiTL/G5BCD99mMENoBSmyvPsfZwrQfotXNBBRO2xnUuMVAIZoj7d/ TgkkGXAWVdluo8flnFcsSjhL8GlAn+k7iXbmd7ZD1CTeP+csX9LyUsXLxalckZmfki QbJvSr1F4VTZ/ZGIgiCu9QypygAbWxcHTSA+s1s0= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-ot1-x334.google.com (mail-ot1-x334.google.com [IPv6:2607:f8b0:4864:20::334]) by sourceware.org (Postfix) with ESMTPS id 1BAE53858298 for ; Wed, 1 Feb 2023 17:04:30 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 1BAE53858298 Received: by mail-ot1-x334.google.com with SMTP id r34-20020a05683044a200b0068d4a8a8d2dso131835otv.12 for ; Wed, 01 Feb 2023 09:04:30 -0800 (PST) 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:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=9NAPzBLwSQ8PToT9tN0pnM5UqowDNGsD7uyHlOdKXeo=; b=gjQuPCvWBDYdNpWBH0ZCppwkWJ2K9w7iPybXJ6oj6o9reO5AFgBgiBfw4mJOc4AOye E+gIWBhN8X+SL/zgXIcKDRQjMJ9gi95/5V9nos02T4ZcUVu6ejAHr8Oftv1vepID+8EE 2sFcywLtGvChQuXQT/5zsndj5T9L+yaC0XmS+Pr5NXwpC+nV+KJ+IpjCQb7J+yz61FU3 Efvorce52831UdxMJJEy8mgB+Z+g+TelgM+GwVfdNAJ5KdNAkGUNGzaFf4s1sB6HgJYm aVbhURKFYKwqdJdhCQ7e3oNiHQ8NfCl2NrfTSMe+a5XEMD6S3PtT1H0e/3vrRUBgwTeF qxnQ== X-Gm-Message-State: AO0yUKWzSxhrnYKEKrcHSi10RTbXb9gtD8HEc+NQDWLw7waKTo/mgNeA BIVpiOruIyyxr4QRjH61FU4jxKkhopHWCZOXNTY= X-Google-Smtp-Source: AK7set94MEgc8PmqbB/ugXyF5Sy7D3PVczYEUqTjvFFQoQM0Qh1s9rC/Hc9wGvJZBlqrfpw/HBMXaQ== X-Received: by 2002:a05:6830:b90:b0:68d:3fc8:7c06 with SMTP id a16-20020a0568300b9000b0068d3fc87c06mr874868otv.1.1675271068790; Wed, 01 Feb 2023 09:04:28 -0800 (PST) Received: from mandiga.. ([2804:1b3:a7c2:1887:d2ed:98c2:d2cc:bf06]) by smtp.gmail.com with ESMTPSA id b17-20020a056830311100b006863ccbf067sm8077090ots.74.2023.02.01.09.04.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 01 Feb 2023 09:04:28 -0800 (PST) To: libc-alpha@sourceware.org, Richard Henderson , Noah Goldstein , Jeff Law , Xi Ruoyao Subject: [PATCH v11 06/29] string: Improve generic strchr Date: Wed, 1 Feb 2023 14:03:43 -0300 Message-Id: <20230201170406.303978-7-adhemerval.zanella@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230201170406.303978-1-adhemerval.zanella@linaro.org> References: <20230201170406.303978-1-adhemerval.zanella@linaro.org> 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_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: , X-Patchwork-Original-From: Adhemerval Zanella via Libc-alpha From: Adhemerval Zanella Netto Reply-To: Adhemerval Zanella Errors-To: libc-alpha-bounces+patchwork=sourceware.org@sourceware.org Sender: "Libc-alpha" New algorithm now calls strchrnul. Checked on x86_64-linux-gnu, i686-linux-gnu, powerpc-linux-gnu, and powerpc64-linux-gnu by removing the arch-specific assembly implementation and disabling multi-arch (it covers both LE and BE for 64 and 32 bits). Reviewed-by: Richard Henderson --- string/strchr.c | 159 ++-------------------------------------- sysdeps/s390/strchr-c.c | 11 +-- 2 files changed, 14 insertions(+), 156 deletions(-) diff --git a/string/strchr.c b/string/strchr.c index 1572b8b42e..30c3eb10f2 100644 --- a/string/strchr.c +++ b/string/strchr.c @@ -21,165 +21,22 @@ . */ #include -#include #undef strchr +#undef index -#ifndef STRCHR -# define STRCHR strchr +#ifdef STRCHR +# define strchr STRCHR #endif /* Find the first occurrence of C in S. */ char * -STRCHR (const char *s, int c_in) +strchr (const char *s, int c_in) { - const unsigned char *char_ptr; - const unsigned long int *longword_ptr; - unsigned long int longword, magic_bits, charmask; - unsigned char c; - - c = (unsigned char) c_in; - - /* Handle the first few characters by reading one character at a time. - Do this until CHAR_PTR is aligned on a longword boundary. */ - for (char_ptr = (const unsigned char *) s; - ((unsigned long int) char_ptr & (sizeof (longword) - 1)) != 0; - ++char_ptr) - if (*char_ptr == c) - return (void *) char_ptr; - else if (*char_ptr == '\0') - return NULL; - - /* All these elucidatory comments refer to 4-byte longwords, - but the theory applies equally well to 8-byte longwords. */ - - longword_ptr = (unsigned long int *) char_ptr; - - /* Bits 31, 24, 16, and 8 of this number are zero. Call these bits - the "holes." Note that there is a hole just to the left of - each byte, with an extra at the end: - - bits: 01111110 11111110 11111110 11111111 - bytes: AAAAAAAA BBBBBBBB CCCCCCCC DDDDDDDD - - The 1-bits make sure that carries propagate to the next 0-bit. - The 0-bits provide holes for carries to fall into. */ - magic_bits = -1; - magic_bits = magic_bits / 0xff * 0xfe << 1 >> 1 | 1; - - /* Set up a longword, each of whose bytes is C. */ - charmask = c | (c << 8); - charmask |= charmask << 16; - if (sizeof (longword) > 4) - /* Do the shift in two steps to avoid a warning if long has 32 bits. */ - charmask |= (charmask << 16) << 16; - if (sizeof (longword) > 8) - abort (); - - /* Instead of the traditional loop which tests each character, - we will test a longword at a time. The tricky part is testing - if *any of the four* bytes in the longword in question are zero. */ - for (;;) - { - /* We tentatively exit the loop if adding MAGIC_BITS to - LONGWORD fails to change any of the hole bits of LONGWORD. - - 1) Is this safe? Will it catch all the zero bytes? - Suppose there is a byte with all zeros. Any carry bits - propagating from its left will fall into the hole at its - least significant bit and stop. Since there will be no - carry from its most significant bit, the LSB of the - byte to the left will be unchanged, and the zero will be - detected. - - 2) Is this worthwhile? Will it ignore everything except - zero bytes? Suppose every byte of LONGWORD has a bit set - somewhere. There will be a carry into bit 8. If bit 8 - is set, this will carry into bit 16. If bit 8 is clear, - one of bits 9-15 must be set, so there will be a carry - into bit 16. Similarly, there will be a carry into bit - 24. If one of bits 24-30 is set, there will be a carry - into bit 31, so all of the hole bits will be changed. - - The one misfire occurs when bits 24-30 are clear and bit - 31 is set; in this case, the hole at bit 31 is not - changed. If we had access to the processor carry flag, - we could close this loophole by putting the fourth hole - at bit 32! - - So it ignores everything except 128's, when they're aligned - properly. - - 3) But wait! Aren't we looking for C as well as zero? - Good point. So what we do is XOR LONGWORD with a longword, - each of whose bytes is C. This turns each byte that is C - into a zero. */ - - longword = *longword_ptr++; - - /* Add MAGIC_BITS to LONGWORD. */ - if ((((longword + magic_bits) - - /* Set those bits that were unchanged by the addition. */ - ^ ~longword) - - /* Look at only the hole bits. If any of the hole bits - are unchanged, most likely one of the bytes was a - zero. */ - & ~magic_bits) != 0 - - /* That caught zeroes. Now test for C. */ - || ((((longword ^ charmask) + magic_bits) ^ ~(longword ^ charmask)) - & ~magic_bits) != 0) - { - /* Which of the bytes was C or zero? - If none of them were, it was a misfire; continue the search. */ - - const unsigned char *cp = (const unsigned char *) (longword_ptr - 1); - - if (*cp == c) - return (char *) cp; - else if (*cp == '\0') - return NULL; - if (*++cp == c) - return (char *) cp; - else if (*cp == '\0') - return NULL; - if (*++cp == c) - return (char *) cp; - else if (*cp == '\0') - return NULL; - if (*++cp == c) - return (char *) cp; - else if (*cp == '\0') - return NULL; - if (sizeof (longword) > 4) - { - if (*++cp == c) - return (char *) cp; - else if (*cp == '\0') - return NULL; - if (*++cp == c) - return (char *) cp; - else if (*cp == '\0') - return NULL; - if (*++cp == c) - return (char *) cp; - else if (*cp == '\0') - return NULL; - if (*++cp == c) - return (char *) cp; - else if (*cp == '\0') - return NULL; - } - } - } - - return NULL; + char *r = __strchrnul (s, c_in); + return (*(unsigned char *)r == (unsigned char)c_in) ? r : NULL; } - -#ifdef weak_alias -# undef index +#ifndef STRCHR weak_alias (strchr, index) -#endif libc_hidden_builtin_def (strchr) +#endif diff --git a/sysdeps/s390/strchr-c.c b/sysdeps/s390/strchr-c.c index c00f2cceea..90822ae0f4 100644 --- a/sysdeps/s390/strchr-c.c +++ b/sysdeps/s390/strchr-c.c @@ -21,13 +21,14 @@ #if HAVE_STRCHR_C # if HAVE_STRCHR_IFUNC # define STRCHR STRCHR_C -# undef weak_alias +# endif + +# include + +# if HAVE_STRCHR_IFUNC # if defined SHARED && IS_IN (libc) -# undef libc_hidden_builtin_def -# define libc_hidden_builtin_def(name) \ - __hidden_ver1 (__strchr_c, __GI_strchr, __strchr_c); +__hidden_ver1 (__strchr_c, __GI_strchr, __strchr_c); # endif # endif -# include #endif From patchwork Wed Feb 1 17:03:44 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adhemerval Zanella Netto X-Patchwork-Id: 64095 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 3012A388B6B6 for ; Wed, 1 Feb 2023 17:06:16 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 3012A388B6B6 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1675271176; bh=TAOcVOOo1EI5ZPiiWn7Dse/eDlr8kK/HN6w733cmB24=; h=To:Subject:Date:In-Reply-To:References:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=FGn1rk23ImHzygZVk5EOCMiWw530vap0KN631gBdts7oCiw3XmE4DCRVCoHs7UMKI 1vapcH+5t1TAk4O6lzHZJlH2352ggju4vhbpjdXCZx8vtNPR+ihNmMHZ6z0l7Nf68r 4N+8x4agKFsqGFrRwEp1sx65iW3VBB3gWowjzjwo= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-oi1-x22d.google.com (mail-oi1-x22d.google.com [IPv6:2607:f8b0:4864:20::22d]) by sourceware.org (Postfix) with ESMTPS id DE09D3857C51 for ; Wed, 1 Feb 2023 17:04:32 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org DE09D3857C51 Received: by mail-oi1-x22d.google.com with SMTP id r9so16261740oig.12 for ; Wed, 01 Feb 2023 09:04:32 -0800 (PST) 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:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=TAOcVOOo1EI5ZPiiWn7Dse/eDlr8kK/HN6w733cmB24=; b=EOpGNG8bTlLETWxsPwXxUfZ57HQxBeVR92CsnUkxS4i/fSsXkjPJBRXjktyO3hvzUX SwI2pI/09exDwDPnuCPL12wuLHsFwXvH1JHQnXKe6vYhAoLn3D4PCX5CeWrgtQywjBtl OHnyEzpSIh37c5CAOcf6Gixi6Xt3iCbdxT6VtmU+9ZYkfGiExnl5ECOAJCu+0GI/cbpo XB4L1cKebTf17N9RTzXyt4EC/J6pQKwppOQhuk6CCp7I/o1PGp36pc8zv5KAePH5SiS6 UD+FtGur6LwMFbATOZnI1lgQoV2uQAkFY2MRjSkvZjaOizmHhGlan1Iv8N5evrtU9EQ3 jIzA== X-Gm-Message-State: AO0yUKVkjwkacAYNu15Ge///izgUtvUOKaYFsxwhuuDyp66uY/txi2fu FamilMyov2xeNh7b1jr3BcNBfSrAVQbNZLdVkK4= X-Google-Smtp-Source: AK7set++sQ/IcKpU/BmxjCFGbM/EPdHaiHrNC6RU+Gj/8tsaQGvOm4fTJKb1ygZNSK2d+aYuOQRcLA== X-Received: by 2002:a54:4703:0:b0:377:7944:554e with SMTP id k3-20020a544703000000b003777944554emr1635461oik.30.1675271071305; Wed, 01 Feb 2023 09:04:31 -0800 (PST) Received: from mandiga.. ([2804:1b3:a7c2:1887:d2ed:98c2:d2cc:bf06]) by smtp.gmail.com with ESMTPSA id b17-20020a056830311100b006863ccbf067sm8077090ots.74.2023.02.01.09.04.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 01 Feb 2023 09:04:30 -0800 (PST) To: libc-alpha@sourceware.org, Richard Henderson , Noah Goldstein , Jeff Law , Xi Ruoyao Subject: [PATCH v11 07/29] string: Improve generic strchrnul Date: Wed, 1 Feb 2023 14:03:44 -0300 Message-Id: <20230201170406.303978-8-adhemerval.zanella@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230201170406.303978-1-adhemerval.zanella@linaro.org> References: <20230201170406.303978-1-adhemerval.zanella@linaro.org> 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_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: , X-Patchwork-Original-From: Adhemerval Zanella via Libc-alpha From: Adhemerval Zanella Netto Reply-To: Adhemerval Zanella Errors-To: libc-alpha-bounces+patchwork=sourceware.org@sourceware.org Sender: "Libc-alpha" New algorithm read the first aligned address and mask off the unwanted bytes (this strategy is similar to arch-specific implementations used on powerpc, sparc, and sh). The loop now read word-aligned address and check using the has_zero_eq function. Checked on x86_64-linux-gnu, i686-linux-gnu, powerpc64-linux-gnu, and powerpc-linux-gnu by removing the arch-specific assembly implementation and disabling multi-arch (it covers both LE and BE for 64 and 32 bits). Co-authored-by: Richard Henderson Reviewed-by: Noah Goldstein --- string/strchrnul.c | 155 +++--------------- .../power4/multiarch/strchrnul-ppc32.c | 4 - sysdeps/s390/strchrnul-c.c | 2 - 3 files changed, 22 insertions(+), 139 deletions(-) diff --git a/string/strchrnul.c b/string/strchrnul.c index fa2db4b417..e7887fa285 100644 --- a/string/strchrnul.c +++ b/string/strchrnul.c @@ -1,10 +1,5 @@ /* Copyright (C) 1991-2023 Free Software Foundation, Inc. This file is part of the GNU C Library. - Based on strlen implementation by Torbjorn Granlund (tege@sics.se), - with help from Dan Sahlin (dan@sics.se) and - bug fix and commentary by Jim Blandy (jimb@ai.mit.edu); - adaptation to strchr suggested by Dick Karpinski (dick@cca.ucsf.edu), - and implemented by Roland McGrath (roland@ai.mit.edu). The GNU C Library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public @@ -20,147 +15,41 @@ License along with the GNU C Library; if not, see . */ +#include +#include +#include +#include +#include #include -#include -#include #undef __strchrnul #undef strchrnul -#ifndef STRCHRNUL -# define STRCHRNUL __strchrnul +#ifdef STRCHRNUL +# define __strchrnul STRCHRNUL #endif /* Find the first occurrence of C in S or the final NUL byte. */ char * -STRCHRNUL (const char *s, int c_in) +__strchrnul (const char *str, int c_in) { - const unsigned char *char_ptr; - const unsigned long int *longword_ptr; - unsigned long int longword, magic_bits, charmask; - unsigned char c; - - c = (unsigned char) c_in; - - /* Handle the first few characters by reading one character at a time. - Do this until CHAR_PTR is aligned on a longword boundary. */ - for (char_ptr = (const unsigned char *) s; - ((unsigned long int) char_ptr & (sizeof (longword) - 1)) != 0; - ++char_ptr) - if (*char_ptr == c || *char_ptr == '\0') - return (void *) char_ptr; - - /* All these elucidatory comments refer to 4-byte longwords, - but the theory applies equally well to 8-byte longwords. */ - - longword_ptr = (unsigned long int *) char_ptr; - - /* Bits 31, 24, 16, and 8 of this number are zero. Call these bits - the "holes." Note that there is a hole just to the left of - each byte, with an extra at the end: - - bits: 01111110 11111110 11111110 11111111 - bytes: AAAAAAAA BBBBBBBB CCCCCCCC DDDDDDDD - - The 1-bits make sure that carries propagate to the next 0-bit. - The 0-bits provide holes for carries to fall into. */ - magic_bits = -1; - magic_bits = magic_bits / 0xff * 0xfe << 1 >> 1 | 1; - - /* Set up a longword, each of whose bytes is C. */ - charmask = c | (c << 8); - charmask |= charmask << 16; - if (sizeof (longword) > 4) - /* Do the shift in two steps to avoid a warning if long has 32 bits. */ - charmask |= (charmask << 16) << 16; - if (sizeof (longword) > 8) - abort (); - - /* Instead of the traditional loop which tests each character, - we will test a longword at a time. The tricky part is testing - if *any of the four* bytes in the longword in question are zero. */ - for (;;) - { - /* We tentatively exit the loop if adding MAGIC_BITS to - LONGWORD fails to change any of the hole bits of LONGWORD. - - 1) Is this safe? Will it catch all the zero bytes? - Suppose there is a byte with all zeros. Any carry bits - propagating from its left will fall into the hole at its - least significant bit and stop. Since there will be no - carry from its most significant bit, the LSB of the - byte to the left will be unchanged, and the zero will be - detected. + /* Align pointer to sizeof op_t. */ + uintptr_t s_int = (uintptr_t) str; + const op_t *word_ptr = (const op_t *) PTR_ALIGN_DOWN (str, sizeof (op_t)); - 2) Is this worthwhile? Will it ignore everything except - zero bytes? Suppose every byte of LONGWORD has a bit set - somewhere. There will be a carry into bit 8. If bit 8 - is set, this will carry into bit 16. If bit 8 is clear, - one of bits 9-15 must be set, so there will be a carry - into bit 16. Similarly, there will be a carry into bit - 24. If one of bits 24-30 is set, there will be a carry - into bit 31, so all of the hole bits will be changed. + op_t repeated_c = repeat_bytes (c_in); - The one misfire occurs when bits 24-30 are clear and bit - 31 is set; in this case, the hole at bit 31 is not - changed. If we had access to the processor carry flag, - we could close this loophole by putting the fourth hole - at bit 32! + op_t word = *word_ptr; + find_t mask = shift_find (find_zero_eq_all (word, repeated_c), s_int); + if (mask != 0) + return (char *) str + index_first (mask); - So it ignores everything except 128's, when they're aligned - properly. + do + word = *++word_ptr; + while (! has_zero_eq (word, repeated_c)); - 3) But wait! Aren't we looking for C as well as zero? - Good point. So what we do is XOR LONGWORD with a longword, - each of whose bytes is C. This turns each byte that is C - into a zero. */ - - longword = *longword_ptr++; - - /* Add MAGIC_BITS to LONGWORD. */ - if ((((longword + magic_bits) - - /* Set those bits that were unchanged by the addition. */ - ^ ~longword) - - /* Look at only the hole bits. If any of the hole bits - are unchanged, most likely one of the bytes was a - zero. */ - & ~magic_bits) != 0 - - /* That caught zeroes. Now test for C. */ - || ((((longword ^ charmask) + magic_bits) ^ ~(longword ^ charmask)) - & ~magic_bits) != 0) - { - /* Which of the bytes was C or zero? - If none of them were, it was a misfire; continue the search. */ - - const unsigned char *cp = (const unsigned char *) (longword_ptr - 1); - - if (*cp == c || *cp == '\0') - return (char *) cp; - if (*++cp == c || *cp == '\0') - return (char *) cp; - if (*++cp == c || *cp == '\0') - return (char *) cp; - if (*++cp == c || *cp == '\0') - return (char *) cp; - if (sizeof (longword) > 4) - { - if (*++cp == c || *cp == '\0') - return (char *) cp; - if (*++cp == c || *cp == '\0') - return (char *) cp; - if (*++cp == c || *cp == '\0') - return (char *) cp; - if (*++cp == c || *cp == '\0') - return (char *) cp; - } - } - } - - /* This should never happen. */ - return NULL; + return (char *) word_ptr + index_first_zero_eq (word, repeated_c); } - +#ifndef STRCHRNUL weak_alias (__strchrnul, strchrnul) +#endif diff --git a/sysdeps/powerpc/powerpc32/power4/multiarch/strchrnul-ppc32.c b/sysdeps/powerpc/powerpc32/power4/multiarch/strchrnul-ppc32.c index 88ce5dfffa..da03ac7c04 100644 --- a/sysdeps/powerpc/powerpc32/power4/multiarch/strchrnul-ppc32.c +++ b/sysdeps/powerpc/powerpc32/power4/multiarch/strchrnul-ppc32.c @@ -19,10 +19,6 @@ #include #define STRCHRNUL __strchrnul_ppc - -#undef weak_alias -#define weak_alias(a,b ) - extern __typeof (strchrnul) __strchrnul_ppc attribute_hidden; #include diff --git a/sysdeps/s390/strchrnul-c.c b/sysdeps/s390/strchrnul-c.c index e1248d1dbf..ff6aa38d4f 100644 --- a/sysdeps/s390/strchrnul-c.c +++ b/sysdeps/s390/strchrnul-c.c @@ -22,8 +22,6 @@ # if HAVE_STRCHRNUL_IFUNC # define STRCHRNUL STRCHRNUL_C # define __strchrnul STRCHRNUL -# undef weak_alias -# define weak_alias(name, alias) # endif # include From patchwork Wed Feb 1 17:03:45 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adhemerval Zanella Netto X-Patchwork-Id: 64099 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 B40143887F69 for ; Wed, 1 Feb 2023 17:06:57 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org B40143887F69 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1675271217; bh=J0Npx0KDYzoKUqvn2dnh07FNwFCRlVqx94u6ZtwAyqQ=; h=To:Subject:Date:In-Reply-To:References:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=qWv9XeFdS4pRgmALCS1xWWtzphW6rRy/hMLEob1Acgo3XS9RugdyQDkj29SZ+JEUl 8YJWn3k8FZxlU/NngSGKfqodH4IufYeXEx67LnnM2QAorrD00CPkDubI/LPBeKLq1p c8DYgOCYsydIw91qzu8erGbDBOfRiJbgxx+mr0Hk= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-oi1-x22b.google.com (mail-oi1-x22b.google.com [IPv6:2607:f8b0:4864:20::22b]) by sourceware.org (Postfix) with ESMTPS id 78A363857BB3 for ; Wed, 1 Feb 2023 17:04:35 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 78A363857BB3 Received: by mail-oi1-x22b.google.com with SMTP id r205so16256096oib.9 for ; Wed, 01 Feb 2023 09:04:35 -0800 (PST) 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:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=J0Npx0KDYzoKUqvn2dnh07FNwFCRlVqx94u6ZtwAyqQ=; b=0Qio/aCzTuEnhQVhNTzwBM7vvrTWUmY4dvb6XItuGX+fyByf03445xGVieYM6Q/nJH JACYV+GK+kbq6WzmE54WVnkcp0Xz+7GJqwtC0obMYP2k8AQ1Q5wH3RiTHx8WQc7oEU4P Ap2OSYkdFvCwyxjfBFHtrn7udpDiXSpUI+bNJE/lUx2wy3ecgE8zkDSxREbv5VJuYMLr WsPeAmalrzwCFTSfszK+JDfzbTHnHbbyWJByZtUAfZ5FzExM7V0r/JVk3etgeeC0KqiP C8mJjkiCz0j1TBiPpN3OhQkYjlmIxg6LkcAWFcB2qHu3PVdbqSOmXJNg4ECumKGj1Ljp z3NA== X-Gm-Message-State: AO0yUKVEh0soioLZbBBCuaMNsQ7dXZj/t40sCx2+lDogV/3oLcT5auxP 42yM8vuJFtAm5b9lKB+4Ct4d85oloL+mXsnrXho= X-Google-Smtp-Source: AK7set9dROkDArRkGn8icTQeQBhSuyCRmjbkAH92CCKtu2v+vRWQumMfjqANx0cPdKRsB+7PUlXzRQ== X-Received: by 2002:a05:6808:a09:b0:378:9dbb:d5a8 with SMTP id n9-20020a0568080a0900b003789dbbd5a8mr1401425oij.7.1675271073774; Wed, 01 Feb 2023 09:04:33 -0800 (PST) Received: from mandiga.. ([2804:1b3:a7c2:1887:d2ed:98c2:d2cc:bf06]) by smtp.gmail.com with ESMTPSA id b17-20020a056830311100b006863ccbf067sm8077090ots.74.2023.02.01.09.04.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 01 Feb 2023 09:04:33 -0800 (PST) To: libc-alpha@sourceware.org, Richard Henderson , Noah Goldstein , Jeff Law , Xi Ruoyao Subject: [PATCH v11 08/29] string: Improve generic strcmp Date: Wed, 1 Feb 2023 14:03:45 -0300 Message-Id: <20230201170406.303978-9-adhemerval.zanella@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230201170406.303978-1-adhemerval.zanella@linaro.org> References: <20230201170406.303978-1-adhemerval.zanella@linaro.org> 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_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: , X-Patchwork-Original-From: Adhemerval Zanella via Libc-alpha From: Adhemerval Zanella Netto Reply-To: Adhemerval Zanella Errors-To: libc-alpha-bounces+patchwork=sourceware.org@sourceware.org Sender: "Libc-alpha" It follows the strategy: - Align the first input to word boundary using byte operations. - If second input is also word aligned, read a word per time, check for null (using has_zero), and check final words using byte operation. - If second input is not word aligned, loop by aligning the source, and merging the result of two reads. Similar to aligned case, check for null with has_zero, and check final words using byte operation. Checked on x86_64-linux-gnu, i686-linux-gnu, powerpc64-linux-gnu, and powerpc-linux-gnu by removing the arch-specific assembly implementation and disabling multi-arch (it covers both LE and BE for 64 and 32 bits). Co-authored-by: Richard Henderson --- string/strcmp.c | 118 +++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 102 insertions(+), 16 deletions(-) diff --git a/string/strcmp.c b/string/strcmp.c index 053f5a8d2b..42e24242b6 100644 --- a/string/strcmp.c +++ b/string/strcmp.c @@ -15,33 +15,119 @@ License along with the GNU C Library; if not, see . */ +#include +#include +#include #include +#include -#undef strcmp - -#ifndef STRCMP -# define STRCMP strcmp +#ifdef STRCMP +# define strcmp STRCMP #endif +static inline int +final_cmp (const op_t w1, const op_t w2) +{ + /* It can not use index_first_zero_ne because it must not compare past the + final '\0' is present (and final_cmp is called before has_zero check). + */ + for (size_t i = 0; i < sizeof (op_t); i++) + { + unsigned char c1 = extractbyte (w1, i); + unsigned char c2 = extractbyte (w2, i); + if (c1 == '\0' || c1 != c2) + return c1 - c2; + } + return 0; +} + +/* Aligned loop: if a difference is found, exit to compare the bytes. Else + if a zero is found we have equal strings. */ +static inline int +strcmp_aligned_loop (const op_t *x1, const op_t *x2, op_t w1) +{ + op_t w2 = *x2++; + + while (w1 == w2) + { + if (has_zero (w1)) + return 0; + w1 = *x1++; + w2 = *x2++; + } + + return final_cmp (w1, w2); +} + +/* Unaligned loop: align the first partial of P2, with 0xff for the rest of + the bytes so that we can also apply the has_zero test to see if we have + already reached EOS. If we have, then we can simply fall through to the + final comparison. */ +static inline int +strcmp_unaligned_loop (const op_t *x1, const op_t *x2, op_t w1, uintptr_t ofs) +{ + op_t w2a = *x2++; + uintptr_t sh_1 = ofs * CHAR_BIT; + uintptr_t sh_2 = sizeof(op_t) * CHAR_BIT - sh_1; + + op_t w2 = MERGE (w2a, sh_1, (op_t)-1, sh_2); + if (!has_zero (w2)) + { + op_t w2b; + + /* Unaligned loop. The invariant is that W2B, which is "ahead" of W1, + does not contain end-of-string. Therefore it is safe (and necessary) + to read another word from each while we do not have a difference. */ + while (1) + { + w2b = *x2++; + w2 = MERGE (w2a, sh_1, w2b, sh_2); + if (w1 != w2) + return final_cmp (w1, w2); + if (has_zero (w2b)) + break; + w1 = *x1++; + w2a = w2b; + } + + /* Zero found in the second partial of P2. If we had EOS in the aligned + word, we have equality. */ + if (has_zero (w1)) + return 0; + + /* Load the final word of P1 and align the final partial of P2. */ + w1 = *x1++; + w2 = MERGE (w2b, sh_1, 0, sh_2); + } + + return final_cmp (w1, w2); +} + /* Compare S1 and S2, returning less than, equal to or greater than zero if S1 is lexicographically less than, equal to or greater than S2. */ int -STRCMP (const char *p1, const char *p2) +strcmp (const char *p1, const char *p2) { - const unsigned char *s1 = (const unsigned char *) p1; - const unsigned char *s2 = (const unsigned char *) p2; - unsigned char c1, c2; - - do + /* Handle the unaligned bytes of p1 first. */ + uintptr_t n = -(uintptr_t)p1 % sizeof(op_t); + for (int i = 0; i < n; ++i) { - c1 = (unsigned char) *s1++; - c2 = (unsigned char) *s2++; - if (c1 == '\0') - return c1 - c2; + unsigned char c1 = *p1++; + unsigned char c2 = *p2++; + int diff = c1 - c2; + if (c1 == '\0' || diff != 0) + return diff; } - while (c1 == c2); - return c1 - c2; + /* P1 is now aligned to op_t. P2 may or may not be. */ + const op_t *x1 = (const op_t *) p1; + op_t w1 = *x1++; + uintptr_t ofs = (uintptr_t) p2 % sizeof(op_t); + return ofs == 0 + ? strcmp_aligned_loop (x1, (const op_t *)p2, w1) + : strcmp_unaligned_loop (x1, (const op_t *)(p2 - ofs), w1, ofs); } +#ifndef STRCMP libc_hidden_builtin_def (strcmp) +#endif From patchwork Wed Feb 1 17:03:46 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adhemerval Zanella Netto X-Patchwork-Id: 64103 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 A8D9F394742B for ; Wed, 1 Feb 2023 17:07:39 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org A8D9F394742B DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1675271259; bh=RigOSPcp4SguP2O0hFzmhpvXg5H4AzvcsiJvlR6LFeo=; h=To:Subject:Date:In-Reply-To:References:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=HQNRrBqj62Sahv9LNveQkFV9ur5cTNw1om51M6a36/AUiq0ToY3+UduBTFY+3td22 /V20Yidqr9cx3OsVkf0rcIDgPf+6BLXUEF8vVfDsTNlmAbmi9SoTYwZ4Lj0pFZnMRZ LOTYvi4SGanCbzFwp9r8LkX/EPM/fiu8SNypXtVM= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-oi1-x22d.google.com (mail-oi1-x22d.google.com [IPv6:2607:f8b0:4864:20::22d]) by sourceware.org (Postfix) with ESMTPS id 3C5FD3858C36 for ; Wed, 1 Feb 2023 17:04:37 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 3C5FD3858C36 Received: by mail-oi1-x22d.google.com with SMTP id r9so16261961oig.12 for ; Wed, 01 Feb 2023 09:04:37 -0800 (PST) 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:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=RigOSPcp4SguP2O0hFzmhpvXg5H4AzvcsiJvlR6LFeo=; b=qFT2aC1mtIJ4p8lAvBBav6HDpbl4Ti6KaKPrrZMpZz/LK3RamDWqqCe/xbyfOnZXTX LjjEtRlY/R4R6GxGZiEJjgT204XY7bkcvhW+N6EJW4xYeE3LhImZg0nQ1zViZKowyDcG XfLD8syXjAD+l4Czi9vNFw4ERS9XdhboXkokA+ZgsQ+jwYazDbI/Da0rjnuSX3FJl7I8 7j2jxdbCQbPdT+dmFjpW1R5gaDjpVT9tm/SbtExcmLzLyDQ56ozIjEYiM6q0Ix3abbuq HJjDZIIeaR8Aa/fEi6/cptg/dAJa6xznZxqcrsNMgwNIgRXt3cm6sNJOf18mGK/ya5rb L8KQ== X-Gm-Message-State: AO0yUKUCP0hjsfJZhDqwxDNvKb2MsSm6G7pcexdk/dpmNSkAL4s/13Tp hIOtYKntlphQujJck6jE1/GZDYWlJg5k5grkg/M= X-Google-Smtp-Source: AK7set9kvpXYpE1NzvyvKiPuUuoeNwxmmSBwIzOSf7/V+uUh6AekRrwZMxWti85qHs0Twn2tZklQcg== X-Received: by 2002:a05:6808:5cf:b0:378:81a0:f640 with SMTP id d15-20020a05680805cf00b0037881a0f640mr1500722oij.43.1675271076232; Wed, 01 Feb 2023 09:04:36 -0800 (PST) Received: from mandiga.. ([2804:1b3:a7c2:1887:d2ed:98c2:d2cc:bf06]) by smtp.gmail.com with ESMTPSA id b17-20020a056830311100b006863ccbf067sm8077090ots.74.2023.02.01.09.04.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 01 Feb 2023 09:04:35 -0800 (PST) To: libc-alpha@sourceware.org, Richard Henderson , Noah Goldstein , Jeff Law , Xi Ruoyao Subject: [PATCH v11 09/29] string: Improve generic strncmp Date: Wed, 1 Feb 2023 14:03:46 -0300 Message-Id: <20230201170406.303978-10-adhemerval.zanella@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230201170406.303978-1-adhemerval.zanella@linaro.org> References: <20230201170406.303978-1-adhemerval.zanella@linaro.org> 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_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: , X-Patchwork-Original-From: Adhemerval Zanella via Libc-alpha From: Adhemerval Zanella Netto Reply-To: Adhemerval Zanella Errors-To: libc-alpha-bounces+patchwork=sourceware.org@sourceware.org Sender: "Libc-alpha" It follows the strategy: - Align the first input to word boundary using byte operations. - If second input is also word aligned, read a word per time, check for null (using has_zero), and check final words using byte operation. - If second input is not word aligned, loop by aligning the source, and merge the result of two reads. Similar to aligned case, check for null with has_zero, and check final words using byte operation. Checked on x86_64-linux-gnu, i686-linux-gnu, powerpc64-linux-gnu, and powerpc-linux-gnu by removing the arch-specific assembly implementation and disabling multi-arch (it covers both LE and BE for 64 and 32 bits). --- string/strcmp-impl.h | 41 ++++++++++++++ string/strcmp.c | 23 ++------ string/strncmp.c | 130 +++++++++++++++++++++++++++++++------------ 3 files changed, 138 insertions(+), 56 deletions(-) create mode 100644 string/strcmp-impl.h diff --git a/string/strcmp-impl.h b/string/strcmp-impl.h new file mode 100644 index 0000000000..618240368a --- /dev/null +++ b/string/strcmp-impl.h @@ -0,0 +1,41 @@ +/* Common definition for string compare implementations. + Copyright (C) 2023 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 + . */ + +#ifndef _STRCMP_IMPL_H +#define _STRCMP_IMPL_H + +#include +#include + +static inline int +final_cmp (const op_t w1, const op_t w2, size_t n) +{ + /* It can not use index_first_zero_ne because it must not compare past the + final '\0' is present (and final_cmp is called before has_zero check). + */ + for (size_t i = 0; i < n; i++) + { + unsigned char c1 = extractbyte (w1, i); + unsigned char c2 = extractbyte (w2, i); + if (c1 == '\0' || c1 != c2) + return c1 - c2; + } + return 0; +} + +#endif diff --git a/string/strcmp.c b/string/strcmp.c index 42e24242b6..8e7b3310db 100644 --- a/string/strcmp.c +++ b/string/strcmp.c @@ -16,6 +16,7 @@ . */ #include +#include #include #include #include @@ -25,22 +26,6 @@ # define strcmp STRCMP #endif -static inline int -final_cmp (const op_t w1, const op_t w2) -{ - /* It can not use index_first_zero_ne because it must not compare past the - final '\0' is present (and final_cmp is called before has_zero check). - */ - for (size_t i = 0; i < sizeof (op_t); i++) - { - unsigned char c1 = extractbyte (w1, i); - unsigned char c2 = extractbyte (w2, i); - if (c1 == '\0' || c1 != c2) - return c1 - c2; - } - return 0; -} - /* Aligned loop: if a difference is found, exit to compare the bytes. Else if a zero is found we have equal strings. */ static inline int @@ -56,7 +41,7 @@ strcmp_aligned_loop (const op_t *x1, const op_t *x2, op_t w1) w2 = *x2++; } - return final_cmp (w1, w2); + return final_cmp (w1, w2, sizeof (op_t)); } /* Unaligned loop: align the first partial of P2, with 0xff for the rest of @@ -83,7 +68,7 @@ strcmp_unaligned_loop (const op_t *x1, const op_t *x2, op_t w1, uintptr_t ofs) w2b = *x2++; w2 = MERGE (w2a, sh_1, w2b, sh_2); if (w1 != w2) - return final_cmp (w1, w2); + return final_cmp (w1, w2, sizeof (op_t)); if (has_zero (w2b)) break; w1 = *x1++; @@ -100,7 +85,7 @@ strcmp_unaligned_loop (const op_t *x1, const op_t *x2, op_t w1, uintptr_t ofs) w2 = MERGE (w2b, sh_1, 0, sh_2); } - return final_cmp (w1, w2); + return final_cmp (w1, w2, sizeof (op_t)); } /* Compare S1 and S2, returning less than, equal to or diff --git a/string/strncmp.c b/string/strncmp.c index fd7cee09b6..3e6040df09 100644 --- a/string/strncmp.c +++ b/string/strncmp.c @@ -15,7 +15,13 @@ License along with the GNU C Library; if not, see . */ +#include +#include +#include +#include +#include #include +#include #include #undef strncmp @@ -24,51 +30,101 @@ #define STRNCMP strncmp #endif -/* Compare no more than N characters of S1 and S2, - returning less than, equal to or greater than zero - if S1 is lexicographically less than, equal to or - greater than S2. */ -int -STRNCMP (const char *s1, const char *s2, size_t n) +/* Aligned loop: if a difference is found, exit to compare the bytes. Else + if a zero is found we have equal strings. */ +static inline int +strncmp_aligned_loop (const op_t *x1, const op_t *x2, op_t w1, size_t n) { - unsigned char c1 = '\0'; - unsigned char c2 = '\0'; + op_t w2 = *x2++; - if (n >= 4) + while (w1 == w2) { - size_t n4 = n >> 2; - do - { - c1 = (unsigned char) *s1++; - c2 = (unsigned char) *s2++; - if (c1 == '\0' || c1 != c2) - return c1 - c2; - c1 = (unsigned char) *s1++; - c2 = (unsigned char) *s2++; - if (c1 == '\0' || c1 != c2) - return c1 - c2; - c1 = (unsigned char) *s1++; - c2 = (unsigned char) *s2++; - if (c1 == '\0' || c1 != c2) - return c1 - c2; - c1 = (unsigned char) *s1++; - c2 = (unsigned char) *s2++; - if (c1 == '\0' || c1 != c2) - return c1 - c2; - } while (--n4 > 0); - n &= 3; + if (n <= sizeof (op_t)) + break; + n -= sizeof (op_t); + + if (has_zero (w1)) + return 0; + w1 = *x1++; + w2 = *x2++; } - while (n > 0) + return final_cmp (w1, w2, n); +} + +/* Unaligned loop: align the first partial of P2, with 0xff for the rest of + the bytes so that we can also apply the has_zero test to see if we have + already reached EOS. If we have, then we can simply fall through to the + final comparison. */ +static inline int +strncmp_unaligned_loop (const op_t *x1, const op_t *x2, op_t w1, uintptr_t ofs, + size_t n) +{ + op_t w2a = *x2++; + uintptr_t sh_1 = ofs * CHAR_BIT; + uintptr_t sh_2 = sizeof(op_t) * CHAR_BIT - sh_1; + + op_t w2 = MERGE (w2a, sh_1, (op_t)-1, sh_2); + if (!has_zero (w2) && n > (sizeof (op_t) - ofs)) { - c1 = (unsigned char) *s1++; - c2 = (unsigned char) *s2++; - if (c1 == '\0' || c1 != c2) - return c1 - c2; - n--; + op_t w2b; + + /* Unaligned loop. The invariant is that W2B, which is "ahead" of W1, + does not contain end-of-string. Therefore it is safe (and necessary) + to read another word from each while we do not have a difference. */ + while (1) + { + w2b = *x2++; + w2 = MERGE (w2a, sh_1, w2b, sh_2); + if (n <= sizeof (op_t) || w1 != w2) + return final_cmp (w1, w2, n); + n -= sizeof(op_t); + if (has_zero (w2b) || n <= (sizeof (op_t) - ofs)) + break; + w1 = *x1++; + w2a = w2b; + } + + /* Zero found in the second partial of P2. If we had EOS in the aligned + word, we have equality. */ + if (has_zero (w1)) + return 0; + + /* Load the final word of P1 and align the final partial of P2. */ + w1 = *x1++; + w2 = MERGE (w2b, sh_1, 0, sh_2); } - return c1 - c2; + return final_cmp (w1, w2, n); } +/* Compare no more than N characters of S1 and S2, + returning less than, equal to or greater than zero + if S1 is lexicographically less than, equal to or + greater than S2. */ +int +STRNCMP (const char *p1, const char *p2, size_t n) +{ + /* Handle the unaligned bytes of p1 first. */ + uintptr_t a = MIN (-(uintptr_t)p1 % sizeof(op_t), n); + int diff = 0; + for (int i = 0; i < a; ++i) + { + unsigned char c1 = *p1++; + unsigned char c2 = *p2++; + diff = c1 - c2; + if (c1 == '\0' || diff != 0) + return diff; + } + if (a == n) + return diff; + + /* P1 is now aligned to op_t. P2 may or may not be. */ + const op_t *x1 = (const op_t *) p1; + op_t w1 = *x1++; + uintptr_t ofs = (uintptr_t) p2 % sizeof(op_t); + return ofs == 0 + ? strncmp_aligned_loop (x1, (const op_t *) p2, w1, n - a) + : strncmp_unaligned_loop (x1, (const op_t *) (p2 - ofs), w1, ofs, n - a); +} libc_hidden_builtin_def (STRNCMP) From patchwork Wed Feb 1 17:03:47 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adhemerval Zanella Netto X-Patchwork-Id: 64107 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 50A29382E682 for ; Wed, 1 Feb 2023 17:08:23 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 50A29382E682 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1675271303; bh=gK9GrUM3bslUVmtrS3stVe3xSJxMT8zT8T6E+gQDgh4=; h=To:Subject:Date:In-Reply-To:References:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=WeetOG+zItBqew3zQ98ZO49Oc/nmSn4IucEaDVQ+y/KM2CZaCAsZoxfD0XTGIEYhF Vhqend/Zw4x3x2/zIojb7gt8EtLh5XNT3iAITZEtcDqmkf4CaEW6X8D2tm97bCRnXs KwylKC2uNafoooy+cA18LWb7pvkP03GWyVkfnjPc= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-oa1-x30.google.com (mail-oa1-x30.google.com [IPv6:2001:4860:4864:20::30]) by sourceware.org (Postfix) with ESMTPS id 292933857400 for ; Wed, 1 Feb 2023 17:04:40 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 292933857400 Received: by mail-oa1-x30.google.com with SMTP id 586e51a60fabf-1685cf2003aso3977034fac.12 for ; Wed, 01 Feb 2023 09:04:40 -0800 (PST) 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:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=gK9GrUM3bslUVmtrS3stVe3xSJxMT8zT8T6E+gQDgh4=; b=eN8pe6yW/XN66IQT3g2FttylW5KJLMvV3jNW+I7Tmxq3dVSk8Tn5fkz/EgOw4JDS7k AEXUzGRDlm1Tf9e9U6I0wAVdzG4QEK0iMeOvUl1aaEqVB+rgd6R/JB8/2ZXbdmqsIhsP AiGCT8c7O91IGIfMWkQyZ6T268S+R6wuBR92CJ6qA81lfypDMIEPrIpr8/AvFfCHTLoy Lj5QJyu2ytFYDkvlyeGAhulF023x7d1n0QWSmB0iBtYnsHKuJ2lGXGUHISB0+UKlgm/6 UkAf9kk3fPMszvJgTP7L7agROAz7gG362uH8tJjWb9ovvJRPL5g4RHAx5kTbiBBFjOji dFPg== X-Gm-Message-State: AO0yUKXSxcx8nxCH/OIihr3ZBh/+cy0S9zQ6nwwYnKehbT81sIXgYZht nQWMJqAHV3aKZQt5L+O7uLwyg89c5KMiAOWyxb4= X-Google-Smtp-Source: AK7set+viKzbzZ+jxKDIVhM5E5saL5CfOihvv2CJ47cLybYDSc8FQwdsA9VFHoThOJb69nYoPHMruw== X-Received: by 2002:a05:6870:41d4:b0:15b:8856:f0cb with SMTP id z20-20020a05687041d400b0015b8856f0cbmr1894663oac.57.1675271078646; Wed, 01 Feb 2023 09:04:38 -0800 (PST) Received: from mandiga.. ([2804:1b3:a7c2:1887:d2ed:98c2:d2cc:bf06]) by smtp.gmail.com with ESMTPSA id b17-20020a056830311100b006863ccbf067sm8077090ots.74.2023.02.01.09.04.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 01 Feb 2023 09:04:37 -0800 (PST) To: libc-alpha@sourceware.org, Richard Henderson , Noah Goldstein , Jeff Law , Xi Ruoyao Subject: [PATCH v11 10/29] string: Improve generic stpcpy Date: Wed, 1 Feb 2023 14:03:47 -0300 Message-Id: <20230201170406.303978-11-adhemerval.zanella@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230201170406.303978-1-adhemerval.zanella@linaro.org> References: <20230201170406.303978-1-adhemerval.zanella@linaro.org> 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_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: , X-Patchwork-Original-From: Adhemerval Zanella via Libc-alpha From: Adhemerval Zanella Netto Reply-To: Adhemerval Zanella Errors-To: libc-alpha-bounces+patchwork=sourceware.org@sourceware.org Sender: "Libc-alpha" It follows the strategy: - Align the destination on word boundary using byte operations. - If source is also word aligned, read a word per time, check for null (using has_zero from string-fzb.h), and write the remaining bytes. - If source is not word aligned, loop by aligning the source, and merging the result of two reads. Similar to aligned case, check for null with has_zero, and write the remaining bytes if null is found. Checked on x86_64-linux-gnu, i686-linux-gnu, powerpc64-linux-gnu, and powerpc-linux-gnu by removing the arch-specific assembly implementation and disabling multi-arch (it covers both LE and BE for 64 and 32 bits). Reviewed-by: Richard Henderson --- string/stpcpy.c | 92 +++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 86 insertions(+), 6 deletions(-) diff --git a/string/stpcpy.c b/string/stpcpy.c index 8df5065cfe..dd0fef12ef 100644 --- a/string/stpcpy.c +++ b/string/stpcpy.c @@ -15,12 +15,12 @@ License along with the GNU C Library; if not, see . */ -#ifdef HAVE_CONFIG_H -# include -#endif - #define NO_MEMPCPY_STPCPY_REDIRECT #include +#include +#include +#include +#include #undef __stpcpy #undef stpcpy @@ -29,12 +29,92 @@ # define STPCPY __stpcpy #endif +static __always_inline char * +write_byte_from_word (op_t *dest, op_t word) +{ + char *d = (char *) dest; + for (size_t i = 0; i < OPSIZ; i++, ++d) + { + char c = extractbyte (word, i); + *d = c; + if (c == '\0') + break; + } + return d; +} + +static __always_inline char * +stpcpy_aligned_loop (op_t *restrict dst, const op_t *restrict src) +{ + op_t word; + while (1) + { + word = *src++; + if (has_zero (word)) + break; + *dst++ = word; + } + + return write_byte_from_word (dst, word); +} + +static __always_inline char * +stpcpy_unaligned_loop (op_t *restrict dst, const op_t *restrict src, + uintptr_t ofs) +{ + op_t w2a = *src++; + uintptr_t sh_1 = ofs * CHAR_BIT; + uintptr_t sh_2 = OPSIZ * CHAR_BIT - sh_1; + + op_t w2 = MERGE (w2a, sh_1, (op_t)-1, sh_2); + if (!has_zero (w2)) + { + op_t w2b; + + /* Unaligned loop. The invariant is that W2B, which is "ahead" of W1, + does not contain end-of-string. Therefore it is safe (and necessary) + to read another word from each while we do not have a difference. */ + while (1) + { + w2b = *src++; + w2 = MERGE (w2a, sh_1, w2b, sh_2); + /* Check if there is zero on w2a. */ + if (has_zero (w2)) + goto out; + *dst++ = w2; + if (has_zero (w2b)) + break; + w2a = w2b; + } + + /* Align the final partial of P2. */ + w2 = MERGE (w2b, sh_1, 0, sh_2); + } + +out: + return write_byte_from_word (dst, w2); +} + + /* Copy SRC to DEST, returning the address of the terminating '\0' in DEST. */ char * STPCPY (char *dest, const char *src) { - size_t len = strlen (src); - return memcpy (dest, src, len + 1) + len; + /* Copy just a few bytes to make DEST aligned. */ + size_t len = (-(uintptr_t) dest) % OPSIZ; + for (; len != 0; len--, ++dest) + { + char c = *src++; + *dest = c; + if (c == '\0') + return dest; + } + + /* DEST is now aligned to op_t, SRC may or may not be. */ + uintptr_t ofs = (uintptr_t) src % OPSIZ; + return ofs == 0 ? stpcpy_aligned_loop ((op_t*) dest, (const op_t *) src) + : stpcpy_unaligned_loop ((op_t*) dest, + (const op_t *) (src - ofs) , ofs); } weak_alias (__stpcpy, stpcpy) libc_hidden_def (__stpcpy) From patchwork Wed Feb 1 17:03:48 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adhemerval Zanella Netto X-Patchwork-Id: 64096 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 A036D3895FD6 for ; Wed, 1 Feb 2023 17:06:20 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org A036D3895FD6 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1675271180; bh=LLY0Tmc+7FJfLueVKTzcdxBygnFQ693kzbq1+1nrLr8=; h=To:Subject:Date:In-Reply-To:References:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=HlDZwnOI+SWw54zTbfxtM4k2lAQ1cMzVuiFRrLOpP3N3zPJE84x5ilV/RMymADydS 6IB5xkhh7+TnkdAoNeuJ5q35LWCRbsR2E7dc8GLedvxIHMDNqIe9HV8+of58b9c6Db Ii1ESzb48LX7hqgdnvk2V8ru3rbdif2Dw2d36fuw= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-ot1-x32a.google.com (mail-ot1-x32a.google.com [IPv6:2607:f8b0:4864:20::32a]) by sourceware.org (Postfix) with ESMTPS id 9859E3858C2F for ; Wed, 1 Feb 2023 17:04:42 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 9859E3858C2F Received: by mail-ot1-x32a.google.com with SMTP id p24-20020a056830131800b0068d4b30536aso37237otq.9 for ; Wed, 01 Feb 2023 09:04:42 -0800 (PST) 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:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=LLY0Tmc+7FJfLueVKTzcdxBygnFQ693kzbq1+1nrLr8=; b=o2ekUSl3rAMdaU1N+/OPJl0vgdyUW27RMndfyztuLkbp1jqSIKhF8qlnsoJEYfPuoa 9DfnXruJnP4sPxaJXgnA6egCcc4+9sczfVO34vab0G6jTiwWJGrUanp+aoQKMqGeopOU sdFo85kGoNEY86iQTk9rJKGRzEdpCHd+5CuQPkUwNxNG7kQPImpylWoKr5b8zk4da7wp K6WpjDYhcASvPfAI5+9mRpe7evSJBQpqvGA1haRwFmgs9WL1YPHwnSy5vn/LjT4L1gIN sTonh/mzotBHKN5UmBHfwy3p6tIMjimVWTIl09Qwnq2pDc4Rp7bIVU5yQ9a3i3MGxqMB RExA== X-Gm-Message-State: AO0yUKU6qlfgROsVDJgSHw7XbzHA1NTGzpQ08nDmxr9QaI1oRMhipOG1 qWBTEEgjPND+qHj1hDYZxITt16301sPj6JxdzqU= X-Google-Smtp-Source: AK7set+rcFg2U0lxlwB/RBGa75d8rnRU0UO4nlwDSy/viPtNRBF/x03dlBujSG6qeeCy3mcSNTDQAw== X-Received: by 2002:a9d:82a:0:b0:68b:e020:e67e with SMTP id 39-20020a9d082a000000b0068be020e67emr3427102oty.12.1675271081009; Wed, 01 Feb 2023 09:04:41 -0800 (PST) Received: from mandiga.. ([2804:1b3:a7c2:1887:d2ed:98c2:d2cc:bf06]) by smtp.gmail.com with ESMTPSA id b17-20020a056830311100b006863ccbf067sm8077090ots.74.2023.02.01.09.04.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 01 Feb 2023 09:04:40 -0800 (PST) To: libc-alpha@sourceware.org, Richard Henderson , Noah Goldstein , Jeff Law , Xi Ruoyao Subject: [PATCH v11 11/29] string: Improve generic strcpy Date: Wed, 1 Feb 2023 14:03:48 -0300 Message-Id: <20230201170406.303978-12-adhemerval.zanella@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230201170406.303978-1-adhemerval.zanella@linaro.org> References: <20230201170406.303978-1-adhemerval.zanella@linaro.org> 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, 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: , X-Patchwork-Original-From: Adhemerval Zanella via Libc-alpha From: Adhemerval Zanella Netto Reply-To: Adhemerval Zanella Errors-To: libc-alpha-bounces+patchwork=sourceware.org@sourceware.org Sender: "Libc-alpha" Now that stpcpy is vectorized based on op_t, it should be better to call it instead of strlen plus memcpy. Checked on x86_64-linux-gnu, i686-linux-gnu, powerpc64-linux-gnu, and powerpc-linux-gnu by removing the arch-specific assembly implementation and disabling multi-arch (it covers both LE and BE for 64 and 32 bits). Reviewed-by: Richard Henderson --- string/strcpy.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/string/strcpy.c b/string/strcpy.c index 0345c71d15..d945d8fdf0 100644 --- a/string/strcpy.c +++ b/string/strcpy.c @@ -19,6 +19,9 @@ #include #undef strcpy +/* Disable internal stpcpy optimization, otherwise the __stpcpy might it + generate a strcpy call. */ +#undef __stpcpy #ifndef STRCPY # define STRCPY strcpy @@ -28,6 +31,7 @@ char * STRCPY (char *dest, const char *src) { - return memcpy (dest, src, strlen (src) + 1); + __stpcpy (dest, src); + return dest; } libc_hidden_builtin_def (strcpy) From patchwork Wed Feb 1 17:03:49 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adhemerval Zanella Netto X-Patchwork-Id: 64109 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 05050395251C for ; Wed, 1 Feb 2023 17:09:05 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 05050395251C DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1675271345; bh=KOV9Ndt4VV0y5vtHWgQr2XcN6XWbZkk7fF/6g9IgGT8=; h=To:Subject:Date:In-Reply-To:References:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=wMErcXEXjIq2t3ErByRpnLpBp1bA+VGMOZlv4VvFvqr6ygM20Tv34+idZ0KrldrWk sY1eC3bIHQzwak3OamIidiTUQV6/RLCH9j96flJ8r4Bz+8+i9z5VoN+1Nxwy71G0C9 +X6+jDLTmMi0tER+bkJEoR/ugSu/WV5lk0NaD5MU= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-ot1-x333.google.com (mail-ot1-x333.google.com [IPv6:2607:f8b0:4864:20::333]) by sourceware.org (Postfix) with ESMTPS id E26653858004 for ; Wed, 1 Feb 2023 17:04:44 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org E26653858004 Received: by mail-ot1-x333.google.com with SMTP id n25-20020a9d7119000000b0068bd8c1e836so2373710otj.3 for ; Wed, 01 Feb 2023 09:04:44 -0800 (PST) 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:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=KOV9Ndt4VV0y5vtHWgQr2XcN6XWbZkk7fF/6g9IgGT8=; b=UezfitIReI6wdKZ15k7oJUacIlikcCpVvOBV9BWUsg2b+rLzBlRk/Qx1pB7OydArsU AsEktzjL67ZTb5FH/1XUkRj3Obxv4zJZZm2dkRCjCqDtRFsNAJYoi0pQbYLI6TTRDJFC vuZjFcyXS02GU0pg1nYsZIb9JDYhGS8I3c167o8dF0osPsDOPaTnoWJC2JBkcE7JYdBX xIRg2gHKf7qv5t4n5Nlz1Mpp8XhiIw4XV8wtRNE227tqHVFH4QjctiLxO9Ta9VokrBWn gohNBq6NjJnB09ot65d0VO2hgGgRr8DBgEfQb+tIq1cPpydUQ/jzIzHRQEYZI4AnpkBT OdTw== X-Gm-Message-State: AO0yUKVy/7uloWT0WzDHcMzIsobm9dJ3Jpy+kKBaLiPD0wN+X+TaQWIc cRYDtRFgbDvNfhRdvF3HS73WfRe4I/kwp/5sYyQ= X-Google-Smtp-Source: AK7set8NVHsSu0t59TJ5/X8jZyM1S4oG7cfv/15r5uoPC3rBzVxmtmgf8VLeEbqRzQH0zXFbGR0Rdg== X-Received: by 2002:a05:6830:105a:b0:684:e09b:439b with SMTP id b26-20020a056830105a00b00684e09b439bmr1697238otp.9.1675271083433; Wed, 01 Feb 2023 09:04:43 -0800 (PST) Received: from mandiga.. ([2804:1b3:a7c2:1887:d2ed:98c2:d2cc:bf06]) by smtp.gmail.com with ESMTPSA id b17-20020a056830311100b006863ccbf067sm8077090ots.74.2023.02.01.09.04.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 01 Feb 2023 09:04:42 -0800 (PST) To: libc-alpha@sourceware.org, Richard Henderson , Noah Goldstein , Jeff Law , Xi Ruoyao Subject: [PATCH v11 12/29] string: Improve generic memchr Date: Wed, 1 Feb 2023 14:03:49 -0300 Message-Id: <20230201170406.303978-13-adhemerval.zanella@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230201170406.303978-1-adhemerval.zanella@linaro.org> References: <20230201170406.303978-1-adhemerval.zanella@linaro.org> 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, 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: , X-Patchwork-Original-From: Adhemerval Zanella via Libc-alpha From: Adhemerval Zanella Netto Reply-To: Adhemerval Zanella Errors-To: libc-alpha-bounces+patchwork=sourceware.org@sourceware.org Sender: "Libc-alpha" New algorithm read the first aligned address and mask off the unwanted bytes (this strategy is similar to arch-specific implementations used on powerpc, sparc, and sh). The loop now read word-aligned address and check using the has_eq macro. Checked on x86_64-linux-gnu, i686-linux-gnu, powerpc-linux-gnu, and powerpc64-linux-gnu by removing the arch-specific assembly implementation and disabling multi-arch (it covers both LE and BE for 64 and 32 bits). Co-authored-by: Richard Henderson Reviewed-by: Noah Goldstein --- string/memchr.c | 176 +++++------------- .../powerpc32/power4/multiarch/memchr-ppc32.c | 14 +- .../powerpc64/multiarch/memchr-ppc64.c | 9 +- 3 files changed, 56 insertions(+), 143 deletions(-) diff --git a/string/memchr.c b/string/memchr.c index f800d47dce..4f497d6166 100644 --- a/string/memchr.c +++ b/string/memchr.c @@ -1,10 +1,6 @@ -/* Copyright (C) 1991-2023 Free Software Foundation, Inc. +/* Scan memory for a character. Generic version + Copyright (C) 1991-2023 Free Software Foundation, Inc. This file is part of the GNU C Library. - Based on strlen implementation by Torbjorn Granlund (tege@sics.se), - with help from Dan Sahlin (dan@sics.se) and - commentary by Jim Blandy (jimb@ai.mit.edu); - adaptation to memchr suggested by Dick Karpinski (dick@cca.ucsf.edu), - and implemented by Roland McGrath (roland@ai.mit.edu). The GNU C Library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public @@ -20,143 +16,73 @@ License along with the GNU C Library; if not, see . */ -#ifndef _LIBC -# include -#endif - +#include +#include +#include +#include +#include #include -#include +#undef memchr -#include - -#undef __memchr -#ifdef _LIBC -# undef memchr +#ifdef MEMCHR +# define __memchr MEMCHR #endif -#ifndef weak_alias -# define __memchr memchr -#endif - -#ifndef MEMCHR -# define MEMCHR __memchr -#endif +static __always_inline const char * +sadd (uintptr_t x, uintptr_t y) +{ + return (const char *)(y > UINTPTR_MAX - x ? UINTPTR_MAX : x + y); +} /* Search no more than N bytes of S for C. */ void * -MEMCHR (void const *s, int c_in, size_t n) +__memchr (void const *s, int c_in, size_t n) { - /* On 32-bit hardware, choosing longword to be a 32-bit unsigned - long instead of a 64-bit uintmax_t tends to give better - performance. On 64-bit hardware, unsigned long is generally 64 - bits already. Change this typedef to experiment with - performance. */ - typedef unsigned long int longword; - - const unsigned char *char_ptr; - const longword *longword_ptr; - longword repeated_one; - longword repeated_c; - unsigned char c; - - c = (unsigned char) c_in; - - /* Handle the first few bytes by reading one byte at a time. - Do this until CHAR_PTR is aligned on a longword boundary. */ - for (char_ptr = (const unsigned char *) s; - n > 0 && (size_t) char_ptr % sizeof (longword) != 0; - --n, ++char_ptr) - if (*char_ptr == c) - return (void *) char_ptr; - - longword_ptr = (const longword *) char_ptr; - - /* All these elucidatory comments refer to 4-byte longwords, - but the theory applies equally well to any size longwords. */ - - /* Compute auxiliary longword values: - repeated_one is a value which has a 1 in every byte. - repeated_c has c in every byte. */ - repeated_one = 0x01010101; - repeated_c = c | (c << 8); - repeated_c |= repeated_c << 16; - if (0xffffffffU < (longword) -1) + if (__glibc_unlikely (n == 0)) + return NULL; + + /* Read the first word, but munge it so that bytes before the array + will not match goal. */ + const op_t *word_ptr = PTR_ALIGN_DOWN (s, sizeof (op_t)); + uintptr_t s_int = (uintptr_t) s; + + op_t word = *word_ptr; + op_t repeated_c = repeat_bytes (c_in); + /* Compute the address of the last byte taking in consideration possible + overflow. */ + const char *lbyte = sadd (s_int, n - 1); + /* And also the address of the word containing the last byte. */ + const op_t *lword = (const op_t *) PTR_ALIGN_DOWN (lbyte, sizeof (op_t)); + + find_t mask = shift_find (find_eq_all (word, repeated_c), s_int); + if (mask != 0) { - repeated_one |= repeated_one << 31 << 1; - repeated_c |= repeated_c << 31 << 1; - if (8 < sizeof (longword)) - { - size_t i; - - for (i = 64; i < sizeof (longword) * 8; i *= 2) - { - repeated_one |= repeated_one << i; - repeated_c |= repeated_c << i; - } - } + char *ret = (char *) s + index_first (mask); + return (ret <= lbyte) ? ret : NULL; } + if (word_ptr == lword) + return NULL; - /* Instead of the traditional loop which tests each byte, we will test a - longword at a time. The tricky part is testing if *any of the four* - bytes in the longword in question are equal to c. We first use an xor - with repeated_c. This reduces the task to testing whether *any of the - four* bytes in longword1 is zero. - - We compute tmp = - ((longword1 - repeated_one) & ~longword1) & (repeated_one << 7). - That is, we perform the following operations: - 1. Subtract repeated_one. - 2. & ~longword1. - 3. & a mask consisting of 0x80 in every byte. - Consider what happens in each byte: - - If a byte of longword1 is zero, step 1 and 2 transform it into 0xff, - and step 3 transforms it into 0x80. A carry can also be propagated - to more significant bytes. - - If a byte of longword1 is nonzero, let its lowest 1 bit be at - position k (0 <= k <= 7); so the lowest k bits are 0. After step 1, - the byte ends in a single bit of value 0 and k bits of value 1. - After step 2, the result is just k bits of value 1: 2^k - 1. After - step 3, the result is 0. And no carry is produced. - So, if longword1 has only non-zero bytes, tmp is zero. - Whereas if longword1 has a zero byte, call j the position of the least - significant zero byte. Then the result has a zero at positions 0, ..., - j-1 and a 0x80 at position j. We cannot predict the result at the more - significant bytes (positions j+1..3), but it does not matter since we - already have a non-zero bit at position 8*j+7. - - So, the test whether any byte in longword1 is zero is equivalent to - testing whether tmp is nonzero. */ - - while (n >= sizeof (longword)) + word = *++word_ptr; + while (word_ptr != lword) { - longword longword1 = *longword_ptr ^ repeated_c; - - if ((((longword1 - repeated_one) & ~longword1) - & (repeated_one << 7)) != 0) - break; - longword_ptr++; - n -= sizeof (longword); + if (has_eq (word, repeated_c)) + return (char *) word_ptr + index_first_eq (word, repeated_c); + word = *++word_ptr; } - char_ptr = (const unsigned char *) longword_ptr; - - /* At this point, we know that either n < sizeof (longword), or one of the - sizeof (longword) bytes starting at char_ptr is == c. On little-endian - machines, we could determine the first such byte without any further - memory accesses, just by looking at the tmp result from the last loop - iteration. But this does not work on big-endian machines. Choose code - that works in both cases. */ - - for (; n > 0; --n, ++char_ptr) + if (has_eq (word, repeated_c)) { - if (*char_ptr == c) - return (void *) char_ptr; + /* We found a match, but it might be in a byte past the end of the + array. */ + char *ret = (char *) word_ptr + index_first_eq (word, repeated_c); + if (ret <= lbyte) + return ret; } - return NULL; } -#ifdef weak_alias +#ifndef MEMCHR weak_alias (__memchr, memchr) -#endif libc_hidden_builtin_def (memchr) +#endif diff --git a/sysdeps/powerpc/powerpc32/power4/multiarch/memchr-ppc32.c b/sysdeps/powerpc/powerpc32/power4/multiarch/memchr-ppc32.c index 39ff84f3f3..a78585650f 100644 --- a/sysdeps/powerpc/powerpc32/power4/multiarch/memchr-ppc32.c +++ b/sysdeps/powerpc/powerpc32/power4/multiarch/memchr-ppc32.c @@ -18,17 +18,11 @@ #include -#define MEMCHR __memchr_ppc +extern __typeof (memchr) __memchr_ppc attribute_hidden; -#undef weak_alias -#define weak_alias(a, b) +#define MEMCHR __memchr_ppc +#include #ifdef SHARED -# undef libc_hidden_builtin_def -# define libc_hidden_builtin_def(name) \ - __hidden_ver1(__memchr_ppc, __GI_memchr, __memchr_ppc); +__hidden_ver1(__memchr_ppc, __GI_memchr, __memchr_ppc); #endif - -extern __typeof (memchr) __memchr_ppc attribute_hidden; - -#include diff --git a/sysdeps/powerpc/powerpc64/multiarch/memchr-ppc64.c b/sysdeps/powerpc/powerpc64/multiarch/memchr-ppc64.c index 8097df709c..49ba5521fe 100644 --- a/sysdeps/powerpc/powerpc64/multiarch/memchr-ppc64.c +++ b/sysdeps/powerpc/powerpc64/multiarch/memchr-ppc64.c @@ -18,14 +18,7 @@ #include -#define MEMCHR __memchr_ppc - -#undef weak_alias -#define weak_alias(a, b) - -# undef libc_hidden_builtin_def -# define libc_hidden_builtin_def(name) - extern __typeof (memchr) __memchr_ppc attribute_hidden; +#define MEMCHR __memchr_ppc #include From patchwork Wed Feb 1 17:03:50 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adhemerval Zanella Netto X-Patchwork-Id: 64101 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 5D9BC38AA243 for ; Wed, 1 Feb 2023 17:07:08 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 5D9BC38AA243 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1675271228; bh=7cy7idv/9iOjqsQkmCHk4Y14no1De7nayu/3OI428ZM=; h=To:Subject:Date:In-Reply-To:References:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=tz81itMeTlwCtYmVuPYZ3BiFu6ZX/9hS6VC8g76IflBjaFUfH35DAcQuHOrmVopW0 oNyh6fqhuPjBlWWBZmEJxLYomMVovKNGm0yhp0asQXiK71o7sMzZf1m/dlwt1Kp1mh RD4/3QYJn/c/xxa2BMTQOLDFtvgdncmA+8anIwuc= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-oi1-x229.google.com (mail-oi1-x229.google.com [IPv6:2607:f8b0:4864:20::229]) by sourceware.org (Postfix) with ESMTPS id 478813858024 for ; Wed, 1 Feb 2023 17:04:47 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 478813858024 Received: by mail-oi1-x229.google.com with SMTP id bx13so10475079oib.13 for ; Wed, 01 Feb 2023 09:04:47 -0800 (PST) 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:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=7cy7idv/9iOjqsQkmCHk4Y14no1De7nayu/3OI428ZM=; b=H5SnZN7Uin6msOkZ4QTSNg22SbsRxnDGK4lGeJgf4QbuJIR0TMMWXJNfOrNt6e9eRr RHQnZzPUgV87uLNFf4/rollt5zUNcpBkCQJYs2oPM/JxA3o3PvV6YWo9brLwXtXEfiDv v6Pr0GL0hMx+Np2dJOILiqX0MzQ6s6pKVw3qkdeVL2bTLRd2JoKeT7Q2/VhQBn1su4FF YIWcmaPTbXHPvRpBbvU4Mh+TNVZ/vAUVJpNCeA2tJnn1PCgcjeNQhiTpXD+XHjIphYgE BdjZ/hZ8wrkfElEb+ZMdwvf6f8oMyzHwmWtatYvXyQETyHyp8SJdOecHhlwPcZuwaV1U 8HbQ== X-Gm-Message-State: AO0yUKVmPpRgYSbycgIjXNvHeu2MYGIN/S0T1f7cf9+mSR54nYAVIzAH rM6My2UDObGqZvluEyVaUPvlmuVve1kQo5DAotQ= X-Google-Smtp-Source: AK7set9zX8HSPCwYTcafMc0SCYeMoDLKoXds6knQRFKlLvk7Q+O5fo0L39QAvmGDQJRbbHCruKRbNw== X-Received: by 2002:a54:4492:0:b0:36e:bab6:cb71 with SMTP id v18-20020a544492000000b0036ebab6cb71mr1396655oiv.50.1675271085986; Wed, 01 Feb 2023 09:04:45 -0800 (PST) Received: from mandiga.. ([2804:1b3:a7c2:1887:d2ed:98c2:d2cc:bf06]) by smtp.gmail.com with ESMTPSA id b17-20020a056830311100b006863ccbf067sm8077090ots.74.2023.02.01.09.04.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 01 Feb 2023 09:04:45 -0800 (PST) To: libc-alpha@sourceware.org, Richard Henderson , Noah Goldstein , Jeff Law , Xi Ruoyao Subject: [PATCH v11 13/29] string: Improve generic memrchr Date: Wed, 1 Feb 2023 14:03:50 -0300 Message-Id: <20230201170406.303978-14-adhemerval.zanella@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230201170406.303978-1-adhemerval.zanella@linaro.org> References: <20230201170406.303978-1-adhemerval.zanella@linaro.org> 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, 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: , X-Patchwork-Original-From: Adhemerval Zanella via Libc-alpha From: Adhemerval Zanella Netto Reply-To: Adhemerval Zanella Errors-To: libc-alpha-bounces+patchwork=sourceware.org@sourceware.org Sender: "Libc-alpha" New algorithm read the lastaligned address and mask off the unwanted bytes. The loop now read word-aligned address and check using the has_eq macro. Checked on x86_64-linux-gnu, i686-linux-gnu, powerpc-linux-gnu, and powerpc64-linux-gnu by removing the arch-specific assembly implementation and disabling multi-arch (it covers both LE and BE for 64 and 32 bits). Co-authored-by: Richard Henderson Reviewed-by: Noah Goldstein --- string/memrchr.c | 196 ++++++++++------------------------------------- 1 file changed, 39 insertions(+), 157 deletions(-) diff --git a/string/memrchr.c b/string/memrchr.c index 18b20ff76a..b37f2a68c8 100644 --- a/string/memrchr.c +++ b/string/memrchr.c @@ -1,11 +1,6 @@ /* memrchr -- find the last occurrence of a byte in a memory block Copyright (C) 1991-2023 Free Software Foundation, Inc. This file is part of the GNU C Library. - Based on strlen implementation by Torbjorn Granlund (tege@sics.se), - with help from Dan Sahlin (dan@sics.se) and - commentary by Jim Blandy (jimb@ai.mit.edu); - adaptation to memchr suggested by Dick Karpinski (dick@cca.ucsf.edu), - and implemented by Roland McGrath (roland@ai.mit.edu). The GNU C Library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public @@ -21,177 +16,64 @@ License along with the GNU C Library; if not, see . */ -#include - -#ifdef HAVE_CONFIG_H -# include -#endif - -#if defined _LIBC -# include -# include -#endif - -#if defined HAVE_LIMITS_H || defined _LIBC -# include -#endif - -#define LONG_MAX_32_BITS 2147483647 - -#ifndef LONG_MAX -# define LONG_MAX LONG_MAX_32_BITS -#endif - -#include +#include +#include +#include +#include +#include +#include #undef __memrchr #undef memrchr -#ifndef weak_alias -# define __memrchr memrchr +#ifdef MEMRCHR +# define __memrchr MEMRCHR #endif -/* Search no more than N bytes of S for C. */ void * -#ifndef MEMRCHR -__memrchr -#else -MEMRCHR -#endif - (const void *s, int c_in, size_t n) +__memrchr (const void *s, int c_in, size_t n) { - const unsigned char *char_ptr; - const unsigned long int *longword_ptr; - unsigned long int longword, magic_bits, charmask; - unsigned char c; - - c = (unsigned char) c_in; - - /* Handle the last few characters by reading one character at a time. - Do this until CHAR_PTR is aligned on a longword boundary. */ - for (char_ptr = (const unsigned char *) s + n; - n > 0 && ((unsigned long int) char_ptr - & (sizeof (longword) - 1)) != 0; - --n) - if (*--char_ptr == c) - return (void *) char_ptr; - - /* All these elucidatory comments refer to 4-byte longwords, - but the theory applies equally well to 8-byte longwords. */ - - longword_ptr = (const unsigned long int *) char_ptr; - - /* Bits 31, 24, 16, and 8 of this number are zero. Call these bits - the "holes." Note that there is a hole just to the left of - each byte, with an extra at the end: + if (__glibc_unlikely (n == 0)) + return NULL; - bits: 01111110 11111110 11111110 11111111 - bytes: AAAAAAAA BBBBBBBB CCCCCCCC DDDDDDDD + const op_t *word_ptr = (const op_t *) PTR_ALIGN_UP (s + n, sizeof (op_t)); + uintptr_t s_int = (uintptr_t) s + n; - The 1-bits make sure that carries propagate to the next 0-bit. - The 0-bits provide holes for carries to fall into. */ - magic_bits = -1; - magic_bits = magic_bits / 0xff * 0xfe << 1 >> 1 | 1; + op_t word = *--word_ptr; + op_t repeated_c = repeat_bytes (c_in); - /* Set up a longword, each of whose bytes is C. */ - charmask = c | (c << 8); - charmask |= charmask << 16; -#if LONG_MAX > LONG_MAX_32_BITS - charmask |= charmask << 32; -#endif + /* Compute the address of the word containing the initial byte. */ + const op_t *sword = (const op_t *) PTR_ALIGN_DOWN (s, sizeof (op_t)); - /* Instead of the traditional loop which tests each character, - we will test a longword at a time. The tricky part is testing - if *any of the four* bytes in the longword in question are zero. */ - while (n >= sizeof (longword)) + /* If the end of buffer is not op_t aligned, mask off the undesirable bits + before find the last byte position. */ + find_t mask = shift_find_last (find_eq_all (word, repeated_c), s_int); + if (mask != 0) { - /* We tentatively exit the loop if adding MAGIC_BITS to - LONGWORD fails to change any of the hole bits of LONGWORD. - - 1) Is this safe? Will it catch all the zero bytes? - Suppose there is a byte with all zeros. Any carry bits - propagating from its left will fall into the hole at its - least significant bit and stop. Since there will be no - carry from its most significant bit, the LSB of the - byte to the left will be unchanged, and the zero will be - detected. - - 2) Is this worthwhile? Will it ignore everything except - zero bytes? Suppose every byte of LONGWORD has a bit set - somewhere. There will be a carry into bit 8. If bit 8 - is set, this will carry into bit 16. If bit 8 is clear, - one of bits 9-15 must be set, so there will be a carry - into bit 16. Similarly, there will be a carry into bit - 24. If one of bits 24-30 is set, there will be a carry - into bit 31, so all of the hole bits will be changed. - - The one misfire occurs when bits 24-30 are clear and bit - 31 is set; in this case, the hole at bit 31 is not - changed. If we had access to the processor carry flag, - we could close this loophole by putting the fourth hole - at bit 32! - - So it ignores everything except 128's, when they're aligned - properly. - - 3) But wait! Aren't we looking for C, not zero? - Good point. So what we do is XOR LONGWORD with a longword, - each of whose bytes is C. This turns each byte that is C - into a zero. */ - - longword = *--longword_ptr ^ charmask; - - /* Add MAGIC_BITS to LONGWORD. */ - if ((((longword + magic_bits) - - /* Set those bits that were unchanged by the addition. */ - ^ ~longword) - - /* Look at only the hole bits. If any of the hole bits - are unchanged, most likely one of the bytes was a - zero. */ - & ~magic_bits) != 0) - { - /* Which of the bytes was C? If none of them were, it was - a misfire; continue the search. */ - - const unsigned char *cp = (const unsigned char *) longword_ptr; - -#if LONG_MAX > 2147483647 - if (cp[7] == c) - return (void *) &cp[7]; - if (cp[6] == c) - return (void *) &cp[6]; - if (cp[5] == c) - return (void *) &cp[5]; - if (cp[4] == c) - return (void *) &cp[4]; -#endif - if (cp[3] == c) - return (void *) &cp[3]; - if (cp[2] == c) - return (void *) &cp[2]; - if (cp[1] == c) - return (void *) &cp[1]; - if (cp[0] == c) - return (void *) cp; - } - - n -= sizeof (longword); + char *ret = (char *) word_ptr + index_last (mask); + return ret >= (char *) s ? ret : NULL; } + if (word_ptr == sword) + return NULL; + word = *--word_ptr; - char_ptr = (const unsigned char *) longword_ptr; - - while (n-- > 0) + while (word_ptr != sword) { - if (*--char_ptr == c) - return (void *) char_ptr; + if (has_eq (word, repeated_c)) + return (char *) word_ptr + index_last_eq (word, repeated_c); + word = *--word_ptr; } - return 0; + if (has_eq (word, repeated_c)) + { + /* We found a match, but it might be in a byte past the end of the + array. */ + char *ret = (char *) word_ptr + index_last_eq (word, repeated_c); + if (ret >= (char *) s) + return ret; + } + return NULL; } #ifndef MEMRCHR -# ifdef weak_alias weak_alias (__memrchr, memrchr) -# endif #endif From patchwork Wed Feb 1 17:03:51 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adhemerval Zanella Netto X-Patchwork-Id: 64111 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 3EF31383FB96 for ; Wed, 1 Feb 2023 17:09:46 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 3EF31383FB96 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1675271386; bh=uR+tmviJAnIQt3Uy9C/8G52NzH6k6qWZDh0/RH+zyro=; h=To:Subject:Date:In-Reply-To:References:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=PGtbod4udQ3xG1gth91ayW1imPo1aWvhmicXRleyqoQfRd4C8QCyKnbp333hneTT+ I+MVFpcMjw9ySoMusPUTMOStE4F8+9vOrtJFNYcpL9Sqzg1F/WkmwenXoGNs9W2t6l aoKnSgejz2yTU9O2GWfIc83kOn6SwvblcZm2diuk= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-ot1-x333.google.com (mail-ot1-x333.google.com [IPv6:2607:f8b0:4864:20::333]) by sourceware.org (Postfix) with ESMTPS id CC37B3858404 for ; Wed, 1 Feb 2023 17:04:49 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org CC37B3858404 Received: by mail-ot1-x333.google.com with SMTP id n25-20020a9d7119000000b0068bd8c1e836so2373783otj.3 for ; Wed, 01 Feb 2023 09:04:49 -0800 (PST) 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:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=uR+tmviJAnIQt3Uy9C/8G52NzH6k6qWZDh0/RH+zyro=; b=SvZmmZgMe1LUuTXUe8Dfy+g6sSBOPpiK9a34Y6U9pueKl1ZEuioQosoC7lilFoBbta kdBgTtK5Ur3zYLUPuekCCpY15IL6F24Mbv5R6VHOmIdLD/MzTaNZIz9vnoa3LsOiszI4 3rQKgS59iWfzz/e7WXhDp0EJlkalUkOoHFk296C5j+vN9kvq4GbzNlg1IeeJ4rV7u/dv WdUoUwGRtJohG/yJA+T6sLGsvCvDv/ex5n+g/F4H2PFx6nuXCww9CS7MxUn8Uj5xb0LW 9zTMjLmviTFbHP5SGOMGxM04RoxkX7sKyzhqZ7Y9S5T0OLPD25DtfUPNDQwMWfUOKF6J KGPQ== X-Gm-Message-State: AO0yUKW2l5XnH8GrFqvAuKE8TRU4TiOA8om5MldXFf1QUkbuZob7DeY0 jbIs5lOZ0zrsU/vdDWA7FiSK918McZPFwTaJfSY= X-Google-Smtp-Source: AK7set+HT5qK7Xgzrp9N/n/ZZuGDGakLl19HjVNACpZCHioAjW6qwDcVrgfP3w4b3cghfcJesCRpHg== X-Received: by 2002:a9d:841:0:b0:68b:cec3:7fe5 with SMTP id 59-20020a9d0841000000b0068bcec37fe5mr1995128oty.4.1675271088450; Wed, 01 Feb 2023 09:04:48 -0800 (PST) Received: from mandiga.. ([2804:1b3:a7c2:1887:d2ed:98c2:d2cc:bf06]) by smtp.gmail.com with ESMTPSA id b17-20020a056830311100b006863ccbf067sm8077090ots.74.2023.02.01.09.04.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 01 Feb 2023 09:04:47 -0800 (PST) To: libc-alpha@sourceware.org, Richard Henderson , Noah Goldstein , Jeff Law , Xi Ruoyao Subject: [PATCH v11 14/29] hppa: Add memcopy.h Date: Wed, 1 Feb 2023 14:03:51 -0300 Message-Id: <20230201170406.303978-15-adhemerval.zanella@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230201170406.303978-1-adhemerval.zanella@linaro.org> References: <20230201170406.303978-1-adhemerval.zanella@linaro.org> 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, 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: , X-Patchwork-Original-From: Adhemerval Zanella via Libc-alpha From: Adhemerval Zanella Netto Reply-To: Adhemerval Zanella Errors-To: libc-alpha-bounces+patchwork=sourceware.org@sourceware.org Sender: "Libc-alpha" From: Richard Henderson GCC's combine pass cannot merge (x >> c | y << (32 - c)) into a double-word shift unless (1) the subtract is in the same basic block and (2) the result of the subtract is used exactly once. Neither condition is true for any use of MERGE. By forcing the use of a double-word shift, we not only reduce contention on SAR, but also allow the setting of SAR to be hoisted outside of a loop. Checked on hppa-linux-gnu. --- sysdeps/hppa/memcopy.h | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 sysdeps/hppa/memcopy.h diff --git a/sysdeps/hppa/memcopy.h b/sysdeps/hppa/memcopy.h new file mode 100644 index 0000000000..0d4b4ac435 --- /dev/null +++ b/sysdeps/hppa/memcopy.h @@ -0,0 +1,42 @@ +/* Definitions for memory copy functions, PA-RISC version. + Copyright (C) 2023 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 + +/* Use a single double-word shift instead of two shifts and an ior. + If the uses of MERGE were close to the computation of shl/shr, + the compiler might have been able to create this itself. + But instead that computation is well separated. + + Using an inline function instead of a macro is the easiest way + to ensure that the types are correct. */ + +#undef MERGE + +static __always_inline op_t +MERGE (op_t w0, int shl, op_t w1, int shr) +{ + _Static_assert (OPSIZ == 4 || OPSIZ == 8, "Invalid OPSIZE"); + + op_t res; + if (OPSIZ == 4) + asm ("shrpw %1,%2,%%sar,%0" : "=r"(res) : "r"(w0), "r"(w1), "q"(shr)); + else if (OPSIZ == 8) + asm ("shrpd %1,%2,%%sar,%0" : "=r"(res) : "r"(w0), "r"(w1), "q"(shr)); + return res; +} From patchwork Wed Feb 1 17:03:52 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adhemerval Zanella Netto X-Patchwork-Id: 64090 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 EE6C43870C01 for ; Wed, 1 Feb 2023 17:05:21 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org EE6C43870C01 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1675271122; bh=jpleRAWHDQCuIaPJ7tBbsrZ7+X97U0E3s7oNtI78EUM=; h=To:Subject:Date:In-Reply-To:References:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=lgn9+MriUe4dTSI91/VxE5Urti0evZ7VYHBgMTb1Dc45gaqcrOHdH6vk8ldQWyxNS AR4iVSsR6bUW5pk3WtBJgo3CJ55JHJMDkfKoBs14k+ibnVZOX11luGvksr+O/x8Xeh p9hkdCIJSxnXdg6VC4uQfFLuvj8+UdaBqqRTzp7E= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-ot1-x330.google.com (mail-ot1-x330.google.com [IPv6:2607:f8b0:4864:20::330]) by sourceware.org (Postfix) with ESMTPS id 996513858436 for ; Wed, 1 Feb 2023 17:04:52 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 996513858436 Received: by mail-ot1-x330.google.com with SMTP id x26-20020a056830115a00b0068bbc0ee3eeso3897271otq.0 for ; Wed, 01 Feb 2023 09:04:52 -0800 (PST) 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:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=jpleRAWHDQCuIaPJ7tBbsrZ7+X97U0E3s7oNtI78EUM=; b=NHYd5qovkSw7wLl6l0ZY4txq2EHj3xCqZfHE5TT8B8RGaHKYtZHHvM61dw0QSTgulH W2Noad3r0OB8JcAQJBr0DRjpbTgg+Yw1piqEJ1AvWiKNGwP72W83/yIy2bvHOHEZqZ4C xw2Ez+T7YExQjxiWx8MMiwmQClCtiukuzIIJuVAD/lRBMkXTZxVFAFNABuFbwP0Z3BwA iWIh2mbGvKu3y1Gpg7ji1A8SOHk4Y8IOLOCrJYAQYAllSeyHFZjcwMYFGit5lp31Uq/8 Mn4gqOrYg3S/hStbBROHk+H1+ITE8W19U+boMjprurjH9n5vMh/ruZzQ384/Pn6OrlM3 j2Aw== X-Gm-Message-State: AO0yUKWdA623QJrJI4w1dBG+yZZ/wfXuX83JS/OKWRCuzL5zNCseG48r bBbTnh7Ln6PfphMn/IlYSRwXGvGGta1jV9bV2mM= X-Google-Smtp-Source: AK7set9QQCI8s6tMHkIWYZYRiTlE6DflLnY2wavIF4aiM/LSe9B9XILL65wLLoZ7FMBplfQfaGJA0Q== X-Received: by 2002:a9d:3e16:0:b0:688:4892:e1d3 with SMTP id a22-20020a9d3e16000000b006884892e1d3mr1647204otd.8.1675271090968; Wed, 01 Feb 2023 09:04:50 -0800 (PST) Received: from mandiga.. ([2804:1b3:a7c2:1887:d2ed:98c2:d2cc:bf06]) by smtp.gmail.com with ESMTPSA id b17-20020a056830311100b006863ccbf067sm8077090ots.74.2023.02.01.09.04.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 01 Feb 2023 09:04:50 -0800 (PST) To: libc-alpha@sourceware.org, Richard Henderson , Noah Goldstein , Jeff Law , Xi Ruoyao Subject: [PATCH v11 15/29] hppa: Add string-fza.h, string-fzc.h, and string-fzi.h Date: Wed, 1 Feb 2023 14:03:52 -0300 Message-Id: <20230201170406.303978-16-adhemerval.zanella@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230201170406.303978-1-adhemerval.zanella@linaro.org> References: <20230201170406.303978-1-adhemerval.zanella@linaro.org> 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, 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: , X-Patchwork-Original-From: Adhemerval Zanella via Libc-alpha From: Adhemerval Zanella Netto Reply-To: Adhemerval Zanella Errors-To: libc-alpha-bounces+patchwork=sourceware.org@sourceware.org Sender: "Libc-alpha" From: Richard Henderson Use UXOR,SBZ to test for a zero byte within a word. While we can get semi-decent code out of asm-goto, we would do slightly better with a compiler builtin. For index_zero et al, sequential testing of bytes is less expensive than any tricks that involve a count-leading-zeros insn that we don't have. Checked on hppa-linux-gnu. --- sysdeps/hppa/string-fzb.h | 63 +++++++++++++++++++ sysdeps/hppa/string-fzc.h | 124 ++++++++++++++++++++++++++++++++++++++ sysdeps/hppa/string-fzi.h | 63 +++++++++++++++++++ 3 files changed, 250 insertions(+) create mode 100644 sysdeps/hppa/string-fzb.h create mode 100644 sysdeps/hppa/string-fzc.h create mode 100644 sysdeps/hppa/string-fzi.h diff --git a/sysdeps/hppa/string-fzb.h b/sysdeps/hppa/string-fzb.h new file mode 100644 index 0000000000..d6b234a271 --- /dev/null +++ b/sysdeps/hppa/string-fzb.h @@ -0,0 +1,63 @@ +/* Zero byte detection, boolean. HPPA version. + Copyright (C) 2023 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 + . */ + +#ifndef _STRING_FZB_H +#define _STRING_FZB_H 1 + +#include +#include + +_Static_assert (sizeof (op_t) == 4, "64-bit not supported"); + +/* Determine if any byte within X is zero. This is a pure boolean test. */ +static __always_inline _Bool +has_zero (op_t x) +{ + /* It's more useful to expose a control transfer to the compiler + than to expose a proper boolean result. */ + asm goto ("uxor,sbz %%r0,%0,%%r0\n\t" + "b,n %l1" : : "r"(x) : : nbz); + return 1; + nbz: + return 0; +} + +/* Likewise, but for byte equality between X1 and X2. */ +static __always_inline _Bool +has_eq (op_t x1, op_t x2) +{ + asm goto ("uxor,sbz %0,%1,%%r0\n\t" + "b,n %l2" : : "r"(x1), "r"(x2) : : nbz); + return 1; + nbz: + return 0; +} + +/* Likewise, but for zeros in X1 and equal bytes between X1 and X2. */ +static __always_inline _Bool +has_zero_eq (op_t x1, op_t x2) +{ + asm goto ("uxor,sbz %%r0,%0,%%r0\n\t" + "uxor,nbz %0,%1,%%r0\n\t" + "b,n %l2" : : "r"(x1), "r"(x2) : : sbz); + return 0; + sbz: + return 1; +} + +#endif /* _STRING_FZB_H */ diff --git a/sysdeps/hppa/string-fzc.h b/sysdeps/hppa/string-fzc.h new file mode 100644 index 0000000000..8ff3416b41 --- /dev/null +++ b/sysdeps/hppa/string-fzc.h @@ -0,0 +1,124 @@ +/* string-fzc.h -- zero byte detection with indexes. HPPA 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 + . */ + +#ifndef _STRING_FZC_H +#define _STRING_FZC_H 1 + +#include + +_Static_assert (sizeof (op_t) == 4, "64-bit not supported"); + +/* Given a word X that is known to contain a zero byte, return the + index of the first such within the long in memory order. */ +static __always_inline unsigned int +index_first_zero (op_t x) +{ + unsigned int ret; + + /* Since we have no clz insn, direct tests of the bytes is faster + than loading up the constants to do the masking. */ + asm ("extrw,u,<> %1,23,8,%%r0\n\t" + "ldi 2,%0\n\t" + "extrw,u,<> %1,15,8,%%r0\n\t" + "ldi 1,%0\n\t" + "extrw,u,<> %1,7,8,%%r0\n\t" + "ldi 0,%0" + : "=r"(ret) : "r"(x), "0"(3)); + + return ret; +} + +/* Similarly, but perform the search for byte equality between X1 and X2. */ +static __always_inline unsigned int +index_first_eq (op_t x1, op_t x2) +{ + return index_first_zero (x1 ^ x2); +} + +/* Similarly, but perform the search for zero within X1 or + equality between X1 and X2. */ +static __always_inline unsigned int +index_first_zero_eq (op_t x1, op_t x2) +{ + unsigned int ret; + + /* Since we have no clz insn, direct tests of the bytes is faster + than loading up the constants to do the masking. */ + asm ("extrw,u,= %1,23,8,%%r0\n\t" + "extrw,u,<> %2,23,8,%%r0\n\t" + "ldi 2,%0\n\t" + "extrw,u,= %1,15,8,%%r0\n\t" + "extrw,u,<> %2,15,8,%%r0\n\t" + "ldi 1,%0\n\t" + "extrw,u,= %1,7,8,%%r0\n\t" + "extrw,u,<> %2,7,8,%%r0\n\t" + "ldi 0,%0" + : "=r"(ret) : "r"(x1), "r"(x1 ^ x2), "0"(3)); + + return ret; +} + +/* Similarly, but perform the search for zero within X1 or + inequality between X1 and X2. */ +static __always_inline unsigned int +index_first_zero_ne (op_t x1, op_t x2) +{ + unsigned int ret; + + /* Since we have no clz insn, direct tests of the bytes is faster + than loading up the constants to do the masking. */ + asm ("extrw,u,<> %2,23,8,%%r0\n\t" + "extrw,u,<> %1,23,8,%%r0\n\t" + "ldi 2,%0\n\t" + "extrw,u,<> %2,15,8,%%r0\n\t" + "extrw,u,<> %1,15,8,%%r0\n\t" + "ldi 1,%0\n\t" + "extrw,u,<> %2,7,8,%%r0\n\t" + "extrw,u,<> %1,7,8,%%r0\n\t" + "ldi 0,%0" + : "=r"(ret) : "r"(x1), "r"(x1 ^ x2), "0"(3)); + + return ret; +} + +/* Similarly, but search for the last zero within X. */ +static __always_inline unsigned int +index_last_zero (op_t x) +{ + unsigned int ret; + + /* Since we have no ctz insn, direct tests of the bytes is faster + than loading up the constants to do the masking. */ + asm ("extrw,u,<> %1,15,8,%%r0\n\t" + "ldi 1,%0\n\t" + "extrw,u,<> %1,23,8,%%r0\n\t" + "ldi 2,%0\n\t" + "extrw,u,<> %1,31,8,%%r0\n\t" + "ldi 3,%0" + : "=r"(ret) : "r"(x), "0"(0)); + + return ret; +} + +static __always_inline unsigned int +index_last_eq (op_t x1, op_t x2) +{ + return index_last_zero (x1 ^ x2); +} + +#endif /* _STRING_FZC_H */ diff --git a/sysdeps/hppa/string-fzi.h b/sysdeps/hppa/string-fzi.h new file mode 100644 index 0000000000..b560fa1a89 --- /dev/null +++ b/sysdeps/hppa/string-fzi.h @@ -0,0 +1,63 @@ +/* string-fzi.h -- zero byte indexes. HPPA 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 + . */ + +#ifndef _STRING_FZI_H +#define _STRING_FZI_H 1 + +#include +#include + +_Static_assert (sizeof (op_t) == 4, "64-bit not supported"); + +static __always_inline unsigned int +index_first (find_t c) +{ + unsigned int ret; + + /* Since we have no clz insn, direct tests of the bytes is faster + than loading up the constants to do the masking. */ + asm ("extrw,u,= %1,23,8,%%r0\n\t" + "ldi 2,%0\n\t" + "extrw,u,= %1,15,8,%%r0\n\t" + "ldi 1,%0\n\t" + "extrw,u,= %1,7,8,%%r0\n\t" + "ldi 0,%0" + : "=r"(ret) : "r"(c), "0"(3)); + + return ret; +} + +static __always_inline unsigned int +index_last (find_t c) +{ + unsigned int ret; + + /* Since we have no ctz insn, direct tests of the bytes is faster + than loading up the constants to do the masking. */ + asm ("extrw,u,= %1,15,8,%%r0\n\t" + "ldi 1,%0\n\t" + "extrw,u,= %1,23,8,%%r0\n\t" + "ldi 2,%0\n\t" + "extrw,u,= %1,31,8,%%r0\n\t" + "ldi 3,%0" + : "=r"(ret) : "r"(c), "0"(0)); + + return ret; +} + +#endif /* _STRING_FZI_H */ From patchwork Wed Feb 1 17:03:53 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adhemerval Zanella Netto X-Patchwork-Id: 64105 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 7920A3895FC3 for ; Wed, 1 Feb 2023 17:07:56 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 7920A3895FC3 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1675271276; bh=jVr6SqXl9FQsWAJ2toPTqtV+Gz4VS69QgbKHY+kPfMQ=; h=To:Subject:Date:In-Reply-To:References:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=G8Pi6+Kk6sDFAcDhndf3yrzUq/C35xFp4qKN7fhsJH25V7jez2w7kHVzOWBA071eI dT4RL7gUP1Iv07SSPKSvJ1ciFfU+DiuI6PCuQp23DyC0TE//H7Uhw39TRfAf7EclAO Us54hxd0vv/jaXDCWTg0UWAHHGrKfMy/Pod5jBOw= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-oi1-x234.google.com (mail-oi1-x234.google.com [IPv6:2607:f8b0:4864:20::234]) by sourceware.org (Postfix) with ESMTPS id 0EC5D385C301 for ; Wed, 1 Feb 2023 17:04:55 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 0EC5D385C301 Received: by mail-oi1-x234.google.com with SMTP id s17so5322072ois.10 for ; Wed, 01 Feb 2023 09:04:55 -0800 (PST) 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:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=jVr6SqXl9FQsWAJ2toPTqtV+Gz4VS69QgbKHY+kPfMQ=; b=YCWTgTi1eOVPsI+EFVS4Neyk93Lhajx6iNY/pkD4t+vmZoOCgc/WEPfm7yDpijLTwF CyAZZkVpFGP9ON8Q+R7w7pmA8Medazyr56GmCF2SNP34HieFx/WFOQJiOD2G+4j7kStP dw0Ci04Xu+ZriOOEYrJj0S9HiriULRUHZbjEqDlJr4idoRfhv0QGug95T12lh8OszOU8 Ataw0O85Uby51K1GFohSmhdlOAz6EWkGT/fOSswNNnKh0ReOGjx6SKghvEM0YMaMK6y6 wA7Mfs4/xGwtY+fgvB0oZmotp7etH8qDUUpMLAWHnMZUv9dQeBro1IB80ClysCvs0J87 lnfA== X-Gm-Message-State: AO0yUKWBQt6obkFxVBAkGfl8HMKqWswO6NRUkt+9BUIuaV8G7/Wm6jkj mLf/GnfffqC8KOTMsOv6ISu97XZyJJ5LQ6XBEBI= X-Google-Smtp-Source: AK7set8NikyEiEV05yYMXqa/1ARseU+YUmfYl7SrUR8QdWM8TM0XKeEQzVZHsW7Zyv4mMG2ul1+6TQ== X-Received: by 2002:a05:6808:bc5:b0:378:528:d83b with SMTP id o5-20020a0568080bc500b003780528d83bmr1478571oik.55.1675271093473; Wed, 01 Feb 2023 09:04:53 -0800 (PST) Received: from mandiga.. ([2804:1b3:a7c2:1887:d2ed:98c2:d2cc:bf06]) by smtp.gmail.com with ESMTPSA id b17-20020a056830311100b006863ccbf067sm8077090ots.74.2023.02.01.09.04.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 01 Feb 2023 09:04:52 -0800 (PST) To: libc-alpha@sourceware.org, Richard Henderson , Noah Goldstein , Jeff Law , Xi Ruoyao Subject: [PATCH v11 16/29] alpha: Add string-fza, string-fzb.h, string-fzi.h, and string-shift.h Date: Wed, 1 Feb 2023 14:03:53 -0300 Message-Id: <20230201170406.303978-17-adhemerval.zanella@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230201170406.303978-1-adhemerval.zanella@linaro.org> References: <20230201170406.303978-1-adhemerval.zanella@linaro.org> 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, 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: , X-Patchwork-Original-From: Adhemerval Zanella via Libc-alpha From: Adhemerval Zanella Netto Reply-To: Adhemerval Zanella Errors-To: libc-alpha-bounces+patchwork=sourceware.org@sourceware.org Sender: "Libc-alpha" From: Richard Henderson While alpha has the more important string functions in assembly, there are still a few for find the generic routines are used. Use the CMPBGE insn, via the builtin, for testing of zeros. Use a simplified expansion of __builtin_ctz when the insn isn't available. Checked on alpha-linux-gnu. Co-authored-by: Adhemerval Zanella --- sysdeps/alpha/string-fza.h | 61 +++++++++++++++++++++++++++++++++++ sysdeps/alpha/string-fzb.h | 52 ++++++++++++++++++++++++++++++ sysdeps/alpha/string-fzi.h | 62 ++++++++++++++++++++++++++++++++++++ sysdeps/alpha/string-shift.h | 44 +++++++++++++++++++++++++ 4 files changed, 219 insertions(+) create mode 100644 sysdeps/alpha/string-fza.h create mode 100644 sysdeps/alpha/string-fzb.h create mode 100644 sysdeps/alpha/string-fzi.h create mode 100644 sysdeps/alpha/string-shift.h diff --git a/sysdeps/alpha/string-fza.h b/sysdeps/alpha/string-fza.h new file mode 100644 index 0000000000..b4a7080c44 --- /dev/null +++ b/sysdeps/alpha/string-fza.h @@ -0,0 +1,61 @@ +/* Basic zero byte detection. Generic C version. + Copyright (C) 2023 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 + . */ + +#ifndef _STRING_FZA_H +#define _STRING_FZA_H 1 + +#include +#include + +/* The CMPBGE instruction creates a bit mask rather than a byte mask. + However, if we narrow find_t to either 'int' or 'uint8_t', we get + unnecessary truncation instructions from the 'unsigned long' type + returned by __builtin_alpha_cmpbge. */ +typedef op_t find_t; + +static __always_inline find_t +find_zero_all (op_t x) +{ + return __builtin_alpha_cmpbge (0, x); +} + +static __always_inline find_t +find_eq_all (op_t x1, op_t x2) +{ + return find_zero_all (x1 ^ x2); +} + +static __always_inline find_t +find_zero_eq_all (op_t x1, op_t x2) +{ + return find_zero_all (x1) | find_zero_all (x1 ^ x2); +} + +static __always_inline find_t +find_zero_ne_all (op_t x1, op_t x2) +{ + return find_zero_all (x1) | (find_zero_all (x1 ^ x2) ^ 0xff); +} + +/* Define the "inexact" versions in terms of the exact versions. */ +#define find_zero_low find_zero_all +#define find_eq_low find_eq_all +#define find_zero_eq_low find_zero_eq_all +#define find_zero_ne_low find_zero_ne_all + +#endif /* _STRING_FZA_H */ diff --git a/sysdeps/alpha/string-fzb.h b/sysdeps/alpha/string-fzb.h new file mode 100644 index 0000000000..e3934ba413 --- /dev/null +++ b/sysdeps/alpha/string-fzb.h @@ -0,0 +1,52 @@ +/* Zero byte detection; boolean. Alpha version. + Copyright (C) 2023 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 + . */ + +#ifndef _STRING_FZB_H +#define _STRING_FZB_H 1 + +#include +#include + +/* Note that since CMPBGE creates a bit mask rather than a byte mask, + we cannot simply provide a target-specific string-fza.h. */ + +/* Determine if any byte within X is zero. This is a pure boolean test. */ + +static __always_inline _Bool +has_zero (op_t x) +{ + return __builtin_alpha_cmpbge (0, x) != 0; +} + +/* Likewise, but for byte equality between X1 and X2. */ + +static __always_inline _Bool +has_eq (op_t x1, op_t x2) +{ + return has_zero (x1 ^ x2); +} + +/* Likewise, but for zeros in X1 and equal bytes between X1 and X2. */ + +static __always_inline _Bool +has_zero_eq (op_t x1, op_t x2) +{ + return has_zero (x1) | has_eq (x1, x2); +} + +#endif /* _STRING_FZB_H */ diff --git a/sysdeps/alpha/string-fzi.h b/sysdeps/alpha/string-fzi.h new file mode 100644 index 0000000000..5129b892e7 --- /dev/null +++ b/sysdeps/alpha/string-fzi.h @@ -0,0 +1,62 @@ +/* string-fzi.h -- zero byte detection; indices. Alpha 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 + . */ + +#ifndef _STRING_FZI_H +#define _STRING_FZI_H + +#include +#include +#include + +/* Note that since CMPBGE creates a bit mask rather than a byte mask, + we cannot simply provide a target-specific string-fza.h. */ + +/* A subroutine for the index_zero functions. Given a bitmask C, + return the index of the first bit set in memory order. */ +static __always_inline unsigned int +index_first (find_t c) +{ +#ifdef __alpha_cix__ + return __builtin_ctzl (c); +#else + c = c & -c; + return (c & 0xf0 ? 4 : 0) + (c & 0xcc ? 2 : 0) + (c & 0xaa ? 1 : 0); +#endif +} + +/* Similarly, but return the (memory order) index of the last bit + that is non-zero. Note that only the least 8 bits may be nonzero. */ + +static __always_inline unsigned int +index_last (find_t x) +{ +#ifdef __alpha_cix__ + return __builtin_clzl (x) ^ 63; +#else + unsigned r = 0; + if (x & 0xf0) + r += 4; + if (x & (0xc << r)) + r += 2; + if (x & (0x2 << r)) + r += 1; + return r; +#endif +} + +#endif /* _STRING_FZI_H */ diff --git a/sysdeps/alpha/string-shift.h b/sysdeps/alpha/string-shift.h new file mode 100644 index 0000000000..4e2cb2fea1 --- /dev/null +++ b/sysdeps/alpha/string-shift.h @@ -0,0 +1,44 @@ +/* Shift unaligned word read. Alpha version. + Copyright (C) 2023 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 + . */ + +#ifndef _STRING_SHIFT_H +#define _STRING_SHIFT_H 1 + +#include +#include +#include + +/* Return the mask WORD shifted based on S_INT address value, to ignore + values not presented in the aligned word read. */ +static __always_inline find_t +shift_find (find_t word, uintptr_t s) +{ + return word >> (s % sizeof (op_t)); +} + +/* Mask off the bits defined the the S alignment value. */ +static __always_inline find_t +shift_find_last (find_t word, uintptr_t s) +{ + s = s % sizeof (op_t); + if (s == 0) + return word; + return word & ~((op_t)-1 << s); +} + +#endif /* _STRING_SHIFT_H */ From patchwork Wed Feb 1 17:03:54 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adhemerval Zanella Netto X-Patchwork-Id: 64113 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 86EBC3858020 for ; Wed, 1 Feb 2023 17:10:27 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 86EBC3858020 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1675271427; bh=eaPuAUW6u9EzarB15eu0qKq3XLrPgGatZ3LrJa3nfQo=; h=To:Subject:Date:In-Reply-To:References:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=e4WeGZ54Dzi2T5H3YIvGJvxdWwenNVpT1XMf4h2fnpWhonDVnFEpwsRDlWI2zIHuC qRvThceoVcf7PpjlxFlCfxhIPqFiZq7PZ6xlkBN/1r8rxmEAR1ws01YE4IkWKafGoE gYwh/lMb5sTHCJFOdmK6x3OZeWvL4zwlo1F0y07Q= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-oa1-x31.google.com (mail-oa1-x31.google.com [IPv6:2001:4860:4864:20::31]) by sourceware.org (Postfix) with ESMTPS id 344333857C4F for ; Wed, 1 Feb 2023 17:04:57 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 344333857C4F Received: by mail-oa1-x31.google.com with SMTP id 586e51a60fabf-16346330067so24358642fac.3 for ; Wed, 01 Feb 2023 09:04:57 -0800 (PST) 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:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=eaPuAUW6u9EzarB15eu0qKq3XLrPgGatZ3LrJa3nfQo=; b=VAq42Ro41ckcs5vJQdzvYInJHlecigy873OuNpcKIFImwNbEIl8+T1Jv9BglqjZXju Dc5nWAVSK9RNGmdp3VIz5HsAJPGo5MMEJZq3Y/5WAEitJq8OoiVD872tkjr2v0THMzCA vZ1thSlWGlm8bL/wan7cjwg//CzQa8BcKTab4NasFr4NZAxU1V30lUWfg/POamz6grlm pPZNewtGbS425usObUSk1PFoqjAmV6623lxBH0STkH9RBuKPaH9zctBtWUoJTKuXclXQ qejod7Px7YGoAyAz/biGiS/UKCzRbVtcaKhOMtYsczIt9dzhHrCkExWKkpwvm/nhQzMc XtPg== X-Gm-Message-State: AO0yUKWTp83fiTzsfdOn17UGJp6jZe9cEYZb8KqL/oXanEcoo9hM9E8r 2kRri7xS0DUjSeXrFVXbtSZM9OaZzHp06BqFdB8= X-Google-Smtp-Source: AK7set/nSg6UqC4fs4FsHfknu2aUp8JGgO4/YjBuBz+F9qF6jlpGklbK4zwU1iBOoCPkTVoFdAZKiA== X-Received: by 2002:a05:6870:c69a:b0:15b:9ee2:4c36 with SMTP id cv26-20020a056870c69a00b0015b9ee24c36mr1788517oab.35.1675271095988; Wed, 01 Feb 2023 09:04:55 -0800 (PST) Received: from mandiga.. ([2804:1b3:a7c2:1887:d2ed:98c2:d2cc:bf06]) by smtp.gmail.com with ESMTPSA id b17-20020a056830311100b006863ccbf067sm8077090ots.74.2023.02.01.09.04.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 01 Feb 2023 09:04:55 -0800 (PST) To: libc-alpha@sourceware.org, Richard Henderson , Noah Goldstein , Jeff Law , Xi Ruoyao Subject: [PATCH v11 17/29] arm: Add string-fza.h Date: Wed, 1 Feb 2023 14:03:54 -0300 Message-Id: <20230201170406.303978-18-adhemerval.zanella@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230201170406.303978-1-adhemerval.zanella@linaro.org> References: <20230201170406.303978-1-adhemerval.zanella@linaro.org> 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, 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: , X-Patchwork-Original-From: Adhemerval Zanella via Libc-alpha From: Adhemerval Zanella Netto Reply-To: Adhemerval Zanella Errors-To: libc-alpha-bounces+patchwork=sourceware.org@sourceware.org Sender: "Libc-alpha" From: Richard Henderson While arm has the more important string functions in assembly, there are still a few generic routines used. Use the UQSUB8 insn for testing of zeros. Checked on armv7-linux-gnueabihf --- sysdeps/arm/armv6t2/string-fza.h | 68 ++++++++++++++++++++++++++++++++ 1 file changed, 68 insertions(+) create mode 100644 sysdeps/arm/armv6t2/string-fza.h diff --git a/sysdeps/arm/armv6t2/string-fza.h b/sysdeps/arm/armv6t2/string-fza.h new file mode 100644 index 0000000000..50afaba038 --- /dev/null +++ b/sysdeps/arm/armv6t2/string-fza.h @@ -0,0 +1,68 @@ +/* Zero byte detection; basics. ARM version. + Copyright (C) 2023 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 + . */ + +#ifndef _STRING_FZA_H +#define _STRING_FZA_H 1 + +#include +#include + +/* The functions return a byte mask. */ +typedef op_t find_t; + +/* This function returns at least one bit set within every byte + of X that is zero. */ +static __always_inline find_t +find_zero_all (op_t x) +{ + /* Use unsigned saturated subtraction from 1 in each byte. + That leaves 1 for every byte that was zero. */ + op_t ones = repeat_bytes (0x01); + return __builtin_arm_uqsub8 (ones, x); +} + +/* Identify bytes that are equal between X1 and X2. */ +static __always_inline find_t +find_eq_all (op_t x1, op_t x2) +{ + return find_zero_all (x1 ^ x2); +} + +/* Identify zero bytes in X1 or equality between X1 and X2. */ +static __always_inline find_t +find_zero_eq_all (op_t x1, op_t x2) +{ + return find_zero_all (x1) | find_zero_all (x1 ^ x2); +} + +/* Identify zero bytes in X1 or inequality between X1 and X2. */ +static __always_inline find_t +find_zero_ne_all (op_t x1, op_t x2) +{ + /* Make use of the fact that we'll already have ONES in a register. */ + op_t ones = repeat_bytes (0x01); + return find_zero_all (x1) | (find_zero_all (x1 ^ x2) ^ ones); +} + +/* Define the "inexact" versions in terms of the exact versions. */ +#define find_zero_low find_zero_all +#define find_eq_low find_eq_all +#define find_zero_eq_low find_zero_eq_all +#define find_zero_ne_low find_zero_ne_all + +#endif /* _STRING_FZA_H */ From patchwork Wed Feb 1 17:03:55 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adhemerval Zanella Netto X-Patchwork-Id: 64114 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 EAD9438AA247 for ; Wed, 1 Feb 2023 17:11:08 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org EAD9438AA247 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1675271469; bh=/ldL5Mg0I3ZuGb3h/TCF9ldgWkiTF4nlu2BkAtFavko=; h=To:Subject:Date:In-Reply-To:References:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=F/GbokvFGJGlRFrTFLkzZidLws5QpfdDvzr1z0WYhuEvwu4q20EungyvNmG29h2Po zvQgnR3LojXoQ00cHAf2NacJX//+apU0HVOSkpNGxrRhuia9SW5i7BtBSVStpyY0FA vNt49e1z3UT/+C0B4V/BG1zrDJvioOgdmot2jRNQ= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-oi1-x234.google.com (mail-oi1-x234.google.com [IPv6:2607:f8b0:4864:20::234]) by sourceware.org (Postfix) with ESMTPS id 8543E3858C83 for ; Wed, 1 Feb 2023 17:04:59 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 8543E3858C83 Received: by mail-oi1-x234.google.com with SMTP id p133so16253552oig.8 for ; Wed, 01 Feb 2023 09:04:59 -0800 (PST) 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:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=/ldL5Mg0I3ZuGb3h/TCF9ldgWkiTF4nlu2BkAtFavko=; b=xMUGvrS6IL7byCwmyL8jySd12qgs8Vh83ob7y7QhPAUGdMuA4IEe6HcI+0JCFfish4 4rd9cQE+uK2fcHScUbTnxLZusp0q2HbAX0gYrjOEFnSL2DOJIqGDl6mHRTzqfxWHGrbh FCkuUeYbI4OEhUT7qO+rIl+d5ez/a+pI0RVj8QQGYjUaKtOMT2TbZ9H7UQI5XyBnWPTG wzFv9dPgT+56cnBGWCnMAjnTx8MKTh0a0O3ZFNmnUot/iJdDlOypgXPUVYU7h3ys/1fO 8aI89osPNwQFS+DZK+Qs2pzE4dhMlOTxg5wZpiHdGVYHA7jf2xBilL5bIIhqvGamZ5DV lBhA== X-Gm-Message-State: AO0yUKXkOF/mv+v5q46VbbiWO3cvLfTQaQ3xE0YKX/j46AT7MOVLQORa s7jTNQfxJvnruMCkGAtnwk8agNTk/zLENRERSro= X-Google-Smtp-Source: AK7set89OZYVsgcLcL5KYBeB8iNMcSqqSao31RIawJlMm2E256eBihVh6wemqjCgbVv6PP3i1ot9JA== X-Received: by 2002:a05:6808:481:b0:378:6ebe:a98b with SMTP id z1-20020a056808048100b003786ebea98bmr1350662oid.37.1675271098277; Wed, 01 Feb 2023 09:04:58 -0800 (PST) Received: from mandiga.. ([2804:1b3:a7c2:1887:d2ed:98c2:d2cc:bf06]) by smtp.gmail.com with ESMTPSA id b17-20020a056830311100b006863ccbf067sm8077090ots.74.2023.02.01.09.04.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 01 Feb 2023 09:04:57 -0800 (PST) To: libc-alpha@sourceware.org, Richard Henderson , Noah Goldstein , Jeff Law , Xi Ruoyao Subject: [PATCH v11 18/29] powerpc: Add string-fza.h Date: Wed, 1 Feb 2023 14:03:55 -0300 Message-Id: <20230201170406.303978-19-adhemerval.zanella@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230201170406.303978-1-adhemerval.zanella@linaro.org> References: <20230201170406.303978-1-adhemerval.zanella@linaro.org> 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, 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: , X-Patchwork-Original-From: Adhemerval Zanella via Libc-alpha From: Adhemerval Zanella Netto Reply-To: Adhemerval Zanella Errors-To: libc-alpha-bounces+patchwork=sourceware.org@sourceware.org Sender: "Libc-alpha" From: Richard Henderson While ppc has the more important string functions in assembly, there are still a few generic routines used. Use the Power 6 CMPB insn for testing of zeros. Checked on powerpc64le-linux-gnu. --- sysdeps/powerpc/string-fza.h | 72 ++++++++++++++++++++++++++++++++++++ 1 file changed, 72 insertions(+) create mode 100644 sysdeps/powerpc/string-fza.h diff --git a/sysdeps/powerpc/string-fza.h b/sysdeps/powerpc/string-fza.h new file mode 100644 index 0000000000..5dec740041 --- /dev/null +++ b/sysdeps/powerpc/string-fza.h @@ -0,0 +1,72 @@ +/* Zero byte detection; basics. PowerPC version. + Copyright (C) 2023 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 + . */ + +#ifndef _POWERPC_STRING_FZA_H +#define _POWERPC_STRING_FZA_H 1 + +/* PowerISA 2.05 (POWER6) provides cmpb instruction. */ +#ifdef _ARCH_PWR6 +# include +# include + +/* The functions return a byte mask. */ +typedef op_t find_t; + +/* This function returns 0xff for each byte that is + equal between X1 and X2. */ + +static __always_inline find_t +find_eq_all (op_t x1, op_t x2) +{ + return __builtin_cmpb (x1, x2); +} + +/* This function returns 0xff for each byte that is zero in X. */ + +static __always_inline find_t +find_zero_all (op_t x) +{ + return find_eq_all (x, 0); +} + +/* Identify zero bytes in X1 or equality between X1 and X2. */ + +static __always_inline find_t +find_zero_eq_all (op_t x1, op_t x2) +{ + return find_zero_all (x1) | find_eq_all (x1, x2); +} + +/* Identify zero bytes in X1 or inequality between X1 and X2. */ + +static __always_inline find_t +find_zero_ne_all (op_t x1, op_t x2) +{ + return find_zero_all (x1) | ~find_eq_all (x1, x2); +} + +/* Define the "inexact" versions in terms of the exact versions. */ +# define find_zero_low find_zero_all +# define find_eq_low find_eq_all +# define find_zero_eq_low find_zero_eq_all +# define find_zero_ne_low find_zero_ne_all +#else +# include +#endif /* _ARCH_PWR6 */ + +#endif /* _POWERPC_STRING_FZA_H */ From patchwork Wed Feb 1 17:03:56 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adhemerval Zanella Netto X-Patchwork-Id: 64100 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 5EB4E38A90AC for ; Wed, 1 Feb 2023 17:07:02 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 5EB4E38A90AC DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1675271222; bh=rhAaYi6DtXp7uLXidJGinRFumCd11mLY/aet6ITY9Xc=; h=To:Subject:Date:In-Reply-To:References:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=lJmuUyOW/AtGRhQlWmK0q3VxmKDbfWn++u3Td8wfmUDx9hEbscTze/wAP1xsfFyOv Dlh6clk6AJm6+BF0xEDaCjiQhvwXiU6dMB4e41QA2kx+wz9dUtVCU55zTNoOYUq9z3 0rFvvXilIho7rWWedm90aTns7whDjeAxkr4UQAnU= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-oi1-x22e.google.com (mail-oi1-x22e.google.com [IPv6:2607:f8b0:4864:20::22e]) by sourceware.org (Postfix) with ESMTPS id 5C640385B501 for ; Wed, 1 Feb 2023 17:05:02 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 5C640385B501 Received: by mail-oi1-x22e.google.com with SMTP id bj22so7181921oib.11 for ; Wed, 01 Feb 2023 09:05:02 -0800 (PST) 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:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=rhAaYi6DtXp7uLXidJGinRFumCd11mLY/aet6ITY9Xc=; b=1sORgA1zWSircvGlC7eGXTndWS5a4wUBoahK94ZB4//0L1Ala4qDVkkpnzRorAKrGf FdsD3mB5tzqMUKHPyBl/nmiSr3DR4/l3tFN4fnbvYdXYQf/IfqclL6hIZ9/Fr7hdemKg Roz0goDO4f93Z9h/ES3H/VuCWZ0+ueAX88pA3wIWhBB/q5E4A3nZhjX3dUeE63WMSTYJ ci+Ogw7bnvlykWBUNZTK07Z4CvKxCoYvpIQZeQjKMi8+Sh7JnzON8iiDkUxsgcydyq22 krayXmxUcf7Mi6br4/phgPuc1OYvcCPOI3tRAj0abvPZYRongo1QtXX8cQRUwr2FDJBa wkYg== X-Gm-Message-State: AO0yUKVeABnQuZ51kKX0K0cMfpIXHeh6A5BrQvX4JPUwDbhzewg/wjeF svWQ+sYiTQPUvI0BXODf4rya0jRHZ+UZg7jpx5I= X-Google-Smtp-Source: AK7set/xYhrnnVil0gybpMAD++nlAe1aP7mUbVZ6AkuhxKSFRz8HGhahiryqZNSB+zUsN25cN34lHQ== X-Received: by 2002:a05:6808:190f:b0:360:e80e:26a9 with SMTP id bf15-20020a056808190f00b00360e80e26a9mr1843846oib.12.1675271100994; Wed, 01 Feb 2023 09:05:00 -0800 (PST) Received: from mandiga.. ([2804:1b3:a7c2:1887:d2ed:98c2:d2cc:bf06]) by smtp.gmail.com with ESMTPSA id b17-20020a056830311100b006863ccbf067sm8077090ots.74.2023.02.01.09.04.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 01 Feb 2023 09:05:00 -0800 (PST) To: libc-alpha@sourceware.org, Richard Henderson , Noah Goldstein , Jeff Law , Xi Ruoyao Subject: [PATCH v11 19/29] sh: Add string-fzb.h Date: Wed, 1 Feb 2023 14:03:56 -0300 Message-Id: <20230201170406.303978-20-adhemerval.zanella@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230201170406.303978-1-adhemerval.zanella@linaro.org> References: <20230201170406.303978-1-adhemerval.zanella@linaro.org> 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, 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: , X-Patchwork-Original-From: Adhemerval Zanella via Libc-alpha From: Adhemerval Zanella Netto Reply-To: Adhemerval Zanella Errors-To: libc-alpha-bounces+patchwork=sourceware.org@sourceware.org Sender: "Libc-alpha" Use the SH cmp/str on has_{zero,eq,zero_eq}. Checked on sh4-linux-gnu. --- sysdeps/sh/string-fzb.h | 55 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 sysdeps/sh/string-fzb.h diff --git a/sysdeps/sh/string-fzb.h b/sysdeps/sh/string-fzb.h new file mode 100644 index 0000000000..c8dd176362 --- /dev/null +++ b/sysdeps/sh/string-fzb.h @@ -0,0 +1,55 @@ +/* Zero byte detection; boolean. SH4 version. + Copyright (C) 2023 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 + . */ + +#ifndef STRING_FZB_H +#define STRING_FZB_H 1 + +#include +#include + +/* Determine if any bytes within X1 and X2 are equal. */ +static __always_inline _Bool +has_eq (op_t x1, op_t x2) +{ + int ret; + + /* TODO: A compiler builtin for cmp/str would be much better. It is + difficult to use asm goto here, because the range of bt/bf are + quite small. */ + asm("cmp/str %1,%2\n\t" + "movt %0" + : "=r" (ret) : "r" (x1), "r" (x2) : "t"); + + return ret; +} + +/* Determine if any byte within X is zero. */ +static __always_inline _Bool +has_zero (op_t x) +{ + return has_eq (x, 0); +} + +/* Likewise, but for zeros in X1 and equal bytes between X1 and X2. */ +static __always_inline _Bool +has_zero_eq (op_t x1, op_t x2) +{ + return has_zero (x1) | has_eq (x1, x2); +} + +#endif /* STRING_FZB_H */ From patchwork Wed Feb 1 17:03:57 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adhemerval Zanella Netto X-Patchwork-Id: 64094 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 925BB388B6B1 for ; Wed, 1 Feb 2023 17:06:05 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 925BB388B6B1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1675271165; bh=6+Gg0Uio9ZRqb/T8ZmTBWPStFXWhlqTUUzWE2r+37s4=; h=To:Subject:Date:In-Reply-To:References:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=EPnSCz9cuDHhDznvoz04X3zk3EX0oxya/NdK5wqvvVXX0W1XX3PEQyXSO6/N1ohnU U43Uam6o8Nls9zWXewwZpDDiVTF90v5xCXStNyl7qWIGSt/lYR2pM3m3l1D73CJcU/ WKPuf9lNe8Jx7ZpNIeuNI0hNQDbZee1YuW2GCkF0= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-oi1-x22b.google.com (mail-oi1-x22b.google.com [IPv6:2607:f8b0:4864:20::22b]) by sourceware.org (Postfix) with ESMTPS id 95103384F00D for ; Wed, 1 Feb 2023 17:05:04 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 95103384F00D Received: by mail-oi1-x22b.google.com with SMTP id r205so16257393oib.9 for ; Wed, 01 Feb 2023 09:05:04 -0800 (PST) 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:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=6+Gg0Uio9ZRqb/T8ZmTBWPStFXWhlqTUUzWE2r+37s4=; b=Vz2d002QOnHuT0qr4m6pL6rkKs+gvIARLOvigJoXzK/7FD9Tc87mWBnj9IbNmps3rp fnPhy5ymmg6kwOgTOblgdvX8akd+eQcxatn3vG6A5j31hmae5aewcbZ80kNqOXwFBTRK zwqlH3sBJZb4g4j1Q/Ggk+AOFY10qgCt5CPh4ebEpxZGoizOrrxPv5iD2cFvvXHql4VT eOe6l2g4Y3jOCIZeD/CGoNa0SMANQTOICtoNHlf1LynLv+lnpybaS1K1DFQllu/+UEIW Q4R+V4qYUy0nSsv81hLPgBg3/Y3T5bqlh8QLXDN6XpQP3Ha9nrebQ7okufAxPIvD57Cg tK6w== X-Gm-Message-State: AO0yUKVrvr67IpW9GJ0UqbQHaJB0KPifPfo8JOOc0gkqUhmLVFL5TJBt Pz+W4S9zgMUQ8B6rUQoH/7YSX1Fv1neX2HUQW2g= X-Google-Smtp-Source: AK7set9Opefc6TLYh9qzfHUKYQmNF3n7ViUYn4aI8AdPLye0j1nmsFitqLu0yMJdXQfEOh63Q8f63g== X-Received: by 2002:a05:6808:2cf:b0:378:85ae:a286 with SMTP id a15-20020a05680802cf00b0037885aea286mr1394058oid.31.1675271103545; Wed, 01 Feb 2023 09:05:03 -0800 (PST) Received: from mandiga.. ([2804:1b3:a7c2:1887:d2ed:98c2:d2cc:bf06]) by smtp.gmail.com with ESMTPSA id b17-20020a056830311100b006863ccbf067sm8077090ots.74.2023.02.01.09.05.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 01 Feb 2023 09:05:02 -0800 (PST) To: libc-alpha@sourceware.org, Richard Henderson , Noah Goldstein , Jeff Law , Xi Ruoyao Subject: [PATCH v11 20/29] riscv: Add string-fza.h and string-fzi.h Date: Wed, 1 Feb 2023 14:03:57 -0300 Message-Id: <20230201170406.303978-21-adhemerval.zanella@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230201170406.303978-1-adhemerval.zanella@linaro.org> References: <20230201170406.303978-1-adhemerval.zanella@linaro.org> 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, 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: , X-Patchwork-Original-From: Adhemerval Zanella via Libc-alpha From: Adhemerval Zanella Netto Reply-To: Adhemerval Zanella Errors-To: libc-alpha-bounces+patchwork=sourceware.org@sourceware.org Sender: "Libc-alpha" It uses the bitmanip extension to optimize index_fist and index_last with clz/ctz (using generic implementation that routes to compiler builtin) and orc.b to check null bytes. Checked the string test on riscv64 user mode. Reviewed-by: Richard Henderson --- sysdeps/riscv/string-fza.h | 70 ++++++++++++++++++++++++++++++++++ sysdeps/riscv/string-fzi.h | 77 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 147 insertions(+) create mode 100644 sysdeps/riscv/string-fza.h create mode 100644 sysdeps/riscv/string-fzi.h diff --git a/sysdeps/riscv/string-fza.h b/sysdeps/riscv/string-fza.h new file mode 100644 index 0000000000..9c7a6efba2 --- /dev/null +++ b/sysdeps/riscv/string-fza.h @@ -0,0 +1,70 @@ +/* Zero byte detection; basics. RISCV version. + Copyright (C) 2023 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 + . */ + +#ifndef _RISCV_STRING_FZA_H +#define _RISCV_STRING_FZA_H 1 + +#ifdef __riscv_zbb +/* With bitmap extension we can use orc.b to find all zero bytes. */ +# include +# include + +/* The functions return a byte mask. */ +typedef op_t find_t; + +/* This function returns 0xff for each byte that is zero in X. */ +static __always_inline find_t +find_zero_all (op_t x) +{ + find_t r; + asm ("orc.b %0, %1" : "=r" (r) : "r" (x)); + return ~r; +} + +/* This function returns 0xff for each byte that is equal between X1 and + X2. */ +static __always_inline find_t +find_eq_all (op_t x1, op_t x2) +{ + return find_zero_all (x1 ^ x2); +} + +/* Identify zero bytes in X1 or equality between X1 and X2. */ +static __always_inline find_t +find_zero_eq_all (op_t x1, op_t x2) +{ + return find_zero_all (x1) | find_eq_all (x1, x2); +} + +/* Identify zero bytes in X1 or inequality between X1 and X2. */ +static __always_inline find_t +find_zero_ne_all (op_t x1, op_t x2) +{ + return find_zero_all (x1) | ~find_eq_all (x1, x2); +} + +/* Define the "inexact" versions in terms of the exact versions. */ +# define find_zero_low find_zero_all +# define find_eq_low find_eq_all +# define find_zero_eq_low find_zero_eq_all +# define find_zero_ne_low find_zero_ne_all +#else +#include +#endif + +#endif /* _RISCV_STRING_FZA_H */ diff --git a/sysdeps/riscv/string-fzi.h b/sysdeps/riscv/string-fzi.h new file mode 100644 index 0000000000..3cde113afb --- /dev/null +++ b/sysdeps/riscv/string-fzi.h @@ -0,0 +1,77 @@ +/* Zero byte detection; indexes. RISCV version. + Copyright (C) 2023 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 + . */ + +#ifndef _STRING_RISCV_FZI_H +#define _STRING_RISCV_FZI_H 1 + +#ifdef __riscv_zbb +# include +#else +/* Without bitmap clz/ctz extensions, it is faster to direct test the bits + instead of calling compiler auxiliary functions. */ +# include + +static __always_inline unsigned int +index_first (find_t c) +{ + if (c & 0x80U) + return 0; + if (c & 0x8000U) + return 1; + if (c & 0x800000U) + return 2; + + if (sizeof (op_t) == 4) + return 3; + + if (c & 0x80000000U) + return 3; + if (c & 0x8000000000UL) + return 4; + if (c & 0x800000000000UL) + return 5; + if (c & 0x80000000000000UL) + return 6; + return 7; +} + +static __always_inline unsigned int +index_last (find_t c) +{ + if (sizeof (op_t) == 8) + { + if (c & 0x8000000000000000UL) + return 7; + if (c & 0x80000000000000UL) + return 6; + if (c & 0x800000000000UL) + return 5; + if (c & 0x8000000000UL) + return 4; + } + if (c & 0x80000000U) + return 3; + if (c & 0x800000U) + return 2; + if (c & 0x8000U) + return 1; + return 0; +} +#endif + +#endif /* STRING_FZI_H */ From patchwork Wed Feb 1 17:03:58 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adhemerval Zanella Netto X-Patchwork-Id: 64098 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 2EB48389EC69 for ; Wed, 1 Feb 2023 17:06:47 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 2EB48389EC69 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1675271207; bh=mCE/YFqXL4Z7i4zGFW/a0I/C1EeOtkop6T1+5F6jnvE=; h=To:Subject:Date:In-Reply-To:References:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=M5PUCy+ZlpQN2AMZ6TqUQNxS7SADcKLcDo8c0XUJMohqys+bVyl8uWBuJzcN06PmU vBOWJ09iJkr1psIYBpuNBc8ExDn2OCNiXweqM8Z/RuEqRvyKmX+FiMKHVuwRUelOlo 6dMeaPvnZeSC7ACD8GEvEuIVm90+WIrSha4TJrsk= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-ot1-x32d.google.com (mail-ot1-x32d.google.com [IPv6:2607:f8b0:4864:20::32d]) by sourceware.org (Postfix) with ESMTPS id 64B9D384A04C for ; Wed, 1 Feb 2023 17:05:07 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 64B9D384A04C Received: by mail-ot1-x32d.google.com with SMTP id e12-20020a0568301e4c00b0068bc93e7e34so3545443otj.4 for ; Wed, 01 Feb 2023 09:05:07 -0800 (PST) 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:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=mCE/YFqXL4Z7i4zGFW/a0I/C1EeOtkop6T1+5F6jnvE=; b=WoMzeCHriR+/xrOsylZELqlhYXdNssZLbECKcZBJoDbhVfBpi1yH4hNYUoHsl4q7pq PyL6lb6nVfFepubfh8hTTAzPbNO6UamA88dJ1pZHwL0982SWp3EWWSUCGw0qsw5pnMVp 47UuXo1cfYZdAS7IYPPC6kRZUSHM6Oshe4LlO/razwm0o/TilmExn3hVS5MlGNs5DWEt qabDPicBaMLuhAbZsPBLdmcZjf9oGmyB5PQzqAwiUhPfu1UWnItLmzjH7w7ZiL64q6KP ms4PiNeQELQlJ2NDLMMamD5c/2yl01YNEM7M2qjQM+tZt/jmUQzzf32BcULsfyyDogqv 2Ftg== X-Gm-Message-State: AO0yUKUs2SsMywf7eMqGZ+Cte4zPkF37M9snMZB2briK/JzUjxSQFJGY wP8QGDUoS39dnCFUf+N7e4QyycufHGUAEtIu3r4= X-Google-Smtp-Source: AK7set+WxXtp/k3L0giFKOmwtsmMPhWyRZnCjWJE/6BsBnUtbhrReu/YsFmpy/3bWEfWctDi7h2w4A== X-Received: by 2002:a05:6830:3090:b0:68d:3fc8:7c09 with SMTP id g16-20020a056830309000b0068d3fc87c09mr937501ots.4.1675271106056; Wed, 01 Feb 2023 09:05:06 -0800 (PST) Received: from mandiga.. ([2804:1b3:a7c2:1887:d2ed:98c2:d2cc:bf06]) by smtp.gmail.com with ESMTPSA id b17-20020a056830311100b006863ccbf067sm8077090ots.74.2023.02.01.09.05.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 01 Feb 2023 09:05:05 -0800 (PST) To: libc-alpha@sourceware.org, Richard Henderson , Noah Goldstein , Jeff Law , Xi Ruoyao Subject: [PATCH v11 21/29] string: Hook up the default implementation on test-strlen Date: Wed, 1 Feb 2023 14:03:58 -0300 Message-Id: <20230201170406.303978-22-adhemerval.zanella@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230201170406.303978-1-adhemerval.zanella@linaro.org> References: <20230201170406.303978-1-adhemerval.zanella@linaro.org> 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, 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: , X-Patchwork-Original-From: Adhemerval Zanella via Libc-alpha From: Adhemerval Zanella Netto Reply-To: Adhemerval Zanella Errors-To: libc-alpha-bounces+patchwork=sourceware.org@sourceware.org Sender: "Libc-alpha" Also remove the simple_STRLEN and builtin_strlen, which are not used anywhere. Reviewed-by: Richard Henderson --- string/test-strlen.c | 31 ++++++++++++++----------------- 1 file changed, 14 insertions(+), 17 deletions(-) diff --git a/string/test-strlen.c b/string/test-strlen.c index 81adf23737..0f98576f40 100644 --- a/string/test-strlen.c +++ b/string/test-strlen.c @@ -37,27 +37,24 @@ typedef size_t (*proto_t) (const CHAR *); -/* Naive implementation to verify results. */ -size_t -simple_STRLEN (const CHAR *s) -{ - const CHAR *p; - - for (p = s; *p; ++p); - return p - s; -} +IMPL (STRLEN, 1) +/* Also check the generic implementation. */ +#undef STRLEN +#undef weak_alias +#define weak_alias(a, b) +#undef libc_hidden_builtin_def +#define libc_hidden_builtin_def(a) #ifndef WIDE -size_t -builtin_strlen (const CHAR *p) -{ - return __builtin_strlen (p); -} -IMPL (builtin_strlen, 0) +# define STRLEN __strlen_default +# include "string/strlen.c" +IMPL (__strlen_default, 1) +#else +# define WCSLEN __wcslen_default +# include "wcsmbs/wcslen.c" +IMPL (__wcslen_default, 1) #endif -IMPL (STRLEN, 1) - static void do_one_test (impl_t *impl, const CHAR *s, size_t exp_len) From patchwork Wed Feb 1 17:03:59 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adhemerval Zanella Netto X-Patchwork-Id: 64102 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 1E9603947410 for ; Wed, 1 Feb 2023 17:07:29 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 1E9603947410 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1675271249; bh=6vrJsjuPSBEnYiH6vQCIl2c/+1Z+TJJoaBWPQwlpPzM=; h=To:Subject:Date:In-Reply-To:References:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=XZh/tWYbL3DkruBHxAjWysiGB5Xuwo1CkX9oRXOuCLoKa/h+lkGuOyLHmQOr6OWw5 AENbmpYJq25ntQlvV++7o4f+LvZJLomHvkdia1kgG8MiTlTYraVrXuaHDa1L/7aax7 0NZbn7ho2S5sFfUEI11YSg6Xr9AReUN6QI0JpAwg= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-ot1-x32c.google.com (mail-ot1-x32c.google.com [IPv6:2607:f8b0:4864:20::32c]) by sourceware.org (Postfix) with ESMTPS id 4B0A93857B9B for ; Wed, 1 Feb 2023 17:05:10 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 4B0A93857B9B Received: by mail-ot1-x32c.google.com with SMTP id r34-20020a05683044a200b0068d4a8a8d2dso132470otv.12 for ; Wed, 01 Feb 2023 09:05:10 -0800 (PST) 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:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=6vrJsjuPSBEnYiH6vQCIl2c/+1Z+TJJoaBWPQwlpPzM=; b=5TNRL8vIx+GKR1zXcZgYIdtFWn3mJAYcTbHeqPukdhFgnfgQ8IH2fGBnPWV2RCg9Vu 0R/CVxr8bccHm1BzWdgcrhuUYY0ojYS7SZwcfSYfYRoBcWgS5f0DN/SQr20KaxquBVwA BkVnDURV4f86mhSRvXWg726CtAbi5toaAVG7+cgVc+SQ/4kVoyItT+D+zJpX8UiU31iV bcpl9SwHxNKGaCPHeMx5EnyHxwvKuiBhRQnkp0UMCvPr4HikWR9WT4YTPPxOFVAH5AfO rPi1KyzcxEPBtXTnNdAXrgKY3YYijUuc79+d3eMCs/4/rBGng6q9nL6zlOp7CccT+j7P S/qw== X-Gm-Message-State: AO0yUKWwoH6J0Xg5jZq/vKtEWk7oTeTIqeBwXsed+AVKjOaYqf4jdaOP S1MOk4Bg0FdaDt3LRIQ46XX3jZDUUT2M9vN3qU0= X-Google-Smtp-Source: AK7set9aA2ZQ45VOHdSebCZv8NyrE6aj9FSgDZ7A/9dK1jnpSxUnEK3NeoZrBkZiyLOss+MmWkLwhA== X-Received: by 2002:a9d:65c2:0:b0:68b:bc6c:d955 with SMTP id z2-20020a9d65c2000000b0068bbc6cd955mr1618439oth.17.1675271108661; Wed, 01 Feb 2023 09:05:08 -0800 (PST) Received: from mandiga.. ([2804:1b3:a7c2:1887:d2ed:98c2:d2cc:bf06]) by smtp.gmail.com with ESMTPSA id b17-20020a056830311100b006863ccbf067sm8077090ots.74.2023.02.01.09.05.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 01 Feb 2023 09:05:07 -0800 (PST) To: libc-alpha@sourceware.org, Richard Henderson , Noah Goldstein , Jeff Law , Xi Ruoyao Subject: [PATCH v11 22/29] string: Hook up the default implementation on test-strnlen Date: Wed, 1 Feb 2023 14:03:59 -0300 Message-Id: <20230201170406.303978-23-adhemerval.zanella@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230201170406.303978-1-adhemerval.zanella@linaro.org> References: <20230201170406.303978-1-adhemerval.zanella@linaro.org> 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, 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: , X-Patchwork-Original-From: Adhemerval Zanella via Libc-alpha From: Adhemerval Zanella Netto Reply-To: Adhemerval Zanella Errors-To: libc-alpha-bounces+patchwork=sourceware.org@sourceware.org Sender: "Libc-alpha" Also remove the SIMPLE_STRNLEN, which is not used anywhere. Reviewed-by: Richard Henderson --- string/test-strnlen.c | 35 ++++++++++++++++++++++++----------- 1 file changed, 24 insertions(+), 11 deletions(-) diff --git a/string/test-strnlen.c b/string/test-strnlen.c index 8b5372c3a1..ef73dd34f4 100644 --- a/string/test-strnlen.c +++ b/string/test-strnlen.c @@ -43,17 +43,30 @@ typedef size_t (*proto_t) (const CHAR *, size_t); -IMPL (STRNLEN, 1) - -/* Naive implementation to verify results. */ -size_t -SIMPLE_STRNLEN (const CHAR *s, size_t maxlen) -{ - size_t i; - - for (i = 0; i < maxlen && s[i]; ++i); - return i; -} +/* Also check the default implementation. */ +#undef STRNLEN +#ifndef WIDE +# define MEMCHR __memchr_default +# define weak_alias(a, b) +# define libc_hidden_def(a) +# define libc_hidden_builtin_def(a) +# include "string/memchr.c" +# undef STRNLEN +# define STRNLEN __strnlen_default +# define memchr __memchr_default +# include "string/strnlen.c" +IMPL (__strnlen_default, 1) +#else +# define WMEMCHR __wmemchr_default +# define weak_alias(a, b) +# define libc_hidden_def(a) +# define libc_hidden_weak(a) +# include "wcsmbs/wmemchr.c" +# define WCSNLEN __wcsnlen_default +# define wmemchr __wmemchr_default +# include "wcsmbs/wcsnlen.c" +IMPL (__wcsnlen_default, 1) +#endif static void do_one_test (impl_t *impl, const CHAR *s, size_t maxlen, size_t exp_len) From patchwork Wed Feb 1 17:04:00 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adhemerval Zanella Netto X-Patchwork-Id: 64104 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 018A7394882E for ; Wed, 1 Feb 2023 17:07:44 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 018A7394882E DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1675271264; bh=WlwRBvpBuUGYAO3ObfLqIDIYorlFz4kL9P0jSfzvCFk=; h=To:Subject:Date:In-Reply-To:References:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=eDODEh9QrimVryphYy8QG91p5ebFRd/e1yqPZhRXxd447NEUUdKWdNzTVskBpyuPt gzibrHziPnQAOYlxQbwdkgokpx+TFoXtMn16y38sUJ2AoQEmP3EQc4vagTLWaUQTcl MBSnMeEeEyCtP6FcTYLTLchjqZ5HyqvZBjXPGS30= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-oa1-x31.google.com (mail-oa1-x31.google.com [IPv6:2001:4860:4864:20::31]) by sourceware.org (Postfix) with ESMTPS id 4885E38493D4 for ; Wed, 1 Feb 2023 17:05:12 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 4885E38493D4 Received: by mail-oa1-x31.google.com with SMTP id 586e51a60fabf-16346330067so24359679fac.3 for ; Wed, 01 Feb 2023 09:05:12 -0800 (PST) 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:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=WlwRBvpBuUGYAO3ObfLqIDIYorlFz4kL9P0jSfzvCFk=; b=QEgzM84twyCaQ+HTNNkNaEfJ8e8TFuutvI/lpc0FhF5XnAE8h+nDMl4olMwO9M+o9j gBnVgCto9nX4rbRpssjBJFjIs6BNs+Rv/DN74UxGKttcCmkfIJ6kDaLTh0TNQceu0ssh yj9NbqtDlEvUmiXD+5PfgGBWhpChhwdb1HV/t2r/OxdO5FfA7EP3siR4Spx8MPWOlFZZ LCxk3R/stTAQ2DdOLwVeTRCnKxHMLo9eeMU1OBzhhko3klq3hnc0YwjVkd24wrm4nRCD 0KJq0Jy6PoFKjUTzTV/bqCXDqHIlOBIagQV28qRgw7D2ocdH0sb3LhxbMmMzdNBJ34i+ Mg4A== X-Gm-Message-State: AO0yUKWXDl3MJlS3LRZIGwu5mZH+3a7m5XfUFSIakoYtOvvSaf684Ahv nf+PlNHDuxPAAtHXos77ihlVDqwnDmGzXPFV7S4= X-Google-Smtp-Source: AK7set+tURo+IpQmdjgI/JvPVZ4ogTmyXxKKwTXi4OPEfprF6WP66z+qr7FICHwD4KRJBGE1JhkzTQ== X-Received: by 2002:a05:6871:411:b0:163:cd07:a5a5 with SMTP id d17-20020a056871041100b00163cd07a5a5mr1431652oag.56.1675271111199; Wed, 01 Feb 2023 09:05:11 -0800 (PST) Received: from mandiga.. ([2804:1b3:a7c2:1887:d2ed:98c2:d2cc:bf06]) by smtp.gmail.com with ESMTPSA id b17-20020a056830311100b006863ccbf067sm8077090ots.74.2023.02.01.09.05.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 01 Feb 2023 09:05:10 -0800 (PST) To: libc-alpha@sourceware.org, Richard Henderson , Noah Goldstein , Jeff Law , Xi Ruoyao Subject: [PATCH v11 23/29] string: Hook up the default implementation on test-strchr Date: Wed, 1 Feb 2023 14:04:00 -0300 Message-Id: <20230201170406.303978-24-adhemerval.zanella@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230201170406.303978-1-adhemerval.zanella@linaro.org> References: <20230201170406.303978-1-adhemerval.zanella@linaro.org> 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, 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: , X-Patchwork-Original-From: Adhemerval Zanella via Libc-alpha From: Adhemerval Zanella Netto Reply-To: Adhemerval Zanella Errors-To: libc-alpha-bounces+patchwork=sourceware.org@sourceware.org Sender: "Libc-alpha" Also remove the simple_STRCHR, which can be easily replaced. Reviewed-by: Richard Henderson --- string/test-strchr.c | 53 +++++++++++++++++++++++++++++++------------- 1 file changed, 38 insertions(+), 15 deletions(-) diff --git a/string/test-strchr.c b/string/test-strchr.c index 323c844d21..933fc0bbba 100644 --- a/string/test-strchr.c +++ b/string/test-strchr.c @@ -35,7 +35,6 @@ #ifndef WIDE # ifdef USE_FOR_STRCHRNUL # define STRCHR strchrnul -# define simple_STRCHR simple_STRCHRNUL # else # define STRCHR strchr # endif /* !USE_FOR_STRCHRNUL */ @@ -50,7 +49,6 @@ # include # ifdef USE_FOR_STRCHRNUL # define STRCHR wcschrnul -# define simple_STRCHR simple_WCSCHRNUL # else # define STRCHR wcschr # endif /* !USE_FOR_STRCHRNUL */ @@ -72,20 +70,41 @@ typedef CHAR *(*proto_t) (const CHAR *, int); -/* Naive implementation to verify results. */ -CHAR * -simple_STRCHR (const CHAR *s, int c) -{ - size_t n = STRLEN (s) + 1; - - while (n--) - if (*s++ == (CHAR) c) - return (CHAR *) s - 1; - return NULLRET ((CHAR *) s - 1); -} - IMPL (STRCHR, 1) +/* Also check the generic implementation. */ +#undef STRCHR +#undef weak_alias +#define weak_alias(a, b) +#undef libc_hidden_builtin_def +#define libc_hidden_builtin_def(a) +#undef libc_hidden_def +#define libc_hidden_def(a) +#undef libc_hidden_weak +#define libc_hidden_weak(a) +#ifndef WIDE +# define STRCHRNUL __strchrnul_default +# include "string/strchrnul.c" +# ifndef USE_FOR_STRCHRNUL +# define STRCHR __strchr_default +# include "string/strchr.c" +# define STRCHR_DEFAULT STRCHR +# else +# define STRCHR_DEFAULT STRCHRNUL +# endif +#else +# ifndef USE_FOR_STRCHRNUL +# define WCSCHR __wcschr_default +# include "wcsmbs/wcschr.c" +# define STRCHR_DEFAULT WCSCHR +# else +# define WCSCHRNUL __wcschrnul_default +# include "wcsmbs/wcschrnul.c" +# define STRCHR_DEFAULT WCSCHRNUL +# endif +#endif +IMPL (STRCHR_DEFAULT, 1) + static int check_result (impl_t *impl, const CHAR *s, int c, const CHAR *exp_res) { @@ -219,7 +238,11 @@ check1 (void) { CHAR s[] __attribute__((aligned(16))) = L ("\xff"); CHAR c = L ('\xfe'); - CHAR *exp_result = simple_STRCHR (s, c); +#ifndef USE_FOR_STRCHRNUL + CHAR *exp_result = NULL; +#else + CHAR *exp_result = s + STRLEN (s); +#endif FOR_EACH_IMPL (impl, 0) check_result (impl, s, c, exp_result); From patchwork Wed Feb 1 17:04:01 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adhemerval Zanella Netto X-Patchwork-Id: 64108 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 D909938983BA for ; Wed, 1 Feb 2023 17:08:26 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org D909938983BA DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1675271306; bh=BjdtcZv5xPKYYHAXCP0rQzjiHaC4gBNPxLaODhMfNdU=; h=To:Subject:Date:In-Reply-To:References:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=FsjdDw7aiQFNdp3jxH56p8DNJwF7HIxUQ+40q3yHhjgnn3YCqRPBTGJ0+K3gjN6os 1wsvfqtTT0S12+PJK5i6diLzV2GuvzsIPy2Rh4T2Z8XUe1iQOj9pYtAaq4AIF9TTc+ KvtnwRKr4mFiIoigenOAxo3CR4AlRuwaqcxkqh7A= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-ot1-x32c.google.com (mail-ot1-x32c.google.com [IPv6:2607:f8b0:4864:20::32c]) by sourceware.org (Postfix) with ESMTPS id 155EE385E82F for ; Wed, 1 Feb 2023 17:05:15 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 155EE385E82F Received: by mail-ot1-x32c.google.com with SMTP id k91-20020a9d19e4000000b0068bca1294aaso3478195otk.8 for ; Wed, 01 Feb 2023 09:05:15 -0800 (PST) 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:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=BjdtcZv5xPKYYHAXCP0rQzjiHaC4gBNPxLaODhMfNdU=; b=mAyEh18HzjwB0rUf6iRDGPnBJyGxkpoWiF2RIt72Veo237wIMfEPZZocA0YSEFdhm4 I5Tg4X+6E3Fr/kDRJRrjOV5kCmnhnpR0YSmLA6BnTT2qpZ9eO9e8Q0+cvg+TLCW+/1QZ 217q3o2u4FBsHyxWGYBh+RVi/36qpgkqE/sp9B/GUxY5uEUbzoR4pdYy+DO1HMN1Mxmm OU6aU2m1nS+RtHSrVYgwTTFgoRbiMMiJJE9GI50PGiMXX1vMTBdmIJrosOgw1BhQTwGK /ddrVNixWK91siy0DYZV76G8y3M1UJnoCOBuK3LZLMyJBWLxqU51XI7Qz1CmBh16FMZb GeXg== X-Gm-Message-State: AO0yUKXRCpuB1pzbxKNDhLIHf6qrtHnhk3XBKXz8yPZzkwQfylPTzAbZ QnlGXLbi66IQyLv8YAM5amEerLw4ecqGuILIaew= X-Google-Smtp-Source: AK7set/fdzc5Sj9ji9JZ71DQzEtIQNMtxOloGHIRG1B7wicmqCZExgNcjOQ6ksh5zGLnq9XbTV8eCQ== X-Received: by 2002:a05:6830:3360:b0:686:7992:9dfa with SMTP id l32-20020a056830336000b0068679929dfamr2101711ott.6.1675271113709; Wed, 01 Feb 2023 09:05:13 -0800 (PST) Received: from mandiga.. ([2804:1b3:a7c2:1887:d2ed:98c2:d2cc:bf06]) by smtp.gmail.com with ESMTPSA id b17-20020a056830311100b006863ccbf067sm8077090ots.74.2023.02.01.09.05.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 01 Feb 2023 09:05:12 -0800 (PST) To: libc-alpha@sourceware.org, Richard Henderson , Noah Goldstein , Jeff Law , Xi Ruoyao Subject: [PATCH v11 24/29] string: Hook up the default implementation on test-strcmp Date: Wed, 1 Feb 2023 14:04:01 -0300 Message-Id: <20230201170406.303978-25-adhemerval.zanella@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230201170406.303978-1-adhemerval.zanella@linaro.org> References: <20230201170406.303978-1-adhemerval.zanella@linaro.org> 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, 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: , X-Patchwork-Original-From: Adhemerval Zanella via Libc-alpha From: Adhemerval Zanella Netto Reply-To: Adhemerval Zanella Errors-To: libc-alpha-bounces+patchwork=sourceware.org@sourceware.org Sender: "Libc-alpha" --- string/test-strcmp.c | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) Reviewed-by: Richard Henderson diff --git a/string/test-strcmp.c b/string/test-strcmp.c index ceb0d29c74..fa3161688c 100644 --- a/string/test-strcmp.c +++ b/string/test-strcmp.c @@ -101,6 +101,28 @@ typedef int (*proto_t) (const CHAR *, const CHAR *); IMPL (STRCMP, 1) +/* Also check the default implementation. */ +#undef STRCMP +#undef libc_hidden_builtin_def +#define libc_hidden_builtin_def(a) +#undef libc_hidden_def +#define libc_hidden_def(a) +#undef weak_alias +#define weak_alias(a, b) +#undef attribute_hidden +#define attribute_hidden +#ifndef WIDE +# define STRCMP __strcmp_default +# include "string/strcmp.c" +# define STRCMP_DEFAULT STRCMP +#else +# define WCSCMP __wcscmp_default +# include "wcsmbs/wcscmp.c" +# define STRCMP_DEFAULT WCSCMP +#endif +IMPL (STRCMP_DEFAULT, 1) + + static int check_result (impl_t *impl, const CHAR *s1, const CHAR *s2, From patchwork Wed Feb 1 17:04:02 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adhemerval Zanella Netto X-Patchwork-Id: 64106 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 8743539502D8 for ; Wed, 1 Feb 2023 17:08:11 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 8743539502D8 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1675271291; bh=KHtcW8v9AgEJXBxhRQhzHR+sZS5ZSEoyLU3ZktxYi8c=; h=To:Subject:Date:In-Reply-To:References:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=jAXpCzsMhONRF4FiUofWTTgLMrFBJsjt7a7LLCPL/b1WEZNMcxMnEoKVc141R3fff lCuJ50ecqtS2GjszXJldBpiErcFZ3/36mNsGNYLm1vv+V3mGnZnG2qlCkH+lIUYK4l q8mU/CpVZ8bMGbYoh5W3AtXiNJ/FHu7pfmXAhTTc= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-ot1-x335.google.com (mail-ot1-x335.google.com [IPv6:2607:f8b0:4864:20::335]) by sourceware.org (Postfix) with ESMTPS id 9B3EC385B534 for ; Wed, 1 Feb 2023 17:05:17 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 9B3EC385B534 Received: by mail-ot1-x335.google.com with SMTP id s41-20020a05683043a900b0068bd63d34d0so2481221otv.6 for ; Wed, 01 Feb 2023 09:05:17 -0800 (PST) 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:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=KHtcW8v9AgEJXBxhRQhzHR+sZS5ZSEoyLU3ZktxYi8c=; b=offhxJJjHlcnv1hXjwVwY8teiTt/duMjC9pJLZgP0OscB+R3tqtdCVPlj4mpuOU/Gv Mmrdh4XW4RnkgqsOgSTHRxLjKrT2zRQ0tBOOoTHLNBmR1LVx7P8o57VSqTdMU4TfBsIM aLK+1yX1g2s4NLBKeB1YbAh4bHS+f5FMM/iYDMAVeMu9jke5YpnZl/E48NIT4Ldeu4af vSDTHABMi2UF/Y+/XlQffT+cV5eHCnefQceReco+mwU6Qrvr+Sh7apePsrm1jyc73bfU Hmfxp6zbc3AF8w/xzOyZj651SWUyznMX0Y7Jo1C6hg1FbjfGGGd3Ijv7rWMZMMOD632q emFw== X-Gm-Message-State: AO0yUKWMNTCpSex4R7yqhFx27CANuN1vVUSofAhGnSqwKUQ9NyoICW2i X05Ys0yVzMVmQsumIZCobb5aCZKDNQZWvwjQ9aQ= X-Google-Smtp-Source: AK7set8Ombwubwxgie5PEtCHt6cI6ELKzDQgU6AZfDuqV1RUHHeFpitd4QDul7mLTquvyTO1ERdppA== X-Received: by 2002:a05:6830:1e57:b0:68b:b721:8f1c with SMTP id e23-20020a0568301e5700b0068bb7218f1cmr1688472otj.27.1675271116117; Wed, 01 Feb 2023 09:05:16 -0800 (PST) Received: from mandiga.. ([2804:1b3:a7c2:1887:d2ed:98c2:d2cc:bf06]) by smtp.gmail.com with ESMTPSA id b17-20020a056830311100b006863ccbf067sm8077090ots.74.2023.02.01.09.05.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 01 Feb 2023 09:05:15 -0800 (PST) To: libc-alpha@sourceware.org, Richard Henderson , Noah Goldstein , Jeff Law , Xi Ruoyao Subject: [PATCH v11 25/29] string: Hook up the default implementation on test-strncmp Date: Wed, 1 Feb 2023 14:04:02 -0300 Message-Id: <20230201170406.303978-26-adhemerval.zanella@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230201170406.303978-1-adhemerval.zanella@linaro.org> References: <20230201170406.303978-1-adhemerval.zanella@linaro.org> 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, 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: , X-Patchwork-Original-From: Adhemerval Zanella via Libc-alpha From: Adhemerval Zanella Netto Reply-To: Adhemerval Zanella Errors-To: libc-alpha-bounces+patchwork=sourceware.org@sourceware.org Sender: "Libc-alpha" --- string/test-strncmp.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) Reviewed-by: Richard Henderson diff --git a/string/test-strncmp.c b/string/test-strncmp.c index fb4c6420b8..35dc496eae 100644 --- a/string/test-strncmp.c +++ b/string/test-strncmp.c @@ -90,6 +90,22 @@ typedef int (*proto_t) (const CHAR *, const CHAR *, size_t); IMPL (STRNCMP, 1) +/* Also check the default implementation. */ +#undef STRNCMP +#undef libc_hidden_builtin_def +#define libc_hidden_builtin_def(a) +#undef attribute_hidden +#define attribute_hidden +#ifndef WIDE +# define STRNCMP __strncmp_default +# include "string/strncmp.c" +# define STRNCMP_DEFAULT STRNCMP +#else +# define WCSNCMP __wcsncmp_default +# include "wcsmbs/wcsncmp.c" +# define STRNCMP_DEFAULT WCSNCMP +#endif +IMPL (STRNCMP_DEFAULT, 1) static int check_result (impl_t *impl, const CHAR *s1, const CHAR *s2, size_t n, From patchwork Wed Feb 1 17:04:03 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adhemerval Zanella Netto X-Patchwork-Id: 64110 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 8CBC6382E6BE for ; Wed, 1 Feb 2023 17:09:08 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 8CBC6382E6BE DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1675271348; bh=Sq2bS6OKH9OGVMzwrmwLBiFn09QfLa9qFmIoj/BIje4=; h=To:Subject:Date:In-Reply-To:References:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=QwpOSKdx1qAvEpJA3dD2eZOwRg3d4q7HxgPzRgPC4mb9QtOVgI40piNVj8sCS+Yy1 bdFFqnvExWGpDuyLpiseO+4i1DEDvVNNuvHPY4dJwtvESc4n+FRZx5MokrulP4p/Sq GFrGqW0kJgNMGO9UZRPcxh5ms9uETStRrvWfQzAA= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-ot1-x329.google.com (mail-ot1-x329.google.com [IPv6:2607:f8b0:4864:20::329]) by sourceware.org (Postfix) with ESMTPS id B97653858412 for ; Wed, 1 Feb 2023 17:05:19 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org B97653858412 Received: by mail-ot1-x329.google.com with SMTP id 14-20020a9d010e000000b0068bdddfa263so2006347otu.2 for ; Wed, 01 Feb 2023 09:05:19 -0800 (PST) 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:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Sq2bS6OKH9OGVMzwrmwLBiFn09QfLa9qFmIoj/BIje4=; b=IDq+o1ud3eFji/mtUJViXz0LrcW7cEs/B+afY2dCU5okRq0CDN9IXIDtxzlsPzLwvL apPYWvbr/SCvEos6QJrC5vOa2lQMXWKY1MmsLUqx7zFzJMyALREcs+Z4gZJcrGyy9ufT vKvqTi9nobnqcoB1nzfTHWpRxQmRy/da+6PI4VsaEspbPt/8aoSbNgaEnrNw6MmiRVM5 1QCAcoBP3JG0EmYiKrQUUPxzxlwQGNzJ5Pvjrv2R+zNGaaNPNpTfRbvgsA53RiXg71lX OIXPItaaI7zqr5S6I7n+II38BSfjC0YKJBaREPBUy9LHHbM/MWX/HBNzZma0uhHSUYCG UOhA== X-Gm-Message-State: AO0yUKVLKpl9jp72+oQQpMFsyienp32xYZuy4f/i7VW0SuVXdhVS+K7y Sm0eEZTYzGUbdzt2o1PKV+5009+9VTPk5RG3Rhg= X-Google-Smtp-Source: AK7set+AojViNtcByshiEsalowO0Xp8ZgxmgHAv98Uod1t9QwDKNXNpcD3ine8evgQ4yF+PWU5YAxQ== X-Received: by 2002:a9d:7b49:0:b0:68c:f7f5:f53d with SMTP id f9-20020a9d7b49000000b0068cf7f5f53dmr1677715oto.0.1675271118390; Wed, 01 Feb 2023 09:05:18 -0800 (PST) Received: from mandiga.. ([2804:1b3:a7c2:1887:d2ed:98c2:d2cc:bf06]) by smtp.gmail.com with ESMTPSA id b17-20020a056830311100b006863ccbf067sm8077090ots.74.2023.02.01.09.05.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 01 Feb 2023 09:05:17 -0800 (PST) To: libc-alpha@sourceware.org, Richard Henderson , Noah Goldstein , Jeff Law , Xi Ruoyao Subject: [PATCH v11 26/29] string: Hook up the default implementation on test-stpcpy Date: Wed, 1 Feb 2023 14:04:03 -0300 Message-Id: <20230201170406.303978-27-adhemerval.zanella@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230201170406.303978-1-adhemerval.zanella@linaro.org> References: <20230201170406.303978-1-adhemerval.zanella@linaro.org> 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, 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: , X-Patchwork-Original-From: Adhemerval Zanella via Libc-alpha From: Adhemerval Zanella Netto Reply-To: Adhemerval Zanella Errors-To: libc-alpha-bounces+patchwork=sourceware.org@sourceware.org Sender: "Libc-alpha" --- string/test-stpcpy.c | 32 +++++++++++++++++++++----------- 1 file changed, 21 insertions(+), 11 deletions(-) Reviewed-by: Richard Henderson diff --git a/string/test-stpcpy.c b/string/test-stpcpy.c index c7a416f93a..5d344b6a23 100644 --- a/string/test-stpcpy.c +++ b/string/test-stpcpy.c @@ -26,26 +26,36 @@ #include "test-string.h" #ifndef WIDE # define CHAR char -# define SIMPLE_STPCPY simple_stpcpy # define STPCPY stpcpy #else # include # define CHAR wchar_t -# define SIMPLE_STPCPY simple_wcpcpy # define STPCPY wcpcpy #endif /* !WIDE */ -CHAR *SIMPLE_STPCPY (CHAR *, const CHAR *); - -IMPL (SIMPLE_STPCPY, 0) IMPL (STPCPY, 1) -CHAR * -SIMPLE_STPCPY (CHAR *dst, const CHAR *src) -{ - while ((*dst++ = *src++) != '\0'); - return dst - 1; -} +/* Also check the generic implementation. */ +#undef STPCPY +#undef weak_alias +#define weak_alias(a, b) +#undef libc_hidden_def +#define libc_hidden_def(a) +#undef libc_hidden_builtin_def +#define libc_hidden_builtin_def(a) +#undef attribute_hidden +#define attribute_hidden +#ifndef WIDE +# define STPCPY __stpcpy_default +# include "string/stpcpy.c" +IMPL (__stpcpy_default, 1) +#else +# define __wcslen wcslen +# define __wmemcpy wmemcpy +# define WCPCPY __wcpcpy_default +# include "wcsmbs/wcpcpy.c" +IMPL (__wcpcpy_default, 1) +#endif #undef CHAR #include "test-strcpy.c" From patchwork Wed Feb 1 17:04:04 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adhemerval Zanella Netto X-Patchwork-Id: 64112 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 D26D73850408 for ; Wed, 1 Feb 2023 17:09:49 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org D26D73850408 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1675271389; bh=fCZ5kyOC1eDtCiQTk6o9DXr/dvyLVONJ0Q+KRkDmCD4=; h=To:Subject:Date:In-Reply-To:References:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=vuTKZKDC4/j7e10CXKKHFRVWlOsBophXzPMRAonTKsmjfJ0pv6dGoCdbFrSqeVLxk G4+yTkj5CruMXDquphz/UabyThFxfm3DS4wT22wuGkE8XS9VD+APt6+FboipflhKEQ bzIXlyBKYs0PdPAzg6edmteeKrEAS02E66x3+Ydc= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-ot1-x32c.google.com (mail-ot1-x32c.google.com [IPv6:2607:f8b0:4864:20::32c]) by sourceware.org (Postfix) with ESMTPS id C407A3858407 for ; Wed, 1 Feb 2023 17:05:21 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org C407A3858407 Received: by mail-ot1-x32c.google.com with SMTP id k91-20020a9d19e4000000b0068bca1294aaso3478311otk.8 for ; Wed, 01 Feb 2023 09:05:21 -0800 (PST) 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:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=fCZ5kyOC1eDtCiQTk6o9DXr/dvyLVONJ0Q+KRkDmCD4=; b=WQn3tjJvIbQRmYVkiOtGbKokkWSwqZQu1WTWF3QLSoO2yxXp9vKsMDxF1tZtv0AjFM dQhRlSjEp6msHzdUzaxRIth/uGiaJ0+nDb+W3vamZnlQajCJNbInReiKvtqa+VIYlL0l AsL+3oZdPER7dxN9bnniob3Redax7Lp93/F/n4JeQenMmThk9rwD9iIHtGpC6TPm5GYV n8L3ox4/fPUz3CwVtdbubUbSvVy86285OlxcoDOxIX1aRvozS4DCbhnjLb5WT1Ey6Wsx LS/rEZENbH17dNIBXp2GPBGiE3T0hU7oSJkrGKxx9I8oL8uW2PiCmAqmJ9yFoEzvguQi l1vg== X-Gm-Message-State: AO0yUKUlfyaljxghgAuqygF89fclDQdpbvTWyg8tRrUZwUabQSsPdhiS WwSJGH+fHztXhMIKnOrztOvDaYDrfTAEfaEtdQs= X-Google-Smtp-Source: AK7set9w9zmfoseIPF+60r7F9G8Li4UP8xcSY7fjFVHOWCv+x9H+k6nA1BXzG+xz5LoomXSLgvZK4Q== X-Received: by 2002:a9d:7e8d:0:b0:68d:3fc8:7c13 with SMTP id m13-20020a9d7e8d000000b0068d3fc87c13mr915757otp.14.1675271120898; Wed, 01 Feb 2023 09:05:20 -0800 (PST) Received: from mandiga.. ([2804:1b3:a7c2:1887:d2ed:98c2:d2cc:bf06]) by smtp.gmail.com with ESMTPSA id b17-20020a056830311100b006863ccbf067sm8077090ots.74.2023.02.01.09.05.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 01 Feb 2023 09:05:20 -0800 (PST) To: libc-alpha@sourceware.org, Richard Henderson , Noah Goldstein , Jeff Law , Xi Ruoyao Subject: [PATCH v11 27/29] string: Hook up the default implementation on test-strcpy Date: Wed, 1 Feb 2023 14:04:04 -0300 Message-Id: <20230201170406.303978-28-adhemerval.zanella@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230201170406.303978-1-adhemerval.zanella@linaro.org> References: <20230201170406.303978-1-adhemerval.zanella@linaro.org> 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, 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: , X-Patchwork-Original-From: Adhemerval Zanella via Libc-alpha From: Adhemerval Zanella Netto Reply-To: Adhemerval Zanella Errors-To: libc-alpha-bounces+patchwork=sourceware.org@sourceware.org Sender: "Libc-alpha" --- string/test-strcpy.c | 34 ++++++++++++++++++++++++---------- 1 file changed, 24 insertions(+), 10 deletions(-) Reviewed-by: Richard Henderson diff --git a/string/test-strcpy.c b/string/test-strcpy.c index 8183c4b7f3..3e04c754d0 100644 --- a/string/test-strcpy.c +++ b/string/test-strcpy.c @@ -47,23 +47,37 @@ # endif # include "test-string.h" # ifndef WIDE -# define SIMPLE_STRCPY simple_strcpy # define STRCPY strcpy # else -# define SIMPLE_STRCPY simple_wcscpy # define STRCPY wcscpy # endif IMPL (STRCPY, 1) -/* Naive implementation to verify results. */ -CHAR * -SIMPLE_STRCPY (CHAR *dst, const CHAR *src) -{ - CHAR *ret = dst; - while ((*dst++ = *src++) != '\0'); - return ret; -} +/* Also check the generic implementation. */ +#undef STRCPY +#undef libc_hidden_builtin_def +#define libc_hidden_builtin_def(a) +#undef libc_hidden_def +#define libc_hidden_def(a) +#undef weak_alias +#define weak_alias(a,b) +#undef attribute_hidden +#define attribute_hidden +# ifndef WIDE +# define STPCPY __stpcpy_default +# include "string/stpcpy.c" +# define STRCPY __strcpy_default +# define __stpcpy __stpcpy_default +# include "string/strcpy.c" +IMPL (__strcpy_default, 1) +# else +# define __wcslen wcslen +# define __wmemcpy wmemcpy +# define WCSCPY __wcscpy_default +# include "wcsmbs/wcscpy.c" +IMPL (__wcscpy_default, 1) +# endif #endif typedef CHAR *(*proto_t) (CHAR *, const CHAR *); From patchwork Wed Feb 1 17:04:05 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adhemerval Zanella Netto X-Patchwork-Id: 64115 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 E2876385AC39 for ; Wed, 1 Feb 2023 17:11:58 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org E2876385AC39 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1675271518; bh=JRmZ2V3BqZ/QE9sTw/u6YDP8y8zkOWJrmkIgxVMn3T0=; h=To:Subject:Date:In-Reply-To:References:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=Nx2hV1tCkgt2DUi/08QVwUTsSyWBfitqthFrCvNpLgmV8f84NcbRDSYjV6YGxxWgx GMsuF1VMQstwWf6d1E0M1xMr/iwcNuPBhyBhLJK2WlvZmZAFseFlmGFHM9+A/F4fLw OEJjr31PyLIH5H/ss/6bE8y+VbmeIaL4pGYH4sIs= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-ot1-x32d.google.com (mail-ot1-x32d.google.com [IPv6:2607:f8b0:4864:20::32d]) by sourceware.org (Postfix) with ESMTPS id 493F9383FBA2 for ; Wed, 1 Feb 2023 17:05:24 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 493F9383FBA2 Received: by mail-ot1-x32d.google.com with SMTP id e12-20020a0568301e4c00b0068bc93e7e34so3545712otj.4 for ; Wed, 01 Feb 2023 09:05:24 -0800 (PST) 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:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=JRmZ2V3BqZ/QE9sTw/u6YDP8y8zkOWJrmkIgxVMn3T0=; b=3cZpXPvHsWVmzCvLCIGN06X79q+wPSlvmrWgGvb0FDMUAaK4kNisRbWMqppMZPlmry j6mmb4vgZTtgi8E68xPTu7KYjmTs9NNwyIIXn7+DA5x9Q/j1GGv2F8MpN07mz7X0BaCu iuxbrKwbyoryCpbBEfak3v8HSzA+jsTBt4a8+Tf1n7IweFHkZSrrhWIoZjS7vI+wWlAv RADvfzhuvc39dVhR4RtSQOuG/d08ghaWEAhxrmYyQL8SsiQ9bpV17/OQEAoBQ83bmHsQ fgZobpGrjGsMnxLKc2QX08k2s8yNvMfsyeS5NROUmyJsDVUv9UOAm16ENdGcwFPDfGgU +Jbw== X-Gm-Message-State: AO0yUKUdktOFUjbWiHYoR5CIb96JY/PymTPdIUUqwsijP02ZP5jofaK4 7SoIrGx2dTK424TFCwDI8DPpB0fI1dRWKEeMXRQ= X-Google-Smtp-Source: AK7set94mvPMAeFiN1l2RkoLPObIMtgRA31xh06SPzgK4rpFGnuCMPgRwx9jNTzx7E6wWzG11OhF6w== X-Received: by 2002:a05:6830:40a9:b0:68b:dddf:a26b with SMTP id x41-20020a05683040a900b0068bdddfa26bmr1523647ott.10.1675271123353; Wed, 01 Feb 2023 09:05:23 -0800 (PST) Received: from mandiga.. ([2804:1b3:a7c2:1887:d2ed:98c2:d2cc:bf06]) by smtp.gmail.com with ESMTPSA id b17-20020a056830311100b006863ccbf067sm8077090ots.74.2023.02.01.09.05.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 01 Feb 2023 09:05:22 -0800 (PST) To: libc-alpha@sourceware.org, Richard Henderson , Noah Goldstein , Jeff Law , Xi Ruoyao Subject: [PATCH v11 28/29] string: Hook up the default implementation on test-memchr Date: Wed, 1 Feb 2023 14:04:05 -0300 Message-Id: <20230201170406.303978-29-adhemerval.zanella@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230201170406.303978-1-adhemerval.zanella@linaro.org> References: <20230201170406.303978-1-adhemerval.zanella@linaro.org> 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, 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: , X-Patchwork-Original-From: Adhemerval Zanella via Libc-alpha From: Adhemerval Zanella Netto Reply-To: Adhemerval Zanella Errors-To: libc-alpha-bounces+patchwork=sourceware.org@sourceware.org Sender: "Libc-alpha" And remove SIMPLE_MEMCHR, which is not used anywhere. Reviewed-by: Richard Henderson --- string/test-memchr.c | 31 ++++++++++++++++++++----------- 1 file changed, 20 insertions(+), 11 deletions(-) diff --git a/string/test-memchr.c b/string/test-memchr.c index 862094ef0b..0daecab537 100644 --- a/string/test-memchr.c +++ b/string/test-memchr.c @@ -30,7 +30,6 @@ # define MEMCHR memchr # define CHAR char # define UCHAR unsigned char -# define SIMPLE_MEMCHR simple_memchr # define BIG_CHAR CHAR_MAX # define SMALL_CHAR 127 #else @@ -38,7 +37,6 @@ # define MEMCHR wmemchr # define CHAR wchar_t # define UCHAR wchar_t -# define SIMPLE_MEMCHR simple_wmemchr # define BIG_CHAR WCHAR_MAX # define SMALL_CHAR 1273 #endif /* WIDE */ @@ -47,15 +45,26 @@ typedef CHAR *(*proto_t) (const CHAR *, int, size_t); IMPL (MEMCHR, 1) -/* Naive implementation to verify results. */ -CHAR * -SIMPLE_MEMCHR (const CHAR *s, int c, size_t n) -{ - while (n--) - if (*s++ == (CHAR) c) - return (CHAR *) s - 1; - return NULL; -} +/* Also check the generic implementation. */ +#undef MEMCHR +#undef weak_alias +#define weak_alias(a, b) +#undef libc_hidden_builtin_def +#define libc_hidden_builtin_def(a) +#undef libc_hidden_def +#define libc_hidden_def(a) +#undef libc_hidden_weak +#define libc_hidden_weak(a) +#ifndef WIDE +# define MEMCHR __memchr_default +# include "string/memchr.c" +# define MEMCHR_DEFAULT MEMCHR +#else +# define WMEMCHR __wmemchr_default +# include "wcsmbs/wmemchr.c" +# define MEMCHR_DEFAULT WMEMCHR +#endif +IMPL (MEMCHR_DEFAULT, 1) static void do_one_test (impl_t *impl, const CHAR *s, int c, size_t n, CHAR *exp_res) From patchwork Wed Feb 1 17:04:06 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adhemerval Zanella Netto X-Patchwork-Id: 64116 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 5BBCE38983AF for ; Wed, 1 Feb 2023 17:12:40 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 5BBCE38983AF DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1675271560; bh=rglDjXE+jaOoHf6Yzx8QzLjp8wBin7SEfUmNHhpOLWc=; h=To:Subject:Date:In-Reply-To:References:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=k07GOlrdNZjd5Qe7NVyeBoV1fQZIV3wRXQITQmt4QJoXSm7akIgFIND8kuG0pkXk4 i3PDYwA2Zg7tMi2UEd5kINL5OZWIWbMD8w4nU+n4Tab8FB0R6P9dqelwnM9WIKQFLM 6rLtz2F/VuA/JbiCgDf8bK1FZFodGdztfBvg5Z+I= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-oi1-x233.google.com (mail-oi1-x233.google.com [IPv6:2607:f8b0:4864:20::233]) by sourceware.org (Postfix) with ESMTPS id 510EB3850401 for ; Wed, 1 Feb 2023 17:05:27 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 510EB3850401 Received: by mail-oi1-x233.google.com with SMTP id r9so16264185oig.12 for ; Wed, 01 Feb 2023 09:05:27 -0800 (PST) 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:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=rglDjXE+jaOoHf6Yzx8QzLjp8wBin7SEfUmNHhpOLWc=; b=x1qZ1UoraUYAJL4Zl5gpWVepMMNwYNB0t3jdj73Ak8aeErQ2/KQMTqj5DhmWEQWJ/7 pRPl647B3g3d+FuJDhh01+xu5LQ/zFr2XIROs9n1p87UTv+v0AdueUzVJazioNaTPUct AQeEkV9M/qKp6jI3p+f0k14kCRoqTj7cD2+YFF+7unAqVG0yd9kLYf96gDuzfhvCAYrb dCq1Hm0IXARk9A7ukhFDd5T4REgYnrvjfFFdA6UwD/p6zl7LlRqOIDmYQH/0cnyq1l1C MDBqIu9E5NRiMR/xXcZT/aQmT0AjyFpJS5z5N0QMivtgeUC7sk6dImcSLKza5mdfblDS o8pw== X-Gm-Message-State: AO0yUKUdzRMrR1P8PX2phtL3+VGQm7eWvXMFDYvLrfBSK/pifJ+KI/iA MpDAdvkjClouYP3OGxpTSG45WNV7mxS3KKscM2g= X-Google-Smtp-Source: AK7set9VSOb4Au7X2Jhvudl+aX3c9TtJD/tDx54Do0MN/nEq2xFX8RD6h4A7mdfqHKH/Sbwl4W9Q6w== X-Received: by 2002:aca:2310:0:b0:378:447d:bce1 with SMTP id e16-20020aca2310000000b00378447dbce1mr1567506oie.18.1675271125770; Wed, 01 Feb 2023 09:05:25 -0800 (PST) Received: from mandiga.. ([2804:1b3:a7c2:1887:d2ed:98c2:d2cc:bf06]) by smtp.gmail.com with ESMTPSA id b17-20020a056830311100b006863ccbf067sm8077090ots.74.2023.02.01.09.05.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 01 Feb 2023 09:05:25 -0800 (PST) To: libc-alpha@sourceware.org, Richard Henderson , Noah Goldstein , Jeff Law , Xi Ruoyao Subject: [PATCH v11 29/29] string: Hook up the default implementation on test-memrchr Date: Wed, 1 Feb 2023 14:04:06 -0300 Message-Id: <20230201170406.303978-30-adhemerval.zanella@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230201170406.303978-1-adhemerval.zanella@linaro.org> References: <20230201170406.303978-1-adhemerval.zanella@linaro.org> 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, 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: , X-Patchwork-Original-From: Adhemerval Zanella via Libc-alpha From: Adhemerval Zanella Netto Reply-To: Adhemerval Zanella Errors-To: libc-alpha-bounces+patchwork=sourceware.org@sourceware.org Sender: "Libc-alpha" --- string/test-memrchr.c | 7 +++++++ 1 file changed, 7 insertions(+) Reviewed-by: Richard Henderson diff --git a/string/test-memrchr.c b/string/test-memrchr.c index a4eac3592e..e4cba1878a 100644 --- a/string/test-memrchr.c +++ b/string/test-memrchr.c @@ -24,6 +24,13 @@ typedef char *(*proto_t) (const char *, int, size_t); IMPL (memrchr, 1) +/* Also check the generic implementation. */ +#undef weak_alias +#define weak_alias(a, b) +#define MEMRCHR __memrchr_default +#include "string/memrchr.c" +IMPL (__memrchr_default, 1) + /* Naive implementation to verify results. */ char * simple_memrchr (const char *s, int c, size_t n)