From patchwork Fri Jan 20 21:15:59 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adhemerval Zanella X-Patchwork-Id: 1729825 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=sourceware.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=sourceware.org; envelope-from=libc-alpha-bounces+incoming=patchwork.ozlabs.org@sourceware.org; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; secure) header.d=sourceware.org header.i=@sourceware.org header.a=rsa-sha256 header.s=default header.b=nA/iaDui; dkim-atps=neutral Received: from sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4NzC425b8sz23gV for ; Sat, 21 Jan 2023 08:16:50 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 6D068385B509 for ; Fri, 20 Jan 2023 21:16:48 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 6D068385B509 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1674249408; 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=nA/iaDuiQyHwyyQuYc7s5+azBJSE8F4Fp6BMj4SgwJkXZ0we77wXcJM9FJSDYfTo0 aacld9lzP4c7QpD04+JeSMK/jziG/nDKIhGzEgdOcOCrNXMJo3bz4p7D1Bqet0sWV1 vf393Y3AeKYJalBP0e15rbeEUa8UgETDkhu578Bc= 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 2635C3858433 for ; Fri, 20 Jan 2023 21:16:32 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 2635C3858433 Received: by mail-oi1-x236.google.com with SMTP id v17so5496992oie.5 for ; Fri, 20 Jan 2023 13:16:32 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=AjKGR2n03+tuVqqBGNtzj55eB24LbWfBk9DVbP0bD/k=; b=TBJo8B4dCjYh1hcUVpHw+gWro/yVGKJ+YXTHv3JZ3YwHL2dtmZmpJui/gUdwCs3CVk xzc3PnnIqqnCyQ/g8mvxcWjo/j3lQZqdudi1buVDIx2f7h9u/tKIoj2vvSVGJEGVzJyf PU2aMPgG+BUgon8ln2uSeaxS9KBA9C3HJygS0zqiSJ3IhWjTUVZMMbg/7WD7zjAkb1O2 S/ynCrvg2pilOuStFxCq6nRExfROnS6+LXlyY+jbVd6UyrbSA6JPaC34Ew0+DQFnznWJ FXoDUMOHV4cAVIW5WDc46CiM7yyLvSwpYmuJ4OtLUj4qS6uUp+jkEy5FJ0vVxNSoarOp PsDw== X-Gm-Message-State: AFqh2kpcfv4/6eQtCMGUG7YI2XmtKwRCYzYFBYH+lLkhOwh8M6m5CxV2 ilvk9wFyfK0OUtjXcwaEtx4QW8h9OeiUsaa8eK0= X-Google-Smtp-Source: AMrXdXusz7jTlQKut8gaMasS5MOv/jyBDyBUzJXFSvwRF2D2asgNGR2O2zhH3mUxickv/E0vCvVweA== X-Received: by 2002:a05:6808:247:b0:364:f951:1a63 with SMTP id m7-20020a056808024700b00364f9511a63mr7690992oie.36.1674249390866; Fri, 20 Jan 2023 13:16:30 -0800 (PST) Received: from mandiga.. ([2804:1b3:a7c1:7e99:f284:be2f:4ee5:d122]) by smtp.gmail.com with ESMTPSA id d18-20020a056830139200b00686467f920bsm6937432otq.48.2023.01.20.13.16.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 20 Jan 2023 13:16:30 -0800 (PST) To: libc-alpha@sourceware.org, Richard Henderson , Noah Goldstein Subject: [PATCH v10 01/24] Parameterize op_t from memcopy.h Date: Fri, 20 Jan 2023 18:15:59 -0300 Message-Id: <20230120211622.3445279-2-adhemerval.zanella@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230120211622.3445279-1-adhemerval.zanella@linaro.org> References: <20230120211622.3445279-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 Reply-To: Adhemerval Zanella Errors-To: libc-alpha-bounces+incoming=patchwork.ozlabs.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 Fri Jan 20 21:16:00 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adhemerval Zanella X-Patchwork-Id: 1729826 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=sourceware.org (client-ip=8.43.85.97; helo=sourceware.org; envelope-from=libc-alpha-bounces+incoming=patchwork.ozlabs.org@sourceware.org; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; secure) header.d=sourceware.org header.i=@sourceware.org header.a=rsa-sha256 header.s=default header.b=lCa5SGNh; dkim-atps=neutral Received: from sourceware.org (ip-8-43-85-97.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4NzC4G6Gq2z23gV for ; Sat, 21 Jan 2023 08:17:02 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 76170383FBAF for ; Fri, 20 Jan 2023 21:17:00 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 76170383FBAF DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1674249420; 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=lCa5SGNhtxMBkEPjgxv44X4LdkaByC9oGfECB0+NZATE3cfYT+9/2BZM96ekKvFwH FSqpG4SI5ZZK9GxJwx+d7dj2cerMY0pZtQfmv8GRU7vruqby6E5hA9jp7oGCU3w30L CheGTM3RBN+PgdfcfnnVnouEx5oTpDGWjyMSzYeQ= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-ot1-x32e.google.com (mail-ot1-x32e.google.com [IPv6:2607:f8b0:4864:20::32e]) by sourceware.org (Postfix) with ESMTPS id BBF8438654B5 for ; Fri, 20 Jan 2023 21:16:34 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org BBF8438654B5 Received: by mail-ot1-x32e.google.com with SMTP id cm26-20020a056830651a00b00684e5c0108dso3819106otb.9 for ; Fri, 20 Jan 2023 13:16:34 -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=S8Ihq7Oa65DqQp6Tz/+wNXV8xhvoIEabYc2dZ9NovMNUJIysV7UAMYD2kepyBVQfwB GLORAKVYHoUQ/58c+w2aI6DalkOICiBfXBKL76gMbQeqTfjuNaJpYsPd0Doz/iFvhPIN o9BRXEwqbGmZclKDtGtq4DDuFcD/gMCUL6PB0fqmgjMK4aPJH+ux+0oy/GBAxopBTmyK meUXWj6Ecr7xqi/V6NfbvcqXSUcfX3jL+1yd8/3RzaLYcZDLX2ef8a/T5lDo8o7tWCTP pVut09Rk2ztss9lWjfje9YuC8oneJRLon6x1Zx40y8iLoK4YSb0MXCcnQ3/lxS/af7BV MhTA== X-Gm-Message-State: AFqh2ko5lqyucUX/fBB5tdhse7uxqM+/fx3tUluURKTT00EgnOm0tOXz 4UVJB69V4lK7BM9c0ywwQPsTNZS2WgDjAY4Q3ps= X-Google-Smtp-Source: AMrXdXsejk3u/eFF0UtgZgC8qQ26QstQnR520zemUHw+2+EP/PDQaDPWjHoPGALhWvIBfV1ZuSFlbA== X-Received: by 2002:a05:6830:40b2:b0:686:5afb:5ed with SMTP id x50-20020a05683040b200b006865afb05edmr5092084ott.1.1674249393388; Fri, 20 Jan 2023 13:16:33 -0800 (PST) Received: from mandiga.. ([2804:1b3:a7c1:7e99:f284:be2f:4ee5:d122]) by smtp.gmail.com with ESMTPSA id d18-20020a056830139200b00686467f920bsm6937432otq.48.2023.01.20.13.16.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 20 Jan 2023 13:16:32 -0800 (PST) To: libc-alpha@sourceware.org, Richard Henderson , Noah Goldstein Cc: Carlos O'Donell Subject: [PATCH v10 02/24] Parameterize OP_T_THRES from memcopy.h Date: Fri, 20 Jan 2023 18:16:00 -0300 Message-Id: <20230120211622.3445279-3-adhemerval.zanella@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230120211622.3445279-1-adhemerval.zanella@linaro.org> References: <20230120211622.3445279-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 Reply-To: Adhemerval Zanella Errors-To: libc-alpha-bounces+incoming=patchwork.ozlabs.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 Fri Jan 20 21:16:01 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adhemerval Zanella X-Patchwork-Id: 1729827 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=sourceware.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=sourceware.org; envelope-from=libc-alpha-bounces+incoming=patchwork.ozlabs.org@sourceware.org; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; secure) header.d=sourceware.org header.i=@sourceware.org header.a=rsa-sha256 header.s=default header.b=bAj/+iNI; dkim-atps=neutral Received: from sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4NzC4K455sz23gV for ; Sat, 21 Jan 2023 08:17:05 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 89DAA3881D0F for ; Fri, 20 Jan 2023 21:17:03 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 89DAA3881D0F DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1674249423; bh=LkBuyLP0sOoxDn4wxkTUVOGoOVk76bq7qy7crcPg9ZA=; h=To:Subject:Date:In-Reply-To:References:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=bAj/+iNIULg2p/kUEwvP21UyT7QDZIHM1jBPcTaEQJ6cYOMGu3hYTGUvs+ArmnwHJ IzLSnhYTGeP6A9gulQV36Kc+eWDng/MU/8judondFyxzX91+0C2wtliYYpKcXmpK7J iEyM287TUpWJ2mQlXRRTlvKFBbZrGCPK0j4KuslM= 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 0155F38493C7 for ; Fri, 20 Jan 2023 21:16:37 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 0155F38493C7 Received: by mail-ot1-x32d.google.com with SMTP id k1-20020a056830150100b006864d1cb279so3813514otp.5 for ; Fri, 20 Jan 2023 13:16:36 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=LkBuyLP0sOoxDn4wxkTUVOGoOVk76bq7qy7crcPg9ZA=; b=KBBg2wLsfT9BidDH/xZFl8rpkcnxqzFek2WfVNUTcG7WYZLNFSfDNRo0FFEU4HFM3e 5ha8IKCmfDRSm9dBZxNJelQAmVdRPWtzci4GieS5B26VGeiJlt4OCD29ZJt5VhqIRCgU dGO10wZFGG0rSpyVgVBQrXd38A2VB5iubjQO2fa8bdj6g5K8fFlRa9FYK8bbCwiOjJ6T 118Mc3LbXXa1c3Y1boN7ieb8Vz5SpYdNiBNC6XwUvFCUeoJzR5Iw5DjImzeIpoqme1Ej stj7HJtHDurCKIirdGWJHQzwegcNY+sJUs7+RVwMnDFQGlxJK95Ow3kYzS7QGWrW6MQI 7F+w== X-Gm-Message-State: AFqh2kqsr2h2vEbJKRqZPz+PV1DEJ90+s0/8jsnC0Y+0Roe/Y2eNA78Y aTTe/IVn9GCXv3seOW2PW3qRe2/42vq0vR4dDw0= X-Google-Smtp-Source: AMrXdXtCdCf+cVwdaLvRxIQCg7dJmOtJLFT6BYhyae4L8Gxir36kFKdAZlr1wE9o9xv42pbTM2NmiA== X-Received: by 2002:a05:6830:670a:b0:684:e1cb:df87 with SMTP id cr10-20020a056830670a00b00684e1cbdf87mr9840887otb.8.1674249395428; Fri, 20 Jan 2023 13:16:35 -0800 (PST) Received: from mandiga.. ([2804:1b3:a7c1:7e99:f284:be2f:4ee5:d122]) by smtp.gmail.com with ESMTPSA id d18-20020a056830139200b00686467f920bsm6937432otq.48.2023.01.20.13.16.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 20 Jan 2023 13:16:34 -0800 (PST) To: libc-alpha@sourceware.org, Richard Henderson , Noah Goldstein Subject: [PATCH v10 03/24] Add string vectorized find and detection functions Date: Fri, 20 Jan 2023 18:16:01 -0300 Message-Id: <20230120211622.3445279-4-adhemerval.zanella@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230120211622.3445279-1-adhemerval.zanella@linaro.org> References: <20230120211622.3445279-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 Reply-To: Adhemerval Zanella Errors-To: libc-alpha-bounces+incoming=patchwork.ozlabs.org@sourceware.org Sender: "Libc-alpha" This patch adds generic string find and detection meant to be used in generic vectorized string implementation. The idea is to decompose the basic string operation so each architecture can reimplement if it provides any specialized hardware instruction. The 'string-misc.h' provides miscellaneous functions: - extractbyte: extracts the byte from an specific index. - repeat_bytes: setup an word by replicate the argument on each byte. The 'string-fza.h' provides zero byte detection functions: - find_zero_low, find_zero_all, find_eq_low, find_eq_all, find_zero_eq_low, find_zero_eq_all, find_zero_ne_low, and find_zero_ne_all The 'string-fzb.h' provides boolean zero byte detection functions: - has_zero: determine if any byte within a word is zero. - has_eq: determine byte equality between two words. - has_zero_eq: determine if any byte within a word is zero along with byte equality between two words. The 'string-fzi.h' provides positions for string-fza.h results: - index_first: return index of first zero byte within a word. - index_last: return index of first byte different between two words. The 'string-fzc.h' provides a combined version of fza and fzi: - index_first_zero_eq: return index of first zero byte within a word or first byte different between two words. - index_first_zero_ne: return index of first zero byte within a word or first byte equal between two words. - index_last_zero: return index of last zero byte within a word. - index_last_eq: return index of last byte different between two words. The 'string-shift.h' provides a way to mask off parts of a work based on some alignmnet (to handle unaligned arguments): - shift_find, shift_find_last. Co-authored-by: Richard Henderson --- sysdeps/generic/string-fza.h | 104 +++++++++++++++++++++++++++++++++ sysdeps/generic/string-fzb.h | 49 ++++++++++++++++ sysdeps/generic/string-fzc.h | 91 +++++++++++++++++++++++++++++ sysdeps/generic/string-fzi.h | 71 ++++++++++++++++++++++ sysdeps/generic/string-misc.h | 45 ++++++++++++++ sysdeps/generic/string-shift.h | 52 +++++++++++++++++ 6 files changed, 412 insertions(+) create mode 100644 sysdeps/generic/string-fza.h create mode 100644 sysdeps/generic/string-fzb.h create mode 100644 sysdeps/generic/string-fzc.h create mode 100644 sysdeps/generic/string-fzi.h create mode 100644 sysdeps/generic/string-misc.h create mode 100644 sysdeps/generic/string-shift.h diff --git a/sysdeps/generic/string-fza.h b/sysdeps/generic/string-fza.h new file mode 100644 index 0000000000..b5a5536f73 --- /dev/null +++ b/sysdeps/generic/string-fza.h @@ -0,0 +1,104 @@ +/* Basic zero byte detection. Generic C version. + Copyright (C) 2023 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, see + . */ + +#ifndef _STRING_FZA_H +#define _STRING_FZA_H 1 + +#include +#include + +/* The function return a byte mask. */ +typedef op_t find_t; + +/* This function returns non-zero if any byte in X is zero. + More specifically, at least one bit set within the least significant + byte that was zero; other bytes within the word are indeterminate. */ +static __always_inline find_t +find_zero_low (op_t x) +{ + /* This expression comes from + https://graphics.stanford.edu/~seander/bithacks.html#ZeroInWord + Subtracting 1 sets 0x80 in a byte that was 0; anding ~x clears + 0x80 in a byte that was >= 128; anding 0x80 isolates that test bit. */ + op_t lsb = repeat_bytes (0x01); + op_t msb = repeat_bytes (0x80); + return (x - lsb) & ~x & msb; +} + +/* This function returns at least one bit set within every byte of X that + is zero. The result is exact in that, unlike find_zero_low, all bytes + are determinate. This is usually used for finding the index of the + most significant byte that was zero. */ +static __always_inline find_t +find_zero_all (op_t x) +{ + /* For each byte, find not-zero by + (0) And 0x7f so that we cannot carry between bytes, + (1) Add 0x7f so that non-zero carries into 0x80, + (2) Or in the original byte (which might have had 0x80 set). + Then invert and mask such that 0x80 is set iff that byte was zero. */ + op_t m = repeat_bytes (0x7f); + return ~(((x & m) + m) | x | m); +} + +/* With similar caveats, identify bytes that are equal between X1 and X2. */ +static __always_inline find_t +find_eq_low (op_t x1, op_t x2) +{ + return find_zero_low (x1 ^ x2); +} + +static __always_inline find_t +find_eq_all (op_t x1, op_t x2) +{ + return find_zero_all (x1 ^ x2); +} + +/* With similar caveats, identify zero bytes in X1 and bytes that are + equal between in X1 and X2. */ +static __always_inline find_t +find_zero_eq_low (op_t x1, op_t x2) +{ + return find_zero_low (x1) | find_zero_low (x1 ^ x2); +} + +static __always_inline find_t +find_zero_eq_all (op_t x1, op_t x2) +{ + return find_zero_all (x1) | find_zero_all (x1 ^ x2); +} + +/* With similar caveats, identify zero bytes in X1 and bytes that are + not equal between in X1 and X2. */ +static __always_inline find_t +find_zero_ne_low (op_t x1, op_t x2) +{ + return (~find_zero_eq_low (x1, x2)) + 1; +} + +static __always_inline find_t +find_zero_ne_all (op_t x1, op_t x2) +{ + op_t m = repeat_bytes (0x7f); + op_t eq = x1 ^ x2; + op_t nz1 = ((x1 & m) + m) | x1; + op_t ne2 = ((eq & m) + m) | eq; + return (ne2 | ~nz1) & ~m; +} + +#endif /* _STRING_FZA_H */ diff --git a/sysdeps/generic/string-fzb.h b/sysdeps/generic/string-fzb.h new file mode 100644 index 0000000000..42de500d67 --- /dev/null +++ b/sysdeps/generic/string-fzb.h @@ -0,0 +1,49 @@ +/* Zero byte detection, boolean. Generic C version. + Copyright (C) 2023 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, see + . */ + +#ifndef _STRING_FZB_H +#define _STRING_FZB_H 1 + +#include +#include + +/* Determine if any byte within X is zero. This is a pure boolean test. */ + +static __always_inline _Bool +has_zero (op_t x) +{ + return find_zero_low (x) != 0; +} + +/* Likewise, but for byte equality between X1 and X2. */ + +static __always_inline _Bool +has_eq (op_t x1, op_t x2) +{ + return find_eq_low (x1, x2) != 0; +} + +/* Likewise, but for zeros in X1 and equal bytes between X1 and X2. */ + +static __always_inline _Bool +has_zero_eq (op_t x1, op_t x2) +{ + return find_zero_eq_low (x1, x2); +} + +#endif /* _STRING_FZB_H */ diff --git a/sysdeps/generic/string-fzc.h b/sysdeps/generic/string-fzc.h new file mode 100644 index 0000000000..f159254535 --- /dev/null +++ b/sysdeps/generic/string-fzc.h @@ -0,0 +1,91 @@ +/* Zero byte detection; indexes. Generic C version. + Copyright (C) 2023 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, see + . */ + +#ifndef _STRING_FZC_H +#define _STRING_FZC_H 1 + +#include +#include +#include + + +/* Given a word X that is known to contain a zero byte, return the index of + the first such within the word in memory order. */ +static __always_inline unsigned int +index_first_zero (op_t x) +{ + if (__BYTE_ORDER == __LITTLE_ENDIAN) + x = find_zero_low (x); + else + x = find_zero_all (x); + return index_first (x); +} + +/* Similarly, but perform the search for byte equality between X1 and X2. */ +static __always_inline unsigned int +index_first_eq (op_t x1, op_t x2) +{ + if (__BYTE_ORDER == __LITTLE_ENDIAN) + x1 = find_eq_low (x1, x2); + else + x1 = find_eq_all (x1, x2); + return index_first (x1); +} + +/* Similarly, but perform the search for zero within X1 or equality between + X1 and X2. */ +static __always_inline unsigned int +index_first_zero_eq (op_t x1, op_t x2) +{ + if (__BYTE_ORDER == __LITTLE_ENDIAN) + x1 = find_zero_eq_low (x1, x2); + else + x1 = find_zero_eq_all (x1, x2); + return index_first (x1); +} + +/* Similarly, but perform the search for zero within X1 or inequality between + X1 and X2. */ +static __always_inline unsigned int +index_first_zero_ne (op_t x1, op_t x2) +{ + if (__BYTE_ORDER == __LITTLE_ENDIAN) + x1 = find_zero_ne_low (x1, x2); + else + x1 = find_zero_ne_all (x1, x2); + return index_first (x1); +} + +/* Similarly, but search for the last zero within X. */ +static __always_inline unsigned int +index_last_zero (op_t x) +{ + if (__BYTE_ORDER == __LITTLE_ENDIAN) + x = find_zero_all (x); + else + x = find_zero_low (x); + return index_last (x); +} + +static __always_inline unsigned int +index_last_eq (op_t x1, op_t x2) +{ + return index_last_zero (x1 ^ x2); +} + +#endif /* STRING_FZC_H */ diff --git a/sysdeps/generic/string-fzi.h b/sysdeps/generic/string-fzi.h new file mode 100644 index 0000000000..2deecefc23 --- /dev/null +++ b/sysdeps/generic/string-fzi.h @@ -0,0 +1,71 @@ +/* Zero byte detection; indexes. Generic C version. + Copyright (C) 2023 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, see + . */ + +#ifndef _STRING_FZI_H +#define _STRING_FZI_H 1 + +#include +#include +#include + +static __always_inline int +clz (find_t c) +{ + if (sizeof (find_t) == sizeof (unsigned long)) + return __builtin_clzl (c); + else + return __builtin_clzll (c); +} + +static __always_inline int +ctz (find_t c) +{ + if (sizeof (find_t) == sizeof (unsigned long)) + return __builtin_ctzl (c); + else + return __builtin_ctzll (c); +} + +/* A subroutine for the index_zero functions. Given a test word C, return + the (memory order) index of the first byte (in memory order) that is + non-zero. */ +static __always_inline unsigned int +index_first (find_t c) +{ + int r; + if (__BYTE_ORDER == __LITTLE_ENDIAN) + r = ctz (c); + else + r = clz (c); + return r / CHAR_BIT; +} + +/* Similarly, but return the (memory order) index of the last byte that is + non-zero. */ +static __always_inline unsigned int +index_last (find_t c) +{ + int r; + if (__BYTE_ORDER == __LITTLE_ENDIAN) + r = clz (c); + else + r = ctz (c); + return sizeof (find_t) - 1 - (r / CHAR_BIT); +} + +#endif /* STRING_FZI_H */ diff --git a/sysdeps/generic/string-misc.h b/sysdeps/generic/string-misc.h new file mode 100644 index 0000000000..a119646957 --- /dev/null +++ b/sysdeps/generic/string-misc.h @@ -0,0 +1,45 @@ +/* Miscellaneous functions used in string implementations. Generic C version. + Copyright (C) 2023 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, see + . */ + +#ifndef _STRING_MISC_H +#define _STRING_MISC_H 1 + +#include +#include +#include + +/* Extract the byte at index IDX from word X, with index 0 being the + least significant byte. */ +static __always_inline unsigned char +extractbyte (op_t x, unsigned int idx) +{ + if (__BYTE_ORDER == __LITTLE_ENDIAN) + return x >> (idx * CHAR_BIT); + else + return x >> (sizeof (x) - 1 - idx) * CHAR_BIT; +} + +/* Setup an word with each byte being c_in. For instance, on a 64 bits + machine with input as 0xce the functions returns 0xcececececececece. */ +static __always_inline op_t +repeat_bytes (unsigned char c_in) +{ + return ((op_t)-1 / 0xff) * c_in; +} + +#endif /* _STRING_MISC_H */ diff --git a/sysdeps/generic/string-shift.h b/sysdeps/generic/string-shift.h new file mode 100644 index 0000000000..9491e8b580 --- /dev/null +++ b/sysdeps/generic/string-shift.h @@ -0,0 +1,52 @@ +/* Shift unaligned word read Generic C version. + Copyright (C) 2023 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, see + . */ + +#ifndef _STRING_SHIFT_H +#define _STRING_SHIFT_H 1 + +#include +#include +#include +#include + +/* Return the mask WORD shifted based on S_INT address value, to ignore + values not presented in the aligned word read. */ +static __always_inline find_t +shift_find (find_t word, uintptr_t s) +{ + if (__BYTE_ORDER == __LITTLE_ENDIAN) + return word >> (CHAR_BIT * (s % sizeof (op_t))); + else + return word << (CHAR_BIT * (s % sizeof (op_t))); +} + +/* Mask off the bits defined for the S alignment value, or return WORD if + S is 0. */ +static __always_inline find_t +shift_find_last (find_t word, uintptr_t s) +{ + s = s % sizeof (op_t); + if (s == 0) + return word; + if (__BYTE_ORDER == __LITTLE_ENDIAN) + return word & ~(((op_t)-1) << (s * CHAR_BIT)); + else + return word & ~(((op_t)-1) >> (s * CHAR_BIT)); +} + +#endif /* _STRING_SHIFT_H */ From patchwork Fri Jan 20 21:16:02 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adhemerval Zanella X-Patchwork-Id: 1729830 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=sourceware.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=sourceware.org; envelope-from=libc-alpha-bounces+incoming=patchwork.ozlabs.org@sourceware.org; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; secure) header.d=sourceware.org header.i=@sourceware.org header.a=rsa-sha256 header.s=default header.b=T9O9OJ++; dkim-atps=neutral Received: from sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4NzC5G2nfCz23gV for ; Sat, 21 Jan 2023 08:17:54 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 5843938543B8 for ; Fri, 20 Jan 2023 21:17:52 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 5843938543B8 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1674249472; bh=sM42ZXZutGLQv3kU8rv2m/t1uT6YlYdKjklNBZY9Pk4=; 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=T9O9OJ++8BVR+C6xm2zIdf144jb/wDqKc8UH+e5gStCvP639wJ9H7zMPCj6790+ne g2pyM1zRWd+dJnPFNuXqvSpc0viB2K/mwvWqxFDH8j7GpFJNNlTRllSl91CnTFkQSw EY9IvUcT43sHowXnqhwFArKsp6kwkuSwE1H26uGk= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-oi1-x22b.google.com (mail-oi1-x22b.google.com [IPv6:2607:f8b0:4864:20::22b]) by sourceware.org (Postfix) with ESMTPS id 2B8563858D33 for ; Fri, 20 Jan 2023 21:16:39 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 2B8563858D33 Received: by mail-oi1-x22b.google.com with SMTP id r9so5466170oig.12 for ; Fri, 20 Jan 2023 13:16:39 -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=sM42ZXZutGLQv3kU8rv2m/t1uT6YlYdKjklNBZY9Pk4=; b=ZxvxGn884o/hRJt24URZv9EaNmME1ZTo9evK9Oy6jMQzj1GNJ2DrjUEV84cgWbDw/t raGJ7J6TVjS+GvR6E95O3bO1skzdspKei+mnM/y7FbqXM6AtJ9ue8HSS829tTITr42cm 0vX0RcEqrbsqnnqDStEi4MovQVvHMWqae5ecu0eMKxU96+E5NEDnyFvg/WGdvRgxBDcC x5+0U7Z53Ap49bfZXv8F78JVatekdU5+KybLz+Nrg0F7MXVroLwntGwn3jFr0BZg/uky dKm9MkJkFB80D65UqivvhxX0MqicgfADFjWv2Wwd+95BuWasoUTK5mqY2v6lg1BdY9R7 X6qA== X-Gm-Message-State: AFqh2kp1DkWkGrZjaMnLOtc0OaAWlxs0jss3JoPy/QAH+inOMkK4tjNr uwP1D4lawiSCY/g6LcgFmbgIsMbGnHJVcQjSxtY= X-Google-Smtp-Source: AMrXdXvhGZaYHfutpKkTXygZEsu5yga69XHLhfZJFWDcfZHZOI6JGOYwAvhBr5rF/gqikKg15Vq+dw== X-Received: by 2002:aca:6187:0:b0:355:1de8:bc80 with SMTP id v129-20020aca6187000000b003551de8bc80mr7989568oib.34.1674249397744; Fri, 20 Jan 2023 13:16:37 -0800 (PST) Received: from mandiga.. ([2804:1b3:a7c1:7e99:f284:be2f:4ee5:d122]) by smtp.gmail.com with ESMTPSA id d18-20020a056830139200b00686467f920bsm6937432otq.48.2023.01.20.13.16.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 20 Jan 2023 13:16:36 -0800 (PST) To: libc-alpha@sourceware.org, Richard Henderson , Noah Goldstein Subject: [PATCH v10 04/24] string: Improve generic strlen Date: Fri, 20 Jan 2023 18:16:02 -0300 Message-Id: <20230120211622.3445279-5-adhemerval.zanella@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230120211622.3445279-1-adhemerval.zanella@linaro.org> References: <20230120211622.3445279-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 Reply-To: Adhemerval Zanella Errors-To: libc-alpha-bounces+incoming=patchwork.ozlabs.org@sourceware.org Sender: "Libc-alpha" New algorithm have the following key differences: - Reads first word unaligned and use string-maskoff functions to remove unwanted data. This strategy follow arch-specific optimization used on powerpc, sparc, and SH. - Use of has_zero and index_first_zero parametrized functions. 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 --- 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 Fri Jan 20 21:16:03 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adhemerval Zanella X-Patchwork-Id: 1729832 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=sourceware.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=sourceware.org; envelope-from=libc-alpha-bounces+incoming=patchwork.ozlabs.org@sourceware.org; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; secure) header.d=sourceware.org header.i=@sourceware.org header.a=rsa-sha256 header.s=default header.b=TkTHEQs4; dkim-atps=neutral Received: from sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4NzC5W1K3Tz23hH for ; Sat, 21 Jan 2023 08:18:07 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 1AC89385B524 for ; Fri, 20 Jan 2023 21:18:05 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 1AC89385B524 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1674249485; bh=TvRBnV0S6Wk5n31+1ekAFjNtk4F034TYW8aTedClA1M=; 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=TkTHEQs4iq3Wmgs3Sm3S3+h1CgyXrD1tvEGfQn0bR+Ruk1cHNPPvqf127w/1XivoT 1zIbTghpO5Dm4OpxRSzcTRcGH/2Z4jO67iLhBngTTn+AkDTQIavu2UQs0XWdnzgQTj Rqg8oumosWtlYdNX5A7CwsqpcGmm06itavZ3OAgI= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-ot1-x32e.google.com (mail-ot1-x32e.google.com [IPv6:2607:f8b0:4864:20::32e]) by sourceware.org (Postfix) with ESMTPS id 542C4385841E for ; Fri, 20 Jan 2023 21:16:41 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 542C4385841E Received: by mail-ot1-x32e.google.com with SMTP id f5-20020a9d5f05000000b00684c0c2eb3fso3810342oti.10 for ; Fri, 20 Jan 2023 13:16:41 -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=TvRBnV0S6Wk5n31+1ekAFjNtk4F034TYW8aTedClA1M=; b=pB2SMW8Uwynrg9GvZUslQ4TzxDL4LcIZTc+yGRZp1+9zE0476xY2lAHJJx3sAiL7DP ya3dz27iFtrmmpGOYaMqyf8k9n/ol/+rjv9Duq19W3hCWuBwkIT/xxjIBUofRljHoIqI YOU/oNpwENPz571ENDedkEIHSDmCLSOMYanlHQFvOu5065pCy66f58YKKP44R15nc3QL dzaqj9iw8v+cz08+aV24tqIJHwLZSm+oRhCNHMdSUBN9+CAzgy3WvZugEpB6IbbIK8Os LBEgR7KbqmD6k1BZiiDM9JT5bSqtPDUSPVvEk2lA95xqr6jpeK6SAzBjbSraiXT0JQGB JqOw== X-Gm-Message-State: AFqh2kpDsohDvzGARKB/o4jzZ37GotV4ZEEOhLg5Kuzqzfac8qpFuMy2 qarI/SvsGS2IkmZJUaWkbdN2bNkscxVcvUw6liI= X-Google-Smtp-Source: AMrXdXu+JqSgmEJ3TAVDK7sOZ3TdPASvGIbmeOkZ7R0wbi4ZFxrF116ghXJcHlxy0hgDCdA3chwPZQ== X-Received: by 2002:a05:6830:96:b0:675:cde9:90b6 with SMTP id a22-20020a056830009600b00675cde990b6mr7809336oto.19.1674249399941; Fri, 20 Jan 2023 13:16:39 -0800 (PST) Received: from mandiga.. ([2804:1b3:a7c1:7e99:f284:be2f:4ee5:d122]) by smtp.gmail.com with ESMTPSA id d18-20020a056830139200b00686467f920bsm6937432otq.48.2023.01.20.13.16.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 20 Jan 2023 13:16:39 -0800 (PST) To: libc-alpha@sourceware.org, Richard Henderson , Noah Goldstein Subject: [PATCH v10 05/24] string: Improve generic strnlen Date: Fri, 20 Jan 2023 18:16:03 -0300 Message-Id: <20230120211622.3445279-6-adhemerval.zanella@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230120211622.3445279-1-adhemerval.zanella@linaro.org> References: <20230120211622.3445279-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 Reply-To: Adhemerval Zanella Errors-To: libc-alpha-bounces+incoming=patchwork.ozlabs.org@sourceware.org Sender: "Libc-alpha" With an optimized memchr, new strnlen implementation basically calls memchr and adjust the result pointer value. It also cleanups the multiple inclusion by leaving the ifunc implementation to undef the weak_alias and libc_hidden_def. Co-authored-by: Richard Henderson --- string/strnlen.c | 137 +----------------- sysdeps/i386/i686/multiarch/strnlen-c.c | 14 +- .../power4/multiarch/strnlen-ppc32.c | 14 +- sysdeps/s390/strnlen-c.c | 14 +- 4 files changed, 27 insertions(+), 152 deletions(-) diff --git a/string/strnlen.c b/string/strnlen.c index 6ff294eab1..dc23354ec8 100644 --- a/string/strnlen.c +++ b/string/strnlen.c @@ -1,10 +1,6 @@ /* Find the length of STRING, but scan at most MAXLEN characters. Copyright (C) 1991-2023 Free Software Foundation, Inc. - Based on strlen written by Torbjorn Granlund (tege@sics.se), - with help from Dan Sahlin (dan@sics.se); - commentary by Jim Blandy (jimb@ai.mit.edu). - The GNU C Library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the @@ -20,7 +16,6 @@ not, see . */ #include -#include /* Find the length of S, but scan at most MAXLEN characters. If no '\0' terminator is found in that many characters, return MAXLEN. */ @@ -32,134 +27,12 @@ size_t __strnlen (const char *str, size_t maxlen) { - const char *char_ptr, *end_ptr = str + maxlen; - const unsigned long int *longword_ptr; - unsigned long int longword, himagic, lomagic; - - if (maxlen == 0) - return 0; - - if (__glibc_unlikely (end_ptr < str)) - end_ptr = (const char *) ~0UL; - - /* Handle the first few characters by reading one character at a time. - Do this until CHAR_PTR is aligned on a longword boundary. */ - for (char_ptr = str; ((unsigned long int) char_ptr - & (sizeof (longword) - 1)) != 0; - ++char_ptr) - if (*char_ptr == '\0') - { - if (char_ptr > end_ptr) - char_ptr = end_ptr; - return char_ptr - str; - } - - /* All these elucidatory comments refer to 4-byte longwords, - but the theory applies equally well to 8-byte longwords. */ - - longword_ptr = (unsigned long int *) char_ptr; - - /* Bits 31, 24, 16, and 8 of this number are zero. Call these bits - the "holes." Note that there is a hole just to the left of - each byte, with an extra at the end: - - bits: 01111110 11111110 11111110 11111111 - bytes: AAAAAAAA BBBBBBBB CCCCCCCC DDDDDDDD - - The 1-bits make sure that carries propagate to the next 0-bit. - The 0-bits provide holes for carries to fall into. */ - himagic = 0x80808080L; - lomagic = 0x01010101L; - if (sizeof (longword) > 4) - { - /* 64-bit version of the magic. */ - /* Do the shift in two steps to avoid a warning if long has 32 bits. */ - himagic = ((himagic << 16) << 16) | himagic; - lomagic = ((lomagic << 16) << 16) | lomagic; - } - if (sizeof (longword) > 8) - abort (); - - /* Instead of the traditional loop which tests each character, - we will test a longword at a time. The tricky part is testing - if *any of the four* bytes in the longword in question are zero. */ - while (longword_ptr < (unsigned long int *) end_ptr) - { - /* We tentatively exit the loop if adding MAGIC_BITS to - LONGWORD fails to change any of the hole bits of LONGWORD. - - 1) Is this safe? Will it catch all the zero bytes? - Suppose there is a byte with all zeros. Any carry bits - propagating from its left will fall into the hole at its - least significant bit and stop. Since there will be no - carry from its most significant bit, the LSB of the - byte to the left will be unchanged, and the zero will be - detected. - - 2) Is this worthwhile? Will it ignore everything except - zero bytes? Suppose every byte of LONGWORD has a bit set - somewhere. There will be a carry into bit 8. If bit 8 - is set, this will carry into bit 16. If bit 8 is clear, - one of bits 9-15 must be set, so there will be a carry - into bit 16. Similarly, there will be a carry into bit - 24. If one of bits 24-30 is set, there will be a carry - into bit 31, so all of the hole bits will be changed. - - The one misfire occurs when bits 24-30 are clear and bit - 31 is set; in this case, the hole at bit 31 is not - changed. If we had access to the processor carry flag, - we could close this loophole by putting the fourth hole - at bit 32! - - So it ignores everything except 128's, when they're aligned - properly. */ - - longword = *longword_ptr++; - - if ((longword - lomagic) & himagic) - { - /* Which of the bytes was the zero? If none of them were, it was - a misfire; continue the search. */ - - const char *cp = (const char *) (longword_ptr - 1); - - char_ptr = cp; - if (cp[0] == 0) - break; - char_ptr = cp + 1; - if (cp[1] == 0) - break; - char_ptr = cp + 2; - if (cp[2] == 0) - break; - char_ptr = cp + 3; - if (cp[3] == 0) - break; - if (sizeof (longword) > 4) - { - char_ptr = cp + 4; - if (cp[4] == 0) - break; - char_ptr = cp + 5; - if (cp[5] == 0) - break; - char_ptr = cp + 6; - if (cp[6] == 0) - break; - char_ptr = cp + 7; - if (cp[7] == 0) - break; - } - } - char_ptr = end_ptr; - } - - if (char_ptr > end_ptr) - char_ptr = end_ptr; - return char_ptr - str; + const char *found = memchr (str, '\0', maxlen); + return found ? found - str : maxlen; } + #ifndef STRNLEN -libc_hidden_def (__strnlen) weak_alias (__strnlen, strnlen) -#endif +libc_hidden_def (__strnlen) libc_hidden_def (strnlen) +#endif diff --git a/sysdeps/i386/i686/multiarch/strnlen-c.c b/sysdeps/i386/i686/multiarch/strnlen-c.c index 351e939a93..beb0350d53 100644 --- a/sysdeps/i386/i686/multiarch/strnlen-c.c +++ b/sysdeps/i386/i686/multiarch/strnlen-c.c @@ -1,10 +1,10 @@ #define STRNLEN __strnlen_ia32 +#include + #ifdef SHARED -# undef libc_hidden_def -# define libc_hidden_def(name) \ - __hidden_ver1 (__strnlen_ia32, __GI_strnlen, __strnlen_ia32); \ - strong_alias (__strnlen_ia32, __strnlen_ia32_1); \ - __hidden_ver1 (__strnlen_ia32_1, __GI___strnlen, __strnlen_ia32_1); +/* Alias for internal symbol to avoid PLT generation, it redirects the + libc_hidden_def (__strnlen/strlen) to default implementation. */ +__hidden_ver1 (__strnlen_ia32, __GI_strnlen, __strnlen_ia32); +strong_alias (__strnlen_ia32, __strnlen_ia32_1); +__hidden_ver1 (__strnlen_ia32_1, __GI___strnlen, __strnlen_ia32_1); #endif - -#include "string/strnlen.c" diff --git a/sysdeps/powerpc/powerpc32/power4/multiarch/strnlen-ppc32.c b/sysdeps/powerpc/powerpc32/power4/multiarch/strnlen-ppc32.c index 957b9b99e8..2ca1cd7181 100644 --- a/sysdeps/powerpc/powerpc32/power4/multiarch/strnlen-ppc32.c +++ b/sysdeps/powerpc/powerpc32/power4/multiarch/strnlen-ppc32.c @@ -17,12 +17,12 @@ . */ #define STRNLEN __strnlen_ppc +#include + #ifdef SHARED -# undef libc_hidden_def -# define libc_hidden_def(name) \ - __hidden_ver1 (__strnlen_ppc, __GI_strnlen, __strnlen_ppc); \ - strong_alias (__strnlen_ppc, __strnlen_ppc_1); \ - __hidden_ver1 (__strnlen_ppc_1, __GI___strnlen, __strnlen_ppc_1); +/* Alias for internal symbol to avoid PLT generation, it redirects the + libc_hidden_def (__strnlen/strlen) to default implementation. */ +__hidden_ver1 (__strnlen_ppc, __GI_strnlen, __strnlen_ppc); \ +strong_alias (__strnlen_ppc, __strnlen_ppc_1); \ +__hidden_ver1 (__strnlen_ppc_1, __GI___strnlen, __strnlen_ppc_1); #endif - -#include diff --git a/sysdeps/s390/strnlen-c.c b/sysdeps/s390/strnlen-c.c index 172fcc7caa..95156a0ff5 100644 --- a/sysdeps/s390/strnlen-c.c +++ b/sysdeps/s390/strnlen-c.c @@ -21,14 +21,16 @@ #if HAVE_STRNLEN_C # if HAVE_STRNLEN_IFUNC # define STRNLEN STRNLEN_C +# endif + +# include + +# if HAVE_STRNLEN_IFUNC # if defined SHARED && IS_IN (libc) -# undef libc_hidden_def -# define libc_hidden_def(name) \ - __hidden_ver1 (__strnlen_c, __GI_strnlen, __strnlen_c); \ - strong_alias (__strnlen_c, __strnlen_c_1); \ - __hidden_ver1 (__strnlen_c_1, __GI___strnlen, __strnlen_c_1); +__hidden_ver1 (__strnlen_c, __GI_strnlen, __strnlen_c); +strong_alias (__strnlen_c, __strnlen_c_1); +__hidden_ver1 (__strnlen_c_1, __GI___strnlen, __strnlen_c_1); # endif # endif -# include #endif From patchwork Fri Jan 20 21:16:04 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adhemerval Zanella X-Patchwork-Id: 1729829 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=sourceware.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=sourceware.org; envelope-from=libc-alpha-bounces+incoming=patchwork.ozlabs.org@sourceware.org; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; secure) header.d=sourceware.org header.i=@sourceware.org header.a=rsa-sha256 header.s=default header.b=M5mR2qyH; dkim-atps=neutral Received: from sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4NzC5B0qcFz23gV for ; Sat, 21 Jan 2023 08:17:50 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 13DFA3839DEF for ; Fri, 20 Jan 2023 21:17:48 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 13DFA3839DEF DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1674249468; bh=9NAPzBLwSQ8PToT9tN0pnM5UqowDNGsD7uyHlOdKXeo=; h=To:Subject:Date:In-Reply-To:References:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=M5mR2qyHxcqU5PpOl1zmjKPqXfWx3l6wkqbB6WuMkKqsZthKLIpTQ6IGjQZU47Nqw EtzI2yFu/wUjIr9z82Q1yEcSETbmqPOhCYs4mvsduCSw0GK00H12qc8h/SNBjlakMo SK9ouUfKmi14w3YILukvOVA99oOWtGm76J/YrXjY= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-ot1-x32e.google.com (mail-ot1-x32e.google.com [IPv6:2607:f8b0:4864:20::32e]) by sourceware.org (Postfix) with ESMTPS id 3BAE6385B525 for ; Fri, 20 Jan 2023 21:16:43 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 3BAE6385B525 Received: by mail-ot1-x32e.google.com with SMTP id cc13-20020a05683061cd00b00684b8cf2f4dso3798858otb.12 for ; Fri, 20 Jan 2023 13:16:43 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=9NAPzBLwSQ8PToT9tN0pnM5UqowDNGsD7uyHlOdKXeo=; b=BI4IoIPJIODXHwenhUOgl5UPdjnne2puNtsBZ7Mkpc6usURKJaSAW7z9z/R7m++LuL E9sY1GdwNOm7XGtw+Uiyxn1jCh4zxEGlahkEFzLkH9r+hxTV2bJcRplHq9phfD8Kak/y l4DEqgmCZjxER9xZeOTjV90YnrwaiBDwVgTWjwjCyWBjpS6ZVLomS/+jCwQBJ5nLomR5 FUBvir7fy/L/fpPeYq1yNrrY1XUQHp/PrQw022qAYSEvs6Mca/OFCwGtIRZBR6fpe7MA dZg65k0s26DNI0eIpoW/q5dRTvkaaR8SAN+HD+eWSetIEr8cy1LUN9MhHV4RtOTdgnJc Diwg== X-Gm-Message-State: AFqh2kqwYvYewQ5/kiAvONiZwDPC5YQ5sC62DvMGs2q7ukFr304vEHqN VfieHkZLZzG7YbnMAuANxo+dCAC3iszMf4xOXKA= X-Google-Smtp-Source: AMrXdXtiTJt9VlxbO7ha+XX3frk/a8r85ZUsGSl4CzuZ1kULAbbxNSC6fTSC7LTJB3qPqqnHeyh0Jw== X-Received: by 2002:a9d:7f17:0:b0:686:75f7:b2bf with SMTP id j23-20020a9d7f17000000b0068675f7b2bfmr3504750otq.22.1674249402038; Fri, 20 Jan 2023 13:16:42 -0800 (PST) Received: from mandiga.. ([2804:1b3:a7c1:7e99:f284:be2f:4ee5:d122]) by smtp.gmail.com with ESMTPSA id d18-20020a056830139200b00686467f920bsm6937432otq.48.2023.01.20.13.16.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 20 Jan 2023 13:16:41 -0800 (PST) To: libc-alpha@sourceware.org, Richard Henderson , Noah Goldstein Subject: [PATCH v10 06/24] string: Improve generic strchr Date: Fri, 20 Jan 2023 18:16:04 -0300 Message-Id: <20230120211622.3445279-7-adhemerval.zanella@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230120211622.3445279-1-adhemerval.zanella@linaro.org> References: <20230120211622.3445279-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 Reply-To: Adhemerval Zanella Errors-To: libc-alpha-bounces+incoming=patchwork.ozlabs.org@sourceware.org Sender: "Libc-alpha" New algorithm now calls strchrnul. Checked on x86_64-linux-gnu, i686-linux-gnu, powerpc-linux-gnu, and powerpc64-linux-gnu by removing the arch-specific assembly implementation and disabling multi-arch (it covers both LE and BE for 64 and 32 bits). Reviewed-by: Richard Henderson --- string/strchr.c | 159 ++-------------------------------------- sysdeps/s390/strchr-c.c | 11 +-- 2 files changed, 14 insertions(+), 156 deletions(-) diff --git a/string/strchr.c b/string/strchr.c index 1572b8b42e..30c3eb10f2 100644 --- a/string/strchr.c +++ b/string/strchr.c @@ -21,165 +21,22 @@ . */ #include -#include #undef strchr +#undef index -#ifndef STRCHR -# define STRCHR strchr +#ifdef STRCHR +# define strchr STRCHR #endif /* Find the first occurrence of C in S. */ char * -STRCHR (const char *s, int c_in) +strchr (const char *s, int c_in) { - const unsigned char *char_ptr; - const unsigned long int *longword_ptr; - unsigned long int longword, magic_bits, charmask; - unsigned char c; - - c = (unsigned char) c_in; - - /* Handle the first few characters by reading one character at a time. - Do this until CHAR_PTR is aligned on a longword boundary. */ - for (char_ptr = (const unsigned char *) s; - ((unsigned long int) char_ptr & (sizeof (longword) - 1)) != 0; - ++char_ptr) - if (*char_ptr == c) - return (void *) char_ptr; - else if (*char_ptr == '\0') - return NULL; - - /* All these elucidatory comments refer to 4-byte longwords, - but the theory applies equally well to 8-byte longwords. */ - - longword_ptr = (unsigned long int *) char_ptr; - - /* Bits 31, 24, 16, and 8 of this number are zero. Call these bits - the "holes." Note that there is a hole just to the left of - each byte, with an extra at the end: - - bits: 01111110 11111110 11111110 11111111 - bytes: AAAAAAAA BBBBBBBB CCCCCCCC DDDDDDDD - - The 1-bits make sure that carries propagate to the next 0-bit. - The 0-bits provide holes for carries to fall into. */ - magic_bits = -1; - magic_bits = magic_bits / 0xff * 0xfe << 1 >> 1 | 1; - - /* Set up a longword, each of whose bytes is C. */ - charmask = c | (c << 8); - charmask |= charmask << 16; - if (sizeof (longword) > 4) - /* Do the shift in two steps to avoid a warning if long has 32 bits. */ - charmask |= (charmask << 16) << 16; - if (sizeof (longword) > 8) - abort (); - - /* Instead of the traditional loop which tests each character, - we will test a longword at a time. The tricky part is testing - if *any of the four* bytes in the longword in question are zero. */ - for (;;) - { - /* We tentatively exit the loop if adding MAGIC_BITS to - LONGWORD fails to change any of the hole bits of LONGWORD. - - 1) Is this safe? Will it catch all the zero bytes? - Suppose there is a byte with all zeros. Any carry bits - propagating from its left will fall into the hole at its - least significant bit and stop. Since there will be no - carry from its most significant bit, the LSB of the - byte to the left will be unchanged, and the zero will be - detected. - - 2) Is this worthwhile? Will it ignore everything except - zero bytes? Suppose every byte of LONGWORD has a bit set - somewhere. There will be a carry into bit 8. If bit 8 - is set, this will carry into bit 16. If bit 8 is clear, - one of bits 9-15 must be set, so there will be a carry - into bit 16. Similarly, there will be a carry into bit - 24. If one of bits 24-30 is set, there will be a carry - into bit 31, so all of the hole bits will be changed. - - The one misfire occurs when bits 24-30 are clear and bit - 31 is set; in this case, the hole at bit 31 is not - changed. If we had access to the processor carry flag, - we could close this loophole by putting the fourth hole - at bit 32! - - So it ignores everything except 128's, when they're aligned - properly. - - 3) But wait! Aren't we looking for C as well as zero? - Good point. So what we do is XOR LONGWORD with a longword, - each of whose bytes is C. This turns each byte that is C - into a zero. */ - - longword = *longword_ptr++; - - /* Add MAGIC_BITS to LONGWORD. */ - if ((((longword + magic_bits) - - /* Set those bits that were unchanged by the addition. */ - ^ ~longword) - - /* Look at only the hole bits. If any of the hole bits - are unchanged, most likely one of the bytes was a - zero. */ - & ~magic_bits) != 0 - - /* That caught zeroes. Now test for C. */ - || ((((longword ^ charmask) + magic_bits) ^ ~(longword ^ charmask)) - & ~magic_bits) != 0) - { - /* Which of the bytes was C or zero? - If none of them were, it was a misfire; continue the search. */ - - const unsigned char *cp = (const unsigned char *) (longword_ptr - 1); - - if (*cp == c) - return (char *) cp; - else if (*cp == '\0') - return NULL; - if (*++cp == c) - return (char *) cp; - else if (*cp == '\0') - return NULL; - if (*++cp == c) - return (char *) cp; - else if (*cp == '\0') - return NULL; - if (*++cp == c) - return (char *) cp; - else if (*cp == '\0') - return NULL; - if (sizeof (longword) > 4) - { - if (*++cp == c) - return (char *) cp; - else if (*cp == '\0') - return NULL; - if (*++cp == c) - return (char *) cp; - else if (*cp == '\0') - return NULL; - if (*++cp == c) - return (char *) cp; - else if (*cp == '\0') - return NULL; - if (*++cp == c) - return (char *) cp; - else if (*cp == '\0') - return NULL; - } - } - } - - return NULL; + char *r = __strchrnul (s, c_in); + return (*(unsigned char *)r == (unsigned char)c_in) ? r : NULL; } - -#ifdef weak_alias -# undef index +#ifndef STRCHR weak_alias (strchr, index) -#endif libc_hidden_builtin_def (strchr) +#endif diff --git a/sysdeps/s390/strchr-c.c b/sysdeps/s390/strchr-c.c index c00f2cceea..90822ae0f4 100644 --- a/sysdeps/s390/strchr-c.c +++ b/sysdeps/s390/strchr-c.c @@ -21,13 +21,14 @@ #if HAVE_STRCHR_C # if HAVE_STRCHR_IFUNC # define STRCHR STRCHR_C -# undef weak_alias +# endif + +# include + +# if HAVE_STRCHR_IFUNC # if defined SHARED && IS_IN (libc) -# undef libc_hidden_builtin_def -# define libc_hidden_builtin_def(name) \ - __hidden_ver1 (__strchr_c, __GI_strchr, __strchr_c); +__hidden_ver1 (__strchr_c, __GI_strchr, __strchr_c); # endif # endif -# include #endif From patchwork Fri Jan 20 21:16:05 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adhemerval Zanella X-Patchwork-Id: 1729833 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=sourceware.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=sourceware.org; envelope-from=libc-alpha-bounces+incoming=patchwork.ozlabs.org@sourceware.org; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; secure) header.d=sourceware.org header.i=@sourceware.org header.a=rsa-sha256 header.s=default header.b=lAxpBJ84; dkim-atps=neutral Received: from sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4NzC612lSrz23gV for ; Sat, 21 Jan 2023 08:18:33 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 29FF93887F54 for ; Fri, 20 Jan 2023 21:18:31 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 29FF93887F54 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1674249511; bh=0UDVvKaTLEZDiUjHrWFMmLUe/L0rUOwOcF1jW84WyMw=; 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=lAxpBJ84B+4FHDyXOnf6Mffv6SHZz5lWYd2s9EjJOfQE1X5WjVK1V3VPsVzspSuvR kmKuJYbpT4D4wY2DatCFOgLD5umv0+GYGLvZ5Urg5TGpQllKvgA2dn/w1nkz7USmqH mQ3EjpBoeOQjUgi84qQtY+nuDwUVYci8o8gz07n0= 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 35368383FB87 for ; Fri, 20 Jan 2023 21:16:45 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 35368383FB87 Received: by mail-ot1-x32d.google.com with SMTP id k1-20020a056830150100b006864d1cb279so3813712otp.5 for ; Fri, 20 Jan 2023 13:16: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=0UDVvKaTLEZDiUjHrWFMmLUe/L0rUOwOcF1jW84WyMw=; b=ZKmB19kcEa+DBIQhZQPZJElJ4klxpRYjKVA3XQo+bHMeNxpqpP9bbm/hITcsjiiknM r1NFOjaW3tRx+OXXecYL85bMvdCU1iZlplTTsg6Rjjgq/7hoqIyTl518ikHK7vRFWg6D 1du0YrcgCZSkA3EcQ3l1BU2T6hie4doPTbujY5I5WAcQuzyQJU1REl1+5xxkYkdz4JeO 1JJvFvY80VduVt7ZekHAvV+hH4k0SlY4kqOapf7rkvduZL6dujd3VXRFlEsOO+CcnQ88 ERRvViKG8UlMgvBSpJP3XxlWRA9HoA3G6MKNjoDS9apkP8W4pKFcX7mWTla11maPq85a 6ZeQ== X-Gm-Message-State: AFqh2koXr3ZZsEth//2z9wcApY91LxR4xsNO8RY4qjL/1YaLhIVLFJ3e MSDaI94s7F63xh33JlxJ8fPmbs2C5+6hJH+CTLc= X-Google-Smtp-Source: AMrXdXsYRspiHiXTeAg0NZCmDXDibrtES5ayx+pQlHSnjkQR0DxiSWcG0zACNRWAn488aqlPkKI5qw== X-Received: by 2002:a05:6830:6993:b0:670:4588:f8c4 with SMTP id cy19-20020a056830699300b006704588f8c4mr10411785otb.18.1674249404302; Fri, 20 Jan 2023 13:16:44 -0800 (PST) Received: from mandiga.. ([2804:1b3:a7c1:7e99:f284:be2f:4ee5:d122]) by smtp.gmail.com with ESMTPSA id d18-20020a056830139200b00686467f920bsm6937432otq.48.2023.01.20.13.16.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 20 Jan 2023 13:16:43 -0800 (PST) To: libc-alpha@sourceware.org, Richard Henderson , Noah Goldstein Subject: [PATCH v10 07/24] string: Improve generic strchrnul Date: Fri, 20 Jan 2023 18:16:05 -0300 Message-Id: <20230120211622.3445279-8-adhemerval.zanella@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230120211622.3445279-1-adhemerval.zanella@linaro.org> References: <20230120211622.3445279-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 Reply-To: Adhemerval Zanella Errors-To: libc-alpha-bounces+incoming=patchwork.ozlabs.org@sourceware.org Sender: "Libc-alpha" New algorithm have the following key differences: - Reads first word unaligned and use string-maskoff function to remove unwanted data. This strategy follow arch-specific optimization used on aarch64 and powerpc. - Use string-fz{b,i} functions. Checked on x86_64-linux-gnu, i686-linux-gnu, powerpc64-linux-gnu, and powerpc-linux-gnu by removing the arch-specific assembly implementation and disabling multi-arch (it covers both LE and BE for 64 and 32 bits). Co-authored-by: Richard Henderson --- string/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 Fri Jan 20 21:16:06 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adhemerval Zanella X-Patchwork-Id: 1729836 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=sourceware.org (client-ip=8.43.85.97; helo=sourceware.org; envelope-from=libc-alpha-bounces+incoming=patchwork.ozlabs.org@sourceware.org; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; secure) header.d=sourceware.org header.i=@sourceware.org header.a=rsa-sha256 header.s=default header.b=gd4oLkVu; dkim-atps=neutral Received: from sourceware.org (ip-8-43-85-97.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4NzC6J6H2Hz23hH for ; Sat, 21 Jan 2023 08:18:48 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id D526938A909F for ; Fri, 20 Jan 2023 21:18:46 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org D526938A909F DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1674249526; bh=QLp/aZ3jNxEC82mR4nilPu438Ce+1KnR7hcNgHWXo1I=; 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=gd4oLkVugR057clB+gD/MY92Sz4sQ986p87mo501ONM9rgnMPp9lZHErTm2y2gdkW 5msoaB66uI46o/q3QKnkLzY9mFTdtDbwyQcP40jX+GBRBnsAihtzhW/0hMGmw26LoZ POo1Fhq2ti1EiJ2VLoc5dujJQJgPbK4Wk6YIOMvs= 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 B9C8938582A1 for ; Fri, 20 Jan 2023 21:16:47 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org B9C8938582A1 Received: by mail-ot1-x330.google.com with SMTP id g2-20020a9d6b02000000b006864bf5e658so3835624otp.1 for ; Fri, 20 Jan 2023 13:16: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=QLp/aZ3jNxEC82mR4nilPu438Ce+1KnR7hcNgHWXo1I=; b=YGPIUKpt8KyTee+lsNPK6FUwuGgGnXPAcYQkG25vDucWN8NUDgLqvvcxna/VjoIo9k bGtrwZilofnxsgRIpXoKcnh6kOQmh2QA56MMZ4vHqjcJE5L7qanXI5gSATZo8MU9705l mOuK/5yCgVahD4tA69ob8niS1Usj7ICCcjz3c7sXWpEHrnAxcnCZunRs/o2xG2XP9oTq XhYl1APbFwLyPNfvDDcxFhDdcKW6FCkq7XdRvVONqeRDksm09cd81Xe4gQR1GztCvLuq ttGdc8ZviRKT3+dmqpCcwAhPazG5WWLmCpHiSyH09tPnjofVMMsAGz7XdHdBtnJ9Tf0x C0sA== X-Gm-Message-State: AFqh2kpEU21sbwVc4KPAFveERgcXBXr9ApzKPas52HEXK1xRl+BdHkZM CFQo39bP7iNnPx+4WZPc/O8KOJ+g2uA5uXcxzzg= X-Google-Smtp-Source: AMrXdXv2g+/X5X37voxl8vloATz3cJIqeL0RzHs2YDo952uh4MYSuK7vsNQcj8nhTgoXFSvG4HKQ4A== X-Received: by 2002:a05:6830:43a5:b0:676:3915:ac77 with SMTP id s37-20020a05683043a500b006763915ac77mr10512550otv.19.1674249406372; Fri, 20 Jan 2023 13:16:46 -0800 (PST) Received: from mandiga.. ([2804:1b3:a7c1:7e99:f284:be2f:4ee5:d122]) by smtp.gmail.com with ESMTPSA id d18-20020a056830139200b00686467f920bsm6937432otq.48.2023.01.20.13.16.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 20 Jan 2023 13:16:45 -0800 (PST) To: libc-alpha@sourceware.org, Richard Henderson , Noah Goldstein Subject: [PATCH v10 08/24] string: Improve generic strcmp Date: Fri, 20 Jan 2023 18:16:06 -0300 Message-Id: <20230120211622.3445279-9-adhemerval.zanella@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230120211622.3445279-1-adhemerval.zanella@linaro.org> References: <20230120211622.3445279-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 Reply-To: Adhemerval Zanella Errors-To: libc-alpha-bounces+incoming=patchwork.ozlabs.org@sourceware.org Sender: "Libc-alpha" New generic implementation tries to use word operations along with the new string-fz{b,i} functions even for inputs with different alignments (with still uses aligned access plus merge operation to get a correct word by word comparison). Checked on x86_64-linux-gnu, i686-linux-gnu, powerpc64-linux-gnu, and powerpc-linux-gnu by removing the arch-specific assembly implementation and disabling multi-arch (it covers both LE and BE for 64 and 32 bits). Co-authored-by: Richard Henderson --- string/strcmp.c | 118 +++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 102 insertions(+), 16 deletions(-) diff --git a/string/strcmp.c b/string/strcmp.c index 053f5a8d2b..42e24242b6 100644 --- a/string/strcmp.c +++ b/string/strcmp.c @@ -15,33 +15,119 @@ License along with the GNU C Library; if not, see . */ +#include +#include +#include #include +#include -#undef strcmp - -#ifndef STRCMP -# define STRCMP strcmp +#ifdef STRCMP +# define strcmp STRCMP #endif +static inline int +final_cmp (const op_t w1, const op_t w2) +{ + /* It can not use index_first_zero_ne because it must not compare past the + final '\0' is present (and final_cmp is called before has_zero check). + */ + for (size_t i = 0; i < sizeof (op_t); i++) + { + unsigned char c1 = extractbyte (w1, i); + unsigned char c2 = extractbyte (w2, i); + if (c1 == '\0' || c1 != c2) + return c1 - c2; + } + return 0; +} + +/* Aligned loop: if a difference is found, exit to compare the bytes. Else + if a zero is found we have equal strings. */ +static inline int +strcmp_aligned_loop (const op_t *x1, const op_t *x2, op_t w1) +{ + op_t w2 = *x2++; + + while (w1 == w2) + { + if (has_zero (w1)) + return 0; + w1 = *x1++; + w2 = *x2++; + } + + return final_cmp (w1, w2); +} + +/* Unaligned loop: align the first partial of P2, with 0xff for the rest of + the bytes so that we can also apply the has_zero test to see if we have + already reached EOS. If we have, then we can simply fall through to the + final comparison. */ +static inline int +strcmp_unaligned_loop (const op_t *x1, const op_t *x2, op_t w1, uintptr_t ofs) +{ + op_t w2a = *x2++; + uintptr_t sh_1 = ofs * CHAR_BIT; + uintptr_t sh_2 = sizeof(op_t) * CHAR_BIT - sh_1; + + op_t w2 = MERGE (w2a, sh_1, (op_t)-1, sh_2); + if (!has_zero (w2)) + { + op_t w2b; + + /* Unaligned loop. The invariant is that W2B, which is "ahead" of W1, + does not contain end-of-string. Therefore it is safe (and necessary) + to read another word from each while we do not have a difference. */ + while (1) + { + w2b = *x2++; + w2 = MERGE (w2a, sh_1, w2b, sh_2); + if (w1 != w2) + return final_cmp (w1, w2); + if (has_zero (w2b)) + break; + w1 = *x1++; + w2a = w2b; + } + + /* Zero found in the second partial of P2. If we had EOS in the aligned + word, we have equality. */ + if (has_zero (w1)) + return 0; + + /* Load the final word of P1 and align the final partial of P2. */ + w1 = *x1++; + w2 = MERGE (w2b, sh_1, 0, sh_2); + } + + return final_cmp (w1, w2); +} + /* Compare S1 and S2, returning less than, equal to or greater than zero if S1 is lexicographically less than, equal to or greater than S2. */ int -STRCMP (const char *p1, const char *p2) +strcmp (const char *p1, const char *p2) { - const unsigned char *s1 = (const unsigned char *) p1; - const unsigned char *s2 = (const unsigned char *) p2; - unsigned char c1, c2; - - do + /* Handle the unaligned bytes of p1 first. */ + uintptr_t n = -(uintptr_t)p1 % sizeof(op_t); + for (int i = 0; i < n; ++i) { - c1 = (unsigned char) *s1++; - c2 = (unsigned char) *s2++; - if (c1 == '\0') - return c1 - c2; + unsigned char c1 = *p1++; + unsigned char c2 = *p2++; + int diff = c1 - c2; + if (c1 == '\0' || diff != 0) + return diff; } - while (c1 == c2); - return c1 - c2; + /* P1 is now aligned to op_t. P2 may or may not be. */ + const op_t *x1 = (const op_t *) p1; + op_t w1 = *x1++; + uintptr_t ofs = (uintptr_t) p2 % sizeof(op_t); + return ofs == 0 + ? strcmp_aligned_loop (x1, (const op_t *)p2, w1) + : strcmp_unaligned_loop (x1, (const op_t *)(p2 - ofs), w1, ofs); } +#ifndef STRCMP libc_hidden_builtin_def (strcmp) +#endif From patchwork Fri Jan 20 21:16:07 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adhemerval Zanella X-Patchwork-Id: 1729839 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=sourceware.org (client-ip=8.43.85.97; helo=sourceware.org; envelope-from=libc-alpha-bounces+incoming=patchwork.ozlabs.org@sourceware.org; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; secure) header.d=sourceware.org header.i=@sourceware.org header.a=rsa-sha256 header.s=default header.b=urc46u59; dkim-atps=neutral Received: from sourceware.org (server2.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4NzC762yQ6z23gV for ; Sat, 21 Jan 2023 08:19:30 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 5ACC13839DF9 for ; Fri, 20 Jan 2023 21:19:28 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 5ACC13839DF9 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1674249568; bh=IlqFI3OmA7S8ZupLEuUiGyd0kNm4R+OCvCJIkGSKMmM=; 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=urc46u59EsM+V5FOtMJCQZ5tO46JQLNJ/ocvj8hbniHKTN53v5fGpVa+klMNHprM0 EScjHWUXaU3AL4oSDT4hVRcsDXb4qxKLYVQKf2c7iYi2c5Hm/gkSW1cGxMWOoUz0U0 Pl+UD3GUo5/XH+CbPE/KNC3gBb35e/PN5I/dGDGc= 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 079A0385438F for ; Fri, 20 Jan 2023 21:16:50 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 079A0385438F Received: by mail-ot1-x330.google.com with SMTP id k44-20020a9d19af000000b00683e176ab01so3798772otk.13 for ; Fri, 20 Jan 2023 13:16:50 -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=IlqFI3OmA7S8ZupLEuUiGyd0kNm4R+OCvCJIkGSKMmM=; b=mjnjcWGIWUSjvsLQY0oXFox4/Ny1kyQwelA5vH0HE8uI18n6jVvW72cjJDt6EsqPYT tfVGgu2+wERZ1uTLjGaMtWYOqmKe+ZGoN+pGFHNc80m2dYMzXE8P3xHWGZeN6owEXxca wEByRy2iKBlpCYdkue67e8rFhA7sbNoZwIksRyLTOvmeZC5Jb2P6FeGDzV2Vq1acGUfG hAJL2uXZvyHcQ49qc5ss1S3y5yMcpmHR4+/Q5wowp7dsI0hqXvD7WOf/3l2CS0Bz59Cq 3l0s5EvvzUS5wG7y70KpxzTOc0CFTMUxOYBgkwoaeFt25zkVyHXpy48+aRtWn1FOzxLV yHGQ== X-Gm-Message-State: AFqh2ko9uIDjZkBRm3NnJ1RyT2unY/LAbDkyPS+NrwyPJQ+koMREY7Eh U1juR2mpBsBF0hDmWt9qiKV7Iq60loZJQiyjaDU= X-Google-Smtp-Source: AMrXdXtNo7LGL2x1jMmJHjeGYPNEUzjMa6ycmmzlXzneXCUQ/FIXjVivB4T/rdRl3A8kAGDSlxYCsw== X-Received: by 2002:a9d:3c5:0:b0:686:516d:6ae4 with SMTP id f63-20020a9d03c5000000b00686516d6ae4mr7667049otf.9.1674249408413; Fri, 20 Jan 2023 13:16:48 -0800 (PST) Received: from mandiga.. ([2804:1b3:a7c1:7e99:f284:be2f:4ee5:d122]) by smtp.gmail.com with ESMTPSA id d18-20020a056830139200b00686467f920bsm6937432otq.48.2023.01.20.13.16.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 20 Jan 2023 13:16:47 -0800 (PST) To: libc-alpha@sourceware.org, Richard Henderson , Noah Goldstein Subject: [PATCH v10 09/24] string: Improve generic strncmp Date: Fri, 20 Jan 2023 18:16:07 -0300 Message-Id: <20230120211622.3445279-10-adhemerval.zanella@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230120211622.3445279-1-adhemerval.zanella@linaro.org> References: <20230120211622.3445279-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 Reply-To: Adhemerval Zanella Errors-To: libc-alpha-bounces+incoming=patchwork.ozlabs.org@sourceware.org Sender: "Libc-alpha" New generic implementation tries to use word operations along with the new string-fz{b,i} functions even for inputs with different alignments (with still uses aligned access plus merge operation to get a correct word by word comparison). Checked on x86_64-linux-gnu, i686-linux-gnu, powerpc64-linux-gnu, and powerpc-linux-gnu by removing the arch-specific assembly implementation and disabling multi-arch (it covers both LE and BE for 64 and 32 bits). --- string/strcmp-impl.h | 41 ++++++++++++++ string/strcmp.c | 23 ++------ string/strncmp.c | 130 +++++++++++++++++++++++++++++++------------ 3 files changed, 138 insertions(+), 56 deletions(-) create mode 100644 string/strcmp-impl.h diff --git a/string/strcmp-impl.h b/string/strcmp-impl.h new file mode 100644 index 0000000000..618240368a --- /dev/null +++ b/string/strcmp-impl.h @@ -0,0 +1,41 @@ +/* Common definition for string compare implementations. + Copyright (C) 2023 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, see + . */ + +#ifndef _STRCMP_IMPL_H +#define _STRCMP_IMPL_H + +#include +#include + +static inline int +final_cmp (const op_t w1, const op_t w2, size_t n) +{ + /* It can not use index_first_zero_ne because it must not compare past the + final '\0' is present (and final_cmp is called before has_zero check). + */ + for (size_t i = 0; i < n; i++) + { + unsigned char c1 = extractbyte (w1, i); + unsigned char c2 = extractbyte (w2, i); + if (c1 == '\0' || c1 != c2) + return c1 - c2; + } + return 0; +} + +#endif diff --git a/string/strcmp.c b/string/strcmp.c index 42e24242b6..8e7b3310db 100644 --- a/string/strcmp.c +++ b/string/strcmp.c @@ -16,6 +16,7 @@ . */ #include +#include #include #include #include @@ -25,22 +26,6 @@ # define strcmp STRCMP #endif -static inline int -final_cmp (const op_t w1, const op_t w2) -{ - /* It can not use index_first_zero_ne because it must not compare past the - final '\0' is present (and final_cmp is called before has_zero check). - */ - for (size_t i = 0; i < sizeof (op_t); i++) - { - unsigned char c1 = extractbyte (w1, i); - unsigned char c2 = extractbyte (w2, i); - if (c1 == '\0' || c1 != c2) - return c1 - c2; - } - return 0; -} - /* Aligned loop: if a difference is found, exit to compare the bytes. Else if a zero is found we have equal strings. */ static inline int @@ -56,7 +41,7 @@ strcmp_aligned_loop (const op_t *x1, const op_t *x2, op_t w1) w2 = *x2++; } - return final_cmp (w1, w2); + return final_cmp (w1, w2, sizeof (op_t)); } /* Unaligned loop: align the first partial of P2, with 0xff for the rest of @@ -83,7 +68,7 @@ strcmp_unaligned_loop (const op_t *x1, const op_t *x2, op_t w1, uintptr_t ofs) w2b = *x2++; w2 = MERGE (w2a, sh_1, w2b, sh_2); if (w1 != w2) - return final_cmp (w1, w2); + return final_cmp (w1, w2, sizeof (op_t)); if (has_zero (w2b)) break; w1 = *x1++; @@ -100,7 +85,7 @@ strcmp_unaligned_loop (const op_t *x1, const op_t *x2, op_t w1, uintptr_t ofs) w2 = MERGE (w2b, sh_1, 0, sh_2); } - return final_cmp (w1, w2); + return final_cmp (w1, w2, sizeof (op_t)); } /* Compare S1 and S2, returning less than, equal to or diff --git a/string/strncmp.c b/string/strncmp.c index fd7cee09b6..3e6040df09 100644 --- a/string/strncmp.c +++ b/string/strncmp.c @@ -15,7 +15,13 @@ License along with the GNU C Library; if not, see . */ +#include +#include +#include +#include +#include #include +#include #include #undef strncmp @@ -24,51 +30,101 @@ #define STRNCMP strncmp #endif -/* Compare no more than N characters of S1 and S2, - returning less than, equal to or greater than zero - if S1 is lexicographically less than, equal to or - greater than S2. */ -int -STRNCMP (const char *s1, const char *s2, size_t n) +/* Aligned loop: if a difference is found, exit to compare the bytes. Else + if a zero is found we have equal strings. */ +static inline int +strncmp_aligned_loop (const op_t *x1, const op_t *x2, op_t w1, size_t n) { - unsigned char c1 = '\0'; - unsigned char c2 = '\0'; + op_t w2 = *x2++; - if (n >= 4) + while (w1 == w2) { - size_t n4 = n >> 2; - do - { - c1 = (unsigned char) *s1++; - c2 = (unsigned char) *s2++; - if (c1 == '\0' || c1 != c2) - return c1 - c2; - c1 = (unsigned char) *s1++; - c2 = (unsigned char) *s2++; - if (c1 == '\0' || c1 != c2) - return c1 - c2; - c1 = (unsigned char) *s1++; - c2 = (unsigned char) *s2++; - if (c1 == '\0' || c1 != c2) - return c1 - c2; - c1 = (unsigned char) *s1++; - c2 = (unsigned char) *s2++; - if (c1 == '\0' || c1 != c2) - return c1 - c2; - } while (--n4 > 0); - n &= 3; + if (n <= sizeof (op_t)) + break; + n -= sizeof (op_t); + + if (has_zero (w1)) + return 0; + w1 = *x1++; + w2 = *x2++; } - while (n > 0) + return final_cmp (w1, w2, n); +} + +/* Unaligned loop: align the first partial of P2, with 0xff for the rest of + the bytes so that we can also apply the has_zero test to see if we have + already reached EOS. If we have, then we can simply fall through to the + final comparison. */ +static inline int +strncmp_unaligned_loop (const op_t *x1, const op_t *x2, op_t w1, uintptr_t ofs, + size_t n) +{ + op_t w2a = *x2++; + uintptr_t sh_1 = ofs * CHAR_BIT; + uintptr_t sh_2 = sizeof(op_t) * CHAR_BIT - sh_1; + + op_t w2 = MERGE (w2a, sh_1, (op_t)-1, sh_2); + if (!has_zero (w2) && n > (sizeof (op_t) - ofs)) { - c1 = (unsigned char) *s1++; - c2 = (unsigned char) *s2++; - if (c1 == '\0' || c1 != c2) - return c1 - c2; - n--; + op_t w2b; + + /* Unaligned loop. The invariant is that W2B, which is "ahead" of W1, + does not contain end-of-string. Therefore it is safe (and necessary) + to read another word from each while we do not have a difference. */ + while (1) + { + w2b = *x2++; + w2 = MERGE (w2a, sh_1, w2b, sh_2); + if (n <= sizeof (op_t) || w1 != w2) + return final_cmp (w1, w2, n); + n -= sizeof(op_t); + if (has_zero (w2b) || n <= (sizeof (op_t) - ofs)) + break; + w1 = *x1++; + w2a = w2b; + } + + /* Zero found in the second partial of P2. If we had EOS in the aligned + word, we have equality. */ + if (has_zero (w1)) + return 0; + + /* Load the final word of P1 and align the final partial of P2. */ + w1 = *x1++; + w2 = MERGE (w2b, sh_1, 0, sh_2); } - return c1 - c2; + return final_cmp (w1, w2, n); } +/* Compare no more than N characters of S1 and S2, + returning less than, equal to or greater than zero + if S1 is lexicographically less than, equal to or + greater than S2. */ +int +STRNCMP (const char *p1, const char *p2, size_t n) +{ + /* Handle the unaligned bytes of p1 first. */ + uintptr_t a = MIN (-(uintptr_t)p1 % sizeof(op_t), n); + int diff = 0; + for (int i = 0; i < a; ++i) + { + unsigned char c1 = *p1++; + unsigned char c2 = *p2++; + diff = c1 - c2; + if (c1 == '\0' || diff != 0) + return diff; + } + if (a == n) + return diff; + + /* P1 is now aligned to op_t. P2 may or may not be. */ + const op_t *x1 = (const op_t *) p1; + op_t w1 = *x1++; + uintptr_t ofs = (uintptr_t) p2 % sizeof(op_t); + return ofs == 0 + ? strncmp_aligned_loop (x1, (const op_t *) p2, w1, n - a) + : strncmp_unaligned_loop (x1, (const op_t *) (p2 - ofs), w1, ofs, n - a); +} libc_hidden_builtin_def (STRNCMP) From patchwork Fri Jan 20 21:16:08 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adhemerval Zanella X-Patchwork-Id: 1729842 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=sourceware.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=sourceware.org; envelope-from=libc-alpha-bounces+incoming=patchwork.ozlabs.org@sourceware.org; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; secure) header.d=sourceware.org header.i=@sourceware.org header.a=rsa-sha256 header.s=default header.b=SIV2Ek9A; dkim-atps=neutral Received: from sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4NzC7x3Yc4z23gM for ; Sat, 21 Jan 2023 08:20:13 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 803DA3895FED for ; Fri, 20 Jan 2023 21:20:10 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 803DA3895FED DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1674249610; bh=Bwjz8GzEtqd8V9tBlepTWaDkJvTCT7M8GrRKQ9veC8U=; 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=SIV2Ek9AkdzY48jlgZ/fufgvlti4AZZOizcp0Xzzzkat+1Wdgxs+J31c+pkXKUgOC S3fV5tCa6Ke5Z6ese81CXh2kKQer+bs9q/3+Em9LH+ODFzFZ0Jpg83G4JZbFTnUcKx G5IRXr8jwkZT18Hj2VP6dEuA7tWlq/DvedG6a6TA= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-oa1-x31.google.com (mail-oa1-x31.google.com [IPv6:2001:4860:4864:20::31]) by sourceware.org (Postfix) with ESMTPS id 188FB3839DEA for ; Fri, 20 Jan 2023 21:16:52 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 188FB3839DEA Received: by mail-oa1-x31.google.com with SMTP id 586e51a60fabf-15bb8ec196aso7712769fac.3 for ; Fri, 20 Jan 2023 13:16: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=Bwjz8GzEtqd8V9tBlepTWaDkJvTCT7M8GrRKQ9veC8U=; b=vtvDMTpzhbmvCMvoC9VIgEGi5tE9/so/di7y1AZUj2ChVuQmIJb2dfKFtHvj4cr9Cy Y/8wz+K4YPxGi3K5ZTOXja29slxXwSfBinNO5Hf/rTPN639aLBOKU9lAXHoq3ehXxyW6 B7Qj7qCjfNZyziUrymuzWbbUnV+gr9FJBm7ND64J288bd8wfJ9xP8d6kyMnAjb6qhCXS fbxzsoS7HgG8Gntez5ghtokVxoQnMUTXIcJhW7fXVIdyCid/aV+Xs0GUERjVNWZVP4VO RUIQZ4EfejV8oqjdfCn+374r400Hk2oZUbamf2ZCIG64nR1alk5cSX6Nc5sHQrifdtvQ CgbQ== X-Gm-Message-State: AFqh2kpTWSik/80uTwRgFdVgIqo2MXNPBtYzzvQiKn8KnrHZrY9Edkp8 PsRTMOT2WClEMIBm0ZuXZgcSFp0UhA3/vGMmaOs= X-Google-Smtp-Source: AMrXdXs32h55MhaXHKQaN8/CRivoiEmKBZ8VF9pD1zRmpCqKKS5fEimXq62ZMon1DDKhJAcfslxbDw== X-Received: by 2002:a05:6870:9728:b0:15f:1e80:5d1c with SMTP id n40-20020a056870972800b0015f1e805d1cmr9821647oaq.57.1674249410604; Fri, 20 Jan 2023 13:16:50 -0800 (PST) Received: from mandiga.. ([2804:1b3:a7c1:7e99:f284:be2f:4ee5:d122]) by smtp.gmail.com with ESMTPSA id d18-20020a056830139200b00686467f920bsm6937432otq.48.2023.01.20.13.16.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 20 Jan 2023 13:16:49 -0800 (PST) To: libc-alpha@sourceware.org, Richard Henderson , Noah Goldstein Subject: [PATCH v10 10/24] string: Improve generic memchr Date: Fri, 20 Jan 2023 18:16:08 -0300 Message-Id: <20230120211622.3445279-11-adhemerval.zanella@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230120211622.3445279-1-adhemerval.zanella@linaro.org> References: <20230120211622.3445279-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 Reply-To: Adhemerval Zanella Errors-To: libc-alpha-bounces+incoming=patchwork.ozlabs.org@sourceware.org Sender: "Libc-alpha" New algorithm have the following key differences: - Reads first word unaligned and use string-maskoff function to remove unwanted data. This strategy follow arch-specific optimization used on aarch64 and powerpc. - Use string-fz{b,i} and string-opthr functions. 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 --- string/memchr.c | 178 ++++++------------ .../powerpc32/power4/multiarch/memchr-ppc32.c | 14 +- .../powerpc64/multiarch/memchr-ppc64.c | 9 +- 3 files changed, 58 insertions(+), 143 deletions(-) diff --git a/string/memchr.c b/string/memchr.c index f800d47dce..888eb9da8f 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,75 @@ License along with the GNU C Library; if not, see . */ -#ifndef _LIBC -# include -#endif - +#include +#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 inline const char * +sadd (uintptr_t x, uintptr_t y) +{ + uintptr_t ret = INT_ADD_OVERFLOW (x, y) ? (uintptr_t)-1 : x + y; + return (const char *)ret; +} /* 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 Fri Jan 20 21:16:09 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adhemerval Zanella X-Patchwork-Id: 1729837 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=sourceware.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=sourceware.org; envelope-from=libc-alpha-bounces+incoming=patchwork.ozlabs.org@sourceware.org; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; secure) header.d=sourceware.org header.i=@sourceware.org header.a=rsa-sha256 header.s=default header.b=iY7/x866; dkim-atps=neutral Received: from sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4NzC6p4RNpz23gV for ; Sat, 21 Jan 2023 08:19:14 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 96AD738543BC for ; Fri, 20 Jan 2023 21:19:12 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 96AD738543BC DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1674249552; bh=WkOhVeg+RHhVIvyiijwZvnbubsGSIvWpxCeL2c9IKIU=; 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=iY7/x866JNkpBWPlYuMeGe2cAaZRxZ9pciyGUf3yZtqaFSzwUM9J5dixNTQYzXCZd 2ygzdr9jsLTRzfcA6qPLNcQAYcmrtFV7A2gGDLI60KN3bbDp3A9zephD7XnNDfrJtr Mq6qRSteWKT5ctzVVcVQjZ/CXMHmvcbYaj3cQcRY= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-ot1-x32e.google.com (mail-ot1-x32e.google.com [IPv6:2607:f8b0:4864:20::32e]) by sourceware.org (Postfix) with ESMTPS id 0CE6C383FB90 for ; Fri, 20 Jan 2023 21:16:53 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 0CE6C383FB90 Received: by mail-ot1-x32e.google.com with SMTP id cm26-20020a056830651a00b00684e5c0108dso3819532otb.9 for ; Fri, 20 Jan 2023 13:16:53 -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=WkOhVeg+RHhVIvyiijwZvnbubsGSIvWpxCeL2c9IKIU=; b=Q965bnPeOK6HMO0OSoJmYFwljiob7dHbhFn7PxCuPOLIAhLzUGPVZiXYQn3jGvEu/t A6A25rWma0XloIBxM/335w/e0C0TXsgTLJtRw3iMhT/h/p0IpZb9RXtCiIM/SqfCJymd i+7FBrr4qo4PdlwYM4TtlfquHqAxTeY6X7O5V34PP9RKepdMa1UKKEf/rOgLy4Tqh3AA 216whFsu+ZryZPnD1WrtvZCUgWTRRZebq4/7E0N4B8WKaGg1rvFWQGHAPgVRel/UmWZo a/kJq4x74qkphVEXMggy7xQFqSid28Wo2Pkhs66mkSUEaboZnBz4LBaJhwq/uQ9DtBku ZxoA== X-Gm-Message-State: AFqh2kpV9+JrQCF+lhQyVvV7AISwmxrj/AJzq5xqaBQ/BSLQIYWrXhRl 0XXsDOggj1MCVJPb/vPrgXYdIwUvL6f7gY9+Yik= X-Google-Smtp-Source: AMrXdXs27jGgQu2+YhHKPAdGZ6l4uBZENCr50DwydKINCgWZe3FAKF0dI9eEj9vRuFldpSKIvVZFsg== X-Received: by 2002:a9d:850:0:b0:684:d932:bb7d with SMTP id 74-20020a9d0850000000b00684d932bb7dmr7599202oty.34.1674249412772; Fri, 20 Jan 2023 13:16:52 -0800 (PST) Received: from mandiga.. ([2804:1b3:a7c1:7e99:f284:be2f:4ee5:d122]) by smtp.gmail.com with ESMTPSA id d18-20020a056830139200b00686467f920bsm6937432otq.48.2023.01.20.13.16.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 20 Jan 2023 13:16:51 -0800 (PST) To: libc-alpha@sourceware.org, Richard Henderson , Noah Goldstein Subject: [PATCH v10 11/24] string: Improve generic memrchr Date: Fri, 20 Jan 2023 18:16:09 -0300 Message-Id: <20230120211622.3445279-12-adhemerval.zanella@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230120211622.3445279-1-adhemerval.zanella@linaro.org> References: <20230120211622.3445279-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 Reply-To: Adhemerval Zanella Errors-To: libc-alpha-bounces+incoming=patchwork.ozlabs.org@sourceware.org Sender: "Libc-alpha" New algorithm have the following key differences: - Use string-fz{b,i} functions. 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 --- 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 Fri Jan 20 21:16:10 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adhemerval Zanella X-Patchwork-Id: 1729840 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=sourceware.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=sourceware.org; envelope-from=libc-alpha-bounces+incoming=patchwork.ozlabs.org@sourceware.org; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; secure) header.d=sourceware.org header.i=@sourceware.org header.a=rsa-sha256 header.s=default header.b=JrxLYERx; dkim-atps=neutral Received: from sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4NzC7c4ghvz23gV for ; Sat, 21 Jan 2023 08:19:56 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 2102E3893672 for ; Fri, 20 Jan 2023 21:19:54 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 2102E3893672 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1674249594; bh=uR+tmviJAnIQt3Uy9C/8G52NzH6k6qWZDh0/RH+zyro=; h=To:Subject:Date:In-Reply-To:References:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=JrxLYERxjmOt3plKkNE8rk/LlkXaiooQYO4SyHI54Y8OXhcNPakTD7wZyB8ESxMX7 J+bfs6l8Yyctop9Rr+14XS3rUVNzXkhXcXaAUMdrdrLAtJZIZ+qDFyOOFXqH3QFmm3 EayjwxGepF2yxyFXrlW7ujui1eIsIAFWJp00BxEE= 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 2EFBD3839C75 for ; Fri, 20 Jan 2023 21:16:56 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 2EFBD3839C75 Received: by mail-ot1-x32a.google.com with SMTP id n24-20020a0568301e9800b006865671a9d5so3813644otr.6 for ; Fri, 20 Jan 2023 13:16:56 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=uR+tmviJAnIQt3Uy9C/8G52NzH6k6qWZDh0/RH+zyro=; b=DIGFRMJw3KJFxV8hPrg8MQidJI8zeVCaZWniu/+BhB6Vdl3nNvSHyI1PkQGN3VmdXo RKLAiDLFHy1fRDIP+GUPIyQvYv//8/CXV6XWzUfJmbo21B9JLWa89OnXEljo3vMCg0dw dsO1HdPlusW4xvsCp2o7dIJKh+uXZLBBz73leKgV5opTxr/OJfE4QiEAXIL3F0La/Gy1 DutK1/D0kCewD8hL8hoHDKGvn3c1x1yJw3/EOGE+P8AsnOfqBzmHqRlod8d9AbUothpi Q3bn8lpwhhkkJ7RZ/GyXrJfuRA+CLTqV0tb/VbHgKlKTf0Hh71ZCCAsKV0vHSa/YMkOE UMGQ== X-Gm-Message-State: AFqh2kq4A9d1/qC8vnGF6HLGLDM1vDJEM9ZhLI+n14wVUI7v8EBiqMIE yNIzugYgP68M6R3gqWe8rxGtwkmad1sXr6zYNTM= X-Google-Smtp-Source: AMrXdXsK91d288N5Y/atUbxaVp7H/GL59hPLdLV+TilAIQkjw8ehcHYLeoIj4ga6HJOjdnEspO+ayQ== X-Received: by 2002:a9d:6b98:0:b0:670:9610:1ce4 with SMTP id b24-20020a9d6b98000000b0067096101ce4mr7473134otq.24.1674249414943; Fri, 20 Jan 2023 13:16:54 -0800 (PST) Received: from mandiga.. ([2804:1b3:a7c1:7e99:f284:be2f:4ee5:d122]) by smtp.gmail.com with ESMTPSA id d18-20020a056830139200b00686467f920bsm6937432otq.48.2023.01.20.13.16.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 20 Jan 2023 13:16:54 -0800 (PST) To: libc-alpha@sourceware.org, Richard Henderson , Noah Goldstein Subject: [PATCH v10 12/24] hppa: Add memcopy.h Date: Fri, 20 Jan 2023 18:16:10 -0300 Message-Id: <20230120211622.3445279-13-adhemerval.zanella@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230120211622.3445279-1-adhemerval.zanella@linaro.org> References: <20230120211622.3445279-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 Reply-To: Adhemerval Zanella Errors-To: libc-alpha-bounces+incoming=patchwork.ozlabs.org@sourceware.org Sender: "Libc-alpha" From: Richard Henderson GCC's combine pass cannot merge (x >> c | y << (32 - c)) into a double-word shift unless (1) the subtract is in the same basic block and (2) the result of the subtract is used exactly once. Neither condition is true for any use of MERGE. By forcing the use of a double-word shift, we not only reduce contention on SAR, but also allow the setting of SAR to be hoisted outside of a loop. Checked on hppa-linux-gnu. --- sysdeps/hppa/memcopy.h | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 sysdeps/hppa/memcopy.h diff --git a/sysdeps/hppa/memcopy.h b/sysdeps/hppa/memcopy.h new file mode 100644 index 0000000000..0d4b4ac435 --- /dev/null +++ b/sysdeps/hppa/memcopy.h @@ -0,0 +1,42 @@ +/* Definitions for memory copy functions, PA-RISC version. + Copyright (C) 2023 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library. If not, see + . */ + +#include + +/* Use a single double-word shift instead of two shifts and an ior. + If the uses of MERGE were close to the computation of shl/shr, + the compiler might have been able to create this itself. + But instead that computation is well separated. + + Using an inline function instead of a macro is the easiest way + to ensure that the types are correct. */ + +#undef MERGE + +static __always_inline op_t +MERGE (op_t w0, int shl, op_t w1, int shr) +{ + _Static_assert (OPSIZ == 4 || OPSIZ == 8, "Invalid OPSIZE"); + + op_t res; + if (OPSIZ == 4) + asm ("shrpw %1,%2,%%sar,%0" : "=r"(res) : "r"(w0), "r"(w1), "q"(shr)); + else if (OPSIZ == 8) + asm ("shrpd %1,%2,%%sar,%0" : "=r"(res) : "r"(w0), "r"(w1), "q"(shr)); + return res; +} From patchwork Fri Jan 20 21:16:11 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adhemerval Zanella X-Patchwork-Id: 1729844 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=sourceware.org (client-ip=8.43.85.97; helo=sourceware.org; envelope-from=libc-alpha-bounces+incoming=patchwork.ozlabs.org@sourceware.org; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; secure) header.d=sourceware.org header.i=@sourceware.org header.a=rsa-sha256 header.s=default header.b=M24jddzc; dkim-atps=neutral Received: from sourceware.org (ip-8-43-85-97.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4NzC8k2yTpz23gM for ; Sat, 21 Jan 2023 08:20:54 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id D3567394D8C6 for ; Fri, 20 Jan 2023 21:20:51 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org D3567394D8C6 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1674249651; bh=twdo6QujejuZ8L/LB6eu/+3VhUFQsN+9ED9W3Y4kE3g=; 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=M24jddzc1vKKWTnWustVOJWby//7GtvQYLDelqfG2sD6wL2o+G5iI9WWweYgItV+U vtbeMFOrxvIv6RPSEUV7KsLvYRLZ+AziyJQy09bjD5MTs93rO+6Cq3Tvj/DPIJLBkw IDSthsNwDlzqTQaa7Mt4WLnpQjzd59qmGr4SFuzE= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-oi1-x22b.google.com (mail-oi1-x22b.google.com [IPv6:2607:f8b0:4864:20::22b]) by sourceware.org (Postfix) with ESMTPS id 31C273881D14 for ; Fri, 20 Jan 2023 21:16:58 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 31C273881D14 Received: by mail-oi1-x22b.google.com with SMTP id r9so5466693oig.12 for ; Fri, 20 Jan 2023 13:16:58 -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=twdo6QujejuZ8L/LB6eu/+3VhUFQsN+9ED9W3Y4kE3g=; b=t/bImQaji/aejjn7M8mAtkAHQaFonumDL5XWChJdlUVBZlxtxQV3quVZp7oAPlyEjN udg+BFNCxXFkU7t1JbRNqjhIPd7QsO52Tk6cJph72vNWQ/K7RCbTJ4c7VsoKuRxAfk1b DgLkSqfuoz/oSuo5i58VdIYEII6p9T3pyCAGtyVy8Ggb5TLdZmrzIjZRk1ncDYaJmoEF GfJ2ErAk8EVH69GoP9NFe80vI8I6z1XKjNJOGeUzHyPrg0Ni9Uy/430KQ/MPTyaF/xXG Q52i8qRXGW2yonHyidlzpOxTqt85d8aCWuA6CMC15u2lKQbjy0NWtiCXvQpcdTPz0hRB daFw== X-Gm-Message-State: AFqh2ko1DzMQCIpk2mmGuh9UyAZqfYuAEYBeLeAJAt/7OZGB4VwsRp87 lxLuuDcm8xfW9UrBpKp+omZbYAdU33HMtqqfG60= X-Google-Smtp-Source: AMrXdXuOT8ABom4KrqaS0j+NzVa+HKdzN/vuduIxSDgdmUS/41CxYukIqJ8KrfW9VWIjjX2bNoeEOQ== X-Received: by 2002:a05:6808:5ce:b0:35b:80e6:86f7 with SMTP id d14-20020a05680805ce00b0035b80e686f7mr7337669oij.43.1674249417080; Fri, 20 Jan 2023 13:16:57 -0800 (PST) Received: from mandiga.. ([2804:1b3:a7c1:7e99:f284:be2f:4ee5:d122]) by smtp.gmail.com with ESMTPSA id d18-20020a056830139200b00686467f920bsm6937432otq.48.2023.01.20.13.16.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 20 Jan 2023 13:16:56 -0800 (PST) To: libc-alpha@sourceware.org, Richard Henderson , Noah Goldstein Subject: [PATCH v10 13/24] hppa: Add string-fzb.h and string-fzi.h Date: Fri, 20 Jan 2023 18:16:11 -0300 Message-Id: <20230120211622.3445279-14-adhemerval.zanella@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230120211622.3445279-1-adhemerval.zanella@linaro.org> References: <20230120211622.3445279-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 Reply-To: Adhemerval Zanella Errors-To: libc-alpha-bounces+incoming=patchwork.ozlabs.org@sourceware.org Sender: "Libc-alpha" From: Richard Henderson Use UXOR,SBZ to test for a zero byte within a word. While we can get semi-decent code out of asm-goto, we would do slightly better with a compiler builtin. For index_zero et al, sequential testing of bytes is less expensive than any tricks that involve a count-leading-zeros insn that we don't have. Checked on hppa-linux-gnu. --- sysdeps/hppa/string-fzb.h | 70 +++++++++++++++++++++ sysdeps/hppa/string-fzc.h | 124 ++++++++++++++++++++++++++++++++++++++ sysdeps/hppa/string-fzi.h | 63 +++++++++++++++++++ 3 files changed, 257 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..865e548492 --- /dev/null +++ b/sysdeps/hppa/string-fzb.h @@ -0,0 +1,70 @@ +/* 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 + +/* Determine if any byte within X is zero. This is a pure boolean test. */ + +static __always_inline _Bool +has_zero (op_t x) +{ + _Static_assert (sizeof (op_t) == 4, "64-bit not supported"); + + /* 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) +{ + _Static_assert (sizeof (op_t) == 4, "64-bit not supported"); + + 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) +{ + _Static_assert (sizeof (op_t) == 4, "64-bit not supported"); + + asm goto ("uxor,sbz %%r0,%0,%%r0\n\t" + "uxor,nbz %0,%1,%%r0\n\t" + "b,n %l2" : : "r"(x1), "r"(x2) : : sbz); + return 0; + sbz: + return 1; +} + +#endif /* _STRING_FZB_H */ diff --git a/sysdeps/hppa/string-fzc.h b/sysdeps/hppa/string-fzc.h new file mode 100644 index 0000000000..8ff3416b41 --- /dev/null +++ b/sysdeps/hppa/string-fzc.h @@ -0,0 +1,124 @@ +/* string-fzc.h -- zero byte detection with indexes. HPPA version. + Copyright (C) 2022 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, see + . */ + +#ifndef _STRING_FZC_H +#define _STRING_FZC_H 1 + +#include + +_Static_assert (sizeof (op_t) == 4, "64-bit not supported"); + +/* Given a word X that is known to contain a zero byte, return the + index of the first such within the long in memory order. */ +static __always_inline unsigned int +index_first_zero (op_t x) +{ + unsigned int ret; + + /* Since we have no clz insn, direct tests of the bytes is faster + than loading up the constants to do the masking. */ + asm ("extrw,u,<> %1,23,8,%%r0\n\t" + "ldi 2,%0\n\t" + "extrw,u,<> %1,15,8,%%r0\n\t" + "ldi 1,%0\n\t" + "extrw,u,<> %1,7,8,%%r0\n\t" + "ldi 0,%0" + : "=r"(ret) : "r"(x), "0"(3)); + + return ret; +} + +/* Similarly, but perform the search for byte equality between X1 and X2. */ +static __always_inline unsigned int +index_first_eq (op_t x1, op_t x2) +{ + return index_first_zero (x1 ^ x2); +} + +/* Similarly, but perform the search for zero within X1 or + equality between X1 and X2. */ +static __always_inline unsigned int +index_first_zero_eq (op_t x1, op_t x2) +{ + unsigned int ret; + + /* Since we have no clz insn, direct tests of the bytes is faster + than loading up the constants to do the masking. */ + asm ("extrw,u,= %1,23,8,%%r0\n\t" + "extrw,u,<> %2,23,8,%%r0\n\t" + "ldi 2,%0\n\t" + "extrw,u,= %1,15,8,%%r0\n\t" + "extrw,u,<> %2,15,8,%%r0\n\t" + "ldi 1,%0\n\t" + "extrw,u,= %1,7,8,%%r0\n\t" + "extrw,u,<> %2,7,8,%%r0\n\t" + "ldi 0,%0" + : "=r"(ret) : "r"(x1), "r"(x1 ^ x2), "0"(3)); + + return ret; +} + +/* Similarly, but perform the search for zero within X1 or + inequality between X1 and X2. */ +static __always_inline unsigned int +index_first_zero_ne (op_t x1, op_t x2) +{ + unsigned int ret; + + /* Since we have no clz insn, direct tests of the bytes is faster + than loading up the constants to do the masking. */ + asm ("extrw,u,<> %2,23,8,%%r0\n\t" + "extrw,u,<> %1,23,8,%%r0\n\t" + "ldi 2,%0\n\t" + "extrw,u,<> %2,15,8,%%r0\n\t" + "extrw,u,<> %1,15,8,%%r0\n\t" + "ldi 1,%0\n\t" + "extrw,u,<> %2,7,8,%%r0\n\t" + "extrw,u,<> %1,7,8,%%r0\n\t" + "ldi 0,%0" + : "=r"(ret) : "r"(x1), "r"(x1 ^ x2), "0"(3)); + + return ret; +} + +/* Similarly, but search for the last zero within X. */ +static __always_inline unsigned int +index_last_zero (op_t x) +{ + unsigned int ret; + + /* Since we have no ctz insn, direct tests of the bytes is faster + than loading up the constants to do the masking. */ + asm ("extrw,u,<> %1,15,8,%%r0\n\t" + "ldi 1,%0\n\t" + "extrw,u,<> %1,23,8,%%r0\n\t" + "ldi 2,%0\n\t" + "extrw,u,<> %1,31,8,%%r0\n\t" + "ldi 3,%0" + : "=r"(ret) : "r"(x), "0"(0)); + + return ret; +} + +static __always_inline unsigned int +index_last_eq (op_t x1, op_t x2) +{ + return index_last_zero (x1 ^ x2); +} + +#endif /* _STRING_FZC_H */ diff --git a/sysdeps/hppa/string-fzi.h b/sysdeps/hppa/string-fzi.h new file mode 100644 index 0000000000..b560fa1a89 --- /dev/null +++ b/sysdeps/hppa/string-fzi.h @@ -0,0 +1,63 @@ +/* string-fzi.h -- zero byte indexes. HPPA version. + Copyright (C) 2022 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, see + . */ + +#ifndef _STRING_FZI_H +#define _STRING_FZI_H 1 + +#include +#include + +_Static_assert (sizeof (op_t) == 4, "64-bit not supported"); + +static __always_inline unsigned int +index_first (find_t c) +{ + unsigned int ret; + + /* Since we have no clz insn, direct tests of the bytes is faster + than loading up the constants to do the masking. */ + asm ("extrw,u,= %1,23,8,%%r0\n\t" + "ldi 2,%0\n\t" + "extrw,u,= %1,15,8,%%r0\n\t" + "ldi 1,%0\n\t" + "extrw,u,= %1,7,8,%%r0\n\t" + "ldi 0,%0" + : "=r"(ret) : "r"(c), "0"(3)); + + return ret; +} + +static __always_inline unsigned int +index_last (find_t c) +{ + unsigned int ret; + + /* Since we have no ctz insn, direct tests of the bytes is faster + than loading up the constants to do the masking. */ + asm ("extrw,u,= %1,15,8,%%r0\n\t" + "ldi 1,%0\n\t" + "extrw,u,= %1,23,8,%%r0\n\t" + "ldi 2,%0\n\t" + "extrw,u,= %1,31,8,%%r0\n\t" + "ldi 3,%0" + : "=r"(ret) : "r"(c), "0"(0)); + + return ret; +} + +#endif /* _STRING_FZI_H */ From patchwork Fri Jan 20 21:16:12 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adhemerval Zanella X-Patchwork-Id: 1729843 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=sourceware.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=sourceware.org; envelope-from=libc-alpha-bounces+incoming=patchwork.ozlabs.org@sourceware.org; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; secure) header.d=sourceware.org header.i=@sourceware.org header.a=rsa-sha256 header.s=default header.b=j4IXZ+wR; dkim-atps=neutral Received: from sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4NzC8P6sLLz23gM for ; Sat, 21 Jan 2023 08:20:37 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id CA9E33885C34 for ; Fri, 20 Jan 2023 21:20:35 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org CA9E33885C34 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1674249635; bh=jVr6SqXl9FQsWAJ2toPTqtV+Gz4VS69QgbKHY+kPfMQ=; h=To:Subject:Date:In-Reply-To:References:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=j4IXZ+wRAwwaC5wtryioYyKoTwGxz9ew1OGeHylQ8PlkL53YhuF40Hf8g1EU71UZg kS5WW8ukysmbj+2032T+wZXJYRF1kqw4jH7ctb2dnYYA/TL+8To2wRWormly0giikd HzXE0pI7M+L6EA0YXlMCPdqmeOgtt4BLsaovE6Cw= 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 6462A385B507 for ; Fri, 20 Jan 2023 21:17:00 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 6462A385B507 Received: by mail-ot1-x32d.google.com with SMTP id k1-20020a056830150100b006864d1cb279so3814060otp.5 for ; Fri, 20 Jan 2023 13:17:00 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=jVr6SqXl9FQsWAJ2toPTqtV+Gz4VS69QgbKHY+kPfMQ=; b=LR7DekX2e0UYk6qLJ7xwJHekHpS0smyczEtGmRGsuHZabzOSgobbCSh1cqHWLxthBw K58eIcEG6zw0FuuLj/RcIwUkuCvih0sqVj8shw7t41OWHkIsy9WT2k7uivbWL91PfOxV XJHUuz3GlUU3AmJrnvGBUD49LuLvt1OiCBKp4QeH//2sGV2lg9+smNmDONI1w/VjuilK wmjKNvy/jy7gXIA3jQ4QFPFVUke4S4zfEBqbGbEF8Sz/XV2TFTmu/Jh5fCI6opnRieUm 2A1B6kabwONXHtqx9ULk3iZeCA7en9NhrTD4KAznEwiRN+TmbfFhR3lBb0YtSiQTv6VK TD4Q== X-Gm-Message-State: AFqh2kq9wSaR2ZElAgST0sKA/tQEfnAHjGwkNHFN/TzPxmLKyniG0JxO DrMzeGnAYJBeJVHuQ8tvMbonn72a34cC/jhRkH8= X-Google-Smtp-Source: AMrXdXttKMUGEtUjCV/fHy2p6D722d5pmmWHI9Z+1wXckJnQORnajItdSIORFPZzmJERTeZxvYNprg== X-Received: by 2002:a9d:2c06:0:b0:684:c8ff:8844 with SMTP id f6-20020a9d2c06000000b00684c8ff8844mr7728664otb.12.1674249419411; Fri, 20 Jan 2023 13:16:59 -0800 (PST) Received: from mandiga.. ([2804:1b3:a7c1:7e99:f284:be2f:4ee5:d122]) by smtp.gmail.com with ESMTPSA id d18-20020a056830139200b00686467f920bsm6937432otq.48.2023.01.20.13.16.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 20 Jan 2023 13:16:58 -0800 (PST) To: libc-alpha@sourceware.org, Richard Henderson , Noah Goldstein Subject: [PATCH v10 14/24] alpha: Add string-fzb.h and string-fzi.h Date: Fri, 20 Jan 2023 18:16:12 -0300 Message-Id: <20230120211622.3445279-15-adhemerval.zanella@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230120211622.3445279-1-adhemerval.zanella@linaro.org> References: <20230120211622.3445279-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 Reply-To: Adhemerval Zanella Errors-To: libc-alpha-bounces+incoming=patchwork.ozlabs.org@sourceware.org Sender: "Libc-alpha" From: Richard Henderson While alpha has the more important string functions in assembly, there are still a few for find the generic routines are used. Use the CMPBGE insn, via the builtin, for testing of zeros. Use a simplified expansion of __builtin_ctz when the insn isn't available. Checked on alpha-linux-gnu. Co-authored-by: Adhemerval Zanella --- sysdeps/alpha/string-fza.h | 61 +++++++++++++++++++++++++++++++++++ sysdeps/alpha/string-fzb.h | 52 ++++++++++++++++++++++++++++++ sysdeps/alpha/string-fzi.h | 62 ++++++++++++++++++++++++++++++++++++ sysdeps/alpha/string-shift.h | 44 +++++++++++++++++++++++++ 4 files changed, 219 insertions(+) create mode 100644 sysdeps/alpha/string-fza.h create mode 100644 sysdeps/alpha/string-fzb.h create mode 100644 sysdeps/alpha/string-fzi.h create mode 100644 sysdeps/alpha/string-shift.h diff --git a/sysdeps/alpha/string-fza.h b/sysdeps/alpha/string-fza.h new file mode 100644 index 0000000000..b4a7080c44 --- /dev/null +++ b/sysdeps/alpha/string-fza.h @@ -0,0 +1,61 @@ +/* Basic zero byte detection. Generic C version. + Copyright (C) 2023 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, see + . */ + +#ifndef _STRING_FZA_H +#define _STRING_FZA_H 1 + +#include +#include + +/* The CMPBGE instruction creates a bit mask rather than a byte mask. + However, if we narrow find_t to either 'int' or 'uint8_t', we get + unnecessary truncation instructions from the 'unsigned long' type + returned by __builtin_alpha_cmpbge. */ +typedef op_t find_t; + +static __always_inline find_t +find_zero_all (op_t x) +{ + return __builtin_alpha_cmpbge (0, x); +} + +static __always_inline find_t +find_eq_all (op_t x1, op_t x2) +{ + return find_zero_all (x1 ^ x2); +} + +static __always_inline find_t +find_zero_eq_all (op_t x1, op_t x2) +{ + return find_zero_all (x1) | find_zero_all (x1 ^ x2); +} + +static __always_inline find_t +find_zero_ne_all (op_t x1, op_t x2) +{ + return find_zero_all (x1) | (find_zero_all (x1 ^ x2) ^ 0xff); +} + +/* Define the "inexact" versions in terms of the exact versions. */ +#define find_zero_low find_zero_all +#define find_eq_low find_eq_all +#define find_zero_eq_low find_zero_eq_all +#define find_zero_ne_low find_zero_ne_all + +#endif /* _STRING_FZA_H */ diff --git a/sysdeps/alpha/string-fzb.h b/sysdeps/alpha/string-fzb.h new file mode 100644 index 0000000000..e3934ba413 --- /dev/null +++ b/sysdeps/alpha/string-fzb.h @@ -0,0 +1,52 @@ +/* Zero byte detection; boolean. Alpha version. + Copyright (C) 2023 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, see + . */ + +#ifndef _STRING_FZB_H +#define _STRING_FZB_H 1 + +#include +#include + +/* Note that since CMPBGE creates a bit mask rather than a byte mask, + we cannot simply provide a target-specific string-fza.h. */ + +/* Determine if any byte within X is zero. This is a pure boolean test. */ + +static __always_inline _Bool +has_zero (op_t x) +{ + return __builtin_alpha_cmpbge (0, x) != 0; +} + +/* Likewise, but for byte equality between X1 and X2. */ + +static __always_inline _Bool +has_eq (op_t x1, op_t x2) +{ + return has_zero (x1 ^ x2); +} + +/* Likewise, but for zeros in X1 and equal bytes between X1 and X2. */ + +static __always_inline _Bool +has_zero_eq (op_t x1, op_t x2) +{ + return has_zero (x1) | has_eq (x1, x2); +} + +#endif /* _STRING_FZB_H */ diff --git a/sysdeps/alpha/string-fzi.h b/sysdeps/alpha/string-fzi.h new file mode 100644 index 0000000000..5129b892e7 --- /dev/null +++ b/sysdeps/alpha/string-fzi.h @@ -0,0 +1,62 @@ +/* string-fzi.h -- zero byte detection; indices. Alpha version. + Copyright (C) 2022 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, see + . */ + +#ifndef _STRING_FZI_H +#define _STRING_FZI_H + +#include +#include +#include + +/* Note that since CMPBGE creates a bit mask rather than a byte mask, + we cannot simply provide a target-specific string-fza.h. */ + +/* A subroutine for the index_zero functions. Given a bitmask C, + return the index of the first bit set in memory order. */ +static __always_inline unsigned int +index_first (find_t c) +{ +#ifdef __alpha_cix__ + return __builtin_ctzl (c); +#else + c = c & -c; + return (c & 0xf0 ? 4 : 0) + (c & 0xcc ? 2 : 0) + (c & 0xaa ? 1 : 0); +#endif +} + +/* Similarly, but return the (memory order) index of the last bit + that is non-zero. Note that only the least 8 bits may be nonzero. */ + +static __always_inline unsigned int +index_last (find_t x) +{ +#ifdef __alpha_cix__ + return __builtin_clzl (x) ^ 63; +#else + unsigned r = 0; + if (x & 0xf0) + r += 4; + if (x & (0xc << r)) + r += 2; + if (x & (0x2 << r)) + r += 1; + return r; +#endif +} + +#endif /* _STRING_FZI_H */ diff --git a/sysdeps/alpha/string-shift.h b/sysdeps/alpha/string-shift.h new file mode 100644 index 0000000000..4e2cb2fea1 --- /dev/null +++ b/sysdeps/alpha/string-shift.h @@ -0,0 +1,44 @@ +/* Shift unaligned word read. Alpha version. + Copyright (C) 2023 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, see + . */ + +#ifndef _STRING_SHIFT_H +#define _STRING_SHIFT_H 1 + +#include +#include +#include + +/* Return the mask WORD shifted based on S_INT address value, to ignore + values not presented in the aligned word read. */ +static __always_inline find_t +shift_find (find_t word, uintptr_t s) +{ + return word >> (s % sizeof (op_t)); +} + +/* Mask off the bits defined the the S alignment value. */ +static __always_inline find_t +shift_find_last (find_t word, uintptr_t s) +{ + s = s % sizeof (op_t); + if (s == 0) + return word; + return word & ~((op_t)-1 << s); +} + +#endif /* _STRING_SHIFT_H */ From patchwork Fri Jan 20 21:16:13 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adhemerval Zanella X-Patchwork-Id: 1729834 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=sourceware.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=sourceware.org; envelope-from=libc-alpha-bounces+incoming=patchwork.ozlabs.org@sourceware.org; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; secure) header.d=sourceware.org header.i=@sourceware.org header.a=rsa-sha256 header.s=default header.b=osSLjfIc; dkim-atps=neutral Received: from sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4NzC6G1ZvZz23gV for ; Sat, 21 Jan 2023 08:18:46 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 26801385843D for ; Fri, 20 Jan 2023 21:18:44 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 26801385843D DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1674249524; bh=eaPuAUW6u9EzarB15eu0qKq3XLrPgGatZ3LrJa3nfQo=; h=To:Subject:Date:In-Reply-To:References:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=osSLjfIc+YoHB8WPiTS6CLqXwkVjDlOxVMHDee+6gD9ZN241RRQr/DBn8pPd6Z1Gj 8Tz6BE8ZxbM4CmbfGBP36ACXofRf0T0aK03q80QaZRD0FCz99BBx+UoHqekjTiG/GW Ugsv9EY+ld4xkye4LogKqlSOezJ/W9m7ue04UQpg= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-ot1-x32e.google.com (mail-ot1-x32e.google.com [IPv6:2607:f8b0:4864:20::32e]) by sourceware.org (Postfix) with ESMTPS id 94F873881D1A for ; Fri, 20 Jan 2023 21:17:03 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 94F873881D1A Received: by mail-ot1-x32e.google.com with SMTP id cm26-20020a056830651a00b00684e5c0108dso3819728otb.9 for ; Fri, 20 Jan 2023 13:17: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=eaPuAUW6u9EzarB15eu0qKq3XLrPgGatZ3LrJa3nfQo=; b=yXhAkw/QvR4+75CRpMJ11i0a14w7de6p7ErVF776rX0FwPJ236VpkIgFxuVCbxCWgw 1vV+AoHkJ53dwIuLzf4GOnbWiH/35VhpuAzGoxbtJf00nbDNDSLlwdyxeVIB8qMzWoLp 15TBfWBHOoMfhsius01687pdF82+mankGelaiqH2Xe/aJb/bA+cRXWmO4K0nGW7mlNhI YOpIXP1OFdsLCF6ZgWzrDnwkLTSyuNIHGUeARmR0/Y8Y7Gse++3XgkAXixx1MwBd6Xl9 TKsBPxmVsHjQzRBeV7vetx8/9SOzHLF50F1Mx6unBINlZmJktz/HrXPiKCTD+0gzuSPc XEWw== X-Gm-Message-State: AFqh2kqIJ/LjS4sfqS5ZH4X93gKq6QKTj54JHP3KbOV02HNxLL5kACgG /WegedAwH23KpXDcTYuVuQWW3/FvPIBWtIsbP+0= X-Google-Smtp-Source: AMrXdXsjz7Xn80dSROJJZIxS+KHudd5LUXWiOLWdTnOZEb6bQFPNQOZLzrS6KiIkSvrq8Tr4roIuhA== X-Received: by 2002:a9d:664a:0:b0:686:6392:ed3c with SMTP id q10-20020a9d664a000000b006866392ed3cmr4383536otm.14.1674249422470; Fri, 20 Jan 2023 13:17:02 -0800 (PST) Received: from mandiga.. ([2804:1b3:a7c1:7e99:f284:be2f:4ee5:d122]) by smtp.gmail.com with ESMTPSA id d18-20020a056830139200b00686467f920bsm6937432otq.48.2023.01.20.13.16.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 20 Jan 2023 13:17:01 -0800 (PST) To: libc-alpha@sourceware.org, Richard Henderson , Noah Goldstein Subject: [PATCH v10 15/24] arm: Add string-fza.h Date: Fri, 20 Jan 2023 18:16:13 -0300 Message-Id: <20230120211622.3445279-16-adhemerval.zanella@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230120211622.3445279-1-adhemerval.zanella@linaro.org> References: <20230120211622.3445279-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 Reply-To: Adhemerval Zanella Errors-To: libc-alpha-bounces+incoming=patchwork.ozlabs.org@sourceware.org Sender: "Libc-alpha" From: Richard Henderson While arm has the more important string functions in assembly, there are still a few generic routines used. Use the UQSUB8 insn for testing of zeros. Checked on armv7-linux-gnueabihf --- sysdeps/arm/armv6t2/string-fza.h | 68 ++++++++++++++++++++++++++++++++ 1 file changed, 68 insertions(+) create mode 100644 sysdeps/arm/armv6t2/string-fza.h diff --git a/sysdeps/arm/armv6t2/string-fza.h b/sysdeps/arm/armv6t2/string-fza.h new file mode 100644 index 0000000000..50afaba038 --- /dev/null +++ b/sysdeps/arm/armv6t2/string-fza.h @@ -0,0 +1,68 @@ +/* Zero byte detection; basics. ARM version. + Copyright (C) 2023 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, see + . */ + +#ifndef _STRING_FZA_H +#define _STRING_FZA_H 1 + +#include +#include + +/* The functions return a byte mask. */ +typedef op_t find_t; + +/* This function returns at least one bit set within every byte + of X that is zero. */ +static __always_inline find_t +find_zero_all (op_t x) +{ + /* Use unsigned saturated subtraction from 1 in each byte. + That leaves 1 for every byte that was zero. */ + op_t ones = repeat_bytes (0x01); + return __builtin_arm_uqsub8 (ones, x); +} + +/* Identify bytes that are equal between X1 and X2. */ +static __always_inline find_t +find_eq_all (op_t x1, op_t x2) +{ + return find_zero_all (x1 ^ x2); +} + +/* Identify zero bytes in X1 or equality between X1 and X2. */ +static __always_inline find_t +find_zero_eq_all (op_t x1, op_t x2) +{ + return find_zero_all (x1) | find_zero_all (x1 ^ x2); +} + +/* Identify zero bytes in X1 or inequality between X1 and X2. */ +static __always_inline find_t +find_zero_ne_all (op_t x1, op_t x2) +{ + /* Make use of the fact that we'll already have ONES in a register. */ + op_t ones = repeat_bytes (0x01); + return find_zero_all (x1) | (find_zero_all (x1 ^ x2) ^ ones); +} + +/* Define the "inexact" versions in terms of the exact versions. */ +#define find_zero_low find_zero_all +#define find_eq_low find_eq_all +#define find_zero_eq_low find_zero_eq_all +#define find_zero_ne_low find_zero_ne_all + +#endif /* _STRING_FZA_H */ From patchwork Fri Jan 20 21:16:14 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adhemerval Zanella X-Patchwork-Id: 1729838 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=sourceware.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=sourceware.org; envelope-from=libc-alpha-bounces+incoming=patchwork.ozlabs.org@sourceware.org; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; secure) header.d=sourceware.org header.i=@sourceware.org header.a=rsa-sha256 header.s=default header.b=v5gZHhwH; dkim-atps=neutral Received: from sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4NzC735HQ7z23gV for ; Sat, 21 Jan 2023 08:19:27 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 8B56038582BD for ; Fri, 20 Jan 2023 21:19:25 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 8B56038582BD DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1674249565; bh=/ldL5Mg0I3ZuGb3h/TCF9ldgWkiTF4nlu2BkAtFavko=; h=To:Subject:Date:In-Reply-To:References:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=v5gZHhwHuDIWsI1RvsCELVjza3CFdzUxV4ll2ESn6Qr9eqXDTrvEEJMDtyRUNFJhG vrBo0nMSNsX4nmoWTzZBZCbDb6ko0YZutcNfr1MgNCPxbkIvaV9w6+JBi2cYwLNsb7 5G5ZLu/3J36gmy9O/IWy/TE2BJp3pVCbd1xEmZFA= 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 BEB7138493C9 for ; Fri, 20 Jan 2023 21:17:05 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org BEB7138493C9 Received: by mail-ot1-x329.google.com with SMTP id x21-20020a056830245500b006865ccca77aso3802551otr.11 for ; Fri, 20 Jan 2023 13:17: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=/ldL5Mg0I3ZuGb3h/TCF9ldgWkiTF4nlu2BkAtFavko=; b=Qsgauvw6+oRY4Gbey8goZVlpN35q03fQ9+rgxdt4w2yuJSDUGv1fSV7aFbotQQgxQd ruh80W7pzCKkDdb1Wwt4YhKGwfnrhwGJI1nQmKT6jeSdjDZUdon3TvWjfrXxY9Zv5a5V a9dyNDO3hCOxN7QTcabc7Z2LLlEv9sYk8hBIvt2n4GYpQOHrUFg61b84GyfCFw5a1tWj pKSh9wAUFn/muLjhABuNg5aQZ2gzAXLGJWrCEjvyfpdoblnAed5cGZzKEz+RkcWUm2kX GeeTJVfkI410NsVJeIOGQi31KDqGUMbpgQGpiVwW+Uw8DsfskG8JigB4PnUEpgmxjjKM hYcQ== X-Gm-Message-State: AFqh2kpHTPgXGfDZuYMPj/YbpkZa2UnGMIt2o0iVXfzogZp3jfiF2aYu i8XHURr2+a4tBTorPDcNKn9hxkhPxWPcNl0wWPM= X-Google-Smtp-Source: AMrXdXtPgcIFoCH9xrHeAKZcZfEHD2e3PAakR1MGIzaSgkkliTACT8JkFX0NS6TlUsgDPo5VPRBBbw== X-Received: by 2002:a9d:74cc:0:b0:66e:9510:1da5 with SMTP id a12-20020a9d74cc000000b0066e95101da5mr9177481otl.8.1674249424568; Fri, 20 Jan 2023 13:17:04 -0800 (PST) Received: from mandiga.. ([2804:1b3:a7c1:7e99:f284:be2f:4ee5:d122]) by smtp.gmail.com with ESMTPSA id d18-20020a056830139200b00686467f920bsm6937432otq.48.2023.01.20.13.17.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 20 Jan 2023 13:17:03 -0800 (PST) To: libc-alpha@sourceware.org, Richard Henderson , Noah Goldstein Subject: [PATCH v10 16/24] powerpc: Add string-fza.h Date: Fri, 20 Jan 2023 18:16:14 -0300 Message-Id: <20230120211622.3445279-17-adhemerval.zanella@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230120211622.3445279-1-adhemerval.zanella@linaro.org> References: <20230120211622.3445279-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 Reply-To: Adhemerval Zanella Errors-To: libc-alpha-bounces+incoming=patchwork.ozlabs.org@sourceware.org Sender: "Libc-alpha" From: Richard Henderson While ppc has the more important string functions in assembly, there are still a few generic routines used. Use the Power 6 CMPB insn for testing of zeros. Checked on powerpc64le-linux-gnu. --- sysdeps/powerpc/string-fza.h | 72 ++++++++++++++++++++++++++++++++++++ 1 file changed, 72 insertions(+) create mode 100644 sysdeps/powerpc/string-fza.h diff --git a/sysdeps/powerpc/string-fza.h b/sysdeps/powerpc/string-fza.h new file mode 100644 index 0000000000..5dec740041 --- /dev/null +++ b/sysdeps/powerpc/string-fza.h @@ -0,0 +1,72 @@ +/* Zero byte detection; basics. PowerPC version. + Copyright (C) 2023 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, see + . */ + +#ifndef _POWERPC_STRING_FZA_H +#define _POWERPC_STRING_FZA_H 1 + +/* PowerISA 2.05 (POWER6) provides cmpb instruction. */ +#ifdef _ARCH_PWR6 +# include +# include + +/* The functions return a byte mask. */ +typedef op_t find_t; + +/* This function returns 0xff for each byte that is + equal between X1 and X2. */ + +static __always_inline find_t +find_eq_all (op_t x1, op_t x2) +{ + return __builtin_cmpb (x1, x2); +} + +/* This function returns 0xff for each byte that is zero in X. */ + +static __always_inline find_t +find_zero_all (op_t x) +{ + return find_eq_all (x, 0); +} + +/* Identify zero bytes in X1 or equality between X1 and X2. */ + +static __always_inline find_t +find_zero_eq_all (op_t x1, op_t x2) +{ + return find_zero_all (x1) | find_eq_all (x1, x2); +} + +/* Identify zero bytes in X1 or inequality between X1 and X2. */ + +static __always_inline find_t +find_zero_ne_all (op_t x1, op_t x2) +{ + return find_zero_all (x1) | ~find_eq_all (x1, x2); +} + +/* Define the "inexact" versions in terms of the exact versions. */ +# define find_zero_low find_zero_all +# define find_eq_low find_eq_all +# define find_zero_eq_low find_zero_eq_all +# define find_zero_ne_low find_zero_ne_all +#else +# include +#endif /* _ARCH_PWR6 */ + +#endif /* _POWERPC_STRING_FZA_H */ From patchwork Fri Jan 20 21:16:15 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adhemerval Zanella X-Patchwork-Id: 1729831 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=sourceware.org (client-ip=8.43.85.97; helo=sourceware.org; envelope-from=libc-alpha-bounces+incoming=patchwork.ozlabs.org@sourceware.org; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; secure) header.d=sourceware.org header.i=@sourceware.org header.a=rsa-sha256 header.s=default header.b=hU6DL+9V; dkim-atps=neutral Received: from sourceware.org (ip-8-43-85-97.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4NzC5W0H4Lz23gV for ; Sat, 21 Jan 2023 08:18:07 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 8D7823893676 for ; Fri, 20 Jan 2023 21:18:04 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 8D7823893676 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1674249484; 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=hU6DL+9VHsCXJqwIHAFt723729+Mq93muC0aRhjgBIzOFleKfP2xhji6jYy9L3/f9 igZ8wSyFXP8M6SkzCtrpD+/lOsURzZTY43uEPyr4+VVe/Dg7gaIzi7BfrrmhhWMDYn 0WOBzYETrNpDPEzlEPTPgfHGDqvsgWM57mfFxKhA= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-ot1-x32e.google.com (mail-ot1-x32e.google.com [IPv6:2607:f8b0:4864:20::32e]) by sourceware.org (Postfix) with ESMTPS id A0CF1384F00C for ; Fri, 20 Jan 2023 21:17:07 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org A0CF1384F00C Received: by mail-ot1-x32e.google.com with SMTP id cc13-20020a05683061cd00b00684b8cf2f4dso3799496otb.12 for ; Fri, 20 Jan 2023 13:17: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=rhAaYi6DtXp7uLXidJGinRFumCd11mLY/aet6ITY9Xc=; b=MpDMpjC5GSBmsldBp8uXUXNK2g10qGc9k44lE7g+rvFKNfE/zF7WGZjo6k1l6w28rJ iPcuAIeexJvBs2MKvCXzoM8a1KPtZtNLCUhr7PNGg5zkxjD3HdHqpv/wXpv4+LPfyQds QFpNlx7PujO2uol9k77biJ5ka71lPZtAU6/pZebFJb1xgEps3mYt+vZCeoi8XJY79plP eftbeWyuMpIAlPGeAoqeT4YfXaUPyis9FyB60p6sUiDv66uCiKJHccoFi+kKwbY6VmuF JcJm59WsSu5gGryrDY/ywqEjE7VO9OWx3ZgHQg5HDdpZXNIlW0NF34D+J6NWvK2myVdZ 8XUQ== X-Gm-Message-State: AFqh2koMAmwi3CKfzNkzw5ASq2p2QZjmcp8ujEsJ8b1ZODm4BySZbGoS QPZTAA460OxuUpqwkKeJLOHNw6tQ05ADLYRk+wM= X-Google-Smtp-Source: AMrXdXveq+OhFrV30pLfYXhjlXyMbBl3WMd4V9KXtFFXI36X2CvjrIGeMwe5sACp+mGsFEifTSHqUw== X-Received: by 2002:a9d:66da:0:b0:686:56c6:34bd with SMTP id t26-20020a9d66da000000b0068656c634bdmr6591623otm.14.1674249426675; Fri, 20 Jan 2023 13:17:06 -0800 (PST) Received: from mandiga.. ([2804:1b3:a7c1:7e99:f284:be2f:4ee5:d122]) by smtp.gmail.com with ESMTPSA id d18-20020a056830139200b00686467f920bsm6937432otq.48.2023.01.20.13.17.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 20 Jan 2023 13:17:05 -0800 (PST) To: libc-alpha@sourceware.org, Richard Henderson , Noah Goldstein Subject: [PATCH v10 17/24] sh: Add string-fzb.h Date: Fri, 20 Jan 2023 18:16:15 -0300 Message-Id: <20230120211622.3445279-18-adhemerval.zanella@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230120211622.3445279-1-adhemerval.zanella@linaro.org> References: <20230120211622.3445279-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 Reply-To: Adhemerval Zanella Errors-To: libc-alpha-bounces+incoming=patchwork.ozlabs.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 Fri Jan 20 21:16:16 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adhemerval Zanella X-Patchwork-Id: 1729847 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=sourceware.org (client-ip=8.43.85.97; helo=sourceware.org; envelope-from=libc-alpha-bounces+incoming=patchwork.ozlabs.org@sourceware.org; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; secure) header.d=sourceware.org header.i=@sourceware.org header.a=rsa-sha256 header.s=default header.b=UeDpHMAq; dkim-atps=neutral Received: from sourceware.org (ip-8-43-85-97.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4NzC9b62LWz23gM for ; Sat, 21 Jan 2023 08:21:39 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id A37F838AA266 for ; Fri, 20 Jan 2023 21:21:37 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org A37F838AA266 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1674249697; bh=mCE/YFqXL4Z7i4zGFW/a0I/C1EeOtkop6T1+5F6jnvE=; h=To:Subject:Date:In-Reply-To:References:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=UeDpHMAqIM5bl0rTrTonWebvXsgPuPJKbg5wpVruA085axiNAJfc8YT8LOpybQzeI R4t4xqqXoOZgB4Q0UJPSRLigqTjZvzfnSPB5jU3l7CloFUjiKAalZb30vfyQ8pFVdg a1A5tUZZy7sDGEwi1WSCQv67JySUH9y/EuC6HHvg= 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 4602E38845F9 for ; Fri, 20 Jan 2023 21:17:10 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 4602E38845F9 Received: by mail-ot1-x329.google.com with SMTP id d6-20020a056830138600b0068585c52f86so3823488otq.4 for ; Fri, 20 Jan 2023 13:17: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=mCE/YFqXL4Z7i4zGFW/a0I/C1EeOtkop6T1+5F6jnvE=; b=gULIv7W7na+ECbV3t68H5cUSCm1goy/ew0Ue1E313fnWQKhVuosqy9jYJL8ToNzXH8 LWjvRCY/M9k08VZqmWwYRluEQ+K51h4njC60BGkEiDg/J4JivE/Ro7RRZlC53uu4HJSi R0fBtKPTavWSj0E9fPWNdJc6mI2bLzZ+mYayO9A2Gy2en7LNUJkDom/sPRVJ7FR/Qmxa 1kWLiKW6olo9LrcpDCQdQzkmjGyB36yfb1mliThPykx8QxfMiCgNmDQwOWS3QBd8PpYW RWckjZU728qUCK8ViC95D/69AgvfjZAVhJp7mj0EbWX2ZRvxc+yinjx+w17xFNfxopgx y/Jw== X-Gm-Message-State: AFqh2kr6qfKsPk6EARZ0spxCt2iB2TSO407rGYM3pPBvX93YrAyddKfw N91TAcJxEmvZ4aQW7VqbOyWpAjVMNS1xVS8RiE8= X-Google-Smtp-Source: AMrXdXsqrkroJA0uVG8YwwAS9TRKMJGQRV0OmxVextPUX9eMZPelys4nBKqo2nA9AKbXKszbsFlZaw== X-Received: by 2002:a9d:6b03:0:b0:684:e93d:c06d with SMTP id g3-20020a9d6b03000000b00684e93dc06dmr7932327otp.17.1674249429010; Fri, 20 Jan 2023 13:17:09 -0800 (PST) Received: from mandiga.. ([2804:1b3:a7c1:7e99:f284:be2f:4ee5:d122]) by smtp.gmail.com with ESMTPSA id d18-20020a056830139200b00686467f920bsm6937432otq.48.2023.01.20.13.17.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 20 Jan 2023 13:17:08 -0800 (PST) To: libc-alpha@sourceware.org, Richard Henderson , Noah Goldstein Subject: [PATCH v10 18/24] string: Hook up the default implementation on test-strlen Date: Fri, 20 Jan 2023 18:16:16 -0300 Message-Id: <20230120211622.3445279-19-adhemerval.zanella@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230120211622.3445279-1-adhemerval.zanella@linaro.org> References: <20230120211622.3445279-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 Reply-To: Adhemerval Zanella Errors-To: libc-alpha-bounces+incoming=patchwork.ozlabs.org@sourceware.org Sender: "Libc-alpha" Also remove the simple_STRLEN and builtin_strlen, which are not used anywhere. --- 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 Fri Jan 20 21:16:17 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adhemerval Zanella X-Patchwork-Id: 1729841 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=sourceware.org (client-ip=8.43.85.97; helo=sourceware.org; envelope-from=libc-alpha-bounces+incoming=patchwork.ozlabs.org@sourceware.org; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; secure) header.d=sourceware.org header.i=@sourceware.org header.a=rsa-sha256 header.s=default header.b=QtshHtvM; dkim-atps=neutral Received: from sourceware.org (server2.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4NzC7s492Gz23hB for ; Sat, 21 Jan 2023 08:20:09 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 5915B3895FDA for ; Fri, 20 Jan 2023 21:20:07 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 5915B3895FDA DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1674249607; bh=sY+YvZjWeG+Di1NMnZoY5q7yd+IP4Ia8ez9SoC+m9Hg=; 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=QtshHtvMNy9OghrhS+U/CEzv1HHgFJ6gudn2Ns26wH8XXpgvEI0mbHLbNXmTwuEEU 6VMq3mnRVbgld38FV8qGJ0DjSVh/FuHOc0CHv+7DqEJ6AwHVIT7iKsNO/DZfbsdp1b 2JubBi4qtpCdxU5yOX517500TclHFAYe0/IQbyqk= 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 9CCC73854153 for ; Fri, 20 Jan 2023 21:17:12 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 9CCC73854153 Received: by mail-ot1-x336.google.com with SMTP id m18-20020a05683026d200b0068661404380so3828794otu.2 for ; Fri, 20 Jan 2023 13:17:12 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=sY+YvZjWeG+Di1NMnZoY5q7yd+IP4Ia8ez9SoC+m9Hg=; b=ZZ7g/xJdxzRUEhxUg1f+Omg2af5xMRAMbCPSuvLwUPlsP/eqBBYiD2XnoqWnYWWeau CBBzF8Bdg1QgCKn79yrdoRW7KxAn0B5nDYO1gu5K6Zxml4Tl7bqDmKWV/aOxEO9tRwhD Fpo/5THltoyJA0YHyHdczP4C1GZJIXHHKRCyRXMheyqlhNkWKqFYrRUccOHJ2Bh4ZYJ6 QwyB4mZuAXMWmEJdqS1eUJsEjjwHHElZo9hRkk/qby56qqzAHp1j1pPxD/kbl7mcxiVm ekhTB0LQrm7WUGhLc7gEl828ZcLgZ+K8vu/WiNONYYQ8OM8oAnGwedIoaZIS/JBoKpQe vlWw== X-Gm-Message-State: AFqh2krl4fQC2Rdrz2d37z1qRj8r/X7Xb41/wGmwGtUMdtZ+hTdDX8Mh nq1l7HXSp/xfhVLfWAbi0aHx4hr0ayqijp187XE= X-Google-Smtp-Source: AMrXdXvqECWysVgW7NorsfkLsuebUTr3yGL3chggkxyR3S91JXmemb02FFU+n4c4FCFVxTTimFu50g== X-Received: by 2002:a05:6830:314f:b0:686:3bb9:19e6 with SMTP id c15-20020a056830314f00b006863bb919e6mr9829233ots.9.1674249431292; Fri, 20 Jan 2023 13:17:11 -0800 (PST) Received: from mandiga.. ([2804:1b3:a7c1:7e99:f284:be2f:4ee5:d122]) by smtp.gmail.com with ESMTPSA id d18-20020a056830139200b00686467f920bsm6937432otq.48.2023.01.20.13.17.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 20 Jan 2023 13:17:10 -0800 (PST) To: libc-alpha@sourceware.org, Richard Henderson , Noah Goldstein Subject: [PATCH v10 19/24] string: Hook up the default implementation on test-strnlen Date: Fri, 20 Jan 2023 18:16:17 -0300 Message-Id: <20230120211622.3445279-20-adhemerval.zanella@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230120211622.3445279-1-adhemerval.zanella@linaro.org> References: <20230120211622.3445279-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 Reply-To: Adhemerval Zanella Errors-To: libc-alpha-bounces+incoming=patchwork.ozlabs.org@sourceware.org Sender: "Libc-alpha" Also remove the SIMPLE_STRNLEN, which is not used anywhere. --- 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..976c65dc09 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 __strlen_default +# define memchr __memchr_default +# include "string/strnlen.c" +IMPL (__strlen_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 Fri Jan 20 21:16:18 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adhemerval Zanella X-Patchwork-Id: 1729848 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=sourceware.org (client-ip=8.43.85.97; helo=sourceware.org; envelope-from=libc-alpha-bounces+incoming=patchwork.ozlabs.org@sourceware.org; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; secure) header.d=sourceware.org header.i=@sourceware.org header.a=rsa-sha256 header.s=default header.b=NmTXDbX6; dkim-atps=neutral Received: from sourceware.org (ip-8-43-85-97.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4NzCBP1PPQz23gM for ; Sat, 21 Jan 2023 08:22:21 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 18FB73896C2B for ; Fri, 20 Jan 2023 21:22:19 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 18FB73896C2B DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1674249739; bh=WlwRBvpBuUGYAO3ObfLqIDIYorlFz4kL9P0jSfzvCFk=; h=To:Subject:Date:In-Reply-To:References:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=NmTXDbX6p1a40JHpepREVR4iC2bXfsqrMwG+4QjF7gUBcwVDmNE6E/O5rBqH40Rul 3Mjt5qXs6rQY3BzmrKB+DtbDrCOh38hPqvKpZ/iOQ3SLJZ1hAhBZFkWBjZunl9cFvq K5TGfkYx/QgpAK2C3zjAHqjU/rD6i09r85uIAs2s= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-ot1-x32f.google.com (mail-ot1-x32f.google.com [IPv6:2607:f8b0:4864:20::32f]) by sourceware.org (Postfix) with ESMTPS id CB337385841E for ; Fri, 20 Jan 2023 21:17:14 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org CB337385841E Received: by mail-ot1-x32f.google.com with SMTP id f88-20020a9d03e1000000b00684c4041ff1so3819431otf.8 for ; Fri, 20 Jan 2023 13:17:14 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=WlwRBvpBuUGYAO3ObfLqIDIYorlFz4kL9P0jSfzvCFk=; b=tvkkkKEb7wEQw45Z+7wroAg50e3u3a0wpRntEvPaPGU6K0kOolsCBC5NRatwbkADDN ogpgq36TW5Rj0nokyZTOqV972Tlr5OebbFmt3ekqNwqDUDFx4CVkszNd5BtOpRTjpVC/ BalbuVdOTRGy1yQTs2NhYHgCPGGTEfrOd99RqigxBOYCr3GS/gIv9H8SoDeAmnEh+kl5 ubbmljy7fQpoFtoic+U+AaBbrI0Mq1j/MuR9pYCqp+iRjQS9V1KcIikFyMCwt28XkyYn yBAtqdjys8bSJk6CIIPdQQPxzEA7SORUqYiq4BVBJBHOyFsE+d5edokfFR4yW/yFBNU9 maUQ== X-Gm-Message-State: AFqh2krVPmd6/S+bFghljTbLXjYZnfzXoTYqeS/tmGV4m5xQGXdZFzzw kMZUHxM1blRQ8KmYRGxydC2fykwewK72YUglSIw= X-Google-Smtp-Source: AMrXdXtAxNXrfEjni/SzaqGEAGsYbs3PHmucWHvYxQt7Wsyx6ZWjnm23Dw7JkuPT4cklQXhFaf17Gw== X-Received: by 2002:a05:6830:1482:b0:684:a027:f831 with SMTP id s2-20020a056830148200b00684a027f831mr7425988otq.13.1674249433498; Fri, 20 Jan 2023 13:17:13 -0800 (PST) Received: from mandiga.. ([2804:1b3:a7c1:7e99:f284:be2f:4ee5:d122]) by smtp.gmail.com with ESMTPSA id d18-20020a056830139200b00686467f920bsm6937432otq.48.2023.01.20.13.17.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 20 Jan 2023 13:17:12 -0800 (PST) To: libc-alpha@sourceware.org, Richard Henderson , Noah Goldstein Subject: [PATCH v10 20/24] string: Hook up the default implementation on test-strchr Date: Fri, 20 Jan 2023 18:16:18 -0300 Message-Id: <20230120211622.3445279-21-adhemerval.zanella@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230120211622.3445279-1-adhemerval.zanella@linaro.org> References: <20230120211622.3445279-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 Reply-To: Adhemerval Zanella Errors-To: libc-alpha-bounces+incoming=patchwork.ozlabs.org@sourceware.org Sender: "Libc-alpha" Also remove the simple_STRCHR, which can be easily replaced. --- 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 Fri Jan 20 21:16:19 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adhemerval Zanella X-Patchwork-Id: 1729849 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=sourceware.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=sourceware.org; envelope-from=libc-alpha-bounces+incoming=patchwork.ozlabs.org@sourceware.org; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; secure) header.d=sourceware.org header.i=@sourceware.org header.a=rsa-sha256 header.s=default header.b=mL2K9CQx; dkim-atps=neutral Received: from sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4NzCCC2R68z23gM for ; Sat, 21 Jan 2023 08:23:03 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id BC8A53881D2D for ; Fri, 20 Jan 2023 21:23:00 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org BC8A53881D2D DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1674249780; bh=BjdtcZv5xPKYYHAXCP0rQzjiHaC4gBNPxLaODhMfNdU=; h=To:Subject:Date:In-Reply-To:References:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=mL2K9CQx08HDZnPeK1n8koIzKgwWVdaYRfyrH7KqLwtZ/jvxq6yyaQ4nB5GTmq0TM 62dcwpcX68OSQa5HsjzKZnMxobAdaUnRBkvvI4zMtQ9aXQmNZ7smQZbwSQZDFx4E8y 2pzmI1CSa6Y4jeiUs57zBQ4yD/Qq9ym50VL9qBRw= 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 E48CC3887F7B for ; Fri, 20 Jan 2023 21:17:16 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org E48CC3887F7B Received: by mail-ot1-x336.google.com with SMTP id f5-20020a9d5f05000000b00684c0c2eb3fso3811113oti.10 for ; Fri, 20 Jan 2023 13:17:16 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=BjdtcZv5xPKYYHAXCP0rQzjiHaC4gBNPxLaODhMfNdU=; b=o+ch1Ie4jl07x9jiKO/ytbsmQyRyjmHUbFXRgyoZBmhJ8xUp1Az2ZYuTS9hU06FJnV Q5LGgE4UozetL+LRnc479QypGq4DUeB7apIeJPaLSjXKAyLYGTiMBx4Kc4Dn6Adc/ZQF HmLhfdXSh/KWeEaYOatqclHhkj6bYR31hc2cxyQgaldjNrpfJoyEafawXnC98/SFlZ/8 d25gtimMbnSKyoHV9zn9d+XjBYX5C/tZnEGxsYiaJ6+L38uW1RYdBra0MnLmFzryCUWX ubI7dZEcGGHkAJqB1wL1eTvNHC91R5328Ei6+d0Bsv68Mb4BpcnoBovo9u3+Irce63bO IKrw== X-Gm-Message-State: AFqh2kq3vl9hXc/Nna4DUGIfarBAVYc7tRo3xhE7fKFAMS2yrvHVAMCv rV1u1r0v5TuuOxX9MnWlg8+E7X5H09SsT9yN3Tk= X-Google-Smtp-Source: AMrXdXvj4ehQRuy0wfkfDo1RqRDpeCVd7/bWwx6qKqywwoqJqVB6Y4wDwah5oXK3RXVkVBZ4zY8JnA== X-Received: by 2002:a05:6830:658c:b0:671:cacb:681b with SMTP id cn12-20020a056830658c00b00671cacb681bmr10103095otb.22.1674249435621; Fri, 20 Jan 2023 13:17:15 -0800 (PST) Received: from mandiga.. ([2804:1b3:a7c1:7e99:f284:be2f:4ee5:d122]) by smtp.gmail.com with ESMTPSA id d18-20020a056830139200b00686467f920bsm6937432otq.48.2023.01.20.13.17.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 20 Jan 2023 13:17:14 -0800 (PST) To: libc-alpha@sourceware.org, Richard Henderson , Noah Goldstein Subject: [PATCH v10 21/24] string: Hook up the default implementation on test-strcmp Date: Fri, 20 Jan 2023 18:16:19 -0300 Message-Id: <20230120211622.3445279-22-adhemerval.zanella@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230120211622.3445279-1-adhemerval.zanella@linaro.org> References: <20230120211622.3445279-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 Reply-To: Adhemerval Zanella Errors-To: libc-alpha-bounces+incoming=patchwork.ozlabs.org@sourceware.org Sender: "Libc-alpha" --- 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 Fri Jan 20 21:16:20 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adhemerval Zanella X-Patchwork-Id: 1729846 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=sourceware.org (client-ip=8.43.85.97; helo=sourceware.org; envelope-from=libc-alpha-bounces+incoming=patchwork.ozlabs.org@sourceware.org; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; secure) header.d=sourceware.org header.i=@sourceware.org header.a=rsa-sha256 header.s=default header.b=OkGfkSLL; dkim-atps=neutral Received: from sourceware.org (ip-8-43-85-97.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4NzC9C1f4hz23gM for ; Sat, 21 Jan 2023 08:21:19 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 18F193889E04 for ; Fri, 20 Jan 2023 21:21:17 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 18F193889E04 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1674249677; bh=KHtcW8v9AgEJXBxhRQhzHR+sZS5ZSEoyLU3ZktxYi8c=; h=To:Subject:Date:In-Reply-To:References:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=OkGfkSLLttPtSOwq5unlM6UYfp3xKyRMxLiHsipazQWWoadp5vgaGXHYcGUuqi/op AWXVTeXToMdlF3EC66IfNbNQmzvkldlbRuBzJP2IcmaHBAqSH2CHToAH97uUJCJ0pu jRvUVZZroL+mKADbCJkYuKBzzF8UhLOQYGRZhy7o= 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 C44A33885523 for ; Fri, 20 Jan 2023 21:17:18 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org C44A33885523 Received: by mail-ot1-x329.google.com with SMTP id d6-20020a056830138600b0068585c52f86so3823644otq.4 for ; Fri, 20 Jan 2023 13:17:18 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=KHtcW8v9AgEJXBxhRQhzHR+sZS5ZSEoyLU3ZktxYi8c=; b=zEc7wAXHq0QPkxrnkSNk5iiniQKfzY4P0AuiR+P8EAmmmCs2PNftNouJz+1dNFsUrS UpCLs/LcXDV8CUt5Eqd0sqk6QFNGwiPYSi65zjmaF8+nyayBmQS+RSJfnAhi6fwzuCpQ UOIj6UQLgKcF6o3+I/8c9/OwPpBPhYG88bBPjFXdLM2yb+/7IvtaFqk0+cCnQpkUKQYU kuboN/Llrs+/nv3JnazQg7Yzui/mo7SsWLEi964jboci+xdEMbCrhtX3sxGy2kvfK/TJ t2TIt5+L8GrJRCbVFSOrdJkMPo3c4JEcpzvTY23UME+yZCwSaM7SHoEJzd5BppaUG+uL 8xKQ== X-Gm-Message-State: AFqh2kp+fqv2Q/1Qph/AZtJNevtC9UgrEh1xRV/reemxaVssodoviJTG fsAWtRN5eZiA8aRc7nlmDz0SCcWyu2iP0mYoNPo= X-Google-Smtp-Source: AMrXdXvyz3HKkwbTPM1nKreUGJuHomZdw3ytl7RYlDE5v+BBD1EM4vzrJKfmE4dwXfQzgFsl/hqR6w== X-Received: by 2002:a05:6830:1bf6:b0:676:dbab:a8ce with SMTP id k22-20020a0568301bf600b00676dbaba8cemr8242876otb.15.1674249437925; Fri, 20 Jan 2023 13:17:17 -0800 (PST) Received: from mandiga.. ([2804:1b3:a7c1:7e99:f284:be2f:4ee5:d122]) by smtp.gmail.com with ESMTPSA id d18-20020a056830139200b00686467f920bsm6937432otq.48.2023.01.20.13.17.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 20 Jan 2023 13:17:17 -0800 (PST) To: libc-alpha@sourceware.org, Richard Henderson , Noah Goldstein Subject: [PATCH v10 22/24] string: Hook up the default implementation on test-strncmp Date: Fri, 20 Jan 2023 18:16:20 -0300 Message-Id: <20230120211622.3445279-23-adhemerval.zanella@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230120211622.3445279-1-adhemerval.zanella@linaro.org> References: <20230120211622.3445279-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 Reply-To: Adhemerval Zanella Errors-To: libc-alpha-bounces+incoming=patchwork.ozlabs.org@sourceware.org Sender: "Libc-alpha" --- 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 Fri Jan 20 21:16:21 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adhemerval Zanella X-Patchwork-Id: 1729845 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=sourceware.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=sourceware.org; envelope-from=libc-alpha-bounces+incoming=patchwork.ozlabs.org@sourceware.org; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; secure) header.d=sourceware.org header.i=@sourceware.org header.a=rsa-sha256 header.s=default header.b=D7I7FDjz; dkim-atps=neutral Received: from sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4NzC8k6cg5z23hH for ; Sat, 21 Jan 2023 08:20:54 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id D234739502EB for ; Fri, 20 Jan 2023 21:20:52 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org D234739502EB DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1674249652; bh=JRmZ2V3BqZ/QE9sTw/u6YDP8y8zkOWJrmkIgxVMn3T0=; h=To:Subject:Date:In-Reply-To:References:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=D7I7FDjz06dRNlMhg0RzeKMncHcejLNik1SCkOkQvC8Z/ndpdmFVG0lTHkTHKdr7R 6P4psUdtBWASG3bAijztEjHsCT2ds6h8f1xqXiyLzPCKmHWDCfOdfw7rQNhwaKNwXH w19Cc/Re21NYbVlOmK+A6eXjXOLWxHMvFqzgL24Q= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-ot1-x32c.google.com (mail-ot1-x32c.google.com [IPv6:2607:f8b0:4864:20::32c]) by sourceware.org (Postfix) with ESMTPS id 73BF63884575 for ; Fri, 20 Jan 2023 21:17:22 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 73BF63884575 Received: by mail-ot1-x32c.google.com with SMTP id g2-20020a9d6b02000000b006864bf5e658so3836372otp.1 for ; Fri, 20 Jan 2023 13:17: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=JRmZ2V3BqZ/QE9sTw/u6YDP8y8zkOWJrmkIgxVMn3T0=; b=ZOcNQDxpTtokTDTfmLst+cH6t4FKTJHLof8Lmsgdgp88ADSDD8df6s9gHubfnpLRGA E0/cueIhdobpJYBq+NY+I2awZrlfyUm3fpV5sWYPiS2id7Jsv1bjOpQvCQjObwjmQFCh RIgvylpdVb72c53QCvRDUG0ID6z/Yx6fwrEu5X1H4REnbsflXSZ5ygGkRpoTNqBbYI7o F2ntxPhymmlY9rTjvjWf1kw12MdUjEfABADUAJCAVPNiCiA3oaf4M/Tw8KgPHRiDYWy9 2ilZyPmr31q7GA89I8D4Mp+yWlN91RkBywxplp/NT22VpHw26WSX53nX/bQ8KwiIWFNn mBZg== X-Gm-Message-State: AFqh2kr2GkglxCOOAXrg3jHj/O1xKr4dVmryRZ0gkCMhWr9iRJikznsS iG8SiAAm8PRkh9bAPU3STWr5vzktnmr+/UzDWwg= X-Google-Smtp-Source: AMrXdXu3WQDKymJLuIPYC212aD/xRzx0FjY32HBcG3d/RDsoZC6ogiD7slReivMI8r54RUmCKQJs6w== X-Received: by 2002:a9d:624a:0:b0:66d:a5f7:9adc with SMTP id i10-20020a9d624a000000b0066da5f79adcmr9898960otk.2.1674249440099; Fri, 20 Jan 2023 13:17:20 -0800 (PST) Received: from mandiga.. ([2804:1b3:a7c1:7e99:f284:be2f:4ee5:d122]) by smtp.gmail.com with ESMTPSA id d18-20020a056830139200b00686467f920bsm6937432otq.48.2023.01.20.13.17.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 20 Jan 2023 13:17:19 -0800 (PST) To: libc-alpha@sourceware.org, Richard Henderson , Noah Goldstein Subject: [PATCH v10 23/24] string: Hook up the default implementation on test-memchr Date: Fri, 20 Jan 2023 18:16:21 -0300 Message-Id: <20230120211622.3445279-24-adhemerval.zanella@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230120211622.3445279-1-adhemerval.zanella@linaro.org> References: <20230120211622.3445279-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 Reply-To: Adhemerval Zanella Errors-To: libc-alpha-bounces+incoming=patchwork.ozlabs.org@sourceware.org Sender: "Libc-alpha" And remove SIMPLE_MEMCHR, which is not used anywhere. --- 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 Fri Jan 20 21:16:22 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adhemerval Zanella X-Patchwork-Id: 1729835 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=sourceware.org (client-ip=8.43.85.97; helo=sourceware.org; envelope-from=libc-alpha-bounces+incoming=patchwork.ozlabs.org@sourceware.org; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; secure) header.d=sourceware.org header.i=@sourceware.org header.a=rsa-sha256 header.s=default header.b=hW05yaph; dkim-atps=neutral Received: from sourceware.org (ip-8-43-85-97.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4NzC6J33C1z23gV for ; Sat, 21 Jan 2023 08:18:48 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 64EC638A9095 for ; Fri, 20 Jan 2023 21:18:46 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 64EC638A9095 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1674249526; bh=rglDjXE+jaOoHf6Yzx8QzLjp8wBin7SEfUmNHhpOLWc=; h=To:Subject:Date:In-Reply-To:References:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=hW05yaphd5rJEpPZKtpgTUuQbF5r4vgfe/UP1u6QgRXwyQYuPsUg+PXtILmHWmrkC gDGDqH2Rt4YJk7dVZ44SPPf9fRxHtg4beA2pWhe/3G1GCT+svOHWyryFxXj/fGllqE EThX5Dx8T4yUBwpiu4Qhyyy2XXnh4JECA7AtV1A0= 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 3D0313885505 for ; Fri, 20 Jan 2023 21:17:23 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 3D0313885505 Received: by mail-ot1-x32a.google.com with SMTP id n24-20020a0568301e9800b006865671a9d5so3814239otr.6 for ; Fri, 20 Jan 2023 13:17:23 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=rglDjXE+jaOoHf6Yzx8QzLjp8wBin7SEfUmNHhpOLWc=; b=MC4u7o5o30lNsQyyynHu+QwFqvNQBc0ls/Tqtw0lPCWMEmC02Lj3fYGltMeU7PolUu 3JPC/0hzYYhdb7duiCiyc4sFEYqlLtEkhidOz1TCFIQkJRME7uhgIKwgnYDFYOSH26RN ZHXklu9E3ReLfYj03qqEdVT/DYUPjX3kkvePXGXrcct3Gh2nVQ69iI7TDi3fOaiyrwHz ImawEOLrpkVxQ0AseWylT+JGtB0gMCD4iDjUfSrvNK/aJeVmzLpz+qQ1LA7jp+A+CDp1 6wEPzmo0NvNk021uz+2iqbhMtmncQDorf/7/Tc9Yn5oGGPaDgJKPhMzbX1hr/GNQhj9a 7iJQ== X-Gm-Message-State: AFqh2krU+qAtoDaiuzQXb6xAw6ETCdo/RNOwDuemOWzlSf1+U/KLC9Qe fE3SU0CZgPMhjxmkneWgyEr6AC652Q7RiqZpnRE= X-Google-Smtp-Source: AMrXdXuUR80NWzSuyKzGFLw7GIHC4GEh5DgRsfPP17UlfNjH9tDN8Qx+6xwbfYARVGFhb6qK/9RKwQ== X-Received: by 2002:a9d:61d9:0:b0:66e:43e3:449 with SMTP id h25-20020a9d61d9000000b0066e43e30449mr9290951otk.14.1674249442279; Fri, 20 Jan 2023 13:17:22 -0800 (PST) Received: from mandiga.. ([2804:1b3:a7c1:7e99:f284:be2f:4ee5:d122]) by smtp.gmail.com with ESMTPSA id d18-20020a056830139200b00686467f920bsm6937432otq.48.2023.01.20.13.17.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 20 Jan 2023 13:17:21 -0800 (PST) To: libc-alpha@sourceware.org, Richard Henderson , Noah Goldstein Subject: [PATCH v10 24/24] string: Hook up the default implementation on test-memrchr Date: Fri, 20 Jan 2023 18:16:22 -0300 Message-Id: <20230120211622.3445279-25-adhemerval.zanella@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230120211622.3445279-1-adhemerval.zanella@linaro.org> References: <20230120211622.3445279-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 Reply-To: Adhemerval Zanella Errors-To: libc-alpha-bounces+incoming=patchwork.ozlabs.org@sourceware.org Sender: "Libc-alpha" --- 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)