xref: /original-bsd/lib/libc/tahoe/fpe/muld.s (revision 54e6d6c7)
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 *
8 * Redistribution and use in source and binary forms are permitted
9 * provided that the above copyright notice and this paragraph are
10 * duplicated in all such forms and that any documentation,
11 * advertising materials, and other materials related to such
12 * distribution and use acknowledge that the software was developed
13 * by the University of California, Berkeley.  The name of the
14 * University may not be used to endorse or promote products derived
15 * from this software without specific prior written permission.
16 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
17 * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
18 * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
19 */
20
21#if defined(SYSLIBC_SCCS) && !defined(lint)
22	.asciz "@(#)muld.s	1.2 (Berkeley) 02/17/89"
23#endif /* SYSLIBC_SCCS and not lint */
24
25#include <tahoemath/fp.h>
26#include "DEFS.h"
27
28#define	HIDDEN	23	/* here we count from 0 not from 1 as in fp.h */
29
30XENTRY(muld, R2|R3|R4|R5|R6|R7|R8|R9)
31	clrl	r3		/* r3 - sign: 0 for positive,1 for negative. */
32	movl	4(fp),r0
33	jgeq	1f
34	movl	$1,r3
351:	movl	12(fp),r2
36	jgeq	2f
37	bbc	$0,r3,1f	/* seconed operand is negative. */
38	clrl	r3		/* if first was negative, make result positive. */
39	jmp	2f
401:	movl	$1,r3		/* if first was positive, make result negative. */
412:	andl2	$EXPMASK,r0	/* compute first 'pure'exponent. */
42	jeql	is_res1
43	shrl	$EXPSHIFT,r0,r0
44	subl2	$BIASP1,r0
45	andl2	$EXPMASK,r2	/* compute seconed 'pure'exponent. */
46	jeql	is_res2
47	shrl	$EXPSHIFT,r2,r2
48	subl2	$BIASP1,r2
49	addl2	r0,r2		/* add the exponents. */
50	addl2	$(BIASP1+2),r2
51	jleq	underflow
52	cmpl	r2,$258		/* normalization can make the exp. smaller. */
53	jgeq	overflow
54 /*
55 *	We have the sign in r3,the exponent in r2,now is the time to
56 * 	perform the multiplication...
57 */
58	/* fetch first fraction: (r0,r1) */
59	andl3	$(0!(EXPMASK | SIGNBIT)),4(fp),r0
60	orl2	$(0!CLEARHID),r0
61	movl	8(fp),r1
62	shlq	$7,r0,r0	/* leave the sign bit cleared. */
63
64	/* fetch seconed fraction: (r4,r5) */
65	andl3	$(0!(EXPMASK | SIGNBIT)),12(fp),r4
66	orl2	$(0!CLEARHID),r4
67	movl	16(fp),r5
68	shlq	$7,r4,r4	/* leave the sign bit cleared. */
69
70	/* in the following lp1 stands for least significant part of operand 1,
71	*		   lp2 for least significant part of operand 2,
72	*		   mp1 for most significant part of operand 1,
73	*		   mp2 for most significant part of operand 2.
74	*/
75
76	clrl 	r6
77	shrl	$1,r1,r1	/* clear the sign bit of the lp1. */
78	jeql	1f
79	emul	r1,r4,$0,r6	/* r6,r7 <-- lp1*mp2 */
80	shlq	$1,r6,r6	/* to compensate for the shift we did to clear the sign bit. */
811:	shrl	$1,r5,r5	/* clear the sign bit of the lp2. */
82	jeql	1f
83	emul	r0,r5,$0,r8	/* r8,r9 <-- mp1*lp2 */
84	shlq	$1,r8,r8
85	addl2	r9,r7		/* r6,r7 <-- the sum of the products. */
86	adwc	r8,r6
871:	emul	r0,r4,$0,r0	/* r0,r1 <-- mp1*mp2  */
88	addl2	r6,r1		/* add the most sig. part of the sum. */
89	adwc	$0,r0
90	movl	r0,r4		/* to see how much we realy need to shift. */
91	movl	$6,r5		/* r5 - shift counter. */
92	shrl	$7,r4,r4	/* dummy shift. */
931:	bbs	$HIDDEN,r4,realshift
94	shll	$1,r4,r4
95	decl	r2		/* update exponent. */
96	jeql	underflow
97	decl	r5		/* update shift counter. */
98	jmp	1b
99realshift:
100	shrq	r5,r0,r0
101	bbc	$0,r1,shiftmore
102	incl	r1		/* rounding. */
103shiftmore:
104	shrq	$1,r0,r0
105comb:
106	andl2	$CLEARHID,r0
107	shll	$EXPSHIFT,r2,r4
108	orl2	r4,r0
109	cmpl	r2,$256
110	jlss	1f
111	callf	$4,fpover
112sign:
1131:	bbc	$0,r3,done
114	orl2	$SIGNBIT,r0
115done:	ret
116
117
118
119is_res1:
120	bbc 	$31,4(fp),retzero
121	callf	$4,fpresop
122	ret
123is_res2:
124	bbc 	$31,12(fp),retzero
125	callf	$4,fpresop
126	ret
127  retzero:
128	  clrl	r0
129	  clrl	r1
130	  ret
131  overflow:
132	callf	$4,fpover
133	jmp	sign
134  underflow:
135	callf	$4,fpunder
136	ret
137