* uint64_t alignof odditity on x86
@ 2009-06-16 6:17 Jan Engelhardt
2009-06-16 7:16 ` Ian Lance Taylor
0 siblings, 1 reply; 2+ messages in thread
From: Jan Engelhardt @ 2009-06-16 6:17 UTC (permalink / raw)
To: gcc
Hi,
I noticed that __alignof__(uint64_t) will return 8, while
__alignof__(struct { uint64_t x; }) will give only 4. This
run on a typical 32-bit x86 CPU (GCC config below).
What I am wondering about is why GCC was coded to give different
alignments here. If aligning a single uint64_t to a boundary of 8 for
whatever reason there may be (performance?), not doing so when it is
inside a struct appears to be a discrepancy.
---
Using built-in specs.
Target: i586-suse-linux
Configured with: ../configure --prefix=/usr --infodir=/usr/share/info
--mandir=/usr/share/man --libdir=/usr/lib --libexecdir=/usr/lib
--enable-languages=c,c++,objc,fortran,obj-c++,java,ada
--enable-checking=release --with-gxx-include-dir=/usr/include/c++/4.3
--enable-ssp --disable-libssp --with-bugurl=http://bugs.opensuse.org/
--with-pkgversion='SUSE Linux' --disable-libgcj --disable-libmudflap
--with-slibdir=/lib --with-system-zlib --enable-__cxa_atexit
--enable-libstdcxx-allocator=new --disable-libstdcxx-pch
--enable-version-specific-runtime-libs --program-suffix=-4.3
--enable-linux-futex --without-system-libunwind --with-cpu=generic
--build=i586-suse-linux
Thread model: posix
gcc version 4.3.2 [gcc-4_3-branch revision 141291] (SUSE Linux)
openSUSE 11.1 i586.
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: uint64_t alignof odditity on x86
2009-06-16 6:17 uint64_t alignof odditity on x86 Jan Engelhardt
@ 2009-06-16 7:16 ` Ian Lance Taylor
0 siblings, 0 replies; 2+ messages in thread
From: Ian Lance Taylor @ 2009-06-16 7:16 UTC (permalink / raw)
To: Jan Engelhardt; +Cc: gcc
Jan Engelhardt <jengelh@medozas.de> writes:
> I noticed that __alignof__(uint64_t) will return 8, while
> __alignof__(struct { uint64_t x; }) will give only 4. This
> run on a typical 32-bit x86 CPU (GCC config below).
>
> What I am wondering about is why GCC was coded to give different
> alignments here. If aligning a single uint64_t to a boundary of 8 for
> whatever reason there may be (performance?), not doing so when it is
> inside a struct appears to be a discrepancy.
This question would have been more appropriate for the mailing list
gcc-help@gcc.gnu.org rather than gcc@gcc.gnu.org. Please take any
followups to gcc-help. Thanks.
The x86 ABI specifies the aligment of fields within a struct. gcc can
not change that alignment without breaking the ABI. This does not
matter much when the only field has type uint64_t, but it matters for a
case like "struct { int f1; uint64_t f2; };". For a variable of type
uint64_t, it's OK for gcc to increase the alignment, since it does not
affec the ABI (although the required alignment is only 4, any program
must work if all uint64_t variables happen to be aligned on an 8-byte
boundary).
Ian
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2009-06-16 7:16 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-06-16 6:17 uint64_t alignof odditity on x86 Jan Engelhardt
2009-06-16 7:16 ` Ian Lance Taylor
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).