xref: /original-bsd/sys/tahoe/math/Kldexpf.s (revision ae291b9c)
1/*-
2 * Copyright (c) 1985 The 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 * %sccs.include.redist.c%
9 *
10 *	@(#)Kldexpf.s	7.1 (Berkeley) 12/06/90
11 */
12
13#include "../tahoe/SYS.h"
14#include "../math/fp.h"
15#include "../math/Kfp.h"
16
17/* @(*)Kldexpf.s	4.2 (Berkeley) 12/21/80
18 *	Tahoe 		2/2/83
19 *
20 * float Kldexpf (op_most, op_least, exp, hfs)
21 *
22 * Ldexp returns value*2**exp, if that result is in range.
23 * If underflow occurs, it returns zero.  If overflow occurs,
24 * it returns a value of appropriate sign and largest
25 * possible magnitude.  In case of either overflow or underflow,
26 * the external int "errno" is set to ERANGE.  Note that errno is
27 * not modified if no error occurs, so if you intend to test it
28 * after you use Kldexpf, you had better set it to something
29 * other than ERANGE first (zero is a reasonable value to use).
30 */
31
32	.text
33ENTRY(Kldexpf, R2)
34	movl	4(fp),r0	/* Fetch "value" */
35	movl	8(fp),r1
36
37	andl3	$EXPMASK,r0,r2	/* r2 := shifted biased exponent */
38	jeql	ld1		/* If it's zero, we're done */
39	shar	$EXPSHIFT,r2,r2	/* shift to get value of exponent  */
40
41	addl2	12(fp),r2	/* r2 := new biased exponent */
42	jleq	under		/* if it's <= 0, we have an underflow */
43	cmpl	r2,$256		/* Otherwise check if it's too big */
44	jgeq	over		/* jump if overflow */
45/*
46 *	Construct the result and return
47 */
48	andl2	$0!EXPMASK,r0	/* clear old exponent */
49	shal 	$EXPSHIFT,r2,r2	/* Put the exponent back in the result */
50	orl2	r2,r0
51ld1:	ret
52/*
53 *	Underflow
54 */
55under:	clrl	r0		/* Result is zero */
56	clrl	r1
57	orl2	$HFS_UNDF,*16(fp)
58	jmp	err		/* Join general error code */
59/*
60 *	Overflow
61 */
62over:	movl	huge0,r0	/* Largest possible floating magnitude */
63	movl	huge1,r1
64	orl2	$HFS_OVF,*16(fp)
65	orl2	$SIGNBIT,r0	/* If arg < 0, make result negative */
66
67err:	orl2	$HFS_RANGE,*16(fp)	/* Indicate range error */
68	ret
69
70	.data
71huge0:	.long	0x7fffffff
72huge1:	.long	0xffffffff
73