`
xiaoer_1982
  • 浏览: 1817459 次
  • 性别: Icon_minigender_2
  • 来自: 北京
文章分类
社区版块
存档分类
最新评论

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

阅读更多

快乐虾

http://blog.csdn.net/lights_joy/

lights@hb165.com

本文适用于

ADSP-BF561

Visual DSP++ 5.0 (update 6)

Vdsp dual processor simulate

欢迎转载,但请保留作者信息

1.1 Vdspfloat除法运算的处理

vdsp下,可以很简单地用:

float fdiv(float x, float y)

{

float r = x / y;

return r;

}

来完成浮点除法运算,编译器自动将里面的乘法操作转换为___float32_div的函数调用,这个函数的调用实现在libdsp/fpdiv.asm中,在这个文件的开头说明了这个函数的用法:

/******************************************************************************

Copyright(c) 2000-2008 Analog Devices Inc. IPDC BANGALORE, India.

All rights reserved

******************************************************************************

File Name : fpdiv32.asm

Module Name : floating point division

Label name : __float32_div

Description : This function computes single precision signed floating point

division. Implemention is based on the algorithm mentioned in

the reference. Some more conditions are added in the present

algorithm to take care of various testcases.

Registers used:

Operands in R0 & R1

R0- Numerator(X),R1- Denominator(Y)

R2 - R7 and P1

******************************************************************************

Special cases :

1) If(X == 0) Return 0.0 or -0.0 depending on sign of X,Y

2) If(Y == 0) Return INF or -INF depending on sign of X,Y

3) If(X == Y) Return 1.0 or -1.0 depending on sign of X,Y

4) If(Y == 1) Return X or -X depending on sign of X,Y

5) Underflow : If(EXP(X) - EXP(Y) < -149),return 0,

6) Overflow : If((EXP(X) - EXP(Y) + 126) > 254), return NAN or -NAN

depending on sign of X,Y

Reference : Computer Architecture a Quantitative Approach

second edition

by John L Hennessy and David Patterson

!!NOTE- Uses non-standard clobber set in compiler:

DefaultClobMinusPABIMandLoop1Regs

Remember to change the #pragma regs_clobbered in fpdiv.c in softfloat if you

change this clobber set

********************************************************************************/

1.2 xnan或者inf

看代码:

// First check if either operand is a NaN or inf, and handle certain

// identities with these values

R7 = (MAXBIASEXP+1) (Z);

CC = R6 == R7;

IF CC JUMP .HANDLE_NAN_INF_X;

……………

.HANDLE_NAN_INF_X:

// Return a NaN unless X is inf and Y is a valid number including 0, in

// which case return inf (signed appropriately)

CC = R5 < R7; // if y is a valid number

R6 = R0 << 9; // and if x is inf zero significand means X=inf

CC &= AZ;

IF CC JUMP .RET_INF (BP); // Return inf

// (predict branch to avoid 05-00-0428)

.RET_NAN:

R0 = -1; // Otherwise return a NaN

(R7:4)=[SP++]; // Pop R7-R4 from stack

RTS;

l xinfy为一个合法的浮点数

返回inf

fdiv(inf, 0) = infCYCLE48

l 其它

返回nan

CYCLE50

1.3 ynan或者inf

看代码:

CC = R5 == R7;

IF CC JUMP .HANDLE_NAN_INF_Y;

…………….

.HANDLE_NAN_INF_Y:

// Return NaN for all cases apart from 0/inf=0

CC = R0 == 0; // x == 0

R7 = R1 << 9; // and y == inf

CC &= AZ;

IF !CC JUMP .RET_NAN;

R0 = 0;

JUMP .SIGN_AND_RETURN;

.DIV_BY_ZERO:

// Return inf unless 0/0 in which case we return NaN.

CC = R0 == 0;

if CC JUMP .RET_NAN;

//else fallthrough - return inf

.RET_INF:

R0 = 0x7F8 (Z); // Infinity.

R0 <<= 20;

……………….

下面是计算结果:

表达式

结果

CYCLE

0 / inf

0

50

0 / nan

nan

52

inf / inf

nan

50

1.4 y0

看代码:

// Handle identities where neither operand is a NaN or inf

CC = R1 == 0; // If X/0, return inf (or NaN if X=0)

IF CC JUMP .DIV_BY_ZERO;

……………

.DIV_BY_ZERO:

// Return inf unless 0/0 in which case we return NaN.

CC = R0 == 0;

if CC JUMP .RET_NAN;

//else fallthrough - return inf

.RET_INF:

R0 = 0x7F8 (Z); // Infinity.

R0 <<= 20;

.SIGN_AND_RETURN:

R0 = R0 | R3; // R3.31 contains the sign bit needed.

(R7:4)=[SP++]; // Pop R7-R4 from stack

RTS;

l x为零

0 / 0 = NAN

CYCLE = 52

l x不为零

任意合法浮点数 / 0 = inf

CYCLE = 46

1.5 x0

看代码:

CC = R0 == 0; // IF 0/Y, return 0

IF CC JUMP .SIGN_AND_RETURN;

………

.SIGN_AND_RETURN:

R0 = R0 | R3; // R3.31 contains the sign bit needed.

(R7:4)=[SP++]; // Pop R7-R4 from stack

RTS;

直接返回0,所用的CYCLE44

1.6 x == y

看代码

CC = R0 == R1; // If X/X, return +/- 1.

IF CC R0 = R2;

IF CC JUMP .SIGN_AND_RETURN;

…….

.SIGN_AND_RETURN:

R0 = R0 | R3; // R3.31 contains the sign bit needed.

(R7:4)=[SP++]; // Pop R7-R4 from stack

RTS;

注意,这里的等是除了符号位之外,其十六进制表示的值完全相等!

直接返回1或者-1,所用的CYCLE48

1.7 向上溢出

当一个大数除以一个小数,将发生向上溢出,这个时候的返回值是inf,而不是说明中的nan,想来应该是写前面那段注释时的失误。

比如

1e30 / 1e-30 = inf

此时的CYCLE值为59

1.8 正常计算

在正常计算一个浮点除法时,所用的CYCLE值为240,这是最慢的一个计算!

1.9 向下溢出

在代码说明里给出的下溢条件是

(EXP(X) - EXP(Y) + 126) > 254

此时返回0,所用的CYCYLE243

2 参考资料

Vdsp(bf561)中的浮点运算(7):float乘法运算(2009-8-13)

Vdsp(bf561)中的浮点运算(6):float加减运算(2009-8-13)

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

Vdsp(bf561)中的浮点运算(4):FLT_MAX(2009-8-12)

Vdsp(bf561)中的浮点运算(3):FLT_MIN(2008-12-19)

Vdsp(bf561)中的浮点运算(2):float的疑问(2008-12-18)

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

分享到:
评论

相关推荐

    u-boot-1.1.6 for vdsp(bf561)

    这是将u-boot移植到VDSP的工程文件,支持的CPU为bf561,支持NandFlash和NorFlash,支持串口下载,不支持网络功能。

    uclinux-2008r1到vdsp5(bf561)的移植记录_v0.1

    这份文档记录了在vdsp5下移植bfin-uclinux-2008r1-rc8内核的过程。 适用于ADSP-BF561。

    u-boot-1.1.6-2008R1到vdsp5(bf561)的移植记录_v0.1

    这份文档记录了将u-boot-1.1.6移植到VDSP5下编译的过程。 所用的DSP为bf561,对其它blackfin系列的DSP也有一定参考意义。 欢迎转载,但请保留作者信息,谢谢!

    uboot_bf537_vdsp

    在VDSP++上面,编译的UBOOT_BF537,这个文件有bug,修改后的在我的另外一个资源里面

    uboot_bf537_VDSP5.0++

    这是在VDSP5.0++下面编译成功的uboot,支持的命令 base - print or set address offset bootm - boot application image from memory cmp - memory compare cp - memory copy crc32 - checksum calculation erase -...

    vdsp查表法

    vdsp C语言编程 正弦函数查表法,专门运用于vdsp中。

    编译器VDSP_v0.1

    使用Visual DSP 5.0的一点心得。 使用ADSP-BF561。 仅供参考。

    uboot_bf537_VDSP++5.0

    uboot1.16版本,在VDSP++5.0环境下编译,适合bf537,实现了uboot的大部分的命令,功能齐全

    VDSP软件说明

    VDSP软件说明。对于visual dsp++软件的介绍,以及如何创建工程等的介绍

    uclinux-2.6 for vdsp4.5

    这是将uclinux-2.6 for bf561的内核移植到Visual DSP 4.5下的工程文件。由于csdn空间限制,删除了Documentation及doj,dlb等中间文件或者无关的内容,请先在http://blackfin.uclinux.org/下载2.6.19.3-ADI-2007R1.1-...

    uboot1.60429.rar_uboot bf561

    本源码是uboot在bf537芯片上的移植,它是在vdsp++5.0环境下编译的,支持uboot绝大部分常用的命令,方便剪裁

    Intro_to_VDSP_transcript

    介绍Visual+DSP++开发环境的资料

    Vdsp LDF文件格式详解

    ADI Blackfin处理器 Vdsp ldf文件格式详解

    rootfs for uclinux

    与uclinux-2.6(bf561) for vdsp配合使用的根文件系统,ext2,使用时将之以hex32的格式插入到_end符号的末尾

    u-boot-1.1.6-2008R1-vdsp

    这个是将u-boot-1.1.6-2008R1移植到VDSP下的工程文件。 具体移植过程参见本人的BLOG。 http://blog.csdn.net/lights_joy/

    如何在VDSP下生成和调用DSP库

    本文将通过两个简单的例程来一步一步演示如何在VisualDSP++里创建并调用基于C 语言的DSP库文件(*.dlb)。虽然例程是基于Blackfin 处理器实的,但创建过程和调用方法依然适用于SHARC、TigerSHARC 等ADI 公司的处理器。

    bfin-uclinux-2008r1-csdn-2008-08-28.part05

    适用于ADSP-BF561。使用了优视科技BV561EVB开发板,但仅实现其DM9000的网卡驱动。 由于CSDN空间限制,请分开下载所有的8个rar文件。 也可在http://sf.net/projects/vdsp-uclinux/中下载单个的软件包。

    bfin-uclinux-2008r1-csdn-2008-08-28.part03

    适用于ADSP-BF561。使用了优视科技BV561EVB开发板,但仅实现其DM9000的网卡驱动。 由于CSDN空间限制,请分开下载所有的8个rar文件。 也可在http://sf.net/projects/vdsp-uclinux/中下载单个的软件包。

    bfin-uclinux-2008r1-csdn-2008-08-28.part04

    适用于ADSP-BF561。使用了优视科技BV561EVB开发板,但仅实现其DM9000的网卡驱动。 由于CSDN空间限制,请分开下载所有的8个rar文件。 也可在http://sf.net/projects/vdsp-uclinux/中下载单个的软件包。

    bfin-uclinux-2008r1-csdn-2008-08-28.part07

    适用于ADSP-BF561。使用了优视科技BV561EVB开发板,但仅实现其DM9000的网卡驱动。 由于CSDN空间限制,请分开下载所有的8个rar文件。 也可在http://sf.net/projects/vdsp-uclinux/中下载单个的软件包。

Global site tag (gtag.js) - Google Analytics