xref: /csrg-svn/lib/libc/vax/gen/ldexp.s (revision 17329)
1*17329Ssam/*	ldexp.s	4.2	84/11/01	*/
213416Sroot
313416Sroot/*
413416Sroot * double ldexp (value, exp)
513416Sroot * double value;
613416Sroot * int exp;
713416Sroot *
813416Sroot * Ldexp returns value*2**exp, if that result is in range.
913416Sroot * If underflow occurs, it returns zero.  If overflow occurs,
1013416Sroot * it returns a value of appropriate sign and largest
1113416Sroot * possible magnitude.  In case of either overflow or underflow,
1213416Sroot * errno is set to ERANGE.  Note that errno is not modified if
1313416Sroot * no error occurs.
1413416Sroot */
1513416Sroot
1613416Sroot#include "DEFS.h"
1713416Sroot#include <errno.h>
1813416Sroot
1913416Sroot	.globl	_errno
2013416Sroot
21*17329SsamENTRY(ldexp, 0)
2213416Sroot	movd	4(ap),r0	/* fetch "value" */
2313416Sroot	extzv	$7,$8,r0,r2	/* r2 := biased exponent */
2413416Sroot	jeql	1f		/* if zero, done */
2513416Sroot
2613416Sroot	addl2	12(ap),r2	/* r2 := new biased exponent */
2713416Sroot	jleq	2f		/* if <= 0, underflow */
2813416Sroot	cmpl	r2,$256		/* otherwise check if too big */
2913416Sroot	jgeq	3f		/* jump if overflow */
3013416Sroot	insv	r2,$7,$8,r0	/* put exponent back in result */
3113416Sroot1:
3213416Sroot	ret
3313416Sroot2:
3413416Sroot	clrd	r0
3513416Sroot	jbr	1f
3613416Sroot3:
3713416Sroot	movd	huge,r0		/* largest possible floating magnitude */
3813416Sroot	jbc	$15,4(ap),1f	/* jump if argument was positive */
3913416Sroot	mnegd	r0,r0		/* if arg < 0, make result negative */
4013416Sroot1:
4113416Sroot	movl	$ERANGE,_errno
4213416Sroot	ret
4313416Sroot
4413416Sroot	.data
4513416Sroothuge:	.word	0x7fff		/* the largest number that can */
4613416Sroot	.word	0xffff		/*   be represented in a long floating */
4713416Sroot	.word	0xffff		/*   number.  This is given in hex in order */
4813416Sroot	.word	0xffff		/*   to avoid floating conversions */
49