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, 2017 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 internals_h
|
---|
38 | #define internals_h 1
|
---|
39 |
|
---|
40 | #include <stdbool.h>
|
---|
41 | #include <stdint.h>
|
---|
42 | #include "primitives.h"
|
---|
43 | #include "softfloat_types.h"
|
---|
44 |
|
---|
45 | union ui16_f16 { uint16_t ui; float16_t f; };
|
---|
46 | union ui32_f32 { uint32_t ui; float32_t f; };
|
---|
47 | union ui64_f64 { uint64_t ui; float64_t f; };
|
---|
48 |
|
---|
49 | #ifdef SOFTFLOAT_FAST_INT64
|
---|
50 | union extF80M_extF80 { struct extFloat80M fM; extFloat80_t f; };
|
---|
51 | # define EXTF80M_EXTF80_INIT( a_signExp, a_signif ) { EXTFLOAT80M_INIT( a_signExp, a_signif ) } /* VBox */
|
---|
52 | # define EXTF80M_EXTF80_INIT3( a_sign, a_signif, a_exp ) { EXTFLOAT80M_INIT3( a_sign, a_signif, a_exp ) } /* VBox */
|
---|
53 | # define EXTF80M_EXTF80_INIT_C( a_signExp, a_signif ) { EXTFLOAT80M_INIT_C( a_signExp, a_signif ) } /* VBox */
|
---|
54 | # define EXTF80M_EXTF80_INIT3_C( a_sign, a_signif, a_exp ) { EXTFLOAT80M_INIT3_C( a_sign, a_signif, a_exp ) } /* VBox */
|
---|
55 | union ui128_f128 { struct uint128 ui; float128_t f; };
|
---|
56 | #endif
|
---|
57 |
|
---|
58 | enum {
|
---|
59 | softfloat_mulAdd_subC = 1,
|
---|
60 | softfloat_mulAdd_subProd = 2
|
---|
61 | };
|
---|
62 |
|
---|
63 | /*----------------------------------------------------------------------------
|
---|
64 | *----------------------------------------------------------------------------*/
|
---|
65 | uint_fast32_t softfloat_roundToUI32( bool, uint_fast64_t, uint_fast8_t, bool SOFTFLOAT_STATE_DECL_COMMA );
|
---|
66 |
|
---|
67 | #ifdef SOFTFLOAT_FAST_INT64
|
---|
68 | uint_fast64_t
|
---|
69 | softfloat_roundToUI64(
|
---|
70 | bool, uint_fast64_t, uint_fast64_t, uint_fast8_t, bool SOFTFLOAT_STATE_DECL_COMMA );
|
---|
71 | #else
|
---|
72 | uint_fast64_t softfloat_roundMToUI64( bool, uint32_t *, uint_fast8_t, bool SOFTFLOAT_STATE_DECL_COMMA );
|
---|
73 | #endif
|
---|
74 |
|
---|
75 | int_fast32_t softfloat_roundToI32( bool, uint_fast64_t, uint_fast8_t, bool SOFTFLOAT_STATE_DECL_COMMA );
|
---|
76 |
|
---|
77 | #ifdef SOFTFLOAT_FAST_INT64
|
---|
78 | int_fast64_t
|
---|
79 | softfloat_roundToI64(
|
---|
80 | bool, uint_fast64_t, uint_fast64_t, uint_fast8_t, bool SOFTFLOAT_STATE_DECL_COMMA );
|
---|
81 | #else
|
---|
82 | int_fast64_t softfloat_roundMToI64( bool, uint32_t *, uint_fast8_t, bool SOFTFLOAT_STATE_DECL_COMMA );
|
---|
83 | #endif
|
---|
84 |
|
---|
85 | /*----------------------------------------------------------------------------
|
---|
86 | *----------------------------------------------------------------------------*/
|
---|
87 | #define signF16UI( a ) ((bool) ((uint16_t) (a)>>15))
|
---|
88 | #define expF16UI( a ) ((int_fast8_t) ((a)>>10) & 0x1F)
|
---|
89 | #define fracF16UI( a ) ((a) & 0x03FF)
|
---|
90 | #define packToF16UI( sign, exp, sig ) (((uint16_t) (sign)<<15) + ((uint16_t) (exp)<<10) + (sig))
|
---|
91 |
|
---|
92 | #define isNaNF16UI( a ) (((~(a) & 0x7C00) == 0) && ((a) & 0x03FF))
|
---|
93 |
|
---|
94 | struct exp8_sig16 { int_fast8_t exp; uint_fast16_t sig; };
|
---|
95 | struct exp8_sig16 softfloat_normSubnormalF16Sig( uint_fast16_t );
|
---|
96 |
|
---|
97 | float16_t softfloat_roundPackToF16( bool, int_fast16_t, uint_fast16_t SOFTFLOAT_STATE_DECL_COMMA );
|
---|
98 | float16_t softfloat_normRoundPackToF16( bool, int_fast16_t, uint_fast16_t SOFTFLOAT_STATE_DECL_COMMA );
|
---|
99 |
|
---|
100 | float16_t softfloat_addMagsF16( uint_fast16_t, uint_fast16_t SOFTFLOAT_STATE_DECL_COMMA );
|
---|
101 | float16_t softfloat_subMagsF16( uint_fast16_t, uint_fast16_t SOFTFLOAT_STATE_DECL_COMMA );
|
---|
102 | float16_t
|
---|
103 | softfloat_mulAddF16(
|
---|
104 | uint_fast16_t, uint_fast16_t, uint_fast16_t, uint_fast8_t SOFTFLOAT_STATE_DECL_COMMA );
|
---|
105 |
|
---|
106 | /*----------------------------------------------------------------------------
|
---|
107 | *----------------------------------------------------------------------------*/
|
---|
108 | #define signF32UI( a ) ((bool) ((uint32_t) (a)>>31))
|
---|
109 | #define expF32UI( a ) ((int_fast16_t) ((a)>>23) & 0xFF)
|
---|
110 | #define fracF32UI( a ) ((a) & 0x007FFFFF)
|
---|
111 | #define packToF32UI( sign, exp, sig ) (((uint32_t) (sign)<<31) + ((uint32_t) (exp)<<23) + (sig))
|
---|
112 |
|
---|
113 | #define isNaNF32UI( a ) (((~(a) & 0x7F800000) == 0) && ((a) & 0x007FFFFF))
|
---|
114 |
|
---|
115 | struct exp16_sig32 { int_fast16_t exp; uint_fast32_t sig; };
|
---|
116 | struct exp16_sig32 softfloat_normSubnormalF32Sig( uint_fast32_t );
|
---|
117 |
|
---|
118 | float32_t softfloat_roundPackToF32( bool, int_fast16_t, uint_fast32_t SOFTFLOAT_STATE_DECL_COMMA );
|
---|
119 | float32_t softfloat_normRoundPackToF32( bool, int_fast16_t, uint_fast32_t SOFTFLOAT_STATE_DECL_COMMA );
|
---|
120 |
|
---|
121 | float32_t softfloat_addMagsF32( uint_fast32_t, uint_fast32_t SOFTFLOAT_STATE_DECL_COMMA );
|
---|
122 | float32_t softfloat_subMagsF32( uint_fast32_t, uint_fast32_t SOFTFLOAT_STATE_DECL_COMMA );
|
---|
123 | float32_t
|
---|
124 | softfloat_mulAddF32(
|
---|
125 | uint_fast32_t, uint_fast32_t, uint_fast32_t, uint_fast8_t SOFTFLOAT_STATE_DECL_COMMA );
|
---|
126 |
|
---|
127 | /*----------------------------------------------------------------------------
|
---|
128 | *----------------------------------------------------------------------------*/
|
---|
129 | #define signF64UI( a ) ((bool) ((uint64_t) (a)>>63))
|
---|
130 | #define expF64UI( a ) ((int_fast16_t) ((a)>>52) & 0x7FF)
|
---|
131 | #define fracF64UI( a ) ((a) & UINT64_C( 0x000FFFFFFFFFFFFF ))
|
---|
132 | #define packToF64UI( sign, exp, sig ) ((uint64_t) (((uint_fast64_t) (sign)<<63) + ((uint_fast64_t) (exp)<<52) + (sig)))
|
---|
133 |
|
---|
134 | #define isNaNF64UI( a ) (((~(a) & UINT64_C( 0x7FF0000000000000 )) == 0) && ((a) & UINT64_C( 0x000FFFFFFFFFFFFF )))
|
---|
135 |
|
---|
136 | struct exp16_sig64 { int_fast16_t exp; uint_fast64_t sig; };
|
---|
137 | struct exp16_sig64 softfloat_normSubnormalF64Sig( uint_fast64_t );
|
---|
138 |
|
---|
139 | float64_t softfloat_roundPackToF64( bool, int_fast16_t, uint_fast64_t SOFTFLOAT_STATE_DECL_COMMA );
|
---|
140 | float64_t softfloat_normRoundPackToF64( bool, int_fast16_t, uint_fast64_t SOFTFLOAT_STATE_DECL_COMMA );
|
---|
141 |
|
---|
142 | float64_t softfloat_addMagsF64( uint_fast64_t, uint_fast64_t, bool SOFTFLOAT_STATE_DECL_COMMA );
|
---|
143 | float64_t softfloat_subMagsF64( uint_fast64_t, uint_fast64_t, bool SOFTFLOAT_STATE_DECL_COMMA );
|
---|
144 | float64_t
|
---|
145 | softfloat_mulAddF64(
|
---|
146 | uint_fast64_t, uint_fast64_t, uint_fast64_t, uint_fast8_t SOFTFLOAT_STATE_DECL_COMMA );
|
---|
147 |
|
---|
148 | /*----------------------------------------------------------------------------
|
---|
149 | *----------------------------------------------------------------------------*/
|
---|
150 | #define signExtF80UI64( a64 ) ((bool) ((uint16_t) (a64)>>15))
|
---|
151 | #define expExtF80UI64( a64 ) ((a64) & 0x7FFF)
|
---|
152 | #define packToExtF80UI64( sign, exp ) ((uint_fast16_t) (sign)<<15 | (exp))
|
---|
153 |
|
---|
154 | #define isNaNExtF80UI( a64, a0 ) ((((a64) & 0x7FFF) == 0x7FFF) && ((a0) & UINT64_C( 0x7FFFFFFFFFFFFFFF )))
|
---|
155 |
|
---|
156 | #ifdef SOFTFLOAT_FAST_INT64
|
---|
157 |
|
---|
158 | /*----------------------------------------------------------------------------
|
---|
159 | *----------------------------------------------------------------------------*/
|
---|
160 |
|
---|
161 | struct exp32_sig64 { int_fast32_t exp; uint64_t sig; };
|
---|
162 | struct exp32_sig64 softfloat_normSubnormalExtF80Sig( uint_fast64_t );
|
---|
163 |
|
---|
164 | extFloat80_t
|
---|
165 | softfloat_roundPackToExtF80(
|
---|
166 | bool, int_fast32_t, uint_fast64_t, uint_fast64_t, uint_fast8_t SOFTFLOAT_STATE_DECL_COMMA );
|
---|
167 | extFloat80_t
|
---|
168 | softfloat_normRoundPackToExtF80(
|
---|
169 | bool, int_fast32_t, uint_fast64_t, uint_fast64_t, uint_fast8_t SOFTFLOAT_STATE_DECL_COMMA );
|
---|
170 |
|
---|
171 | extFloat80_t
|
---|
172 | softfloat_addMagsExtF80(
|
---|
173 | uint_fast16_t, uint_fast64_t, uint_fast16_t, uint_fast64_t, bool SOFTFLOAT_STATE_DECL_COMMA );
|
---|
174 | extFloat80_t
|
---|
175 | softfloat_subMagsExtF80(
|
---|
176 | uint_fast16_t, uint_fast64_t, uint_fast16_t, uint_fast64_t, bool SOFTFLOAT_STATE_DECL_COMMA );
|
---|
177 |
|
---|
178 | /*----------------------------------------------------------------------------
|
---|
179 | *----------------------------------------------------------------------------*/
|
---|
180 | #define signF128UI64( a64 ) ((bool) ((uint64_t) (a64)>>63))
|
---|
181 | #define expF128UI64( a64 ) ((int_fast32_t) ((a64)>>48) & 0x7FFF)
|
---|
182 | #define fracF128UI64( a64 ) ((a64) & UINT64_C( 0x0000FFFFFFFFFFFF ))
|
---|
183 | #define packToF128UI64( sign, exp, sig64 ) (((uint_fast64_t) (sign)<<63) + ((uint_fast64_t) (exp)<<48) + (sig64))
|
---|
184 |
|
---|
185 | #define isNaNF128UI( a64, a0 ) (((~(a64) & UINT64_C( 0x7FFF000000000000 )) == 0) && (a0 || ((a64) & UINT64_C( 0x0000FFFFFFFFFFFF ))))
|
---|
186 |
|
---|
187 | struct exp32_sig128 { int_fast32_t exp; struct uint128 sig; };
|
---|
188 | struct exp32_sig128
|
---|
189 | softfloat_normSubnormalF128Sig( uint_fast64_t, uint_fast64_t );
|
---|
190 |
|
---|
191 | float128_t
|
---|
192 | softfloat_roundPackToF128(
|
---|
193 | bool, int_fast32_t, uint_fast64_t, uint_fast64_t, uint_fast64_t SOFTFLOAT_STATE_DECL_COMMA );
|
---|
194 | float128_t
|
---|
195 | softfloat_normRoundPackToF128(
|
---|
196 | bool, int_fast32_t, uint_fast64_t, uint_fast64_t SOFTFLOAT_STATE_DECL_COMMA );
|
---|
197 |
|
---|
198 | float128_t
|
---|
199 | softfloat_addMagsF128(
|
---|
200 | uint_fast64_t, uint_fast64_t, uint_fast64_t, uint_fast64_t, bool SOFTFLOAT_STATE_DECL_COMMA );
|
---|
201 | float128_t
|
---|
202 | softfloat_subMagsF128(
|
---|
203 | uint_fast64_t, uint_fast64_t, uint_fast64_t, uint_fast64_t, bool SOFTFLOAT_STATE_DECL_COMMA );
|
---|
204 | float128_t
|
---|
205 | softfloat_mulAddF128(
|
---|
206 | uint_fast64_t,
|
---|
207 | uint_fast64_t,
|
---|
208 | uint_fast64_t,
|
---|
209 | uint_fast64_t,
|
---|
210 | uint_fast64_t,
|
---|
211 | uint_fast64_t,
|
---|
212 | uint_fast8_t
|
---|
213 | SOFTFLOAT_STATE_DECL_COMMA
|
---|
214 | );
|
---|
215 |
|
---|
216 | #else
|
---|
217 |
|
---|
218 | /*----------------------------------------------------------------------------
|
---|
219 | *----------------------------------------------------------------------------*/
|
---|
220 |
|
---|
221 | bool
|
---|
222 | softfloat_tryPropagateNaNExtF80M(
|
---|
223 | const struct extFloat80M *,
|
---|
224 | const struct extFloat80M *,
|
---|
225 | struct extFloat80M *
|
---|
226 | SOFTFLOAT_STATE_DECL_COMMA
|
---|
227 | );
|
---|
228 | void softfloat_invalidExtF80M( struct extFloat80M * SOFTFLOAT_STATE_DECL_COMMA );
|
---|
229 |
|
---|
230 | int softfloat_normExtF80SigM( uint64_t * );
|
---|
231 |
|
---|
232 | void
|
---|
233 | softfloat_roundPackMToExtF80M(
|
---|
234 | bool, int32_t, uint32_t *, uint_fast8_t, struct extFloat80M * SOFTFLOAT_STATE_DECL_COMMA );
|
---|
235 | void
|
---|
236 | softfloat_normRoundPackMToExtF80M(
|
---|
237 | bool, int32_t, uint32_t *, uint_fast8_t, struct extFloat80M * SOFTFLOAT_STATE_DECL_COMMA );
|
---|
238 |
|
---|
239 | void
|
---|
240 | softfloat_addExtF80M(
|
---|
241 | const struct extFloat80M *,
|
---|
242 | const struct extFloat80M *,
|
---|
243 | struct extFloat80M *,
|
---|
244 | bool
|
---|
245 | SOFTFLOAT_STATE_DECL_COMMA
|
---|
246 | );
|
---|
247 |
|
---|
248 | int
|
---|
249 | softfloat_compareNonnormExtF80M(
|
---|
250 | const struct extFloat80M *, const struct extFloat80M * SOFTFLOAT_STATE_DECL_COMMA );
|
---|
251 |
|
---|
252 | /*----------------------------------------------------------------------------
|
---|
253 | *----------------------------------------------------------------------------*/
|
---|
254 | #define signF128UI96( a96 ) ((bool) ((uint32_t) (a96)>>31))
|
---|
255 | #define expF128UI96( a96 ) ((int32_t) ((a96)>>16) & 0x7FFF)
|
---|
256 | #define fracF128UI96( a96 ) ((a96) & 0x0000FFFF)
|
---|
257 | #define packToF128UI96( sign, exp, sig96 ) (((uint32_t) (sign)<<31) + ((uint32_t) (exp)<<16) + (sig96))
|
---|
258 |
|
---|
259 | bool softfloat_isNaNF128M( const uint32_t * );
|
---|
260 |
|
---|
261 | bool
|
---|
262 | softfloat_tryPropagateNaNF128M(
|
---|
263 | const uint32_t *, const uint32_t *, uint32_t * SOFTFLOAT_STATE_DECL_COMMA );
|
---|
264 | void softfloat_invalidF128M( uint32_t * SOFTFLOAT_STATE_DECL_COMMA );
|
---|
265 |
|
---|
266 | int softfloat_shiftNormSigF128M( const uint32_t *, uint_fast8_t, uint32_t * );
|
---|
267 |
|
---|
268 | void softfloat_roundPackMToF128M( bool, int32_t, uint32_t *, uint32_t * SOFTFLOAT_STATE_DECL_COMMA );
|
---|
269 | void softfloat_normRoundPackMToF128M( bool, int32_t, uint32_t *, uint32_t * SOFTFLOAT_STATE_DECL_COMMA );
|
---|
270 |
|
---|
271 | void
|
---|
272 | softfloat_addF128M( const uint32_t *, const uint32_t *, uint32_t *, bool SOFTFLOAT_STATE_DECL_COMMA );
|
---|
273 | void
|
---|
274 | softfloat_mulAddF128M(
|
---|
275 | const uint32_t *,
|
---|
276 | const uint32_t *,
|
---|
277 | const uint32_t *,
|
---|
278 | uint32_t *,
|
---|
279 | uint_fast8_t
|
---|
280 | SOFTFLOAT_STATE_DECL_COMMA
|
---|
281 | );
|
---|
282 |
|
---|
283 | #endif
|
---|
284 |
|
---|
285 | #endif
|
---|
286 |
|
---|