xref: /original-bsd/lib/libc/tahoe/fpe/mulf.s (revision 10ea2def)
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 "@(#)mulf.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(mulf, 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) */
59	andl3	$(0!(EXPMASK | SIGNBIT)),4(fp),r0
60	orl2	$(0!CLEARHID),r0
61	shll	$7,r0,r0	/* leave the sign bit cleared. */
62
63	/* fetch seconed fraction: (r4) */
64	andl3	$(0!(EXPMASK | SIGNBIT)),12(fp),r4
65	orl2	$(0!CLEARHID),r4
66	shll	$7,r4,r4	/* leave the sign bit cleared. */
67
68
69	emul	r4,r0,$0,r0
70	movl	r0,r4		/* to see how much we realy need to shift. */
71	movl	$6,r5		/* r5 - shift counter. */
72	shrl	$7,r4,r4	/* dummy shift. */
731:	bbs	$HIDDEN,r4,realshift
74	shll	$1,r4,r4
75	decl	r2		/* update exponent. */
76	jeql	underflow
77	decl	r5		/* update shift counter. */
78	jmp	1b
79realshift:
80	shrl	r5,r0,r0
81	bbc	$0,r1,shiftmore
82	incl	r1		/* rounding. */
83shiftmore:
84	shrl	$1,r0,r0
85comb:
86	andl2	$CLEARHID,r0
87	shll	$EXPSHIFT,r2,r4
88	orl2	r4,r0
89	cmpl	r2,$256
90	jlss	1f
91	callf	$4,sfpover
92sign:
931:	bbc	$0,r3,done
94	orl2	$SIGNBIT,r0
95done:	ret
96
97
98
99is_res1:
100	bbc 	$31,4(fp),retzero
101	callf	$4,sfpresop
102	ret
103is_res2:
104	bbc 	$31,12(fp),retzero
105	callf	$4,sfpresop
106	ret
107  retzero:
108	  clrl	r0
109	  ret
110  overflow:
111	callf	$4,sfpover
112	jmp	sign
113  underflow:
114	callf	$4,sfpunder
115	ret
116
117
118
119