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 | * | |
af359dea C |
8 | * Redistribution and use in source and binary forms, with or without |
9 | * modification, are permitted provided that the following conditions | |
10 | * are met: | |
11 | * 1. Redistributions of source code must retain the above copyright | |
12 | * notice, this list of conditions and the following disclaimer. | |
13 | * 2. Redistributions in binary form must reproduce the above copyright | |
14 | * notice, this list of conditions and the following disclaimer in the | |
15 | * documentation and/or other materials provided with the distribution. | |
16 | * 3. All advertising materials mentioning features or use of this software | |
17 | * must display the following acknowledgement: | |
18 | * This product includes software developed by the University of | |
19 | * California, Berkeley and its contributors. | |
20 | * 4. Neither the name of the University nor the names of its contributors | |
21 | * may be used to endorse or promote products derived from this software | |
22 | * without specific prior written permission. | |
23 | * | |
24 | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND | |
25 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | |
26 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | |
27 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE | |
28 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | |
29 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | |
30 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | |
31 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | |
32 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | |
33 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | |
34 | * SUCH DAMAGE. | |
1f0502d3 KB |
35 | */ |
36 | ||
37 | #if defined(SYSLIBC_SCCS) && !defined(lint) | |
1c15e888 | 38 | .asciz "@(#)addf.s 1.3 (Berkeley) 6/1/90" |
1f0502d3 | 39 | #endif /* SYSLIBC_SCCS and not lint */ |
5733b822 SL |
40 | |
41 | #include <tahoemath//fp.h> | |
42 | #include "DEFS.h" | |
43 | ||
44 | XENTRY(addf, R2|R3|R4|R5|R6|R7|R8|R9|R10) | |
45 | /* | |
46 | * see which operand has a greater exponent | |
47 | * The greater one will be fetched into r0,r2,r3. | |
48 | * r0- 'pure' fraction, r2 - exponent, r3 - sign). | |
49 | * The smaller operand will be fetched into r4,r6,r7. | |
50 | */ | |
51 | clrl r1 | |
52 | andl3 $EXPMASK,4(fp),r0 | |
53 | andl3 $EXPMASK,12(fp),r1 | |
54 | cmpl r0,r1 | |
55 | jgtr first_greater | |
56 | ||
57 | movl 12(fp),r0 # bigger operand to r0 | |
58 | ||
59 | movl 4(fp),r4 # smaller operand to r4 | |
60 | jmp expo | |
61 | ||
62 | first_greater: | |
63 | movl 4(fp),r0 # bigger operand to r0 | |
64 | ||
65 | movl 12(fp),r4 # smaller operand to r4 | |
66 | ||
67 | ||
68 | /* | |
69 | *compute exponents: | |
70 | */ | |
71 | expo: | |
72 | andl3 $EXPMASK,r0,r2 # r2 will hold the exponent of greater operand. | |
73 | jeql is_res1 # check for reserved operand. | |
74 | shrl $EXPSHIFT,r2,r2 | |
75 | ||
76 | ||
77 | andl3 $EXPMASK,r4,r6 # r6 will hold the exponent of smaller operand. | |
78 | jeql is_res2 # check for reserved operand. | |
79 | shrl $EXPSHIFT,r6,r6 | |
80 | /* | |
81 | *compare the exponents: | |
82 | */ | |
83 | subl3 r6,r2,r8 | |
84 | jeql signs | |
85 | cmpl r8,$MAX_EXP_DIF | |
86 | jlss signs | |
87 | ret # return the bigger number. | |
88 | ||
89 | /* | |
90 | *remember the signs: | |
91 | */ | |
92 | signs: | |
93 | clrl r3 | |
94 | bbc $31,r0,sign2 # if negative remember it.(R3=1) | |
95 | incl r3 | |
96 | sign2: | |
97 | clrl r7 | |
98 | bbc $31,r4,frac # if negative remember it.(R7=1) | |
99 | incl r7 | |
100 | /* | |
101 | *compute 'pure' fraction: | |
102 | */ | |
103 | frac: | |
104 | # clear the non fraction parts. | |
105 | andl2 $(0!(EXPMASK | SIGNBIT)),r0 | |
106 | # add the hidden bit. | |
107 | orl2 $(0!CLEARHID),r0 | |
108 | # clear the non fraction parts. | |
109 | andl2 $(0!(EXPMASK | SIGNBIT)),r4 | |
110 | # add the hidden bit. | |
111 | orl2 $(0!CLEARHID),r4 | |
112 | ||
113 | /* | |
114 | *shift the smaller operand: | |
115 | */ | |
116 | shar r8,r4,r4 | |
117 | eql_exps: | |
118 | cmpl r3,r7 | |
119 | jeql add | |
120 | bbc $0,r3,negr4 | |
121 | /* | |
122 | *negate r0: | |
123 | */ | |
124 | clrl r3 | |
125 | mnegl r0,r0 | |
126 | ||
127 | /* | |
128 | *add the fractions: | |
129 | */ | |
130 | add: | |
131 | clrl r10 | |
132 | addl2 r4,r0 | |
133 | jgeq norm | |
134 | incl r10 | |
135 | /* | |
136 | *negate the pair r0,r1: | |
137 | */ | |
138 | mnegl r0,r0 | |
139 | norm: callf $4,sfnorm | |
140 | ||
141 | /* | |
142 | *add the sign bit | |
143 | */ | |
144 | bbs $0,r10,negative | |
145 | bbs $0,r3,negative # the bigger operand was negative. | |
146 | ret | |
147 | negative: | |
148 | orl2 $SIGNBIT,r0 | |
149 | ret | |
150 | ||
151 | ||
152 | /* | |
153 | *negate r4: | |
154 | */ | |
155 | negr4: | |
156 | mnegl r4,r4 | |
157 | jmp add | |
158 | ||
159 | ||
160 | is_res1: | |
161 | bbs $31,r0,res_op | |
162 | movl r4,r0 # return the smaller operand. | |
163 | ret | |
164 | ||
165 | is_res2: | |
166 | bbs $31,r4,res_op | |
167 | ret # we allready have the 'result' in r0,r1. | |
168 | ||
169 | res_op: | |
170 | callf $4,sfpresop | |
171 | ret |