|
|
1.1 root 1: .data
2: .asciz "@(#)Fflts.s 1.1 86/02/03 Copyr 1985 Sun Micro"
3: .even
4: .text
5:
6: | Copyright (c) 1985 by Sun Microsystems, Inc.
7:
8: #include "fpcrtdefs.h"
9:
10: /*
11: * single-precision coersions
12: */
13:
14: /*
15: * single integer to floating conversion:
16: * input:
17: * d0 integer value
18: * output:
19: * d0 floating value
20: */
21:
22: RTENTRY(Fflts)
23: movel d0,a0 | a0 saves x.
24: movel d2,a1 | a1 saves d2.
25: movel #0x9e,d1 | d1 accumulates exponent.
26: tstl d0
27: bpls 3f | Branch if x is non-negative.
28: negl d0 | d0 gets abs(x).
29: 3:
30: bmis 2f | Branch if d0 is normalized.
31: beqs Ffltsdone | Branch if zero.
32: 1:
33: subqw #1,d1 | Adjust exponent.
34: lsll #1,d0 | Normalize.
35: bpls 1b | Branch if already normalized.
36: 2:
37: bclr #31,d0 | Clear I bit.
38: movel d0,d2 | d2 gets significand.
39: lsrl #8,d0 | Align high order bits.
40: swap d1
41: lsll #7,d1 | Align exponent.
42: orl d1,d0 | Stick exponent.
43: movel #24,d1
44: lsll d1,d2 | Align rounding bits.
45: addl #0x80000000,d2
46: bccs 1f | Branch if no carry out.
47: tstl d2
48: bnes 1f | Branch if not ambiguous.
49: bclr #0,d0 | Force even.
50: 1:
51: cmpl #0,a0
52: bges Ffltsdone | Branch if x was non-negative.
53: bset #31,d0 | Set sign if negative.
54: Ffltsdone:
55: movel a1,d2 | Restore d2.
56: RET
57:
58: /*
59: * single floating to integer conversion:
60: * input:
61: * d0 floating value
62: * output:
63: * d0 integer value
64: */
65:
66: RTENTRY(Fints)
67: movel d0,d1 | d1 gets x.
68: bclr #31,d1 | d1 gets abs(x).
69: cmpl #0x3f800000,d1
70: bges ge1 | Branch if abs(x) >= 1.
71: clrl d0 | Result is zero.
72: bras Fintsdone
73: ge1:
74: cmpl #0x4f000000,d1
75: bles 1f | Branch if 1 <= |x| <= 2**31.
76: movel #0x80000000,d0 | Max negative integer.
77: bras Fintsdone
78: 1:
79: movel d0,a0 | Save x.
80: andl #0x7fffff,d0 | Clear sign and exponent.
81: bset #23,d0 | Set I bit.
82: roll #1,d1
83: roll #8,d1
84: andw #0xff,d1 | d1 gets biased exponent.
85: subw #23+0x7f,d1 | d1 gets unbiased exponent - 23 = left shift count.
86: beqs Fintsign | Branch if no shift indicated.
87: bmis Fintsright | Branch if right shift indicated.
88: Fintsleft:
89: lsll d1,d0 | Left shift.
90: bras Fintsign
91: Fintsright:
92: negw d1 | Reverse count.
93: lsrl d1,d0 | Right shift.
94: Fintsign:
95: cmpl #0,a0
96: bges Fintsdone | Branch if x was non-negative.
97: negl d0 | Negate result.
98: Fintsdone:
99: RET
100:
101: RTENTRY(Fnints)
102: movel d0,d1 | d1 gets x.
103: bclr #31,d1 | d1 gets abs(x).
104: cmpl #0x3f000000,d1
105: bges gehalf | Branch if abs(x) >= 0.5.
106: clrl d0 | Result is zero.
107: bras Fintsdone
108: gehalf:
109: cmpl #0x4f000000,d1
110: bles 1f | Branch if 0.5 <= |x| <= 2**31.
111: movel #0x80000000,d0 | Max negative integer.
112: bras Fintsdone
113: 1:
114: movel d0,a0 | Save x.
115: andl #0x7fffff,d0 | Clear sign and exponent.
116: bset #23,d0 | Set I bit.
117: roll #1,d1
118: roll #8,d1
119: andw #0xff,d1 | d1 gets biased exponent.
120: subw #23+0x7f,d1 | d1 gets unbiased exponent - 23 = left shift count.
121: beqs Fintsign | Branch if no shift indicated.
122: bpls Fintsleft | Branch if right shift indicated.
123: negw d1 | Reverse count.
124: subqw #1,d1 | Decrement for rounding position.
125: lsrl d1,d0 | Right shift.
126: addql #1,d0 | Round.
127: lsrl #1,d0 | Finish shift.
128: jra Fintsign
129:
130: RTENTRY(Frints)
131: movel d0,d1 | d1 gets x.
132: bclr #31,d1 | d1 gets abs(x).
133: cmpl #0x3f000000,d1
134: bgts gthalf | Branch if abs(x) > 0.5.
135: clrl d0 | Result is zero.
136: jra Fintsdone
137: gthalf:
138: cmpl #0x4f000000,d1
139: bles 1f | Branch if 0.5 < |x| <= 2**31.
140: movel #0x80000000,d0 | Max negative integer.
141: jra Fintsdone
142: 1:
143: movel d0,a0 | Save x.
144: andl #0x7fffff,d0 | Clear sign and exponent.
145: bset #23,d0 | Set I bit.
146: roll #1,d1
147: roll #8,d1
148: andw #0xff,d1 | d1 gets biased exponent.
149: subw #23+0x7f,d1 | d1 gets unbiased exponent - 23 = left shift count.
150: jeq Fintsign | Branch if no shift indicated.
151: jpl Fintsleft | Branch if right shift indicated.
152: movel d2,a1 | a1 saves d2.
153: movel d0,d2
154: negw d1 | Reverse count.
155: lsrl d1,d0 | Right shift.
156: negw d1
157: addw #32,d1
158: lsll d1,d2 | d2 gets round and sticky bits.
159: addl #0x80000000,d2 | Round.
160: bccs 2f | Branch if no carry out.
161: addl #1,d0 | Propagate carry.
162: tstl d2
163: bnes 2f | Branch if not ambiguous.
164: bclr #0,d0 | Force even.
165: 2:
166: movel a1,d2 | Restore d2.
167: jra Fintsign
168:
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.