Lor*_*one 5 c floating-point gcc compiler-optimization
我一直认为使用long double
数据类型的速度大约是使用double
时计算速度的两倍-funsafe-math-optimizations
.我想对此有所了解,因为80位格式已经弃用了很长时间,或者我可能正在做一些非常愚蠢的double
数据类型.编译器是g ++ 4.8.2,目标是x86_64(所以如果我不使用,gcc会更喜欢SSE2 long double
).
我的代码或多或少像这样(伪代码):
//x is an array of floating point numbers
for i -> x.size
accumulator = 0
for k -> kmax
accumulator += A[k]*(B[k]*cos(C*k*x[i]) - D[k]*sin(C*k*x[i]));
x[i] += F*accumulator;
if(x[i] >= 1/2) x[i] -= integer(x[i]+1/2);
else if(x[i] < -1/2) x[i] -= integer(x[i]-1/2);
Run Code Online (Sandbox Code Playgroud)
A
,, B
...是一些预先计算的数组/常量.
加速似乎与高速缓存行问题无关,因为如果我使用OpenMP并行化外部for循环,我会获得相同的相对加速.
编辑:我纠正了伪代码:注意cos
并且sin
有相同的参数,这最终是加速的原因(参见gsg的答案和评论).
归档时间: |
|
查看次数: |
369 次 |
最近记录: |