This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Speedup int_bit_from_pos


> 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 ();
+}
+
+
 #define sizetype sizetype_tab[(int) stk_sizetype]
 #define bitsizetype sizetype_tab[(int) stk_bitsizetype]
 #define ssizetype sizetype_tab[(int) stk_ssizetype]


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]