I have the following code to find the maximum value
int length = 2000;
float *data;
// data is allocated and initialized
float max = 0.0;
for(int i = 0; i < length; i++)
{
if(data[i] > max)
{
max = data;
}
}
I tried vectorizing it by using SSE3 intrinsics, but I am kind of struck on how I should do the comparison.
int length = 2000;
float *data;
// data is allocated and initialized
float max = 0.0;
// for time being just assume that length is always mod 4
for(int i = 0; i < length; i+=4)
{
__m128 a = _mm_loadu_ps(data[i]);
__m128 b = _mm_load1_ps(max);
__m128 gt = _mm_cmpgt_ps(a,b);
// Kinda of struck on what to do next
}
Can anyone give some idea on it.