2 /*============================================================================
4 This C header file is part of the SoftFloat IEEE Floating-Point Arithmetic
5 Package, Release 3a, by John R. Hauser.
7 Copyright 2011, 2012, 2013, 2014 The Regents of the University of California.
10 Redistribution and use in source and binary forms, with or without
11 modification, are permitted provided that the following conditions are met:
13 1. Redistributions of source code must retain the above copyright notice,
14 this list of conditions, and the following disclaimer.
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.
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.
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.
35 =============================================================================*/
38 #define primitives_h 1
46 #include "primitiveTypes.h"
48 #ifndef softfloat_shortShiftRightJam64
49 /*----------------------------------------------------------------------------
50 | Shifts `a' right by the number of bits given in `count', which must be in
51 | the range 1 to 63. If any nonzero bits are shifted off, they are "jammed"
52 | into the least-significant bit of the shifted value by setting the least-
53 | significant bit to 1. This shifted-and-jammed value is returned.
54 *----------------------------------------------------------------------------*/
55 #if defined INLINE_LEVEL && (2 <= INLINE_LEVEL)
57 uint64_t softfloat_shortShiftRightJam64( uint64_t a
, uint_fast8_t count
)
58 { return a
>>count
| ((a
& (((uint_fast64_t) 1<<count
) - 1)) != 0); }
60 uint64_t softfloat_shortShiftRightJam64( uint64_t a
, uint_fast8_t count
);
64 #ifndef softfloat_shiftRightJam32
65 /*----------------------------------------------------------------------------
66 | Shifts `a' right by the number of bits given in `count', which must not
67 | be zero. If any nonzero bits are shifted off, they are "jammed" into the
68 | least-significant bit of the shifted value by setting the least-significant
69 | bit to 1. This shifted-and-jammed value is returned.
70 | The value of `count' can be arbitrarily large. In particular, if `count'
71 | is greater than 32, the result will be either 0 or 1, depending on whether
72 | `a' is zero or nonzero.
73 *----------------------------------------------------------------------------*/
74 #if defined INLINE_LEVEL && (2 <= INLINE_LEVEL)
75 INLINE
uint32_t softfloat_shiftRightJam32( uint32_t a
, uint_fast16_t count
)
78 (count
< 31) ? a
>>count
| ((uint32_t) (a
<<(-count
& 31)) != 0)
82 uint32_t softfloat_shiftRightJam32( uint32_t a
, uint_fast16_t count
);
86 #ifndef softfloat_shiftRightJam64
87 /*----------------------------------------------------------------------------
88 | Shifts `a' right by the number of bits given in `count', which must not
89 | be zero. If any nonzero bits are shifted off, they are "jammed" into the
90 | least-significant bit of the shifted value by setting the least-significant
91 | bit to 1. This shifted-and-jammed value is returned.
92 | The value of `count' can be arbitrarily large. In particular, if `count'
93 | is greater than 64, the result will be either 0 or 1, depending on whether
94 | `a' is zero or nonzero.
95 *----------------------------------------------------------------------------*/
96 #if defined INLINE_LEVEL && (3 <= INLINE_LEVEL)
97 INLINE
uint64_t softfloat_shiftRightJam64( uint64_t a
, uint_fast32_t count
)
100 (count
< 63) ? a
>>count
| ((uint64_t) (a
<<(-count
& 63)) != 0)
104 uint64_t softfloat_shiftRightJam64( uint64_t a
, uint_fast32_t count
);
108 /*----------------------------------------------------------------------------
109 | A constant table that translates an 8-bit unsigned integer (the array index)
110 | into the number of leading 0 bits before the most-significant 1 of that
111 | integer. For integer zero (index 0), the corresponding table element is 8.
112 *----------------------------------------------------------------------------*/
113 extern const uint_least8_t softfloat_countLeadingZeros8
[256];
115 #ifndef softfloat_countLeadingZeros32
116 /*----------------------------------------------------------------------------
117 | Returns the number of leading 0 bits before the most-significant 1 bit of
118 | `a'. If `a' is zero, 32 is returned.
119 *----------------------------------------------------------------------------*/
120 #if defined INLINE_LEVEL && (3 <= INLINE_LEVEL)
121 INLINE
uint_fast8_t softfloat_countLeadingZeros32( uint32_t a
)
123 uint_fast8_t count
= 0;
128 if ( a
< 0x1000000 ) {
132 count
+= softfloat_countLeadingZeros8
[a
>>24];
136 uint_fast8_t softfloat_countLeadingZeros32( uint32_t a
);
140 #ifndef softfloat_countLeadingZeros64
141 /*----------------------------------------------------------------------------
142 | Returns the number of leading 0 bits before the most-significant 1 bit of
143 | `a'. If `a' is zero, 64 is returned.
144 *----------------------------------------------------------------------------*/
145 uint_fast8_t softfloat_countLeadingZeros64( uint64_t a
);
148 #ifndef softfloat_approxRecip32_1
149 /*----------------------------------------------------------------------------
150 | Returns an approximation to the reciprocal of the number represented by `a',
151 | where `a' is interpreted as an unsigned fixed-point number with one integer
152 | bit and 31 fraction bits. The `a' input must be "normalized", meaning that
153 | its most-significant bit (bit 31) must be 1. Thus, if A is the value of
154 | the fixed-point interpretation of `a', then 1 <= A < 2. The returned value
155 | is interpreted as a pure unsigned fraction, having no integer bits and 32
156 | fraction bits. The approximation returned is never greater than the true
157 | reciprocal 1/A, and it differs from the true reciprocal by at most 2.006 ulp
158 | (units in the last place).
159 *----------------------------------------------------------------------------*/
160 #ifdef SOFTFLOAT_FAST_DIV64TO32
161 #define softfloat_approxRecip32_1( a ) ((uint32_t) (UINT64_C( 0x7FFFFFFFFFFFFFFF ) / (uint32_t) (a)))
163 uint32_t softfloat_approxRecip32_1( uint32_t a
);
167 #ifndef softfloat_approxRecipSqrt32_1
168 /*----------------------------------------------------------------------------
169 | Returns an approximation to the reciprocal of the square root of the number
170 | represented by `a', where `a' is interpreted as an unsigned fixed-point
171 | number either with one integer bit and 31 fraction bits or with two integer
172 | bits and 30 fraction bits. The format of `a' is determined by `oddExpA',
173 | which must be either 0 or 1. If `oddExpA' is 1, `a' is interpreted as
174 | having one integer bit, and if `oddExpA' is 0, `a' is interpreted as having
175 | two integer bits. The `a' input must be "normalized", meaning that its
176 | most-significant bit (bit 31) must be 1. Thus, if A is the value of the
177 | fixed-point interpretation of `a', it follows that 1 <= A < 2 when `oddExpA'
178 | is 1, and 2 <= A < 4 when `oddExpA' is 0.
179 | The returned value is interpreted as a pure unsigned fraction, having
180 | no integer bits and 32 fraction bits. The approximation returned is never
181 | greater than the true reciprocal 1/sqrt(A), and it differs from the true
182 | reciprocal by at most 2.06 ulp (units in the last place). The approximation
183 | returned is also always within the range 0.5 to 1; thus, the most-
184 | significant bit of the result is always set.
185 *----------------------------------------------------------------------------*/
186 uint32_t softfloat_approxRecipSqrt32_1( unsigned int oddExpA
, uint32_t a
);
189 #ifdef SOFTFLOAT_FAST_INT64
191 /*----------------------------------------------------------------------------
192 | The following functions are needed only when `SOFTFLOAT_FAST_INT64' is
194 *----------------------------------------------------------------------------*/
196 #ifndef softfloat_eq128
197 /*----------------------------------------------------------------------------
198 | Returns true if the 128-bit unsigned integer formed by concatenating `a64'
199 | and `a0' is equal to the 128-bit unsigned integer formed by concatenating
201 *----------------------------------------------------------------------------*/
202 #if defined INLINE_LEVEL && (1 <= INLINE_LEVEL)
204 bool softfloat_eq128( uint64_t a64
, uint64_t a0
, uint64_t b64
, uint64_t b0
)
205 { return (a64
== b64
) && (a0
== b0
); }
207 bool softfloat_eq128( uint64_t a64
, uint64_t a0
, uint64_t b64
, uint64_t b0
);
211 #ifndef softfloat_le128
212 /*----------------------------------------------------------------------------
213 | Returns true if the 128-bit unsigned integer formed by concatenating `a64'
214 | and `a0' is less than or equal to the 128-bit unsigned integer formed by
215 | concatenating `b64' and `b0'.
216 *----------------------------------------------------------------------------*/
217 #if defined INLINE_LEVEL && (2 <= INLINE_LEVEL)
219 bool softfloat_le128( uint64_t a64
, uint64_t a0
, uint64_t b64
, uint64_t b0
)
220 { return (a64
< b64
) || ((a64
== b64
) && (a0
<= b0
)); }
222 bool softfloat_le128( uint64_t a64
, uint64_t a0
, uint64_t b64
, uint64_t b0
);
226 #ifndef softfloat_lt128
227 /*----------------------------------------------------------------------------
228 | Returns true if the 128-bit unsigned integer formed by concatenating `a64'
229 | and `a0' is less than the 128-bit unsigned integer formed by concatenating
231 *----------------------------------------------------------------------------*/
232 #if defined INLINE_LEVEL && (2 <= INLINE_LEVEL)
234 bool softfloat_lt128( uint64_t a64
, uint64_t a0
, uint64_t b64
, uint64_t b0
)
235 { return (a64
< b64
) || ((a64
== b64
) && (a0
< b0
)); }
237 bool softfloat_lt128( uint64_t a64
, uint64_t a0
, uint64_t b64
, uint64_t b0
);
241 #ifndef softfloat_shortShiftLeft128
242 /*----------------------------------------------------------------------------
243 | Shifts the 128 bits formed by concatenating `a64' and `a0' left by the
244 | number of bits given in `count', which must be in the range 1 to 63.
245 *----------------------------------------------------------------------------*/
246 #if defined INLINE_LEVEL && (2 <= INLINE_LEVEL)
249 softfloat_shortShiftLeft128( uint64_t a64
, uint64_t a0
, uint_fast8_t count
)
252 z
.v64
= a64
<<count
| a0
>>(-count
& 63);
258 softfloat_shortShiftLeft128( uint64_t a64
, uint64_t a0
, uint_fast8_t count
);
262 #ifndef softfloat_shortShiftRight128
263 /*----------------------------------------------------------------------------
264 | Shifts the 128 bits formed by concatenating `a64' and `a0' right by the
265 | number of bits given in `count', which must be in the range 1 to 63.
266 *----------------------------------------------------------------------------*/
267 #if defined INLINE_LEVEL && (2 <= INLINE_LEVEL)
270 softfloat_shortShiftRight128( uint64_t a64
, uint64_t a0
, uint_fast8_t count
)
274 z
.v0
= a64
<<(-count
& 63) | a0
>>count
;
279 softfloat_shortShiftRight128( uint64_t a64
, uint64_t a0
, uint_fast8_t count
);
283 #ifndef softfloat_shortShiftRightJam64Extra
284 /*----------------------------------------------------------------------------
285 | This function is the same as `softfloat_shiftRightJam64Extra' (below),
286 | except that `count' must be in the range 1 to 63.
287 *----------------------------------------------------------------------------*/
288 #if defined INLINE_LEVEL && (2 <= INLINE_LEVEL)
291 softfloat_shortShiftRightJam64Extra(
292 uint64_t a
, uint64_t extra
, uint_fast8_t count
)
294 struct uint64_extra z
;
296 z
.extra
= a
<<(-count
& 63) | (extra
!= 0);
301 softfloat_shortShiftRightJam64Extra(
302 uint64_t a
, uint64_t extra
, uint_fast8_t count
);
306 #ifndef softfloat_shortShiftRightJam128
307 /*----------------------------------------------------------------------------
308 | Shifts the 128 bits formed by concatenating `a64' and `a0' right by the
309 | number of bits given in `count', which must be in the range 1 to 63. If any
310 | nonzero bits are shifted off, they are "jammed" into the least-significant
311 | bit of the shifted value by setting the least-significant bit to 1. This
312 | shifted-and-jammed value is returned.
313 *----------------------------------------------------------------------------*/
314 #if defined INLINE_LEVEL && (3 <= INLINE_LEVEL)
317 softfloat_shortShiftRightJam128(
318 uint64_t a64
, uint64_t a0
, uint_fast8_t count
)
320 uint_fast8_t negCount
= -count
;
324 a64
<<(negCount
& 63) | a0
>>count
325 | ((uint64_t) (a0
<<(negCount
& 63)) != 0);
330 softfloat_shortShiftRightJam128(
331 uint64_t a64
, uint64_t a0
, uint_fast8_t count
);
335 #ifndef softfloat_shortShiftRightJam128Extra
336 /*----------------------------------------------------------------------------
337 | This function is the same as `softfloat_shiftRightJam128Extra' (below),
338 | except that `count' must be in the range 1 to 63.
339 *----------------------------------------------------------------------------*/
340 #if defined INLINE_LEVEL && (3 <= INLINE_LEVEL)
343 softfloat_shortShiftRightJam128Extra(
344 uint64_t a64
, uint64_t a0
, uint64_t extra
, uint_fast8_t count
)
346 uint_fast8_t negCount
= -count
;
347 struct uint128_extra z
;
348 z
.v
.v64
= a64
>>count
;
349 z
.v
.v0
= a64
<<(negCount
& 63) | a0
>>count
;
350 z
.extra
= a0
<<(negCount
& 63) | (extra
!= 0);
355 softfloat_shortShiftRightJam128Extra(
356 uint64_t a64
, uint64_t a0
, uint64_t extra
, uint_fast8_t count
);
360 #ifndef softfloat_shiftRightJam64Extra
361 /*----------------------------------------------------------------------------
362 | Shifts the 128 bits formed by concatenating `a' and `extra' right by 64
363 | _plus_ the number of bits given in `count', which must not be zero. This
364 | shifted value is at most 64 nonzero bits and is returned in the `v' field
365 | of the `struct uint64_extra' result. The 64-bit `extra' field of the result
366 | contains a value formed as follows from the bits that were shifted off: The
367 | _last_ bit shifted off is the most-significant bit of the `extra' field, and
368 | the other 63 bits of the `extra' field are all zero if and only if _all_but_
369 | _the_last_ bits shifted off were all zero.
370 | (This function makes more sense if `a' and `extra' are considered to form
371 | an unsigned fixed-point number with binary point between `a' and `extra'.
372 | This fixed-point value is shifted right by the number of bits given in
373 | `count', and the integer part of this shifted value is returned in the `v'
374 | field of the result. The fractional part of the shifted value is modified
375 | as described above and returned in the `extra' field of the result.)
376 *----------------------------------------------------------------------------*/
377 #if defined INLINE_LEVEL && (4 <= INLINE_LEVEL)
380 softfloat_shiftRightJam64Extra(
381 uint64_t a
, uint64_t extra
, uint_fast32_t count
)
383 struct uint64_extra z
;
386 z
.extra
= a
<<(-count
& 63);
389 z
.extra
= (count
== 64) ? a
: (a
!= 0);
391 z
.extra
|= (extra
!= 0);
396 softfloat_shiftRightJam64Extra(
397 uint64_t a
, uint64_t extra
, uint_fast32_t count
);
401 #ifndef softfloat_shiftRightJam128
402 /*----------------------------------------------------------------------------
403 | Shifts the 128 bits formed by concatenating `a64' and `a0' right by the
404 | number of bits given in `count', which must not be zero. If any nonzero
405 | bits are shifted off, they are "jammed" into the least-significant bit of
406 | the shifted value by setting the least-significant bit to 1. This shifted-
407 | and-jammed value is returned.
408 | The value of `count' can be arbitrarily large. In particular, if `count'
409 | is greater than 128, the result will be either 0 or 1, depending on whether
410 | the original 128 bits are all zeros.
411 *----------------------------------------------------------------------------*/
413 softfloat_shiftRightJam128( uint64_t a64
, uint64_t a0
, uint_fast32_t count
);
416 #ifndef softfloat_shiftRightJam128Extra
417 /*----------------------------------------------------------------------------
418 | Shifts the 192 bits formed by concatenating `a64', `a0', and `extra' right
419 | by 64 _plus_ the number of bits given in `count', which must not be zero.
420 | This shifted value is at most 128 nonzero bits and is returned in the `v'
421 | field of the `struct uint128_extra' result. The 64-bit `extra' field of the
422 | result contains a value formed as follows from the bits that were shifted
423 | off: The _last_ bit shifted off is the most-significant bit of the `extra'
424 | field, and the other 63 bits of the `extra' field are all zero if and only
425 | if _all_but_the_last_ bits shifted off were all zero.
426 | (This function makes more sense if `a64', `a0', and `extra' are considered
427 | to form an unsigned fixed-point number with binary point between `a0' and
428 | `extra'. This fixed-point value is shifted right by the number of bits
429 | given in `count', and the integer part of this shifted value is returned
430 | in the `v' field of the result. The fractional part of the shifted value
431 | is modified as described above and returned in the `extra' field of the
433 *----------------------------------------------------------------------------*/
435 softfloat_shiftRightJam128Extra(
436 uint64_t a64
, uint64_t a0
, uint64_t extra
, uint_fast32_t count
);
439 #ifndef softfloat_shiftRightJam256M
440 /*----------------------------------------------------------------------------
441 | Shifts the 256-bit unsigned integer pointed to by `aPtr' right by the number
442 | of bits given in `count', which must not be zero. If any nonzero bits are
443 | shifted off, they are "jammed" into the least-significant bit of the shifted
444 | value by setting the least-significant bit to 1. This shifted-and-jammed
445 | value is stored at the location pointed to by `zPtr'. Each of `aPtr' and
446 | `zPtr' points to an array of four 64-bit elements that concatenate in the
447 | platform's normal endian order to form a 256-bit integer.
448 | The value of `count' can be arbitrarily large. In particular, if `count'
449 | is greater than 256, the stored result will be either 0 or 1, depending on
450 | whether the original 256 bits are all zeros.
451 *----------------------------------------------------------------------------*/
453 softfloat_shiftRightJam256M(
454 const uint64_t *aPtr
, uint_fast32_t count
, uint64_t *zPtr
);
457 #ifndef softfloat_add128
458 /*----------------------------------------------------------------------------
459 | Returns the sum of the 128-bit integer formed by concatenating `a64' and
460 | `a0' and the 128-bit integer formed by concatenating `b64' and `b0'. The
461 | addition is modulo 2^128, so any carry out is lost.
462 *----------------------------------------------------------------------------*/
463 #if defined INLINE_LEVEL && (2 <= INLINE_LEVEL)
466 softfloat_add128( uint64_t a64
, uint64_t a0
, uint64_t b64
, uint64_t b0
)
470 z
.v64
= a64
+ b64
+ (z
.v0
< a0
);
475 softfloat_add128( uint64_t a64
, uint64_t a0
, uint64_t b64
, uint64_t b0
);
479 #ifndef softfloat_add256M
480 /*----------------------------------------------------------------------------
481 | Adds the two 256-bit integers pointed to by `aPtr' and `bPtr'. The addition
482 | is modulo 2^256, so any carry out is lost. The sum is stored at the
483 | location pointed to by `zPtr'. Each of `aPtr', `bPtr', and `zPtr' points to
484 | an array of four 64-bit elements that concatenate in the platform's normal
485 | endian order to form a 256-bit integer.
486 *----------------------------------------------------------------------------*/
489 const uint64_t *aPtr
, const uint64_t *bPtr
, uint64_t *zPtr
);
492 #ifndef softfloat_sub128
493 /*----------------------------------------------------------------------------
494 | Returns the difference of the 128-bit integer formed by concatenating `a64'
495 | and `a0' and the 128-bit integer formed by concatenating `b64' and `b0'.
496 | The subtraction is modulo 2^128, so any borrow out (carry out) is lost.
497 *----------------------------------------------------------------------------*/
498 #if defined INLINE_LEVEL && (2 <= INLINE_LEVEL)
501 softfloat_sub128( uint64_t a64
, uint64_t a0
, uint64_t b64
, uint64_t b0
)
511 softfloat_sub128( uint64_t a64
, uint64_t a0
, uint64_t b64
, uint64_t b0
);
515 #ifndef softfloat_sub256M
516 /*----------------------------------------------------------------------------
517 | Subtracts the 256-bit integer pointed to by `bPtr' from the 256-bit integer
518 | pointed to by `aPtr'. The addition is modulo 2^256, so any borrow out
519 | (carry out) is lost. The difference is stored at the location pointed to
520 | by `zPtr'. Each of `aPtr', `bPtr', and `zPtr' points to an array of four
521 | 64-bit elements that concatenate in the platform's normal endian order to
522 | form a 256-bit integer.
523 *----------------------------------------------------------------------------*/
526 const uint64_t *aPtr
, const uint64_t *bPtr
, uint64_t *zPtr
);
529 #ifndef softfloat_mul64ByShifted32To128
530 /*----------------------------------------------------------------------------
531 | Returns the 128-bit product of `a', `b', and 2^32.
532 *----------------------------------------------------------------------------*/
533 #if defined INLINE_LEVEL && (3 <= INLINE_LEVEL)
534 INLINE
struct uint128
softfloat_mul64ByShifted32To128( uint64_t a
, uint32_t b
)
538 mid
= (uint_fast64_t) (uint32_t) a
* b
;
540 z
.v64
= (uint_fast64_t) (uint32_t) (a
>>32) * b
+ (mid
>>32);
544 struct uint128
softfloat_mul64ByShifted32To128( uint64_t a
, uint32_t b
);
548 #ifndef softfloat_mul64To128
549 /*----------------------------------------------------------------------------
550 | Returns the 128-bit product of `a' and `b'.
551 *----------------------------------------------------------------------------*/
552 struct uint128
softfloat_mul64To128( uint64_t a
, uint64_t b
);
555 #ifndef softfloat_mul128By32
556 /*----------------------------------------------------------------------------
557 | Returns the product of the 128-bit integer formed by concatenating `a64' and
558 | `a0', multiplied by `b'. The multiplication is modulo 2^128; any overflow
559 | bits are discarded.
560 *----------------------------------------------------------------------------*/
561 #if defined INLINE_LEVEL && (4 <= INLINE_LEVEL)
563 struct uint128
softfloat_mul128By32( uint64_t a64
, uint64_t a0
, uint32_t b
)
569 mid
= (uint_fast64_t) (uint32_t) (a0
>>32) * b
;
570 carry
= (uint32_t) ((uint_fast32_t) (z
.v0
>>32) - (uint_fast32_t) mid
);
571 z
.v64
= a64
* b
+ (uint_fast32_t) ((mid
+ carry
)>>32);
575 struct uint128
softfloat_mul128By32( uint64_t a64
, uint64_t a0
, uint32_t b
);
579 #ifndef softfloat_mul128To256M
580 /*----------------------------------------------------------------------------
581 | Multiplies the 128-bit unsigned integer formed by concatenating `a64' and
582 | `a0' by the 128-bit unsigned integer formed by concatenating `b64' and
583 | `b0'. The 256-bit product is stored at the location pointed to by `zPtr'.
584 | Argument `zPtr' points to an array of four 64-bit elements that concatenate
585 | in the platform's normal endian order to form a 256-bit integer.
586 *----------------------------------------------------------------------------*/
588 softfloat_mul128To256M(
589 uint64_t a64
, uint64_t a0
, uint64_t b64
, uint64_t b0
, uint64_t *zPtr
);
594 /*----------------------------------------------------------------------------
595 | The following functions are needed only when `SOFTFLOAT_FAST_INT64' is not
597 *----------------------------------------------------------------------------*/
599 #ifndef softfloat_compare96M
600 /*----------------------------------------------------------------------------
601 | Compares the two 96-bit unsigned integers pointed to by `aPtr' and `bPtr'.
602 | Returns -1 if the first integer (A) is less than the second (B); returns 0
603 | if the two integers are equal; and returns +1 if the first integer (A)
604 | is greater than the second (B). (The result is thus the signum of A - B.)
605 | Each of `aPtr' and `bPtr' points to an array of three 32-bit elements that
606 | concatenate in the platform's normal endian order to form a 96-bit integer.
607 *----------------------------------------------------------------------------*/
608 int_fast8_t softfloat_compare96M( const uint32_t *aPtr
, const uint32_t *bPtr
);
611 #ifndef softfloat_compare128M
612 /*----------------------------------------------------------------------------
613 | Compares the two 128-bit unsigned integers pointed to by `aPtr' and `bPtr'.
614 | Returns -1 if the first integer (A) is less than the second (B); returns 0
615 | if the two integers are equal; and returns +1 if the first integer (A)
616 | is greater than the second (B). (The result is thus the signum of A - B.)
617 | Each of `aPtr' and `bPtr' points to an array of four 32-bit elements that
618 | concatenate in the platform's normal endian order to form a 128-bit integer.
619 *----------------------------------------------------------------------------*/
621 softfloat_compare128M( const uint32_t *aPtr
, const uint32_t *bPtr
);
624 #ifndef softfloat_shortShiftLeft64To96M
625 /*----------------------------------------------------------------------------
626 | Extends `a' to 96 bits and shifts the value left by the number of bits given
627 | in `count', which must be in the range 1 to 31. The result is stored at the
628 | location pointed to by `zPtr'. Argument `zPtr' points to an array of three
629 | 32-bit elements that concatenate in the platform's normal endian order to
630 | form a 96-bit integer.
631 *----------------------------------------------------------------------------*/
632 #if defined INLINE_LEVEL && (2 <= INLINE_LEVEL)
635 softfloat_shortShiftLeft64To96M(
636 uint64_t a
, uint_fast8_t count
, uint32_t *zPtr
)
638 zPtr
[indexWord( 3, 0 )] = (uint32_t) a
<<count
;
640 zPtr
[indexWord( 3, 2 )] = a
>>32;
641 zPtr
[indexWord( 3, 1 )] = a
;
645 softfloat_shortShiftLeft64To96M(
646 uint64_t a
, uint_fast8_t count
, uint32_t *zPtr
);
650 #ifndef softfloat_shortShiftLeftM
651 /*----------------------------------------------------------------------------
652 | Shifts the N-bit unsigned integer pointed to by `aPtr' left by the number
653 | of bits given in `count', where N = `size_words' * 32. The value of `count'
654 | must be in the range 1 to 31. Any nonzero bits shifted off are lost. The
655 | shifted N-bit result is stored at the location pointed to by `zPtr'. Each
656 | of `aPtr' and `zPtr' points to a `size_words'-long array of 32-bit elements
657 | that concatenate in the platform's normal endian order to form an N-bit
659 *----------------------------------------------------------------------------*/
661 softfloat_shortShiftLeftM(
662 uint_fast8_t size_words
,
663 const uint32_t *aPtr
,
669 #ifndef softfloat_shortShiftLeft96M
670 /*----------------------------------------------------------------------------
671 | This function or macro is the same as `softfloat_shortShiftLeftM' with
672 | `size_words' = 3 (N = 96).
673 *----------------------------------------------------------------------------*/
674 #define softfloat_shortShiftLeft96M( aPtr, count, zPtr ) softfloat_shortShiftLeftM( 3, aPtr, count, zPtr )
677 #ifndef softfloat_shortShiftLeft128M
678 /*----------------------------------------------------------------------------
679 | This function or macro is the same as `softfloat_shortShiftLeftM' with
680 | `size_words' = 4 (N = 128).
681 *----------------------------------------------------------------------------*/
682 #define softfloat_shortShiftLeft128M( aPtr, count, zPtr ) softfloat_shortShiftLeftM( 4, aPtr, count, zPtr )
685 #ifndef softfloat_shortShiftLeft160M
686 /*----------------------------------------------------------------------------
687 | This function or macro is the same as `softfloat_shortShiftLeftM' with
688 | `size_words' = 5 (N = 160).
689 *----------------------------------------------------------------------------*/
690 #define softfloat_shortShiftLeft160M( aPtr, count, zPtr ) softfloat_shortShiftLeftM( 5, aPtr, count, zPtr )
693 #ifndef softfloat_shiftLeftM
694 /*----------------------------------------------------------------------------
695 | Shifts the N-bit unsigned integer pointed to by `aPtr' left by the number
696 | of bits given in `count', where N = `size_words' * 32. The value of `count'
697 | must not be zero. Any nonzero bits shifted off are lost. The shifted
698 | N-bit result is stored at the location pointed to by `zPtr'. Each of `aPtr'
699 | and `zPtr' points to a `size_words'-long array of 32-bit elements that
700 | concatenate in the platform's normal endian order to form an N-bit integer.
701 | The value of `count' can be arbitrarily large. In particular, if `count'
702 | is greater than N, the stored result will be 0.
703 *----------------------------------------------------------------------------*/
705 softfloat_shiftLeftM(
706 uint_fast8_t size_words
,
707 const uint32_t *aPtr
,
713 #ifndef softfloat_shiftLeft96M
714 /*----------------------------------------------------------------------------
715 | This function or macro is the same as `softfloat_shiftLeftM' with
716 | `size_words' = 3 (N = 96).
717 *----------------------------------------------------------------------------*/
718 #define softfloat_shiftLeft96M( aPtr, count, zPtr ) softfloat_shiftLeftM( 3, aPtr, count, zPtr )
721 #ifndef softfloat_shiftLeft128M
722 /*----------------------------------------------------------------------------
723 | This function or macro is the same as `softfloat_shiftLeftM' with
724 | `size_words' = 4 (N = 128).
725 *----------------------------------------------------------------------------*/
726 #define softfloat_shiftLeft128M( aPtr, count, zPtr ) softfloat_shiftLeftM( 4, aPtr, count, zPtr )
729 #ifndef softfloat_shiftLeft160M
730 /*----------------------------------------------------------------------------
731 | This function or macro is the same as `softfloat_shiftLeftM' with
732 | `size_words' = 5 (N = 160).
733 *----------------------------------------------------------------------------*/
734 #define softfloat_shiftLeft160M( aPtr, count, zPtr ) softfloat_shiftLeftM( 5, aPtr, count, zPtr )
737 #ifndef softfloat_shortShiftRightM
738 /*----------------------------------------------------------------------------
739 | Shifts the N-bit unsigned integer pointed to by `aPtr' right by the number
740 | of bits given in `count', where N = `size_words' * 32. The value of `count'
741 | must be in the range 1 to 31. Any nonzero bits shifted off are lost. The
742 | shifted N-bit result is stored at the location pointed to by `zPtr'. Each
743 | of `aPtr' and `zPtr' points to a `size_words'-long array of 32-bit elements
744 | that concatenate in the platform's normal endian order to form an N-bit
746 *----------------------------------------------------------------------------*/
748 softfloat_shortShiftRightM(
749 uint_fast8_t size_words
,
750 const uint32_t *aPtr
,
756 #ifndef softfloat_shortShiftRight128M
757 /*----------------------------------------------------------------------------
758 | This function or macro is the same as `softfloat_shortShiftRightM' with
759 | `size_words' = 4 (N = 128).
760 *----------------------------------------------------------------------------*/
761 #define softfloat_shortShiftRight128M( aPtr, count, zPtr ) softfloat_shortShiftRightM( 4, aPtr, count, zPtr )
764 #ifndef softfloat_shortShiftRight160M
765 /*----------------------------------------------------------------------------
766 | This function or macro is the same as `softfloat_shortShiftRightM' with
767 | `size_words' = 5 (N = 160).
768 *----------------------------------------------------------------------------*/
769 #define softfloat_shortShiftRight160M( aPtr, count, zPtr ) softfloat_shortShiftRightM( 5, aPtr, count, zPtr )
772 #ifndef softfloat_shortShiftRightJamM
773 /*----------------------------------------------------------------------------
774 | Shifts the N-bit unsigned integer pointed to by `aPtr' right by the number
775 | of bits given in `count', where N = `size_words' * 32. The value of `count'
776 | must be in the range 1 to 31. If any nonzero bits are shifted off, they are
777 | "jammed" into the least-significant bit of the shifted value by setting the
778 | least-significant bit to 1. This shifted-and-jammed N-bit result is stored
779 | at the location pointed to by `zPtr'. Each of `aPtr' and `zPtr' points
780 | to a `size_words'-long array of 32-bit elements that concatenate in the
781 | platform's normal endian order to form an N-bit integer.
782 *----------------------------------------------------------------------------*/
784 softfloat_shortShiftRightJamM(
785 uint_fast8_t, const uint32_t *, uint_fast8_t, uint32_t * );
788 #ifndef softfloat_shortShiftRightJam160M
789 /*----------------------------------------------------------------------------
790 | This function or macro is the same as `softfloat_shortShiftRightJamM' with
791 | `size_words' = 5 (N = 160).
792 *----------------------------------------------------------------------------*/
793 #define softfloat_shortShiftRightJam160M( aPtr, count, zPtr ) softfloat_shortShiftRightJamM( 5, aPtr, count, zPtr )
796 #ifndef softfloat_shiftRightM
797 /*----------------------------------------------------------------------------
798 | Shifts the N-bit unsigned integer pointed to by `aPtr' right by the number
799 | of bits given in `count', where N = `size_words' * 32. The value of `count'
800 | must not be zero. Any nonzero bits shifted off are lost. The shifted
801 | N-bit result is stored at the location pointed to by `zPtr'. Each of `aPtr'
802 | and `zPtr' points to a `size_words'-long array of 32-bit elements that
803 | concatenate in the platform's normal endian order to form an N-bit integer.
804 | The value of `count' can be arbitrarily large. In particular, if `count'
805 | is greater than N, the stored result will be 0.
806 *----------------------------------------------------------------------------*/
808 softfloat_shiftRightM(
809 uint_fast8_t size_words
,
810 const uint32_t *aPtr
,
816 #ifndef softfloat_shiftRight96M
817 /*----------------------------------------------------------------------------
818 | This function or macro is the same as `softfloat_shiftRightM' with
819 | `size_words' = 3 (N = 96).
820 *----------------------------------------------------------------------------*/
821 #define softfloat_shiftRight96M( aPtr, count, zPtr ) softfloat_shiftRightM( 3, aPtr, count, zPtr )
824 #ifndef softfloat_shiftRightJamM
825 /*----------------------------------------------------------------------------
826 | Shifts the N-bit unsigned integer pointed to by `aPtr' right by the number
827 | of bits given in `count', where N = `size_words' * 32. The value of `count'
828 | must not be zero. If any nonzero bits are shifted off, they are "jammed"
829 | into the least-significant bit of the shifted value by setting the least-
830 | significant bit to 1. This shifted-and-jammed N-bit result is stored
831 | at the location pointed to by `zPtr'. Each of `aPtr' and `zPtr' points
832 | to a `size_words'-long array of 32-bit elements that concatenate in the
833 | platform's normal endian order to form an N-bit integer.
834 | The value of `count' can be arbitrarily large. In particular, if `count'
835 | is greater than N, the stored result will be either 0 or 1, depending on
836 | whether the original N bits are all zeros.
837 *----------------------------------------------------------------------------*/
839 softfloat_shiftRightJamM(
840 uint_fast8_t size_words
,
841 const uint32_t *aPtr
,
847 #ifndef softfloat_shiftRightJam96M
848 /*----------------------------------------------------------------------------
849 | This function or macro is the same as `softfloat_shiftRightJamM' with
850 | `size_words' = 3 (N = 96).
851 *----------------------------------------------------------------------------*/
852 #define softfloat_shiftRightJam96M( aPtr, count, zPtr ) softfloat_shiftRightJamM( 3, aPtr, count, zPtr )
855 #ifndef softfloat_shiftRightJam128M
856 /*----------------------------------------------------------------------------
857 | This function or macro is the same as `softfloat_shiftRightJamM' with
858 | `size_words' = 4 (N = 128).
859 *----------------------------------------------------------------------------*/
860 #define softfloat_shiftRightJam128M( aPtr, count, zPtr ) softfloat_shiftRightJamM( 4, aPtr, count, zPtr )
863 #ifndef softfloat_shiftRightJam160M
864 /*----------------------------------------------------------------------------
865 | This function or macro is the same as `softfloat_shiftRightJamM' with
866 | `size_words' = 5 (N = 160).
867 *----------------------------------------------------------------------------*/
868 #define softfloat_shiftRightJam160M( aPtr, count, zPtr ) softfloat_shiftRightJamM( 5, aPtr, count, zPtr )
871 #ifndef softfloat_addM
872 /*----------------------------------------------------------------------------
873 | Adds the two N-bit integers pointed to by `aPtr' and `bPtr', where N =
874 | `size_words' * 32. The addition is modulo 2^N, so any carry out is lost.
875 | The N-bit sum is stored at the location pointed to by `zPtr'. Each of
876 | `aPtr', `bPtr', and `zPtr' points to a `size_words'-long array of 32-bit
877 | elements that concatenate in the platform's normal endian order to form an
879 *----------------------------------------------------------------------------*/
882 uint_fast8_t size_words
,
883 const uint32_t *aPtr
,
884 const uint32_t *bPtr
,
889 #ifndef softfloat_add96M
890 /*----------------------------------------------------------------------------
891 | This function or macro is the same as `softfloat_addM' with `size_words'
893 *----------------------------------------------------------------------------*/
894 #define softfloat_add96M( aPtr, bPtr, zPtr ) softfloat_addM( 3, aPtr, bPtr, zPtr )
897 #ifndef softfloat_add128M
898 /*----------------------------------------------------------------------------
899 | This function or macro is the same as `softfloat_addM' with `size_words'
901 *----------------------------------------------------------------------------*/
902 #define softfloat_add128M( aPtr, bPtr, zPtr ) softfloat_addM( 4, aPtr, bPtr, zPtr )
905 #ifndef softfloat_add160M
906 /*----------------------------------------------------------------------------
907 | This function or macro is the same as `softfloat_addM' with `size_words'
909 *----------------------------------------------------------------------------*/
910 #define softfloat_add160M( aPtr, bPtr, zPtr ) softfloat_addM( 5, aPtr, bPtr, zPtr )
913 #ifndef softfloat_addCarryM
914 /*----------------------------------------------------------------------------
915 | Adds the two N-bit unsigned integers pointed to by `aPtr' and `bPtr', where
916 | N = `size_words' * 32, plus `carry', which must be either 0 or 1. The N-bit
917 | sum (modulo 2^N) is stored at the location pointed to by `zPtr', and any
918 | carry out is returned as the result. Each of `aPtr', `bPtr', and `zPtr'
919 | points to a `size_words'-long array of 32-bit elements that concatenate in
920 | the platform's normal endian order to form an N-bit integer.
921 *----------------------------------------------------------------------------*/
924 uint_fast8_t size_words
,
925 const uint32_t *aPtr
,
926 const uint32_t *bPtr
,
932 #ifndef softfloat_addComplCarryM
933 /*----------------------------------------------------------------------------
934 | This function or macro is the same as `softfloat_addCarryM', except that
935 | the value of the unsigned integer pointed to by `bPtr' is bit-wise completed
936 | before the addition.
937 *----------------------------------------------------------------------------*/
939 softfloat_addComplCarryM(
940 uint_fast8_t size_words
,
941 const uint32_t *aPtr
,
942 const uint32_t *bPtr
,
948 #ifndef softfloat_addComplCarry96M
949 /*----------------------------------------------------------------------------
950 | This function or macro is the same as `softfloat_addComplCarryM' with
951 | `size_words' = 3 (N = 96).
952 *----------------------------------------------------------------------------*/
953 #define softfloat_addComplCarry96M( aPtr, bPtr, carry, zPtr ) softfloat_addComplCarryM( 3, aPtr, bPtr, carry, zPtr )
956 #ifndef softfloat_negXM
957 /*----------------------------------------------------------------------------
958 | Replaces the N-bit unsigned integer pointed to by `zPtr' by the
959 | 2s-complement of itself, where N = `size_words' * 32. Argument `zPtr'
960 | points to a `size_words'-long array of 32-bit elements that concatenate in
961 | the platform's normal endian order to form an N-bit integer.
962 *----------------------------------------------------------------------------*/
963 void softfloat_negXM( uint_fast8_t size_words
, uint32_t *zPtr
);
966 #ifndef softfloat_negX96M
967 /*----------------------------------------------------------------------------
968 | This function or macro is the same as `softfloat_negXM' with `size_words'
970 *----------------------------------------------------------------------------*/
971 #define softfloat_negX96M( zPtr ) softfloat_negXM( 3, zPtr )
974 #ifndef softfloat_negX128M
975 /*----------------------------------------------------------------------------
976 | This function or macro is the same as `softfloat_negXM' with `size_words'
978 *----------------------------------------------------------------------------*/
979 #define softfloat_negX128M( zPtr ) softfloat_negXM( 4, zPtr )
982 #ifndef softfloat_negX160M
983 /*----------------------------------------------------------------------------
984 | This function or macro is the same as `softfloat_negXM' with `size_words'
986 *----------------------------------------------------------------------------*/
987 #define softfloat_negX160M( zPtr ) softfloat_negXM( 5, zPtr )
990 #ifndef softfloat_negX256M
991 /*----------------------------------------------------------------------------
992 | This function or macro is the same as `softfloat_negXM' with `size_words'
994 *----------------------------------------------------------------------------*/
995 #define softfloat_negX256M( zPtr ) softfloat_negXM( 8, zPtr )
998 #ifndef softfloat_sub1XM
999 /*----------------------------------------------------------------------------
1000 | Subtracts 1 from the N-bit integer pointed to by `zPtr', where N =
1001 | `size_words' * 32. The subtraction is modulo 2^N, so any borrow out (carry
1002 | out) is lost. Argument `zPtr' points to a `size_words'-long array of 32-bit
1003 | elements that concatenate in the platform's normal endian order to form an
1005 *----------------------------------------------------------------------------*/
1006 void softfloat_sub1XM( uint_fast8_t size_words
, uint32_t *zPtr
);
1009 #ifndef softfloat_sub1X96M
1010 /*----------------------------------------------------------------------------
1011 | This function or macro is the same as `softfloat_sub1XM' with `size_words'
1013 *----------------------------------------------------------------------------*/
1014 #define softfloat_sub1X96M( zPtr ) softfloat_sub1XM( 3, zPtr )
1017 #ifndef softfloat_sub1X160M
1018 /*----------------------------------------------------------------------------
1019 | This function or macro is the same as `softfloat_sub1XM' with `size_words'
1021 *----------------------------------------------------------------------------*/
1022 #define softfloat_sub1X160M( zPtr ) softfloat_sub1XM( 5, zPtr )
1025 #ifndef softfloat_subM
1026 /*----------------------------------------------------------------------------
1027 | Subtracts the two N-bit integers pointed to by `aPtr' and `bPtr', where N =
1028 | `size_words' * 32. The subtraction is modulo 2^N, so any borrow out (carry
1029 | out) is lost. The N-bit difference is stored at the location pointed to by
1030 | `zPtr'. Each of `aPtr', `bPtr', and `zPtr' points to a `size_words'-long
1031 | array of 32-bit elements that concatenate in the platform's normal endian
1032 | order to form an N-bit integer.
1033 *----------------------------------------------------------------------------*/
1036 uint_fast8_t size_words
,
1037 const uint32_t *aPtr
,
1038 const uint32_t *bPtr
,
1043 #ifndef softfloat_sub96M
1044 /*----------------------------------------------------------------------------
1045 | This function or macro is the same as `softfloat_subM' with `size_words'
1047 *----------------------------------------------------------------------------*/
1048 #define softfloat_sub96M( aPtr, bPtr, zPtr ) softfloat_subM( 3, aPtr, bPtr, zPtr )
1051 #ifndef softfloat_sub128M
1052 /*----------------------------------------------------------------------------
1053 | This function or macro is the same as `softfloat_subM' with `size_words'
1055 *----------------------------------------------------------------------------*/
1056 #define softfloat_sub128M( aPtr, bPtr, zPtr ) softfloat_subM( 4, aPtr, bPtr, zPtr )
1059 #ifndef softfloat_sub160M
1060 /*----------------------------------------------------------------------------
1061 | This function or macro is the same as `softfloat_subM' with `size_words'
1063 *----------------------------------------------------------------------------*/
1064 #define softfloat_sub160M( aPtr, bPtr, zPtr ) softfloat_subM( 5, aPtr, bPtr, zPtr )
1067 #ifndef softfloat_mul64To128M
1068 /*----------------------------------------------------------------------------
1069 | Multiplies `a' and `b' and stores the 128-bit product at the location
1070 | pointed to by `zPtr'. Argument `zPtr' points to an array of four 32-bit
1071 | elements that concatenate in the platform's normal endian order to form a
1073 *----------------------------------------------------------------------------*/
1074 void softfloat_mul64To128M( uint64_t a
, uint64_t b
, uint32_t *zPtr
);
1077 #ifndef softfloat_mul128MTo256M
1078 /*----------------------------------------------------------------------------
1079 | Multiplies the two 128-bit unsigned integers pointed to by `aPtr' and
1080 | `bPtr', and stores the 256-bit product at the location pointed to by `zPtr'.
1081 | Each of `aPtr' and `bPtr' points to an array of four 32-bit elements that
1082 | concatenate in the platform's normal endian order to form a 128-bit integer.
1083 | Argument `zPtr' points to an array of eight 32-bit elements that concatenate
1084 | to form a 256-bit integer.
1085 *----------------------------------------------------------------------------*/
1087 softfloat_mul128MTo256M(
1088 const uint32_t *aPtr
, const uint32_t *bPtr
, uint32_t *zPtr
);
1091 #ifndef softfloat_remStepMBy32
1092 /*----------------------------------------------------------------------------
1093 | Performs a "remainder reduction step" as follows: Arguments `remPtr' and
1094 | `bPtr' both point to N-bit unsigned integers, where N = `size_words' * 32.
1095 | Defining R and B as the values of those integers, the expression (R<<`count')
1096 | - B * q is computed modulo 2^N, and the N-bit result is stored at the
1097 | location pointed to by `zPtr'. Each of `remPtr', `bPtr', and `zPtr' points
1098 | to a `size_words'-long array of 32-bit elements that concatenate in the
1099 | platform's normal endian order to form an N-bit integer.
1100 *----------------------------------------------------------------------------*/
1102 softfloat_remStepMBy32(
1103 uint_fast8_t size_words
,
1104 const uint32_t *remPtr
,
1106 const uint32_t *bPtr
,
1112 #ifndef softfloat_remStep96MBy32
1113 /*----------------------------------------------------------------------------
1114 | This function or macro is the same as `softfloat_remStepMBy32' with
1115 | `size_words' = 3 (N = 96).
1116 *----------------------------------------------------------------------------*/
1117 #define softfloat_remStep96MBy32( remPtr, count, bPtr, q, zPtr ) softfloat_remStepMBy32( 3, remPtr, count, bPtr, q, zPtr )
1120 #ifndef softfloat_remStep128MBy32
1121 /*----------------------------------------------------------------------------
1122 | This function or macro is the same as `softfloat_remStepMBy32' with
1123 | `size_words' = 4 (N = 128).
1124 *----------------------------------------------------------------------------*/
1125 #define softfloat_remStep128MBy32( remPtr, count, bPtr, q, zPtr ) softfloat_remStepMBy32( 4, remPtr, count, bPtr, q, zPtr )
1128 #ifndef softfloat_remStep160MBy32
1129 /*----------------------------------------------------------------------------
1130 | This function or macro is the same as `softfloat_remStepMBy32' with
1131 | `size_words' = 5 (N = 160).
1132 *----------------------------------------------------------------------------*/
1133 #define softfloat_remStep160MBy32( remPtr, count, bPtr, q, zPtr ) softfloat_remStepMBy32( 5, remPtr, count, bPtr, q, zPtr )