1*7c3d14c8STreehugger Robot /* This file is distributed under the University of Illinois Open Source 2*7c3d14c8STreehugger Robot * License. See LICENSE.TXT for details. 3*7c3d14c8STreehugger Robot */ 4*7c3d14c8STreehugger Robot 5*7c3d14c8STreehugger Robot /* long double __floatunditf(unsigned long long x); */ 6*7c3d14c8STreehugger Robot /* This file implements the PowerPC unsigned long long -> long double conversion */ 7*7c3d14c8STreehugger Robot 8*7c3d14c8STreehugger Robot #include "DD.h" 9*7c3d14c8STreehugger Robot __floatunditf(uint64_t a)10*7c3d14c8STreehugger Robotlong double __floatunditf(uint64_t a) { 11*7c3d14c8STreehugger Robot 12*7c3d14c8STreehugger Robot /* Begins with an exact copy of the code from __floatundidf */ 13*7c3d14c8STreehugger Robot 14*7c3d14c8STreehugger Robot static const double twop52 = 0x1.0p52; 15*7c3d14c8STreehugger Robot static const double twop84 = 0x1.0p84; 16*7c3d14c8STreehugger Robot static const double twop84_plus_twop52 = 0x1.00000001p84; 17*7c3d14c8STreehugger Robot 18*7c3d14c8STreehugger Robot doublebits high = { .d = twop84 }; 19*7c3d14c8STreehugger Robot doublebits low = { .d = twop52 }; 20*7c3d14c8STreehugger Robot 21*7c3d14c8STreehugger Robot high.x |= a >> 32; /* 0x1.0p84 + high 32 bits of a */ 22*7c3d14c8STreehugger Robot low.x |= a & UINT64_C(0x00000000ffffffff); /* 0x1.0p52 + low 32 bits of a */ 23*7c3d14c8STreehugger Robot 24*7c3d14c8STreehugger Robot const double high_addend = high.d - twop84_plus_twop52; 25*7c3d14c8STreehugger Robot 26*7c3d14c8STreehugger Robot /* At this point, we have two double precision numbers 27*7c3d14c8STreehugger Robot * high_addend and low.d, and we wish to return their sum 28*7c3d14c8STreehugger Robot * as a canonicalized long double: 29*7c3d14c8STreehugger Robot */ 30*7c3d14c8STreehugger Robot 31*7c3d14c8STreehugger Robot /* This implementation sets the inexact flag spuriously. */ 32*7c3d14c8STreehugger Robot /* This could be avoided, but at some substantial cost. */ 33*7c3d14c8STreehugger Robot 34*7c3d14c8STreehugger Robot DD result; 35*7c3d14c8STreehugger Robot 36*7c3d14c8STreehugger Robot result.s.hi = high_addend + low.d; 37*7c3d14c8STreehugger Robot result.s.lo = (high_addend - result.s.hi) + low.d; 38*7c3d14c8STreehugger Robot 39*7c3d14c8STreehugger Robot return result.ld; 40*7c3d14c8STreehugger Robot 41*7c3d14c8STreehugger Robot } 42