Vdsp(bf561)中的浮点运算(9):long double和float的比较

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

时间: 2024-08-04 12:04:35

Vdsp(bf561)中的浮点运算(9):long double和float的比较的相关文章

Vdsp(bf561)中的浮点运算(8):float除法运算

1.1 Vdsp对float除法运算的处理 在vdsp下,可以很简单地用: float fdiv(float x, float y) { float r = x / y; return r; } 来完成浮点除法运算,编译器自动将里面的乘法操作转换为___float32_div的函数调用,这个函数的调用实现在libdsp/fpdiv.asm中,在这个文件的开头说明了这个函数的用法: /*********************************************************

Vdsp(bf561)中的浮点运算(7):float乘法运算

1.1 Vdsp对float乘法运算的处理 在vdsp下,可以很简单地用: float mul (float x, float y) { float r = x * y; return r; } 来完成浮点乘法运算,编译器自动将里面的乘法操作转换为___float32_mul的函数调用,这个函数的调用实现在libdsp/fpmult.asm中,在这个文件的开头说明了这个函数的用法: /********************************************************

Vdsp(bf561)中的浮点运算(6):float加减运算

一直以为float加减运算很简单,无非就是将之转换为__float32_add和__float32_sub这两个函数调用而已,然后用软件模拟进行加减运算.但真的如此简单吗?当一些让人不太舒服的条件出现的时候,还是如此吗? 1.1 Vdsp对float加减运算的处理 在vdsp下,可以很简单地用: float add(float x, float y) { float r = x + y; return r; } float sub(float x, float y) { float r = x

Vdsp(bf561)中的浮点运算(5):float类型表示总结

1.1 float的疑问 写一行很简单的C代码: float a = 1234.56; 用vdsp编译后的汇编代码为: R0 = 20972 ( X ) ; R0.H = 17562 ; [ FP + 0x10 ] = R0 ; 有点看不懂,呵呵,R0的值转换为十六进制就是0x449A51EC.根据vdsp文档的说法,其单精度浮点数格式为: 浮点数计算公式: 将0x449A51EC转换为二进制: 0100 0100 1001 1010 0101 0001 1110 1100 可得: Sign =

Vdsp(bf561)中的浮点运算(2):float的疑问

写一行很简单的C代码: float a = 1234.56; 用vdsp编译后的汇编代码为: R0 = 20972 ( X ) ; R0.H = 17562 ; [ FP + 0x10 ] = R0 ; 有点看不懂,呵呵,R0的值转换为十六进制就是0x449A51EC.根据vdsp文档的说法,其单精度浮点数格式为: 浮点数计算公式: 将0x449A51EC转换为二进制: 0100 0100 1001 1010 0101 0001 1110 1100 可得: Sign = 0 Mantissa =

Vdsp(bf561)中的浮点运算(15):vdsp库的一个BUG

在写完fract除法之后,偶然发现在vdsp的一个头文件中提供了fract16除法运算的函数,这个文件就是VisualDSP 5.0\Blackfin\include\fract_math.h: /* Produces a result which is the fractional division of f1 by f2. Not a builtin * as written in C code. */ #pragma inline #pragma always_inline static

Vdsp(bf561)中的浮点运算(1):文档的说法

在vdsp提供的<VisualDSP++ 5.0 C/C++ Compiler and Library Manual for Blackfin Processors Revision 5.1, August 2008>中列出了vdsp支持的所有数据类型,其中与浮点有点的类型有: Type Bit Size Number Representation sizeof returns double 32 bits 32-bit IEEE single-precision 4 float 32 bit

Vdsp(bf561)中的浮点运算(16):fract2x16类型

由于BF561内部带有两个16位的MAC,因此它将可以在一个周期内进行两个fract16类型的运算. 为适应这种特性,vdsp引入了一个称之为fract2x16的类型.它其实是定义为一个int类型的整数,但是其实际意义却是要用高低16位分别来表示两个fract16类型. typedef int _raw32; typedef _raw32 raw2x16; typedef raw2x16 fract2x16; 要查看fract2x16类型的值还是只能通过data register窗口,手动将类型

Vdsp(bf561)中的浮点运算(11):fract16与float的转换

vdsp提供了两个函数用以实现fract16与float之间的相互转换: fract16 float_to_fr16 (float _x); float fr16_to_float (fract16 _x); 看看这两个转换函数到底做了什么. 1.1 float_to_fr16 这个函数的原始代码在Blackfin\lib\src\libc\runtime\fl2fr.asm中,先看看它的注释: /*************************************************