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 __floatditf(long long x); 6353358Sdim// This file implements the PowerPC long long -> long double conversion 7276789Sdim 8276789Sdim#include "DD.h" 9276789Sdim 10276789Sdimlong double __floatditf(int64_t a) { 11276789Sdim 12353358Sdim static const double twop32 = 0x1.0p32; 13353358Sdim static const double twop52 = 0x1.0p52; 14276789Sdim 15353358Sdim doublebits low = {.d = twop52}; 16353358Sdim low.x |= a & UINT64_C(0x00000000ffffffff); // 0x1.0p52 + low 32 bits of a. 17353358Sdim 18353358Sdim const double high_addend = (double)((int32_t)(a >> 32)) * twop32 - twop52; 19353358Sdim 20353358Sdim // At this point, we have two double precision numbers 21353358Sdim // high_addend and low.d, and we wish to return their sum 22353358Sdim // as a canonicalized long double: 23353358Sdim 24353358Sdim // This implementation sets the inexact flag spuriously. 25353358Sdim // This could be avoided, but at some substantial cost. 26353358Sdim 27353358Sdim DD result; 28353358Sdim 29353358Sdim result.s.hi = high_addend + low.d; 30353358Sdim result.s.lo = (high_addend - result.s.hi) + low.d; 31353358Sdim 32353358Sdim return result.ld; 33276789Sdim} 34