[xcc] minor performance tweaks
[riscv-isa-sim.git] / softfloat / s_roundPackToUI64.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_fast64_t
9 softfloat_roundPackToUI64(
10 bool sign,
11 uint_fast64_t sig64,
12 uint_fast64_t sig0,
13 int_fast8_t roundingMode,
14 bool exact
15 )
16 {
17 bool roundNearestEven, increment;
18
19 roundNearestEven = ( roundingMode == softfloat_round_nearest_even );
20 increment = ( UINT64_C( 0x8000000000000000 ) <= sig0 );
21 if (
22 ! roundNearestEven
23 && ( roundingMode != softfloat_round_nearest_maxMag )
24 ) {
25 increment =
26 ( roundingMode != softfloat_round_minMag )
27 && ( roundingMode
28 == ( sign ? softfloat_round_min : softfloat_round_max ) )
29 && sig0;
30 }
31 if ( increment ) {
32 ++sig64;
33 if ( ! sig64 ) goto invalid;
34 sig64 &=
35 ~ ( ! ( sig0 & UINT64_C( 0x7FFFFFFFFFFFFFFF ) )
36 & roundNearestEven );
37 }
38 if ( sign && sig64 ) goto invalid;
39 if ( exact && sig0 ) softfloat_exceptionFlags |= softfloat_flag_inexact;
40 return sig64;
41 invalid:
42 softfloat_raiseFlags( softfloat_flag_invalid );
43 return UINT64_C( 0xFFFFFFFFFFFFFFFF );
44
45 }
46