From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 122665 invoked by alias); 30 May 2017 06:36:02 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Received: (qmail 122642 invoked by uid 89); 30 May 2017 06:36:01 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-25.0 required=5.0 tests=AWL,BAYES_00,GIT_PATCH_0,GIT_PATCH_1,GIT_PATCH_2,GIT_PATCH_3,RCVD_IN_DNSWL_NONE,RCVD_IN_SORBS_SPAM,SPF_PASS autolearn=ham version=3.3.2 spammy=H*i:5KbQ, H*f:5KbQ, H*i:sk:L25coQz, H*f:sk:L25coQz X-HELO: mail-wm0-f50.google.com Received: from mail-wm0-f50.google.com (HELO mail-wm0-f50.google.com) (74.125.82.50) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Tue, 30 May 2017 06:36:00 +0000 Received: by mail-wm0-f50.google.com with SMTP id 7so78197335wmo.1 for ; Mon, 29 May 2017 23:36:03 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:mail-followup-to:cc:subject:references :date:in-reply-to:message-id:user-agent:mime-version; bh=fHL+APaw4QpxtqIP3FxjjpofIidf3xurXbdxiLeNXPI=; b=IDKa7Hv91GxWsibPe6lM5HvKtzkfcVNY+1JkyszPATF7+6w6K78XCOJxAns7p5jNgM SsMoBIzA/tyTz3FHbzr1qDTogQMFf/8NB5w5ls4ryI/EI4jIxVjOogu4sEwlpF6VCFrT cTqKZxWczGsBHqOGHpixX+m9QJI3D9qQW7UmMDpasgeujCE8mcnYkF/grxuPM+PWF0Zf 7XKE5iYWAvphBCsW691M8U/YV1KeGJ3EzGPKTd5lJtROr/0ZzT3yMFHorZ4fTGxaLZq7 H+dCU0Kef/MtCXjc7+XVGgK5DVjm3j9z+3iJ04eZ7SKNv1z8zgR+h/nHN4gMqrGhNWCz yPtQ== X-Gm-Message-State: AODbwcADaVlzC0CB6dMc3P4dFPLGjzH/It1KwQVyPCXgOSHD4WCWzure pqLE/NPlf/nInAtF X-Received: by 10.28.154.133 with SMTP id c127mr464269wme.42.1496126161748; Mon, 29 May 2017 23:36:01 -0700 (PDT) Received: from localhost ([2.26.27.176]) by smtp.gmail.com with ESMTPSA id u198sm26670121wmd.29.2017.05.29.23.36.00 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 29 May 2017 23:36:01 -0700 (PDT) From: Richard Sandiford To: Yuri Gribov Mail-Followup-To: Yuri Gribov ,GCC Patches , Alan Modra , rguenth@gcc.gnu.org, richard.sandiford@linaro.org Cc: GCC Patches , Alan Modra , rguenth@gcc.gnu.org Subject: Re: [PATCH 3/4 v3][PR 67328] Added bool conversion for wide_ints References: Date: Tue, 30 May 2017 06:59:00 -0000 In-Reply-To: (Yuri Gribov's message of "Mon, 29 May 2017 07:59:32 +0100") Message-ID: <87tw42onqo.fsf@linaro.org> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/25.1 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain X-SW-Source: 2017-05/txt/msg02228.txt.bz2 Yuri Gribov writes: > From 330209f721a598ec393dcb5d62de3457ee282153 Mon Sep 17 00:00:00 2001 > From: Yury Gribov > Date: Fri, 26 May 2017 07:53:10 +0100 > Subject: [PATCH 3/4] Added bool conversion for wide_ints. > > gcc/ > 2017-05-26 Yury Gribov > > * wide-int.cc (wi::zero_p_large): New method. > * wide-int.h (wi::zero_p): New method. Do you still need this bit? It looks like it isn't used by the other parts of the series. The idea was that wi::eq_p (x, 0) (or just x == 0, if x is a wide-int-based type) is supposed to be as fast as a dedicated zero check. It'd be OK to have a helper function anyway, but it should probably be defined using wi::eq_p. The zero_p_large fallback can never return true, since a zero of any precision will have a length of 1. Thanks, Richard > --- > gcc/wide-int.cc | 10 ++++++++++ > gcc/wide-int.h | 17 +++++++++++++++++ > 2 files changed, 27 insertions(+) > > diff --git a/gcc/wide-int.cc b/gcc/wide-int.cc > index dab4c19..f1be89b 100644 > --- a/gcc/wide-int.cc > +++ b/gcc/wide-int.cc > @@ -433,6 +433,16 @@ top_bit_of (const HOST_WIDE_INT *a, unsigned int len, unsigned int prec) > * unsigned and C++ has no such operators. > */ > > +/* Return true if OP == 0. */ > +bool > +wi::zero_p_large (const HOST_WIDE_INT *op, unsigned int len) > +{ > + for (unsigned i = 0; i < len; ++i) > + if (op[i]) > + return false; > + return true; > +} > + > /* Return true if OP0 == OP1. */ > bool > wi::eq_p_large (const HOST_WIDE_INT *op0, unsigned int op0len, > diff --git a/gcc/wide-int.h b/gcc/wide-int.h > index 2115b61..af63ffe 100644 > --- a/gcc/wide-int.h > +++ b/gcc/wide-int.h > @@ -462,6 +462,7 @@ namespace wi > UNARY_PREDICATE fits_shwi_p (const T &); > UNARY_PREDICATE fits_uhwi_p (const T &); > UNARY_PREDICATE neg_p (const T &, signop = SIGNED); > + UNARY_PREDICATE zero_p (const T &); > > template > HOST_WIDE_INT sign_mask (const T &); > @@ -675,6 +676,9 @@ public: > template > generic_wide_int &operator = (const T &); > > +#define UNARY_PREDICATE(OP, F) \ > + bool OP () const { return wi::F (*this); } > + > #define BINARY_PREDICATE(OP, F) \ > template \ > bool OP (const T &c) const { return wi::F (*this, c); } > @@ -699,6 +703,7 @@ public: > #define INCDEC_OPERATOR(OP, DELTA) \ > generic_wide_int &OP () { *this += DELTA; return *this; } > > + UNARY_PREDICATE (operator !, zero_p) > UNARY_OPERATOR (operator ~, bit_not) > UNARY_OPERATOR (operator -, neg) > BINARY_PREDICATE (operator ==, eq_p) > @@ -1605,6 +1610,7 @@ decompose (HOST_WIDE_INT *scratch, unsigned int precision, > we generally want those to be removed by SRA.) */ > namespace wi > { > + bool zero_p_large (const HOST_WIDE_INT *, unsigned int); > bool eq_p_large (const HOST_WIDE_INT *, unsigned int, > const HOST_WIDE_INT *, unsigned int, unsigned int); > bool lts_p_large (const HOST_WIDE_INT *, unsigned int, unsigned int, > @@ -1729,6 +1735,17 @@ wi::neg_p (const T &x, signop sgn) > return xi.sign_mask () < 0; > } > > +/* Return true if X is zero. */ > +template > +inline bool > +wi::zero_p (const T &x) > +{ > + WIDE_INT_REF_FOR (T) xi (x); > + if (__builtin_expect (xi.len == 1, true)) > + return !xi.val[0]; > + return zero_p_large (xi.val, xi.len); > +} > + > /* Return -1 if the top bit of X is set and 0 if the top bit is clear. */ > template > inline HOST_WIDE_INT