On Sep 22, 2014, at 8:51 AM, Jan Hubicka <hubi...@ucw.cz> wrote:
>> On Sun, 21 Sep 2014, Jan Hubicka wrote:
>> 
>>>> 
>>>> Please omit static from inline functions.
>>> 
>>> Yep, I suppose we want to drop static in all inlines? I can make patch for 
>>> that.
>>>> 
>>>> Also one notable difference with your patches is that the fits hwi is now 
>>>> not tested on the result but on the result input which, multiplied by 8, 
>>>> might not fit a hwi now.  So please use wide-ints here (the to_offset 
>>>> flavor).
>>> 
>>> The function must always suceed (so user promise it will fit in HWI) and for
>>> performance reasons I would rather not go into wide int by defualt, but I 
>>> can
>>> do that with checking enabled.
>> 
>> wide-int should be fast enough, please use it.
> 
> Like this?
> 
> Index: tree.h
> ===================================================================
> --- tree.h    (revision 215421)
> +++ tree.h    (working copy)
> @@ -3877,10 +3877,20 @@ extern tree size_in_bytes (const_tree);
> extern HOST_WIDE_INT int_size_in_bytes (const_tree);
> extern HOST_WIDE_INT max_int_size_in_bytes (const_tree);
> extern tree bit_position (const_tree);
> -extern HOST_WIDE_INT int_bit_position (const_tree);
> extern tree byte_position (const_tree);
> extern HOST_WIDE_INT int_byte_position (const_tree);
> 
> +/* Like bit_position, but return as an integer.  It must be representable in
> +   that way (since it could be a signed value, we don't have the
> +   option of returning -1 like int_size_in_byte can.  */
> +
> +static inline HOST_WIDE_INT int_bit_position (const_tree field)
> +{ 
> +  return ((wide_int)DECL_FIELD_OFFSET (field) * BITS_PER_UNIT
> +       + (wide_int)DECL_FIELD_BIT_OFFSET (field)).to_shwi ();
> +}
> +
> +

Not quite:

      offset_int woffset
        = (wi::to_offset (xoffset)
           + wi::lrshift (wi::to_offset (DECL_FIELD_BIT_OFFSET (field)),
                          LOG2_BITS_PER_UNIT));

offset_int is the type that can hold all bit positions, byte positions, byte 
sizes and bit sizes.

One can use wi::to_offset to convert things into it.  You can see woffset uses 
to see that various uses to convert back out.  The idea is that eventually all 
the code that plays with that concept, could use that type.  Convert into it 
sooner, and convert out of it later.

Reply via email to