MCPcopy Create free account
hub / github.com/BlitterStudio/amiberry / getRoundedFloatInternal

Function getRoundedFloatInternal

src/softfloat/softfloat.cpp:228–313  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

226 *----------------------------------------------------------------------------*/
227
228void getRoundedFloatInternal( int8_t roundingPrecision, flag *pzSign, int32_t *pzExp, uint64_t *pzSig )
229{
230 uint64_t roundMask, roundBits;
231 uint64_t roundIncrement;
232 flag increment;
233
234 flag zSign = floatx80_internal_sign;
235 int32_t zExp = floatx80_internal_exp;
236 uint64_t zSig0 = floatx80_internal_sig0;
237 uint64_t zSig1 = floatx80_internal_sig1;
238
239 if ( roundingPrecision == 80 ) {
240 goto precision80;
241 } else if ( roundingPrecision == 64 ) {
242 roundIncrement = LIT64( 0x0000000000000400 );
243 roundMask = LIT64( 0x00000000000007FF );
244 } else if ( roundingPrecision == 32 ) {
245 roundIncrement = LIT64( 0x0000008000000000 );
246 roundMask = LIT64( 0x000000FFFFFFFFFF );
247 } else {
248 goto precision80;
249 }
250
251 zSig0 |= ( zSig1 != 0 );
252 if ( floatx80_internal_mode != float_round_nearest_even ) {
253 if ( floatx80_internal_mode == float_round_to_zero ) {
254 roundIncrement = 0;
255 } else {
256 roundIncrement = roundMask;
257 if ( zSign ) {
258 if ( floatx80_internal_mode == float_round_up ) roundIncrement = 0;
259 } else {
260 if ( floatx80_internal_mode == float_round_down ) roundIncrement = 0;
261 }
262 }
263 }
264
265 roundBits = zSig0 & roundMask;
266
267 zSig0 += roundIncrement;
268 if ( zSig0 < roundIncrement ) {
269 ++zExp;
270 zSig0 = LIT64( 0x8000000000000000 );
271 }
272 roundIncrement = roundMask + 1;
273 if ( floatx80_internal_mode == float_round_nearest_even && ( roundBits<<1 == roundIncrement ) ) {
274 roundMask |= roundIncrement;
275 }
276 zSig0 &= ~ roundMask;
277 if ( zSig0 == 0 ) zExp = 0;
278
279 *pzSign = zSign;
280 *pzExp = zExp;
281 *pzSig = zSig0;
282 return;
283
284precision80:
285 increment = ( (int64_t) zSig1 < 0 );

Callers 5

getFloatInternalOverflowFunction · 0.85
getFloatInternalFloatx80Function · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected