Numworks Epsilon  1.4.1
Graphing Calculator Operating System
specialize.h
Go to the documentation of this file.
1 
2 /*============================================================================
3 
4 This C header file is part of the SoftFloat IEEE Floating-Point Arithmetic
5 Package, Release 3c, by John R. Hauser.
6 
7 Copyright 2011, 2012, 2013, 2014, 2015, 2016 The Regents of the University of
8 California. All rights reserved.
9 
10 Redistribution and use in source and binary forms, with or without
11 modification, are permitted provided that the following conditions are met:
12 
13  1. Redistributions of source code must retain the above copyright notice,
14  this list of conditions, and the following disclaimer.
15 
16  2. Redistributions in binary form must reproduce the above copyright notice,
17  this list of conditions, and the following disclaimer in the documentation
18  and/or other materials provided with the distribution.
19 
20  3. Neither the name of the University nor the names of its contributors may
21  be used to endorse or promote products derived from this software without
22  specific prior written permission.
23 
24 THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS "AS IS", AND ANY
25 EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
26 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, ARE
27 DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY
28 DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
29 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
30 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
31 ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
32 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
33 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34 
35 =============================================================================*/
36 
37 #ifndef specialize_h
38 #define specialize_h 1
39 
40 #include <stdbool.h>
41 #include <stdint.h>
42 #include "softfloat_types.h"
43 
44 /*----------------------------------------------------------------------------
45 | Default value for `softfloat_detectTininess'.
46 *----------------------------------------------------------------------------*/
47 #define init_detectTininess softfloat_tininess_afterRounding
48 
49 /*----------------------------------------------------------------------------
50 | The values to return on conversions to 32-bit integer formats that raise an
51 | invalid exception.
52 *----------------------------------------------------------------------------*/
53 #define ui32_fromPosOverflow 0xFFFFFFFF
54 #define ui32_fromNegOverflow 0
55 #define ui32_fromNaN 0xFFFFFFFF
56 #define i32_fromPosOverflow 0x7FFFFFFF
57 #define i32_fromNegOverflow (-0x7FFFFFFF - 1)
58 #define i32_fromNaN 0x7FFFFFFF
59 
60 /*----------------------------------------------------------------------------
61 | The values to return on conversions to 64-bit integer formats that raise an
62 | invalid exception.
63 *----------------------------------------------------------------------------*/
64 #define ui64_fromPosOverflow UINT64_C( 0xFFFFFFFFFFFFFFFF )
65 #define ui64_fromNegOverflow 0
66 #define ui64_fromNaN UINT64_C( 0xFFFFFFFFFFFFFFFF )
67 #define i64_fromPosOverflow UINT64_C( 0x7FFFFFFFFFFFFFFF )
68 #define i64_fromNegOverflow (-UINT64_C( 0x7FFFFFFFFFFFFFFF ) - 1)
69 #define i64_fromNaN UINT64_C( 0x7FFFFFFFFFFFFFFF )
70 
71 /*----------------------------------------------------------------------------
72 | "Common NaN" structure, used to transfer NaN representations from one format
73 | to another.
74 *----------------------------------------------------------------------------*/
75 struct commonNaN {
76  bool sign;
77 #ifdef LITTLEENDIAN
78  uint64_t v0, v64;
79 #else
81 #endif
82 };
83 
84 /*----------------------------------------------------------------------------
85 | The bit pattern for a default generated 16-bit floating-point NaN.
86 *----------------------------------------------------------------------------*/
87 #define defaultNaNF16UI 0xFE00
88 
89 /*----------------------------------------------------------------------------
90 | Returns true when 16-bit unsigned integer `uiA' has the bit pattern of a
91 | 16-bit floating-point signaling NaN.
92 | Note: This macro evaluates its argument more than once.
93 *----------------------------------------------------------------------------*/
94 #define softfloat_isSigNaNF16UI( uiA ) ((((uiA) & 0x7E00) == 0x7C00) && ((uiA) & 0x01FF))
95 
96 /*----------------------------------------------------------------------------
97 | Assuming `uiA' has the bit pattern of a 16-bit floating-point NaN, converts
98 | this NaN to the common NaN form, and stores the resulting common NaN at the
99 | location pointed to by `zPtr'. If the NaN is a signaling NaN, the invalid
100 | exception is raised.
101 *----------------------------------------------------------------------------*/
102 void softfloat_f16UIToCommonNaN( uint_fast16_t uiA, struct commonNaN *zPtr );
103 
104 /*----------------------------------------------------------------------------
105 | Converts the common NaN pointed to by `aPtr' into a 16-bit floating-point
106 | NaN, and returns the bit pattern of this value as an unsigned integer.
107 *----------------------------------------------------------------------------*/
109 
110 /*----------------------------------------------------------------------------
111 | Interpreting `uiA' and `uiB' as the bit patterns of two 16-bit floating-
112 | point values, at least one of which is a NaN, returns the bit pattern of
113 | the combined NaN result. If either `uiA' or `uiB' has the pattern of a
114 | signaling NaN, the invalid exception is raised.
115 *----------------------------------------------------------------------------*/
118 
119 /*----------------------------------------------------------------------------
120 | The bit pattern for a default generated 32-bit floating-point NaN.
121 *----------------------------------------------------------------------------*/
122 #define defaultNaNF32UI 0xFFC00000
123 
124 /*----------------------------------------------------------------------------
125 | Returns true when 32-bit unsigned integer `uiA' has the bit pattern of a
126 | 32-bit floating-point signaling NaN.
127 | Note: This macro evaluates its argument more than once.
128 *----------------------------------------------------------------------------*/
129 #define softfloat_isSigNaNF32UI( uiA ) ((((uiA) & 0x7FC00000) == 0x7F800000) && ((uiA) & 0x003FFFFF))
130 
131 /*----------------------------------------------------------------------------
132 | Assuming `uiA' has the bit pattern of a 32-bit floating-point NaN, converts
133 | this NaN to the common NaN form, and stores the resulting common NaN at the
134 | location pointed to by `zPtr'. If the NaN is a signaling NaN, the invalid
135 | exception is raised.
136 *----------------------------------------------------------------------------*/
137 void softfloat_f32UIToCommonNaN( uint_fast32_t uiA, struct commonNaN *zPtr );
138 
139 /*----------------------------------------------------------------------------
140 | Converts the common NaN pointed to by `aPtr' into a 32-bit floating-point
141 | NaN, and returns the bit pattern of this value as an unsigned integer.
142 *----------------------------------------------------------------------------*/
144 
145 /*----------------------------------------------------------------------------
146 | Interpreting `uiA' and `uiB' as the bit patterns of two 32-bit floating-
147 | point values, at least one of which is a NaN, returns the bit pattern of
148 | the combined NaN result. If either `uiA' or `uiB' has the pattern of a
149 | signaling NaN, the invalid exception is raised.
150 *----------------------------------------------------------------------------*/
153 
154 /*----------------------------------------------------------------------------
155 | The bit pattern for a default generated 64-bit floating-point NaN.
156 *----------------------------------------------------------------------------*/
157 #define defaultNaNF64UI UINT64_C( 0xFFF8000000000000 )
158 
159 /*----------------------------------------------------------------------------
160 | Returns true when 64-bit unsigned integer `uiA' has the bit pattern of a
161 | 64-bit floating-point signaling NaN.
162 | Note: This macro evaluates its argument more than once.
163 *----------------------------------------------------------------------------*/
164 #define softfloat_isSigNaNF64UI( uiA ) ((((uiA) & UINT64_C( 0x7FF8000000000000 )) == UINT64_C( 0x7FF0000000000000 )) && ((uiA) & UINT64_C( 0x0007FFFFFFFFFFFF )))
165 
166 /*----------------------------------------------------------------------------
167 | Assuming `uiA' has the bit pattern of a 64-bit floating-point NaN, converts
168 | this NaN to the common NaN form, and stores the resulting common NaN at the
169 | location pointed to by `zPtr'. If the NaN is a signaling NaN, the invalid
170 | exception is raised.
171 *----------------------------------------------------------------------------*/
172 void softfloat_f64UIToCommonNaN( uint_fast64_t uiA, struct commonNaN *zPtr );
173 
174 /*----------------------------------------------------------------------------
175 | Converts the common NaN pointed to by `aPtr' into a 64-bit floating-point
176 | NaN, and returns the bit pattern of this value as an unsigned integer.
177 *----------------------------------------------------------------------------*/
179 
180 /*----------------------------------------------------------------------------
181 | Interpreting `uiA' and `uiB' as the bit patterns of two 64-bit floating-
182 | point values, at least one of which is a NaN, returns the bit pattern of
183 | the combined NaN result. If either `uiA' or `uiB' has the pattern of a
184 | signaling NaN, the invalid exception is raised.
185 *----------------------------------------------------------------------------*/
188 
189 /*----------------------------------------------------------------------------
190 | The bit pattern for a default generated 80-bit extended floating-point NaN.
191 *----------------------------------------------------------------------------*/
192 #define defaultNaNExtF80UI64 0xFFFF
193 #define defaultNaNExtF80UI0 UINT64_C( 0xC000000000000000 )
194 
195 /*----------------------------------------------------------------------------
196 | Returns true when the 80-bit unsigned integer formed from concatenating
197 | 16-bit `uiA64' and 64-bit `uiA0' has the bit pattern of an 80-bit extended
198 | floating-point signaling NaN.
199 | Note: This macro evaluates its arguments more than once.
200 *----------------------------------------------------------------------------*/
201 #define softfloat_isSigNaNExtF80UI( uiA64, uiA0 ) ((((uiA64) & 0x7FFF) == 0x7FFF) && ! ((uiA0) & UINT64_C( 0x4000000000000000 )) && ((uiA0) & UINT64_C( 0x3FFFFFFFFFFFFFFF )))
202 
203 #ifdef SOFTFLOAT_FAST_INT64
204 
205 /*----------------------------------------------------------------------------
206 | The following functions are needed only when `SOFTFLOAT_FAST_INT64' is
207 | defined.
208 *----------------------------------------------------------------------------*/
209 
210 /*----------------------------------------------------------------------------
211 | Assuming the unsigned integer formed from concatenating `uiA64' and `uiA0'
212 | has the bit pattern of an 80-bit extended floating-point NaN, converts
213 | this NaN to the common NaN form, and stores the resulting common NaN at the
214 | location pointed to by `zPtr'. If the NaN is a signaling NaN, the invalid
215 | exception is raised.
216 *----------------------------------------------------------------------------*/
217 void
218  softfloat_extF80UIToCommonNaN(
219  uint_fast16_t uiA64, uint_fast64_t uiA0, struct commonNaN *zPtr );
220 
221 /*----------------------------------------------------------------------------
222 | Converts the common NaN pointed to by `aPtr' into an 80-bit extended
223 | floating-point NaN, and returns the bit pattern of this value as an unsigned
224 | integer.
225 *----------------------------------------------------------------------------*/
226 struct uint128 softfloat_commonNaNToExtF80UI( const struct commonNaN *aPtr );
227 
228 /*----------------------------------------------------------------------------
229 | Interpreting the unsigned integer formed from concatenating `uiA64' and
230 | `uiA0' as an 80-bit extended floating-point value, and likewise interpreting
231 | the unsigned integer formed from concatenating `uiB64' and `uiB0' as another
232 | 80-bit extended floating-point value, and assuming at least on of these
233 | floating-point values is a NaN, returns the bit pattern of the combined NaN
234 | result. If either original floating-point value is a signaling NaN, the
235 | invalid exception is raised.
236 *----------------------------------------------------------------------------*/
237 struct uint128
238  softfloat_propagateNaNExtF80UI(
239  uint_fast16_t uiA64,
240  uint_fast64_t uiA0,
241  uint_fast16_t uiB64,
242  uint_fast64_t uiB0
243  );
244 
245 /*----------------------------------------------------------------------------
246 | The bit pattern for a default generated 128-bit floating-point NaN.
247 *----------------------------------------------------------------------------*/
248 #define defaultNaNF128UI64 UINT64_C( 0xFFFF800000000000 )
249 #define defaultNaNF128UI0 UINT64_C( 0 )
250 
251 /*----------------------------------------------------------------------------
252 | Returns true when the 128-bit unsigned integer formed from concatenating
253 | 64-bit `uiA64' and 64-bit `uiA0' has the bit pattern of a 128-bit floating-
254 | point signaling NaN.
255 | Note: This macro evaluates its arguments more than once.
256 *----------------------------------------------------------------------------*/
257 #define softfloat_isSigNaNF128UI( uiA64, uiA0 ) ((((uiA64) & UINT64_C( 0x7FFF800000000000 )) == UINT64_C( 0x7FFF000000000000 )) && ((uiA0) || ((uiA64) & UINT64_C( 0x00007FFFFFFFFFFF ))))
258 
259 /*----------------------------------------------------------------------------
260 | Assuming the unsigned integer formed from concatenating `uiA64' and `uiA0'
261 | has the bit pattern of a 128-bit floating-point NaN, converts this NaN to
262 | the common NaN form, and stores the resulting common NaN at the location
263 | pointed to by `zPtr'. If the NaN is a signaling NaN, the invalid exception
264 | is raised.
265 *----------------------------------------------------------------------------*/
266 void
267  softfloat_f128UIToCommonNaN(
268  uint_fast64_t uiA64, uint_fast64_t uiA0, struct commonNaN *zPtr );
269 
270 /*----------------------------------------------------------------------------
271 | Converts the common NaN pointed to by `aPtr' into a 128-bit floating-point
272 | NaN, and returns the bit pattern of this value as an unsigned integer.
273 *----------------------------------------------------------------------------*/
274 struct uint128 softfloat_commonNaNToF128UI( const struct commonNaN * );
275 
276 /*----------------------------------------------------------------------------
277 | Interpreting the unsigned integer formed from concatenating `uiA64' and
278 | `uiA0' as a 128-bit floating-point value, and likewise interpreting the
279 | unsigned integer formed from concatenating `uiB64' and `uiB0' as another
280 | 128-bit floating-point value, and assuming at least on of these floating-
281 | point values is a NaN, returns the bit pattern of the combined NaN result.
282 | If either original floating-point value is a signaling NaN, the invalid
283 | exception is raised.
284 *----------------------------------------------------------------------------*/
285 struct uint128
286  softfloat_propagateNaNF128UI(
287  uint_fast64_t uiA64,
288  uint_fast64_t uiA0,
289  uint_fast64_t uiB64,
290  uint_fast64_t uiB0
291  );
292 
293 #else
294 
295 /*----------------------------------------------------------------------------
296 | The following functions are needed only when `SOFTFLOAT_FAST_INT64' is not
297 | defined.
298 *----------------------------------------------------------------------------*/
299 
300 /*----------------------------------------------------------------------------
301 | Assuming the 80-bit extended floating-point value pointed to by `aSPtr' is
302 | a NaN, converts this NaN to the common NaN form, and stores the resulting
303 | common NaN at the location pointed to by `zPtr'. If the NaN is a signaling
304 | NaN, the invalid exception is raised.
305 *----------------------------------------------------------------------------*/
306 void
308  const struct extFloat80M *aSPtr, struct commonNaN *zPtr );
309 
310 /*----------------------------------------------------------------------------
311 | Converts the common NaN pointed to by `aPtr' into an 80-bit extended
312 | floating-point NaN, and stores this NaN at the location pointed to by
313 | `zSPtr'.
314 *----------------------------------------------------------------------------*/
315 void
317  const struct commonNaN *aPtr, struct extFloat80M *zSPtr );
318 
319 /*----------------------------------------------------------------------------
320 | Assuming at least one of the two 80-bit extended floating-point values
321 | pointed to by `aSPtr' and `bSPtr' is a NaN, stores the combined NaN result
322 | at the location pointed to by `zSPtr'. If either original floating-point
323 | value is a signaling NaN, the invalid exception is raised.
324 *----------------------------------------------------------------------------*/
325 void
327  const struct extFloat80M *aSPtr,
328  const struct extFloat80M *bSPtr,
329  struct extFloat80M *zSPtr
330  );
331 
332 /*----------------------------------------------------------------------------
333 | The bit pattern for a default generated 128-bit floating-point NaN.
334 *----------------------------------------------------------------------------*/
335 #define defaultNaNF128UI96 0xFFFF8000
336 #define defaultNaNF128UI64 0
337 #define defaultNaNF128UI32 0
338 #define defaultNaNF128UI0 0
339 
340 /*----------------------------------------------------------------------------
341 | Assuming the 128-bit floating-point value pointed to by `aWPtr' is a NaN,
342 | converts this NaN to the common NaN form, and stores the resulting common
343 | NaN at the location pointed to by `zPtr'. If the NaN is a signaling NaN,
344 | the invalid exception is raised. Argument `aWPtr' points to an array of
345 | four 32-bit elements that concatenate in the platform's normal endian order
346 | to form a 128-bit floating-point value.
347 *----------------------------------------------------------------------------*/
348 void
349  softfloat_f128MToCommonNaN( const uint32_t *aWPtr, struct commonNaN *zPtr );
350 
351 /*----------------------------------------------------------------------------
352 | Converts the common NaN pointed to by `aPtr' into a 128-bit floating-point
353 | NaN, and stores this NaN at the location pointed to by `zWPtr'. Argument
354 | `zWPtr' points to an array of four 32-bit elements that concatenate in the
355 | platform's normal endian order to form a 128-bit floating-point value.
356 *----------------------------------------------------------------------------*/
357 void
358  softfloat_commonNaNToF128M( const struct commonNaN *aPtr, uint32_t *zWPtr );
359 
360 /*----------------------------------------------------------------------------
361 | Assuming at least one of the two 128-bit floating-point values pointed to by
362 | `aWPtr' and `bWPtr' is a NaN, stores the combined NaN result at the location
363 | pointed to by `zWPtr'. If either original floating-point value is a
364 | signaling NaN, the invalid exception is raised. Each of `aWPtr', `bWPtr',
365 | and `zWPtr' points to an array of four 32-bit elements that concatenate in
366 | the platform's normal endian order to form a 128-bit floating-point value.
367 *----------------------------------------------------------------------------*/
368 void
370  const uint32_t *aWPtr, const uint32_t *bWPtr, uint32_t *zWPtr );
371 
372 #endif
373 
374 #endif
375 
void softfloat_f32UIToCommonNaN(uint_fast32_t uiA, struct commonNaN *zPtr)
void softfloat_commonNaNToExtF80M(const struct commonNaN *aPtr, struct extFloat80M *zSPtr)
void softfloat_extF80MToCommonNaN(const struct extFloat80M *aSPtr, struct commonNaN *zPtr)
uint32_t uint_fast16_t
Definition: stdint.h:18
uint_fast32_t softfloat_propagateNaNF32UI(uint_fast32_t uiA, uint_fast32_t uiB)
uint_fast32_t softfloat_commonNaNToF32UI(const struct commonNaN *aPtr)
void softfloat_propagateNaNExtF80M(const struct extFloat80M *aSPtr, const struct extFloat80M *bSPtr, struct extFloat80M *zSPtr)
void softfloat_f16UIToCommonNaN(uint_fast16_t uiA, struct commonNaN *zPtr)
void softfloat_commonNaNToF128M(const struct commonNaN *aPtr, uint32_t *zWPtr)
uint_fast64_t softfloat_commonNaNToF64UI(const struct commonNaN *aPtr)
uint64_t v0
Definition: specialize.h:80
void softfloat_propagateNaNF128M(const uint32_t *aWPtr, const uint32_t *bWPtr, uint32_t *zWPtr)
void softfloat_f128MToCommonNaN(const uint32_t *aWPtr, struct commonNaN *zPtr)
unsigned int uint32_t
Definition: stdint.h:6
uint_fast64_t softfloat_propagateNaNF64UI(uint_fast64_t uiA, uint_fast64_t uiB)
unsigned long long uint64_t
Definition: stdint.h:7
void softfloat_f64UIToCommonNaN(uint_fast64_t uiA, struct commonNaN *zPtr)
uint_fast16_t softfloat_commonNaNToF16UI(const struct commonNaN *aPtr)
bool sign
Definition: specialize.h:76
uint64_t uint_fast64_t
Definition: stdint.h:20
uint_fast16_t softfloat_propagateNaNF16UI(uint_fast16_t uiA, uint_fast16_t uiB)
uint64_t v64
Definition: specialize.h:80
uint32_t uint_fast32_t
Definition: stdint.h:19