SSE And Visual Studio problem

timeflieslikeabanana
Posts: 5
Joined: Sun Oct 27, 2013 10:05 pm

SSE And Visual Studio problem

Post by timeflieslikeabanana »

Hi Bullet, I'm still stuck on this bug, and I have a bit more information now. The bug is triggered by the assignment operatore of btQuadWord (usually called via btQuaternion), and specifically is the _m128 assignment at fault. It only occurs while in release mode, and I have just confirmed that if I turn off the BT_USE_SSE define it goes away as well. The only problem is that I'd really love to have the fast library in my code! I'm on the edge of acceptable performance constantly as is, so I really didn't need this performance hit.

Anyone had problems with this sort of thing before?

To be clear, running on windows 7, and compiled on visual studio 2012. Amd Phenom(II), so 64 bit, although the code is being compiled in 32 bit.

Thanks!
User avatar
Erwin Coumans
Site Admin
Posts: 4221
Joined: Sun Jun 26, 2005 6:43 pm
Location: California, USA

Re: SSE And Visual Studio problem

Post by Erwin Coumans »

If you embed an 16-byte aligned variable as member of a class/struct, that requires this alignment because it is used for SIMD/SSE,
your class/struct needs to be 16 byte aligned too. In other words, add the alignment macro in your class.

Just see the btCollisionObject headerfile:
#include "LinearMath/btScalar.h"

ATTRIBUTE_ALIGNED16(class) btCollisionObject
{
...
public:
BT_DECLARE_ALIGNED_ALLOCATOR();

...

Alternatively, you can disable SSE/SIMD and suffer a bit of performance, or use the BT_DOUBLE_PRECISION build (it has SSE/SIMD disabled too).
Just edit the btScalar.h to disable SSE/SIMD.
timeflieslikeabanana
Posts: 5
Joined: Sun Oct 27, 2013 10:05 pm

Re: SSE And Visual Studio problem

Post by timeflieslikeabanana »

Erwin Coumans wrote:If you embed an 16-byte aligned variable as member of a class/struct, that requires this alignment because it is used for SIMD/SSE,
your class/struct needs to be 16 byte aligned too. In other words, add the alignment macro in your class.

Just see the btCollisionObject headerfile:
#include "LinearMath/btScalar.h"

ATTRIBUTE_ALIGNED16(class) btCollisionObject
{
...
public:
BT_DECLARE_ALIGNED_ALLOCATOR();

...

Alternatively, you can disable SSE/SIMD and suffer a bit of performance, or use the BT_DOUBLE_PRECISION build (it has SSE/SIMD disabled too).
Just edit the btScalar.h to disable SSE/SIMD.
I'm somewhat confused why this didn't cause immediate problems - this took six months of development to show up. Does this mean that _every_ class which has as a member function a pointer or object from the bt library needs to be aligned? That effectively means dozens in practice here I think. Thanks for your help! My last comment didn't get any traction, I think because it wasn't obvious that SSE was the problem to me yet. It just looked like a crash on assignment of a quaternion, which is totally different on the surface.