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 "@(#)addd.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(addd, 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,r1,r2,r3. | |
48 | * r0,r1 - 'pure' fraction, r2 - exponent, r3 - sign). | |
49 | * The smaller operand will be fetched into r4,r5,r6,r7. | |
50 | */ | |
51 | andl3 $EXPMASK,4(fp),r0 | |
52 | andl3 $EXPMASK,12(fp),r1 | |
53 | cmpl r0,r1 | |
54 | jgtr first_greater | |
55 | ||
56 | movl 12(fp),r0 # bigger operand to r0,r1 | |
57 | movl 16(fp),r1 | |
58 | ||
59 | movl 4(fp),r4 # smaller operand to r4,r5 | |
60 | movl 8(fp),r5 | |
61 | jmp expo | |
62 | ||
63 | first_greater: | |
64 | movl 4(fp),r0 # bigger operand to r0,r1 | |
65 | movl 8(fp),r1 | |
66 | ||
67 | movl 12(fp),r4 # smaller operand to r4,r5 | |
68 | movl 16(fp),r5 | |
69 | ||
70 | /* | |
71 | * compute exponents: | |
72 | */ | |
73 | expo: | |
74 | andl3 $EXPMASK,r0,r2 # r2 will hold the exponent. | |
75 | jeql is_res1 # check for reserved operand. | |
76 | shrl $EXPSHIFT,r2,r2 | |
77 | ||
78 | ||
79 | andl3 $EXPMASK,r4,r6 # r6 will hold the exponent. | |
80 | jeql is_res2 # check for reserved operand. | |
81 | shrl $EXPSHIFT,r6,r6 | |
82 | /* | |
83 | * compare the exponents: | |
84 | */ | |
85 | subl3 r6,r2,r8 | |
86 | jeql signs | |
87 | cmpl r8,$MAX_EXP_DIF | |
88 | jlss signs | |
89 | ret # return the bigger number. | |
90 | ||
91 | /* | |
92 | * remember the signs: | |
93 | */ | |
94 | signs: | |
95 | clrl r3 | |
96 | bbc $31,r0,sign2 # if negative remember it. | |
97 | incl r3 | |
98 | sign2: | |
99 | clrl r7 | |
100 | bbc $31,r4,frac # if negative remember it. | |
101 | incl r7 | |
102 | /* | |
103 | * compute 'pure' fraction: | |
104 | */ | |
105 | frac: | |
106 | # clear the non fraction parts. | |
107 | andl2 $(0!(EXPMASK | SIGNBIT)),r0 | |
108 | # add the hidden bit. | |
109 | orl2 $(0!CLEARHID),r0 | |
110 | # clear the non fraction parts. | |
111 | andl2 $(0!(EXPMASK | SIGNBIT)),r4 | |
112 | # add the hidden bit. | |
113 | orl2 $(0!CLEARHID),r4 | |
114 | ||
115 | /* | |
116 | * shift the smaller operand: | |
117 | */ | |
118 | shrq r8,r4,r4 | |
119 | eql_exps: | |
120 | cmpl r3,r7 | |
121 | jeql add | |
122 | bbc $0,r3,negr4r5 | |
123 | /* | |
124 | * negate the pair r0,r1: | |
125 | */ | |
126 | clrl r3 | |
127 | mcoml r1,r1 | |
128 | clrl r9 # r9 - carry flag. | |
129 | incl r1 | |
130 | bcc comr0 | |
131 | incl r9 # remember the carry. | |
132 | comr0: mcoml r0,r0 | |
133 | bbc $0,r9,add | |
134 | incl r0 | |
135 | ||
136 | /* | |
137 | * add the fractions: | |
138 | */ | |
139 | add: | |
140 | clrl r10 # to remember the sign of the result. | |
141 | addl2 r5,r1 | |
142 | adwc r4,r0 | |
143 | jgeq norm # if positive go to normelize. | |
144 | incl r10 # else remember it and negate the result. | |
145 | /* | |
146 | * negate the pair r0,r1: | |
147 | */ | |
148 | clrl r3 | |
149 | mcoml r1,r1 | |
150 | clrl r9 # r9 - carry flag. | |
151 | incl r1 | |
152 | bcc comr00 | |
153 | incl r9 # remember the carry. | |
154 | comr00: mcoml r0,r0 | |
155 | bbc $0,r9,norm | |
156 | incl r0 | |
157 | norm: callf $4,fnorm | |
158 | ||
159 | /* | |
160 | * add the sign bit | |
161 | */ | |
162 | bbs $0,r10,negative | |
163 | bbs $0,r3,negative | |
164 | ret | |
165 | negative: | |
166 | orl2 $SIGNBIT,r0 | |
167 | ret | |
168 | ||
169 | ||
170 | /* | |
171 | * negate the pair r4,r5: | |
172 | */ | |
173 | negr4r5: | |
174 | clrl r7 | |
175 | mcoml r5,r5 | |
176 | clrl r9 # r9 - carry flag. | |
177 | incl r5 | |
178 | bcc comr4 | |
179 | incl r9 # remember the carry. | |
180 | comr4: mcoml r4,r4 | |
181 | bbc $0,r9,add | |
182 | incl r4 | |
183 | jmp add | |
184 | ||
185 | ||
186 | is_res1: | |
187 | bbs $31,r0,res_op | |
188 | movl r4,r0 # return the smaller operand. | |
189 | movl r5,r1 | |
190 | ret | |
191 | ||
192 | is_res2: | |
193 | bbs $31,r4,res_op | |
194 | ret # we allready have the 'result' in r0,r1. | |
195 | ||
196 | res_op: | |
197 | callf $4,fpresop | |
198 | ret |