xref: /original-bsd/lib/libc/tahoe/fpe/addd.s (revision c3e32dec)
1/*
2 * Copyright (c) 1986, 1993
3 *	The Regents of the University of California.  All rights reserved.
4 *
5 * This code is derived from software contributed to Berkeley by
6 * Computer Consoles Inc.
7 *
8 * %sccs.include.redist.c%
9 */
10
11#if defined(SYSLIBC_SCCS) && !defined(lint)
12	.asciz "@(#)addd.s	8.1 (Berkeley) 06/04/93"
13#endif /* SYSLIBC_SCCS and not lint */
14
15#include <tahoemath/fp.h>
16#include "DEFS.h"
17
18XENTRY(addd, R2|R3|R4|R5|R6|R7|R8|R9|R10)
19/*
20 * see which operand has a greater exponent
21 * The greater one will be fetched into r0,r1,r2,r3.
22 * r0,r1 - 'pure' fraction, r2 - exponent, r3 - sign).
23 * The smaller operand will be fetched into r4,r5,r6,r7.
24 */
25	andl3	$EXPMASK,4(fp),r0
26	andl3	$EXPMASK,12(fp),r1
27	cmpl	r0,r1
28	jgtr	first_greater
29
30	movl	12(fp),r0	# bigger operand to r0,r1
31	movl	16(fp),r1
32
33	movl	4(fp),r4	# smaller operand to r4,r5
34	movl	8(fp),r5
35	jmp	expo
36
37first_greater:
38	movl	4(fp),r0	# bigger operand to r0,r1
39	movl	8(fp),r1
40
41	movl	12(fp),r4	# smaller operand to r4,r5
42	movl	16(fp),r5
43
44/*
45 * compute exponents:
46 */
47expo:
48	andl3	$EXPMASK,r0,r2	# r2 will hold the exponent.
49	jeql	is_res1		# check for reserved operand.
50	shrl	$EXPSHIFT,r2,r2
51
52
53	andl3	$EXPMASK,r4,r6	# r6 will hold the exponent.
54	jeql	is_res2		# check for reserved operand.
55	shrl	$EXPSHIFT,r6,r6
56/*
57 * compare the exponents:
58 */
59	subl3	r6,r2,r8
60	jeql	signs
61	cmpl	r8,$MAX_EXP_DIF
62	jlss	signs
63	ret			# return the bigger number.
64
65/*
66 * remember the signs:
67 */
68signs:
69	clrl	r3
70	bbc	$31,r0,sign2	# if negative remember it.
71	incl	r3
72sign2:
73	clrl	r7
74	bbc	$31,r4,frac	# if negative remember it.
75	incl	r7
76/*
77 * compute 'pure' fraction:
78 */
79frac:
80				# clear the non fraction parts.
81	andl2	$(0!(EXPMASK | SIGNBIT)),r0
82				# add the hidden bit.
83	orl2	$(0!CLEARHID),r0
84				# clear the non fraction parts.
85	andl2	$(0!(EXPMASK | SIGNBIT)),r4
86				# add the hidden bit.
87	orl2	$(0!CLEARHID),r4
88
89/*
90 * shift the smaller operand:
91 */
92	shrq	r8,r4,r4
93eql_exps:
94	cmpl 	r3,r7
95	jeql	add
96	bbc	$0,r3,negr4r5
97/*
98 * negate the pair r0,r1:
99 */
100	clrl	r3
101	mcoml	r1,r1
102	clrl	r9		# r9 - carry flag.
103	incl	r1
104	bcc	comr0
105	incl	r9		# remember the carry.
106comr0:	mcoml	r0,r0
107	bbc	$0,r9,add
108	incl	r0
109
110/*
111 * add the fractions:
112 */
113add:
114	clrl	r10 		# to remember the sign of the result.
115	addl2	r5,r1
116	adwc	r4,r0
117	jgeq	norm		# if positive go to normelize.
118	incl	r10		# else remember it and negate the result.
119/*
120 * negate the pair r0,r1:
121 */
122	clrl	r3
123	mcoml	r1,r1
124	clrl	r9		# r9 - carry flag.
125	incl	r1
126	bcc	comr00
127	incl	r9		# remember the carry.
128comr00:	mcoml	r0,r0
129	bbc	$0,r9,norm
130	incl	r0
131norm:	callf	$4,fnorm
132
133/*
134 * add the sign bit
135 */
136	bbs	$0,r10,negative
137	bbs	$0,r3,negative
138	ret
139negative:
140	orl2	$SIGNBIT,r0
141	ret
142
143
144/*
145 * negate the pair r4,r5:
146 */
147negr4r5:
148	clrl	r7
149	mcoml	r5,r5
150	clrl	r9		# r9 - carry flag.
151	incl	r5
152	bcc	comr4
153	incl	r9		# remember the carry.
154comr4:	mcoml	r4,r4
155	bbc	$0,r9,add
156	incl	r4
157	jmp	add
158
159
160is_res1:
161	bbs	$31,r0,res_op
162	movl	r4,r0		# return the  smaller operand.
163	movl	r5,r1
164	ret
165
166is_res2:
167	bbs	$31,r4,res_op
168	ret			# we allready have the 'result' in r0,r1.
169
170res_op:
171	callf	$4,fpresop
172	ret
173