Speedup int_bit_from_pos

Jan Hubicka hubicka@ucw.cz
Mon Sep 22 18:53:00 GMT 2014


> On Sep 22, 2014, at 11:22 AM, Jan Hubicka <hubicka@ucw.cz> wrote:
> >> 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.
> > 
> > Yep, I worked that out in meantime. Now I get:
> > ../../gcc/tree.h: In function �long int int_bit_position(const_tree)�:
> > ../../gcc/tree.h:3890:24: error: �to_offset� is not a member of �wi�
> >   return (wi::lrshift (wi::to_offset (DECL_FIELD_OFFSET (field)), BITS_PER_UNIT_LOG)
> 
> That is defined later in tree.h?  If you want to use it in tree.h, you will have to have it after to_offset is defined.  Alternatively, you can move it up, but, you will need to understand the dependancies some (or try some builds).

Aha, missed that bit.  I am testing this variant.

Honza

Index: tree.h
===================================================================
--- tree.h	(revision 215421)
+++ tree.h	(working copy)
@@ -3877,10 +3877,9 @@ 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);
 
 #define sizetype sizetype_tab[(int) stk_sizetype]
 #define bitsizetype sizetype_tab[(int) stk_bitsizetype]
 #define ssizetype sizetype_tab[(int) stk_ssizetype]
@@ -4797,4 +4797,14 @@ extern tree get_inner_reference (tree, H
    EXP, an ARRAY_REF or an ARRAY_RANGE_REF.  */
 extern tree array_ref_low_bound (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 (wi::lrshift (wi::to_offset (DECL_FIELD_OFFSET (field)), BITS_PER_UNIT_LOG)
+	  + wi::to_offset (DECL_FIELD_BIT_OFFSET (field))).to_shwi ();
+}
 #endif  /* GCC_TREE_H  */



More information about the Gcc-patches mailing list