xref: /original-bsd/lib/libc/vax/gen/ldexp.s (revision 16dabc82)
1/*
2 * Copyright (c) 1983 Regents of the University of California.
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms are permitted
6 * provided that the above copyright notice and this paragraph are
7 * duplicated in all such forms and that any documentation,
8 * advertising materials, and other materials related to such
9 * distribution and use acknowledge that the software was developed
10 * by the University of California, Berkeley.  The name of the
11 * University may not be used to endorse or promote products derived
12 * from this software without specific prior written permission.
13 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
14 * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
15 * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
16 */
17
18#if defined(LIBC_SCCS) && !defined(lint)
19	.asciz "@(#)ldexp.s	5.5 (Berkeley) 05/17/90"
20#endif /* LIBC_SCCS and not lint */
21
22/*
23 * double ldexp (value, exp)
24 * double value;
25 * int exp;
26 *
27 * Ldexp returns value*2**exp, if that result is in range.
28 * If underflow occurs, it returns zero.  If overflow occurs,
29 * it returns a value of appropriate sign and largest
30 * possible magnitude.  In case of either overflow or underflow,
31 * errno is set to ERANGE.  Note that errno is not modified if
32 * no error occurs.
33 */
34
35#include "DEFS.h"
36
37/*
38 * don't include errno.h, ANSI C says it defines errno.
39 *
40 * #include <errno.h>
41 */
42#define	ERANGE	34
43
44	.globl	_errno
45
46ENTRY(ldexp, 0)
47	movd	4(ap),r0	/* fetch "value" */
48	extzv	$7,$8,r0,r2	/* r2 := biased exponent */
49	jeql	1f		/* if zero, done */
50
51	addl2	12(ap),r2	/* r2 := new biased exponent */
52	jleq	2f		/* if <= 0, underflow */
53	cmpl	r2,$256		/* otherwise check if too big */
54	jgeq	3f		/* jump if overflow */
55	insv	r2,$7,$8,r0	/* put exponent back in result */
561:
57	ret
582:
59	clrd	r0
60	jbr	1f
613:
62	movd	huge,r0		/* largest possible floating magnitude */
63	jbc	$15,4(ap),1f	/* jump if argument was positive */
64	mnegd	r0,r0		/* if arg < 0, make result negative */
651:
66	movl	$ERANGE,_errno
67	ret
68
69	.data
70huge:	.word	0x7fff		/* the largest number that can */
71	.word	0xffff		/*   be represented in a long floating */
72	.word	0xffff		/*   number.  This is given in hex in order */
73	.word	0xffff		/*   to avoid floating conversions */
74