Patchwork Optimize byte_from_pos, pos_from_bit

login
register
mail settings
Submitter Richard Guenther
Date May 10, 2012, 7:44 a.m.
Message ID <Pine.LNX.4.64.1205100944210.11924@jbgna.fhfr.qr>
Download mbox | patch
Permalink /patch/158214/
State New
Headers show

Comments

Richard Guenther - May 10, 2012, 7:44 a.m.
On Wed, 9 May 2012, Eric Botcazou wrote:

> > This optimizes byte_from_pos and pos_from_bit by noting that we operate
> > on sizes whose computations have no intermediate (or final) overflow.
> > This is the single patch necessary to get Ada to bootstrap and test
> > with TYPE_IS_SIZETYPE removed.  Rather than amending size_binop
> > (my original plan) I chose to optimize the above two commonly used
> > accessors.
> >
> > Conveniently normalize_offset can be re-written to use pos_from_bit
> > instead of inlinig it.  I also took the liberty to document the
> > functions (sic).
> 
> Nice, thanks.  Could you add a blurb, in the head comment of the first function 
> in which you operate under the no-overflow assumption, stating this fact and 
> why this is necessary (an explicit mention of Ada isn't forbidden ;-), as well 
> as a cross-reference to it in the head comment of the other function(s).

Like this?

Thanks,
Richard.

2012-05-10  Richard Guenther  <rguenther@suse.de>

	* stor-layout.c (byte_from_pos): Amend comment.
Eric Botcazou - May 10, 2012, 10:11 a.m.
> Like this?

Let's be a bit more factual. :-)

 /* Return the combined truncated byte position for the byte offset OFFSET and
    the bit position BITPOS.

    These functions operate on byte and bit positions present in FIELD_DECLs
    and assume that these expressions result in no (intermediate) overflow.
    This assumption is necessary to fold the expressions as much as possible,
    so as to avoid creating artificially variable-sized types in languages
    supporting variable-sized types like Ada.  */
Richard Guenther - May 10, 2012, 10:25 a.m.
On Thu, 10 May 2012, Eric Botcazou wrote:

> > Like this?
> 
> Let's be a bit more factual. :-)
> 
>  /* Return the combined truncated byte position for the byte offset OFFSET and
>     the bit position BITPOS.
> 
>     These functions operate on byte and bit positions present in FIELD_DECLs
>     and assume that these expressions result in no (intermediate) overflow.
>     This assumption is necessary to fold the expressions as much as possible,
>     so as to avoid creating artificially variable-sized types in languages
>     supporting variable-sized types like Ada.  */

Works for me.

Applied that way.

Thanks,
Richard.

Patch

Index: gcc/stor-layout.c
===================================================================
--- gcc/stor-layout.c	(revision 187362)
+++ gcc/stor-layout.c	(working copy)
@@ -798,7 +798,11 @@  bit_from_pos (tree offset, tree bitpos)
 }
 
 /* Return the combined truncated byte position for the byte offset OFFSET and
-   the bit position BITPOS.  */
+   the bit position BITPOS.
+   These functions operate on byte and bit positions as present in FIELD_DECLs
+   and it assumes that expressions result in no (intermediate) overflow.
+   This assumption is necessary to optimize these values as much as possible,
+   especially to make Ada happy.  */
 
 tree
 byte_from_pos (tree offset, tree bitpos)