public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug target/94452] New: I386 ABI: How to determine the alignment of struct or union determined when passes them on stack?
@ 2020-04-02  2:28 chen3.liu at intel dot com
  2020-04-02  8:12 ` [Bug target/94452] " rguenth at gcc dot gnu.org
                   ` (5 more replies)
  0 siblings, 6 replies; 7+ messages in thread
From: chen3.liu at intel dot com @ 2020-04-02  2:28 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94452

            Bug ID: 94452
           Summary: I386 ABI: How to determine the alignment of struct or
                    union determined when passes them on stack?
           Product: gcc
           Version: unknown
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: target
          Assignee: unassigned at gcc dot gnu.org
          Reporter: chen3.liu at intel dot com
  Target Milestone: ---

For example:

#include <immintrin.h>

typedef __attribute__((aligned(16))) int alignedint;
struct __attribute__((aligned(64))) X {
    int x;
//    __m128 y;
// alignedint y;
};

void g(int x, struct X);
_Static_assert(_Alignof(struct X) == 64);

struct X gx;

void f() {
    g(1, gx);
}

In this case, the gx  will align to 4 byte. If we uncomment either the __m128
or alignedint y, and  gcc aligns to 64 bytes.

The logic of gcc alignment we now think is as below: 

StackAlignmentForType(T):
1.      If T's alignment is < 16 bytes(any type, including struct and union),
return 4.
2.      If T is a struct/union/array type, then:
•       recursively calculate on each member's type ( ignores any
attribute((aligned(N))) directly on the fields of a struct, but not those that
appear on typedefs, or the underlying types ?).
•       If all of those calls return alignments < 16, then return 4.
3.      Otherwise, return the alignment of T.

Is this logic correct for gcc?  We want to make clang compatible with gcc.

Thanks.

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [Bug target/94452] I386 ABI: How to determine the alignment of struct or union determined when passes them on stack?
  2020-04-02  2:28 [Bug target/94452] New: I386 ABI: How to determine the alignment of struct or union determined when passes them on stack? chen3.liu at intel dot com
@ 2020-04-02  8:12 ` rguenth at gcc dot gnu.org
  2020-04-02  8:26 ` chen3.liu at intel dot com
                   ` (4 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: rguenth at gcc dot gnu.org @ 2020-04-02  8:12 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94452

Richard Biener <rguenth at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |WAITING
   Last reconfirmed|                            |2020-04-02
     Ever confirmed|0                           |1

--- Comment #1 from Richard Biener <rguenth at gcc dot gnu.org> ---
I see gx aligned to 64 bytes (as I expected).  Can you be more specific as to
what target you tested?

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [Bug target/94452] I386 ABI: How to determine the alignment of struct or union determined when passes them on stack?
  2020-04-02  2:28 [Bug target/94452] New: I386 ABI: How to determine the alignment of struct or union determined when passes them on stack? chen3.liu at intel dot com
  2020-04-02  8:12 ` [Bug target/94452] " rguenth at gcc dot gnu.org
@ 2020-04-02  8:26 ` chen3.liu at intel dot com
  2020-04-02  8:50 ` chen3.liu at intel dot com
                   ` (3 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: chen3.liu at intel dot com @ 2020-04-02  8:26 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94452

--- Comment #2 from ChenLiu <chen3.liu at intel dot com> ---
(In reply to Richard Biener from comment #1)
> I see gx aligned to 64 bytes (as I expected).  Can you be more specific as
> to what target you tested?

I tested on i386 target. I think you may misunderstand what I mean. The gx will
align to 4 byte when passing it on stack. I think this should belong to calling
conventions.

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [Bug target/94452] I386 ABI: How to determine the alignment of struct or union determined when passes them on stack?
  2020-04-02  2:28 [Bug target/94452] New: I386 ABI: How to determine the alignment of struct or union determined when passes them on stack? chen3.liu at intel dot com
  2020-04-02  8:12 ` [Bug target/94452] " rguenth at gcc dot gnu.org
  2020-04-02  8:26 ` chen3.liu at intel dot com
@ 2020-04-02  8:50 ` chen3.liu at intel dot com
  2020-04-02  9:09 ` [Bug target/94452] I386 ABI: How to determine the alignment arguments on the stack of struct or union for argument passing rguenth at gcc dot gnu.org
                   ` (2 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: chen3.liu at intel dot com @ 2020-04-02  8:50 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94452

--- Comment #3 from ChenLiu <chen3.liu at intel dot com> ---
(In reply to Richard Biener from comment #1)
> I see gx aligned to 64 bytes (as I expected).  Can you be more specific as
> to what target you tested?

The gcc version I use is 7.3.0 and only one option was used: -m32.

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [Bug target/94452] I386 ABI: How to determine the alignment arguments on the stack of struct or union for argument passing
  2020-04-02  2:28 [Bug target/94452] New: I386 ABI: How to determine the alignment of struct or union determined when passes them on stack? chen3.liu at intel dot com
                   ` (2 preceding siblings ...)
  2020-04-02  8:50 ` chen3.liu at intel dot com
@ 2020-04-02  9:09 ` rguenth at gcc dot gnu.org
  2020-04-02  9:18 ` chen3.liu at intel dot com
  2020-04-02 11:56 ` hjl.tools at gmail dot com
  5 siblings, 0 replies; 7+ messages in thread
From: rguenth at gcc dot gnu.org @ 2020-04-02  9:09 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94452

Richard Biener <rguenth at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
            Summary|I386 ABI: How to determine  |I386 ABI: How to determine
                   |the alignment of struct or  |the alignment arguments on
                   |union determined when       |the stack of struct or
                   |passes them on stack?       |union for argument passing
             Status|WAITING                     |UNCONFIRMED
     Ever confirmed|1                           |0

--- Comment #4 from Richard Biener <rguenth at gcc dot gnu.org> ---
(In reply to ChenLiu from comment #2)
> (In reply to Richard Biener from comment #1)
> > I see gx aligned to 64 bytes (as I expected).  Can you be more specific as
> > to what target you tested?
> 
> I tested on i386 target. I think you may misunderstand what I mean. The gx
> will align to 4 byte when passing it on stack. I think this should belong to
> calling conventions.

Ah, OK.  IIRC the psABI does not factor in over/under alignment but only
size and kind of (sub-)objects so eventually extra copy-in/out is required
to have the callee see arguments of the desired alignment.

HJ can probably clarify.

Note bugzilla isn't really for this kind of questions, there's a psABI
mailing list somewhere.

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [Bug target/94452] I386 ABI: How to determine the alignment arguments on the stack of struct or union for argument passing
  2020-04-02  2:28 [Bug target/94452] New: I386 ABI: How to determine the alignment of struct or union determined when passes them on stack? chen3.liu at intel dot com
                   ` (3 preceding siblings ...)
  2020-04-02  9:09 ` [Bug target/94452] I386 ABI: How to determine the alignment arguments on the stack of struct or union for argument passing rguenth at gcc dot gnu.org
@ 2020-04-02  9:18 ` chen3.liu at intel dot com
  2020-04-02 11:56 ` hjl.tools at gmail dot com
  5 siblings, 0 replies; 7+ messages in thread
From: chen3.liu at intel dot com @ 2020-04-02  9:18 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94452

--- Comment #5 from ChenLiu <chen3.liu at intel dot com> ---
(In reply to Richard Biener from comment #4)
> (In reply to ChenLiu from comment #2)
> > (In reply to Richard Biener from comment #1)
> > > I see gx aligned to 64 bytes (as I expected).  Can you be more specific as
> > > to what target you tested?
> > 
> > I tested on i386 target. I think you may misunderstand what I mean. The gx
> > will align to 4 byte when passing it on stack. I think this should belong to
> > calling conventions.
> 
> Ah, OK.  IIRC the psABI does not factor in over/under alignment but only
> size and kind of (sub-)objects so eventually extra copy-in/out is required
> to have the callee see arguments of the desired alignment.
> 
> HJ can probably clarify.
> 
> Note bugzilla isn't really for this kind of questions, there's a psABI
> mailing list somewhere.

Thanks for your help.

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [Bug target/94452] I386 ABI: How to determine the alignment arguments on the stack of struct or union for argument passing
  2020-04-02  2:28 [Bug target/94452] New: I386 ABI: How to determine the alignment of struct or union determined when passes them on stack? chen3.liu at intel dot com
                   ` (4 preceding siblings ...)
  2020-04-02  9:18 ` chen3.liu at intel dot com
@ 2020-04-02 11:56 ` hjl.tools at gmail dot com
  5 siblings, 0 replies; 7+ messages in thread
From: hjl.tools at gmail dot com @ 2020-04-02 11:56 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94452

H.J. Lu <hjl.tools at gmail dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |NEW
     Ever confirmed|0                           |1

--- Comment #6 from H.J. Lu <hjl.tools at gmail dot com> ---
(In reply to ChenLiu from comment #5)
> (In reply to Richard Biener from comment #4)
> > (In reply to ChenLiu from comment #2)
> > > (In reply to Richard Biener from comment #1)
> > > > I see gx aligned to 64 bytes (as I expected).  Can you be more specific as
> > > > to what target you tested?
> > > 
> > > I tested on i386 target. I think you may misunderstand what I mean. The gx
> > > will align to 4 byte when passing it on stack. I think this should belong to
> > > calling conventions.
> > 
> > Ah, OK.  IIRC the psABI does not factor in over/under alignment but only
> > size and kind of (sub-)objects so eventually extra copy-in/out is required
> > to have the callee see arguments of the desired alignment.
> > 
> > HJ can probably clarify.
> > 
> > Note bugzilla isn't really for this kind of questions, there's a psABI
> > mailing list somewhere.
> 
> Thanks for your help.

Please raise this question at

https://groups.google.com/forum/#!forum/ia32-abi

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2020-04-02 11:56 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-04-02  2:28 [Bug target/94452] New: I386 ABI: How to determine the alignment of struct or union determined when passes them on stack? chen3.liu at intel dot com
2020-04-02  8:12 ` [Bug target/94452] " rguenth at gcc dot gnu.org
2020-04-02  8:26 ` chen3.liu at intel dot com
2020-04-02  8:50 ` chen3.liu at intel dot com
2020-04-02  9:09 ` [Bug target/94452] I386 ABI: How to determine the alignment arguments on the stack of struct or union for argument passing rguenth at gcc dot gnu.org
2020-04-02  9:18 ` chen3.liu at intel dot com
2020-04-02 11:56 ` hjl.tools at gmail dot com

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).