3 回答
TA貢獻1840條經驗 獲得超5個贊
00.1
int main() {
double start = omp_get_wtime();
const float x[16]={1.1,1.2,1.3,1.4,1.5,1.6,1.7,1.8,1.9,2.0,2.1,2.2,2.3,2.4,2.5,2.6};
const float z[16]={1.123,1.234,1.345,156.467,1.578,1.689,1.790,1.812,1.923,2.034,2.145,2.256,2.367,2.478,2.589,2.690};
float y[16];
for(int i=0;i<16;i++)
{
y[i]=x[i];
}
for(int j=0;j<9000000;j++)
{
for(int i=0;i<16;i++)
{
y[i]*=x[i];
y[i]/=z[i];#ifdef FLOATING
y[i]=y[i]+0.1f;
y[i]=y[i]-0.1f;#else
y[i]=y[i]+0;
y[i]=y[i]-0;#endif
if (j > 10000)
cout << y[i] << " ";
}
if (j > 10000)
cout << endl;
}
double end = omp_get_wtime();
cout << end - start << endl;
system("pause");
return 0;}產出:
#define FLOATING1.78814e-007 1.3411e-007 1.04308e-007 0 7.45058e-008 6.70552e-008 6.70552e-008 5.58794e-007 3.05474e-007 2.16067e-007 1.71363e-007 1.49012e-007 1.2666e-007 1.11759e-007 1.04308e-007 1.04308e-0071.78814e-007 1.3411e-007 1.04308e-007 0 7.45058e-008 6.70552e-008 6.70552e-008 5.58794e-007 3.05474e-007 2.16067e-007 1.71363e-007 1.49012e-007 1.2666e-007 1.11759e-007 1.04308e-007 1.04308e-007//#define FLOATING6.30584e-044 3.92364e-044 3.08286e-044 0 1.82169e-044 1.54143e-044 2.10195e-044 2.46842e-029 7.56701e-044 4.06377e-044 3.92364e-044 3.22299e-044 3.08286e-044 2.66247e-044 2.66247e-044 2.24208e-0446.30584e-044 3.92364e-044 3.08286e-044 0 1.82169e-044 1.54143e-044 2.10195e-044 2.45208e-029 7.56701e-044 4.06377e-044 3.92364e-044 3.22299e-044 3.08286e-044 2.66247e-044 2.66247e-044 2.24208e-044
_MM_SET_FLUSH_ZERO_MODE(_MM_FLUSH_ZERO_ON);
0
計時:核心i7 [email protected] GHz:
// Don't flush denormals to zero.0.1f: 0.5640670 : 26.7669// Flush denormals to zero.0.1f: 0.5871170 : 0.341406
00.1f
TA貢獻1906條經驗 獲得超10個贊
可能在GCC的環境下不起作用: // Requires #include <fenv.h>fesetenv(FE_DFL_DISABLE_SSE_DENORMS_ENV);
可能無法在某些VisualStudio環境中工作: 1// Requires #include <xmmintrin.h>_mm_setcsr( _mm_getcsr() | (1<<15) | (1<<6) ); // Does both FTZ and DAZ bits. You can also use just hex value 0x8040 to do both. // You might also want to use the underflow mask (1<<11)
在GCC和VisualStudio中都可以使用: // Requires #include <xmmintrin.h>// Requires #include <pmmintrin.h>_MM_SET_FLUSH_ZERO_MODE (_MM_FLUSH_ZERO_ON);_MM_SET_DENORMALS_ZERO_MODE(_MM_DENORMALS_ZERO_ON);
Intel編譯器可以在現代的Intel CPU上默認禁用非正常值。 這里有更多的細節 編譯器開關 -ffast-math,-msse或 -mfpmath=sse將禁用取消,并使其他一些事情更快,但不幸的是,也做了許多其他的近似,可能破壞您的代碼。仔細測試!與VisualStudio編譯器的快速數學等價的是 /fp:fast但我還沒能證實這是否也是禁用的。 1
- 3 回答
- 0 關注
- 583 瀏覽
添加回答
舉報
