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