Sync usage with man page.
[netbsd-mini2440.git] / lib / libc / pc532 / gen / ldexp.s
blobf064704426d135c18fdf34e35c7cf41e1b17897d
1 /*
2 * Copyright (c) 1992 Helsinki University of Technology
3 * All Rights Reserved.
4 *
5 * Permission to use, copy, modify and distribute this software and its
6 * documentation is hereby granted, provided that both the copyright
7 * notice and this permission notice appear in all copies of the
8 * software, derivative works or modified versions, and any portions
9 * thereof, and that both notices appear in supporting documentation.
11 * HELSINKI UNIVERSITY OF TECHNOLOGY ALLOWS FREE USE OF THIS SOFTWARE IN
12 * ITS "AS IS" CONDITION. HELSINKI UNIVERSITY OF TECHNOLOGY DISCLAIMS ANY
13 * LIABILITY OF ANY KIND FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE
14 * USE OF THIS SOFTWARE.
17 * HISTORY
18 * 29-Apr-92 Tero Kivinen (kivinen) at Helsinki University of Technology
19 * Created.
21 * $Id: ldexp.s,v 1.1 1993/09/17 18:43:46 phil Exp $
25 * double ldexp (value, exp)
26 * double value;
27 * int exp;
29 * Ldexp returns value*2**exp, if that result is in range.
30 * If underflow occurs, it returns zero. If overflow occurs,
31 * it returns a value of appropriate sign and largest
32 * possible magnitude. In case of either overflow or underflow,
33 * errno is set to ERANGE. Note that errno is not modified if
34 * no error occurs.
37 #include <machine/asm.h>
39 #define ERANGE 34
41 .globl EX(errno)
43 ENTRY(ldexp)
44 enter [],8
45 movd 12(fp),r1 /* get value, high 32 bit */
46 lshd -20,r1 /* extract exponent */
47 andd 0x7ff,r1 /* 11 lower bits */
48 subd 1023,r1 /* unbias exponent */
49 movd 16(fp),r0 /* get exp */
50 addd r1,r0 /* add exponents */
51 cmpd r0,1023 /* most positive exponent */
52 bgt ldexp_overflow /* too large */
53 cmpd r0,-1022 /* most negative exponent */
54 blt ldexp_underflow /* too small */
55 addd 1023,r0 /* bias exponent */
56 lshd 20,r0 /* convert exponent back to its place */
57 movd 12(fp),r1 /* get value high 32 bit */
58 bicd 0x7ff00000,r1 /* clear exponent */
59 ord r0,r1 /* insert exponent */
60 movd r1,-4(fp) /* put high 32 bit to local variable */
61 movd 8(fp),-8(fp) /* value low 32 bit to local variable */
62 movl -8(fp),f0 /* return value * 2**exp */
63 exit []
64 ret 0 /* neither */
65 ldexp_underflow:
66 movdl 0d0e0,f0 /* if underflow return 0, set errno */
67 movd ERANGE,@EX(errno)
68 exit []
69 ret 0
70 ldexp_overflow:
71 movl @huge,f0 /* if overflow return HUGE */
72 movdl 0d0e0,f2
73 cmpl f2,8(fp) /* check original sign */
74 bgt ldexp_positive
75 negl f0,f0 /* if negative, return -HUGE */
76 ldexp_positive:
77 movd ERANGE,@EX(errno) /* set errno */
78 exit []
79 ret 0
81 huge: .long 0xffffffff /* the largest number that can */
82 .long 0x7fefffff /* be represented in a long floating */
83 /* number. This is given in hex in order */
84 /* to avoid floating conversions */