Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

AIX, compiler xlC: alignment of double-member in structure

54 views
Skip to first unread message

Alex Vinokur

unread,
Apr 8, 2010, 1:41:23 AM4/8/10
to avin...@amdocs.com

Hi,

I have the following problem on AIX (compiler xlC) with alignment of
double-member in structure.

1. cpp-file

// ------- File align1.cpp : BEGIN -------
#include <cstdlib>
#include <iostream>
#include <iomanip>

struct SampleLong
{
char m_char;
long m_long;
};

struct SampleDouble
{
char m_char;
// --------------
// On AIX, compiler xlC:
// 1) sizeof (m_double) == 8, but offset == 4,
// 2) pointer &m_double has only two binary nulls at the end,
// i.e. is not aligned to 8 bytes
double m_double;
// --------------
};

#define SHOW(s,m) std::cout << "" \
<< #s \
<< "." \
<< std::setw(8) \
<< std::left \
<< #m \
<< std::right \
<< ": " \
<< "struct sizeof = " << sizeof(s) \
<< ", " \
<< "member sizeof = " << sizeof(s.m) \
<< ", " \
<< "member offset = " <<
(reinterpret_cast<std::size_t>(&s.m) -
reinterpret_cast<std::size_t>(&s)) \
<< ", " \
<< "struct ptr = " <<
reinterpret_cast<void*>(&s) \
<< ", " \
<< "member ptr = " <<
reinterpret_cast<void*>(&s.m) \
<< std::endl


int main()
{

system ("uname -a");
std::cout << std::endl;
#ifdef _AIX
system ("xlC -qversion");
std::cout << std::endl;
#endif

#ifdef __hpux
system ("aCC -V");
std::cout << std::endl;
#endif

SampleLong instL;
SampleDouble instD;

SHOW (instL, m_long);
SHOW (instD, m_double);

return 0;
}

// ------- File align1.cpp : END -------

2.1. Compilation and running on AIX 5.3 (compiler xlC V8.0)

> xlC -q64 -qwarn64 align1.cpp

> ./a.out
AIX ep5710g 3 5 00C58FE04C00

IBM XL C/C++ Enterprise Edition V8.0 for AIX
Version: 08.00.0000.0014

instL.m_long : struct sizeof = 16, member sizeof = 8, member offset =
8, struct ptr = fffffffffff3eb0, member ptr = fffffffffff3eb8
instD.m_double: struct sizeof = 12, member sizeof = 8, member offset =
4, struct ptr = fffffffffff3ed0, member ptr = fffffffffff3ed4


2.2. Compilation and running on AIX 6.1 (compiler xlC V10.1)

> xlC -q64 -qwarn64 align1.cpp

AIX ep5512b 1 6 000497A2D900

IBM XL C/C++ for AIX, V10.1
Version: 10.01.0000.0000

instL.m_long : struct sizeof = 16, member sizeof = 8, member offset =
8, struct ptr = fffffffffff0790, member ptr = fffffffffff0798
instD.m_double: struct sizeof = 12, member sizeof = 8, member offset =
4, struct ptr = fffffffffff07b0, member ptr = fffffffffff07b4

2.3. Compilation and running on HP-UX v2 (compiler xlC aCC A.06.15)

HP-UX hpx418 B.11.23 U ia64 1139467043 unlimited-user license

aCC: HP C/aC++ B3910B A.06.15 [May 16 2007]

instL.m_long : struct sizeof = 16, member sizeof = 8, member offset =
8, struct ptr = 9ffffffffffec9e0, member ptr = 9ffffffffffec9e8
instD.m_double: struct sizeof = 16, member sizeof = 8, member offset =
8, struct ptr = 9ffffffffffec9f0, member ptr = 9ffffffffffec9f8


3. Analysis

We can see some problem on AIX compiler with m_double:
its sizeof = 8, but its offset = 4
and
its pointer is not aligned to 8 bytes

P.S. No problem with double-member on HP-UX compiler.

Alex Vinokur

Joerg

unread,
Apr 8, 2010, 4:02:27 AM4/8/10
to
> 3. Analysis
>
> We can see some problem on AIX compiler with m_double:
>   its sizeof = 8, but its offset = 4
>      and
>   its pointer is not aligned to 8 bytes

Hi,

When the double is not the first member, the alignment is 4. The AIX
ABI specifies it to be so.
This is because some old AIX compiler introduced this bug. All newer
compilers behave the same
to be backward compatible.


Jörg

Alex Vinokur

unread,
Apr 9, 2010, 1:02:49 AM4/9/10
to

"Joerg" <j_ri...@gmx.de> wrote in message
news:ff5e0ccd-2b74-4c14...@r1g2000yqj.googlegroups.com...

Thanks.

Does that affect performance of processing double-members?

Alex Vinokur

Joerg

unread,
Apr 9, 2010, 2:42:41 AM4/9/10
to
On 9 Apr., 07:02, "Alex Vinokur" <ale...@users.sourceforge.net> wrote:

> Does that affect performance of processing double-members?

Hi,

I haven't measured, so I can't tell you.
But I wouldn't be surprised if it does.

Jörg

Gary R. Hook

unread,
Apr 10, 2010, 3:57:15 PM4/10/10
to
On 4/9/2010 12:02 AM, Alex Vinokur wrote:
>
> Does that affect performance of processing double-members?

On AIX?

IIRC yes. You want doubles and long-longs to be double-word aligned.
I think you still get alignment exceptions when they're not.

Rule: put the member with the strictest alignment requirements first in
your structure.

0 new messages