From patchwork Tue Jan 10 21:00:49 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adhemerval Zanella Netto X-Patchwork-Id: 55401 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 356B9385B523 for ; Tue, 10 Jan 2023 21:01:37 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 356B9385B523 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1673384497; bh=GSndUFfeRd9C61NwSinWtL8hbeO0xWrwQ+NivoIfX1o=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=UaTejX1Eo5OEoz9uYGSaEEzMCZi/YLlH212U2XmFSQcMlbo2xmABtRyuuwaEAM88a Vjt7Z7mih1GozXJTIwcqXt75SHIyVoFV45PUPzXeFe0ICDbCYMgYCcaFjgBuUvHKhG w2XY46yxbxY68yjvQ7vKSPbj5hCrFaeClgReTSRY= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-oo1-xc2b.google.com (mail-oo1-xc2b.google.com [IPv6:2607:f8b0:4864:20::c2b]) by sourceware.org (Postfix) with ESMTPS id E78CB385840A for ; Tue, 10 Jan 2023 21:01:12 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org E78CB385840A Received: by mail-oo1-xc2b.google.com with SMTP id d9-20020a4aa589000000b004af737509f4so3536928oom.11 for ; Tue, 10 Jan 2023 13:01: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:message-id:date:subject:to :from:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=GSndUFfeRd9C61NwSinWtL8hbeO0xWrwQ+NivoIfX1o=; b=YoTQpSAazqa8EeiigkJWYjqG88bnsZhLUuSdk8mh0l+uW/dXqmJ7ZxpJZNwpj98NFW wn11Fl9bduAGZL2tf6uA9qNMn8bkahdoRNZiISt8Rl5fcGri4LaMSy5qaRX7ZiEDWvxP SqVXKqNmKxWDLC4UWIlvSZ8wNANwz9HHqqDfTpo7fsS4ClpOVVLBUOS0buu7MLMDl1cC JzDi+HfIVRxscZhVfNafupzjopvQGNRzez2P8Nz/8Z8yTfb5Lexg4ejDkasvTc//L7Ca 8a3hxdr6FEJVxEldGlvGQgWBEndxOxKhf79sPPuNsgz8TQhHS7A9y+bVe/aRTp5D2K6G IN3Q== X-Gm-Message-State: AFqh2ko8Aw2nrsVl7d72fqYkuJRbe5u09sIFrRITMxxWFRc15PiBQbPV k7z61Dct2UKKBmZDZGrGl++rSumRVj/XHzJL14E= X-Google-Smtp-Source: AMrXdXuY3YIulsBYW3MfxKjcf9l/zUb1O5SyHUGGspvKvcwbfPu1QvjJct8YnUJJ9nBZkKRBodWItg== X-Received: by 2002:a4a:4183:0:b0:4f1:f0b7:68b1 with SMTP id x125-20020a4a4183000000b004f1f0b768b1mr5817088ooa.8.1673384471504; Tue, 10 Jan 2023 13:01:11 -0800 (PST) Received: from mandiga.. ([2804:1b3:a7c0:a93a:e8a0:dd55:3328:997]) by smtp.gmail.com with ESMTPSA id r5-20020a4a83c5000000b0049ee88e86f9sm6202193oog.10.2023.01.10.13.01.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Jan 2023 13:01:10 -0800 (PST) To: libc-alpha@sourceware.org, Noah Goldstein , Richard Henderson Subject: [PATCH v6 00/17] Improve generic string routines Date: Tue, 10 Jan 2023 18:00:49 -0300 Message-Id: <20230110210106.1457686-1-adhemerval.zanella@linaro.org> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 X-Spam-Status: No, score=-5.4 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Adhemerval Zanella via Libc-alpha From: Adhemerval Zanella Netto Reply-To: Adhemerval Zanella Errors-To: libc-alpha-bounces+patchwork=sourceware.org@sourceware.org Sender: "Libc-alpha" It is done by: 1. parametrizing the internal routines (for instance the find zero in a word) so each architecture can reimplement without the need to reimplement the whole routine. 2. vectorizing more string implementations (for instance strcpy and strcmp). 3. Change some implementations to use already possible optimized ones (for instance strnlen). It makes new ports to focus on only provide optimized implementation of a hardful symbols (for instance memchr) and make its improvement to be used in a larger set of routines. For the rest of #5806 I think we can handle them later and if performance of generic implementation is closer I think it is better to just remove old assembly implementations. I also 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 multiarch (it covers both LE and BE for 64 and 32 bits). I also checked the string routines on alpha, hppa, and sh. Changes since v5: * Replace 'inline' with '__always_inline' macros. * Replace strchr implementation with a simpler one that call strchrnul. * Add strchrnul suggested changes. * Add memchr suggested changes. * Added check_mask on string-maskoff.h. * Rebase and update Copyright years. Changes since v4: * Removed __clz and __ctz in favor of count_leading_zero and count_trailing_zeros from longlong.h. * Use repeat_bytes more often. * Added a comment on strcmp final_cmp on why index_first_zero_ne can not be used. Changes since v3: * Rebased against master. * Dropped strcpy optimization. * Refactor strcmp implementation. * Some minor changes in comments. Changes since v2: * Move string-fz{a,b,i} to its own patch. * Add a inline implementation for __builtin_c{l,t}z to avoid using compiler provided symbols. * Add a new header, string-maskoff.h, to handle unaligned accesses on some implementation. * Fixed strcmp on LE machines. * Added a unaligned strcpy variant for architecture that define _STRING_ARCH_unaligned. * Add SH string-fzb.h (which uses cmp/str instruction to find a zero in word). Changes since v1: * Marked ChangeLog entries with [BZ #5806], as appropriate. * Reorganized the headers, so that armv6t2 and power6 need override as little as possible to use their (integer) zero detection insns. * Hopefully fixed all of the coding style issues. * Adjusted the memrchr algorithm as discussed. * Replaced the #ifdef STRRCHR etc that are used by the multiarch * files. * Tested on i386, i686, x86_64 (verified this is unused), ppc64, ppc64le --with-cpu=power8 (to use power6 in multiarch), armv7, aarch64, alpha (qemu) and hppa (qemu). Adhemerval Zanella (1): Parameterize op_t from memcopy.h Adhemerval Zanella Netto (10): Add string-maskoff.h generic header Add string vectorized find and detection functions string: Improve generic strlen string: Improve generic strnlen string: Improve generic strchr string: Improve generic strchrnul string: Improve generic strcmp string: Improve generic memchr string: Improve generic memrchr sh: Add string-fzb.h Richard Henderson (6): Parameterize OP_T_THRES from memcopy.h hppa: Add memcopy.h hppa: Add string-fzb.h and string-fzi.h alpha: Add string-fzb.h and string-fzi.h arm: Add string-fza.h powerpc: Add string-fza.h string/memchr.c | 171 +++++----------- string/memcmp.c | 4 - string/memrchr.c | 189 +++--------------- string/strchr.c | 159 +-------------- string/strchrnul.c | 153 ++------------ string/strcmp.c | 119 +++++++++-- string/strlen.c | 90 ++------- string/strnlen.c | 137 +------------ sysdeps/alpha/string-fzb.h | 52 +++++ sysdeps/alpha/string-fzi.h | 113 +++++++++++ sysdeps/arm/armv6t2/string-fza.h | 70 +++++++ sysdeps/generic/memcopy.h | 10 +- sysdeps/generic/string-extbyte.h | 37 ++++ sysdeps/generic/string-fza.h | 102 ++++++++++ sysdeps/generic/string-fzb.h | 49 +++++ sysdeps/generic/string-fzi.h | 135 +++++++++++++ sysdeps/generic/string-maskoff.h | 84 ++++++++ sysdeps/generic/string-opthr.h | 25 +++ sysdeps/generic/string-optype.h | 24 +++ sysdeps/hppa/memcopy.h | 42 ++++ sysdeps/hppa/string-fzb.h | 70 +++++++ sysdeps/hppa/string-fzi.h | 139 +++++++++++++ sysdeps/i386/i686/multiarch/strnlen-c.c | 14 +- sysdeps/i386/memcopy.h | 3 - sysdeps/i386/string-opthr.h | 25 +++ sysdeps/m68k/memcopy.h | 3 - sysdeps/powerpc/powerpc32/power4/memcopy.h | 5 - .../powerpc32/power4/multiarch/memchr-ppc32.c | 14 +- .../power4/multiarch/strchrnul-ppc32.c | 4 - .../power4/multiarch/strnlen-ppc32.c | 14 +- .../powerpc64/multiarch/memchr-ppc64.c | 9 +- sysdeps/powerpc/string-fza.h | 70 +++++++ sysdeps/s390/strchr-c.c | 11 +- sysdeps/s390/strchrnul-c.c | 2 - sysdeps/s390/strlen-c.c | 10 +- sysdeps/s390/strnlen-c.c | 14 +- sysdeps/sh/string-fzb.h | 54 +++++ sysdeps/x86_64/x32/string-optype.h | 24 +++ 38 files changed, 1397 insertions(+), 853 deletions(-) create mode 100644 sysdeps/alpha/string-fzb.h create mode 100644 sysdeps/alpha/string-fzi.h create mode 100644 sysdeps/arm/armv6t2/string-fza.h create mode 100644 sysdeps/generic/string-extbyte.h create mode 100644 sysdeps/generic/string-fza.h create mode 100644 sysdeps/generic/string-fzb.h create mode 100644 sysdeps/generic/string-fzi.h create mode 100644 sysdeps/generic/string-maskoff.h create mode 100644 sysdeps/generic/string-opthr.h create mode 100644 sysdeps/generic/string-optype.h create mode 100644 sysdeps/hppa/memcopy.h create mode 100644 sysdeps/hppa/string-fzb.h create mode 100644 sysdeps/hppa/string-fzi.h create mode 100644 sysdeps/i386/string-opthr.h create mode 100644 sysdeps/powerpc/string-fza.h create mode 100644 sysdeps/sh/string-fzb.h create mode 100644 sysdeps/x86_64/x32/string-optype.h