Wire Sysio Wire Sysion 1.0.0
Loading...
Searching...
No Matches
s_roundPackToF32.c File Reference
#include <stdbool.h>
#include <stdint.h>
#include "platform.h"
#include "internals.h"
#include "softfloat.h"
Include dependency graph for s_roundPackToF32.c:

Go to the source code of this file.

Functions

float32_t softfloat_roundPackToF32 (bool sign, int_fast16_t exp, uint_fast32_t sig)
 

Function Documentation

◆ softfloat_roundPackToF32()

float32_t softfloat_roundPackToF32 ( bool sign,
int_fast16_t exp,
uint_fast32_t sig )

Definition at line 44 of file s_roundPackToF32.c.

45{
46 uint_fast8_t roundingMode;
47 bool roundNearEven;
48 uint_fast8_t roundIncrement, roundBits;
49 bool isTiny;
50 uint_fast32_t uiZ;
51 union ui32_f32 uZ;
52
53 /*------------------------------------------------------------------------
54 *------------------------------------------------------------------------*/
55 roundingMode = softfloat_roundingMode;
56 roundNearEven = (roundingMode == softfloat_round_near_even);
57 roundIncrement = 0x40;
58 if ( ! roundNearEven && (roundingMode != softfloat_round_near_maxMag) ) {
59 roundIncrement =
60 (roundingMode
62 ? 0x7F
63 : 0;
64 }
65 roundBits = sig & 0x7F;
66 /*------------------------------------------------------------------------
67 *------------------------------------------------------------------------*/
68 if ( 0xFD <= (unsigned int) exp ) {
69 if ( exp < 0 ) {
70 /*----------------------------------------------------------------
71 *----------------------------------------------------------------*/
72 isTiny =
74 || (exp < -1) || (sig + roundIncrement < 0x80000000);
75 sig = softfloat_shiftRightJam32( sig, -exp );
76 exp = 0;
77 roundBits = sig & 0x7F;
78 if ( isTiny && roundBits ) {
80 }
81 } else if ( (0xFD < exp) || (0x80000000 <= sig + roundIncrement) ) {
82 /*----------------------------------------------------------------
83 *----------------------------------------------------------------*/
86 uiZ = packToF32UI( sign, 0xFF, 0 ) - ! roundIncrement;
87 goto uiZ;
88 }
89 }
90 /*------------------------------------------------------------------------
91 *------------------------------------------------------------------------*/
92 sig = (sig + roundIncrement)>>7;
93 if ( roundBits ) {
95#ifdef SOFTFLOAT_ROUND_ODD
96 if ( roundingMode == softfloat_round_odd ) {
97 sig |= 1;
98 goto packReturn;
99 }
100#endif
101 }
102 sig &= ~(uint_fast32_t) (! (roundBits ^ 0x40) & roundNearEven);
103 if ( ! sig ) exp = 0;
104 /*------------------------------------------------------------------------
105 *------------------------------------------------------------------------*/
106 packReturn:
107 uiZ = packToF32UI( sign, exp, sig );
108 uiZ:
109 uZ.ui = uiZ;
110 return uZ.f;
111
112}
void softfloat_raiseFlags(uint_fast8_t flags)
#define packToF32UI(sign, exp, sig)
Definition internals.h:107
uint32_t softfloat_shiftRightJam32(uint32_t a, uint_fast16_t dist)
THREAD_LOCAL uint_fast8_t softfloat_roundingMode
@ softfloat_flag_inexact
Definition softfloat.h:85
@ softfloat_flag_underflow
Definition softfloat.h:86
@ softfloat_flag_overflow
Definition softfloat.h:87
THREAD_LOCAL uint_fast8_t softfloat_exceptionFlags
THREAD_LOCAL uint_fast8_t softfloat_detectTininess
@ softfloat_round_odd
Definition softfloat.h:77
@ softfloat_round_max
Definition softfloat.h:75
@ softfloat_round_min
Definition softfloat.h:74
@ softfloat_round_near_even
Definition softfloat.h:72
@ softfloat_round_near_maxMag
Definition softfloat.h:76
@ softfloat_tininess_beforeRounding
Definition softfloat.h:62
uint32_t uint_fast32_t
Definition stdint.h:156
uint8_t uint_fast8_t
Definition stdint.h:154