This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: wide-int branch updated
- From: Richard Sandiford <rdsandiford at googlemail dot com>
- To: Kenneth Zadeck <zadeck at naturalbridge dot com>
- Cc: Mike Stump <mikestump at comcast dot net>, Richard Sandiford <r dot sandiford at uk dot ibm dot com>, gcc-patches <gcc-patches at gcc dot gnu dot org>, rguenther at suse dot de
- Date: Tue, 27 Aug 2013 19:31:04 +0100
- Subject: Re: wide-int branch updated
- Authentication-results: sourceware.org; auth=none
- References: <521B45A3 dot 5010201 at naturalbridge dot com>
Kenneth Zadeck <zadeck@naturalbridge.com> writes:
> fixed fits_uhwi_p.
>
> tested on x86-64.
>
> kenny
>
> Index: gcc/wide-int.h
> ===================================================================
> --- gcc/wide-int.h (revision 201985)
> +++ gcc/wide-int.h (working copy)
> @@ -1650,7 +1650,7 @@ wide_int_ro::fits_shwi_p () const
> inline bool
> wide_int_ro::fits_uhwi_p () const
> {
> - return len == 1 || (len == 2 && val[1] == 0);
> + return (len == 1 && val[0] >= 0) || (len == 2 && val[1] == 0);
> }
With upper bits being undefined, it doesn't seem safe to check
val[0] or val[1] like this. I was thinking along the lines of:
inline bool
wide_int_ro::fits_uhwi_p () const
{
if (precision <= HOST_BITS_PER_WIDE_INT)
return true;
if (len == 1)
return val[0] >= 0;
if (precision < HOST_BITS_PER_WIDE_INT * 2)
return ((unsigned HOST_WIDE_INT) val[1]
<< (HOST_BITS_PER_WIDE_INT * 2 - precision)) == 0;
return val[1] == 0;
}
Since we don't have a sign, everything HWI-sized or smaller fits in a
uhwi without loss of precision.
I've tested the above on x86_64-linux-gnu FWIW, in case it looks OK.
Thanks,
Richard