On August 21, 2017 5:43:08 PM GMT+02:00, Aldy Hernandez <al...@redhat.com> 
wrote:
>The attached patch fixes the problem by sign extending before
>constructing the wide int.  It does so while constructing the
>hwi_with_prec object, since the  int_traits <wi::hwi_with_prec>
>container has is_sign_extended=true, so I assume the underlying
>hwi_with_prec must be stored with sign extension.
>
>Is this what you had in mind, or would you prefer the sign extension
>in the wi::int_traits <wi::hwi_with_prec> decompose routine?
>
>Or somewhere else entirely ;-).

Richard? 

>Thanks.
>Aldy
>
>On Sun, Aug 20, 2017 at 6:40 AM, Richard Biener
><richard.guent...@gmail.com> wrote:
>> On August 20, 2017 10:46:54 AM GMT+02:00, Aldy Hernandez
><al...@redhat.com> wrote:
>>>Hi folks.
>>>
>>>Calling wi::max_value() of a boolean_type creates a wide_int with all
>>>bits set, not just the least significant bit.
>>>
>>>tree type = boolean_type_node;
>>>wide_int x = wi::max_value (TYPE_PRECISION (type), TYPE_SIGN (type));
>>>(gdb) print x.dump()
>>>[0xffffffffffffffff], precision = 1
>>>
>>>However, one can also create a boolean of true with:
>>>
>>>wide_int one = wi::uhwi (1, TYPE_PRECISION (boolean_type_node));
>>>(gdb) print one.dump()
>>>[0x1], precision = 1
>>
>> Looks like this one fails to be sign extended.
>> Richard.
>>
>>>These will not be equal to each other because wi::eq_p() will only
>>>strip
>>>off excess bits when <is_sign_extended=false>.  However,
>>>is_sign_extended=true for all wide_int's.
>>>
>>>Am I doing something wrong?
>>>
>>>Could I change wi::max_value() to strip off excess bits, instead of
>>>setting all bits like it's currently doing:
>>>
>>>wide_int
>>>wi::max_value (unsigned int precision, signop sgn)
>>>{
>>>   gcc_checking_assert (precision != 0);
>>>   if (sgn == UNSIGNED)
>>>     /* The unsigned max is just all ones.  */
>>>     return shwi (-1, precision);
>>>...
>>>...
>>>
>>>Or perhaps change wi::eq_p() to strip off excess bits?
>>>
>>>Or am I missing something else entirely?
>>>Aldy
>>

Reply via email to