From patchwork Thu Feb 2 18:11:19 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: 64163 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 780193850408 for ; Thu, 2 Feb 2023 18:13:16 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 780193850408 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1675361596; 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=Gc6IqgqMc/d7sKH6qocz8q5Sg7I+vaA/WCwMY0ZN/wgQWgQLJQUIV0iVC/mc2DPcD 0dh+m1qIrOMFHHnVNNNanGP/I11M/bMp4Jx+SPhvZ6xg2JvhtQtbMV1i6jm4Hv0vE+ /2G4EtqfD1tpDHezTT/u27MQd8raiD85C7STMCiU= 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 CEF0C3858C20 for ; Thu, 2 Feb 2023 18:12:01 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org CEF0C3858C20 Received: by mail-ot1-x32d.google.com with SMTP id e21-20020a9d5615000000b006884e5dce99so692764oti.5 for ; Thu, 02 Feb 2023 10:12:01 -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=b/fckrQeOrEbmBh/t7RLk3Tz+el0T5sBkjKFsccJT9wdeQ+n5xmuGX86mp8VVC1EOb wW9zxZeYIaEXKdr4sti86cpCnZfO1p0S4vlZSWD+Xwlt8vcAA7Jd7FnuUzRg+iPC4b/m VCZ6z9+GTIHmiHQCWwome/V7GX6lWuXaFtpgaNBmuumYf5oNH7ti/OudnKUaCN9IXAYq QKUP2evw3axUnxzl5j9yYSQbXxxi7D5oaa5qwpZvRdQGCPkr1PAuLE/ETJFEePSj5ojM 0LD44niOJIAHMt0lcTncAFdDue9hXyXOHq71yh6p8k2TXfVH240GuUrFREi1LnWVM25X 5pWw== X-Gm-Message-State: AO0yUKVyLvLIWxMIFONGySe8llpjIa1wRgdcaf0AejtxDU7SfaGTKafi xBbUtSBeLdRuf4oen9IxXS5fQbl0mDpjDt8xF74= X-Google-Smtp-Source: AK7set983Qm5NpMBVcjt4nE4xK6r+VYo7aP4y91hCcK+Mv4FtqpXSksxT4s4XkQ1Mwk1ZboN23MzTg== X-Received: by 2002:a05:6830:1182:b0:68b:dd8b:6cd with SMTP id u2-20020a056830118200b0068bdd8b06cdmr3432061otq.7.1675361520390; Thu, 02 Feb 2023 10:12:00 -0800 (PST) Received: from mandiga.. ([2804:1b3:a7c2:1887:da12:b9d3:2162:a28c]) by smtp.gmail.com with ESMTPSA id ci10-20020a05683063ca00b00684a10970adsm126689otb.16.2023.02.02.10.11.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 02 Feb 2023 10:11:59 -0800 (PST) To: libc-alpha@sourceware.org, Richard Henderson , Jeff Law , Xi Ruoyao , Noah Goldstein Subject: [PATCH v12 01/31] Parameterize op_t from memcopy.h Date: Thu, 2 Feb 2023 15:11:19 -0300 Message-Id: <20230202181149.2181553-2-adhemerval.zanella@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230202181149.2181553-1-adhemerval.zanella@linaro.org> References: <20230202181149.2181553-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 Thu Feb 2 18:11:20 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: 64167 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 1D3203893679 for ; Thu, 2 Feb 2023 18:14:01 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 1D3203893679 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1675361641; 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=SsxS/AjuByjit1I/GPmx3+PQSQFsb9vlurZmypQ9PMatXkdc/Q2LG2nEzvBGDuRbZ KJmZ0KaaJi+tB0cvSH7n7ePl1qg4fmno1yQ21seRUw3ENpDBPGkDwMYORnbkjryKyx iGdudC0+OdSxFkk9KZ6tvZucTZUik5tmWiLN02XM= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-oa1-x2f.google.com (mail-oa1-x2f.google.com [IPv6:2001:4860:4864:20::2f]) by sourceware.org (Postfix) with ESMTPS id EBAFD385840D for ; Thu, 2 Feb 2023 18:12:05 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org EBAFD385840D Received: by mail-oa1-x2f.google.com with SMTP id 586e51a60fabf-1631b928691so3517539fac.11 for ; Thu, 02 Feb 2023 10:12:05 -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=GJ9xGqTjeWzEJUAVgv1IKPvqTiAdtIMT2XQ/ukOHcHYjtnJFDR6lrS6yDcCpXoRTD5 bHtE+arSU21rMkZeMimQRrya7Pqz8SgU0EPn1pjlO/nUjw0pdtKfOGfxuQzsKeBJSpy/ VL6PeqnChSiaclpA0JBg3hyek74bH1dPCt6l1sGkcN3aEwojk08Jq0l8BvgnYWBxchtH PQcATWme4A9X79uFHwJoRlOqxtMw3WQXJiMH+JcGoeDqOWre/xdtMXHtxUBqpYJmbPOi WJgvXn1laB541GTN+bCPzIWZOre/84gS3w7xC4Z9AVq0wGZKlCRmPBl53TzBxXVFlSDl e3aQ== X-Gm-Message-State: AO0yUKWSaBw5cckjAoUYAKHECzXkDdb9xmzUiVeJ/tODrGU+USHZlNi3 F+UmzwlW4Ch7Ndf3h4nTVJWpSXe88swOZnv73+4= X-Google-Smtp-Source: AK7set+guhkItG7MFrLsS8HUUOKBgDYzOOmNGpSmC1h9sOTkXJ08xXFJ/RNYgbeLCD2q8Np0OibTNw== X-Received: by 2002:a05:6871:721:b0:152:4c46:fa6c with SMTP id f33-20020a056871072100b001524c46fa6cmr3991349oap.17.1675361522774; Thu, 02 Feb 2023 10:12:02 -0800 (PST) Received: from mandiga.. ([2804:1b3:a7c2:1887:da12:b9d3:2162:a28c]) by smtp.gmail.com with ESMTPSA id ci10-20020a05683063ca00b00684a10970adsm126689otb.16.2023.02.02.10.12.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 02 Feb 2023 10:12:02 -0800 (PST) To: libc-alpha@sourceware.org, Richard Henderson , Jeff Law , Xi Ruoyao , Noah Goldstein Cc: Carlos O'Donell Subject: [PATCH v12 02/31] Parameterize OP_T_THRES from memcopy.h Date: Thu, 2 Feb 2023 15:11:20 -0300 Message-Id: <20230202181149.2181553-3-adhemerval.zanella@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230202181149.2181553-1-adhemerval.zanella@linaro.org> References: <20230202181149.2181553-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 Thu Feb 2 18:11:21 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: 64160 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 D25EB38654A4 for ; Thu, 2 Feb 2023 18:12:32 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org D25EB38654A4 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1675361552; bh=yhaXv7LjqjgqoD0ikszLObnHwJBs6U7RdQSObtk/Fo4=; 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=A2EG9K2UgcI1SfbvlkniYXbV0P062rABb3mMaSKFnCI5SnHQd30j+Tk29CwtUVtC8 Y91Sld0jjHL0HuZVq5bjzE9AF1gKPmBGqBmcQ9eSXN3WUcV4mg4bB8lzaZhP4TTKop mIYaLCwEkVl6L3Pghz39lSjaB08GhnCnmrzhQTgs= 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 B16803858C60 for ; Thu, 2 Feb 2023 18:12:06 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org B16803858C60 Received: by mail-ot1-x335.google.com with SMTP id g21-20020a9d6495000000b0068bb336141dso687407otl.11 for ; Thu, 02 Feb 2023 10:12:06 -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=yhaXv7LjqjgqoD0ikszLObnHwJBs6U7RdQSObtk/Fo4=; b=1O/mA8sil5iGP8F/VZCxUkAOdQS9SS1AXBgrtnLLsoAHN67/u7Hzyehu/SRLlzPE+i 348I96H1oFj3SBSx1G6/jpsEohkWs+nI3Tsz8T5X+fT8iFuKuSS6ccAdPIM7fxqQ7zZB rvrS+8ZA4z/LngX2+hNd+Pfb/SBgPbEIgKflhqYshyeA06xZMHmP8PfgbEmYYczGG1kn jXYO3ydsqycEiiN6Nwqm+BOZpN7uN9X5bJ+F+r+OvpEF+VcFYLLaB/NJ32Tq297jWpYT 5h21WVOfdpEG4AOHtW/L9xJsZj7uEo/+M3pVCU4CZGH1qMEFg3tZ6bJRRaIHLSeH0M4O 70ng== X-Gm-Message-State: AO0yUKWznyEZovhq8u6t5g/bcsCw1phFMu8qYHENvrtWN7ywiWl9dH+B Al3PjpbGNL+HbdQgY+Lb9AARO9NaWm+bzEqvBCI= X-Google-Smtp-Source: AK7set+eQz+2wTR/zkv31F4E5V7qNbrdeXEOyETksiZK9cWu2kfOfOuuGt4NVQ/gAtHJf82sVX35Ag== X-Received: by 2002:a9d:7f03:0:b0:68b:daba:9b2b with SMTP id j3-20020a9d7f03000000b0068bdaba9b2bmr3760073otq.13.1675361525084; Thu, 02 Feb 2023 10:12:05 -0800 (PST) Received: from mandiga.. ([2804:1b3:a7c2:1887:da12:b9d3:2162:a28c]) by smtp.gmail.com with ESMTPSA id ci10-20020a05683063ca00b00684a10970adsm126689otb.16.2023.02.02.10.12.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 02 Feb 2023 10:12:04 -0800 (PST) To: libc-alpha@sourceware.org, Richard Henderson , Jeff Law , Xi Ruoyao , Noah Goldstein Subject: [PATCH v12 03/31] Add string vectorized find and detection functions Date: Thu, 2 Feb 2023 15:11:21 -0300 Message-Id: <20230202181149.2181553-4-adhemerval.zanella@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230202181149.2181553-1-adhemerval.zanella@linaro.org> References: <20230202181149.2181553-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 Reviewed-by: Richard Henderson --- sysdeps/generic/string-fza.h | 104 +++++++++++++++++++++++++++++++++ sysdeps/generic/string-fzb.h | 49 ++++++++++++++++ sysdeps/generic/string-fzc.h | 83 ++++++++++++++++++++++++++ sysdeps/generic/string-fzi.h | 71 ++++++++++++++++++++++ sysdeps/generic/string-misc.h | 45 ++++++++++++++ sysdeps/generic/string-shift.h | 52 +++++++++++++++++ 6 files changed, 404 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..75b2bf884e --- /dev/null +++ b/sysdeps/generic/string-fzc.h @@ -0,0 +1,83 @@ +/* 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) +{ + return index_first (find_zero_ne_all (x1, x2)); +} + +/* Similarly, but search for the last zero within X. */ +static __always_inline unsigned int +index_last_zero (op_t x) +{ + return index_last (find_zero_all (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 Thu Feb 2 18:11:22 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: 64161 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 133353857B98 for ; Thu, 2 Feb 2023 18:12:37 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 133353857B98 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1675361557; bh=FpYQowWvQFK1aTVKlN5lV/5/t/qdEfaQ1HmjysyNPbI=; 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=rNiFnzJCjO145c+QL60Ojw5gony2WtZfJemaCakzHPz8skYNRY9I+mB8cXDeO5Abo ZRPl+3JqXsKHSiGUtwmpAAiWYQO+oTAyVIOQLT1OXn+VdnpywCWfHOQOLQrsI7Y1z8 PVmVBYSFah+mL3H2sA4xo5bnWl4d1P6+9P+kEblo= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-oi1-x22c.google.com (mail-oi1-x22c.google.com [IPv6:2607:f8b0:4864:20::22c]) by sourceware.org (Postfix) with ESMTPS id 9DB6B3858C3A for ; Thu, 2 Feb 2023 18:12:10 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 9DB6B3858C3A Received: by mail-oi1-x22c.google.com with SMTP id r9so2109280oig.12 for ; Thu, 02 Feb 2023 10:12: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=FpYQowWvQFK1aTVKlN5lV/5/t/qdEfaQ1HmjysyNPbI=; b=B/7tdUA/2Z9DSLDrnScNcUJqQcVEi8F1lsqiXjNaCHNJNtkwyLoFw/LYOaOMV2fo3F L8NxRRSQf/kyDZ04UqeUp5Se3W8RacKM8KHeg+mrtBWDAl7akZwRdUwzVM50uS5syHH5 lmY/Xzh5slCKsQ+q2tVGWOd2G3jMV5hwrOSZ7QowjWoWoEatR+HjpjF8v+p8yYe3VOw1 iqnojf9cZIdcYsamh5XQjC1ZKcLzQIjq0i01i/H9UsV3A+CKuMpo8vG0uYGyuM+N7gDE XH+MPW0ghlxNUB1e4uGxKsR4PPZHtvBVI59bghTpFrXkKBu5vILp5OuS3z+Ual5k/KXY ek8g== X-Gm-Message-State: AO0yUKU3VZaB3ZXvPV008UGovgXlO6zSCbgHUGN7DMgIxlgWE56bz45S KCCLRYwqSZGBE9BlvpYtnuEdPtRFpPxTPWpUlSw= X-Google-Smtp-Source: AK7set+00iNSpuq4nmvLBxz0qdE1u97xmk0EJA/frmUiwtwGz/lg49CDJ+2modrwBEpEtpA239/TVA== X-Received: by 2002:a05:6808:8f5:b0:35b:e81d:285b with SMTP id d21-20020a05680808f500b0035be81d285bmr1230350oic.28.1675361527380; Thu, 02 Feb 2023 10:12:07 -0800 (PST) Received: from mandiga.. ([2804:1b3:a7c2:1887:da12:b9d3:2162:a28c]) by smtp.gmail.com with ESMTPSA id ci10-20020a05683063ca00b00684a10970adsm126689otb.16.2023.02.02.10.12.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 02 Feb 2023 10:12:06 -0800 (PST) To: libc-alpha@sourceware.org, Richard Henderson , Jeff Law , Xi Ruoyao , Noah Goldstein Subject: [PATCH v12 04/31] string: Improve generic strlen Date: Thu, 2 Feb 2023 15:11:22 -0300 Message-Id: <20230202181149.2181553-5-adhemerval.zanella@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230202181149.2181553-1-adhemerval.zanella@linaro.org> References: <20230202181149.2181553-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 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 Thu Feb 2 18:11:23 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: 64162 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 5ABEF38708F5 for ; Thu, 2 Feb 2023 18:12:43 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 5ABEF38708F5 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1675361563; bh=oXs45FA6nyUHujHuSEtxBV5sVi+ayKwCFcFW4lFwlSY=; 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=YNH5GsFjd2e3HA4jROtlbqvo48OJh5cnrJ5pEVctCm7UhhDYc0PqjyRuGz8tZGW+T N8inBVaf/cZz7lEYq9/xYLEPodeWb6On7mTKTZRgwJNvQxanynF4ynmG4u/93UWKc8 w7Ze2Gr1HsjaJ5CiylQSAOt55MsSvcxaUkTqI5JI= 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 2BB0B3858416 for ; Thu, 2 Feb 2023 18:12:11 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 2BB0B3858416 Received: by mail-ot1-x330.google.com with SMTP id d21-20020a056830005500b0068bd2e0b25bso698753otp.1 for ; Thu, 02 Feb 2023 10:12:11 -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=oXs45FA6nyUHujHuSEtxBV5sVi+ayKwCFcFW4lFwlSY=; b=gQ63FJke8XT/5Nlk3HaRljzEBk6ZxndGmqePLfeB9iC+SCGSBba/5nHYGDbllCmsUL eH/B74VM1/1BXDH1PSfDbO1IE0PnOpKflVWXqhmf3IRssyoY2/U6GGBHURMxi0xEjA4+ VpX2DER8tPrFRZULO9jzU6IXx4Xmqtf/ArLh7ZsfuTAZWbpduXydzZSKy2M2178aqlfB iq6MnPg/V4oZUtf0/PiEv49pnSYGdS7TkD3pLRdbwLLpFFYMq8cEkB/oQh4uJNljz5YO YxyT1ti1tWc19jtOsq7DX3uVpXZalwmMED+OKnVgdxsJEDMWcDlYSKwY0vL6PPLsxTBs pFsQ== X-Gm-Message-State: AO0yUKUdtTiI/rxfzwHE3ZAKl3CAimXmIzsiZCVolC925EJUfB18NxOl E++3zkML3K8OuoRTbW1iMr+0sMycpyP6IM1rb80= X-Google-Smtp-Source: AK7set+PidC4e2LNUtwXbajv7cfNlPC/6G2n0kTU7OP4+y+rx+hmcPXaJhz1qygysCDr7YozJqENmA== X-Received: by 2002:a05:6830:2b1f:b0:68b:ba12:424d with SMTP id l31-20020a0568302b1f00b0068bba12424dmr5442741otv.29.1675361529504; Thu, 02 Feb 2023 10:12:09 -0800 (PST) Received: from mandiga.. ([2804:1b3:a7c2:1887:da12:b9d3:2162:a28c]) by smtp.gmail.com with ESMTPSA id ci10-20020a05683063ca00b00684a10970adsm126689otb.16.2023.02.02.10.12.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 02 Feb 2023 10:12:08 -0800 (PST) To: libc-alpha@sourceware.org, Richard Henderson , Jeff Law , Xi Ruoyao , Noah Goldstein Subject: [PATCH v12 05/31] string: Improve generic strchrnul Date: Thu, 2 Feb 2023 15:11:23 -0300 Message-Id: <20230202181149.2181553-6-adhemerval.zanella@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230202181149.2181553-1-adhemerval.zanella@linaro.org> References: <20230202181149.2181553-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_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 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 Thu Feb 2 18:11:24 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: 64166 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 20341385802F for ; Thu, 2 Feb 2023 18:13:33 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 20341385802F DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1675361613; bh=YMWiuPyw80vAt+Bi7GyXNMkeJTMXUqNtraZzrN0Hd/g=; 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=xggzPT8x2JL5R85YmwYdqW0HgmByWRk02IuySZPF9Zk5RKykBGpq2++Z0aOsM8ISZ nEy499i2aeMXpoG213EsTaMapRrZmf0Rg6G7tJiF7NXN8H1pzjM2QU55+URqOXVI3E 5P4Hc3O1HTFIYMALTvSVJM6bnUwCo7Wbn5/VHsyo= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-ot1-x336.google.com (mail-ot1-x336.google.com [IPv6:2607:f8b0:4864:20::336]) by sourceware.org (Postfix) with ESMTPS id 1684E3858428 for ; Thu, 2 Feb 2023 18:12:13 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 1684E3858428 Received: by mail-ot1-x336.google.com with SMTP id v24-20020a05683011d800b0068bdd29b160so680935otq.13 for ; Thu, 02 Feb 2023 10:12:13 -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=YMWiuPyw80vAt+Bi7GyXNMkeJTMXUqNtraZzrN0Hd/g=; b=ufjRK7546DwKK66+kwNQpssPrOalBbgyQmeVJ4apfCSoEwE9foUM8FGajvgAmghjLX hJJeqIEIobRNzOLYwOLtSmxsmerHYJTJZwCy5l1dedHBhRW7oRX3EuQIm7zsirCgkS5S qNebOKK9kdZz4LN4Z3REWkgYOFlhCqRaRGJeS9Q+tH7KAD258klad0yWTNaIwOoekUgn 6SPB9HsVCY39Xqe4KBUbMvVMKFTZipP2vGh4thVJR+txnCgHgGbSjyJ7iXnqdmZKfUC0 ZLNmQOXqCpKr4VFjxioubXn9UWNOs0qHASedP+5BsdilGAJ7biIw0UoTVtJfuUsnit+Q XHmA== X-Gm-Message-State: AO0yUKX1VtpMOKtq0KrXzOC8npsvYznMEIoo+pWmz9WHu6GIK11KGb6U wG0jiCGQ8llb7zWqVtPYugnGL7nT7Z2NuVNSr3w= X-Google-Smtp-Source: AK7set/KnC9YjSl2w9TzAucql8jGcsBFKFwVIg/fNTNFWf3VhnFVtaPsq/m7jl+AvhwIAwp1xqu8EA== X-Received: by 2002:a9d:6749:0:b0:684:c723:539c with SMTP id w9-20020a9d6749000000b00684c723539cmr3545720otm.35.1675361531772; Thu, 02 Feb 2023 10:12:11 -0800 (PST) Received: from mandiga.. ([2804:1b3:a7c2:1887:da12:b9d3:2162:a28c]) by smtp.gmail.com with ESMTPSA id ci10-20020a05683063ca00b00684a10970adsm126689otb.16.2023.02.02.10.12.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 02 Feb 2023 10:12:11 -0800 (PST) To: libc-alpha@sourceware.org, Richard Henderson , Jeff Law , Xi Ruoyao , Noah Goldstein Subject: [PATCH v12 06/31] string: Improve generic strchr Date: Thu, 2 Feb 2023 15:11:24 -0300 Message-Id: <20230202181149.2181553-7-adhemerval.zanella@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230202181149.2181553-1-adhemerval.zanella@linaro.org> References: <20230202181149.2181553-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 Reviewed-by: Noah Goldstein --- string/strchr.c | 164 ++-------------------------------------- sysdeps/s390/strchr-c.c | 11 +-- 2 files changed, 14 insertions(+), 161 deletions(-) diff --git a/string/strchr.c b/string/strchr.c index 1572b8b42e..90ae0b69fc 100644 --- a/string/strchr.c +++ b/string/strchr.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 @@ -21,165 +16,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 Thu Feb 2 18:11:25 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: 64170 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 AAF443895FDF for ; Thu, 2 Feb 2023 18:14:15 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org AAF443895FDF DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1675361655; bh=T9gYAWKa3f2//8Q5aHVbt5Ox2BgkxovC2xqWRMVWBZo=; 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=V87Xb3hb1TL8WbHHhbsMua+CJeoFsvshx8YHPnxo9UuYhHtyHghRbChADyE8T629R HdEDKgjv/mWq478JptNyLuRojavlVpD0KJYFzsSSGFutFEaiqOfxTZ0iTpbO1ymj8z gSe6kDgGYut1fYgNdXfnq0nb1lOP1d+HDT/KSdQs= 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 769453857352 for ; Thu, 2 Feb 2023 18:12:15 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 769453857352 Received: by mail-oi1-x22d.google.com with SMTP id dt8so2173952oib.0 for ; Thu, 02 Feb 2023 10:12: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=T9gYAWKa3f2//8Q5aHVbt5Ox2BgkxovC2xqWRMVWBZo=; b=LrmMFeXhtnxCAxhbWGZFN5xopX7Ujmq6OizbOkhk2RUaIAuaOAY7i+t6CRXOfAfdlM Hq83UvT3Gspn72XZVC8ALlZ5bW/R+YhKxGDTPZr67m88hVJ5B43PK/R0B8IAL3W7vLYp oTARf/aImQyEtyokvs7nAfEIVaQbtz03qKnJgpAshWfx1pj5DfCFC2SDEQAxEbkcR5QB I9p9aZDeD5l5MuWb0NvM3f4oJgrZAn4E3+zBo8XwfqzlgQkqReCg9iJVHD48uAe6Ah6v SaRiL0iEtOyHekdxh61ddZdkbcMsBzNIJIPkCi2WzoVzBNf8uUzwduvaxRenFVkJCvqw 5JqA== X-Gm-Message-State: AO0yUKWAJ+pyoN3bBKAzH4EEBzkiEIHkXvt80uOObofsyCXdAdovMJOn KNbieS16gC/sPIJaVULCHniJyVP3ZFGsKaQPEbc= X-Google-Smtp-Source: AK7set8J/8W4V9pZTirSOoilpE8C1paPrOWW8bOVSmWoKuVnnBuy5W1S/mfkODcyD1K9yxEFoABcwQ== X-Received: by 2002:a05:6808:14c7:b0:367:6c7:ba8d with SMTP id f7-20020a05680814c700b0036706c7ba8dmr2481357oiw.26.1675361533958; Thu, 02 Feb 2023 10:12:13 -0800 (PST) Received: from mandiga.. ([2804:1b3:a7c2:1887:da12:b9d3:2162:a28c]) by smtp.gmail.com with ESMTPSA id ci10-20020a05683063ca00b00684a10970adsm126689otb.16.2023.02.02.10.12.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 02 Feb 2023 10:12:13 -0800 (PST) To: libc-alpha@sourceware.org, Richard Henderson , Jeff Law , Xi Ruoyao , Noah Goldstein Subject: [PATCH v12 07/31] string: Improve generic strcmp Date: Thu, 2 Feb 2023 15:11:25 -0300 Message-Id: <20230202181149.2181553-8-adhemerval.zanella@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230202181149.2181553-1-adhemerval.zanella@linaro.org> References: <20230202181149.2181553-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 Reviewed-by: Noah Goldstein --- string/strcmp.c | 110 +++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 94 insertions(+), 16 deletions(-) diff --git a/string/strcmp.c b/string/strcmp.c index 053f5a8d2b..11ec8bac81 100644 --- a/string/strcmp.c +++ b/string/strcmp.c @@ -15,33 +15,111 @@ License along with the GNU C Library; if not, see . */ +#include +#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) +{ + unsigned int idx = index_first_zero_ne (w1, w2); + return extractbyte (w1, idx) - extractbyte (w2, idx); +} + +/* 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 Thu Feb 2 18:11:26 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: 64174 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 4639838AA241 for ; Thu, 2 Feb 2023 18:14:57 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 4639838AA241 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1675361697; bh=a/Zspv675rhfTQmqLMxUF+7k75/mM3dVzA7D6r+lHKo=; 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=xkg1BoKY5FuPKj/+G45T9gZiFpLbdNkrN6sPQByf7xvWhkpYTSXaTSsqtf6AizKYO Fmyy7hg41Ltb9Xj4KaAN0DJq6wlta96LH7XNUml9MKZ7kS+vpKrAgZToD06pejm6Ov ItxPyIdf1sSzPvA0f29PbWYazvF1U+Q0kG24DThU= 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 53A413857C5A for ; Thu, 2 Feb 2023 18:12:17 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 53A413857C5A Received: by mail-ot1-x330.google.com with SMTP id d21-20020a056830005500b0068bd2e0b25bso698862otp.1 for ; Thu, 02 Feb 2023 10:12: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=a/Zspv675rhfTQmqLMxUF+7k75/mM3dVzA7D6r+lHKo=; b=2I30iGRFowYOrJOADGkveqO6HX9CpFX4Q0SoUJO/jCDcigbWJnO/ibxqig6YrLVMBR kSdADdoHP7uQLN3XOooXrCB3Z5qSts/6vNCl86DRYjZr+1AcjAXBwAalrQLhk7TCmyM0 733gcZEbAeb+FI9uFBuGAK8kaPUvqAtVwRXa24PY8wW+M1bEUM7f24uAQuZ45KtiaThI AG6sFfdW82YEQ26Lj894p1NjRD9ciTQDsAvXIVjyAbh9dJR18HpnkvxtCUQoKPyNl3r0 S9oh9Y+05HCNS2upmJx4JA1J/WTOuMXtoDLux3UMROBSDnraJ/tT5Kf8Jy4c1dIQxZgP S3tw== X-Gm-Message-State: AO0yUKVrcTK1LMUU7KT/hLkP7xU9fewnZ9Vn8ThhaBQKeWzKfw0OZypD 27eCr9lGEvuloVh6S2MalRjtU8nSf1kfV+Lwy4s= X-Google-Smtp-Source: AK7set94uvwLU4CpGdllbT16hp2j+BdPPD5Yx/N5JdfgcI8YAmFLIZCqPhJOitWZpbButLU3SMy9Hg== X-Received: by 2002:a05:6830:4803:b0:68b:a341:b93b with SMTP id dg3-20020a056830480300b0068ba341b93bmr3242179otb.36.1675361536308; Thu, 02 Feb 2023 10:12:16 -0800 (PST) Received: from mandiga.. ([2804:1b3:a7c2:1887:da12:b9d3:2162:a28c]) by smtp.gmail.com with ESMTPSA id ci10-20020a05683063ca00b00684a10970adsm126689otb.16.2023.02.02.10.12.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 02 Feb 2023 10:12:15 -0800 (PST) To: libc-alpha@sourceware.org, Richard Henderson , Jeff Law , Xi Ruoyao , Noah Goldstein Subject: [PATCH v12 08/31] string: Improve generic strncmp Date: Thu, 2 Feb 2023 15:11:26 -0300 Message-Id: <20230202181149.2181553-9-adhemerval.zanella@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230202181149.2181553-1-adhemerval.zanella@linaro.org> References: <20230202181149.2181553-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). Reviewed-by: Richard Henderson --- string/strncmp.c | 138 ++++++++++++++++++++++++++++++++++------------- 1 file changed, 101 insertions(+), 37 deletions(-) diff --git a/string/strncmp.c b/string/strncmp.c index fd7cee09b6..4c8bf36bb9 100644 --- a/string/strncmp.c +++ b/string/strncmp.c @@ -15,7 +15,12 @@ License along with the GNU C Library; if not, see . */ +#include +#include +#include +#include #include +#include #include #undef strncmp @@ -24,51 +29,110 @@ #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) +static inline int +final_cmp (const op_t w1, const op_t w2, size_t n) +{ + unsigned int idx = index_first_zero_ne (w1, w2); + if (n <= idx) + return 0; + return extractbyte (w1, idx) - extractbyte (w2, idx); +} + +/* 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 0; + + /* 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 Thu Feb 2 18:11:27 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: 64178 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 62DCA3947426 for ; Thu, 2 Feb 2023 18:15:39 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 62DCA3947426 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1675361739; bh=5avUm1yomjyzJDaEa3GoJBqoNeKtiA3G3u3KIcclhSM=; 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=LAMXVUUFKj+mdNn/LnzRNid6Ccp+omisLOKz2Ky75P82gxU/qKAJf76GKRKXiLrZ2 9k0irLdIfovKI/JyIlY05TGKz1HyfWusyeV/fmN4YThbtBvxV2kqA30sJ/XbAiLANT K6h2uWU3+pcqqKyzSDFimEAmdKfiU2d36QxRN7QQ= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-ot1-x336.google.com (mail-ot1-x336.google.com [IPv6:2607:f8b0:4864:20::336]) by sourceware.org (Postfix) with ESMTPS id E07CA3856975 for ; Thu, 2 Feb 2023 18:12:19 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org E07CA3856975 Received: by mail-ot1-x336.google.com with SMTP id p24-20020a056830131800b0068d4b30536aso688454otq.9 for ; Thu, 02 Feb 2023 10:12: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=5avUm1yomjyzJDaEa3GoJBqoNeKtiA3G3u3KIcclhSM=; b=fBqLNNACVczUQ6dvFRZCSdh7rKw7Sv0nyrTPowaIKpikT/OL+2m2aD69+wlrSXng/b nS33K6WU9UEBwvWLpja/D48Vf1bW03vLKSHNmAhPBO6kmN+HtUIFv+KSIYvVqjC6jJnw fd0a5JJXQXoSuJ11+/NHpFj6Lro7dKnwpNOmmXFCiIpQp31z5UNxK6IBU3edhL1J7RJY M4uSyigMxjcGTrZavoXrtBvPgOfQOcDwktR2NaegX4yue3TQoPbLqtO2humf2GS4afJ3 /5Gop0eN/L4AYKCj5aVTKj0llxKJQgbRJz63MEO/ukV0U2ipxus5lRPCzyET3/A7y88g D0pw== X-Gm-Message-State: AO0yUKXGIMNcY+ViI9KDXywR7JxJuEziA1YAnQwLk87SEodixbItD7Jx OSSaiFAbllt9FzrZc+oWmwmJ+OK0QNoARqK8Qeg= X-Google-Smtp-Source: AK7set9ZFw+U7UtK0XSLbJRPkQ4NbkooJOR6t8I9jJ3kp5UygiU0rLU6Y3E8k+YuEclbZzUpeifesQ== X-Received: by 2002:a05:6830:3b86:b0:68b:e3cf:2967 with SMTP id dm6-20020a0568303b8600b0068be3cf2967mr3308655otb.29.1675361538701; Thu, 02 Feb 2023 10:12:18 -0800 (PST) Received: from mandiga.. ([2804:1b3:a7c2:1887:da12:b9d3:2162:a28c]) by smtp.gmail.com with ESMTPSA id ci10-20020a05683063ca00b00684a10970adsm126689otb.16.2023.02.02.10.12.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 02 Feb 2023 10:12:17 -0800 (PST) To: libc-alpha@sourceware.org, Richard Henderson , Jeff Law , Xi Ruoyao , Noah Goldstein Subject: [PATCH v12 09/31] string: Improve generic stpcpy Date: Thu, 2 Feb 2023 15:11:27 -0300 Message-Id: <20230202181149.2181553-10-adhemerval.zanella@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230202181149.2181553-1-adhemerval.zanella@linaro.org> References: <20230202181149.2181553-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 Reviewed-by: Noah Goldstein --- 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 Thu Feb 2 18:11:28 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: 64164 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 ACFFA385802F for ; Thu, 2 Feb 2023 18:13:22 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org ACFFA385802F DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1675361602; bh=bSd7SA8Na6FigOWp4XOKr27O+fBOT5QrDyAGCcSMAVw=; 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=n+KL2WGnQR66I9F1QHjbqqHrnw8yKQ+n2Ccd2xfoPNmmIHpUwvuVPL14DfNpsmxBO OZe8pCqcr0zSDToZMtvNn0GytluZg+FGvxDNRQgENkBTUxRdBfj6UNLFIVf6St1kmS PaSEBK6oHFo7/1buRNFx8DHPyL+m2Ert5vTtZwOs= 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 32FC7385B53B for ; Thu, 2 Feb 2023 18:12:22 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 32FC7385B53B Received: by mail-ot1-x334.google.com with SMTP id 14-20020a9d010e000000b0068bdddfa263so695931otu.2 for ; Thu, 02 Feb 2023 10:12:22 -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=bSd7SA8Na6FigOWp4XOKr27O+fBOT5QrDyAGCcSMAVw=; b=NInKU7DGzjer04h7BCTSK5IZsjn/CxQfSA59cjWjB4Mk+y1IQluOUUddf65QphHr8v rOtzLQ0JERd/8wsmNi7M/ycMlTgpKwbWUuucIIZCkW1XVWhfPivd7zMBL1kuorw5yNHJ R/RytFEHbZfCIofNscHnsI+ZjL+d6A6okXqxqckkpoSTeI3HqVA5eaKdCW2Wyni2aqBv edZuRe19WUko8PnMTZa+3m9uT49GH7ATfL0bIk0qN6KS0jnEN4kapv/nYngkUgsfZaZ6 kcBGzLsx9p5fBP1MAo9DaWtMmzTZm6KPtNCXpb7qToHUCTE+L5fIoTxwnPJgZmQ40cRl qE7w== X-Gm-Message-State: AO0yUKV3O5FLyra8/eyDOLyVy0T6s9Jl/Ovk256axaqV4u1sQh//27xt YTJ/XkZPy1RnZXGD/rLzgguXoZ4J16wOGnZ/+J0= X-Google-Smtp-Source: AK7set/FQ4RSyGafLQ36j9IM+43gsAzTuYpkGi/46WEeAhpVDiX3ObyZynMjMHhPGIGZsIUybhT7FA== X-Received: by 2002:a9d:841:0:b0:68b:cec3:7fe5 with SMTP id 59-20020a9d0841000000b0068bcec37fe5mr4544923oty.4.1675361540996; Thu, 02 Feb 2023 10:12:20 -0800 (PST) Received: from mandiga.. ([2804:1b3:a7c2:1887:da12:b9d3:2162:a28c]) by smtp.gmail.com with ESMTPSA id ci10-20020a05683063ca00b00684a10970adsm126689otb.16.2023.02.02.10.12.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 02 Feb 2023 10:12:20 -0800 (PST) To: libc-alpha@sourceware.org, Richard Henderson , Jeff Law , Xi Ruoyao , Noah Goldstein Subject: [PATCH v12 10/31] string: Improve generic strcpy Date: Thu, 2 Feb 2023 15:11:28 -0300 Message-Id: <20230202181149.2181553-11-adhemerval.zanella@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230202181149.2181553-1-adhemerval.zanella@linaro.org> References: <20230202181149.2181553-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, 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 Reviewed-by: Noah Goldstein --- 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 Thu Feb 2 18:11:29 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: 64168 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 484E43894C04 for ; Thu, 2 Feb 2023 18:14:05 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 484E43894C04 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1675361645; bh=Hq+8ZvNSfJ7ySgnTJMywy4nixCEK/WHKYTKluA2XoCE=; 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=EkHutF5YS88RF4OcPBVL0qGENL7dU4OpWuJokxkxWHQzpCu9pbzplMMKci+oErcWw xh/o8XrRyWCGbFNJFEGgLVXS135esS2noKoK5Han570EpjcAONE0xeKyY4glulv3IG thM9H8v/+rVgbz1ZvLhR4fHptzHkWU9m1pMnn78c= 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 51A1E385B532 for ; Thu, 2 Feb 2023 18:12:24 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 51A1E385B532 Received: by mail-ot1-x32d.google.com with SMTP id e21-20020a9d5615000000b006884e5dce99so693071oti.5 for ; Thu, 02 Feb 2023 10:12: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=Hq+8ZvNSfJ7ySgnTJMywy4nixCEK/WHKYTKluA2XoCE=; b=GIq5ehL/So6V3p18OxYeMhwbarRKxcAWOW/z88NPAQxL4y7TL+zvbvShPvau6yc0X+ 71Qcv3h2LSUciGtEsdwpG5JRnDlDzMJGRz+L7zG4bc50vywdVx9yiH9TDbDXQ+PXMion gRSA6j6+A1ixqfLWQwDkHmP7t7rEgjsmb1oArJSlvBGi+IrzzHidWLZjSjjUjaPhaq/a tmioi4bdYnuXk/ZjSQYPoC8QObQ1661AhNvcO9F+t6OAK+7pVwyHRgq/ziHAv/SWHf0Z pJWJdMMAGncBwf+iQ6963r8l5CPc6JDhMErduM5hvXFMQauMO07yjpyEEjs9TumhjeS1 B67A== X-Gm-Message-State: AO0yUKVpaVSl9anD6nivy3hyynvR3BIBQ5smZVxlhmd49RZEbnmszugP ZObUM09ARIu1hvZ0cylRNWDofc0erHP2BwQhLN0= X-Google-Smtp-Source: AK7set/NwBP5y4N0XMXANQD3Y02sMPjD4omXgBKT7SpqS6p0W+UPJDvyw7Awoh2CFHvoWGYMHUs8FQ== X-Received: by 2002:a9d:1b27:0:b0:68b:dd09:2b6 with SMTP id l36-20020a9d1b27000000b0068bdd0902b6mr4260285otl.25.1675361543270; Thu, 02 Feb 2023 10:12:23 -0800 (PST) Received: from mandiga.. ([2804:1b3:a7c2:1887:da12:b9d3:2162:a28c]) by smtp.gmail.com with ESMTPSA id ci10-20020a05683063ca00b00684a10970adsm126689otb.16.2023.02.02.10.12.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 02 Feb 2023 10:12:22 -0800 (PST) To: libc-alpha@sourceware.org, Richard Henderson , Jeff Law , Xi Ruoyao , Noah Goldstein Subject: [PATCH v12 11/31] string: Improve generic memchr Date: Thu, 2 Feb 2023 15:11:29 -0300 Message-Id: <20230202181149.2181553-12-adhemerval.zanella@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230202181149.2181553-1-adhemerval.zanella@linaro.org> References: <20230202181149.2181553-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 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 Thu Feb 2 18:11:30 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: 64165 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 768FC388551C for ; Thu, 2 Feb 2023 18:13:30 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 768FC388551C DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1675361610; 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=ekAx2Xa+qgi7DGknNKMChHzi7JUJFyI5MGjreaN5N8SxhHivwOTzJ5XZGT/ErFrTT AvEQv/wDgzg0tbWli7L0jwi3tnh2UKf1JKf6S6h0Ll/XP1hdX6zgBtiEm6PYnRPoQZ 5cxMSJx3ftjoi3+13WYUTdq9IrfZemgs0w+Ly2oI= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-ot1-x336.google.com (mail-ot1-x336.google.com [IPv6:2607:f8b0:4864:20::336]) by sourceware.org (Postfix) with ESMTPS id 78230385558F for ; Thu, 2 Feb 2023 18:12:26 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 78230385558F Received: by mail-ot1-x336.google.com with SMTP id v24-20020a05683011d800b0068bdd29b160so681174otq.13 for ; Thu, 02 Feb 2023 10:12:26 -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=iABmvn9/2NuT8So+g6rxW1XYR3rcOIcLK59RWwQSaXdVeog0/fwfLVrkXOfr6U4rsh lsFFKhdUaTb7k18fEV7KnNJlpOaa2ka227kQoOY3YFnq3r8r3Ob2jkoIOPNxn0vgCYEa 3dp40WSwO4IeTEQOmPWQePx+wMldTfn2g17vA6Iduz8GB/Fdr8rCN8PggysoWMFVcZpe u4b9P+Pxir40lJ8zeVm2mzOZfJL0T2Oco3HJwDta3NTd0/tccj/ya388kwkhYaPbtoUi OOlNpDwAO0a7cq00XEuqWyfjIxvI78MTPwOZD3OJfCuqbtkMh4WogN7SS2kUwDCgcIMo 1LXA== X-Gm-Message-State: AO0yUKVxv9vPWgSTVrCghLt06j85mECSzY4TB18al/BHDlSmmp/xgKA4 RHnb14tasBN46GH/eN5x8nGITBY2UYsCw3Dpmt8= X-Google-Smtp-Source: AK7set/mL0YFSRk/MmeEVCzdKDShTb5Wov1Xo+H1JZ1yJUsbcgW4KjMgIOWEAf77AP0m2f9WdPEKfA== X-Received: by 2002:a9d:7f8d:0:b0:68b:e2a2:6e8c with SMTP id t13-20020a9d7f8d000000b0068be2a26e8cmr1171701otp.30.1675361545591; Thu, 02 Feb 2023 10:12:25 -0800 (PST) Received: from mandiga.. ([2804:1b3:a7c2:1887:da12:b9d3:2162:a28c]) by smtp.gmail.com with ESMTPSA id ci10-20020a05683063ca00b00684a10970adsm126689otb.16.2023.02.02.10.12.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 02 Feb 2023 10:12:24 -0800 (PST) To: libc-alpha@sourceware.org, Richard Henderson , Jeff Law , Xi Ruoyao , Noah Goldstein Subject: [PATCH v12 12/31] string: Improve generic strnlen with memchr Date: Thu, 2 Feb 2023 15:11:30 -0300 Message-Id: <20230202181149.2181553-13-adhemerval.zanella@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230202181149.2181553-1-adhemerval.zanella@linaro.org> References: <20230202181149.2181553-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 also cleanups the multiple inclusion by leaving the ifunc implementation to undef the weak_alias and libc_hidden_def. Co-authored-by: Richard Henderson Reviewed-by: Noah Goldstein --- 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 Thu Feb 2 18:11:31 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: 64171 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 568FA389941E for ; Thu, 2 Feb 2023 18:14:47 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 568FA389941E DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1675361687; bh=COPxbgjL39E/wVSr7EMR7qQRWVOBOB4Zqco28tqWNDU=; 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=I0xUtKY1AWqw2VTLMyzKy/hg+H4dQgPUjc3f42FepStCa/S3pudKhwRfFUwcKjNvS WlZ92DCQ0m5zT/W5SJuPgDUfbQcy3AcamqmDWdeFK/aYmOPicDk96Ty+HILINEVDad GHrO6GqUPPUTfFQpnOiEo3iYVUSQzVHmft32izN0= 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 56D2F3858023 for ; Thu, 2 Feb 2023 18:12:29 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 56D2F3858023 Received: by mail-ot1-x32a.google.com with SMTP id n25-20020a9d7119000000b0068bd8c1e836so696389otj.3 for ; Thu, 02 Feb 2023 10:12:29 -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=COPxbgjL39E/wVSr7EMR7qQRWVOBOB4Zqco28tqWNDU=; b=64trYPtLEHuD9dDfWej8xIJV95IbmJVgHm/DWBwKgmaJbOlXh7on1TgSaxranBjvbw LrjkKQxq7+cF60jt7uQSP/QS7Wie9JoelQSLH6ae8qAYzoEeK4W/vIv3XFCAaXfImTrQ 4Rx9cnN1J5u95y0iGaqOKdpyuZVTQwyK6roM5xv5Ehu0w1d/lcGh1kII+0mt14o929Nu Z2xbpMZH9aS4BCalkoH74qMqnvQS8Qjmulv4wjq+4S7nhCT2NMYRZsXcLkW5Fd5ykI4v FU8aoH/DM24vBt+Bn+W2Lj5JAUARmqZya77etU52r1SEutPs1jShtOnF7DDXqR5JUcNy 5Mag== X-Gm-Message-State: AO0yUKWzPCdEqIwFSi62ILC1UMZYcIAfTv1csm5mQPQpwsxOuP4gJ2UL L02Pjh/zWaRzN3qb7Q7a8O8CRXTD5SQLDIvGi9U= X-Google-Smtp-Source: AK7set/rqeYTEuLheVkg7F3oGKFS89lMytfE9BXRmrzg9sEFMIdRdo3EhY8PHblSRxCplL29+TMPKA== X-Received: by 2002:a9d:6b0d:0:b0:68d:53d5:f7d2 with SMTP id g13-20020a9d6b0d000000b0068d53d5f7d2mr1104341otp.31.1675361547866; Thu, 02 Feb 2023 10:12:27 -0800 (PST) Received: from mandiga.. ([2804:1b3:a7c2:1887:da12:b9d3:2162:a28c]) by smtp.gmail.com with ESMTPSA id ci10-20020a05683063ca00b00684a10970adsm126689otb.16.2023.02.02.10.12.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 02 Feb 2023 10:12:27 -0800 (PST) To: libc-alpha@sourceware.org, Richard Henderson , Jeff Law , Xi Ruoyao , Noah Goldstein Subject: [PATCH v12 13/31] string: Improve generic memrchr Date: Thu, 2 Feb 2023 15:11:31 -0300 Message-Id: <20230202181149.2181553-14-adhemerval.zanella@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230202181149.2181553-1-adhemerval.zanella@linaro.org> References: <20230202181149.2181553-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 Thu Feb 2 18:11:32 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: 64179 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 303E5382E6B5 for ; Thu, 2 Feb 2023 18:16:21 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 303E5382E6B5 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1675361781; bh=NEs74f/T44NZOxbSYnquYKRGf5z3hN+b5jVwTA7327U=; 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=RFFhdzsM78xD9fx0OVlhKiWAH2TkMsmyqweeFsW9/Ui8U92XDN2XgSnv/cfyB3w4L xhxtpv11PTlbB4w0rpD/xRSCTUNATa37A+oz/3ytF004qZFTJ49w37A/Zmjyv7PEI/ uzRCD/u59wqH+Vt6RwZYDgeIQn3LGxQgtPOUOFRU= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-ot1-x331.google.com (mail-ot1-x331.google.com [IPv6:2607:f8b0:4864:20::331]) by sourceware.org (Postfix) with ESMTPS id 8516D385483F for ; Thu, 2 Feb 2023 18:12:31 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 8516D385483F Received: by mail-ot1-x331.google.com with SMTP id k91-20020a9d19e4000000b0068bca1294aaso690339otk.8 for ; Thu, 02 Feb 2023 10:12:31 -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=NEs74f/T44NZOxbSYnquYKRGf5z3hN+b5jVwTA7327U=; b=yreE0X2QJZSot5mzTWBxPcH+ObnFgqw6DDonWHR+Y4dzwYEiKCyLpKGwqpqFxAMsx1 6u4ltOriVBvM9ngK37sS5TEnrduJUwRCN24tYgdTm7eB1yXctz6rNyhdOAdWhqBgbPpe pSUi6RAfe6ViO3VELcL5q5YLBzk6mfX63fa8f0TDtzQIBBeWJ0gsXD4nFMFRHl2oUQFD P5x7bVjwohsdOsk4+LC1SWrAIEa2AAvoyjTSUjjJF2AtqYGy9sUYMFS9e5gZCW3mgs8G TDvqXLrzhrJgJExEYl3gsYKvlI4kAxtMRoZSHXkH3TYECzvZMpbh8TzrnBGFvTwwljLL xTEA== X-Gm-Message-State: AO0yUKXFz9pGHaJGi23cKXHry/p5J7a+/sKpASawbtmgmdJ0bylFJNmO 1bobsbnsYoqYnHHUSOuSRZMD4iXIc8hLMUNKmfk= X-Google-Smtp-Source: AK7set/Gy/dDQ7DPIncVlRHQNNV+Js5zgyVb2VO+kW41UM8pjuZVvtOPl6sEGJmNfH+jwrC2qS+TIw== X-Received: by 2002:a05:6830:918:b0:68b:c490:5372 with SMTP id v24-20020a056830091800b0068bc4905372mr4833781ott.22.1675361550181; Thu, 02 Feb 2023 10:12:30 -0800 (PST) Received: from mandiga.. ([2804:1b3:a7c2:1887:da12:b9d3:2162:a28c]) by smtp.gmail.com with ESMTPSA id ci10-20020a05683063ca00b00684a10970adsm126689otb.16.2023.02.02.10.12.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 02 Feb 2023 10:12:29 -0800 (PST) To: libc-alpha@sourceware.org, Richard Henderson , Jeff Law , Xi Ruoyao , Noah Goldstein Subject: [PATCH v12 14/31] string: Improve generic strrchr with memrchr and strlen Date: Thu, 2 Feb 2023 15:11:32 -0300 Message-Id: <20230202181149.2181553-15-adhemerval.zanella@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230202181149.2181553-1-adhemerval.zanella@linaro.org> References: <20230202181149.2181553-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 both strlen and memrchr have word vectorized implementation, it should be faster to implement strrchr based on memrchr over the string length instead of calling strchr on a loop. 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). --- string/strrchr.c | 18 +----------------- 1 file changed, 1 insertion(+), 17 deletions(-) diff --git a/string/strrchr.c b/string/strrchr.c index 3c6e715d3b..7b76dea4e0 100644 --- a/string/strrchr.c +++ b/string/strrchr.c @@ -27,23 +27,7 @@ char * STRRCHR (const char *s, int c) { - const char *found, *p; - - c = (unsigned char) c; - - /* Since strchr is fast, we use it rather than the obvious loop. */ - - if (c == '\0') - return strchr (s, '\0'); - - found = NULL; - while ((p = strchr (s, c)) != NULL) - { - found = p; - s = p + 1; - } - - return (char *) found; + return __memrchr (s, c, strlen (s) + 1); } #ifdef weak_alias From patchwork Thu Feb 2 18:11:33 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: 64175 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 150B93945C2C for ; Thu, 2 Feb 2023 18:15:29 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 150B93945C2C DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1675361729; bh=h+vPvH7WJFuFiXaNRppqjpFasecUdh17PIqB9elepeI=; 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=LRWLJZjWVIRzZIJ6fhjUQ8PyvBflE2weVvdn5/82/3RbNxgCyYbpxjSr2HUPhce9W zl/P6TF+yVAztiEX1vruBNBGMiTUV8lpjfyUd2aflpQKXVNzvPJKooM5jZJZ0z+lyO Lm2X7Hx2T47WgJYY6mk7AjxDcczufkkj061pvnY4= 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 4D942385700E for ; Thu, 2 Feb 2023 18:12:33 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 4D942385700E Received: by mail-ot1-x335.google.com with SMTP id g21-20020a9d6495000000b0068bb336141dso687807otl.11 for ; Thu, 02 Feb 2023 10:12:33 -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=h+vPvH7WJFuFiXaNRppqjpFasecUdh17PIqB9elepeI=; b=BL//Gt/57RUYJJFOEn0X/j+vHwb3Mz7/u0ysqrW26i0ZXbWH4+LzpRaurDzhBma+Gz 0NGwC/UJOjKHhgggO7Gj+dUQDrfequyp0ZvI1y/5uVKW0+pGc7y1wRyLfrTgbPbRze6W 6m71HyKo9hXUTqLmXl65CqB/Hmnd8NrULuxRI86OxMnxk2nasUGBOttpIQLoFRo3T65s KHyqiHlj1ijr2UaURx/WYtu/ruR8FZ4P0oCIhhwAGtkeLGUsmuaEvzXM0lBwkp7bfPp1 5LMqqxQ/10/m/nxDvV9JuoiLr9D1NMGlbsc0/k76fQ8nP7S78YB+BqLroRQOwz/LBI7g T6Zw== X-Gm-Message-State: AO0yUKVGPqszsxG3IDa7u6let9f5tvKVyXZyukOgHUjdtKWZeAcHEmSI r/1/skfgmK/i6+oGMEufP4QcUtGs1jKeIdM5Bbw= X-Google-Smtp-Source: AK7set9VnwLCTFJhJf3yPn1HdJKZOTY6o9J4QPU2c4TswAxpCIs+GUuMw0Xgsg3MUBwAoX3m2Rk3AA== X-Received: by 2002:a9d:6a05:0:b0:68b:cd66:2c52 with SMTP id g5-20020a9d6a05000000b0068bcd662c52mr3202226otn.5.1675361552460; Thu, 02 Feb 2023 10:12:32 -0800 (PST) Received: from mandiga.. ([2804:1b3:a7c2:1887:da12:b9d3:2162:a28c]) by smtp.gmail.com with ESMTPSA id ci10-20020a05683063ca00b00684a10970adsm126689otb.16.2023.02.02.10.12.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 02 Feb 2023 10:12:31 -0800 (PST) To: libc-alpha@sourceware.org, Richard Henderson , Jeff Law , Xi Ruoyao , Noah Goldstein Subject: [PATCH v12 15/31] hppa: Add memcopy.h Date: Thu, 2 Feb 2023 15:11:33 -0300 Message-Id: <20230202181149.2181553-16-adhemerval.zanella@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230202181149.2181553-1-adhemerval.zanella@linaro.org> References: <20230202181149.2181553-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. Reviewewd-by: Adhemerval Zanella --- 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 Thu Feb 2 18:11:34 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: 64181 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 457D23885C2C for ; Thu, 2 Feb 2023 18:17:02 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 457D23885C2C DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1675361822; bh=idrqENDX2WuyAiQLTdhPSJ6g6u6MMmWmcKCanb7PO1g=; 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=cmoqPSD1dZeizfkogKJTjPrT6hcPJffgRbb71IYWKjEPKu5HGOG39L8U/YXgQ5UV/ FtDwLxJPukIM1WPHyu+wJeXpgDIF8HmPJWsgg0CcoZ9A8G/MXj7o+ShjtSDfuA1YqH KvXYPfr//8LwwVYlvmZV4RZCBADeXWkJ6oK8OJ58= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-ot1-x336.google.com (mail-ot1-x336.google.com [IPv6:2607:f8b0:4864:20::336]) by sourceware.org (Postfix) with ESMTPS id D3BAA385828D for ; Thu, 2 Feb 2023 18:12:35 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org D3BAA385828D Received: by mail-ot1-x336.google.com with SMTP id v24-20020a05683011d800b0068bdd29b160so681331otq.13 for ; Thu, 02 Feb 2023 10:12: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=idrqENDX2WuyAiQLTdhPSJ6g6u6MMmWmcKCanb7PO1g=; b=Y16MK9KO2x6lNWVON124px8gYkqNsfBE/6FU0SwpF9QttGoyZE1bbOeiMH1vdCFsJp CdtSid2NCyqkBM/6jza2ZQp1zlrN8A4tS38dHXciHxmIbdTSlbXRwy/WxdLsz3CM4pd4 E8itfk2PtAwXDXtnXrUOBbfK9GGs9Pxz6pghrojBWvgiOCIgSJwRV/7oAqi6+x1tVMtx qCyqvfnH1Fq8Zt2A8YOB/VtrXXv+rc7sa0NKPdWUqZ0SVHtIi2d6AviLV20AQt/6Bpzi S9rDHg9VUV34ka2m7PwJYqerdx8C3i+/l2+DwLAlaVxASFNpHSSvcx8gH1P9ud0pPX7W Alhg== X-Gm-Message-State: AO0yUKUbx+FnjigzslO9Px6W9db0xHZGCMTMNXbvwzlkRpJchKdgj/4q 5FfTBSWUKHxt0WSSSquewXKE8FHpTXJ/gPMXCMM= X-Google-Smtp-Source: AK7set98A+6LKKag7TWHtE4g2Tnm/sgRFV7k+wpY0SPbCoXJV8U6U/wbzKHM+004uTq31dkPpKUqZw== X-Received: by 2002:a9d:6a05:0:b0:68b:cd66:2c52 with SMTP id g5-20020a9d6a05000000b0068bcd662c52mr3202277otn.5.1675361554777; Thu, 02 Feb 2023 10:12:34 -0800 (PST) Received: from mandiga.. ([2804:1b3:a7c2:1887:da12:b9d3:2162:a28c]) by smtp.gmail.com with ESMTPSA id ci10-20020a05683063ca00b00684a10970adsm126689otb.16.2023.02.02.10.12.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 02 Feb 2023 10:12:34 -0800 (PST) To: libc-alpha@sourceware.org, Richard Henderson , Jeff Law , Xi Ruoyao , Noah Goldstein Subject: [PATCH v12 16/31] hppa: Add string-fza.h, string-fzc.h, and string-fzi.h Date: Thu, 2 Feb 2023 15:11:34 -0300 Message-Id: <20230202181149.2181553-17-adhemerval.zanella@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230202181149.2181553-1-adhemerval.zanella@linaro.org> References: <20230202181149.2181553-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. Reviewed-by: Adhemerval Zanella --- 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..c4e2e11550 --- /dev/null +++ b/sysdeps/hppa/string-fzc.h @@ -0,0 +1,124 @@ +/* string-fzc.h -- zero byte detection with indexes. 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_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..08cdace416 --- /dev/null +++ b/sysdeps/hppa/string-fzi.h @@ -0,0 +1,63 @@ +/* string-fzi.h -- zero byte indexes. 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_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 Thu Feb 2 18:11:35 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: 64182 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 9A32D3899018 for ; Thu, 2 Feb 2023 18:17:43 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 9A32D3899018 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1675361863; bh=3fXaGuwJOwgZL6V5OO2V4xLMuaQnwW5wgOb9uE8jyn4=; 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=XSRW6welC/4WO4PBsylHiaxxSVE8Sp6oTcnuHWhV/T7hxSbRsXDLLQ75D3e+rHQKF vp2TZ+1GMd3ZwBfJg7VGG2D3Fr7ReYovo+eWzJChoi5zIQVj2G4/zTXnL7wzpsx+NF 56Im7AsozLTxVB+6/+4qujXLDCro1VoZ0LL+58nU= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-oa1-x29.google.com (mail-oa1-x29.google.com [IPv6:2001:4860:4864:20::29]) by sourceware.org (Postfix) with ESMTPS id A2AEE385B533 for ; Thu, 2 Feb 2023 18:12:38 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org A2AEE385B533 Received: by mail-oa1-x29.google.com with SMTP id 586e51a60fabf-1636eae256cso3638462fac.0 for ; Thu, 02 Feb 2023 10:12:38 -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=3fXaGuwJOwgZL6V5OO2V4xLMuaQnwW5wgOb9uE8jyn4=; b=hlTn9JTrXCJamKD+lFplmGHtIURfYCQTy3/Osas9vsYwVZvJ+7HukqLyHupBke1l5R igtIoeLBrfP0Nn5x2zsPpKHqzt7XGQamhJLm+aXwwdXoWA1na5VHVwswtQEW5sbOGRi0 De6PRrBdv75WABq0JcJnDUZosNH3/Wv0yMayCrJc++ZIJEbQpM34SJBiXPYpH+G0arVf CHMqARRQ2S6YgfHaYuw5HeYQT6YiTv28Z6U8SliLpcz7GLCkzS1kHZMIYGGix1phgJDS aBaT9j0czq3c33OCeS8CC9xs3c060CUmEZUGzo/aAArUxTHqUTfz3CbZyYUByqAVI5o/ r6tA== X-Gm-Message-State: AO0yUKXACJbePoSVJSWZfmescuhRuaAspYrUcjQN/6IDhe5cIFeRJk0B Na/AEUCIc7p2Zhe8ja5XlsB4FZU8o5L8qXCjEfY= X-Google-Smtp-Source: AK7set/GCGXN9Z3XtyKxstt7NkwqjKIp/kR0S9JCi02cL2M8ptsat2yH309g4OqVmUpTp1YXuPjC7w== X-Received: by 2002:a05:6871:714:b0:163:49a0:5557 with SMTP id f20-20020a056871071400b0016349a05557mr3907827oap.6.1675361557137; Thu, 02 Feb 2023 10:12:37 -0800 (PST) Received: from mandiga.. ([2804:1b3:a7c2:1887:da12:b9d3:2162:a28c]) by smtp.gmail.com with ESMTPSA id ci10-20020a05683063ca00b00684a10970adsm126689otb.16.2023.02.02.10.12.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 02 Feb 2023 10:12:36 -0800 (PST) To: libc-alpha@sourceware.org, Richard Henderson , Jeff Law , Xi Ruoyao , Noah Goldstein Subject: [PATCH v12 17/31] alpha: Add string-fza, string-fzb.h, string-fzi.h, and string-shift.h Date: Thu, 2 Feb 2023 15:11:35 -0300 Message-Id: <20230202181149.2181553-18-adhemerval.zanella@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230202181149.2181553-1-adhemerval.zanella@linaro.org> References: <20230202181149.2181553-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 Reviewed-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..aba7ca4f3d --- /dev/null +++ b/sysdeps/alpha/string-fzi.h @@ -0,0 +1,62 @@ +/* string-fzi.h -- zero byte detection; indices. 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_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 Thu Feb 2 18:11:36 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: 64183 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 C4EC93881D26 for ; Thu, 2 Feb 2023 18:18:24 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org C4EC93881D26 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1675361904; bh=4YbYZoIUJG5C/9HOQop3Df8+9J6Xk8b5bFDcEadWMBU=; 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=SPXERLjHdu6kHy8dlu3TZ0WtEmWOoSHpRJi0HA/I75S/EJWbuERqmUaMvelRiEXd7 ku3bZ169qqIJu2ynLEAbzcUhGK9PffU3BCzdiovMKGBP2wm0fLTtD76tNWyWBhKZ4r nHyiVcuq5NmhyeeLlxpi9Bp+QGyLsJZsII9VQ1PE= 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 7AB2A38493EB for ; Thu, 2 Feb 2023 18:12:40 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 7AB2A38493EB Received: by mail-ot1-x334.google.com with SMTP id 14-20020a9d010e000000b0068bdddfa263so696246otu.2 for ; Thu, 02 Feb 2023 10:12: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=4YbYZoIUJG5C/9HOQop3Df8+9J6Xk8b5bFDcEadWMBU=; b=kf67v98KjnPZMb9Wup7AKKHebAIt/lkYSJyGf0nru6KRmqcG7NT9LeNnb9oiuPL+6p lJ/7CwvVj5svBEOTM71Np4L2Tj08ysjnkeUSOheCxUyBrgx7fJSGwZiJAyhjUdYU8xhX CDHWBlAoJxC2lt/yBH+lH4GfkX2iq/7h0KsoVZ0AKI6He2bShnY52SXr6+wdOkTiuD5a XSB+QstD0fi9+2JSsdYKUs0qYN56MYW2T2KqX13VYYAnble8S6g0GU48bSy0NceEew9W t3bizjZxiI+HVnnikWzeqvYVgy4e4VqBbsOcQN19au6F+5X6xhRUdlnLcfBkG5RCHw0v DjZQ== X-Gm-Message-State: AO0yUKUEUgAkL8aeWeCI+72VApc8qieJBbUW5A4tzHAaG6p9mUTHT7GN FEhKrPXYL72sTIbtQ5/C83t1GcmNbHaqkqxQsR8= X-Google-Smtp-Source: AK7set9dkI037cOoq0UdhuWH2OzyWfHetjLmjED+AKQuz78n7vAY/59rf64kXlZlHMoA+LOgNskDhA== X-Received: by 2002:a05:6830:1e68:b0:68b:b96b:ec5 with SMTP id m8-20020a0568301e6800b0068bb96b0ec5mr3694855otr.9.1675361559542; Thu, 02 Feb 2023 10:12:39 -0800 (PST) Received: from mandiga.. ([2804:1b3:a7c2:1887:da12:b9d3:2162:a28c]) by smtp.gmail.com with ESMTPSA id ci10-20020a05683063ca00b00684a10970adsm126689otb.16.2023.02.02.10.12.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 02 Feb 2023 10:12:38 -0800 (PST) To: libc-alpha@sourceware.org, Richard Henderson , Jeff Law , Xi Ruoyao , Noah Goldstein Subject: [PATCH v12 18/31] arm: Add string-fza.h Date: Thu, 2 Feb 2023 15:11:36 -0300 Message-Id: <20230202181149.2181553-19-adhemerval.zanella@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230202181149.2181553-1-adhemerval.zanella@linaro.org> References: <20230202181149.2181553-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 Reviewed-by: Adhemerval Zanella --- 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 Thu Feb 2 18:11:37 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: 64169 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 40C5838432DE for ; Thu, 2 Feb 2023 18:14:13 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 40C5838432DE DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1675361653; bh=iBGDBU1LOIu4kx/c1fhVkLNNrKP6X4acltTDNOqXoVA=; 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=jDkerryRGD62Uv8xpaHSwmMEiIuUsvX/uBy+O0S+KQfix+StvDAth55uFrWpXwBBl BalNSKTNPAlVy62565WlPN2cp5wSYqDAZLlr0BC5Cd1nSTxh7+dju8nMFXQlAr9r2g Ee20wyJBRiySVt2QxSUmCtAiKwHJmT7IKRd4Jj+g= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-oa1-x29.google.com (mail-oa1-x29.google.com [IPv6:2001:4860:4864:20::29]) by sourceware.org (Postfix) with ESMTPS id D812238582BE for ; Thu, 2 Feb 2023 18:12:42 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org D812238582BE Received: by mail-oa1-x29.google.com with SMTP id 586e51a60fabf-163bd802238so3591089fac.1 for ; Thu, 02 Feb 2023 10:12: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=iBGDBU1LOIu4kx/c1fhVkLNNrKP6X4acltTDNOqXoVA=; b=FfRyLpeTbnXCaDOxLFOqOoYIVk+zv2oEr2c+l2E6vn7t/pdihXgn4AfjtKWohtK1Jk Vz1lGkMBWUX3tqFEQSohCVXeRPpEVXWs72+Q4y4m0oNwwpMvdxZwx43vt2TGrFnixoR1 NMSF4BiOzZquEeh6TJg4jeztTh2ivliL5nmTNWgN2hEYrCv3AJ3M7AZAAVVY+f3IhOvP pgOe+b5YPwxiM/4SSv28FabjZP8p5D4W5wACtOB/fJTa46TXHDo+pZpEOE+Ubo5oK2qS WASxg9LPt1+ZVQyXSyQvtQStsoAs0AMqSOmkn24DK6W2vo0X9NNR6JNSEPGeS962uKks D/yg== X-Gm-Message-State: AO0yUKWbRcjEjRkAE2QF9nY5GQ19wWW1w07bfdFCIIp10GHjkgIKRGkl AniFm4lNofXe3H4sJFYcwEOybboXsFwDc67LyIg= X-Google-Smtp-Source: AK7set+GVwlDnUs++EwriwE30Z1qo5qCKrF5t676sGywGqLg1xgnuh8G6VlA1qLzeHeg1PaCgnkS/w== X-Received: by 2002:a05:6871:b10:b0:162:9d70:2f59 with SMTP id fq16-20020a0568710b1000b001629d702f59mr4209307oab.52.1675361561767; Thu, 02 Feb 2023 10:12:41 -0800 (PST) Received: from mandiga.. ([2804:1b3:a7c2:1887:da12:b9d3:2162:a28c]) by smtp.gmail.com with ESMTPSA id ci10-20020a05683063ca00b00684a10970adsm126689otb.16.2023.02.02.10.12.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 02 Feb 2023 10:12:41 -0800 (PST) To: libc-alpha@sourceware.org, Richard Henderson , Jeff Law , Xi Ruoyao , Noah Goldstein Subject: [PATCH v12 19/31] powerpc: Add string-fza.h Date: Thu, 2 Feb 2023 15:11:37 -0300 Message-Id: <20230202181149.2181553-20-adhemerval.zanella@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230202181149.2181553-1-adhemerval.zanella@linaro.org> References: <20230202181149.2181553-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. Reviewed-by: Adhemerval Zanella --- 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 Thu Feb 2 18:11: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: 64173 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 BC5683888C7C for ; Thu, 2 Feb 2023 18:14:54 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org BC5683888C7C DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1675361694; 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=CbugOpdg9GxDwMc26QOE/IE5+ukLzI6H3b5Nx6LcUioaTMO5nMmA40Zwl2/eEIVoS Nv9Uv7OivPnOoDQ3463ipeWi1H10pA3tk0SjQgJVE2QHGQvkYPtUpknvkyUcZno4o3 TrxKO9hhc4zlgnzLGv4XlASicVj1YktvX2KEt/eU= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-oa1-x2e.google.com (mail-oa1-x2e.google.com [IPv6:2001:4860:4864:20::2e]) by sourceware.org (Postfix) with ESMTPS id B7BEB387101B for ; Thu, 2 Feb 2023 18:12:45 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org B7BEB387101B Received: by mail-oa1-x2e.google.com with SMTP id 586e51a60fabf-169b190e1fdso3571432fac.4 for ; Thu, 02 Feb 2023 10:12:45 -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=Og1Rgq9yy6ttDLTNQYJgrK3h+/56aIPoKm0dzfaiXBGjcCkjWHetQs5qna4wTzSKT9 5mL1k5nVzDCbtrX6VAB+LhNBENzf9zBV8fnKpXloHupsQjnYZwTkeF/ncIFDnHW4xv/4 dxY91NQ6x6Mon7IqkzpyLEFu5+Q9GAUknDjwaaR/OlFpOLri2Z5Ax2t4oI/e65bMhO55 yeDdqaoAYHonpyiGdXVPR1dj6tID4dqccoIBvOV6Yb7gHZbdzPD0LnDP2J7Lm/DpCDy7 l/+BTzCBgZ1VWcL3I84w/wllYLV/ZKNR/x2bQ4N3guwH1Y54/Em3MzaM7XxXNxTx0nN3 Bi8A== X-Gm-Message-State: AO0yUKWnxwoc0bYfiaqX/rNkV9VL2pxw6kiQbBG0iFT2gvav1LoUssP1 RA/qt9am8P3G906XfBsx3GDvLIS4fZ68/nbr+0M= X-Google-Smtp-Source: AK7set+qJOfNOAJFpPeEdKxX0IsZwQq+QvLzUqBB2TBBUvJCLhIxrxAL2cuHrrgrgpsJ3ZydB8GElA== X-Received: by 2002:a05:6870:5893:b0:163:bbe4:f7a0 with SMTP id be19-20020a056870589300b00163bbe4f7a0mr3210796oab.55.1675361564295; Thu, 02 Feb 2023 10:12:44 -0800 (PST) Received: from mandiga.. ([2804:1b3:a7c2:1887:da12:b9d3:2162:a28c]) by smtp.gmail.com with ESMTPSA id ci10-20020a05683063ca00b00684a10970adsm126689otb.16.2023.02.02.10.12.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 02 Feb 2023 10:12:43 -0800 (PST) To: libc-alpha@sourceware.org, Richard Henderson , Jeff Law , Xi Ruoyao , Noah Goldstein Subject: [PATCH v12 20/31] sh: Add string-fzb.h Date: Thu, 2 Feb 2023 15:11:38 -0300 Message-Id: <20230202181149.2181553-21-adhemerval.zanella@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230202181149.2181553-1-adhemerval.zanella@linaro.org> References: <20230202181149.2181553-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 Thu Feb 2 18:11: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: 64184 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 14450385842D for ; Thu, 2 Feb 2023 18:19:06 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 14450385842D DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1675361946; bh=IZae/T37iLL1MGDMx4SxF7or+Kfq+KjDIyUEiRzWEvU=; 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=ML0nLhIF97srKqVA/pPkTsekpePBbNqiReBeZLbWwjYcQt+k+gOiGUhadaL0Qlufh g2zpYlJcRd/y6V3vAx4IAVHThZ8Pc0VrkJ/VEr/iEx4QbSx81UMjTsJ4EC+jfs2NdN G58W57BnvSXUg/Y9aSKbVfgQ1mwRLUxBZExh/wTU= 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 9D329385DC3C for ; Thu, 2 Feb 2023 18:12:47 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 9D329385DC3C Received: by mail-ot1-x32d.google.com with SMTP id r34-20020a05683044a200b0068d4a8a8d2dso685982otv.12 for ; Thu, 02 Feb 2023 10:12: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=IZae/T37iLL1MGDMx4SxF7or+Kfq+KjDIyUEiRzWEvU=; b=yS1GqwzL9yMz+7BZKIuLsyI4ntTM8oarObOWyIQYZohOckAL/DM2SgeM/NiQgQMs1U +HWfl3eUSaC7Uy5BwRq9VaBmGOMMaXRaud0W+bEVP1ovUqHx4TmQbSVlijs14IZkrGPU 8G06vOT3KxA0EBhyYyjozPP5y6jmaNqetWz2V0TS6jsRa3UozNCFkUP75hbH/yfFUaQ6 n+5q9VkSFw0mWSgApIFxk7uagxN8G1K06bLY3X3zQIcZnIeM50VfChPNBLZ+PkLqKXyh drm+n3aInA3pWOtJgWDyR5/fPwlyFvw4liiwdMNBZQ3pcNDzjuz3kMKnSzAftV2jSGD1 ZI7g== X-Gm-Message-State: AO0yUKXiV2uqUfVB52/UBjHmPdVzM2eCcgOwzT74BTKe2BUQ2Bxwoiwd ybLGCXnk8eJF23fJRgirgVsCLVmC/nRUhAZ1QpQ= X-Google-Smtp-Source: AK7set+0mZjiag4rxtjFkOcwzVwNhFD61pHn4yjA5K92M6a59SY3+qyaW4n4G3E4xEmCbqLrwFL8Qw== X-Received: by 2002:a05:6830:4109:b0:68b:c8fc:bfcc with SMTP id w9-20020a056830410900b0068bc8fcbfccmr4387372ott.9.1675361566410; Thu, 02 Feb 2023 10:12:46 -0800 (PST) Received: from mandiga.. ([2804:1b3:a7c2:1887:da12:b9d3:2162:a28c]) by smtp.gmail.com with ESMTPSA id ci10-20020a05683063ca00b00684a10970adsm126689otb.16.2023.02.02.10.12.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 02 Feb 2023 10:12:45 -0800 (PST) To: libc-alpha@sourceware.org, Richard Henderson , Jeff Law , Xi Ruoyao , Noah Goldstein Subject: [PATCH v12 21/31] riscv: Add string-fza.h and string-fzi.h Date: Thu, 2 Feb 2023 15:11:39 -0300 Message-Id: <20230202181149.2181553-22-adhemerval.zanella@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230202181149.2181553-1-adhemerval.zanella@linaro.org> References: <20230202181149.2181553-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 Thu Feb 2 18:11: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: 64177 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 96B5F38582BC for ; Thu, 2 Feb 2023 18:15:36 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 96B5F38582BC DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1675361736; bh=EdEacAiDNy91IxfCbhUa2BV1sVEmxuELNg72O36/HDw=; 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=nzqJzuikNwFtVTmIXxEAygdirx3v+o21J8faTxVKVfOThvojPAuvKq3OgTKhNjw6u Y3sllJnJPn1VXd/K8WBcSECSAvWSvnsfDkxxs7V0yRRzKnDOLjTMZZxBQ/q/nFM4KC G/QjuJyRmxWc+aFKmtnENPxEmKobTy+UIX57L/Rc= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-ot1-x336.google.com (mail-ot1-x336.google.com [IPv6:2607:f8b0:4864:20::336]) by sourceware.org (Postfix) with ESMTPS id D619D3858004 for ; Thu, 2 Feb 2023 18:12:49 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org D619D3858004 Received: by mail-ot1-x336.google.com with SMTP id v24-20020a05683011d800b0068bdd29b160so681536otq.13 for ; Thu, 02 Feb 2023 10:12: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=EdEacAiDNy91IxfCbhUa2BV1sVEmxuELNg72O36/HDw=; b=LsjLS/3/acnEp8tLoSK5bncvsotfGOi4IT6kKNsoeb4Rt6ylLwx89koMuZBZTs/D4u z7GI70ak/hXiZMeejqZ1Go4kb1LuAzwqnQphruw730Rn3lI++wYAqkkgqMqXl4n146HB FOowKXhOamqQeL5jL2Ef7lMUBKV+cdV2auNS8XMqY4tVCWCox/8v7Tyy5qYXIAC01d09 Ek7uUMA0kqkXpDRIoJ6wZNbOlPR68hlOKHp/QZ1sWDfLVu0bLSrHbbSBd/sSkn5TWQys SjuSbLmk7hDa85SoRR4DC1yU+umgukFqk33jB+Yp26eCH8/yoDy5pZCIHtNRycJzWyBY gIpA== X-Gm-Message-State: AO0yUKUjmm08cqlfIor3OqT9DZY2tnyDR+gTw4Vs3GLqR6HLyUWhaYFe QTt49FkKukkP1iYqeCbb7fyZ7lRXfYGlWo+IHbk= X-Google-Smtp-Source: AK7set95smygH1c1xDZSEC1GlyoaI33PKqV9MHqgxSBWKKA+RaARy85sH2cEUApKWqo0+IPuSMD8ww== X-Received: by 2002:a9d:3e7:0:b0:68b:e3c5:6eb0 with SMTP id f94-20020a9d03e7000000b0068be3c56eb0mr1145196otf.22.1675361568782; Thu, 02 Feb 2023 10:12:48 -0800 (PST) Received: from mandiga.. ([2804:1b3:a7c2:1887:da12:b9d3:2162:a28c]) by smtp.gmail.com with ESMTPSA id ci10-20020a05683063ca00b00684a10970adsm126689otb.16.2023.02.02.10.12.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 02 Feb 2023 10:12:47 -0800 (PST) To: libc-alpha@sourceware.org, Richard Henderson , Jeff Law , Xi Ruoyao , Noah Goldstein Subject: [PATCH v12 22/31] string: Hook up the default implementation on test-strlen Date: Thu, 2 Feb 2023 15:11:40 -0300 Message-Id: <20230202181149.2181553-23-adhemerval.zanella@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230202181149.2181553-1-adhemerval.zanella@linaro.org> References: <20230202181149.2181553-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 Thu Feb 2 18:11: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: 64185 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 78B423893673 for ; Thu, 2 Feb 2023 18:19:47 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 78B423893673 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1675361987; bh=nL3t/Vb1wus9jJSBkebYEj0KSZ0wG9m9limuqle5l3A=; 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=XVjpKEjepiJHlncNnrx7jXhXKhu1oVhdnpNHxGe5Zf/7tLyyNMYv1vILTPQhOXBAi nahihwIP4M3his4Dx26D8o3iE0qpBKL2FLRNA8jUP9yXEiV3AL7J49A3hW8BjIGeLs wpZcM/ldbieuHXv4lac3I/+3oNMnd6p/DrB3Pato= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-oi1-x236.google.com (mail-oi1-x236.google.com [IPv6:2607:f8b0:4864:20::236]) by sourceware.org (Postfix) with ESMTPS id 50A553865488 for ; Thu, 2 Feb 2023 18:12:52 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 50A553865488 Received: by mail-oi1-x236.google.com with SMTP id s66so2130732oib.7 for ; Thu, 02 Feb 2023 10:12: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=nL3t/Vb1wus9jJSBkebYEj0KSZ0wG9m9limuqle5l3A=; b=zdADwfjd3B1v9KnZkLYmLJJy3Pg0b2gxjoxExNjCYflBl9Y5IkruG7pWN4S+3XZ3u1 96p/Bh4Jj/fJHxtTXe4GKyQrNCdwve/5G6yrUqvZvDQAYrSEBBQMt8qXsB2FNcR+A66Q JGcy8KfGcxYKlK7uSHJc2ZcvYzZRo+/l4wok1e0fKDz8z7NDB+n6DZQm9eYmYsiDj53I ZizXnhZACo0pmww4oa/aZLmHQq2rYiM051BDeff7AeZc6soUy1YF5RYtPhQV5lICkq6F wPdEpcQ0vIb8dNeAmye4UZSK0WmtXxfCuTLxZZtCSmLQpbOzANp6UNT/bEPNJRtXayb7 bzHA== X-Gm-Message-State: AO0yUKWug8IGw3F4+5M1Rea0AX3QXuVvLCp2hKo9P89EvBMVjmxfZw/7 9RiXPA1i1IXhkH27rrCQYxMipCgM/Gm6oAKjZLI= X-Google-Smtp-Source: AK7set8Y52seN1bZO9YDOM1IhmtXdflzjWNf33157szXWQweSHsAje261uLyjgiW8+4LB9U0CJ6weQ== X-Received: by 2002:a05:6808:298:b0:378:8edd:1f7a with SMTP id z24-20020a056808029800b003788edd1f7amr1065240oic.42.1675361571067; Thu, 02 Feb 2023 10:12:51 -0800 (PST) Received: from mandiga.. ([2804:1b3:a7c2:1887:da12:b9d3:2162:a28c]) by smtp.gmail.com with ESMTPSA id ci10-20020a05683063ca00b00684a10970adsm126689otb.16.2023.02.02.10.12.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 02 Feb 2023 10:12:50 -0800 (PST) To: libc-alpha@sourceware.org, Richard Henderson , Jeff Law , Xi Ruoyao , Noah Goldstein Subject: [PATCH v12 23/31] string: Hook up the default implementation on test-strnlen Date: Thu, 2 Feb 2023 15:11:41 -0300 Message-Id: <20230202181149.2181553-24-adhemerval.zanella@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230202181149.2181553-1-adhemerval.zanella@linaro.org> References: <20230202181149.2181553-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 Thu Feb 2 18:11: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: 64186 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 A95783884508 for ; Thu, 2 Feb 2023 18:20:28 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org A95783884508 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1675362028; bh=kzGuyfJWcNU2IX1SBElhnkD+5hzdocahp3CTjowzN0Y=; 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=MFBdLJecgi06EkBj8s/7Opxp5l41wQFJsSLzpI0ZUVpIWGEyVoNNUw42Me53vneQX NZjPjR65/16t19E9cNAy4FUai7NUlXXzn+78xrgvxr8pbqOrxVjxVw4MZVio1MRmkR 2WiEAL+iUx2cw6hrqc1lAY4cufzauli8y7saM75M= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-oi1-x230.google.com (mail-oi1-x230.google.com [IPv6:2607:f8b0:4864:20::230]) by sourceware.org (Postfix) with ESMTPS id ABC7B383A330 for ; Thu, 2 Feb 2023 18:12:54 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org ABC7B383A330 Received: by mail-oi1-x230.google.com with SMTP id r9so2111131oig.12 for ; Thu, 02 Feb 2023 10:12:54 -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=kzGuyfJWcNU2IX1SBElhnkD+5hzdocahp3CTjowzN0Y=; b=rq0qOqozLLtiPp6qkcU+bPSKlMaSA1E/4IR0wuB+Q9JcxdwriWbGu7szteWkADcFWe FCMoB4fzuN0LkSVJHTbhk2afMejgnVS2eWv5ZsCZo7VPYYSN13WGke3WqmvL8vsuiOSk FbaQxjX74j3bxr890oeVhom6JjQqaj9SDewZ/mU9+E/n9/Ug4fqkWaY2Kx1ZeKKTDZ9g /2IjlS7ZFQYyq9nMyG4F+UC71sCzCCmdCmKuBsf1WXJ1LyyxqZ5isO5j2So7t5F7v+Mz luPEj0rq6p+rG6PWb3M7PsIT3iaS8bkmmidx1mmMWlDeiRAjCbnybGPkGCCnVwYGocFH t43w== X-Gm-Message-State: AO0yUKUwZohPnxVLYxe0dOSGQz7rtpqUw4rYePUwpjKK5kLa+YDEYb4+ A55WZX6mbpfCDg8r96rmxQ/dx0RQkN2uRyspkwg= X-Google-Smtp-Source: AK7set9vLE3kgrPWqSXjbU7BcYCGbMY4PiMPank69X1Ts/AUhcdvTMsZNTYtFayO5qBXT+rUn1VQ/Q== X-Received: by 2002:aca:a9cc:0:b0:36c:d1c7:ba37 with SMTP id s195-20020acaa9cc000000b0036cd1c7ba37mr3138938oie.41.1675361573390; Thu, 02 Feb 2023 10:12:53 -0800 (PST) Received: from mandiga.. ([2804:1b3:a7c2:1887:da12:b9d3:2162:a28c]) by smtp.gmail.com with ESMTPSA id ci10-20020a05683063ca00b00684a10970adsm126689otb.16.2023.02.02.10.12.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 02 Feb 2023 10:12:52 -0800 (PST) To: libc-alpha@sourceware.org, Richard Henderson , Jeff Law , Xi Ruoyao , Noah Goldstein Subject: [PATCH v12 24/31] string: Hook up the default implementation on test-strchr Date: Thu, 2 Feb 2023 15:11:42 -0300 Message-Id: <20230202181149.2181553-25-adhemerval.zanella@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230202181149.2181553-1-adhemerval.zanella@linaro.org> References: <20230202181149.2181553-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 Thu Feb 2 18:11: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: 64187 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 61A133896C19 for ; Thu, 2 Feb 2023 18:21:10 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 61A133896C19 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1675362070; bh=XG4KbyuoKmeHF58Ke4AwPJ6PeFHhhUuGh3WJT/w5D/U=; 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=whdyWN4ToNGqJpiUvp+LvwFvDf09nTwn0RsyR++R2WoFKHoaUno80e2Bsq1ahHmZM +MErVaCoQ/rMk2UT8Yz+Dq/cEN0r7FJP/MAbBHFFdWRNxbLHiyoECXzV5WWtYlRuAI RMY+L/3Aqr2Mlj5fhv9SQ3hjKumSymiE87W85d8E= 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 0C110385480C for ; Thu, 2 Feb 2023 18:12:57 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 0C110385480C Received: by mail-ot1-x332.google.com with SMTP id d21-20020a056830005500b0068bd2e0b25bso699473otp.1 for ; Thu, 02 Feb 2023 10:12: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=XG4KbyuoKmeHF58Ke4AwPJ6PeFHhhUuGh3WJT/w5D/U=; b=2F9mgPbixmJ/Hp+zgMcjcReDCbDGQN5vaQzAhU+1/w6Re4vvs8sXfcZYmEs5zn4Tna AIs+lyfTBTEGQC1dUNk54T59/k9c5IrMMoZEAezTuh/hbDfsQzvBTqMQK1+o9exookPx dChFcllDtZ8VbX9/CBvIEiZ9kRc9H+hDKGusJxBOgLdBqhhyE3NrZFHmqKPxNImuroTu 0mpTQXtgJk7tIBCVwFmC0NUbxiYvJWGDvh+2iIDqtlmeV5F0NmBv7YnWT76bBPOOi3Nb X0Z3XjXS0BDzKRQwJIgq8X5rsv54bPCvU3DijA4g7EAwsM0wt0n3oTAvCz2/20zB1w7g xf/g== X-Gm-Message-State: AO0yUKUtAfa/aqDOJC9FkNVI6xBcI8l7Q3C4ufIWUAwiCqARgISf39SR guZlt6GcM0JtjJIM5RuAFKxU0N0bXFDJzO+Mnwg= X-Google-Smtp-Source: AK7set8hocAS9pe6CVk7a4u1CEmXRkr1NrajbSJOrvYCqjdhGeJ9vv5vWlscg+SMHFjjYf6XzOeDiw== X-Received: by 2002:a9d:644e:0:b0:68b:d30e:7a9f with SMTP id m14-20020a9d644e000000b0068bd30e7a9fmr3144503otl.28.1675361575634; Thu, 02 Feb 2023 10:12:55 -0800 (PST) Received: from mandiga.. ([2804:1b3:a7c2:1887:da12:b9d3:2162:a28c]) by smtp.gmail.com with ESMTPSA id ci10-20020a05683063ca00b00684a10970adsm126689otb.16.2023.02.02.10.12.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 02 Feb 2023 10:12:54 -0800 (PST) To: libc-alpha@sourceware.org, Richard Henderson , Jeff Law , Xi Ruoyao , Noah Goldstein Subject: [PATCH v12 25/31] string: Hook up the default implementation on test-strcmp Date: Thu, 2 Feb 2023 15:11:43 -0300 Message-Id: <20230202181149.2181553-26-adhemerval.zanella@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230202181149.2181553-1-adhemerval.zanella@linaro.org> References: <20230202181149.2181553-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" Reviewed-by: Richard Henderson --- string/test-strcmp.c | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) 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 Thu Feb 2 18:11: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: 64189 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 ED7B93895FC3 for ; Thu, 2 Feb 2023 18:21:52 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org ED7B93895FC3 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1675362113; bh=ExJp9NqaluTZU0y2Gv8vSU2JONn+XxMc+8TOMhPd5Jw=; 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=K06ZE425lwJOrkLk/8/Eo7Bz/WQb9xr7H2WvKS2xAofGDpL6qbvfQaF12KETVYGil lf/4aeKsgQ8PsXzUpzidL/a4IpTc59vRh6u+N2X5ubGvY/KeychSx1afyc4ljESVYR SryzSnvOPAR1vSqHway3nmukbJNnz3XcYGLO9JRw= 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 25D1D38346B8 for ; Thu, 2 Feb 2023 18:12:59 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 25D1D38346B8 Received: by mail-ot1-x329.google.com with SMTP id j6-20020a9d7686000000b0068d4ba9d141so692425otl.6 for ; Thu, 02 Feb 2023 10:12: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=ExJp9NqaluTZU0y2Gv8vSU2JONn+XxMc+8TOMhPd5Jw=; b=BzsQYlLfpZp0wyxk6G0rVviUUb+0Y+GxbmFqZB1jcibhQoOrWpR5WGle/eZn3RPnNK vlHXkZ5kRerVcdmrGpsplGbwGE93EWniWmLILgn0qUIQoaIxJ+eOc6PM1hFGyU3i1HjL X3KbjZswv+MKCz/tNJ5m2UINlxexicD9tIld00OUjhhiMHmEcubRS+QhvQFyIk1m+YR/ WLvo5BeG2K55NRBWVwSozR4i4dv2Vn/HHOznLeR5qiHzlFxqIk4mkickmoLhTl/UsxYe FYxXKFV7PqP3LPaD/Aui5CcM4dU9AZIEzxgQ3cqqGOKvQRdisHvzC8Dc5URf5Sm6BvOt vloA== X-Gm-Message-State: AO0yUKW2DkGgfD71x3v7kHK5+962TrcQn84lhk798JQvlwMJ+Fm5Afid ucIDvHhGI8iE5JzmaHCNycbnBLYYsXBqb1xr4lI= X-Google-Smtp-Source: AK7set8qCsHHyDZstCVXwMDkWQTW0ysFOnUG8PrGmenTSpad6w7FvOT8MaT+a1VMIlYF5ngBKm91nA== X-Received: by 2002:a05:6830:1e84:b0:688:4c9c:d45f with SMTP id n4-20020a0568301e8400b006884c9cd45fmr3559441otr.20.1675361577987; Thu, 02 Feb 2023 10:12:57 -0800 (PST) Received: from mandiga.. ([2804:1b3:a7c2:1887:da12:b9d3:2162:a28c]) by smtp.gmail.com with ESMTPSA id ci10-20020a05683063ca00b00684a10970adsm126689otb.16.2023.02.02.10.12.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 02 Feb 2023 10:12:57 -0800 (PST) To: libc-alpha@sourceware.org, Richard Henderson , Jeff Law , Xi Ruoyao , Noah Goldstein Subject: [PATCH v12 26/31] string: Hook up the default implementation on test-strncmp Date: Thu, 2 Feb 2023 15:11:44 -0300 Message-Id: <20230202181149.2181553-27-adhemerval.zanella@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230202181149.2181553-1-adhemerval.zanella@linaro.org> References: <20230202181149.2181553-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" Reviewed-by: Richard Henderson --- string/test-strncmp.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) 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 Thu Feb 2 18:11: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: 64180 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 0DC5A3896C17 for ; Thu, 2 Feb 2023 18:16:22 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 0DC5A3896C17 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1675361782; bh=yp7d9ZhXZEifCrrQc8AHjNoV8JRIdvNw91N1+33ZME8=; 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=rYCApkDXnqU2SUYBziqoafcnmNszvc78lxiUW5RyBOI3PQjXOr800OAY7AHhJn2jn /ZDHwbcNmy6F9l5wWIuJ5w36/I1feBUAXRrAkUSxriUa2Oerzt+5fnJzXvwTgNRJZY EFDEOsR0dHNuI/fa+NFG9KWa4sjIw50jPvCh4ejs= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-ot1-x331.google.com (mail-ot1-x331.google.com [IPv6:2607:f8b0:4864:20::331]) by sourceware.org (Postfix) with ESMTPS id 0B73B38493CA for ; Thu, 2 Feb 2023 18:13:01 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 0B73B38493CA Received: by mail-ot1-x331.google.com with SMTP id k91-20020a9d19e4000000b0068bca1294aaso690757otk.8 for ; Thu, 02 Feb 2023 10:13:01 -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=yp7d9ZhXZEifCrrQc8AHjNoV8JRIdvNw91N1+33ZME8=; b=MeitFy2CimYoYX3D8Ht6bo94n2Uz/bosx/g+qkIwo34mJlLklt4RxY8QB7x+cnhyDZ nic8ZLUAHomgrSjB26k/ubabE6Dmpy/4ItvzwWh5kBhXk2a8ejq3R5L4590mtMTTzeqV UZICRhwn7glfO4ZIDhKwGIzs2koLOOGUASx97hRzxVJDEUe1CIb9Hw9s0kWP+lDClmrn Lbsm3RAwvg++DZebV0Ena4UUvv8i9ioomkUoPyAIYfZjNy5YTPDSiql2qPoZhV9c5hPu koIxnB072SQfrfgHUxRA90Ha1t72LaJgM3bxIkWRGgXpxFUBO10R5RfyxHVGBhVdQrza mNLw== X-Gm-Message-State: AO0yUKXMh8zbvEPU7tEYsxLgPqh+NBDyGQnxGROQj92DauKwUZh6WFhz DZA10MJQFRtqLVXqEh1S6kR1loi4jzrR2CnMfKE= X-Google-Smtp-Source: AK7set887IVlMidrSuLGfY2dZL4kVI5y3BUQ5RUWfZctl2Wqy55tQwgnmj4miVIk9oVquF2GIPaC3w== X-Received: by 2002:a9d:588d:0:b0:685:134:b73d with SMTP id x13-20020a9d588d000000b006850134b73dmr3166169otg.23.1675361580228; Thu, 02 Feb 2023 10:13:00 -0800 (PST) Received: from mandiga.. ([2804:1b3:a7c2:1887:da12:b9d3:2162:a28c]) by smtp.gmail.com with ESMTPSA id ci10-20020a05683063ca00b00684a10970adsm126689otb.16.2023.02.02.10.12.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 02 Feb 2023 10:12:59 -0800 (PST) To: libc-alpha@sourceware.org, Richard Henderson , Jeff Law , Xi Ruoyao , Noah Goldstein Subject: [PATCH v12 27/31] string: Hook up the default implementation on test-stpcpy Date: Thu, 2 Feb 2023 15:11:45 -0300 Message-Id: <20230202181149.2181553-28-adhemerval.zanella@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230202181149.2181553-1-adhemerval.zanella@linaro.org> References: <20230202181149.2181553-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" Reviewed-by: Richard Henderson --- string/test-stpcpy.c | 32 +++++++++++++++++++++----------- 1 file changed, 21 insertions(+), 11 deletions(-) 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 Thu Feb 2 18:11: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: 64190 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 D456B382E6B2 for ; Thu, 2 Feb 2023 18:22:33 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org D456B382E6B2 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1675362153; bh=OL/nmtaNoSYIPMw63VnOCBfX+pGM1wE/+KBtx1BSXX0=; 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=L4W9olyPtbPQaKdDlPI7MJt+4ESm2ZTbblcGf0mRYP9G5trXvpWvqfq7a+96nUZAo E9GfctWeDmEMuG8oMefhqn3aWYc/zjbw1VOAFDC4cy8kyxMtq7JDEHgGUiwIV1Myw8 mNw3v2CzZysSFCaC9LVP6QAIr43x0+p1Jr7YY3N8= 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 7660B38493C9 for ; Thu, 2 Feb 2023 18:13:03 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 7660B38493C9 Received: by mail-ot1-x32d.google.com with SMTP id r34-20020a05683044a200b0068d4a8a8d2dso686186otv.12 for ; Thu, 02 Feb 2023 10:13:03 -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=OL/nmtaNoSYIPMw63VnOCBfX+pGM1wE/+KBtx1BSXX0=; b=ONoS0BkssKqXOSCYq/KKhNna8PfazPLDf1YsO9/1dx2woaMPNsdHesY1nFJX4Dgxyx fyO5C5M59V4kNflMGzKOOScwNiExTS3QumYxQCgNNdJ2XDZzkcfhzVmAFPnorbuUbrco AwnsetigXYQ5cKcKn8PfQGvPIZfnbZULKFRz4blCqlbZ9gUt+Q1mktl91IqL+8J/ziOn XLSnvLpfDbMqudOo5EPNxeglcWEN1qctvObCg4HtjN8ux96v2ULYOrPscCGykfosYJOm kG6tPWMtOUF1Lu/FemJjjsh058CdCOkff19VnvA5aYL6aVYSIlJ05tXkuE0TEAGRRzi8 O9/Q== X-Gm-Message-State: AO0yUKWNuTmka3dVlFOr3cswWZ4cS4rUx1WWvyrCePX9XZt4+t3wFvBh h67OsEFzapuyTejvRcFnR6OmJZjA9D1v6WYNPts= X-Google-Smtp-Source: AK7set85rq8ai3NrL/1JUlW1Oy4OagDLQaVKfht1BLtk+a/6dKgDqRsGhBfmseNXAGlxxKDCf+mnRg== X-Received: by 2002:a05:6830:30a5:b0:68b:d40e:e21f with SMTP id g37-20020a05683030a500b0068bd40ee21fmr3292239ots.34.1675361582468; Thu, 02 Feb 2023 10:13:02 -0800 (PST) Received: from mandiga.. ([2804:1b3:a7c2:1887:da12:b9d3:2162:a28c]) by smtp.gmail.com with ESMTPSA id ci10-20020a05683063ca00b00684a10970adsm126689otb.16.2023.02.02.10.13.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 02 Feb 2023 10:13:01 -0800 (PST) To: libc-alpha@sourceware.org, Richard Henderson , Jeff Law , Xi Ruoyao , Noah Goldstein Subject: [PATCH v12 28/31] string: Hook up the default implementation on test-strcpy Date: Thu, 2 Feb 2023 15:11:46 -0300 Message-Id: <20230202181149.2181553-29-adhemerval.zanella@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230202181149.2181553-1-adhemerval.zanella@linaro.org> References: <20230202181149.2181553-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" Reviewed-by: Richard Henderson --- string/test-strcpy.c | 34 ++++++++++++++++++++++++---------- 1 file changed, 24 insertions(+), 10 deletions(-) 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 Thu Feb 2 18:11: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: 64172 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 BB16F388883C for ; Thu, 2 Feb 2023 18:14:52 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org BB16F388883C DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1675361692; bh=y0lWmX08mljxv5oNTaThg5yPPAYl7+FH1A0aW7U6Dbc=; 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=UcfLlimB2SyIaftx2S+FPWHwawm2+FAG4k0yCSW2qfXP8zOdWwmPDWks4NuwSv+hO yfzVScIbj855hF9/erwPXOZtwDOmMBil41gW5wrqOYqzFwV/iyZNfdy3dJf6RW6YnS bJ3NpTCpVcWkvGgzQNBVP8rp9XWzs24qYeqxCaoA= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-ot1-x331.google.com (mail-ot1-x331.google.com [IPv6:2607:f8b0:4864:20::331]) by sourceware.org (Postfix) with ESMTPS id 7FC143844066 for ; Thu, 2 Feb 2023 18:13:05 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 7FC143844066 Received: by mail-ot1-x331.google.com with SMTP id k91-20020a9d19e4000000b0068bca1294aaso690805otk.8 for ; Thu, 02 Feb 2023 10:13:05 -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=y0lWmX08mljxv5oNTaThg5yPPAYl7+FH1A0aW7U6Dbc=; b=FJM70yUCNuBQleOJAr177yBaaAZX60SUPTkXP4Qqkkx06ERYJYPnCkt7dvPNlO5coV LjiDCrzBcqleRAeWe/vlAFvWw3PuVWLmtQyWrWFSHO5z+EA2tsBH53O2i/WnZpvDmamN qrkknhEg4DZxMp5C0npNiX6kDQPn8GQ1QnrdZzMbCCM0cCpxtRkgFQXe18Y06d6jEThJ FBJuoVKJDqu8x58VxIKUPe9V6iZdBGB1COtb1wTFY07VEO1q8Mbf0lwrKGIjen9oPVpH bhKMjbEzmT1vnNJlaZtslFEZAeEsnevLGiWBe/9hsjEJfCC8w+ryWzaQpRr+BALvPjSe m21Q== X-Gm-Message-State: AO0yUKX6Oc72+moQPVJMz5UiNVJerrfPg2NWOVoIy01QXK9F3m35FfOB ZuOVQD0WNUJNFuIE2SelDMK43NeGk9uV/UQBgiU= X-Google-Smtp-Source: AK7set+XXMsQlBU1ncoICQ/s4gule+RRoOoFUk2IhNMMBEbCejs4Q8BJmbMNAgV4pYaEZjxoKtdAdg== X-Received: by 2002:a05:6830:1d81:b0:68b:dd4e:256c with SMTP id y1-20020a0568301d8100b0068bdd4e256cmr4204395oti.0.1675361584698; Thu, 02 Feb 2023 10:13:04 -0800 (PST) Received: from mandiga.. ([2804:1b3:a7c2:1887:da12:b9d3:2162:a28c]) by smtp.gmail.com with ESMTPSA id ci10-20020a05683063ca00b00684a10970adsm126689otb.16.2023.02.02.10.13.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 02 Feb 2023 10:13:04 -0800 (PST) To: libc-alpha@sourceware.org, Richard Henderson , Jeff Law , Xi Ruoyao , Noah Goldstein Subject: [PATCH v12 29/31] string: Hook up the default implementation on test-memchr Date: Thu, 2 Feb 2023 15:11:47 -0300 Message-Id: <20230202181149.2181553-30-adhemerval.zanella@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230202181149.2181553-1-adhemerval.zanella@linaro.org> References: <20230202181149.2181553-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 Thu Feb 2 18:11: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: 64191 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 04436392AC3F for ; Thu, 2 Feb 2023 18:23:15 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 04436392AC3F DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1675362195; bh=vKKqKa5eSCgnSIEIB7xc5yTjbSsIz+O5sUXfGiVrmKc=; 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=vanbHA0ke7zb4mz7NjGwAx7Lxy4N4G02vwqjuU+FpRwiBBZJs00UUFXyvH7E95wto xw/qqdgupUMPE58u66YxGqJ+Tg2k5gA9U5F0cNjFzNZbxKr3Y3dcRXkhuQjZkIhpzo hNOVE0Pamssfo8WPaHGMMiiO4h/Y1euT75NWtLRA= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-ot1-x331.google.com (mail-ot1-x331.google.com [IPv6:2607:f8b0:4864:20::331]) by sourceware.org (Postfix) with ESMTPS id E1AA5384406A for ; Thu, 2 Feb 2023 18:13:07 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org E1AA5384406A Received: by mail-ot1-x331.google.com with SMTP id k91-20020a9d19e4000000b0068bca1294aaso690839otk.8 for ; Thu, 02 Feb 2023 10:13: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=vKKqKa5eSCgnSIEIB7xc5yTjbSsIz+O5sUXfGiVrmKc=; b=wDcMISYOSloQyHJ4HErPVpKBccybaBaPvKInIrh++Gr8xJro4F5NbI9PfCu1eVqzO7 6+5mCuaY1/BBUc1nT3BEOPjBpVjpF9DdXxad72l1d1Q1OVtYhJwanDaSMSBuvw+UnFkI ZT7B+bdu5SIztBoUrWNfGPvslzelPKnq9GrDYjz+PHF7V8R/IK3MjyQK0eU6PnJzpBFG JOpESVQzsV36qirtO0xFnBi5RsHvgAIuTJphKkyXfboJEybxbeA5+bBXf6LPCrNmiXCu fA7oqetmFmTw5do4V7mRW2A3PjdToKYP0hmOdhAecgcEY75WPOL0HDlnmIfDHPeGzbeI 0jGw== X-Gm-Message-State: AO0yUKVqeRj/UoO+uas9+o1FdMwMzEmMGZZ7vqu+WGIoa4RFV/WD75u4 Pl8RJqBmMRiJ6kfq5mC5GDMrAKx4DoztNYwZxZA= X-Google-Smtp-Source: AK7set9PDc7ylMze3H3U9aLo3bGG+eFx2aTB//fHW3svCXkMNowX+UD3jHhloShiZfmMcHY+KSgvCw== X-Received: by 2002:a05:6830:658c:b0:68b:a89a:ab7 with SMTP id cn12-20020a056830658c00b0068ba89a0ab7mr4846904otb.15.1675361587005; Thu, 02 Feb 2023 10:13:07 -0800 (PST) Received: from mandiga.. ([2804:1b3:a7c2:1887:da12:b9d3:2162:a28c]) by smtp.gmail.com with ESMTPSA id ci10-20020a05683063ca00b00684a10970adsm126689otb.16.2023.02.02.10.13.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 02 Feb 2023 10:13:06 -0800 (PST) To: libc-alpha@sourceware.org, Richard Henderson , Jeff Law , Xi Ruoyao , Noah Goldstein Subject: [PATCH v12 30/31] string: Hook up the default implementation on test-memrchr Date: Thu, 2 Feb 2023 15:11:48 -0300 Message-Id: <20230202181149.2181553-31-adhemerval.zanella@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230202181149.2181553-1-adhemerval.zanella@linaro.org> References: <20230202181149.2181553-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" Reviewed-by: Richard Henderson --- string/test-memrchr.c | 7 +++++++ 1 file changed, 7 insertions(+) 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) From patchwork Thu Feb 2 18:11: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: 64176 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 CE1DE3846054 for ; Thu, 2 Feb 2023 18:15:34 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org CE1DE3846054 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1675361734; bh=84s2cdQFH8ThfW1Y+HDXwNcet8gOIqmO0wxEXttSTec=; 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=NCnfItAZoGtz/+O8+qy+CyEm0BAjaGxC7/BGWjEywUP0mSf2HmPkQmC9/i2FlQFb2 yxYCsV3XHPCRp5pnPnHbJW55pDwGl4/aZHEeo9Df4awcX5vxKTYZfUl2OXtWjKFX9b nkj2wPzBVYQ6jYX8dW7iu8rtvBCo25GnNlwQftlk= 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 6BB9D3882117 for ; Thu, 2 Feb 2023 18:13:10 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 6BB9D3882117 Received: by mail-oi1-x229.google.com with SMTP id bj22so2109308oib.11 for ; Thu, 02 Feb 2023 10:13: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=84s2cdQFH8ThfW1Y+HDXwNcet8gOIqmO0wxEXttSTec=; b=aoh2of3jChOVDbCUOmniKlHRTLws3pv1EDOn/J1bGrE5XVQ8yB1g0NE+u8Vpof7XcN NJ8dXZBo758mTN6BLV7YC2abWe7ZqVqN87aV5rfirB1zIyJJwxtGEh0Jn6qZ7OegTCBh buoiX95R0BDFEOFAuZtZ+Z98DHnfG0B70vqxuKNRjIpJs4ypXbjR0x0m3t5rwUki0zhn OSxWH4dXcsyzW4SUVhTgfONUK8Ox9t0vEW5xRxn1quPNeD71HUYIWeXLhTw51mIbqvg2 M6M0KtUyuWhQQydmhyBS52HmJ6bBaYdhg8QiBacOoCqnczDEbazBJxTKGFHjIfNHmu0p Yvpg== X-Gm-Message-State: AO0yUKUSHG7e9apmrUjAFpWOhCGOojgt8sY8xXhrzGV+zJU4U1Iazahx XqopOhwzOZEvrk2uW+wOndPoWz4aJu2H29/p/2U= X-Google-Smtp-Source: AK7set+URSMAQoTjSP2tOi0tlpV6v7G6nr4vA5qZa8ZfjYx6fXZgMYr2pxoZXPpv9tOkFll93yTzng== X-Received: by 2002:a05:6808:190f:b0:360:e80e:26a9 with SMTP id bf15-20020a056808190f00b00360e80e26a9mr4250141oib.12.1675361589233; Thu, 02 Feb 2023 10:13:09 -0800 (PST) Received: from mandiga.. ([2804:1b3:a7c2:1887:da12:b9d3:2162:a28c]) by smtp.gmail.com with ESMTPSA id ci10-20020a05683063ca00b00684a10970adsm126689otb.16.2023.02.02.10.13.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 02 Feb 2023 10:13:08 -0800 (PST) To: libc-alpha@sourceware.org, Richard Henderson , Jeff Law , Xi Ruoyao , Noah Goldstein Subject: [PATCH v12 31/31] string: Hook up the default implementation on test-strrchr Date: Thu, 2 Feb 2023 15:11:49 -0300 Message-Id: <20230202181149.2181553-32-adhemerval.zanella@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230202181149.2181553-1-adhemerval.zanella@linaro.org> References: <20230202181149.2181553-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_STRRCHR, which is not used anywhere. Reviewed-by: Richard Henderson --- string/test-strrchr.c | 38 ++++++++++++++++++++++++-------------- 1 file changed, 24 insertions(+), 14 deletions(-) diff --git a/string/test-strrchr.c b/string/test-strrchr.c index 2cd5de42cd..c979574c92 100644 --- a/string/test-strrchr.c +++ b/string/test-strrchr.c @@ -26,14 +26,12 @@ #ifdef WIDE # include -# define SIMPLE_STRRCHR simple_wcsrchr # define STRRCHR wcsrchr # define CHAR wchar_t # define UCHAR wchar_t # define BIG_CHAR WCHAR_MAX # define SMALL_CHAR 1273 #else -# define SIMPLE_STRRCHR simple_strrchr # define STRRCHR strrchr # define CHAR char # define UCHAR unsigned char @@ -45,18 +43,30 @@ typedef CHAR *(*proto_t) (const CHAR *, int); IMPL (STRRCHR, 1) -/* Naive implementation to verify results. */ -CHAR * -SIMPLE_STRRCHR (const CHAR *s, int c) -{ - const CHAR *ret = NULL; - - for (; *s != '\0'; ++s) - if (*s == (CHAR) c) - ret = s; - - return (CHAR *) (c == '\0' ? s : ret); -} +/* Also check the generic implementation. */ +#undef STRRCHR +#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 STRLEN __strlen_default +# include "string/strlen.c" +# define MEMRCHR __memrchr_default +# include "string/memrchr.c" +# define STRRCHR __strrchr_default +# include "string/strrchr.c" +# define STRRCHR_DEFAULT __strrchr_default +#else +# define WCSRCHR __wcsrchr_default +# include "wcsmbs/wcsrchr.c" +# define STRRCHR_DEFAULT __wcsrchr_default +#endif +IMPL (STRRCHR_DEFAULT, 1) static void do_one_test (impl_t *impl, const CHAR *s, int c, CHAR *exp_res)