How should _Decimal64 and _Decimal128 be aligned on stack?

22 views
Skip to first unread message

H.J.

unread,
Mar 21, 2008, 8:29:38 PM3/21/08
to IA32 System V Application Binary Interface, g...@gcc.gnu.org
When passing _Decimal64 or _Decimal128 to a function via stack, how
should they be aligned? Currently, gcc aligns them at 4byte boundary.
Is this desirable?

H.J.

H.J. Lu

unread,
Mar 22, 2008, 12:00:25 AM3/22/08
to Andrew Pinski, IA32 System V Application Binary Interface, g...@gcc.gnu.org
On Fri, Mar 21, 2008 at 5:37 PM, Andrew Pinski <pin...@gmail.com> wrote:
> Shouldn't it always be 4 byte aligned because the SysV ABI only talks
> about word alignment?
>

DFP is beyond i386 psABI. Gcc aligns _Decimal32 to 4 byte, _Decimal64 to 8 bytes
and _Decimal128 to 16bytes. The question is what is the best alignment for them
when passing to a functions.


H.J.

Michael Eager

unread,
Mar 22, 2008, 11:48:02 AM3/22/08
to ia32...@googlegroups.com

Unless there is some hardware penalty in loading from
a 4-byte boundary rather than 8-byte boundary, then it
would seem that 4-byte alignment is simpler. On the
other hand, it would seem that alignment of a data value
should be on the expected boundary whether it statically
allocated or passed to a function.


--
Michael Eager ea...@eagercon.com
1960 Park Blvd., Palo Alto, CA 94306 650-325-8077

H.J. Lu

unread,
Mar 23, 2008, 11:09:18 AM3/23/08
to Ben Elliston, Andrew Pinski, IA32 System V Application Binary Interface, g...@gcc.gnu.org
On Sun, Mar 23, 2008 at 11:41:00PM +1100, Ben Elliston wrote:
> > DFP is beyond i386 psABI. Gcc aligns _Decimal32 to 4 byte, _Decimal64 to 8 bytes
> > and _Decimal128 to 16bytes. The question is what is the best alignment for them
> > when passing to a functions.
>
> The original work I did for the x86-64 backend placed them at that
> alignment because that is the required alignment for loading those
> values into SSE registers. Right?

That is a good question. For x86, _Decimal128 is passed on stack
and aligned at 4 byte. For x86-64, _Decimal128 is passed in SSE
registers. An implementation of _Decimal128 in 32bit may want
to use SSE registers.


H.J.

H.J. Lu

unread,
Mar 24, 2008, 8:29:53 PM3/24/08
to Ben Elliston, Andrew Pinski, IA32 System V Application Binary Interface, g...@gcc.gnu.org

I think we should align _Decimal64 and _Decimal128 to their natural
alignments when passing a function. The same should apply to x86-64
when they are passed on stack.


H.J.

Dave Kreitzer

unread,
Apr 1, 2008, 1:53:39 PM4/1/08
to IA32 System V Application Binary Interface
> I think we should align _Decimal64 and _Decimal128 to their natural
> alignments when passing a function. The same should apply to x86-64
> when they are passed on stack.
>

Rather than aligning _Decimal64 to its natural boundary, I think it is
more sensible to be consistent with the existing 8-byte scalar types,
i.e. double and long long. That would mean aligning _Decimal64 to 4
bytes within structures and when passing to a function.

For _Decimal128, I agree with the conclusion to align to 16-bytes
within structures and as outgoing arguments. That behavior is
consistent with the existing data types __m128, __m128d, and __m128i.

Dave Kreitzer
IA-32 and Intel 64 Code Generation
Intel Compiler Lab

H.J. Lu

unread,
Apr 1, 2008, 2:18:04 PM4/1/08
to ia32...@googlegroups.com, GCC
Hi David,

I added gcc mailing list.

H.J.


On Tue, Apr 1, 2008 at 10:53 AM, Dave Kreitzer
<david.l....@intel.com> wrote:
>
> > I think we should align _Decimal64 and _Decimal128 to their natural
> > alignments when passing a function. The same should apply to x86-64
> > when they are passed on stack.
> >
>
> Rather than aligning _Decimal64 to its natural boundary, I think it is
> more sensible to be consistent with the existing 8-byte scalar types,
> i.e. double and long long. That would mean aligning _Decimal64 to 4
> bytes within structures and when passing to a function.
>

That means to change the default alignment of _Decimal64 to 4 bytes in
32bit mode.

Reply all
Reply to author
Forward
0 new messages