1 | double float to long conversion routine
3 | written by Kai-Uwe Bloem
(I5110401@dbstu1.bitnet
).
4 | Based on
a 80x86 floating point packet from comp.os.minix
, written by P.Housel
7 | Revision
1.3, kub
01-90 :
8 | added support for denormalized numbers
10 | Revision
1.2, kub
01-90 :
11 | replace far shifts by swaps to gain speed
13 | Revision
1.1, kub
12-89 :
14 | Ported over to
68k assembler
17 | original
8088 code from P.S.Housel
26 lea
%sp@
(4),%a0 | pointer to parameters
27 moveml
%d2
/%d4
/%d5
,%sp@
- | save registers
28 moveml
%a0@
,%d4-
%d5 | get the number
29 movew
%a0@
,%d0 | extract exp
30 movew
%d0
,%d2 | extract sign
32 andw
#0x07ff,%d0 | kill sign bit
34 andl
#0x0fffff,%d4 | remove exponent from mantissa
35 orl
#0x100000,%d4 | restore implied leading "1"
37 cmpw #BIAS8,%d0 | check exponent
38 blt zero | strictly factional
, no integer part ?
39 cmpw #BIAS8+32,%d0 | is it too big to fit in a 32-bit integer ?
42 subw
#BIAS8+21,%d0 | adjust exponent
46 cmpw #-8,%d0 | replace far shifts by swap
48 movew
%d4
,%d5 | shift fast
, 16 bits
52 addw
#16,%d0 | account for swap
56 L_1
: lsrl
#1,%d4 | shift down to align radix point;
57 addw
#1,%d0 | extra bits fall off the end (no rounding)
58 blt L_1 | shifted all the way down yet ?
61 L_2
: addl
%d5
,%d5 | shift up to align radix point
66 L_3
: movel
%d4
,%d0 | put integer into result register
67 cmpl #0x80000000,%d0 | -2147483648 is a nasty evil special case
69 tstw
%d2 | this had better
be -2^
31 and not 2^
31
72 L_6
: tstl
%d0 | sign bit set ?
(i.e. too big
)
75 tstw
%d2 | is it negative ?
79 moveml
%sp@
+,%d2
/%d4
/%d5
83 clrl
%d0 | make the whole thing zero
87 movel
#0x7fffffff,%d0 | ugh. Should cause a trap here.