From patchwork Sat Dec 17 06:57:29 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 706658 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3tgdMq2sz8z9t2D for ; Sat, 17 Dec 2016 17:59:35 +1100 (AEDT) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; secure) header.d=sourceware.org header.i=@sourceware.org header.b="t1TC7hS+"; dkim-atps=neutral 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:subject:date:message-id:in-reply-to :references; q=dns; s=default; b=WXJIJsPTrpqQWM8FCzTeFFyIpKORbx8 5+YI5zrBCpscZqfw8W7ZS3+/cBUr2IiwUnsie9KT9AjOUHkFFFYgU1oTmm7I2rJm A2vg9OTP/Q6as93A4C9ZTneguB9nL3hb5RM9PJgbBWtntaQeYMWnlwOzmTFJjgO9 34fQjdvelebI= 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:subject:date:message-id:in-reply-to :references; s=default; bh=ixIoBJj38SLEtykU29z1R0aqKWM=; b=t1TC7 hS+OyO4iP8imulgAy/NybHoVELYsvUyUpdkBx2yqcW1krjQSLDU2tlZVwjPr0ru+ 3n8v/X8bftJVld83fnj/PUf+aoXTNItkX3CTALTUlLal1dYrW2wcQULT3aDk5Gi2 997Sl9CCU3y866sMLl6qp4rryQfupbSKivkpZs= Received: (qmail 94534 invoked by alias); 17 Dec 2016 06:58:02 -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 94449 invoked by uid 89); 17 Dec 2016 06:58:01 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.4 required=5.0 tests=BAYES_00, FREEMAIL_ENVFROM_END_DIGIT, FREEMAIL_FROM, RCVD_IN_DNSWL_LOW, SPF_PASS autolearn=ham version=3.3.2 spammy=1, 55, simultaneously, H*RU:209.85.192.196, Hx-spam-relays-external:209.85.192.196 X-HELO: mail-pf0-f196.google.com X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:subject:date:message-id :in-reply-to:references; bh=mFmq/MHKA7L+cEspADjAFwGJhlIxHViFrPIkt91s6GE=; b=nkSi6UJofK3pnqqnt9si9gcJKWqzGTxL+7C9lDgKkVJ8LSbquUX11Ryfvs8Mfuz8go tA+xY9OysZ157K7Rfmvp3vdBt4vAPL8oQ/Iy+nUtvjzISzwaIAwORZDume2hGlUGuj9e xRT3mwu8RuUMzCk9CGV0/rqpx3f5Pd4rhyhTpi0zy9BZhxsJl/oC0HkMkH6x645JqdiP XfzGkJO/8g2bGmKev6zzZKaUIV+8T/w8ltZ+XUCd0IvJV4eAsZHpf33YqVg9J/JDic9u cU/iPyq+S3IUC53E/vFSQNcrptp9Lv+/AQRDKQLulv/7lGpUNfcfKedtG0B8kbNcU+hG zpDQ== X-Gm-Message-State: AKaTC02YZUUsoP72IWKm0zwgMGS++Lmo5w/4RYuuWf1o/OaSnWue9jJJu/CfGCFI/gyBNQ== X-Received: by 10.98.163.71 with SMTP id s68mr6666158pfe.60.1481957867642; Fri, 16 Dec 2016 22:57:47 -0800 (PST) From: Richard Henderson To: libc-alpha@sourceware.org Subject: [PATCH 11/11] alpha: Add haszero.h and whichzero.h Date: Fri, 16 Dec 2016 22:57:29 -0800 Message-Id: <20161217065729.28561-12-rth@twiddle.net> In-Reply-To: <20161217065729.28561-1-rth@twiddle.net> References: <20161217065729.28561-1-rth@twiddle.net> While alpha has the more important string functions in assembly, there are still a few for which 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. * sysdeps/alpha/haszero.h: New file. * sysdeps/alpha/whichzero.h: New file. --- sysdeps/alpha/haszero.h | 36 +++++++++++++++++++++++++++++++ sysdeps/alpha/whichzero.h | 55 +++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 91 insertions(+) create mode 100644 sysdeps/alpha/haszero.h create mode 100644 sysdeps/alpha/whichzero.h diff --git a/sysdeps/alpha/haszero.h b/sysdeps/alpha/haszero.h new file mode 100644 index 0000000..e5c2c49 --- /dev/null +++ b/sysdeps/alpha/haszero.h @@ -0,0 +1,36 @@ +/* haszero.h -- function for zero byte detection. 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 HASZERO_H +#define HASZERO_H 1 + +static inline unsigned long int +haszero(unsigned long int x) +{ + return __builtin_alpha_cmpbge (0, x); +} + +/* Likewise, but for two words simultaneously. */ + +static inline unsigned long int +haszero2(unsigned long int x1, unsigned long int x2) +{ + return __builtin_alpha_cmpbge (0, x1) | __builtin_alpha_cmpbge (0, x2); +} + +#endif /* haszero.h */ diff --git a/sysdeps/alpha/whichzero.h b/sysdeps/alpha/whichzero.h new file mode 100644 index 0000000..3f8e5c9 --- /dev/null +++ b/sysdeps/alpha/whichzero.h @@ -0,0 +1,55 @@ +/* whichzero.h -- functions for zero byte searching. 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 WHICHZERO_H +#define WHICHZERO_H 1 + +/* A subroutine for the whichzero and whichzero2 functions. Given a + test word C, return the index of the first byte in memory order + that contains 0x80 (all other bits will be zero). */ + +static inline unsigned int +whichzero_ffs(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 +} + +/* Given a long that is known to contain a zero byte, return the + index of the first such within the long in host memory order. */ + +static inline unsigned int +whichzero(unsigned long int x) +{ + return whichzero_ffs (__builtin_alpha_cmpbge (0, x)); +} + +/* Similarly, but perform the test for two longs simultaneously. */ + +static inline unsigned int +whichzero2(unsigned long int x1, unsigned long int x2) +{ + return whichzero_ffs (__builtin_alpha_cmpbge (0, x1) + | __builtin_alpha_cmpbge (0, x2)); +} + +#endif /* whichzero.h */