?? _divide.inc
字號:
/************************************************************************
*
* _divide.inc : $Revision: 1.12 $
*
* (c) Copyright 2002 Analog Devices, Inc. All rights reserved.
*
************************************************************************/
/*
* Description : This file contains macros to do various divide algorithms
*/
/*{!PAFH}_____________________________________________________________________
Macro name : DIVIDE
----------------------------------------------------------------------------
Purpose : This macro implements a generic divide algorithm.
Description : ~ This divide macro uses the following algorithm to implement
divide:
~ result = x * inv(y)
~ Where r[i] = inv(y) is calculated using 5 iterations of the
following forumla:
~ r[i] = (r[i-1] * 2.0) - ((y * r[i-1])*r[i-1])
Inputs : ~ Rx - reg containing x (can be 32 or 40-bit reg)
~ fRx - freg containing x (can be 32 or 40-bit reg)
~ Ry - reg containing y (can be 32 or 40-bit reg)
~ fRy - freg containing y (can be 32 or 40-bit reg)
~ Rtwo - reg containing 2.0 (can be 32 or 40-bit val)
Outputs : ~ Rresult - reg to get result (can be 32 or 40-bit reg)
~ fRresult - freg to get result (can be 32 or 40-bit reg)
Modifies : ~ Rtmp0 - reg used for temp (can be 32 or 40-bit reg)
~ fRtmp0 - freg used for temp (can be 32 or 40-bit reg)
: ~ Rtmp1 - reg used for temp (can be 32 or 40-bit reg)
~ fRtmp1 - freg used for temp (can be 32 or 40-bit reg)
Data Memory : 0
Prog Memory : 22 words
Cycles : 13
Notes : ~ Rx, Ry, Rresult, Rtwo, Rtmp0, Rtmp1 can be ALL 32-bit
registers to implement a 32-bit divide
~ OR
~ Rx, Ry, Rresult, Rtwo, Rtmp0, Rtmp1 can be ALL 40-bit
registers to implement a -bit divide
~ Rreg must be of the form r<n>
~ fRreg must be of the form fr<n> or xfr<n>
~
~ To save registers, the following registers can be set
to the same:
~ Rtmp1 <-> Rx (note that Rx will be modified)
~ Rresult <-> Ry (note that Ry will be modified)
_____________________________________________________________________{!EHDR}
*/
#define DIVIDE(Rx, fRx, Ry, fRy, Rresult, fRresult, Rtmp0, fRtmp0, Rtmp1, fRtmp1, Rtwo) \
\
fRtmp0 = recips Ry;; /* t0 = x0 */ \
fRtmp1 = Rtmp0 * Rx;; /* result = x * x0 */ \
Rresult = Rtmp1;; \
fRtmp1 = Ry * Rtmp0;; /* t1 = y * x0 */ \
\
/* Iteration 1 */ \
fRtmp0 = Rtwo - Rtmp1;; /* t0 = 2 - y * x0 */ \
fRtmp1 = Rtmp0 * Rtmp1;; /* t1 = (2 - y*x0) * (y*x0) */ \
/* = y * x1 */ \
fRresult = Rtmp0 * Rresult;; /* result = (2 - y*x0) * x*x0 */ \
/* = x * x1 */ \
\
/* Iteration 2 */ \
fRtmp0 = Rtwo - Rtmp1;; /* t0 = 2 - y * x1 */ \
fRtmp1 = Rtmp0 * Rtmp1;; /* t1 = (2 - y*x1) * (y*x1) */ \
/* = y * x2 */ \
fRresult = Rtmp0 * Rresult;; /* result = (2 - y*x1) * x*x1 */ \
/* = x * x2 */ \
\
/* Iteration 3 */ \
fRtmp0 = Rtwo - Rtmp1;; /* t0 = 2 - y * x2 */ \
fRtmp1 = Rtmp0 * Rtmp1;; /* t1 = (2 - y*x2) * (y*x2) */ \
/* = y * x3 */ \
fRresult = Rtmp0 * Rresult;; /* result = (2 - y*x2) * x*x2 */ \
/* = x * x3 */ \
\
/* Iteration 4 */ \
fRtmp0 = Rtwo - Rtmp1;; /* t0 = 2 - y * x3 */ \
fRtmp1 = Rtmp0 * Rtmp1;; /* t1 = (2 - y*x3) * (y*x3) */ \
/* = y * x3 */ \
fRresult = Rtmp0 * Rresult /* result = (2 - y*x3) * x*x3 */ \
/* = x * x4 */ \
/*{!PAFH}_____________________________________________________________________
Macro name : DIVIDE40
----------------------------------------------------------------------------
Purpose : This macro implements a 40-bit divide algorithm.
Description : ~ This divide macro uses the following algorithm to implement
divide:
~ tmp_exp = -(exponent of y)
~ set exponent of y to 0
~ result = x * inv(y)
~ scale result by tmp_exp
~ Where r[i] = inv(y) is calculated using 5 iterations of the
following forumla:
~ r[i] = (r[i-1] * 2.0) - ((y * r[i-1])*r[i-1])
Inputs : ~ Rx40 - 40-bit reg containing x
~ Ry40 - 40-bit reg containing y
~ fRy40 - 40-bit freg containing y
~ Ry_exp - 32-bit reg pointing to exponent of y
(eg. Ry = r5:4, Ry_exp = r5)
~ sRy_exp - 32-bit side-specific reg pointing to exponent of y
(eg. Ry = r5:4, sRy_exp = xr5 or yr5)
~ Rtwo40 - 40-bit reg containing 2.0
~ COND - nxaeq if x side desired
~ - nyaeq if y side desired
Outputs : ~ Rresult40 - 40-bit reg to get result
~ fRresult40 - 40-bit freg to get result
Modifies : ~ Rtmp0 - 40-bit reg used for temp
~ fRtmp0 - 40-bit freg used for temp
: ~ Rtmp1 - 40-bit reg used for temp
~ fRtmp1 - 40-bit freg used for temp
~ Rtmp_exp - 32-bit reg used for scaling the exponent
~ sRtmp_exp - 32-bit side-specific reg used for scaling the exponent
~ Ry40 - 40-bit reg containing y
~ fRy40 - 40-bit freg containing y
Data Memory : 0
Prog Memory : 23 words
Cycles : 16
Notes : ~ Either the x OR y side is used
~ To save registers, the following registers can be set
to the same:
~ Rtmp1 <-> Rx (note that Rx will be modified)
~ Rresult <-> Ry (note that Ry will be modified)
~ To save registers, the following registers can be set
to the same:
~ Rtmp1 <-> Rx (note that Rx will be modified)
~ Rresult <-> Ry (note that Ry will be modified)
_____________________________________________________________________{!EHDR}
*/
#define DIVIDE40(Rx40, Ry40, fRy40, Ry_exp, sRy_exp, Rresult40, fRresult40, Rtmp_exp, sRtmp_exp, Rtmp0, fRtmp0, Rtmp1, fRtmp1, Rtwo40, COND) \
\
sRtmp_exp = 0x3f800000; /* set tmp_exp to 127 */ \
fRresult40 = pass Ry40;; /* set condition flags on y, save y */ \
\
if COND; /* if (y != 0) */ \
do, sRy_exp = lshift Rtmp_exp by 0; /* exp(y) = 127 */ \
sRtmp_exp = Rtmp_exp - Ry_exp;; /* exp(tmp) = -(exp(y) - 127) */ \
\
sRtmp_exp = ashift Rtmp_exp by -23; /* shift exp(tmp) such that exponent is in lsb */ \
fRtmp0 = recips Ry40;; /* t0 = x0 */ \
\
fRtmp1 = Ry40 * Rtmp0; /* t1 = y * x0 */ \
fRy40 = pass Rresult40;; /* restore y */ \
\
fRresult40 = Rtmp0 * Rx40;; /* result = x * x0 */ \
\
/* Iteration 1 */ \
fRtmp0 = Rtwo40 - Rtmp1;; /* t0 = 2 - y * x0 */ \
fRtmp1 = Rtmp0 * Rtmp1;; /* t1 = (2 - y*x0) * (y*x0) */ \
/* = y * x1 */ \
fRresult40 = Rtmp0 * Rresult40;; /* result = (2 - y*x0) * x*x0 */ \
/* = x * x1 */ \
\
/* Iteration 2 */ \
fRtmp0 = Rtwo40 - Rtmp1;; /* t0 = 2 - y * x0 */ \
fRtmp1 = Rtmp0 * Rtmp1;; /* t1 = (2 - y*x0) * (y*x0) */ \
/* = y * x1 */ \
fRresult40 = Rtmp0 * Rresult40;; /* result = (2 - y*x0) * x*x0 */ \
/* = x * x1 */ \
\
/* Iteration 3 */ \
fRtmp0 = Rtwo40 - Rtmp1;; /* t0 = 2 - y * x0 */ \
fRtmp1 = Rtmp0 * Rtmp1;; /* t1 = (2 - y*x0) * (y*x0) */ \
/* = y * x1 */ \
fRresult40 = Rtmp0 * Rresult40;; /* result = (2 - y*x0) * x*x0 */ \
/* = x * x1 */ \
\
/* Iteration 4 */ \
fRtmp0 = Rtwo40 - Rtmp1;; /* t0 = 2 - y * x0 */ \
fRresult40 = scalb fRresult40 by Rtmp_exp; /* exp(x) = exp(x) - (exp(y) - 127) */ \
fRtmp1 = Rtmp0 * Rtmp1;; /* t1 = (2 - y*x0) * (y*x0) */ \
/* = y * x1 */ \
fRresult40 = Rtmp0 * Rresult40 /* result = (2 - y*x0) * x*x0 */ \
/* = x * x1 */ \
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -