From patchwork Wed Jan 10 12:47:59 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adhemerval Zanella Netto X-Patchwork-Id: 124079 Delivered-To: patch@linaro.org Received: by 10.140.22.227 with SMTP id 90csp5234920qgn; Wed, 10 Jan 2018 04:49:11 -0800 (PST) X-Google-Smtp-Source: ACJfBotjr5aMoiypCZ166IezulHiZ2Bsj1wUOu3NsHkPb/l0CitCifzokOCdxtEP+b26C0V1AUPQ X-Received: by 10.84.217.76 with SMTP id e12mr5883666plj.331.1515588551120; Wed, 10 Jan 2018 04:49:11 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1515588551; cv=none; d=google.com; s=arc-20160816; b=eAUc5HBGVwK7Y72OU7yuU7gfw2MZVk5bpNaQFH6vdN7nSnyo9d5wYuldtgG+it5NCi Akuh/PeKSDetQmvKoQ3e3obIAVTOXArSbmRdxaN8TEmOuNROMlMqK/yFN9ESj23Mm6rd ogQyubY3gKpyLd3JMO4kLep63DcyRdLNnxkasphNNDQDXTSFJu+qiwL6qO+zllFIi9aL Q9u7AtQEcaD96lKR0yBBTJ5pe3odc4JWPn7qzsBgcMH4+IE3Smht+bDL3o0tqvd0LaCy vBueAx71Eaeb8G7UY1BiQLiWe/JIeroRnCiykPSjrp/bLH1JhEPdPALJMha0X+XaUNrA joGg== 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=dRrSRLzJnc/25De4rEe6MG53SfYheTJv01cUWmbfE/E=; b=yAZ1jQev8ynINAh/ZGLjhQcIQ5K5KeLzVIYRBomCE75QUrA4eTmbHes0LoMbyOM93U wLyN6ber8W8hARCj5YdVhY5Q/qoKqy2ovVFGuoImos0W3Yl4ayArQvSvu4fP71dQ8qnf D0W7x3r1tKF5UbZUoyykzeYvNOjfLfuiKk4F4wd6AfaixjPWFGY18qZqV13WnzJJ2PSJ 7DKAoPyvu2KQ/WswaILoZXbQ++S0gVV+BLOVgGVs/zery1TP/fNaes2RiGUJ5/AV/0JU iTeHg1thy4bja62Yx3FVKxs2nH0T/kEi42mCQIDegsp4G708V/xZYQnriYhW8O4mxOz0 YhEg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@sourceware.org header.s=default header.b=RQsr2ol8; spf=pass (google.com: domain of libc-alpha-return-89001-patch=linaro.org@sourceware.org designates 209.132.180.131 as permitted sender) smtp.mailfrom=libc-alpha-return-89001-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 c9si1703166plk.195.2018.01.10.04.49.10 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 10 Jan 2018 04:49:11 -0800 (PST) Received-SPF: pass (google.com: domain of libc-alpha-return-89001-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=RQsr2ol8; spf=pass (google.com: domain of libc-alpha-return-89001-patch=linaro.org@sourceware.org designates 209.132.180.131 as permitted sender) smtp.mailfrom=libc-alpha-return-89001-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=xH5kkq0jmb5m9Mdvd5EsdFnbdg4J8AU VY02sYMCnIz3v0NRXfHly4NBTxOqrvOafCxrk+6ycCQsI+UAl2B7Ltb02rasAGS0 PnhXZMj29z1ImtILa1VIXq1tZe03uxDsTWZerwS5SjsU/QhPyeZ0tUNFhJdqtUyB MV3PjIGr4mJU= 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=aW/Xx4AVmYADnxQZFfleMzPdVss=; b=RQsr2 ol8zgZTVqBelaRqwjUFY0eI6nSI51T/FRAHtTQDbva2Sh+m8xJQm/ZaHLSczMkPV 3PBIKfinYbAqQbB26BP3MVIrNK7wEuaf/0Bxwv6Sfdb3+at2Q82YpbOfbDCw3Kkh URr3vLk5afeb9s/8s3CMz9vV/HKGafuPGzI2Ek= Received: (qmail 129565 invoked by alias); 10 Jan 2018 12:48:42 -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 125765 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= X-HELO: mail-qt0-f195.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=dRrSRLzJnc/25De4rEe6MG53SfYheTJv01cUWmbfE/E=; b=jKlgk736lZyaQH6o5A9a+YdL+CaAAgryHuu2HbcEMpZMQDlIyJPyCXUvMfFXYQ78Zu qXr+k4R5EpWKaWeaAd7cT7UQbDY/EpJ+pwDaW/ndpE86oZhxPnYE2MLI0sDhoLmdjAgH tUbgmq1f7Dd9QmHMkOiTNoWJomeD+S9G8x9V7POyGKYT66q/LEMauoRQXhFUlgVMq/Ot /+h6dEIUWSs6rjQMlEAnLg4ZavzfeBrrRULAE12XEKzV9JEpT0iBk2Al/m6BwlJdBasf Qm33JgOayDLsogpgyJkr6IK31ki5kKr/tJVcy3s7nD84QZpSUZn58n2gRAWBq4EP41sF mnOA== X-Gm-Message-State: AKwxytf1H5aIRSU99clxTTbWa2bdh2Y3eDaGDCeg4OfSXei4ZoPbFfBs sOe3yrrugMB88F8+SAtpVReb87SoE2U= X-Received: by 10.200.42.80 with SMTP id l16mr26179167qtl.164.1515588512392; Wed, 10 Jan 2018 04:48:32 -0800 (PST) From: Adhemerval Zanella To: libc-alpha@sourceware.org Cc: Richard Henderson Subject: [PATCH v3 15/18] alpha: Add string-fzb.h and string-fzi.h Date: Wed, 10 Jan 2018 10:47:59 -0200 Message-Id: <1515588482-15744-16-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 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. Richard Henderson * sysdeps/alpha/string-fzb.h: New file. * sysdeps/alpha/string-fzi.h: Likewise. --- sysdeps/alpha/string-fzb.h | 51 ++++++++++++++++++++ sysdeps/alpha/string-fzi.h | 113 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 164 insertions(+) create mode 100644 sysdeps/alpha/string-fzb.h create mode 100644 sysdeps/alpha/string-fzi.h -- 2.7.4 diff --git a/sysdeps/alpha/string-fzb.h b/sysdeps/alpha/string-fzb.h new file mode 100644 index 0000000..0e6a71c --- /dev/null +++ b/sysdeps/alpha/string-fzb.h @@ -0,0 +1,51 @@ +/* Zero byte detection; boolean. Alpha 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_FZB_H +#define STRING_FZB_H 1 + +#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 inline _Bool +has_zero (op_t x) +{ + return __builtin_alpha_cmpbge (0, x) != 0; +} + +/* Likewise, but for byte equality between X1 and X2. */ + +static 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 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 0000000..243a9e5 --- /dev/null +++ b/sysdeps/alpha/string-fzi.h @@ -0,0 +1,113 @@ +/* string-fzi.h -- zero byte detection; indices. Alpha 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 + +#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 inline unsigned int +index_first_ (unsigned long int 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 inline unsigned int +index_last_ (unsigned long int 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 +} + +/* 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 inline unsigned int +index_first_zero (op_t x) +{ + return index_first_ (__builtin_alpha_cmpbge (0, x)); +} + +/* Similarly, but perform the test 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) +{ + return index_first_ (__builtin_alpha_cmpbge (0, x1) + | __builtin_alpha_cmpbge (0, x1 ^ x2)); +} + +/* 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) +{ + return index_first_ (__builtin_alpha_cmpbge (0, x1) + | (__builtin_alpha_cmpbge (0, x1 ^ x2) ^ 0xFF)); +} + +/* Similarly, but search for the last zero within X. */ + +static inline unsigned int +index_last_zero (op_t x) +{ + return index_last_ (__builtin_alpha_cmpbge (0, x)); +} + +static inline unsigned int +index_last_eq (op_t x1, op_t x2) +{ + return index_last_zero (x1 ^ x2); +} + +#endif /* STRING_FZI_H */