Wire Sysio Wire Sysion 1.0.0
Loading...
Searching...
No Matches
extF80M_roundToInt.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 extF80M_roundToInt.c:

Go to the source code of this file.

Functions

void extF80M_roundToInt (const extFloat80_t *aPtr, uint_fast8_t roundingMode, bool exact, extFloat80_t *zPtr)
 

Function Documentation

◆ extF80M_roundToInt()

void extF80M_roundToInt ( const extFloat80_t * aPtr,
uint_fast8_t roundingMode,
bool exact,
extFloat80_t * zPtr )

Definition at line 62 of file extF80M_roundToInt.c.

68{
69 const struct extFloat80M *aSPtr;
70 struct extFloat80M *zSPtr;
71 uint_fast16_t uiA64, signUI64;
72 int32_t exp;
73 uint64_t sigA;
74 uint_fast16_t uiZ64;
75 uint64_t sigZ, lastBitMask, roundBitsMask;
76
77 /*------------------------------------------------------------------------
78 *------------------------------------------------------------------------*/
79 aSPtr = (const struct extFloat80M *) aPtr;
80 zSPtr = (struct extFloat80M *) zPtr;
81 /*------------------------------------------------------------------------
82 *------------------------------------------------------------------------*/
83 uiA64 = aSPtr->signExp;
84 signUI64 = uiA64 & packToExtF80UI64( 1, 0 );
85 exp = expExtF80UI64( uiA64 );
86 sigA = aSPtr->signif;
87 /*------------------------------------------------------------------------
88 *------------------------------------------------------------------------*/
89 if ( !(sigA & UINT64_C( 0x8000000000000000 )) && (exp != 0x7FFF) ) {
90 if ( !sigA ) {
91 uiZ64 = signUI64;
92 sigZ = 0;
93 goto uiZ;
94 }
95 exp += softfloat_normExtF80SigM( &sigA );
96 }
97 /*------------------------------------------------------------------------
98 *------------------------------------------------------------------------*/
99 if ( exp <= 0x3FFE ) {
101 switch ( roundingMode ) {
103 if ( !(sigA & UINT64_C( 0x7FFFFFFFFFFFFFFF )) ) break;
105 if ( exp == 0x3FFE ) goto mag1;
106 break;
108 if ( signUI64 ) goto mag1;
109 break;
111 if ( !signUI64 ) goto mag1;
112 break;
113#ifdef SOFTFLOAT_ROUND_ODD
115 goto mag1;
116#endif
117 }
118 uiZ64 = signUI64;
119 sigZ = 0;
120 goto uiZ;
121 mag1:
122 uiZ64 = signUI64 | 0x3FFF;
123 sigZ = UINT64_C( 0x8000000000000000 );
124 goto uiZ;
125 }
126 /*------------------------------------------------------------------------
127 *------------------------------------------------------------------------*/
128 if ( 0x403E <= exp ) {
129 if ( exp == 0x7FFF ) {
130 if ( sigA & UINT64_C( 0x7FFFFFFFFFFFFFFF ) ) {
131 softfloat_propagateNaNExtF80M( aSPtr, 0, zSPtr );
132 return;
133 }
134 sigZ = UINT64_C( 0x8000000000000000 );
135 } else {
136 sigZ = sigA;
137 }
138 uiZ64 = signUI64 | exp;
139 goto uiZ;
140 }
141 /*------------------------------------------------------------------------
142 *------------------------------------------------------------------------*/
143 uiZ64 = signUI64 | exp;
144 lastBitMask = (uint64_t) 1<<(0x403E - exp);
145 roundBitsMask = lastBitMask - 1;
146 sigZ = sigA;
147 if ( roundingMode == softfloat_round_near_maxMag ) {
148 sigZ += lastBitMask>>1;
149 } else if ( roundingMode == softfloat_round_near_even ) {
150 sigZ += lastBitMask>>1;
151 if ( !(sigZ & roundBitsMask) ) sigZ &= ~lastBitMask;
152 } else if (
153 roundingMode == (signUI64 ? softfloat_round_min : softfloat_round_max)
154 ) {
155 sigZ += roundBitsMask;
156 }
157 sigZ &= ~roundBitsMask;
158 if ( !sigZ ) {
159 ++uiZ64;
160 sigZ = UINT64_C( 0x8000000000000000 );
161 }
162 if ( sigZ != sigA ) {
163#ifdef SOFTFLOAT_ROUND_ODD
164 if ( roundingMode == softfloat_round_odd ) sigZ |= lastBitMask;
165#endif
167 }
168 uiZ:
169 zSPtr->signExp = uiZ64;
170 zSPtr->signif = sigZ;
171 return;
172
173}
void softfloat_propagateNaNExtF80M(const struct extFloat80M *aSPtr, const struct extFloat80M *bSPtr, struct extFloat80M *zSPtr)
#define packToExtF80UI64(sign, exp)
Definition internals.h:148
#define expExtF80UI64(a64)
Definition internals.h:147
int softfloat_normExtF80SigM(uint64_t *)
@ 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
uint16_t uint_fast16_t
Definition stdint.h:155
#define UINT64_C(val)
Definition stdint.h:284
signed int int32_t
Definition stdint.h:123
unsigned __int64 uint64_t
Definition stdint.h:136
uint64_t signif
uint16_t signExp
Here is the call graph for this function: