Intel® C++ Compiler
Community support and assistance for creating C++ code that runs on platforms based on Intel® processors.
7956 Discussions

d3dxvector and intel compiler agressive inlining bug

alexander_radchenko
300 Views
Hi,
I'm usingIntel C++ Composer XE 2011 for Windows
Code generation options are:
"Floating point model" set to"fp:fast" or "fp:fast = 2".
"Enable Enhanced Instuction Set" set to SSE, SSE2 or Intel Advanced Vector Instructions
Problem only occurs in Release
I was adding ICC support for our product ( BigWorld middleware ) and found an interesting problem.
Basically Microsoft DirectX 9 defines 3d vector like this
class Vector3
{
public:
float x, y, z;
Vector3() {}
operator float*() { return &x; }
}
It's far more complicated than this, I've simplified it to make it readable.
You can download DirectX sdk and look at d3dx9math.h and d3dxmath.inl
later on our code access vector components using [] operator
like this
void func()
{
Vector3 v;
v[0] = 0.0f;
v[1] = 0.0f;
v[2] = 0.0f;
// do some complex calculations accessing vector components by index
// eventually acessing v[2] returns rubbish
}
Problem only occurs in Release if SSE optimisation is enabled.
Looking into assembly it looks like compiler was inlining as much as it can and at some point acessing second and third component of vector failed.
C++ standard 9.2.12 Class members states
"Implementation alignment requirements might cause two adjacent members not to be allocated immediately after each other"
I assume this is the reason for this bug, I managed to "fix" it by overwriting float* operator like this
operator float*() { return reinterpret_cast(this); }
But it doesn't feel like a proper fix.
Btw, Visual Studio C++ compiler works fine and doesn't produce buggy code.
Which makes me think this could be a bug in the compiler.
Can you confirm that this is the intended behaviour and DirectX code contains a bug in it
What's the best workaround ?
I have a small .cpp file which reproduces this bug, if someone is interested to take a look at it let me know.
Cheers,
Alexander
0 Kudos
0 Replies
Reply