Skip to main content
GameDev.net gamedev.net

PRO Tired of ads? Read GameDev.net ad-free and help keep the community independent with GameDev Pro — $3/month.

Performance testing with bit operations, SSE2 and asm

Performance testing with bit operations, SSE2 and asm

Paul C Skertich
Paul C Skertich
SIC Games' Journal · · 1 min read
3,608 7
Today I figure I sit down and see how SSE2 is benefitial to a game. I don't come fromt a strong background knowledge of ASM code. However, I found it fascinating to say the least! I can understand the headaches that go into ASM but if you can get around knowing some ASM then you're good to go on SSE2 instructions.

As I already aknowledged from previous issues with DIrectX Math is the vectors have to be 16 bit aligned or there will be access violations exceptions thrown about. I recently had issues like this when I changed the camera class.

On my performance test I tested out a simple function that would return the minimal of two floating points.inline float _b_min(float a, float b) { return (a < b ? a : b);}inline float _a_nin(float a, float b) { float result = 0.0f; __asm { mov eax,a mov ebx,b cmp eax,ebx mov [result], eax }return result;}
the function _a_min was a bit faster than _b_min. _a_min gave around 900 microseconds.
_b_min function gave over 1 millisecond time elapsed from the high resolution timer.

The sse2 min function gave me around 0.003 milliseconds.inline float *_sse2_min(float a, float b) { __m128 _a = _mm_set_ps1(a); //-- set _a to the floating point a; __m128 _b = _mm_set_ps1(b); //-- set _b to floating point b; __m128 c = _mm_min_ps(_a,_b); //-- return in C the minimal of _a,_b; float *result = (float*)_aligned_malloc(sizeof(float), sizeof(float)); _mm_store_ps(result, c); //-- store the result float* result; return result;}
my question is for whomever the reader is - why is SSE2 and bit operator maniupation a bit slower than ASM or does it not matter? Possible SSE2 is better with bigger data than just comparing minimal of floating points?

Discussion

Loading comments...