1353358Sdim// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 2353358Sdim// See https://llvm.org/LICENSE.txt for license information. 3353358Sdim// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 4276789Sdim 5353358Sdim// long double __floatunditf(unsigned long long x); 6353358Sdim// This file implements the PowerPC unsigned long long -> long double conversion 7276789Sdim 8276789Sdim#include "DD.h" 9276789Sdim 10276789Sdimlong double __floatunditf(uint64_t a) { 11276789Sdim 12353358Sdim // Begins with an exact copy of the code from __floatundidf 13353358Sdim 14353358Sdim static const double twop52 = 0x1.0p52; 15353358Sdim static const double twop84 = 0x1.0p84; 16353358Sdim static const double twop84_plus_twop52 = 0x1.00000001p84; 17353358Sdim 18353358Sdim doublebits high = {.d = twop84}; 19353358Sdim doublebits low = {.d = twop52}; 20353358Sdim 21353358Sdim high.x |= a >> 32; // 0x1.0p84 + high 32 bits of a 22353358Sdim low.x |= a & UINT64_C(0x00000000ffffffff); // 0x1.0p52 + low 32 bits of a 23353358Sdim 24353358Sdim const double high_addend = high.d - twop84_plus_twop52; 25353358Sdim 26353358Sdim // At this point, we have two double precision numbers 27353358Sdim // high_addend and low.d, and we wish to return their sum 28353358Sdim // as a canonicalized long double: 29353358Sdim 30353358Sdim // This implementation sets the inexact flag spuriously. 31353358Sdim // This could be avoided, but at some substantial cost. 32353358Sdim 33353358Sdim DD result; 34353358Sdim 35353358Sdim result.s.hi = high_addend + low.d; 36353358Sdim result.s.lo = (high_addend - result.s.hi) + low.d; 37353358Sdim 38353358Sdim return result.ld; 39276789Sdim} 40