public inbox for gcc@gcc.gnu.org
 help / color / mirror / Atom feed
From: Geert Bosch <bosch@gnat.com>
To: Jason Merrill <jason@redhat.com>
Cc: Alexandre Oliva <aoliva@redhat.com>,
	kenner@vlsi1.ultra.nyu.edu (Richard Kenner),
	gcc-patches@gcc.gnu.org, gcc@gcc.gnu.org,
	Jakub Jelinek <jakub@redhat.com>,
	Richard Henderson <rth@redhat.com>
Subject: Re: DATA_ALIGNMENT vs. DECL_USER_ALIGNMENT
Date: Thu, 24 Apr 2003 21:32:00 -0000	[thread overview]
Message-ID: <5E98DB9A-768B-11D7-A844-00039344BF4A@gnat.com> (raw)
In-Reply-To: <wvlr87rbytv.fsf@prospero.boston.redhat.com>


On Thursday, Apr 24, 2003, at 13:16 America/New_York, Jason Merrill 
wrote:
> I was referring to what dewar said here:
>
> On Mon, 21 Apr 2003 17:35:51 -0400 (EDT), dewar@gnat.com (Robert 
> Dewar) wrote:
>
>>   type A is ...
>>
>>   B : A;
>>   for B'Alignment use 4;
>>
>>   Put_Line (Integer'Image (B'Alignment));
>>
>> This must output 4. Of course the compiler could still silently put
>> B on a bigger alignment, since there would be no way to tell that it
>> was doing this systematically, but this would be a poor 
>> implementation.
>
> To me, this means that DECL_ALIGN for B must be exactly 4, whereas 
> giving A a TYPE_ALIGN of 4 would only mean that DECL_ALIGN for B must 
> be at least 4.

Exactly. A TYPE_ALIGN of 4 means that any variable of the type is
aligned to at least 4. So the maximum alignment the compiler can
assume for any pointer to a 4-byte aligned type is 4.

>> Of course the compiler should have a good reason to increase, but 
>> that's a quality of implementation issue. For example, a compiler 
>> might well align all 14-byte local objects of a 2-byte aligned type 
>> to 16 bytes and then take advantage of that stricter alignment in 
>> code generation.

> This seems to conflict with what dewar is saying.
No it does not. Note that this is the case where no DECL_ALIGN has been
specified. Such as:
   type T is record
      X, Y, Z : Unsigned_16; -- 16-bit unsigned type
   end T;
   for T'Size use 48; --  48 bits
   for T'Alignment use 2;

   R : T := (1, 2, 3);
   Put (R'Alignment);

This may output a value that is a multiple of 2. Here the compiler
might decide to align R on a 8-byte boundary for efficiency. This
may enable the initialization to be done with a single 64-bit write,
for example. Of course, the knowledge about the better alignment
of R will get lost when passing (a pointer to) it to another
function. Still, increasing the alignment of objects is a
significant optimization that can speed up code immensely.
This will only be more true when the compiler will learn
more about vector instructions.

>> Specifying an alignment for a type means "don't reduce" the alignment
>> for any allocations of objects of this type and "don't assume 
>> increased" alignment for any objects accessed of this type.
>
> I think everyone agrees about this.  The alignment for a type is a 
> contract between definitions and uses.
>
> So, what exactly do we need to be able to express?
>
> 1) For types, we want to be able to force a minimum alignment for
>   efficiency/correctness of access.
> 2) For fields, we want to be able to force a minimum alignment.
> 3) For fields, we want to be able to reduce alignment for packing 
> efficiency.
Note where you write "field", this really means "component of a
composite type", where a composite type can either be a record
or array.
> 4) For objects, we want to be able to force a minimum alignment.
Yes, where minimum alignment is not smaller than the type alignment.
> 5) For objects, we want to be able to force an exact alignment for 
> building up special sections (and for other reasons?).
How would this interact with reordering of objects (for example,
sorting by decreasing size, or for increasing cache efficiency)?
Also, do we guarantee that the compiler will not decide to output
extra objects between user-defined ones?
> 1 is handled by TYPE_ALIGN/TYPE_USER_ALIGN.
> 2 and 4/5 are handled by DECL_ALIGN/DECL_USER_ALIGN.
> 3 is handled by DECL_PACKED.
>
> It seems to me that the question people have been arguing about is 
> what to do about the distinction between 4 and 5.  I think that 
> DECL_USER_ALIGN was intended to mean 2, which logically extends to 4.
Agreed.
>
> rth's patch of 2001-08-15 changed it to mean 5.
>
> It makes sense to inherit DECL_USER_ALIGN from TYPE_USER_ALIGN if it 
> means 4, but not if it means 5; that's why we're seeing the S/390 
> problem.

I don't think inheriting is a good idea, even for 4. This way
we loose the capability to over-align objects for which no specific
alignment was specified. It is important that we can do this,
especially as it allows small records to be stored in registers.
> There would seem to be two ways to fix this:
>
> A) Stop inheriting DECL_USER_ALIGN from TYPE_USER_ALIGN on VAR_DECLs.
> B) Change DECL_USER_ALIGN to mean 4, and use DECL_PACKED to mean 5.
>
> I'm partial to solution B.  Other opinions?

I'm in favor of A, since it differentiates between the case where
the compiler has freedom to choose the alignment that gives the
most efficient code on each machine and the case where the user
has good reasons to pin down the details.

   -Geert

  parent reply	other threads:[~2003-04-24 19:31 UTC|newest]

Thread overview: 101+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2003-04-23  2:20 Richard Kenner
2003-04-23  5:31 ` Alexandre Oliva
2003-04-24  6:23   ` Jason Merrill
2003-04-24  8:43     ` Geert Bosch
2003-04-24 17:48       ` Jason Merrill
2003-04-24 18:04         ` Zack Weinberg
2003-04-24 19:31           ` Jason Merrill
2003-04-24 21:32         ` Geert Bosch [this message]
2003-04-24 23:24           ` Jason Merrill
2003-04-25  2:56     ` Richard Henderson
  -- strict thread matches above, loose matches on Subject: below --
2003-04-23  3:29 Robert Dewar
2003-04-22 15:08 Richard Kenner
2003-04-23  1:07 ` Alexandre Oliva
2003-04-22  0:15 Robert Dewar
2003-04-22  1:58 ` Jamie Lokier
2003-04-22  0:11 Robert Dewar
2003-04-22  1:35 ` Jamie Lokier
2003-04-21 21:25 Richard Kenner
2003-04-21 20:59 Richard Kenner
2003-04-21 21:14 ` Jamie Lokier
2003-04-21 20:45 Richard Kenner
2003-04-21 20:58 ` Jamie Lokier
2003-04-21 18:14 Richard Kenner
2003-04-21 20:33 ` Jamie Lokier
2003-04-21 17:25 Richard Kenner
2003-04-21 18:14 ` Jamie Lokier
2003-04-22  9:00 ` Alexandre Oliva
2003-04-20 21:28 Robert Dewar
2003-04-21 17:05 ` Alexandre Oliva
2003-04-20 21:19 Robert Dewar
2003-04-18 11:41 Richard Kenner
2003-04-18  8:06 Richard Kenner
2003-04-18  8:59 ` Richard Henderson
2003-04-17 21:41 Richard Kenner
2003-04-17 23:20 ` Alexandre Oliva
2003-04-18  1:16 ` Richard Henderson
2003-04-17 21:40 Richard Kenner
2003-04-17 11:56 Richard Kenner
2003-04-17 20:35 ` Alexandre Oliva
2003-04-17 22:41   ` Geert Bosch
2003-04-17 23:19     ` Alexandre Oliva
2003-04-17 10:44 Robert Dewar
2003-04-17 20:30 ` Alexandre Oliva
2003-04-17  8:12 Richard Kenner
2003-04-17  8:38 ` Alexandre Oliva
2003-04-11 22:26 Robert Dewar
2003-04-11 16:59 Robert Dewar
2003-04-11 18:49 ` Laurent Guerby
2003-04-11 16:51 Robert Dewar
2003-04-11 14:52 Robert Dewar
2003-04-11  4:45 Richard Kenner
2003-04-17  5:39 ` Alexandre Oliva
2003-04-11  0:45 Ulrich Weigand
2003-04-10 22:43 Richard Kenner
2003-04-11  0:31 ` Richard Henderson
2003-04-11  2:19   ` David Edelsohn
2003-04-10 22:23 Richard Kenner
2003-04-10 22:16 Richard Kenner
2003-04-10 22:07 Richard Kenner
2003-04-10 22:23 ` David Edelsohn
2003-04-10 22:05 Robert Dewar
2003-04-10 22:02 Richard Kenner
2003-04-10 22:24 ` Richard Henderson
2003-04-11 11:20   ` Laurent Guerby
2003-04-11 11:57     ` Arnaud Charlet
2003-04-11 14:16       ` Laurent Guerby
2003-04-10 21:56 Richard Kenner
2003-04-10 22:02 ` David Edelsohn
2003-04-10 21:45 Richard Kenner
2003-04-10 21:52 ` David Edelsohn
2003-04-10 21:57 ` Richard Henderson
2003-04-10 21:44 Richard Kenner
2003-04-10 21:32 Robert Dewar
2003-04-10 21:32 ` David Edelsohn
2003-04-10 21:31 Richard Kenner
2003-04-10 21:29 Robert Dewar
2003-04-10 21:10 Robert Dewar
2003-04-10 21:17 ` David Edelsohn
2003-04-10 21:10 Richard Kenner
2003-04-10 21:04 Richard Kenner
2003-04-10 21:41 ` Geoff Keating
2003-04-10 20:57 Robert Dewar
2003-04-10 21:07 ` Ulrich Weigand
2003-04-10 20:52 Robert Dewar
2003-04-10 20:39 Richard Kenner
2003-04-10 21:00 ` Geoff Keating
2003-04-10 21:01 ` Ulrich Weigand
2003-04-10 21:44 ` Richard Henderson
2003-04-10 20:13 Richard Kenner
2003-04-10 20:28 ` Ulrich Weigand
2003-04-10 19:20 Richard Kenner
2003-04-10  5:33 Richard Kenner
2003-04-10  7:20 ` Ulrich Weigand
2003-04-09 23:31 Ulrich Weigand
2003-04-10  2:27 ` Richard Henderson
2003-04-10  3:10   ` Ulrich Weigand
2003-04-10 16:20     ` Ulrich Weigand
2003-04-10 16:39       ` Geoff Keating
2003-04-10 16:44         ` Ulrich Weigand
2003-04-10 18:06       ` Richard Henderson
2003-04-08 17:47 Ulrich Weigand

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=5E98DB9A-768B-11D7-A844-00039344BF4A@gnat.com \
    --to=bosch@gnat.com \
    --cc=aoliva@redhat.com \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=gcc@gcc.gnu.org \
    --cc=jakub@redhat.com \
    --cc=jason@redhat.com \
    --cc=kenner@vlsi1.ultra.nyu.edu \
    --cc=rth@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).