在默認情況下,vdsp認為double和float這兩種類型是一樣的,因此我們比較long double和float。
1.1 類型表示
下面是兩種類型的數據表示:
float long double 字節數 4 8 符號位 1 1 指數位數 8 11 尾數位數 23 52 最小值 1.1754943508222875E-38F 2.2250738585072014E-308L 最大值 3.4028234663852886E+38F 1.797693134862315708E+308L 分辨率 1.1920928955078125E-07F 2.2204460492503131E-16L
1.2 正常情況下的運算效率
下表給出兩種類型下做運算的效率比較,選擇High performance
float long double 加減運算 132 cycle 166 cycle 乘法運算 92 cycle 179 cycle 除法運算 240 cycle 1506 cycle
狂汗,這個long double做除法也太狠了點!
下表給出兩種類型下做運算的效率比較,選擇Strict IEEE:
Float long double 加減運算 310 cycle 381 cycle 乘法運算 274 cycle 585 cycle 除法運算 497 cycle 1063 cycle
這裡有一個值顯得很奇怪,在選擇了Strict IEEE選項之後,long double進行除法運算反而變快了!
在vdsp的文檔裡這樣解釋這兩種不同的選項:
The -fast-fp (fast floating point) switch directs the compiler to link with the high-speed floating-point emulation library. This library relaxes some of the IEEE floating-point standard’s rules for checking inputs against not-a-number (NaN) and denormalized numbers to improve performance. This switch is enabled by default.
The -ieee-fp (slower floating point) switch directs the compiler to link with the fully-compliant floating-point emulation library. This library obeys all of the IEEE floating-point standard’s rules, and incurs a performance penalty when compared with the default floating-point emulation library.
照說使用Strict IEEE選項之後應該所有的計算都變慢,但long double的浮點除法似乎是個例外!