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

Go to the source code of this file.

Functions

void f128M_roundToInt (const float128_t *aPtr, uint_fast8_t roundingMode, bool exact, float128_t *zPtr)
 

Function Documentation

◆ f128M_roundToInt()

void f128M_roundToInt ( const float128_t * aPtr,
uint_fast8_t roundingMode,
bool exact,
float128_t * zPtr )

Definition at line 62 of file f128M_roundToInt.c.

68{
69 const uint32_t *aWPtr;
70 uint32_t *zWPtr;
71 uint32_t ui96;
72 int32_t exp;
73 uint32_t sigExtra;
74 bool sign;
75 uint_fast8_t bitPos;
76 bool roundNear;
77 unsigned int index, lastIndex;
78 bool extra;
79 uint32_t wordA, bit, wordZ;
80 uint_fast8_t carry;
81 uint32_t extrasMask;
82
83 /*------------------------------------------------------------------------
84 *------------------------------------------------------------------------*/
85 aWPtr = (const uint32_t *) aPtr;
86 zWPtr = (uint32_t *) zPtr;
87 /*------------------------------------------------------------------------
88 *------------------------------------------------------------------------*/
89 ui96 = aWPtr[indexWordHi( 4 )];
90 exp = expF128UI96( ui96 );
91 /*------------------------------------------------------------------------
92 *------------------------------------------------------------------------*/
93 if ( exp < 0x3FFF ) {
94 zWPtr[indexWord( 4, 2 )] = 0;
95 zWPtr[indexWord( 4, 1 )] = 0;
96 zWPtr[indexWord( 4, 0 )] = 0;
97 sigExtra = aWPtr[indexWord( 4, 2 )];
98 if ( !sigExtra ) {
99 sigExtra = aWPtr[indexWord( 4, 1 )] | aWPtr[indexWord( 4, 0 )];
100 }
101 if ( !sigExtra && !(ui96 & 0x7FFFFFFF) ) goto ui96;
103 sign = signF128UI96( ui96 );
104 switch ( roundingMode ) {
106 if ( !fracF128UI96( ui96 ) && !sigExtra ) break;
108 if ( exp == 0x3FFE ) goto mag1;
109 break;
111 if ( sign ) goto mag1;
112 break;
114 if ( !sign ) goto mag1;
115 break;
116#ifdef SOFTFLOAT_ROUND_ODD
118 goto mag1;
119#endif
120 }
121 ui96 = packToF128UI96( sign, 0, 0 );
122 goto ui96;
123 mag1:
124 ui96 = packToF128UI96( sign, 0x3FFF, 0 );
125 goto ui96;
126 }
127 /*------------------------------------------------------------------------
128 *------------------------------------------------------------------------*/
129 if ( 0x406F <= exp ) {
130 if (
131 (exp == 0x7FFF)
132 && (fracF128UI96( ui96 )
133 || (aWPtr[indexWord( 4, 2 )] | aWPtr[indexWord( 4, 1 )]
134 | aWPtr[indexWord( 4, 0 )]))
135 ) {
136 softfloat_propagateNaNF128M( aWPtr, 0, zWPtr );
137 return;
138 }
139 zWPtr[indexWord( 4, 2 )] = aWPtr[indexWord( 4, 2 )];
140 zWPtr[indexWord( 4, 1 )] = aWPtr[indexWord( 4, 1 )];
141 zWPtr[indexWord( 4, 0 )] = aWPtr[indexWord( 4, 0 )];
142 goto ui96;
143 }
144 /*------------------------------------------------------------------------
145 *------------------------------------------------------------------------*/
146 bitPos = 0x406F - exp;
147 roundNear =
148 (roundingMode == softfloat_round_near_maxMag)
149 || (roundingMode == softfloat_round_near_even);
150 bitPos -= roundNear;
151 index = indexWordLo( 4 );
152 lastIndex = indexWordHi( 4 );
153 extra = 0;
154 for (;;) {
155 wordA = aWPtr[index];
156 if ( bitPos < 32 ) break;
157 if ( wordA ) extra = 1;
158 zWPtr[index] = 0;
159 index += wordIncr;
160 bitPos -= 32;
161 }
162 bit = (uint32_t) 1<<bitPos;
163 if ( roundNear ) {
164 wordZ = wordA + bit;
165 carry = (wordZ < wordA);
166 bit <<= 1;
167 extrasMask = bit - 1;
168 if ( exact && (extra || (wordA & extrasMask)) ) {
170 }
171 if (
172 (roundingMode == softfloat_round_near_even)
173 && !extra && !(wordZ & extrasMask)
174 ) {
175 if ( !bit ) {
176 zWPtr[index] = wordZ;
177 index += wordIncr;
178 wordZ = aWPtr[index] + carry;
179 carry &= !wordZ;
180 zWPtr[index] = wordZ & ~1;
181 goto propagateCarry;
182 }
183 wordZ &= ~bit;
184 }
185 } else {
186 wordZ = wordA;
187 carry = 0;
188 extrasMask = bit - 1;
189 if ( extra || (wordA & extrasMask) ) {
191 if (
192 roundingMode
195 ) {
196 wordZ += bit;
197 carry = (wordZ < wordA);
198#ifdef SOFTFLOAT_ROUND_ODD
199 } else if ( roundingMode == softfloat_round_odd ) {
200 wordZ |= bit;
201#endif
202 }
203 }
204 }
205 wordZ &= ~extrasMask;
206 zWPtr[index] = wordZ;
207 propagateCarry:
208 while ( index != lastIndex ) {
209 index += wordIncr;
210 wordZ = aWPtr[index] + carry;
211 zWPtr[index] = wordZ;
212 carry &= !wordZ;
213 }
214 return;
215 /*------------------------------------------------------------------------
216 *------------------------------------------------------------------------*/
217 ui96:
218 zWPtr[indexWordHi( 4 )] = ui96;
219
220}
void softfloat_propagateNaNF128M(const uint32_t *aWPtr, const uint32_t *bWPtr, uint32_t *zWPtr)
#define fracF128UI96(a96)
Definition internals.h:249
#define packToF128UI96(sign, exp, sig96)
Definition internals.h:250
#define signF128UI96(a96)
Definition internals.h:247
#define expF128UI96(a96)
Definition internals.h:248
#define wordIncr
#define indexWordLo(total)
#define indexWord(total, n)
#define indexWordHi(total)
@ 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
signed int int32_t
Definition stdint.h:123
uint8_t uint_fast8_t
Definition stdint.h:154
int bit
Definition yubihsm.h:566
Here is the call graph for this function: