xref: /original-bsd/lib/libc/tahoe/gen/ldexp.s (revision 4092c5cc)
1/*
2 * Copyright (c) 1988, 1993
3 *	The Regents of the University of California.  All rights reserved.
4 *
5 * This code is derived from software contributed to Berkeley by
6 * Computer Consoles Inc.
7 *
8 * %sccs.include.redist.c%
9 */
10
11#if defined(LIBC_SCCS) && !defined(lint)
12	.asciz "@(#)ldexp.s	8.1 (Berkeley) 06/04/93"
13#endif /* LIBC_SCCS and not lint */
14
15/*
16 * double ldexp (value, exp)
17 *	double value;
18 *	int exp;
19 *
20 * Ldexp returns value*2**exp, if that result is in range.
21 * If underflow occurs, it returns zero.  If overflow occurs,
22 * it returns a value of appropriate sign and largest
23 * possible magnitude.  In case of either overflow or underflow,
24 * the external int "errno" is set to ERANGE.  Note that errno is
25 * not modified if no error occurs, so if you intend to test it
26 * after you use ldexp, you had better set it to something
27 * other than ERANGE first (zero is a reasonable value to use).
28 *
29 * Constants
30 */
31
32/*
33 * we can't include errno.h anymore, ANSI says that it defines errno.
34 *
35 * #include <errno.h>
36 */
37#define	ERANGE	34
38#include <tahoe/math/fp.h>
39
40#include "DEFS.h"
41
42ENTRY(ldexp, 0)
43	movl	4(fp),r0	/* Fetch "value" */
44	movl	8(fp),r1
45
46	andl3	$EXPMASK,r0,r2	/* r2 := shifted biased exponent */
47	jeql	ld1		/* If it's zero, we're done */
48	shar	$EXPSHIFT,r2,r2	/* shift to get value of exponent  */
49
50	addl2	12(fp),r2	/* r2 := new biased exponent */
51	jleq	under		/* if it's <= 0, we have an underflow */
52	cmpl	r2,$256		/* Otherwise check if it's too big */
53	jgeq	over		/* jump if overflow */
54/*
55*	Construct the result and return
56*/
57	andl2	$0!EXPMASK,r0	/* clear old exponent */
58	shal 	$EXPSHIFT,r2,r2	/* Put the exponent back in the result */
59	orl2	r2,r0
60ld1:	ret
61/*
62*	Underflow
63*/
64under:	clrl	r0		/* Result is zero */
65	clrl	r1
66	jbr	err		/* Join general error code */
67/*
68*	Overflow
69*/
70over:	movl	huge0,r0	/* Largest possible floating magnitude */
71	movl	huge1,r1
72	jbc	$31,4(fp),err	/* Jump if argument was positive */
73	orl2	$SIGNBIT,r0	/* If arg < 0, make result negative */
74
75err:	movl	$ERANGE,_errno	/* Indicate range error */
76	ret
77
78	.data
79	.globl	_errno		/* error flag */
80huge0:	.word	0x7fff		/* The largest number that can */
81	.word	0xffff		/*   be represented in a long floating */
82huge1:	.word	0xffff		/*   number.  */
83	.word	0xffff
84