Hello,
Attending to the following code (C++):
class __declspec(align(16)) Point
{
public:
__m128 m;
float v[4];
};
class __declspec(align(16)) CPS
{
public:
int a;
Point b;
};
int main()
{
cout << sizeof(Point) << endl;
cout << sizeof(CPS) << endl;
CPS rrr[2];
cout << &rrr[0] << endl;
cout << &rrr[0].b.m << endl;
cout << &rrr[1] << endl;
cout << &rrr[1].b.m << endl;
return 0;
}
Standar output:
16
24
0x0012FF20
0x0012FF28
0x0012FF38
0x0012FF40
Im using the 6.0 Version of the Intel C++ Compiler. Why
does the size of class "CPS" equal to 24? The compiler, is integrated with 6.0 Version of Microsoft Visual Studio
under Windows XP Profesional. We use debug mode options for Microsoft Visual.
The "rrr" array, disaligns the __m128 member of the class "Point". That is why, the size of the class CPS isnt 16 multiple. However, when we run the same code, under linux, and the linux version for the Intel C++ Compiler 6.0, the size of the class CPS equals to 32 so the arrays will align the __m128 members of "Point".
We are suspicious of "__declspec(align(16))", we think that it doesnt work properly. What is the matter with the alignement??? We need to align to 16 byte boundary the __m128 members, in order to use the SSE instructions.
So, how can I align that members, in all situations?
Thanks in advance,
ruben
__declspec(align(16))
For more complete information about compiler optimizations, see our Optimization Notice.


