VirtualBox

source: vbox/trunk/src/libs/softfloat-3e/source/8086-SSE/specialize.h@ 94681

Last change on this file since 94681 was 94558, checked in by vboxsync, 3 years ago

VMM/IEM,libs/softfloat: Don't use global variables in SoftFloat, pass in a state pointer to (almost) all functions instead. Started on fsqrt instruction implementation. bugref:9898

  • Property svn:eol-style set to native
File size: 19.8 KB
Line 
1
2/*============================================================================
3
4This C header file is part of the SoftFloat IEEE Floating-Point Arithmetic
5Package, Release 3e, by John R. Hauser.
6
7Copyright 2011, 2012, 2013, 2014, 2015, 2016, 2018 The Regents of the
8University of California. All rights reserved.
9
10Redistribution and use in source and binary forms, with or without
11modification, 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
24THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS "AS IS", AND ANY
25EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
26WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, ARE
27DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY
28DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
29(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
30LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
31ON 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
33SOFTWARE, 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*----------------------------------------------------------------------------*/
76struct 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*----------------------------------------------------------------------------*/
103void softfloat_f16UIToCommonNaN( uint_fast16_t uiA, struct commonNaN *zPtr SOFTFLOAT_STATE_DECL_COMMA );
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*----------------------------------------------------------------------------*/
109uint_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*----------------------------------------------------------------------------*/
117uint_fast16_t
118 softfloat_propagateNaNF16UI( uint_fast16_t uiA, uint_fast16_t uiB SOFTFLOAT_STATE_DECL_COMMA );
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*----------------------------------------------------------------------------*/
138void softfloat_f32UIToCommonNaN( uint_fast32_t uiA, struct commonNaN *zPtr SOFTFLOAT_STATE_DECL_COMMA );
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*----------------------------------------------------------------------------*/
144uint_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*----------------------------------------------------------------------------*/
152uint_fast32_t
153 softfloat_propagateNaNF32UI( uint_fast32_t uiA, uint_fast32_t uiB SOFTFLOAT_STATE_DECL_COMMA );
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*----------------------------------------------------------------------------*/
173void softfloat_f64UIToCommonNaN( uint_fast64_t uiA, struct commonNaN *zPtr SOFTFLOAT_STATE_DECL_COMMA );
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*----------------------------------------------------------------------------*/
179uint_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*----------------------------------------------------------------------------*/
187uint_fast64_t
188 softfloat_propagateNaNF64UI( uint_fast64_t uiA, uint_fast64_t uiB SOFTFLOAT_STATE_DECL_COMMA );
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*----------------------------------------------------------------------------*/
218void
219 softfloat_extF80UIToCommonNaN(
220 uint_fast16_t uiA64, uint_fast64_t uiA0, struct commonNaN *zPtr SOFTFLOAT_STATE_DECL_COMMA );
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*----------------------------------------------------------------------------*/
227struct 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*----------------------------------------------------------------------------*/
238struct 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 SOFTFLOAT_STATE_DECL_COMMA
245 );
246
247/*----------------------------------------------------------------------------
248| The bit pattern for a default generated 128-bit floating-point NaN.
249*----------------------------------------------------------------------------*/
250#define defaultNaNF128UI64 UINT64_C( 0xFFFF800000000000 )
251#define defaultNaNF128UI0 UINT64_C( 0 )
252
253/*----------------------------------------------------------------------------
254| Returns true when the 128-bit unsigned integer formed from concatenating
255| 64-bit 'uiA64' and 64-bit 'uiA0' has the bit pattern of a 128-bit floating-
256| point signaling NaN.
257| Note: This macro evaluates its arguments more than once.
258*----------------------------------------------------------------------------*/
259#define softfloat_isSigNaNF128UI( uiA64, uiA0 ) ((((uiA64) & UINT64_C( 0x7FFF800000000000 )) == UINT64_C( 0x7FFF000000000000 )) && ((uiA0) || ((uiA64) & UINT64_C( 0x00007FFFFFFFFFFF ))))
260
261/*----------------------------------------------------------------------------
262| Assuming the unsigned integer formed from concatenating 'uiA64' and 'uiA0'
263| has the bit pattern of a 128-bit floating-point NaN, converts this NaN to
264| the common NaN form, and stores the resulting common NaN at the location
265| pointed to by 'zPtr'. If the NaN is a signaling NaN, the invalid exception
266| is raised.
267*----------------------------------------------------------------------------*/
268void
269 softfloat_f128UIToCommonNaN(
270 uint_fast64_t uiA64, uint_fast64_t uiA0, struct commonNaN *zPtr SOFTFLOAT_STATE_DECL_COMMA );
271
272/*----------------------------------------------------------------------------
273| Converts the common NaN pointed to by 'aPtr' into a 128-bit floating-point
274| NaN, and returns the bit pattern of this value as an unsigned integer.
275*----------------------------------------------------------------------------*/
276struct uint128 softfloat_commonNaNToF128UI( const struct commonNaN * );
277
278/*----------------------------------------------------------------------------
279| Interpreting the unsigned integer formed from concatenating 'uiA64' and
280| 'uiA0' as a 128-bit floating-point value, and likewise interpreting the
281| unsigned integer formed from concatenating 'uiB64' and 'uiB0' as another
282| 128-bit floating-point value, and assuming at least on of these floating-
283| point values is a NaN, returns the bit pattern of the combined NaN result.
284| If either original floating-point value is a signaling NaN, the invalid
285| exception is raised.
286*----------------------------------------------------------------------------*/
287struct uint128
288 softfloat_propagateNaNF128UI(
289 uint_fast64_t uiA64,
290 uint_fast64_t uiA0,
291 uint_fast64_t uiB64,
292 uint_fast64_t uiB0
293 SOFTFLOAT_STATE_DECL_COMMA
294 );
295
296#else
297
298/*----------------------------------------------------------------------------
299| The following functions are needed only when 'SOFTFLOAT_FAST_INT64' is not
300| defined.
301*----------------------------------------------------------------------------*/
302
303/*----------------------------------------------------------------------------
304| Assuming the 80-bit extended floating-point value pointed to by 'aSPtr' is
305| a NaN, converts this NaN to the common NaN form, and stores the resulting
306| common NaN at the location pointed to by 'zPtr'. If the NaN is a signaling
307| NaN, the invalid exception is raised.
308*----------------------------------------------------------------------------*/
309void
310 softfloat_extF80MToCommonNaN(
311 const struct extFloat80M *aSPtr, struct commonNaN *zPtr SOFTFLOAT_STATE_DECL_COMMA );
312
313/*----------------------------------------------------------------------------
314| Converts the common NaN pointed to by 'aPtr' into an 80-bit extended
315| floating-point NaN, and stores this NaN at the location pointed to by
316| 'zSPtr'.
317*----------------------------------------------------------------------------*/
318void
319 softfloat_commonNaNToExtF80M(
320 const struct commonNaN *aPtr, struct extFloat80M *zSPtr );
321
322/*----------------------------------------------------------------------------
323| Assuming at least one of the two 80-bit extended floating-point values
324| pointed to by 'aSPtr' and 'bSPtr' is a NaN, stores the combined NaN result
325| at the location pointed to by 'zSPtr'. If either original floating-point
326| value is a signaling NaN, the invalid exception is raised.
327*----------------------------------------------------------------------------*/
328void
329 softfloat_propagateNaNExtF80M(
330 const struct extFloat80M *aSPtr,
331 const struct extFloat80M *bSPtr,
332 struct extFloat80M *zSPtr
333 SOFTFLOAT_STATE_DECL_COMMA
334 );
335
336/*----------------------------------------------------------------------------
337| The bit pattern for a default generated 128-bit floating-point NaN.
338*----------------------------------------------------------------------------*/
339#define defaultNaNF128UI96 0xFFFF8000
340#define defaultNaNF128UI64 0
341#define defaultNaNF128UI32 0
342#define defaultNaNF128UI0 0
343
344/*----------------------------------------------------------------------------
345| Assuming the 128-bit floating-point value pointed to by 'aWPtr' is a NaN,
346| converts this NaN to the common NaN form, and stores the resulting common
347| NaN at the location pointed to by 'zPtr'. If the NaN is a signaling NaN,
348| the invalid exception is raised. Argument 'aWPtr' points to an array of
349| four 32-bit elements that concatenate in the platform's normal endian order
350| to form a 128-bit floating-point value.
351*----------------------------------------------------------------------------*/
352void
353 softfloat_f128MToCommonNaN( const uint32_t *aWPtr, struct commonNaN *zPtr SOFTFLOAT_STATE_DECL_COMMA );
354
355/*----------------------------------------------------------------------------
356| Converts the common NaN pointed to by 'aPtr' into a 128-bit floating-point
357| NaN, and stores this NaN at the location pointed to by 'zWPtr'. Argument
358| 'zWPtr' points to an array of four 32-bit elements that concatenate in the
359| platform's normal endian order to form a 128-bit floating-point value.
360*----------------------------------------------------------------------------*/
361void
362 softfloat_commonNaNToF128M( const struct commonNaN *aPtr, uint32_t *zWPtr );
363
364/*----------------------------------------------------------------------------
365| Assuming at least one of the two 128-bit floating-point values pointed to by
366| 'aWPtr' and 'bWPtr' is a NaN, stores the combined NaN result at the location
367| pointed to by 'zWPtr'. If either original floating-point value is a
368| signaling NaN, the invalid exception is raised. Each of 'aWPtr', 'bWPtr',
369| and 'zWPtr' points to an array of four 32-bit elements that concatenate in
370| the platform's normal endian order to form a 128-bit floating-point value.
371*----------------------------------------------------------------------------*/
372void
373 softfloat_propagateNaNF128M(
374 const uint32_t *aWPtr, const uint32_t *bWPtr, uint32_t *zWPtr SOFTFLOAT_STATE_DECL_COMMA );
375
376#endif
377
378#endif
379
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette