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