Other Parts Discussed in Thread: CONTROLSUITE
In e.g. SPRUEO2A page 48 there is sample code for doing a floating point divide using the FPU.
For Y = A/B
DIV:
EINVF32 R2H, R1H ; R2H = Ye = Estimate(1/B)
CMPF32 R0H, #0.0 ; Check if A == 0
MPYF32 R3H, R2H, R1H ; R3H = Ye*B
NOP
SUBF32 R3H, #2.0, R3H ; R3H = 2.0 - Ye*B
NOP
MPYF32 R2H, R2H, R3H ; R2H = Ye = Ye*(2.0 - Ye*B)
NOP
MPYF32 R3H, R2H, R1H ; R3H = Ye*B
CMPF32 R1H, #0.0 ; Check if B == 0.0
SUBF32 R3H, #2.0, R3H ; R3H = 2.0 - Ye*B
NEGF32 R0H, R0H, EQ ; Fixes sign for A/0.0
MPYF32 R2H, R2H, R3H ; R2H = Ye = Ye*(2.0 - Ye*B)
NOP
<-- insert here
MPYF32 R0H, R0H, R2H ; R0H = Y = A*Ye = A/B
LRETR
If B is very large (MAX FLOAT or close), then I am finding that the calculation of Ye underflows to zero, and the returned result is zero whatever the value of A. Thus 1/1e38 and 1e38/1e38 both return zero instead of 1e-38 and 1.0 – both possible floating-point values,
Assuming this underflow is unavoidable, we would like to fix this to get +/-INF in these cases so that it is clear that something has gone wrong. My idea is to add a check for Ye == 0 at the marked point and if true set Ye to INF (preferably with the same sign as B).
As I know little of assembler, my question is – is this possible and what are the instructions?
Regards, Giles