1 | /*-
|
---|
2 | * Copyright (c) 1990 Andrew Moore, Talke Studio
|
---|
3 | * All rights reserved.
|
---|
4 | *
|
---|
5 | * Redistribution and use in source and binary forms, with or without
|
---|
6 | * modification, are permitted provided that the following conditions
|
---|
7 | * are met:
|
---|
8 | * 1. Redistributions of source code must retain the above copyright
|
---|
9 | * notice, this list of conditions and the following disclaimer.
|
---|
10 | * 2. Redistributions in binary form must reproduce the above copyright
|
---|
11 | * notice, this list of conditions and the following disclaimer in the
|
---|
12 | * documentation and/or other materials provided with the distribution.
|
---|
13 | * 3. All advertising materials mentioning features or use of this software
|
---|
14 | * must display the following acknowledgement:
|
---|
15 | * This product includes software developed by the University of
|
---|
16 | * California, Berkeley and its contributors.
|
---|
17 | * 4. Neither the name of the University nor the names of its contributors
|
---|
18 | * may be used to endorse or promote products derived from this software
|
---|
19 | * without specific prior written permission.
|
---|
20 | *
|
---|
21 | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
---|
22 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
---|
23 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
---|
24 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
---|
25 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
---|
26 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
---|
27 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
---|
28 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
---|
29 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
---|
30 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
---|
31 | * SUCH DAMAGE.
|
---|
32 | *
|
---|
33 | * from: @(#) ieeefp.h 1.0 (Berkeley) 9/23/93
|
---|
34 | * $FreeBSD: src/sys/i386/include/ieeefp.h,v 1.8 2003/01/19 06:01:33 marcel Exp $
|
---|
35 | */
|
---|
36 | /** @file
|
---|
37 | * FreeBSD 5.1
|
---|
38 | */
|
---|
39 |
|
---|
40 | /*
|
---|
41 | * IEEE floating point type and constant definitions.
|
---|
42 | */
|
---|
43 |
|
---|
44 | #ifndef _MACHINE_IEEEFP_H_
|
---|
45 | #define _MACHINE_IEEEFP_H_
|
---|
46 |
|
---|
47 | /*
|
---|
48 | * FP rounding modes
|
---|
49 | */
|
---|
50 | typedef enum {
|
---|
51 | FP_RN=0, /* round to nearest */
|
---|
52 | FP_RM, /* round down to minus infinity */
|
---|
53 | FP_RP, /* round up to plus infinity */
|
---|
54 | FP_RZ /* truncate */
|
---|
55 | } fp_rnd_t;
|
---|
56 |
|
---|
57 | /*
|
---|
58 | * FP precision modes
|
---|
59 | */
|
---|
60 | typedef enum {
|
---|
61 | FP_PS=0, /* 24 bit (single-precision) */
|
---|
62 | FP_PRS, /* reserved */
|
---|
63 | FP_PD, /* 53 bit (double-precision) */
|
---|
64 | FP_PE /* 64 bit (extended-precision) */
|
---|
65 | } fp_prec_t;
|
---|
66 |
|
---|
67 | #define fp_except_t int
|
---|
68 |
|
---|
69 | /*
|
---|
70 | * FP exception masks
|
---|
71 | */
|
---|
72 | #define FP_X_INV 0x01 /* invalid operation */
|
---|
73 | #define FP_X_DNML 0x02 /* denormal */
|
---|
74 | #define FP_X_DZ 0x04 /* zero divide */
|
---|
75 | #define FP_X_OFL 0x08 /* overflow */
|
---|
76 | #define FP_X_UFL 0x10 /* underflow */
|
---|
77 | #define FP_X_IMP 0x20 /* (im)precision */
|
---|
78 | #define FP_X_STK 0x40 /* stack fault */
|
---|
79 |
|
---|
80 | /*
|
---|
81 | * FP registers
|
---|
82 | */
|
---|
83 | #define FP_MSKS_REG 0 /* exception masks */
|
---|
84 | #define FP_PRC_REG 0 /* precision */
|
---|
85 | #define FP_RND_REG 0 /* direction */
|
---|
86 | #define FP_STKY_REG 1 /* sticky flags */
|
---|
87 |
|
---|
88 | /*
|
---|
89 | * FP register bit field masks
|
---|
90 | */
|
---|
91 | #define FP_MSKS_FLD 0x3f /* exception masks field */
|
---|
92 | #define FP_PRC_FLD 0x300 /* precision control field */
|
---|
93 | #define FP_RND_FLD 0xc00 /* round control field */
|
---|
94 | #define FP_STKY_FLD 0x3f /* sticky flags field */
|
---|
95 |
|
---|
96 | /*
|
---|
97 | * FP register bit field offsets
|
---|
98 | */
|
---|
99 | #define FP_MSKS_OFF 0 /* exception masks offset */
|
---|
100 | #define FP_PRC_OFF 8 /* precision control offset */
|
---|
101 | #define FP_RND_OFF 10 /* round control offset */
|
---|
102 | #define FP_STKY_OFF 0 /* sticky flags offset */
|
---|
103 |
|
---|
104 | #ifdef __GNUC__
|
---|
105 |
|
---|
106 | #define __fldenv(addr) __asm __volatile("fldenv %0" : : "m" (*(addr)))
|
---|
107 | #define __fnstenv(addr) __asm __volatile("fnstenv %0" : "=m" (*(addr)))
|
---|
108 | #define __fnstcw(addr) __asm __volatile("fnstcw %0" : "=m" (*(addr)))
|
---|
109 | #define __fnstsw(addr) __asm __volatile("fnstsw %0" : "=m" (*(addr)))
|
---|
110 |
|
---|
111 | /*
|
---|
112 | * return the contents of a FP register
|
---|
113 | */
|
---|
114 | static __inline__ int
|
---|
115 | __fpgetreg(int _reg)
|
---|
116 | {
|
---|
117 | unsigned short _mem;
|
---|
118 |
|
---|
119 | /*-
|
---|
120 | * This is more efficient than it looks. The switch gets optimized
|
---|
121 | * away if _reg is constant.
|
---|
122 | *
|
---|
123 | * The default case only supports _reg == 0. We could handle more
|
---|
124 | * registers (e.g., tags) using fnstenv, but the interface doesn't
|
---|
125 | * support more.
|
---|
126 | */
|
---|
127 | switch(_reg) {
|
---|
128 | default:
|
---|
129 | __fnstcw(&_mem);
|
---|
130 | break;
|
---|
131 | case FP_STKY_REG:
|
---|
132 | __fnstsw(&_mem);
|
---|
133 | break;
|
---|
134 | }
|
---|
135 | return _mem;
|
---|
136 | }
|
---|
137 |
|
---|
138 | /*
|
---|
139 | * set a FP mode; return previous mode
|
---|
140 | */
|
---|
141 | static __inline__ int
|
---|
142 | __fpsetreg(int _m, int _reg, int _fld, int _off)
|
---|
143 | {
|
---|
144 | unsigned _env[7];
|
---|
145 | unsigned _p;
|
---|
146 |
|
---|
147 | /*
|
---|
148 | * _reg == 0 could be handled better using fnstcw/fldcw.
|
---|
149 | */
|
---|
150 | __fnstenv(_env);
|
---|
151 | _p = (_env[_reg] & _fld) >> _off;
|
---|
152 | _env[_reg] = (_env[_reg] & ~_fld) | (_m << _off & _fld);
|
---|
153 | __fldenv(_env);
|
---|
154 | return _p;
|
---|
155 | }
|
---|
156 |
|
---|
157 | #endif /* __GNUC__ */
|
---|
158 |
|
---|
159 | /*
|
---|
160 | * SysV/386 FP control interface
|
---|
161 | */
|
---|
162 | #define fpgetround() ((fp_rnd_t) \
|
---|
163 | ((__fpgetreg(FP_RND_REG) & FP_RND_FLD) >> FP_RND_OFF))
|
---|
164 | #define fpsetround(m) ((fp_rnd_t) \
|
---|
165 | __fpsetreg((m), FP_RND_REG, FP_RND_FLD, FP_RND_OFF))
|
---|
166 | #define fpgetprec() ((fp_prec_t) \
|
---|
167 | ((__fpgetreg(FP_PRC_REG) & FP_PRC_FLD) >> FP_PRC_OFF))
|
---|
168 | #define fpsetprec(m) ((fp_prec_t) \
|
---|
169 | __fpsetreg((m), FP_PRC_REG, FP_PRC_FLD, FP_PRC_OFF))
|
---|
170 | #define fpgetmask() ((fp_except_t) \
|
---|
171 | ((~__fpgetreg(FP_MSKS_REG) & FP_MSKS_FLD) >> FP_MSKS_OFF))
|
---|
172 | #define fpsetmask(m) ((fp_except_t) \
|
---|
173 | (~__fpsetreg(~(m), FP_MSKS_REG, FP_MSKS_FLD, FP_MSKS_OFF)) & \
|
---|
174 | (FP_MSKS_FLD >> FP_MSKS_OFF))
|
---|
175 | #define fpgetsticky() ((fp_except_t) \
|
---|
176 | ((__fpgetreg(FP_STKY_REG) & FP_STKY_FLD) >> FP_STKY_OFF))
|
---|
177 | #define fpresetsticky(m) ((fp_except_t) \
|
---|
178 | __fpsetreg(0, FP_STKY_REG, (m), FP_STKY_OFF))
|
---|
179 | #define fpsetsticky(m) fpresetsticky(m)
|
---|
180 |
|
---|
181 | /* Suppress prototypes in the MI header. */
|
---|
182 | #define _IEEEFP_INLINED_ 1
|
---|
183 |
|
---|
184 | #endif /* !_MACHINE_IEEEFP_H_ */
|
---|