From patchwork Wed Jan 10 12:47:58 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adhemerval Zanella X-Patchwork-Id: 124092 Delivered-To: patch@linaro.org Received: by 10.140.22.227 with SMTP id 90csp5236807qgn; Wed, 10 Jan 2018 04:51:19 -0800 (PST) X-Google-Smtp-Source: ACJfBotyoVOzZbnhQLPnQyojVZ31fbx9UMBmm6FSUCPBBbgC4oIsuZAw8OMOTV/6L9cXjYOBWsEA X-Received: by 10.84.218.69 with SMTP id f5mr6573622plm.431.1515588679328; Wed, 10 Jan 2018 04:51:19 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1515588679; cv=none; d=google.com; s=arc-20160816; b=1F6q+OJdP5isrW2QFxDN3SLpBYIs1+oyNRv6nCG9Ls/ABwZyXZMXr2mrUfHRFaneHJ ZSXKhEmEGRRxCwRAYatLL54DNREbRVwE0KiJCk+i4210BtxpP7q2vTvoMjtICw9yKicX utSl4EUnOiENNI2Qyg2D4ypPjLEKEuceCFc3Cjx2X21jOaGEpJmYKRwUCqAYblIREPpZ knk1aBmbN4ytR5UVEtwzktOVE8AOSZCrhzSqNi0v31bw6UzlNTIP1dnnPhXKCnsR+EYO Pt8WjUzhENo7dH9vgERsS5EX07tcFz9XLwi6Nvp2+vPeG8gkBacMbCAaOUSTxBGr39ks wNmA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=references:in-reply-to:message-id:date:subject:cc:to:from :delivered-to:sender:list-help:list-post:list-archive:list-subscribe :list-unsubscribe:list-id:precedence:mailing-list:dkim-signature :domainkey-signature:arc-authentication-results; bh=Z6EmNX77pGOB5rAa+ITkSM7/K6R0N+X+q3x4RWbR9bE=; b=w3UFx+nHTQ6KGmDO/syquZM1HSwVEG0ly65kqayoHEw+YmGXj2Pn8mKVcibdj9BANp GL5sUzS1dziXAipIQMcDkbrY/Rnurnjxaa3WgE+5iG/AU8qkRvdeTaBuMznV7kcBy6E6 2OtVRU0brVoHmlpBjt+UVk0RKU9MXN5rR2ZU6625mmrw4iwaotHOEf18vx5F41dZTBGR vjLmKFINrhQG4snZ9Or+OmMqSTv4xwg0wZM0PLIldvg57QPU4TzMN77Bo3jRnF1XMjZD xzswJwDWrB3mU22p52F49WMB4alsnq47hP7pLSVCMDDWEDNZG4s+S5cGovCm/CUUVI+j cL4g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@sourceware.org header.s=default header.b=Ze+Nryz8; spf=pass (google.com: domain of libc-alpha-return-89014-patch=linaro.org@sourceware.org designates 209.132.180.131 as permitted sender) smtp.mailfrom=libc-alpha-return-89014-patch=linaro.org@sourceware.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from sourceware.org (server1.sourceware.org. [209.132.180.131]) by mx.google.com with ESMTPS id a3si10533457pgc.105.2018.01.10.04.51.18 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 10 Jan 2018 04:51:19 -0800 (PST) Received-SPF: pass (google.com: domain of libc-alpha-return-89014-patch=linaro.org@sourceware.org designates 209.132.180.131 as permitted sender) client-ip=209.132.180.131; Authentication-Results: mx.google.com; dkim=pass header.i=@sourceware.org header.s=default header.b=Ze+Nryz8; spf=pass (google.com: domain of libc-alpha-return-89014-patch=linaro.org@sourceware.org designates 209.132.180.131 as permitted sender) smtp.mailfrom=libc-alpha-return-89014-patch=linaro.org@sourceware.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org DomainKey-Signature: a=rsa-sha1; c=nofws; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:from:to:cc:subject:date:message-id:in-reply-to :references; q=dns; s=default; b=QNIqg0eFSAd4PDtrb4gOaEhtVVC62ZI ll+SLCPxl3OhO7rea6UOYccW86Nzx0AyW9JiPlFowF5gFEMcD3p+OVo3rA/F8YsN B9PPvVnIEql668qJKO681aiQt7OfMKTbfKg2nfEg733LTsbO3GNtzgby9Y3ofGnk XCzEn2H33Ci0= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:from:to:cc:subject:date:message-id:in-reply-to :references; s=default; bh=4fAwDoNJ+LtSSP4OO3ZgiKckPxY=; b=Ze+Nr yz83hugF/GNU9095A6vVCAr/VJimVvArPyA8PbuIQlb5l3+QtR9I8a15oUjshLoj uwIUZGpY7VAtqWbEVlNiu8eN0ntJ5YMFRgk93EiULejPFibnlHRyF5AdkwuRzMsr WWB3DDXaP9jTDftplPrY2x9jxenJd8QB93FKXM= Received: (qmail 336 invoked by alias); 10 Jan 2018 12:48:47 -0000 Mailing-List: contact libc-alpha-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: libc-alpha-owner@sourceware.org Delivered-To: mailing list libc-alpha@sourceware.org Received: (qmail 125945 invoked by uid 89); 10 Jan 2018 12:48:36 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-25.9 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, KAM_SHORT, RCVD_IN_DNSWL_NONE, SPF_PASS autolearn=ham version=3.3.2 spammy=bn X-HELO: mail-qt0-f194.google.com X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=Z6EmNX77pGOB5rAa+ITkSM7/K6R0N+X+q3x4RWbR9bE=; b=j61UsQQrrZgZHBGRVVWWIx6R/I6ype9XQ0QRn46wHLjZ33encuCiZW6dz8olvEtAt6 clZink8UNGJp/eSiMHcjurva36siAz7vw1+X6DOulhBLxmFvHW2nH2Oju/4qyj9nZi1m oVv6/fumXJQPNfmw3IwB4TmhPSpK09igOi2cRi+p7zGGHRYtxCmBcUB43AUK7jqEv5Pm AELgO2nPJY49bXSQccX4qwXubBOZbTbNpeuykmAxaXHFkSc/3O3URrfFGasfbFdCkLuN O/d5pUYOZLLwTPD6SnZNuBG2w18Tp7n1HWjJcLgyBiDAD2RVnngRsva2r0vKNfQRFG4R aSSA== X-Gm-Message-State: AKwxyteW3gAnVj5KtMwNvfRSwgR6YJkBoVGhecvvP04OtFPonfLUFp7B A/Y6n3poQjWbdGnnE1DhOoDbdh/WvSY= X-Received: by 10.200.27.135 with SMTP id z7mr7447242qtj.58.1515588510762; Wed, 10 Jan 2018 04:48:30 -0800 (PST) From: Adhemerval Zanella To: libc-alpha@sourceware.org Cc: Richard Henderson Subject: [PATCH v3 14/18] hppa: Add string-fzb.h and string-fzi.h Date: Wed, 10 Jan 2018 10:47:58 -0200 Message-Id: <1515588482-15744-15-git-send-email-adhemerval.zanella@linaro.org> In-Reply-To: <1515588482-15744-1-git-send-email-adhemerval.zanella@linaro.org> References: <1515588482-15744-1-git-send-email-adhemerval.zanella@linaro.org> 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. Richard Henderson * sysdeps/hppa/string-fzb.h: New file. * sysdeps/hppa/string-fzi.h: Likewise. --- sysdeps/hppa/string-fzb.h | 69 ++++++++++++++++++++++++ sysdeps/hppa/string-fzi.h | 135 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 204 insertions(+) create mode 100644 sysdeps/hppa/string-fzb.h create mode 100644 sysdeps/hppa/string-fzi.h -- 2.7.4 diff --git a/sysdeps/hppa/string-fzb.h b/sysdeps/hppa/string-fzb.h new file mode 100644 index 0000000..0385d99 --- /dev/null +++ b/sysdeps/hppa/string-fzb.h @@ -0,0 +1,69 @@ +/* Zero byte detection, boolean. HPPA 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 STRING_FZB_H +#define STRING_FZB_H 1 + +#include + +/* Determine if any byte within X is zero. This is a pure boolean test. */ + +static 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 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 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_HASZERO_H */ diff --git a/sysdeps/hppa/string-fzi.h b/sysdeps/hppa/string-fzi.h new file mode 100644 index 0000000..22bd8ac --- /dev/null +++ b/sysdeps/hppa/string-fzi.h @@ -0,0 +1,135 @@ +/* string-fzi.h -- zero byte detection; indexes. HPPA version. + Copyright (C) 2016 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 + +/* 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 inline unsigned int +index_first_zero (op_t x) +{ + unsigned int ret; + + _Static_assert (sizeof (op_t) == 4, "64-bit not supported"); + + /* 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 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 inline unsigned int +index_first_zero_eq (op_t x1, op_t x2) +{ + unsigned int ret; + + _Static_assert (sizeof (op_t) == 4, "64-bit not supported"); + + /* 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 inline unsigned int +index_first_zero_ne (op_t x1, op_t x2) +{ + unsigned int ret; + + _Static_assert (sizeof (op_t) == 4, "64-bit not supported"); + + /* 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 inline unsigned int +index_last_zero (op_t x) +{ + unsigned int ret; + + _Static_assert (sizeof (op_t) == 4, "64-bit not supported"); + + /* 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 inline unsigned int +index_last_eq (op_t x1, op_t x2) +{ + return index_last_zero (x1 ^ x2); +} + +#endif /* STRING_FZI_H */