在默认情况下,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的浮点除法似乎是个例外!