I'm trying to optimize a small piece of code using the built-in SSEs (I'm a complete newbie to this topic), but I'm a little fixated on using conditional expressions.
My source code:
unsigned long c; unsigned long constant = 0x12345678; unsigned long table[256]; int n, k; for( n = 0; n < 256; n++ ) { c = n; for( k = 0; k < 8; k++ ) { if( c & 1 ) c = constant ^ (c >> 1); else c >>= 1; } table[n] = c; }
The purpose of this code is to compute the crc table (a constant can be any polynomial, it does not matter here),
I suppose my optimized code would be something like this:
__m128 x; __m128 y; __m128 *table; x = _mm_set_ps(3, 2, 1, 0); y = _mm_set_ps(3, 2, 1, 0); //offset for incrementation offset = _mm_set1_ps(4); for( n = 0; n < 64; n++ ) { y = x; for( k = 0; k < 8; k++ ) { //if do something with y //else do something with y } table[n] = y; x = _mm_add_epi32 (x, offset); }
I don't know how to go through the if-else statement, but I suspect there is a smart trick. Does anyone know how to do this?
(Besides this, my optimization is probably pretty bad - any advice or corrections on it will be considered with the greatest sympathy)
source share