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 $
58 * $DragonFly: src/sys/i386/gnu/fpemul/Attic/fpu_emu.h,v 1.3 2003/08/07 21:17:20 dillon Exp $
67 * Define DENORM_OPERAND to make the emulator detect denormals
68 * and use the denormal flag of the status word. Note: this only
69 * affects the flag and corresponding interrupt, the emulator
70 * will always generate denormals and operate upon them as required.
72 #define DENORM_OPERAND
75 * Define PECULIAR_486 to get a closer approximation to 80486 behaviour,
76 * rather than behaviour which appears to be cleaner.
77 * This is a matter of opinion: for all I know, the 80486 may simply
78 * be complying with the IEEE spec. Maybe one day I'll get to see the
85 #define Const(x) $/**/x
90 #define EXP_BIAS Const(0)
91 #define EXP_OVER Const(0x4000) /* smallest invalid large exponent */
92 #define EXP_UNDER Const(-0x3fff) /* largest invalid small exponent */
94 #define SIGN_POS Const(0)
95 #define SIGN_NEG Const(1)
97 /* Keep the order TW_Valid, TW_Zero, TW_Denormal */
98 #define TW_Valid Const(0)/* valid */
99 #define TW_Zero Const(1)/* zero */
100 /* The following fold to 2 (Special) in the Tag Word */
101 #define TW_Denormal Const(4)/* De-normal */
102 #define TW_Infinity Const(5)/* + or - infinity */
103 #define TW_NaN Const(6)/* Not a Number */
105 #define TW_Empty Const(7)/* empty */
107 /* #define TW_FPU_Interrupt Const(0x80) *//* Signals an interrupt */
112 #include <sys/types.h>
113 #include "math_emu.h"
116 extern char emulating;
117 #define REENTRANT_CHECK(state) emulating = (state)
121 #define REENTRANT_CHECK(state)
122 #endif /* PARANOID */
124 typedef void (*FUNC) (void);
125 typedef struct fpu_reg FPU_REG;
127 #define st(x) ( regs[((top+x) &7 )] )
129 #define STACK_OVERFLOW (st_new_ptr = &st(-1), st_new_ptr->tag != TW_Empty)
130 #define NOT_EMPTY(i) (st(i).tag != TW_Empty)
131 #define NOT_EMPTY_0 (FPU_st0_tag ^ TW_Empty)
133 extern unsigned char FPU_rm;
135 extern char FPU_st0_tag;
136 extern FPU_REG *FPU_st0_ptr;
138 extern void *FPU_data_address;
140 extern FPU_REG FPU_loaded_data;
142 #define pop() { FPU_st0_ptr->tag = TW_Empty; top++; }
144 /* push() does not affect the tags */
145 #define push() { top--; FPU_st0_ptr = st_new_ptr; }
148 #define reg_move(x, y) { \
149 *(short *)&((y)->sign) = *(short *)&((x)->sign); \
150 *(long *)&((y)->exp) = *(long *)&((x)->exp); \
151 *(long long *)&((y)->sigl) = *(long long *)&((x)->sigl); }
154 /*----- Prototypes for functions written in assembler -----*/
155 /* extern void reg_move(FPU_REG *a, FPU_REG *b); */
157 extern void mul64(long long *a, long long *b, long long *result);
158 extern void poly_div2(long long *x);
159 extern void poly_div4(long long *x);
160 extern void poly_div16(long long *x);
162 polynomial(unsigned accum[], unsigned x[],
163 unsigned short terms[][4], int n);
164 extern void normalize(FPU_REG * x);
165 extern void normalize_nuo(FPU_REG * x);
166 extern void reg_div(FPU_REG * arg1, FPU_REG * arg2, FPU_REG * answ,
167 unsigned int control_w);
168 extern void reg_u_sub(FPU_REG * arg1, FPU_REG * arg2, FPU_REG * answ,
169 unsigned int control_w);
170 extern void reg_u_mul(FPU_REG * arg1, FPU_REG * arg2, FPU_REG * answ,
171 unsigned int control_w);
172 extern void reg_u_div(FPU_REG * arg1, FPU_REG * arg2, FPU_REG * answ,
173 unsigned int control_w);
174 extern void reg_u_add(FPU_REG * arg1, FPU_REG * arg2, FPU_REG * answ,
175 unsigned int control_w);
176 extern void wm_sqrt(FPU_REG * n, unsigned int control_w);
177 extern unsigned shrx(void *l, unsigned x);
178 extern unsigned shrxs(void *v, unsigned x);
179 extern unsigned long div_small(unsigned long long *x, unsigned long y);
180 extern void round_reg(FPU_REG * arg, unsigned int extent,
181 unsigned int control_w);
184 #include "fpu_proto.h"
189 #endif /* _FPU_EMU_H_ */