xref: /csrg-svn/lib/libc/vax/gen/ldexp.s (revision 61225)
134480Sbostic/*
2*61225Sbostic * Copyright (c) 1983, 1993
3*61225Sbostic *	The Regents of the University of California.  All rights reserved.
434480Sbostic *
542637Sbostic * %sccs.include.redist.c%
634480Sbostic */
713416Sroot
834819Sbostic#if defined(LIBC_SCCS) && !defined(lint)
9*61225Sbostic	.asciz "@(#)ldexp.s	8.1 (Berkeley) 06/04/93"
1034819Sbostic#endif /* LIBC_SCCS and not lint */
1134480Sbostic
1213416Sroot/*
1313416Sroot * double ldexp (value, exp)
1413416Sroot * double value;
1513416Sroot * int exp;
1613416Sroot *
1713416Sroot * Ldexp returns value*2**exp, if that result is in range.
1813416Sroot * If underflow occurs, it returns zero.  If overflow occurs,
1913416Sroot * it returns a value of appropriate sign and largest
2013416Sroot * possible magnitude.  In case of either overflow or underflow,
2113416Sroot * errno is set to ERANGE.  Note that errno is not modified if
2213416Sroot * no error occurs.
2313416Sroot */
2413416Sroot
2513416Sroot#include "DEFS.h"
2613416Sroot
2742189Sbostic/*
2842189Sbostic * don't include errno.h, ANSI C says it defines errno.
2942189Sbostic *
3042189Sbostic * #include <errno.h>
3142189Sbostic */
3242189Sbostic#define	ERANGE	34
3342189Sbostic
3413416Sroot	.globl	_errno
3513416Sroot
3617329SsamENTRY(ldexp, 0)
3713416Sroot	movd	4(ap),r0	/* fetch "value" */
3813416Sroot	extzv	$7,$8,r0,r2	/* r2 := biased exponent */
3913416Sroot	jeql	1f		/* if zero, done */
4013416Sroot
4113416Sroot	addl2	12(ap),r2	/* r2 := new biased exponent */
4213416Sroot	jleq	2f		/* if <= 0, underflow */
4313416Sroot	cmpl	r2,$256		/* otherwise check if too big */
4413416Sroot	jgeq	3f		/* jump if overflow */
4513416Sroot	insv	r2,$7,$8,r0	/* put exponent back in result */
4613416Sroot1:
4713416Sroot	ret
4813416Sroot2:
4913416Sroot	clrd	r0
5013416Sroot	jbr	1f
5113416Sroot3:
5213416Sroot	movd	huge,r0		/* largest possible floating magnitude */
5313416Sroot	jbc	$15,4(ap),1f	/* jump if argument was positive */
5413416Sroot	mnegd	r0,r0		/* if arg < 0, make result negative */
5513416Sroot1:
5613416Sroot	movl	$ERANGE,_errno
5713416Sroot	ret
5813416Sroot
5913416Sroot	.data
6013416Sroothuge:	.word	0x7fff		/* the largest number that can */
6113416Sroot	.word	0xffff		/*   be represented in a long floating */
6213416Sroot	.word	0xffff		/*   number.  This is given in hex in order */
6313416Sroot	.word	0xffff		/*   to avoid floating conversions */
64