Welcome

首页 / 软件开发 / C++ / Vdsp(bf561)中的浮点运算(9):long double和float的比较

Vdsp(bf561)中的浮点运算(9):long double和float的比较2010-02-01 csdn博客 快乐虾在默认情况下,vdsp认为double和float这两种类型是一样的,因此我们比较long double和float。

1.1 类型表示

下面是两种类型的数据表示:

 floatlong double
字节数48
符号位11
指数位数811
尾数位数2352
最小值1.1754943508222875E-38F2.2250738585072014E-308L
最大值3.4028234663852886E+38F1.797693134862315708E+308L
分辨率1.1920928955078125E-07F2.2204460492503131E-16L

1.2 正常情况下的运算效率

下表给出两种类型下做运算的效率比较,选择High performance

 floatlong double
加减运算132 cycle166 cycle
乘法运算92 cycle179 cycle
除法运算240 cycle1506 cycle

狂汗,这个long double做除法也太狠了点!

下表给出两种类型下做运算的效率比较,选择Strict IEEE:

 Floatlong double
加减运算310 cycle381 cycle
乘法运算274 cycle585 cycle
除法运算497 cycle1063 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的浮点除法似乎是个例外!