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
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.
15 * Redistribution and use in source and binary forms, with or without
16 * modification, are permitted provided that the following conditions
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
23 * a) an offer to provide the source code for a nominal distribution
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
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
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.
47 * The purpose of this copyright, based upon the Berkeley copyright, is to
48 * ensure that the covered software remains freely available to everyone.
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.
54 * W. Metzenthen June 1994.
57 * $FreeBSD: src/sys/gnu/i386/fpemul/fpu_emu.h,v 1.7 1999/08/28 00:42:50 peter Exp $
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.
71 #define DENORM_OPERAND
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
83 #include <gnu/i386/fpemul/fpu_asm.h>
84 #define Const(x) $/**/x
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 */
93 #define SIGN_POS Const(0)
94 #define SIGN_NEG Const(1)
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 */
104 #define TW_Empty Const(7)/* empty */
106 /* #define TW_FPU_Interrupt Const(0x80) *//* Signals an interrupt */
111 #include <sys/types.h>
112 #include <gnu/i386/fpemul/math_emu.h>
115 extern char emulating;
116 #define REENTRANT_CHECK(state) emulating = (state)
120 #define REENTRANT_CHECK(state)
121 #endif /* PARANOID */
123 typedef void (*FUNC) (void);
124 typedef struct fpu_reg FPU_REG;
126 #define st(x) ( regs[((top+x) &7 )] )
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)
132 extern unsigned char FPU_rm;
134 extern char FPU_st0_tag;
135 extern FPU_REG *FPU_st0_ptr;
137 extern void *FPU_data_address;
139 extern FPU_REG FPU_loaded_data;
141 #define pop() { FPU_st0_ptr->tag = TW_Empty; top++; }
143 /* push() does not affect the tags */
144 #define push() { top--; FPU_st0_ptr = st_new_ptr; }
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); }
153 /*----- Prototypes for functions written in assembler -----*/
154 /* extern void reg_move(FPU_REG *a, FPU_REG *b); */
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);
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);
183 #include <gnu/i386/fpemul/fpu_proto.h>
188 #endif /* _FPU_EMU_H_ */