xref: /original-bsd/lib/libc/tahoe/fpe/cvtdl.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 "@(#)cvtdl.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(cvtdu, R2|R3|R4|R5)
19	jbr	1f
20
21XENTRY(cvtdl, R2|R3|R4|R5)
22 #
23 #Some initializations:
24 #
251:
26	movl	4(fp),r0	# fetch operand.
27	movl	8(fp),r1
28	clrl	r3		# r3 - negative flag.
29 #
30 #get exponent
31 #
32	andl3	$EXPMASK,r0,r2	# r2 will hold the exponent.
33	jeql	is_reserved	# check for reserved operand.
34	cmpl	$ONE_EXP,r2	# if exponent is less then 1,return zero.
35	jgtr	retzero
36	andl2	$0!EXPSIGN,r2	# turn off biased exponent sign
37	shrl	$EXPSHIFT,r2,r2
38 #
39 #get fraction
40 #
41	bbc	$31,r0,positive	# if negative remember it.
42	incl	r3
43positive:
44				# clear the non fraction parts.
45	andl2	$(0!(EXPMASK | SIGNBIT)),r0
46				# add the hidden bit.
47	orl2	$(0!CLEARHID),r0
48	subl2	$24,r2		# compute the shift.
49	jgtr	shift_left
50	mnegl	r2,r2
51	shrl	r2,r0,r0	# shift right.
52	jmp	shifted
53shift_left:
54	cmpl	r2,$7
55	jgtr	overflow
56go_on:	shlq	r2,r0,r0	# shift right.
57shifted:
58	bbc	$0,r3,done	# check for negative
59	mnegl	r0,r0
60done:
61	ret
62
63retzero:
64	clrl	r0
65	ret
66overflow:
67	callf	$4,fpover
68	jmp	go_on
69
70is_reserved:
71	bbc	$31,r0,retzero
72
73	callf	$4,fpresop
74	ret
75