4 * Function to compute 2^x-1 by a polynomial approximation.
7 * Copyright (C) 1992,1993,1994
8 * W. Metzenthen, 22 Parker St, Ormond, Vic 3163,
9 * Australia. E-mail billm@vaxc.cc.monash.edu.au
10 * All rights reserved.
12 * This copyright notice covers the redistribution and use of the
13 * FPU emulator developed by W. Metzenthen. It covers only its use
14 * in the 386BSD, FreeBSD and NetBSD operating systems. Any other
15 * use is not permitted under this copyright.
17 * Redistribution and use in source and binary forms, with or without
18 * modification, are permitted provided that the following conditions
20 * 1. Redistributions of source code must retain the above copyright
21 * notice, this list of conditions and the following disclaimer.
22 * 2. Redistributions in binary form must include information specifying
23 * that source code for the emulator is freely available and include
25 * a) an offer to provide the source code for a nominal distribution
27 * b) list at least two alternative methods whereby the source
28 * can be obtained, e.g. a publically accessible bulletin board
29 * and an anonymous ftp site from which the software can be
31 * 3. All advertising materials specifically mentioning features or use of
32 * this emulator must acknowledge that it was developed by W. Metzenthen.
33 * 4. The name of W. Metzenthen may not be used to endorse or promote
34 * products derived from this software without specific prior written
37 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
38 * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
39 * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
40 * W. METZENTHEN BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
41 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
42 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
43 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
44 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
45 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
46 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
49 * The purpose of this copyright, based upon the Berkeley copyright, is to
50 * ensure that the covered software remains freely available to everyone.
52 * The software (with necessary differences) is also available, but under
53 * the terms of the GNU copyleft, for the Linux operating system and for
54 * the djgpp ms-dos extender.
56 * W. Metzenthen June 1994.
63 #include <gnu/i386/fpemul/reg_constant.h>
68 static unsigned short lterms[HIPOWER][4] =
70 {0x79b5, 0xd1cf, 0x17f7, 0xb172},
71 {0x1b56, 0x058b, 0x7bff, 0x3d7f},
72 {0x8bb0, 0x8250, 0x846b, 0x0e35},
73 {0xbc65, 0xf747, 0x556d, 0x0276},
74 {0x17cb, 0x9e39, 0x61ff, 0x0057},
75 {0xe018, 0x9776, 0x1848, 0x000a},
76 {0x66f2, 0xff30, 0xffe5, 0x0000},
77 {0x682f, 0xffb6, 0x162b, 0x0000},
78 {0xb7ca, 0x2956, 0x01b5, 0x0000},
79 {0xcd3e, 0x4817, 0x001e, 0x0000},
80 {0xb7e2, 0xecbe, 0x0001, 0x0000},
81 {0x0ed5, 0x1a27, 0x0000, 0x0000},
82 {0x101d, 0x0222, 0x0000, 0x0000},
86 /*--- poly_2xm1() -----------------------------------------------------------+
88 +---------------------------------------------------------------------------*/
90 poly_2xm1(FPU_REG * arg, FPU_REG * result)
97 exponent = arg->exp - EXP_BIAS;
99 if (arg->tag == TW_Zero) {
101 reg_move(&CONST_Z, result);
104 if (exponent >= 0) { /* Can't hack a number >= 1.0 */
105 arith_invalid(result); /* Number too large */
108 if (arg->sign != SIGN_POS) { /* Can't hack a number < 0.0 */
109 arith_invalid(result); /* Number negative */
112 if (exponent < -64) {
113 reg_move(&CONST_LN2, result);
116 *(unsigned *) &Xll = arg->sigl;
117 *(((unsigned *) &Xll) + 1) = arg->sigh;
119 /* shift the argument right by the required places */
120 if (shrx(&Xll, -1 - exponent) >= (unsigned)0x80000000)
121 Xll++; /* round up */
123 *(short *) &(accum.sign) = 0; /* will be a valid positive nr with
127 /* Do the basic fixed point polynomial evaluation */
128 polynomial((unsigned *) &accum.sigl, (unsigned *) &Xll, lterms, HIPOWER - 1);
130 /* Convert to 64 bit signed-compatible */
131 accum.exp += EXP_BIAS - 1;
133 reg_move(&accum, result);