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

Go to the source code of this file.

Functions

int_fast32_t softfloat_roundToI32 (bool sign, uint_fast64_t sig, uint_fast8_t roundingMode, bool exact)
 

Function Documentation

◆ softfloat_roundToI32()

int_fast32_t softfloat_roundToI32 ( bool sign,
uint_fast64_t sig,
uint_fast8_t roundingMode,
bool exact )

Definition at line 45 of file s_roundToI32.c.

47{
48 uint_fast16_t roundIncrement, roundBits;
49 uint_fast32_t sig32;
50 union { uint32_t ui; int32_t i; } uZ;
52
53 /*------------------------------------------------------------------------
54 *------------------------------------------------------------------------*/
55 roundIncrement = 0x800;
56 if (
57 (roundingMode != softfloat_round_near_maxMag)
58 && (roundingMode != softfloat_round_near_even)
59 ) {
60 roundIncrement = 0;
61 if (
62 sign
63 ? (roundingMode == softfloat_round_min)
64#ifdef SOFTFLOAT_ROUND_ODD
65 || (roundingMode == softfloat_round_odd)
66#endif
67 : (roundingMode == softfloat_round_max)
68 ) {
69 roundIncrement = 0xFFF;
70 }
71 }
72 roundBits = sig & 0xFFF;
73 sig += roundIncrement;
74 if ( sig & UINT64_C( 0xFFFFF00000000000 ) ) goto invalid;
75 sig32 = sig>>12;
76 if (
77 (roundBits == 0x800) && (roundingMode == softfloat_round_near_even)
78 ) {
79 sig32 &= ~(uint_fast32_t) 1;
80 }
81 uZ.ui = sign ? -sig32 : sig32;
82 z = uZ.i;
83 if ( z && ((z < 0) ^ sign) ) goto invalid;
84 if ( roundBits ) {
85#ifdef SOFTFLOAT_ROUND_ODD
86 if ( roundingMode == softfloat_round_odd ) z |= 1;
87#endif
89 }
90 return z;
91 /*------------------------------------------------------------------------
92 *------------------------------------------------------------------------*/
93 invalid:
96
97}
void softfloat_raiseFlags(uint_fast8_t flags)
#define i32_fromNegOverflow
Definition specialize.h:58
#define i32_fromPosOverflow
Definition specialize.h:57
@ softfloat_flag_invalid
Definition softfloat.h:89
@ softfloat_flag_inexact
Definition softfloat.h:85
THREAD_LOCAL uint_fast8_t softfloat_exceptionFlags
@ 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
unsigned int uint32_t
Definition stdint.h:126
uint16_t uint_fast16_t
Definition stdint.h:155
#define UINT64_C(val)
Definition stdint.h:284
uint32_t uint_fast32_t
Definition stdint.h:156
int32_t int_fast32_t
Definition stdint.h:152
signed int int32_t
Definition stdint.h:123
Here is the call graph for this function:
Here is the caller graph for this function: