xref: /csrg-svn/lib/libc/vax/gen/ldexp.s (revision 42189)
134480Sbostic/*
234480Sbostic * Copyright (c) 1983 Regents of the University of California.
334480Sbostic * All rights reserved.
434480Sbostic *
534480Sbostic * Redistribution and use in source and binary forms are permitted
634819Sbostic * provided that the above copyright notice and this paragraph are
734819Sbostic * duplicated in all such forms and that any documentation,
834819Sbostic * advertising materials, and other materials related to such
934819Sbostic * distribution and use acknowledge that the software was developed
1034819Sbostic * by the University of California, Berkeley.  The name of the
1134819Sbostic * University may not be used to endorse or promote products derived
1234819Sbostic * from this software without specific prior written permission.
1334819Sbostic * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
1434819Sbostic * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
1534819Sbostic * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
1634480Sbostic */
1713416Sroot
1834819Sbostic#if defined(LIBC_SCCS) && !defined(lint)
19*42189Sbostic	.asciz "@(#)ldexp.s	5.5 (Berkeley) 05/17/90"
2034819Sbostic#endif /* LIBC_SCCS and not lint */
2134480Sbostic
2213416Sroot/*
2313416Sroot * double ldexp (value, exp)
2413416Sroot * double value;
2513416Sroot * int exp;
2613416Sroot *
2713416Sroot * Ldexp returns value*2**exp, if that result is in range.
2813416Sroot * If underflow occurs, it returns zero.  If overflow occurs,
2913416Sroot * it returns a value of appropriate sign and largest
3013416Sroot * possible magnitude.  In case of either overflow or underflow,
3113416Sroot * errno is set to ERANGE.  Note that errno is not modified if
3213416Sroot * no error occurs.
3313416Sroot */
3413416Sroot
3513416Sroot#include "DEFS.h"
3613416Sroot
37*42189Sbostic/*
38*42189Sbostic * don't include errno.h, ANSI C says it defines errno.
39*42189Sbostic *
40*42189Sbostic * #include <errno.h>
41*42189Sbostic */
42*42189Sbostic#define	ERANGE	34
43*42189Sbostic
4413416Sroot	.globl	_errno
4513416Sroot
4617329SsamENTRY(ldexp, 0)
4713416Sroot	movd	4(ap),r0	/* fetch "value" */
4813416Sroot	extzv	$7,$8,r0,r2	/* r2 := biased exponent */
4913416Sroot	jeql	1f		/* if zero, done */
5013416Sroot
5113416Sroot	addl2	12(ap),r2	/* r2 := new biased exponent */
5213416Sroot	jleq	2f		/* if <= 0, underflow */
5313416Sroot	cmpl	r2,$256		/* otherwise check if too big */
5413416Sroot	jgeq	3f		/* jump if overflow */
5513416Sroot	insv	r2,$7,$8,r0	/* put exponent back in result */
5613416Sroot1:
5713416Sroot	ret
5813416Sroot2:
5913416Sroot	clrd	r0
6013416Sroot	jbr	1f
6113416Sroot3:
6213416Sroot	movd	huge,r0		/* largest possible floating magnitude */
6313416Sroot	jbc	$15,4(ap),1f	/* jump if argument was positive */
6413416Sroot	mnegd	r0,r0		/* if arg < 0, make result negative */
6513416Sroot1:
6613416Sroot	movl	$ERANGE,_errno
6713416Sroot	ret
6813416Sroot
6913416Sroot	.data
7013416Sroothuge:	.word	0x7fff		/* the largest number that can */
7113416Sroot	.word	0xffff		/*   be represented in a long floating */
7213416Sroot	.word	0xffff		/*   number.  This is given in hex in order */
7313416Sroot	.word	0xffff		/*   to avoid floating conversions */
74