d3dxvector and intel compiler agressive inlining bug

d3dxvector and intel compiler agressive inlining bug

Hi,I'm usingIntel C++ Composer XE 2011 for WindowsCode 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 InstructionsProblem only occurs in ReleaseI was adding ICC support for our product ( BigWorld middleware ) and found an interesting problem.Basically Microsoft DirectX 9 defines 3d vector like thisclass 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.inllater on our code access vector components using [] operatorlike thisvoid 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 thisoperator 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 itWhat'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

1 post / 0 new
For more complete information about compiler optimizations, see our Optimization Notice.