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