Sony Computer Entertainment Inc. contributed Vector Math library and SIMD math library as open source under the BSD license. Bullet physics SDK will be the main repository. Vector Math was previously only available to licensed PlayStation 3 developers.
Vector Math provides linear algebra useful for 3D graphics (vector, matrix, quaternion). SIMD implementations for PowerPC PPU, Cell SPU and x86 SSE are available, next to a portable generic scalar version. You can read the overview document online. Reference manuals and documentation is included in the doc folder.
Repository:
http://bullet.svn.sourceforge.net/viewv ... thlibrary/
SIMD math library provides 4way SIMD implementations of common math functions like cos4f, sin4f, floor4f, fabs4f etc. Vector Math depends on this lower level C library on PPU and SPU.
Repository:
http://bullet.svn.sourceforge.net/viewv ... thlibrary/
Both libraries are included in the Bullet distribution under the Bullet/Extras folder, available from Bullet 2.55. Download Bullet physics SDK.
Feedback, patches for Vector Math and SIMD math library are welcome in this forum.
Thanks,
Erwin
Sony Vector Math library and SIMD math library open sourced

 Posts: 16
 Joined: Mon Oct 28, 2013 12:18 am
Re: Sony Vector Math library and SIMD math library open sourced
That's a very good news for everybody looking for a well written math lib, especially the SoA one which is quite rare.
Anyway, it seems to me that I'm facing an issue:
 The sse implementation of boolInVec uses for the == operator the _mm_cmpeq_ps intrinsic (vectormathlibrary\include\vectormath\SSE\cpp\boolInVec.h line 207).
 The __m128 argument stores either 0xfffffff or 0x0 to reflect a boolean value (respectively true or false). See constructor boolInVec::boolInVec(bool scalar) line 139.
 As seen as a float value, 0xfffffff is a NAN.
 According to sse instruction specifications (that I found here : http://www.cs.cmu.edu/~410/doc/intelisr.pdf), _mm_cmpeq_ps always returns false when comparing NANs.
Thus comparing 2 boolInVec that are initialized to "true" with the == operator returns false, which is not the expected result.
I've experimented this behavior with those 3 lines of code:
You'll notice that c equals 0x0 instead of the expected 0xffffffff.
Am I wrong?
Guillaume
Anyway, it seems to me that I'm facing an issue:
 The sse implementation of boolInVec uses for the == operator the _mm_cmpeq_ps intrinsic (vectormathlibrary\include\vectormath\SSE\cpp\boolInVec.h line 207).
 The __m128 argument stores either 0xfffffff or 0x0 to reflect a boolean value (respectively true or false). See constructor boolInVec::boolInVec(bool scalar) line 139.
 As seen as a float value, 0xfffffff is a NAN.
 According to sse instruction specifications (that I found here : http://www.cs.cmu.edu/~410/doc/intelisr.pdf), _mm_cmpeq_ps always returns false when comparing NANs.
Thus comparing 2 boolInVec that are initialized to "true" with the == operator returns false, which is not the expected result.
I've experimented this behavior with those 3 lines of code:
Code: Select all
int i = 0xffffffff;
__m128 a = _mm_set1_ps(*(float*)&i);
__m128 c = _mm_cmpeq_ps(a, a);
Am I wrong?
Guillaume

 Posts: 2
 Joined: Thu Sep 18, 2008 1:44 am
Re: Sony Vector Math library and SIMD math library open sourced
When you compare two numbers in SIMD, you should be always aware of the type of entities you compare. VMX and modern SSE allows you to treat register contents as integers, masks or floats freely, but it doesn't mean you can magically add two numbers when they're float and int. Or compare two masks as if they were floats.
cmpeq_ps will compare two floatingpoint numbers. If you have masks in your registers, it is logically a wrong operation to perform. Comparing masks bitwise would be a NOTXOR operation, for example.
cmpeq_ps will compare two floatingpoint numbers. If you have masks in your registers, it is logically a wrong operation to perform. Comparing masks bitwise would be a NOTXOR operation, for example.
Re: Sony Vector Math library and SIMD math library open sour
Hi,
I just discovered the lib (yes, 3 years later ), and I read the code and found things like this:
(somewhere in scalar/cpp/mat_aos.h, but ti's the same in all implementaiton)
Why do the getter getCol creates a copy of a member variable ? Why can't we return a const reference like this:
Because here, each time I want to access 1 element of a matrix, I do a Vector4 copy... not very efficient.
But maybe I'm missing a good reason for this.
Anyone can clarify this for me ?
Thanks again for making Bullet Open Source, I learn a lot.
I just discovered the lib (yes, 3 years later ), and I read the code and found things like this:
(somewhere in scalar/cpp/mat_aos.h, but ti's the same in all implementaiton)
Code: Select all
inline float Matrix4::getElem( int col, int row ) const
{
return this>getCol( col ).getElem( row );
}
inline const Vector4 Matrix4::getCol( int col ) const
{
return *(&mCol0 + col);
}
Code: Select all
inline const Vector4 & Matrix4::getCol( int col ) const
{
return *(&mCol0 + col);
}
But maybe I'm missing a good reason for this.
Anyone can clarify this for me ?
Thanks again for making Bullet Open Source, I learn a lot.

 Posts: 10
 Joined: Thu May 20, 2010 10:45 pm
Re: Sony Vector Math library and SIMD math library open sour
If the architecture, abi, compiler, and math library all cooperate, then returning a vector by value is cheap  it goes in a register. Also, the less aliasing means more opportunities for the compiler to optimize.
It's not OK for the api to change between the scalar and simd implementations (the change in semantics is subtle but real). vectormath is really not a great choice if you're not going to use a simd implementation.
It's not OK for the api to change between the scalar and simd implementations (the change in semantics is subtle but real). vectormath is really not a great choice if you're not going to use a simd implementation.
Re: Sony Vector Math library and SIMD math library open sour
Hi,
I ran some quick SSE tests with a naive c++ implementation, some intrisics on simple float arrays and the sony library. It appears that the prefetch and the cache have a huge impact on the performance. For example, my compiler seems to manage cache optimization on the naive c++ implementation which give better performances than Vectormath::Aos.
Is there any plans to add prefetch call to the library ?
Thanks.
I ran some quick SSE tests with a naive c++ implementation, some intrisics on simple float arrays and the sony library. It appears that the prefetch and the cache have a huge impact on the performance. For example, my compiler seems to manage cache optimization on the naive c++ implementation which give better performances than Vectormath::Aos.
Is there any plans to add prefetch call to the library ?
Thanks.