我试图在函数中使用sse simd指令来评估值。
double integrate (double from, double to,double* counter)
{
__m128d sum=_mm_setzero_pd();
__m128d val=_mm_setzero_pd();
__m128d width;
__m128d fr=_mm_set1_pd(from);
__m128d t=_mm_set1_pd(to);
__m128d one=_mm_set1_pd(1.0);
__m128d a,b,c,step;
double result=0,i=0;
width=_mm_set1_pd((to-from)/1000);
while(i<1000){
step = _mm_loadu_pd(&counter[i]);
a = _mm_mul_pd(step,width);
b = _mm_add_pd(fr,a);
val = _mm_div_pd(one,b);
c = _mm_mul_pd(val,width);
sum = _mm_mul_pd(sum,c);
i=i+2;
}
for(int i=0; i<1000; i++) {
result += sum[i];
}
return result;
}
它需要3个参数,其中两个是double,其中一个是用于将数组传递给funtion的双指针。我尝试转换的代码就是这个;
double integrate (double from, double to)
{
double sum=0,val=0,width;
int i;
width=(to-from)/1000;
for(i=1;i<1000;i++){
val=1/(from+(i*width));
sum=sum+(val*width);
}
return sum;
}
代码评估一个值,但它并不像我预期的那样。据我所知,我真正的问题在于这个部分;
step = _mm_loadu_pd(&counter[i]);
我想要做的是每次将名为counter(保持数字从0到999)的数字传递到步骤向量2的数字(例如r0:0 r1:1,r0:2,r1:3)并进行评估其他的东西。我做错了什么?
答案 0 :(得分:1)
变化:
step = _mm_loadu_pd(&counter[i]);
为:
step = _mm_set1_pd(counter[i]);