xref: /original-bsd/lib/libc/vax/gen/ldexp.s (revision c3e32dec)
1/*
2 * Copyright (c) 1983, 1993
3 *	The Regents of the University of California.  All rights reserved.
4 *
5 * %sccs.include.redist.c%
6 */
7
8#if defined(LIBC_SCCS) && !defined(lint)
9	.asciz "@(#)ldexp.s	8.1 (Berkeley) 06/04/93"
10#endif /* LIBC_SCCS and not lint */
11
12/*
13 * double ldexp (value, exp)
14 * double value;
15 * int exp;
16 *
17 * Ldexp returns value*2**exp, if that result is in range.
18 * If underflow occurs, it returns zero.  If overflow occurs,
19 * it returns a value of appropriate sign and largest
20 * possible magnitude.  In case of either overflow or underflow,
21 * errno is set to ERANGE.  Note that errno is not modified if
22 * no error occurs.
23 */
24
25#include "DEFS.h"
26
27/*
28 * don't include errno.h, ANSI C says it defines errno.
29 *
30 * #include <errno.h>
31 */
32#define	ERANGE	34
33
34	.globl	_errno
35
36ENTRY(ldexp, 0)
37	movd	4(ap),r0	/* fetch "value" */
38	extzv	$7,$8,r0,r2	/* r2 := biased exponent */
39	jeql	1f		/* if zero, done */
40
41	addl2	12(ap),r2	/* r2 := new biased exponent */
42	jleq	2f		/* if <= 0, underflow */
43	cmpl	r2,$256		/* otherwise check if too big */
44	jgeq	3f		/* jump if overflow */
45	insv	r2,$7,$8,r0	/* put exponent back in result */
461:
47	ret
482:
49	clrd	r0
50	jbr	1f
513:
52	movd	huge,r0		/* largest possible floating magnitude */
53	jbc	$15,4(ap),1f	/* jump if argument was positive */
54	mnegd	r0,r0		/* if arg < 0, make result negative */
551:
56	movl	$ERANGE,_errno
57	ret
58
59	.data
60huge:	.word	0x7fff		/* the largest number that can */
61	.word	0xffff		/*   be represented in a long floating */
62	.word	0xffff		/*   number.  This is given in hex in order */
63	.word	0xffff		/*   to avoid floating conversions */
64