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.
59 * $FreeBSD: src/sys/gnu/i386/fpemul/poly_2xm1.c,v 1.8 1999/08/28 00:42:53 peter Exp $
60 * $DragonFly: src/sys/i386/gnu/fpemul/Attic/poly_2xm1.c,v 1.3 2003/08/07 21:17:20 dillon Exp $
64 #include "reg_constant.h"
69 static unsigned short lterms[HIPOWER][4] =
71 {0x79b5, 0xd1cf, 0x17f7, 0xb172},
72 {0x1b56, 0x058b, 0x7bff, 0x3d7f},
73 {0x8bb0, 0x8250, 0x846b, 0x0e35},
74 {0xbc65, 0xf747, 0x556d, 0x0276},
75 {0x17cb, 0x9e39, 0x61ff, 0x0057},
76 {0xe018, 0x9776, 0x1848, 0x000a},
77 {0x66f2, 0xff30, 0xffe5, 0x0000},
78 {0x682f, 0xffb6, 0x162b, 0x0000},
79 {0xb7ca, 0x2956, 0x01b5, 0x0000},
80 {0xcd3e, 0x4817, 0x001e, 0x0000},
81 {0xb7e2, 0xecbe, 0x0001, 0x0000},
82 {0x0ed5, 0x1a27, 0x0000, 0x0000},
83 {0x101d, 0x0222, 0x0000, 0x0000},
87 /*--- poly_2xm1() -----------------------------------------------------------+
89 +---------------------------------------------------------------------------*/
91 poly_2xm1(FPU_REG * arg, FPU_REG * result)
98 exponent = arg->exp - EXP_BIAS;
100 if (arg->tag == TW_Zero) {
102 reg_move(&CONST_Z, result);
105 if (exponent >= 0) { /* Can't hack a number >= 1.0 */
106 arith_invalid(result); /* Number too large */
109 if (arg->sign != SIGN_POS) { /* Can't hack a number < 0.0 */
110 arith_invalid(result); /* Number negative */
113 if (exponent < -64) {
114 reg_move(&CONST_LN2, result);
117 *(unsigned *) &Xll = arg->sigl;
118 *(((unsigned *) &Xll) + 1) = arg->sigh;
120 /* shift the argument right by the required places */
121 if (shrx(&Xll, -1 - exponent) >= (unsigned)0x80000000)
122 Xll++; /* round up */
124 *(short *) &(accum.sign) = 0; /* will be a valid positive nr with
128 /* Do the basic fixed point polynomial evaluation */
129 polynomial((unsigned *) &accum.sigl, (unsigned *) &Xll, lterms, HIPOWER - 1);
131 /* Convert to 64 bit signed-compatible */
132 accum.exp += EXP_BIAS - 1;
134 reg_move(&accum, result);