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: 644655 Delivered-To: patch@linaro.org Received: by 2002:a17:522:b9de:b0:4b9:b062:db3b with SMTP id fj30csp1017791pvb; Fri, 20 Jan 2023 13:20:47 -0800 (PST) X-Google-Smtp-Source: AMrXdXuFm9Y7g0It7u2tqn/g9rjJA/+ytOADwjLz5CrlRfdpkMtIHsH1vcugaGiBmbYsoRR9YzDU X-Received: by 2002:a17:907:d505:b0:877:8100:8bd0 with SMTP id wb5-20020a170907d50500b0087781008bd0mr8411192ejc.75.1674249647511; Fri, 20 Jan 2023 13:20:47 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1674249647; cv=none; d=google.com; s=arc-20160816; b=oLbwBkVlX+jc4DQkQdTDM1nppJPKXrBzZWVVBFa+Fi9moay7OMp6sCqK7uuBj93pkB +b/clvWbvKSR9sn+dj6vTD+CkT2MdH/ZB0C5Y7F7LFGbv7KdpCZvaq/4Jpioo/dHBLUb J+1cX6IDLm5/KCBBdLnQLS4GXaw6yGEzZ4LYLv7P6DY0WFwdxhNTplwk6nKMwh26bZku EiLBOWZazns+yO0zv5A9O5oC+zG3QvAZfAOMtznkJw7R8cMCscGKHqkyUmhHFlf1tvN5 IsPuWbL8xxlEcjJIbjr3MSO5aOON4L5uzNsktcFUpGIRsu1XDoOlfeCXYqV6dGdnlKf4 +z5w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:reply-to:from:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence :content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:dmarc-filter:delivered-to:dkim-signature :dkim-filter; bh=twdo6QujejuZ8L/LB6eu/+3VhUFQsN+9ED9W3Y4kE3g=; b=DL8sk45VD9b06rUuKKHbf4Z16ZQLJu51OzvP36mGluZkT/f3b+kPuA0UFGpxzzzv36 P4wyXg9M3NNxu/mepdbQjyWCf8HDfNeHjyngVFGiyzYnYTcHFGJr+RNq6rawMXzd5vVf xdqMWTKmlLXbIbPjmhvdr57Eo4kT8ePZIVePBm4QhAwMSORwn3Lq0pMUeX8sygiHLKJw Hdydup+A0tvsQGt1n9aQcwPQzvB6BRHkP7iXsfWoHaDMsi/brBRm5EjB/6+oU6ADYW0X 2gbCtjyW46Wd0HieCPoXa0pmobE1rw676WZw3AI0jPhF+4jJWzJ2JXk+0tPtGrEU1CZ/ VpAA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@sourceware.org header.s=default header.b=XphM5ZqH; spf=pass (google.com: domain of libc-alpha-bounces+patch=linaro.org@sourceware.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="libc-alpha-bounces+patch=linaro.org@sourceware.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=sourceware.org Return-Path: Received: from sourceware.org (server2.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id hj1-20020a1709069fc100b0084cd9dba340si42496623ejc.962.2023.01.20.13.20.47 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 20 Jan 2023 13:20:47 -0800 (PST) Received-SPF: pass (google.com: domain of libc-alpha-bounces+patch=linaro.org@sourceware.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@sourceware.org header.s=default header.b=XphM5ZqH; spf=pass (google.com: domain of libc-alpha-bounces+patch=linaro.org@sourceware.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="libc-alpha-bounces+patch=linaro.org@sourceware.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 3E8D138983A3 for ; Fri, 20 Jan 2023 21:20:46 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 3E8D138983A3 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1674249646; 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=XphM5ZqHRUsE8wT5NuNZIEiX3BP5tYyRsmFissTDQez68BC73d1TELm7qcQJ7ZBx7 KhiLR70ucyJWka52HmYQwn9tgKRMg5qQBgUAY4cqwmqAbK9gVDNJMN3uWTVPdWEKt2 u7WbhhCXASPWclqCxboUAlxpXNasc757jI6O+z+8= 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-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+patch=linaro.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 */