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