]> CyberLeo.Net >> Repos - FreeBSD/releng/10.0.git/blob - lib/libc/softfloat/templates/softfloat.h
- Copy stable/10 (r259064) to releng/10.0 as part of the
[FreeBSD/releng/10.0.git] / lib / libc / softfloat / templates / softfloat.h
1 /* $FreeBSD$ */\r
2 \r
3 /*\r
4 ===============================================================================\r
5 \r
6 This C header file is part of the SoftFloat IEC/IEEE Floating-point\r
7 Arithmetic Package, Release 2a.\r
8 \r
9 Written by John R. Hauser.  This work was made possible in part by the\r
10 International Computer Science Institute, located at Suite 600, 1947 Center\r
11 Street, Berkeley, California 94704.  Funding was partially provided by the\r
12 National Science Foundation under grant MIP-9311980.  The original version\r
13 of this code was written as part of a project to build a fixed-point vector\r
14 processor in collaboration with the University of California at Berkeley,\r
15 overseen by Profs. Nelson Morgan and John Wawrzynek.  More information\r
16 is available through the Web page `http://HTTP.CS.Berkeley.EDU/~jhauser/\r
17 arithmetic/SoftFloat.html'.\r
18 \r
19 THIS SOFTWARE IS DISTRIBUTED AS IS, FOR FREE.  Although reasonable effort\r
20 has been made to avoid it, THIS SOFTWARE MAY CONTAIN FAULTS THAT WILL AT\r
21 TIMES RESULT IN INCORRECT BEHAVIOR.  USE OF THIS SOFTWARE IS RESTRICTED TO\r
22 PERSONS AND ORGANIZATIONS WHO CAN AND WILL TAKE FULL RESPONSIBILITY FOR ANY\r
23 AND ALL LOSSES, COSTS, OR OTHER PROBLEMS ARISING FROM ITS USE.\r
24 \r
25 Derivative works are acceptable, even for commercial purposes, so long as\r
26 (1) they include prominent notice that the work is derivative, and (2) they\r
27 include prominent notice akin to these four paragraphs for those parts of\r
28 this code that are retained.\r
29 \r
30 ===============================================================================\r
31 */\r
32 \r
33 /*\r
34 -------------------------------------------------------------------------------\r
35 The macro `FLOATX80' must be defined to enable the extended double-precision\r
36 floating-point format `floatx80'.  If this macro is not defined, the\r
37 `floatx80' type will not be defined, and none of the functions that either\r
38 input or output the `floatx80' type will be defined.  The same applies to\r
39 the `FLOAT128' macro and the quadruple-precision format `float128'.\r
40 -------------------------------------------------------------------------------\r
41 */\r
42 #define FLOATX80\r
43 #define FLOAT128\r
44 \r
45 /*\r
46 -------------------------------------------------------------------------------\r
47 Software IEC/IEEE floating-point types.\r
48 -------------------------------------------------------------------------------\r
49 */\r
50 typedef !!!bits32 float32;\r
51 typedef !!!bits64 float64;\r
52 #ifdef FLOATX80\r
53 typedef struct {\r
54     !!!bits16 high;\r
55     !!!bits64 low;\r
56 } floatx80;\r
57 #endif\r
58 #ifdef FLOAT128\r
59 typedef struct {\r
60     !!!bits64 high, low;\r
61 } float128;\r
62 #endif\r
63 \r
64 /*\r
65 -------------------------------------------------------------------------------\r
66 Software IEC/IEEE floating-point underflow tininess-detection mode.\r
67 -------------------------------------------------------------------------------\r
68 */\r
69 extern !!!int8 float_detect_tininess;\r
70 enum {\r
71     float_tininess_after_rounding  = 0,\r
72     float_tininess_before_rounding = 1\r
73 };\r
74 \r
75 /*\r
76 -------------------------------------------------------------------------------\r
77 Software IEC/IEEE floating-point rounding mode.\r
78 -------------------------------------------------------------------------------\r
79 */\r
80 extern !!!int8 float_rounding_mode;\r
81 enum {\r
82     float_round_nearest_even = 0,\r
83     float_round_to_zero      = 1,\r
84     float_round_down         = 2,\r
85     float_round_up           = 3\r
86 };\r
87 \r
88 /*\r
89 -------------------------------------------------------------------------------\r
90 Software IEC/IEEE floating-point exception flags.\r
91 -------------------------------------------------------------------------------\r
92 */\r
93 extern !!!int8 float_exception_flags;\r
94 enum {\r
95     float_flag_inexact   =  1,\r
96     float_flag_underflow =  2,\r
97     float_flag_overflow  =  4,\r
98     float_flag_divbyzero =  8,\r
99     float_flag_invalid   = 16\r
100 };\r
101 \r
102 /*\r
103 -------------------------------------------------------------------------------\r
104 Routine to raise any or all of the software IEC/IEEE floating-point\r
105 exception flags.\r
106 -------------------------------------------------------------------------------\r
107 */\r
108 void float_raise( !!!int8 );\r
109 \r
110 /*\r
111 -------------------------------------------------------------------------------\r
112 Software IEC/IEEE integer-to-floating-point conversion routines.\r
113 -------------------------------------------------------------------------------\r
114 */\r
115 float32 int32_to_float32( !!!int32 );\r
116 float64 int32_to_float64( !!!int32 );\r
117 #ifdef FLOATX80\r
118 floatx80 int32_to_floatx80( !!!int32 );\r
119 #endif\r
120 #ifdef FLOAT128\r
121 float128 int32_to_float128( !!!int32 );\r
122 #endif\r
123 float32 int64_to_float32( !!!int64 );\r
124 float64 int64_to_float64( !!!int64 );\r
125 #ifdef FLOATX80\r
126 floatx80 int64_to_floatx80( !!!int64 );\r
127 #endif\r
128 #ifdef FLOAT128\r
129 float128 int64_to_float128( !!!int64 );\r
130 #endif\r
131 \r
132 /*\r
133 -------------------------------------------------------------------------------\r
134 Software IEC/IEEE single-precision conversion routines.\r
135 -------------------------------------------------------------------------------\r
136 */\r
137 !!!int32 float32_to_int32( float32 );\r
138 !!!int32 float32_to_int32_round_to_zero( float32 );\r
139 !!!int64 float32_to_int64( float32 );\r
140 !!!int64 float32_to_int64_round_to_zero( float32 );\r
141 float64 float32_to_float64( float32 );\r
142 #ifdef FLOATX80\r
143 floatx80 float32_to_floatx80( float32 );\r
144 #endif\r
145 #ifdef FLOAT128\r
146 float128 float32_to_float128( float32 );\r
147 #endif\r
148 \r
149 /*\r
150 -------------------------------------------------------------------------------\r
151 Software IEC/IEEE single-precision operations.\r
152 -------------------------------------------------------------------------------\r
153 */\r
154 float32 float32_round_to_int( float32 );\r
155 float32 float32_add( float32, float32 );\r
156 float32 float32_sub( float32, float32 );\r
157 float32 float32_mul( float32, float32 );\r
158 float32 float32_div( float32, float32 );\r
159 float32 float32_rem( float32, float32 );\r
160 float32 float32_sqrt( float32 );\r
161 !!!flag float32_eq( float32, float32 );\r
162 !!!flag float32_le( float32, float32 );\r
163 !!!flag float32_lt( float32, float32 );\r
164 !!!flag float32_eq_signaling( float32, float32 );\r
165 !!!flag float32_le_quiet( float32, float32 );\r
166 !!!flag float32_lt_quiet( float32, float32 );\r
167 !!!flag float32_is_signaling_nan( float32 );\r
168 \r
169 /*\r
170 -------------------------------------------------------------------------------\r
171 Software IEC/IEEE double-precision conversion routines.\r
172 -------------------------------------------------------------------------------\r
173 */\r
174 !!!int32 float64_to_int32( float64 );\r
175 !!!int32 float64_to_int32_round_to_zero( float64 );\r
176 !!!int64 float64_to_int64( float64 );\r
177 !!!int64 float64_to_int64_round_to_zero( float64 );\r
178 float32 float64_to_float32( float64 );\r
179 #ifdef FLOATX80\r
180 floatx80 float64_to_floatx80( float64 );\r
181 #endif\r
182 #ifdef FLOAT128\r
183 float128 float64_to_float128( float64 );\r
184 #endif\r
185 \r
186 /*\r
187 -------------------------------------------------------------------------------\r
188 Software IEC/IEEE double-precision operations.\r
189 -------------------------------------------------------------------------------\r
190 */\r
191 float64 float64_round_to_int( float64 );\r
192 float64 float64_add( float64, float64 );\r
193 float64 float64_sub( float64, float64 );\r
194 float64 float64_mul( float64, float64 );\r
195 float64 float64_div( float64, float64 );\r
196 float64 float64_rem( float64, float64 );\r
197 float64 float64_sqrt( float64 );\r
198 !!!flag float64_eq( float64, float64 );\r
199 !!!flag float64_le( float64, float64 );\r
200 !!!flag float64_lt( float64, float64 );\r
201 !!!flag float64_eq_signaling( float64, float64 );\r
202 !!!flag float64_le_quiet( float64, float64 );\r
203 !!!flag float64_lt_quiet( float64, float64 );\r
204 !!!flag float64_is_signaling_nan( float64 );\r
205 \r
206 #ifdef FLOATX80\r
207 \r
208 /*\r
209 -------------------------------------------------------------------------------\r
210 Software IEC/IEEE extended double-precision conversion routines.\r
211 -------------------------------------------------------------------------------\r
212 */\r
213 !!!int32 floatx80_to_int32( floatx80 );\r
214 !!!int32 floatx80_to_int32_round_to_zero( floatx80 );\r
215 !!!int64 floatx80_to_int64( floatx80 );\r
216 !!!int64 floatx80_to_int64_round_to_zero( floatx80 );\r
217 float32 floatx80_to_float32( floatx80 );\r
218 float64 floatx80_to_float64( floatx80 );\r
219 #ifdef FLOAT128\r
220 float128 floatx80_to_float128( floatx80 );\r
221 #endif\r
222 \r
223 /*\r
224 -------------------------------------------------------------------------------\r
225 Software IEC/IEEE extended double-precision rounding precision.  Valid\r
226 values are 32, 64, and 80.\r
227 -------------------------------------------------------------------------------\r
228 */\r
229 extern !!!int8 floatx80_rounding_precision;\r
230 \r
231 /*\r
232 -------------------------------------------------------------------------------\r
233 Software IEC/IEEE extended double-precision operations.\r
234 -------------------------------------------------------------------------------\r
235 */\r
236 floatx80 floatx80_round_to_int( floatx80 );\r
237 floatx80 floatx80_add( floatx80, floatx80 );\r
238 floatx80 floatx80_sub( floatx80, floatx80 );\r
239 floatx80 floatx80_mul( floatx80, floatx80 );\r
240 floatx80 floatx80_div( floatx80, floatx80 );\r
241 floatx80 floatx80_rem( floatx80, floatx80 );\r
242 floatx80 floatx80_sqrt( floatx80 );\r
243 !!!flag floatx80_eq( floatx80, floatx80 );\r
244 !!!flag floatx80_le( floatx80, floatx80 );\r
245 !!!flag floatx80_lt( floatx80, floatx80 );\r
246 !!!flag floatx80_eq_signaling( floatx80, floatx80 );\r
247 !!!flag floatx80_le_quiet( floatx80, floatx80 );\r
248 !!!flag floatx80_lt_quiet( floatx80, floatx80 );\r
249 !!!flag floatx80_is_signaling_nan( floatx80 );\r
250 \r
251 #endif\r
252 \r
253 #ifdef FLOAT128\r
254 \r
255 /*\r
256 -------------------------------------------------------------------------------\r
257 Software IEC/IEEE quadruple-precision conversion routines.\r
258 -------------------------------------------------------------------------------\r
259 */\r
260 !!!int32 float128_to_int32( float128 );\r
261 !!!int32 float128_to_int32_round_to_zero( float128 );\r
262 !!!int64 float128_to_int64( float128 );\r
263 !!!int64 float128_to_int64_round_to_zero( float128 );\r
264 float32 float128_to_float32( float128 );\r
265 float64 float128_to_float64( float128 );\r
266 #ifdef FLOATX80\r
267 floatx80 float128_to_floatx80( float128 );\r
268 #endif\r
269 \r
270 /*\r
271 -------------------------------------------------------------------------------\r
272 Software IEC/IEEE quadruple-precision operations.\r
273 -------------------------------------------------------------------------------\r
274 */\r
275 float128 float128_round_to_int( float128 );\r
276 float128 float128_add( float128, float128 );\r
277 float128 float128_sub( float128, float128 );\r
278 float128 float128_mul( float128, float128 );\r
279 float128 float128_div( float128, float128 );\r
280 float128 float128_rem( float128, float128 );\r
281 float128 float128_sqrt( float128 );\r
282 !!!flag float128_eq( float128, float128 );\r
283 !!!flag float128_le( float128, float128 );\r
284 !!!flag float128_lt( float128, float128 );\r
285 !!!flag float128_eq_signaling( float128, float128 );\r
286 !!!flag float128_le_quiet( float128, float128 );\r
287 !!!flag float128_lt_quiet( float128, float128 );\r
288 !!!flag float128_is_signaling_nan( float128 );\r
289 \r
290 #endif\r
291 \r