public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Jakub Jelinek <jakub@redhat.com>
To: Kyrill Tkachov <kyrylo.tkachov@arm.com>
Cc: Richard Earnshaw <Richard.Earnshaw@foss.arm.com>,
	       GCC Patches <gcc-patches@gcc.gnu.org>,
	       Ramana Radhakrishnan <Ramana.Radhakrishnan@arm.com>,
	       Richard Earnshaw <Richard.Earnshaw@arm.com>
Subject: Re: [PATCH][ARM][cleanup] Use IN_RANGE more often
Date: Mon, 20 Apr 2015 11:07:00 -0000	[thread overview]
Message-ID: <20150420110731.GF1725@tucnak.redhat.com> (raw)
In-Reply-To: <5534DCEF.6000305@arm.com>

On Mon, Apr 20, 2015 at 12:03:11PM +0100, Kyrill Tkachov wrote:
> The definition and comment on IN_RANGE in system.h is:
> /* A macro to determine whether a VALUE lies inclusively within a
>    certain range without evaluating the VALUE more than once.  This
>    macro won't warn if the VALUE is unsigned and the LOWER bound is
>    zero, as it would e.g. with "VALUE >= 0 && ...".  Note the LOWER
>    bound *is* evaluated twice, and LOWER must not be greater than
>    UPPER.  However the bounds themselves can be either positive or
>    negative.  */
> #define IN_RANGE(VALUE, LOWER, UPPER) \
>   ((unsigned HOST_WIDE_INT) (VALUE) - (unsigned HOST_WIDE_INT) (LOWER) \
>    <= (unsigned HOST_WIDE_INT) (UPPER) - (unsigned HOST_WIDE_INT) (LOWER))
> 
> Since it works on positive or negative bounds, I'd think it would work on
> signed numbers, wouldn't it?

Of course it does, as long as the types of VALUE, LOWER and UPPER aren't
wider integer types than {,un}signed HOST_WIDE_INT.  As HWI is always 64-bit
now, that just means it wouldn't work for 128-bit integral types that aren't
used anywhere in GCC.  So, just don't use IN_RANGE for floating point
values, that might have surprising effects, otherwise it is safe to use it.

	Jakub

  reply	other threads:[~2015-04-20 11:07 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-04-15 15:22 Kyrill Tkachov
2015-04-18 14:18 ` Richard Earnshaw
2015-04-20 11:03   ` Kyrill Tkachov
2015-04-20 11:07     ` Jakub Jelinek [this message]
2015-04-20 11:31     ` Richard Earnshaw

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20150420110731.GF1725@tucnak.redhat.com \
    --to=jakub@redhat.com \
    --cc=Ramana.Radhakrishnan@arm.com \
    --cc=Richard.Earnshaw@arm.com \
    --cc=Richard.Earnshaw@foss.arm.com \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=kyrylo.tkachov@arm.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).