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 __floatditf(long long x); */ 6*0a6a1f1dSLionel Sambuc /* This file implements the PowerPC long long -> long double conversion */ 7*0a6a1f1dSLionel Sambuc 8*0a6a1f1dSLionel Sambuc #include "DD.h" 9*0a6a1f1dSLionel Sambuc __floatditf(int64_t a)10*0a6a1f1dSLionel Sambuclong double __floatditf(int64_t a) { 11*0a6a1f1dSLionel Sambuc 12*0a6a1f1dSLionel Sambuc static const double twop32 = 0x1.0p32; 13*0a6a1f1dSLionel Sambuc static const double twop52 = 0x1.0p52; 14*0a6a1f1dSLionel Sambuc 15*0a6a1f1dSLionel Sambuc doublebits low = { .d = twop52 }; 16*0a6a1f1dSLionel Sambuc low.x |= a & UINT64_C(0x00000000ffffffff); /* 0x1.0p52 + low 32 bits of a. */ 17*0a6a1f1dSLionel Sambuc 18*0a6a1f1dSLionel Sambuc const double high_addend = (double)((int32_t)(a >> 32))*twop32 - twop52; 19*0a6a1f1dSLionel Sambuc 20*0a6a1f1dSLionel Sambuc /* At this point, we have two double precision numbers 21*0a6a1f1dSLionel Sambuc * high_addend and low.d, and we wish to return their sum 22*0a6a1f1dSLionel Sambuc * as a canonicalized long double: 23*0a6a1f1dSLionel Sambuc */ 24*0a6a1f1dSLionel Sambuc 25*0a6a1f1dSLionel Sambuc /* This implementation sets the inexact flag spuriously. 26*0a6a1f1dSLionel Sambuc * This could be avoided, but at some substantial cost. 27*0a6a1f1dSLionel Sambuc */ 28*0a6a1f1dSLionel Sambuc 29*0a6a1f1dSLionel Sambuc DD result; 30*0a6a1f1dSLionel Sambuc 31*0a6a1f1dSLionel Sambuc result.s.hi = high_addend + low.d; 32*0a6a1f1dSLionel Sambuc result.s.lo = (high_addend - result.s.hi) + low.d; 33*0a6a1f1dSLionel Sambuc 34*0a6a1f1dSLionel Sambuc return result.ld; 35*0a6a1f1dSLionel Sambuc 36*0a6a1f1dSLionel Sambuc } 37