[xcc] minor performance tweaks
[riscv-isa-sim.git] / softfloat / s_roundPackToF32.c
1
2 #include <stdbool.h>
3 #include <stdint.h>
4 #include "platform.h"
5 #include "primitives.h"
6 #include "internals.h"
7 #include "softfloat.h"
8
9 float32_t
10 softfloat_roundPackToF32( bool sign, int_fast16_t exp, uint_fast32_t sig )
11 {
12 int roundingMode;
13 bool roundNearestEven;
14 int roundIncrement, roundBits;
15 bool isTiny;
16 uint_fast32_t uiZ;
17 union ui32_f32 uZ;
18
19 roundingMode = softfloat_roundingMode;
20 roundNearestEven = ( roundingMode == softfloat_round_nearest_even );
21 roundIncrement = 0x40;
22 if (
23 ! roundNearestEven
24 && ( roundingMode != softfloat_round_nearest_maxMag )
25 ) {
26 roundIncrement =
27 ( roundingMode == softfloat_round_minMag )
28 || ( roundingMode
29 == ( sign ? softfloat_round_max : softfloat_round_min ) )
30 ? 0
31 : 0x7F;
32 }
33 roundBits = sig & 0x7F;
34 if ( 0xFD <= (uint16_t) exp ) {
35 if ( exp < 0 ) {
36 isTiny =
37 ( softfloat_detectTininess
38 == softfloat_tininess_beforeRounding )
39 || ( exp < -1 )
40 || ( sig + roundIncrement < 0x80000000 );
41 sig = softfloat_shift32RightJam( sig, - exp );
42 exp = 0;
43 roundBits = sig & 0x7F;
44 if ( isTiny && roundBits ) {
45 softfloat_raiseFlags( softfloat_flag_underflow );
46 }
47 } else if (
48 ( 0xFD < exp ) || ( 0x80000000 <= sig + roundIncrement )
49 ) {
50 softfloat_raiseFlags(
51 softfloat_flag_overflow | softfloat_flag_inexact );
52 uiZ = packToF32UI( sign, 0xFF, 0 ) - ! roundIncrement;
53 goto uiZ;
54 }
55 }
56 if ( roundBits ) softfloat_exceptionFlags |= softfloat_flag_inexact;
57 sig = ( sig + roundIncrement )>>7;
58 sig &= ~ ( ! ( roundBits ^ 0x40 ) & roundNearestEven );
59 uiZ = packToF32UI( sign, sig ? exp : 0, sig );
60 uiZ:
61 uZ.ui = uiZ;
62 return uZ.f;
63
64 }
65