BSD 4_3_Net_2 development
[unix-history] / .ref-BSD-4_3_Reno / usr / src / lib / libc / tahoe / fpe / addd.s
CommitLineData
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 *
1c15e888
C
8 * Redistribution and use in source and binary forms are permitted
9 * provided that: (1) source distributions retain this entire copyright
10 * notice and comment, and (2) distributions including binaries display
11 * the following acknowledgement: ``This product includes software
12 * developed by the University of California, Berkeley and its contributors''
13 * in the documentation or other materials provided with the distribution
14 * and in all advertising materials mentioning features or use of this
15 * software. Neither the name of the University nor the names of its
16 * contributors may be used to endorse or promote products derived
17 * from this software without specific prior written permission.
18 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
19 * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
20 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
1f0502d3
KB
21 */
22
23#if defined(SYSLIBC_SCCS) && !defined(lint)
1c15e888 24 .asciz "@(#)addd.s 1.3 (Berkeley) 6/1/90"
1f0502d3 25#endif /* SYSLIBC_SCCS and not lint */
5733b822
SL
26
27#include <tahoemath/fp.h>
28#include "DEFS.h"
29
30XENTRY(addd, R2|R3|R4|R5|R6|R7|R8|R9|R10)
31/*
32 * see which operand has a greater exponent
33 * The greater one will be fetched into r0,r1,r2,r3.
34 * r0,r1 - 'pure' fraction, r2 - exponent, r3 - sign).
35 * The smaller operand will be fetched into r4,r5,r6,r7.
36 */
37 andl3 $EXPMASK,4(fp),r0
38 andl3 $EXPMASK,12(fp),r1
39 cmpl r0,r1
40 jgtr first_greater
41
42 movl 12(fp),r0 # bigger operand to r0,r1
43 movl 16(fp),r1
44
45 movl 4(fp),r4 # smaller operand to r4,r5
46 movl 8(fp),r5
47 jmp expo
48
49first_greater:
50 movl 4(fp),r0 # bigger operand to r0,r1
51 movl 8(fp),r1
52
53 movl 12(fp),r4 # smaller operand to r4,r5
54 movl 16(fp),r5
55
56/*
57 * compute exponents:
58 */
59expo:
60 andl3 $EXPMASK,r0,r2 # r2 will hold the exponent.
61 jeql is_res1 # check for reserved operand.
62 shrl $EXPSHIFT,r2,r2
63
64
65 andl3 $EXPMASK,r4,r6 # r6 will hold the exponent.
66 jeql is_res2 # check for reserved operand.
67 shrl $EXPSHIFT,r6,r6
68/*
69 * compare the exponents:
70 */
71 subl3 r6,r2,r8
72 jeql signs
73 cmpl r8,$MAX_EXP_DIF
74 jlss signs
75 ret # return the bigger number.
76
77/*
78 * remember the signs:
79 */
80signs:
81 clrl r3
82 bbc $31,r0,sign2 # if negative remember it.
83 incl r3
84sign2:
85 clrl r7
86 bbc $31,r4,frac # if negative remember it.
87 incl r7
88/*
89 * compute 'pure' fraction:
90 */
91frac:
92 # clear the non fraction parts.
93 andl2 $(0!(EXPMASK | SIGNBIT)),r0
94 # add the hidden bit.
95 orl2 $(0!CLEARHID),r0
96 # clear the non fraction parts.
97 andl2 $(0!(EXPMASK | SIGNBIT)),r4
98 # add the hidden bit.
99 orl2 $(0!CLEARHID),r4
100
101/*
102 * shift the smaller operand:
103 */
104 shrq r8,r4,r4
105eql_exps:
106 cmpl r3,r7
107 jeql add
108 bbc $0,r3,negr4r5
109/*
110 * negate the pair r0,r1:
111 */
112 clrl r3
113 mcoml r1,r1
114 clrl r9 # r9 - carry flag.
115 incl r1
116 bcc comr0
117 incl r9 # remember the carry.
118comr0: mcoml r0,r0
119 bbc $0,r9,add
120 incl r0
121
122/*
123 * add the fractions:
124 */
125add:
126 clrl r10 # to remember the sign of the result.
127 addl2 r5,r1
128 adwc r4,r0
129 jgeq norm # if positive go to normelize.
130 incl r10 # else remember it and negate the result.
131/*
132 * negate the pair r0,r1:
133 */
134 clrl r3
135 mcoml r1,r1
136 clrl r9 # r9 - carry flag.
137 incl r1
138 bcc comr00
139 incl r9 # remember the carry.
140comr00: mcoml r0,r0
141 bbc $0,r9,norm
142 incl r0
143norm: callf $4,fnorm
144
145/*
146 * add the sign bit
147 */
148 bbs $0,r10,negative
149 bbs $0,r3,negative
150 ret
151negative:
152 orl2 $SIGNBIT,r0
153 ret
154
155
156/*
157 * negate the pair r4,r5:
158 */
159negr4r5:
160 clrl r7
161 mcoml r5,r5
162 clrl r9 # r9 - carry flag.
163 incl r5
164 bcc comr4
165 incl r9 # remember the carry.
166comr4: mcoml r4,r4
167 bbc $0,r9,add
168 incl r4
169 jmp add
170
171
172is_res1:
173 bbs $31,r0,res_op
174 movl r4,r0 # return the smaller operand.
175 movl r5,r1
176 ret
177
178is_res2:
179 bbs $31,r4,res_op
180 ret # we allready have the 'result' in r0,r1.
181
182res_op:
183 callf $4,fpresop
184 ret