My first commit.
[dragonfly.git] / sys / i386 / gnu / fpemul / reg_constant.c
1 /*
2  *  reg_constant.c
3  *
4  * All of the constant FPU_REGs
5  *
6  *
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.
11  *
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.
16  *
17  * Redistribution and use in source and binary forms, with or without
18  * modification, are permitted provided that the following conditions
19  * are met:
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
24  *    either:
25  *      a) an offer to provide the source code for a nominal distribution
26  *         fee, or
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
30  *         downloaded.
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
35  *    permission.
36  *
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.
47  *
48  *
49  * The purpose of this copyright, based upon the Berkeley copyright, is to
50  * ensure that the covered software remains freely available to everyone.
51  *
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.
55  *
56  * W. Metzenthen   June 1994.
57  *
58  * $FreeBSD: src/sys/gnu/i386/fpemul/reg_constant.c,v 1.6.8.1 2000/08/03 00:53:55 peter Exp $
59  * $DragonFly: src/sys/i386/gnu/fpemul/Attic/reg_constant.c,v 1.3 2003/08/07 21:17:20 dillon Exp $
60  */
61
62
63
64 #include <sys/param.h>
65 #include <sys/proc.h>
66 #include <machine/pcb.h>
67
68 #include "fpu_emu.h"
69 #include "fpu_system.h"
70 #include "status_w.h"
71
72
73 FPU_REG CONST_1 = {SIGN_POS, TW_Valid, EXP_BIAS,
74 0x00000000, 0x80000000};
75 static FPU_REG CONST_L2T = {SIGN_POS, TW_Valid, EXP_BIAS + 1,
76 0xcd1b8afe, 0xd49a784b};
77 static FPU_REG CONST_L2E = {SIGN_POS, TW_Valid, EXP_BIAS,
78 0x5c17f0bc, 0xb8aa3b29};
79 FPU_REG CONST_PI = {SIGN_POS, TW_Valid, EXP_BIAS + 1,
80 0x2168c235, 0xc90fdaa2};
81 FPU_REG CONST_PI2 = {SIGN_POS, TW_Valid, EXP_BIAS,
82 0x2168c235, 0xc90fdaa2};
83 FPU_REG CONST_PI4 = {SIGN_POS, TW_Valid, EXP_BIAS - 1,
84 0x2168c235, 0xc90fdaa2};
85 static FPU_REG CONST_LG2 = {SIGN_POS, TW_Valid, EXP_BIAS - 2,
86 0xfbcff799, 0x9a209a84};
87 FPU_REG CONST_LN2 = {SIGN_POS, TW_Valid, EXP_BIAS - 1,
88 0xd1cf79ac, 0xb17217f7};
89 /* Only the sign (and tag) is used in internal zeroes */
90 FPU_REG CONST_Z = {SIGN_POS, TW_Zero, 0, 0x0, 0x0};
91 /* Only the sign and significand (and tag) are used in internal NaNs */
92 /* The 80486 never generates one of these
93 FPU_REG CONST_SNAN = { SIGN_POS, TW_NaN, EXP_OVER, 0x00000001, 0x80000000 };
94  */
95 /* This is the real indefinite QNaN */
96 FPU_REG CONST_QNaN = {SIGN_NEG, TW_NaN, EXP_OVER, 0x00000000, 0xC0000000};
97 /* Only the sign (and tag) is used in internal infinities */
98 FPU_REG CONST_INF = {SIGN_POS, TW_Infinity, EXP_OVER, 0x00000000, 0x80000000};
99
100
101
102 static void
103 fld_const(FPU_REG * c)
104 {
105         FPU_REG *st_new_ptr;
106
107         if (STACK_OVERFLOW) {
108                 stack_overflow();
109                 return;
110         }
111         push();
112         reg_move(c, FPU_st0_ptr);
113         status_word &= ~SW_C1;
114 }
115
116
117 static void
118 fld1(void)
119 {
120         fld_const(&CONST_1);
121 }
122
123 static void
124 fldl2t(void)
125 {
126         fld_const(&CONST_L2T);
127 }
128
129 static void
130 fldl2e(void)
131 {
132         fld_const(&CONST_L2E);
133 }
134
135 static void
136 fldpi(void)
137 {
138         fld_const(&CONST_PI);
139 }
140
141 static void
142 fldlg2(void)
143 {
144         fld_const(&CONST_LG2);
145 }
146
147 static void
148 fldln2(void)
149 {
150         fld_const(&CONST_LN2);
151 }
152
153 static void
154 fldz(void)
155 {
156         fld_const(&CONST_Z);
157 }
158
159 static FUNC constants_table[] = {
160         fld1, fldl2t, fldl2e, fldpi, fldlg2, fldln2, fldz, Un_impl
161 };
162
163 void
164 fconst(void)
165 {
166         (constants_table[FPU_rm]) ();
167 }