temporary undoing of renaming
[riscv-isa-sim.git] / softfloat / s_roundPackToI32.c
1
2 #include <stdbool.h>
3 #include <stdint.h>
4 #include "platform.h"
5 #include "internals.h"
6 #include "softfloat.h"
7
8 int_fast32_t
9 softfloat_roundPackToI32(
10 bool sign, uint_fast64_t sig, int_fast8_t roundingMode, bool exact )
11 {
12 bool roundNearestEven;
13 int roundIncrement, roundBits;
14 uint_fast32_t sig32;
15 union { uint32_t ui; int32_t i; } uZ;
16 int_fast32_t z;
17
18 roundNearestEven = ( roundingMode == softfloat_round_nearest_even );
19 roundIncrement = 0x40;
20 if (
21 ! roundNearestEven
22 && ( roundingMode != softfloat_round_nearest_maxMag )
23 ) {
24 roundIncrement =
25 ( roundingMode == softfloat_round_minMag )
26 || ( roundingMode
27 == ( sign ? softfloat_round_max : softfloat_round_min ) )
28 ? 0
29 : 0x7F;
30 }
31 roundBits = sig & 0x7F;
32 sig += roundIncrement;
33 if ( sig & UINT64_C( 0xFFFFFF8000000000 ) ) goto invalid;
34 sig32 = sig>>7;
35 sig32 &= ~ ( ! ( roundBits ^ 0x40 ) & roundNearestEven );
36 uZ.ui = sign ? - sig32 : sig32;
37 z = uZ.i;
38 if ( z && ( ( z < 0 ) ^ sign ) ) goto invalid;
39 if ( exact && roundBits ) {
40 softfloat_exceptionFlags |= softfloat_flag_inexact;
41 }
42 return z;
43 invalid:
44 softfloat_raiseFlags( softfloat_flag_invalid );
45 return sign ? -0x7FFFFFFF - 1 : 0x7FFFFFFF;
46
47 }
48