|
|
1.1 root 1: /*-
2: * Copyright (c) 1985 The 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: *
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.
35: *
36: * @(#)Kaddf.s 7.1 (Berkeley) 12/6/90
37: */
38:
39: #include "../math/fp.h"
40: #include "../tahoe/SYS.h"
41:
42: /*
43: * _Kaddf(acc_most,acc_least,op_most,op_least,hfs)
44: */
45: .text
46: ENTRY(Kaddf, R10|R9|R8|R7|R6|R5|R4|R3|R2)
47: /*
48: * see which operand has a greater exponent
49: * The greater one will be fetched into r0,r1,r2,r3.
50: * r0,r1 - 'pure' fraction, r2 - exponent, r3 - sign).
51: * The smaller operand will be fetched into r4,r5,r6,r7.
52: */
53: tstl 4(fp) # handle (a+b) where a and/or b = 0.0
54: jneq next
55: movl $0,r1
56: movl 12(fp),r0
57: ret
58: next:
59: tstl 12(fp)
60: jneq doit
61: movl $0,r1
62: movl 4(fp),r0
63: ret
64: doit:
65: andl3 $EXPMASK,4(fp),r0
66: andl3 $EXPMASK,12(fp),r1
67: cmpl r0,r1
68: jgtr first_greater
69:
70: movl 12(fp),r0 # bigger operand to r0,r1
71: movl 16(fp),r1
72:
73: movl 4(fp),r4 # smaller operand to r4,r5
74: movl 8(fp),r5
75: jmp expo
76:
77: first_greater:
78: movl 4(fp),r0 # bigger operand to r0,r1
79: movl 8(fp),r1
80:
81: movl 12(fp),r4 # smaller operand to r4,r5
82: movl 16(fp),r5
83:
84:
85: #
86: #compute exponents:
87: #
88: expo:
89: andl3 $EXPMASK,r0,r2 # r2 will hold the exponent.
90: shrl $EXPSHIFT,r2,r2
91: andl3 $EXPMASK,r4,r6 # r6 will hold the exponent.
92: shrl $EXPSHIFT,r6,r6
93: #
94: #compare the exponents:
95: #
96: subl3 r6,r2,r8
97: jeql signs
98: cmpl r8,$MAX_EXP_DIF
99: jlss signs
100: ret # return the bigger number.
101:
102: #
103: #remember the signs:
104: #
105: signs:
106: clrl r3
107: bbc $31,r0,sign2 # if negative remember it.
108: incl r3
109: sign2:
110: clrl r7
111: bbc $31,r4,frac # if negative remember it.
112: incl r7
113: #
114: #compute 'pure' fraction:
115: #
116: frac:
117: # clear the non fraction parts.
118: andl2 $(0!(EXPMASK | SIGNBIT)),r0
119: # add the hidden bit.
120: orl2 $(0!CLEARHID),r0
121: # clear the non fraction parts.
122: andl2 $(0!(EXPMASK | SIGNBIT)),r4
123: # add the hidden bit.
124: orl2 $(0!CLEARHID),r4
125:
126: #
127: #shift the smaller operand:
128: #
129: shrq r8,r4,r4
130: eql_exps:
131: cmpl r3,r7
132: jeql add
133: bbc $0,r3,negr4r5
134: #
135: #negate the pair r0,r1:
136: #
137: clrl r3
138: mcoml r1,r1
139: clrl r9 # r9 - carry flag.
140: incl r1
141: bcc comr0
142: incl r9 # remember the carry.
143: comr0: mcoml r0,r0
144: bbc $0,r9,add
145: incl r0
146:
147: #
148: #add the fractions:
149: #
150: add:
151: clrl r10 # to remember the sign of the result.
152: addl2 r5,r1
153: adwc r4,r0
154: jgeq norm # if positive go to normelize.
155: incl r10 # else remember it and negate the result.
156: #
157: #negate the pair r0,r1:
158: #
159: clrl r3
160: mcoml r1,r1
161: clrl r9 # r9 - carry flag.
162: incl r1
163: bcc comr00
164: incl r9 # remember the carry.
165: comr00: mcoml r0,r0
166: bbc $0,r9,norm
167: incl r0
168: norm: pushl 20(fp) # addr of returnen exception.
169: callf $8,_Kfnorm
170:
171: #
172: #add the sign bit
173: #
174: bbs $0,r10,negative
175: bbs $0,r3,negative
176: ret
177: negative:
178: orl2 $SIGNBIT,r0
179: ret
180:
181:
182: #
183: #negate the pair r4,r5:
184: #
185: negr4r5:
186: clrl r7
187: mcoml r5,r5
188: clrl r9 # r9 - carry flag.
189: incl r5
190: bcc comr4
191: incl r9 # remember the carry.
192: comr4: mcoml r4,r4
193: bbc $0,r9,add
194: incl r4
195: jmp add
196:
197:
198: movl r4,r0 # return the smaller operand.
199: movl r5,r1
200: ret
201:
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.