Fix debug reset.
[riscv-isa-sim.git] / softfloat / specialize.h
1
2 /*============================================================================
3
4 This C header file is part of the SoftFloat IEEE Floating-Point Arithmetic
5 Package, Release 3a+, 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 "primitiveTypes.h"
43 #include "softfloat.h"
44
45 /*----------------------------------------------------------------------------
46 | Default value for `softfloat_detectTininess'.
47 *----------------------------------------------------------------------------*/
48 #define init_detectTininess softfloat_tininess_afterRounding
49
50 /*----------------------------------------------------------------------------
51 | The values to return on conversions to 32-bit integer format that raise an
52 | invalid exception.
53 *----------------------------------------------------------------------------*/
54 #define ui32_fromPosOverflow 0xFFFFFFFF
55 #define ui32_fromNegOverflow 0
56 #define ui32_fromNaN 0xFFFFFFFF
57 #define i32_fromPosOverflow 0x7FFFFFFF
58 #define i32_fromNegOverflow (-0x7FFFFFFF - 1)
59 #define i32_fromNaN 0x7FFFFFFF
60
61 /*----------------------------------------------------------------------------
62 | The values to return on conversions to 64-bit integer format that raise an
63 | invalid exception.
64 *----------------------------------------------------------------------------*/
65 #define ui64_fromPosOverflow UINT64_C( 0xFFFFFFFFFFFFFFFF )
66 #define ui64_fromNegOverflow 0
67 #define ui64_fromNaN UINT64_C( 0xFFFFFFFFFFFFFFFF )
68 #define i64_fromPosOverflow UINT64_C( 0x7FFFFFFFFFFFFFFF )
69 #define i64_fromNegOverflow (-UINT64_C( 0x7FFFFFFFFFFFFFFF ) - 1)
70 #define i64_fromNaN UINT64_C( 0x7FFFFFFFFFFFFFFF )
71
72 /*----------------------------------------------------------------------------
73 | "Common NaN" structure, used to transfer NaN representations from one format
74 | to another.
75 *----------------------------------------------------------------------------*/
76 struct commonNaN { char _unused; };
77
78 /*----------------------------------------------------------------------------
79 | The bit pattern for a default generated 32-bit floating-point NaN.
80 *----------------------------------------------------------------------------*/
81 #define defaultNaNF32UI 0x7FC00000
82
83 /*----------------------------------------------------------------------------
84 | Returns true when 32-bit unsigned integer `uiA' has the bit pattern of a
85 | 32-bit floating-point signaling NaN.
86 | Note: This macro evaluates its argument more than once.
87 *----------------------------------------------------------------------------*/
88 #define softfloat_isSigNaNF32UI( uiA ) ((((uiA) & 0x7FC00000) == 0x7F800000) && ((uiA) & 0x003FFFFF))
89
90 /*----------------------------------------------------------------------------
91 | Assuming `uiA' has the bit pattern of a 32-bit floating-point NaN, converts
92 | this NaN to the common NaN form, and stores the resulting common NaN at the
93 | location pointed to by `zPtr'. If the NaN is a signaling NaN, the invalid
94 | exception is raised.
95 *----------------------------------------------------------------------------*/
96 #define softfloat_f32UIToCommonNaN( uiA, zPtr ) if ( ! ((uiA) & 0x00400000) ) softfloat_raiseFlags( softfloat_flag_invalid )
97
98 /*----------------------------------------------------------------------------
99 | Converts the common NaN pointed to by `aPtr' into a 32-bit floating-point
100 | NaN, and returns the bit pattern of this value as an unsigned integer.
101 *----------------------------------------------------------------------------*/
102 #define softfloat_commonNaNToF32UI( aPtr ) ((uint_fast32_t) defaultNaNF32UI)
103
104 /*----------------------------------------------------------------------------
105 | Interpreting `uiA' and `uiB' as the bit patterns of two 32-bit floating-
106 | point values, at least one of which is a NaN, returns the bit pattern of
107 | the combined NaN result. If either `uiA' or `uiB' has the pattern of a
108 | signaling NaN, the invalid exception is raised.
109 *----------------------------------------------------------------------------*/
110 uint_fast32_t
111 softfloat_propagateNaNF32UI( uint_fast32_t uiA, uint_fast32_t uiB );
112
113 /*----------------------------------------------------------------------------
114 | The bit pattern for a default generated 64-bit floating-point NaN.
115 *----------------------------------------------------------------------------*/
116 #define defaultNaNF64UI UINT64_C( 0x7FF8000000000000 )
117
118 /*----------------------------------------------------------------------------
119 | Returns true when 64-bit unsigned integer `uiA' has the bit pattern of a
120 | 64-bit floating-point signaling NaN.
121 | Note: This macro evaluates its argument more than once.
122 *----------------------------------------------------------------------------*/
123 #define softfloat_isSigNaNF64UI( uiA ) ((((uiA) & UINT64_C( 0x7FF8000000000000 )) == UINT64_C( 0x7FF0000000000000 )) && ((uiA) & UINT64_C( 0x0007FFFFFFFFFFFF )))
124
125 /*----------------------------------------------------------------------------
126 | Assuming `uiA' has the bit pattern of a 64-bit floating-point NaN, converts
127 | this NaN to the common NaN form, and stores the resulting common NaN at the
128 | location pointed to by `zPtr'. If the NaN is a signaling NaN, the invalid
129 | exception is raised.
130 *----------------------------------------------------------------------------*/
131 #define softfloat_f64UIToCommonNaN( uiA, zPtr ) if ( ! ((uiA) & UINT64_C( 0x0008000000000000 )) ) softfloat_raiseFlags( softfloat_flag_invalid )
132
133 /*----------------------------------------------------------------------------
134 | Converts the common NaN pointed to by `aPtr' into a 64-bit floating-point
135 | NaN, and returns the bit pattern of this value as an unsigned integer.
136 *----------------------------------------------------------------------------*/
137 #define softfloat_commonNaNToF64UI( aPtr ) ((uint_fast64_t) defaultNaNF64UI)
138
139 /*----------------------------------------------------------------------------
140 | Interpreting `uiA' and `uiB' as the bit patterns of two 64-bit floating-
141 | point values, at least one of which is a NaN, returns the bit pattern of
142 | the combined NaN result. If either `uiA' or `uiB' has the pattern of a
143 | signaling NaN, the invalid exception is raised.
144 *----------------------------------------------------------------------------*/
145 uint_fast64_t
146 softfloat_propagateNaNF64UI( uint_fast64_t uiA, uint_fast64_t uiB );
147
148 /*----------------------------------------------------------------------------
149 | The bit pattern for a default generated 80-bit extended floating-point NaN.
150 *----------------------------------------------------------------------------*/
151 #define defaultNaNExtF80UI64 0x7FFF
152 #define defaultNaNExtF80UI0 UINT64_C( 0xC000000000000000 )
153
154 /*----------------------------------------------------------------------------
155 | Returns true when the 80-bit unsigned integer formed from concatenating
156 | 16-bit `uiA64' and 64-bit `uiA0' has the bit pattern of an 80-bit extended
157 | floating-point signaling NaN.
158 | Note: This macro evaluates its arguments more than once.
159 *----------------------------------------------------------------------------*/
160 #define softfloat_isSigNaNExtF80UI( uiA64, uiA0 ) ((((uiA64) & 0x7FFF) == 0x7FFF) && ! ((uiA0) & UINT64_C( 0x4000000000000000 )) && ((uiA0) & UINT64_C( 0x3FFFFFFFFFFFFFFF )))
161
162 #ifdef SOFTFLOAT_FAST_INT64
163
164 /*----------------------------------------------------------------------------
165 | The following functions are needed only when `SOFTFLOAT_FAST_INT64' is
166 | defined.
167 *----------------------------------------------------------------------------*/
168
169 /*----------------------------------------------------------------------------
170 | Assuming the unsigned integer formed from concatenating `uiA64' and `uiA0'
171 | has the bit pattern of an 80-bit extended floating-point NaN, converts
172 | this NaN to the common NaN form, and stores the resulting common NaN at the
173 | location pointed to by `zPtr'. If the NaN is a signaling NaN, the invalid
174 | exception is raised.
175 *----------------------------------------------------------------------------*/
176 #define softfloat_extF80UIToCommonNaN( uiA64, uiA0, zPtr ) if ( ! ((uiA0) & UINT64_C( 0x4000000000000000 )) ) softfloat_raiseFlags( softfloat_flag_invalid )
177
178 /*----------------------------------------------------------------------------
179 | Converts the common NaN pointed to by `aPtr' into an 80-bit extended
180 | floating-point NaN, and returns the bit pattern of this value as an unsigned
181 | integer.
182 *----------------------------------------------------------------------------*/
183 #if defined INLINE && ! defined softfloat_commonNaNToExtF80UI
184 INLINE
185 struct uint128 softfloat_commonNaNToExtF80UI( const struct commonNaN *aPtr )
186 {
187 struct uint128 uiZ;
188 uiZ.v64 = defaultNaNExtF80UI64;
189 uiZ.v0 = defaultNaNExtF80UI0;
190 return uiZ;
191 }
192 #else
193 struct uint128 softfloat_commonNaNToExtF80UI( const struct commonNaN *aPtr );
194 #endif
195
196 /*----------------------------------------------------------------------------
197 | Interpreting the unsigned integer formed from concatenating `uiA64' and
198 | `uiA0' as an 80-bit extended floating-point value, and likewise interpreting
199 | the unsigned integer formed from concatenating `uiB64' and `uiB0' as another
200 | 80-bit extended floating-point value, and assuming at least on of these
201 | floating-point values is a NaN, returns the bit pattern of the combined NaN
202 | result. If either original floating-point value is a signaling NaN, the
203 | invalid exception is raised.
204 *----------------------------------------------------------------------------*/
205 struct uint128
206 softfloat_propagateNaNExtF80UI(
207 uint_fast16_t uiA64,
208 uint_fast64_t uiA0,
209 uint_fast16_t uiB64,
210 uint_fast64_t uiB0
211 );
212
213 /*----------------------------------------------------------------------------
214 | The bit pattern for a default generated 128-bit floating-point NaN.
215 *----------------------------------------------------------------------------*/
216 #define defaultNaNF128UI64 UINT64_C( 0x7FFF800000000000 )
217 #define defaultNaNF128UI0 UINT64_C( 0 )
218
219 /*----------------------------------------------------------------------------
220 | Returns true when the 128-bit unsigned integer formed from concatenating
221 | 64-bit `uiA64' and 64-bit `uiA0' has the bit pattern of a 128-bit floating-
222 | point signaling NaN.
223 | Note: This macro evaluates its arguments more than once.
224 *----------------------------------------------------------------------------*/
225 #define softfloat_isSigNaNF128UI( uiA64, uiA0 ) ((((uiA64) & UINT64_C( 0x7FFF800000000000 )) == UINT64_C( 0x7FFF000000000000 )) && ((uiA0) || ((uiA64) & UINT64_C( 0x00007FFFFFFFFFFF ))))
226
227 /*----------------------------------------------------------------------------
228 | Assuming the unsigned integer formed from concatenating `uiA64' and `uiA0'
229 | has the bit pattern of a 128-bit floating-point NaN, converts this NaN to
230 | the common NaN form, and stores the resulting common NaN at the location
231 | pointed to by `zPtr'. If the NaN is a signaling NaN, the invalid exception
232 | is raised.
233 *----------------------------------------------------------------------------*/
234 #define softfloat_f128UIToCommonNaN( uiA64, uiA0, zPtr ) if ( ! ((uiA64) & UINT64_C( 0x0000800000000000 )) ) softfloat_raiseFlags( softfloat_flag_invalid )
235
236 /*----------------------------------------------------------------------------
237 | Converts the common NaN pointed to by `aPtr' into a 128-bit floating-point
238 | NaN, and returns the bit pattern of this value as an unsigned integer.
239 *----------------------------------------------------------------------------*/
240 #if defined INLINE && ! defined softfloat_commonNaNToF128UI
241 INLINE
242 struct uint128 softfloat_commonNaNToF128UI( const struct commonNaN *aPtr )
243 {
244 struct uint128 uiZ;
245 uiZ.v64 = defaultNaNF128UI64;
246 uiZ.v0 = defaultNaNF128UI0;
247 return uiZ;
248 }
249 #else
250 struct uint128 softfloat_commonNaNToF128UI( const struct commonNaN * );
251 #endif
252
253 /*----------------------------------------------------------------------------
254 | Interpreting the unsigned integer formed from concatenating `uiA64' and
255 | `uiA0' as a 128-bit floating-point value, and likewise interpreting the
256 | unsigned integer formed from concatenating `uiB64' and `uiB0' as another
257 | 128-bit floating-point value, and assuming at least on of these floating-
258 | point values is a NaN, returns the bit pattern of the combined NaN result.
259 | If either original floating-point value is a signaling NaN, the invalid
260 | exception is raised.
261 *----------------------------------------------------------------------------*/
262 struct uint128
263 softfloat_propagateNaNF128UI(
264 uint_fast64_t uiA64,
265 uint_fast64_t uiA0,
266 uint_fast64_t uiB64,
267 uint_fast64_t uiB0
268 );
269
270 #else
271
272 /*----------------------------------------------------------------------------
273 | The following functions are needed only when `SOFTFLOAT_FAST_INT64' is not
274 | defined.
275 *----------------------------------------------------------------------------*/
276
277 /*----------------------------------------------------------------------------
278 | Assuming the 80-bit extended floating-point value pointed to by `aSPtr' is
279 | a NaN, converts this NaN to the common NaN form, and stores the resulting
280 | common NaN at the location pointed to by `zPtr'. If the NaN is a signaling
281 | NaN, the invalid exception is raised.
282 *----------------------------------------------------------------------------*/
283 #define softfloat_extF80MToCommonNaN( aSPtr, zPtr ) if ( ! ((aSPtr)->signif & UINT64_C( 0x4000000000000000 )) ) softfloat_raiseFlags( softfloat_flag_invalid )
284
285 /*----------------------------------------------------------------------------
286 | Converts the common NaN pointed to by `aPtr' into an 80-bit extended
287 | floating-point NaN, and stores this NaN at the location pointed to by
288 | `zSPtr'.
289 *----------------------------------------------------------------------------*/
290 #if defined INLINE && ! defined softfloat_commonNaNToExtF80M
291 INLINE
292 void
293 softfloat_commonNaNToExtF80M(
294 const struct commonNaN *aPtr, struct extFloat80M *zSPtr )
295 {
296 zSPtr->signExp = defaultNaNExtF80UI64;
297 zSPtr->signif = defaultNaNExtF80UI0;
298 }
299 #else
300 void
301 softfloat_commonNaNToExtF80M(
302 const struct commonNaN *aPtr, struct extFloat80M *zSPtr );
303 #endif
304
305 /*----------------------------------------------------------------------------
306 | Assuming at least one of the two 80-bit extended floating-point values
307 | pointed to by `aSPtr' and `bSPtr' is a NaN, stores the combined NaN result
308 | at the location pointed to by `zSPtr'. If either original floating-point
309 | value is a signaling NaN, the invalid exception is raised.
310 *----------------------------------------------------------------------------*/
311 void
312 softfloat_propagateNaNExtF80M(
313 const struct extFloat80M *aSPtr,
314 const struct extFloat80M *bSPtr,
315 struct extFloat80M *zSPtr
316 );
317
318 /*----------------------------------------------------------------------------
319 | The bit pattern for a default generated 128-bit floating-point NaN.
320 *----------------------------------------------------------------------------*/
321 #define defaultNaNF128UI96 0xFFFFFFFF
322 #define defaultNaNF128UI64 0xFFFFFFFF
323 #define defaultNaNF128UI32 0xFFFFFFFF
324 #define defaultNaNF128UI0 0xFFFFFFFF
325
326 /*----------------------------------------------------------------------------
327 | Assuming the 128-bit floating-point value pointed to by `aWPtr' is a NaN,
328 | converts this NaN to the common NaN form, and stores the resulting common
329 | NaN at the location pointed to by `zPtr'. If the NaN is a signaling NaN,
330 | the invalid exception is raised. Argument `aWPtr' points to an array of
331 | four 32-bit elements that concatenate in the platform's normal endian order
332 | to form a 128-bit floating-point value.
333 *----------------------------------------------------------------------------*/
334 #define softfloat_f128MToCommonNaN( aWPtr, zPtr ) if ( ! ((aWPtr)[indexWordHi( 4 )] & UINT64_C( 0x0000800000000000 )) ) softfloat_raiseFlags( softfloat_flag_invalid )
335
336 /*----------------------------------------------------------------------------
337 | Converts the common NaN pointed to by `aPtr' into a 128-bit floating-point
338 | NaN, and stores this NaN at the location pointed to by `zWPtr'. Argument
339 | `zWPtr' points to an array of four 32-bit elements that concatenate in the
340 | platform's normal endian order to form a 128-bit floating-point value.
341 *----------------------------------------------------------------------------*/
342 #if defined INLINE && ! defined softfloat_commonNaNToF128M
343 INLINE
344 void
345 softfloat_commonNaNToF128M( const struct commonNaN *aPtr, uint32_t *zWPtr )
346 {
347 zWPtr[indexWord( 4, 3 )] = defaultNaNF128UI96;
348 zWPtr[indexWord( 4, 2 )] = defaultNaNF128UI64;
349 zWPtr[indexWord( 4, 1 )] = defaultNaNF128UI32;
350 zWPtr[indexWord( 4, 0 )] = defaultNaNF128UI0;
351 }
352 #else
353 void
354 softfloat_commonNaNToF128M( const struct commonNaN *aPtr, uint32_t *zWPtr );
355 #endif
356
357 /*----------------------------------------------------------------------------
358 | Assuming at least one of the two 128-bit floating-point values pointed to by
359 | `aWPtr' and `bWPtr' is a NaN, stores the combined NaN result at the location
360 | pointed to by `zWPtr'. If either original floating-point value is a
361 | signaling NaN, the invalid exception is raised. Each of `aWPtr', `bWPtr',
362 | and `zWPtr' points to an array of four 32-bit elements that concatenate in
363 | the platform's normal endian order to form a 128-bit floating-point value.
364 *----------------------------------------------------------------------------*/
365 void
366 softfloat_propagateNaNF128M(
367 const uint32_t *aWPtr, const uint32_t *bWPtr, uint32_t *zWPtr );
368
369 #endif
370
371 #endif
372