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