Commit | Line | Data |
---|---|---|
1f0502d3 KB |
1 | /* |
2 | * Copyright (c) 1986 Regents of the University of California. | |
3 | * All rights reserved. | |
4 | * | |
5 | * This code is derived from software contributed to Berkeley by | |
6 | * Computer Consoles Inc. | |
7 | * | |
019bea33 | 8 | * %sccs.include.redist.c% |
1f0502d3 KB |
9 | */ |
10 | ||
11 | #if defined(SYSLIBC_SCCS) && !defined(lint) | |
019bea33 | 12 | .asciz "@(#)cvtld.s 1.3 (Berkeley) %G%" |
1f0502d3 | 13 | #endif /* SYSLIBC_SCCS and not lint */ |
c13f0b2e SL |
14 | |
15 | #include <tahoemath/fp.h> | |
16 | #include "DEFS.h" | |
17 | ||
18 | XENTRY(cvtld, R2|R3|R4|R5) | |
19 | # | |
20 | #Some initializations: | |
21 | # | |
22 | clrl r4 # r4 - negative flag. | |
23 | clrl r2 # r2 - exponent. | |
24 | movl 4(fp),r0 # fetch operand. | |
25 | movl r0,r5 # need another copy. | |
26 | jeql retzero # return zero. | |
27 | jgtr positive | |
28 | mnegl r0,r0 | |
29 | jvs retmin # return minimum integer. | |
30 | incl r4 # remember it was negative. | |
31 | movl r0,r5 # remember the negated value. | |
32 | # | |
33 | #Compute exponent: | |
34 | # | |
35 | positive: | |
36 | ffs r0,r1 | |
37 | incl r1 | |
38 | addl2 r1,r2 | |
39 | shrl r1,r0,r0 | |
40 | jneq positive # look for more set bits. | |
41 | # | |
42 | #we have the exponent in r2. | |
43 | # | |
44 | movl r5,r0 # r0,r1 will hold the resulting f.p. number. | |
45 | clrl r1 | |
46 | # | |
47 | #Shift the fraction part to its proper place: | |
48 | # | |
49 | subl3 r2,$HID_POS,r3 | |
50 | jlss shiftr # if less then zero we have to shift right. | |
51 | shll r3,r0,r0 # else we shift left. | |
52 | jmp shifted | |
53 | shiftr: | |
54 | mnegl r3,r3 | |
55 | shrq r3,r0,r0 | |
56 | shifted: | |
57 | andl2 $CLEARHID,r0 # clear the hidden bit. | |
58 | shal $EXPSHIFT,r2,r2 # shift the exponent to its proper place. | |
59 | orl2 $EXPSIGN,r2 # set the exponent sign bit(to bias it). | |
60 | orl2 r2,r0 # combine exponent & fraction. | |
61 | bbc $0,r4,sign_ok # do we have to set the sign bit? | |
62 | orl2 $SIGNBIT,r0 # yes... | |
63 | sign_ok: | |
64 | ret | |
65 | ||
66 | retzero: | |
67 | clrl r0 | |
68 | clrl r1 | |
69 | ret | |
70 | ||
71 | retmin: | |
72 | movl $0xd0000000,r0 | |
73 | clrl r1 | |
74 | ret | |
75 | ||
76 | ||
77 |