Re: alignment on powerpc
David Bélanger <[email protected]> Wed, 3 May 2006 23:10:48 -0400
| Newsgroups | gmane.comp.java.vm.sablevm.devel |
|---|---|
| Message-ID | <[email protected]> |
Hi Chris,
OS X, Linux, and AIX uses different ABI.
OS X ABI is somewhere on Apple's website in the doc.
Linux uses SVR4 ABI - PowerPC supplement.
The test tests for the alignment of members in a struct.
The Linux ABI says that double in struct must be aligned
on 8-byte boundary. But the Mac OS X ABI is likely to
say that a 4-byte boundary is fine (though I will need
to find the ABI doc to really know... and I cannot find it...
it's somewhere on Apple's site...)
Double on 8-byte alignment is the safest to go if you
consider all PowerPC CPU implementation since the alignment
is the same size as the type -- this is called the
"natural alignment" in the ABI docs. It is not necessary
the minimal required alignment.
The cost of double aligned on 4-byte would depend on
the actual PowerPC CPU implementation. Might have one,
might not have one, or some cost depending on location
in memory.
>From googled gcc doc on Apple site:
-malign-power
-malign-natural
The option -malign-mac68k causes structure fields to be aligned on
2-byte boundaries, in order to be compatible with m68k compiler
output. The option -malign-power is the standard alignment mode for
the PowerPC. The option -malign-natural is an extension of PowerPC
alignment that aligns larger data types such as doubles on their
natural boundaries. (APPLE ONLY)=20
So this confirms that Apple does not align double on 8-byte in struct
by default.
I think I noticed it when I ported SableVM to OS X but since 8-byte
is fine, I let it at 8 for both Linux and OS X.
David
On Tue, May 02, 2006 at 10:55:58PM -0400, Chris Pickett wrote:
> Hi,
>=20
> [I haven't looked at the prepare_code.c data race stuff yet.]
>=20
> If I run the (slightly modified) program following this message from=20
> libsablevm/system.h on a 32-bit iBook under Mac OS X with gcc 3.3, I ge=
t=20
> "alignment =3D 4" printed out. Yet we have
>=20
> #define SVM_ALIGNMENT 8
> #define SVM_ALIGNMENT_POWER 3
>=20
> defined in the __powerpc__ section of system.h.
>=20
> Why is alignment defined like this? Also, perhaps there need to be=20
> separate ports for 32-bit and 64-bit PowerPC processors, since the word=
=20
> size is very likely 8 on a 64-bit arch and not 4.
>=20
> Cheers,
> Chris
>=20
> #include <stdio.h>
>=20
> struct {
> char c;
> int v;
> } a;
>=20
> int
> main (int argc, char *argv[])
> {
> printf ("alignment =3D %u\n",
> (unsigned int) (((char *) &a.v) - ((char *) &a)));
> return 0;
> }
>=20
> _______________________________________________
> SableVM-devel mailing list
> [email protected]
> http://sablevm.org/lists/control/listinfo/sablevm-devel
>=20
--=20
---
David B=E9langer
Web page: http://www.cs.mcgill.ca/~dbelan2/
Public key: http://www.cs.mcgill.ca/~dbelan2/public_key.txt