Sony Vector Math library and SIMD math library open sourced

Open source Bullet Physics SDK release information
Post Reply
bullet_team
Posts: 16
Joined: Mon Oct 28, 2013 12:18 am

Sony Vector Math library and SIMD math library open sourced

Post by bullet_team » Sat Jul 28, 2007 1:19 am

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 on-line. Reference manuals and documentation is included in the doc folder.
Repository:
http://bullet.svn.sourceforge.net/viewv ... thlibrary/

SIMD math library provides 4-way 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

lib_team
Posts: 1
Joined: Wed Mar 04, 2009 2:50 pm

Re: Sony Vector Math library and SIMD math library open sourced

Post by lib_team » Wed Mar 04, 2009 4:08 pm

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/intel-isr.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);
You'll notice that c equals 0x0 instead of the expected 0xffffffff.

Am I wrong?

Guillaume

migdalskiy
Posts: 2
Joined: Thu Sep 18, 2008 1:44 am

Re: Sony Vector Math library and SIMD math library open sourced

Post by migdalskiy » Thu Jun 04, 2009 12:05 am

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 floating-point numbers. If you have masks in your registers, it is logically a wrong operation to perform. Comparing masks bit-wise would be a NOT-XOR operation, for example.

Guillaume
Posts: 1
Joined: Tue Aug 31, 2010 1:43 pm

Re: Sony Vector Math library and SIMD math library open sour

Post by Guillaume » Tue Aug 31, 2010 2:00 pm

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)

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);
}
Why do the getter getCol creates a copy of a member variable ? Why can't we return a const reference like this:

Code: Select all

inline const Vector4 & Matrix4::getCol( int col ) const
{
    return *(&mCol0 + col);
}
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.

paul.dubois
Posts: 10
Joined: Thu May 20, 2010 10:45 pm

Re: Sony Vector Math library and SIMD math library open sour

Post by paul.dubois » Thu Oct 14, 2010 3:06 am

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.

kiwilex
Posts: 1
Joined: Thu Oct 06, 2011 8:25 am
Location: France

Re: Sony Vector Math library and SIMD math library open sour

Post by kiwilex » Thu Oct 06, 2011 8:34 am

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.

Post Reply