[xcc] minor performance tweaks
[riscv-isa-sim.git] / softfloat / s_roundPackToUI32.c
1
2 #include <stdbool.h>
3 #include <stdint.h>
4 #include "platform.h"
5 #include "internals.h"
6 #include "softfloat.h"
7
8 uint_fast32_t
9 softfloat_roundPackToUI32(
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 z;
15
16 roundNearestEven = ( roundingMode == softfloat_round_nearest_even );
17 roundIncrement = 0x40;
18 if (
19 ! roundNearestEven
20 && ( roundingMode != softfloat_round_nearest_maxMag )
21 ) {
22 roundIncrement =
23 ( roundingMode == softfloat_round_minMag )
24 || ( roundingMode
25 == ( sign ? softfloat_round_max : softfloat_round_min ) )
26 ? 0
27 : 0x7F;
28 }
29 roundBits = sig & 0x7F;
30 sig += roundIncrement;
31 if ( sig & UINT64_C( 0xFFFFFF8000000000 ) ) goto invalid;
32 z = sig>>7;
33 z &= ~ ( ! ( roundBits ^ 0x40 ) & roundNearestEven );
34 if ( sign && z ) goto invalid;
35 if ( exact && roundBits ) {
36 softfloat_exceptionFlags |= softfloat_flag_inexact;
37 }
38 return z;
39 invalid:
40 softfloat_raiseFlags( softfloat_flag_invalid );
41 return 0xFFFFFFFF;
42
43 }
44