Initial import from FreeBSD RELENG_4:
[dragonfly.git] / sys / platform / pc32 / gnu / fpemul / fpu_emu.h
1 /*
2  *  fpu_emu.h
3  *
4  *
5  * Copyright (C) 1992,1993,1994
6  *                       W. Metzenthen, 22 Parker St, Ormond, Vic 3163,
7  *                       Australia.  E-mail   billm@vaxc.cc.monash.edu.au
8  * All rights reserved.
9  *
10  * This copyright notice covers the redistribution and use of the
11  * FPU emulator developed by W. Metzenthen. It covers only its use
12  * in the 386BSD, FreeBSD and NetBSD operating systems. Any other
13  * use is not permitted under this copyright.
14  *
15  * Redistribution and use in source and binary forms, with or without
16  * modification, are permitted provided that the following conditions
17  * are met:
18  * 1. Redistributions of source code must retain the above copyright
19  *    notice, this list of conditions and the following disclaimer.
20  * 2. Redistributions in binary form must include information specifying
21  *    that source code for the emulator is freely available and include
22  *    either:
23  *      a) an offer to provide the source code for a nominal distribution
24  *         fee, or
25  *      b) list at least two alternative methods whereby the source
26  *         can be obtained, e.g. a publically accessible bulletin board
27  *         and an anonymous ftp site from which the software can be
28  *         downloaded.
29  * 3. All advertising materials specifically mentioning features or use of
30  *    this emulator must acknowledge that it was developed by W. Metzenthen.
31  * 4. The name of W. Metzenthen may not be used to endorse or promote
32  *    products derived from this software without specific prior written
33  *    permission.
34  *
35  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
36  * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
37  * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL
38  * W. METZENTHEN BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
39  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
40  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
41  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
42  * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
43  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
44  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
45  *
46  *
47  * The purpose of this copyright, based upon the Berkeley copyright, is to
48  * ensure that the covered software remains freely available to everyone.
49  *
50  * The software (with necessary differences) is also available, but under
51  * the terms of the GNU copyleft, for the Linux operating system and for
52  * the djgpp ms-dos extender.
53  *
54  * W. Metzenthen   June 1994.
55  *
56  *
57  * $FreeBSD: src/sys/gnu/i386/fpemul/fpu_emu.h,v 1.7 1999/08/28 00:42:50 peter Exp $
58  *
59  */
60
61
62 #ifndef _FPU_EMU_H_
63 #define _FPU_EMU_H_
64
65 /*
66  * Define DENORM_OPERAND to make the emulator detect denormals
67  * and use the denormal flag of the status word. Note: this only
68  * affects the flag and corresponding interrupt, the emulator
69  * will always generate denormals and operate upon them as required.
70  */
71 #define DENORM_OPERAND
72
73 /*
74  * Define PECULIAR_486 to get a closer approximation to 80486 behaviour,
75  * rather than behaviour which appears to be cleaner.
76  * This is a matter of opinion: for all I know, the 80486 may simply
77  * be complying with the IEEE spec. Maybe one day I'll get to see the
78  * spec...
79  */
80 #define PECULIAR_486
81
82 #ifdef LOCORE
83 #include <gnu/i386/fpemul/fpu_asm.h>
84 #define Const(x)        $/**/x
85 #else
86 #define Const(x)        x
87 #endif
88
89 #define EXP_BIAS        Const(0)
90 #define EXP_OVER        Const(0x4000)   /* smallest invalid large exponent */
91 #define EXP_UNDER       Const(-0x3fff)  /* largest invalid small exponent */
92
93 #define SIGN_POS        Const(0)
94 #define SIGN_NEG        Const(1)
95
96 /* Keep the order TW_Valid, TW_Zero, TW_Denormal */
97 #define TW_Valid        Const(0)/* valid */
98 #define TW_Zero         Const(1)/* zero */
99 /* The following fold to 2 (Special) in the Tag Word */
100 #define TW_Denormal     Const(4)/* De-normal */
101 #define TW_Infinity     Const(5)/* + or - infinity */
102 #define TW_NaN          Const(6)/* Not a Number */
103
104 #define TW_Empty        Const(7)/* empty */
105
106  /* #define TW_FPU_Interrupt Const(0x80) *//* Signals an interrupt */
107
108
109 #ifndef LOCORE
110
111 #include <sys/types.h>
112 #include <gnu/i386/fpemul/math_emu.h>
113
114 #ifdef PARANOID
115 extern char emulating;
116 #define REENTRANT_CHECK(state) emulating = (state)
117 #define ON 1
118 #define OFF 0
119 #else
120 #define REENTRANT_CHECK(state)
121 #endif                          /* PARANOID */
122
123 typedef void (*FUNC) (void);
124 typedef struct fpu_reg FPU_REG;
125
126 #define st(x)   ( regs[((top+x) &7 )] )
127
128 #define STACK_OVERFLOW  (st_new_ptr = &st(-1), st_new_ptr->tag != TW_Empty)
129 #define NOT_EMPTY(i)    (st(i).tag != TW_Empty)
130 #define NOT_EMPTY_0     (FPU_st0_tag ^ TW_Empty)
131
132 extern unsigned char FPU_rm;
133
134 extern char FPU_st0_tag;
135 extern FPU_REG *FPU_st0_ptr;
136
137 extern void *FPU_data_address;
138
139 extern FPU_REG FPU_loaded_data;
140
141 #define pop()   { FPU_st0_ptr->tag = TW_Empty; top++; }
142
143 /* push() does not affect the tags */
144 #define push()  { top--; FPU_st0_ptr = st_new_ptr; }
145
146
147 #define reg_move(x, y) { \
148                  *(short *)&((y)->sign) = *(short *)&((x)->sign); \
149                  *(long *)&((y)->exp) = *(long *)&((x)->exp); \
150                  *(long long *)&((y)->sigl) = *(long long *)&((x)->sigl); }
151
152
153 /*----- Prototypes for functions written in assembler -----*/
154 /* extern void reg_move(FPU_REG *a, FPU_REG *b); */
155
156 extern void mul64(long long *a, long long *b, long long *result);
157 extern void poly_div2(long long *x);
158 extern void poly_div4(long long *x);
159 extern void poly_div16(long long *x);
160 extern void
161 polynomial(unsigned accum[], unsigned x[],
162     unsigned short terms[][4], int n);
163         extern void normalize(FPU_REG * x);
164         extern void normalize_nuo(FPU_REG * x);
165         extern void reg_div(FPU_REG * arg1, FPU_REG * arg2, FPU_REG * answ,
166             unsigned int control_w);
167         extern void reg_u_sub(FPU_REG * arg1, FPU_REG * arg2, FPU_REG * answ,
168             unsigned int control_w);
169         extern void reg_u_mul(FPU_REG * arg1, FPU_REG * arg2, FPU_REG * answ,
170             unsigned int control_w);
171         extern void reg_u_div(FPU_REG * arg1, FPU_REG * arg2, FPU_REG * answ,
172             unsigned int control_w);
173         extern void reg_u_add(FPU_REG * arg1, FPU_REG * arg2, FPU_REG * answ,
174             unsigned int control_w);
175         extern void wm_sqrt(FPU_REG * n, unsigned int control_w);
176         extern unsigned shrx(void *l, unsigned x);
177         extern unsigned shrxs(void *v, unsigned x);
178         extern unsigned long div_small(unsigned long long *x, unsigned long y);
179         extern void round_reg(FPU_REG * arg, unsigned int extent,
180             unsigned int control_w);
181
182 #ifndef MAKING_PROTO
183 #include <gnu/i386/fpemul/fpu_proto.h>
184 #endif
185
186 #endif                          /* LOCORE */
187
188 #endif                          /* _FPU_EMU_H_ */