我有以下代码来找到最大值
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;
}
}
我尝试使用 SSE3 内在函数对其进行矢量化,但我对应该如何进行比较感到有点震惊。
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
}
任何人都可以给出一些想法。