Initial import from FreeBSD RELENG_4:
[dragonfly.git] / sys / platform / pc32 / 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  */
60
61
62
63 #include <sys/param.h>
64 #include <sys/proc.h>
65 #include <machine/pcb.h>
66
67 #include <gnu/i386/fpemul/fpu_emu.h>
68 #include <gnu/i386/fpemul/fpu_system.h>
69 #include <gnu/i386/fpemul/status_w.h>
70
71
72 FPU_REG CONST_1 = {SIGN_POS, TW_Valid, EXP_BIAS,
73 0x00000000, 0x80000000};
74 static FPU_REG CONST_L2T = {SIGN_POS, TW_Valid, EXP_BIAS + 1,
75 0xcd1b8afe, 0xd49a784b};
76 static FPU_REG CONST_L2E = {SIGN_POS, TW_Valid, EXP_BIAS,
77 0x5c17f0bc, 0xb8aa3b29};
78 FPU_REG CONST_PI = {SIGN_POS, TW_Valid, EXP_BIAS + 1,
79 0x2168c235, 0xc90fdaa2};
80 FPU_REG CONST_PI2 = {SIGN_POS, TW_Valid, EXP_BIAS,
81 0x2168c235, 0xc90fdaa2};
82 FPU_REG CONST_PI4 = {SIGN_POS, TW_Valid, EXP_BIAS - 1,
83 0x2168c235, 0xc90fdaa2};
84 static FPU_REG CONST_LG2 = {SIGN_POS, TW_Valid, EXP_BIAS - 2,
85 0xfbcff799, 0x9a209a84};
86 FPU_REG CONST_LN2 = {SIGN_POS, TW_Valid, EXP_BIAS - 1,
87 0xd1cf79ac, 0xb17217f7};
88 /* Only the sign (and tag) is used in internal zeroes */
89 FPU_REG CONST_Z = {SIGN_POS, TW_Zero, 0, 0x0, 0x0};
90 /* Only the sign and significand (and tag) are used in internal NaNs */
91 /* The 80486 never generates one of these
92 FPU_REG CONST_SNAN = { SIGN_POS, TW_NaN, EXP_OVER, 0x00000001, 0x80000000 };
93  */
94 /* This is the real indefinite QNaN */
95 FPU_REG CONST_QNaN = {SIGN_NEG, TW_NaN, EXP_OVER, 0x00000000, 0xC0000000};
96 /* Only the sign (and tag) is used in internal infinities */
97 FPU_REG CONST_INF = {SIGN_POS, TW_Infinity, EXP_OVER, 0x00000000, 0x80000000};
98
99
100
101 static void
102 fld_const(FPU_REG * c)
103 {
104         FPU_REG *st_new_ptr;
105
106         if (STACK_OVERFLOW) {
107                 stack_overflow();
108                 return;
109         }
110         push();
111         reg_move(c, FPU_st0_ptr);
112         status_word &= ~SW_C1;
113 }
114
115
116 static void
117 fld1(void)
118 {
119         fld_const(&CONST_1);
120 }
121
122 static void
123 fldl2t(void)
124 {
125         fld_const(&CONST_L2T);
126 }
127
128 static void
129 fldl2e(void)
130 {
131         fld_const(&CONST_L2E);
132 }
133
134 static void
135 fldpi(void)
136 {
137         fld_const(&CONST_PI);
138 }
139
140 static void
141 fldlg2(void)
142 {
143         fld_const(&CONST_LG2);
144 }
145
146 static void
147 fldln2(void)
148 {
149         fld_const(&CONST_LN2);
150 }
151
152 static void
153 fldz(void)
154 {
155         fld_const(&CONST_Z);
156 }
157
158 static FUNC constants_table[] = {
159         fld1, fldl2t, fldl2e, fldpi, fldlg2, fldln2, fldz, Un_impl
160 };
161
162 void
163 fconst(void)
164 {
165         (constants_table[FPU_rm]) ();
166 }