2 * Copyright (c) 2003 Peter Wemm.
3 * Copyright (c) 1990 Andrew Moore, Talke Studio
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 * 3. All advertising materials mentioning features or use of this software
15 * must display the following acknowledgement:
16 * This product includes software developed by the University of
17 * California, Berkeley and its contributors.
18 * 4. Neither the name of the University nor the names of its contributors
19 * may be used to endorse or promote products derived from this software
20 * without specific prior written permission.
22 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
23 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
26 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
28 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34 * from: @(#) ieeefp.h 1.0 (Berkeley) 9/23/93
38 #ifndef _MACHINE_IEEEFP_H_
39 #define _MACHINE_IEEEFP_H_
42 * IEEE floating point type, constant and function definitions.
43 * XXX: FP*FLD, FP*REG and FP*OFF are undocumented pollution.
47 #error this file needs sys/cdefs.h as a prerequisite
54 FP_RN=0, /* round to nearest */
55 FP_RM, /* round down towards minus infinity */
56 FP_RP, /* round up towards plus infinity */
61 * Precision (i.e., rounding precision) modes.
64 FP_PS=0, /* 24 bit (single-precision) */
65 FP_PRS, /* reserved */
66 FP_PD, /* 53 bit (double-precision) */
67 FP_PE /* 64 bit (extended-precision) */
70 #define fp_except_t int
73 * Exception bit masks.
75 #define FP_X_INV 0x01 /* invalid operation */
76 #define FP_X_DNML 0x02 /* denormal */
77 #define FP_X_DZ 0x04 /* zero divide */
78 #define FP_X_OFL 0x08 /* overflow */
79 #define FP_X_UFL 0x10 /* underflow */
80 #define FP_X_IMP 0x20 /* (im)precision */
81 #define FP_X_STK 0x40 /* stack fault */
84 * FPU control and status register numbers (indexes into the env array).
86 #define FP_MSKS_REG 0 /* exception masks */
87 #define FP_PRC_REG 0 /* precision */
88 #define FP_RND_REG 0 /* direction */
89 #define FP_STKY_REG 1 /* sticky flags */
92 * FPU control word bit-field masks.
94 #define FP_MSKS_FLD 0x3f /* exception masks field */
95 #define FP_PRC_FLD 0x300 /* precision control field */
96 #define FP_RND_FLD 0xc00 /* rounding control field */
99 * FPU status word bit-field masks.
101 #define FP_STKY_FLD 0x3f /* sticky flags field */
104 * FPU control word bit-field offsets (shift counts).
106 #define FP_MSKS_OFF 0 /* exception masks offset */
107 #define FP_PRC_OFF 8 /* precision control offset */
108 #define FP_RND_OFF 10 /* rounding control offset */
111 * FPU status word bit-field offsets (shift counts).
113 #define FP_STKY_OFF 0 /* sticky flags offset */
115 #ifdef __GNUCLIKE_ASM
117 #define __fldenv(addr) __asm __volatile("fldenv %0" : : "m" (*(addr)))
118 #define __fnclex() __asm __volatile("fnclex")
119 #define __fnstcw(addr) __asm __volatile("fnstcw %0" : "=m" (*(addr)))
120 #define __fnstenv(addr) __asm __volatile("fnstenv %0" : "=m" (*(addr)))
121 #define __fnstsw(addr) __asm __volatile("fnstsw %0" : "=m" (*(addr)))
124 * return the contents of a FP register
126 static __inline__ int
132 * This is more efficient than it looks. The switch gets optimized
133 * away if _reg is constant.
135 * The default case only supports _reg == 0. We could handle more
136 * registers (e.g., tags) using fnstenv, but the interface doesn't
151 * set a FP mode; return previous mode
153 static __inline__ int
154 __fpsetreg(int _m, int _reg, int _fld, int _off)
160 * _reg == 0 could be handled better using fnstcw/fldcw.
163 _p = (_env[_reg] & _fld) >> _off;
164 _env[_reg] = (_env[_reg] & ~_fld) | (_m << _off & _fld);
170 * SysV/386 FP control interface
172 #define fpgetround() ((fp_rnd_t) \
173 ((__fpgetreg(FP_RND_REG) & FP_RND_FLD) >> FP_RND_OFF))
174 #define fpsetround(m) ((fp_rnd_t) \
175 __fpsetreg((m), FP_RND_REG, FP_RND_FLD, FP_RND_OFF))
176 #define fpgetprec() ((fp_prec_t) \
177 ((__fpgetreg(FP_PRC_REG) & FP_PRC_FLD) >> FP_PRC_OFF))
178 #define fpsetprec(m) ((fp_prec_t) \
179 __fpsetreg((m), FP_PRC_REG, FP_PRC_FLD, FP_PRC_OFF))
180 #define fpgetmask() ((fp_except_t) \
181 ((~__fpgetreg(FP_MSKS_REG) & FP_MSKS_FLD) >> FP_MSKS_OFF))
182 #define fpsetmask(m) ((fp_except_t) \
183 (~__fpsetreg(~(m), FP_MSKS_REG, FP_MSKS_FLD, FP_MSKS_OFF)) & \
184 (FP_MSKS_FLD >> FP_MSKS_OFF))
185 #define fpgetsticky() ((fp_except_t) \
186 ((__fpgetreg(FP_STKY_REG) & FP_STKY_FLD) >> FP_STKY_OFF))
188 static __inline fp_except_t
189 fpresetsticky(fp_except_t _m)
198 _m &= FP_STKY_FLD >> FP_STKY_OFF;
200 if ((_p & ~_m) == _p)
202 if ((_p & ~_m) == 0) {
212 #endif /* __GNUCLIKE_ASM */
214 /* Suppress prototypes in the MI header. */
215 #define _IEEEFP_INLINED_ 1
217 #endif /* !_MACHINE_IEEEFP_H_ */