10b57cec5SDimitry Andric //===-- floatdixf.c - Implement __floatdixf -------------------------------===// 20b57cec5SDimitry Andric // 30b57cec5SDimitry Andric // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 40b57cec5SDimitry Andric // See https://llvm.org/LICENSE.txt for license information. 50b57cec5SDimitry Andric // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 60b57cec5SDimitry Andric // 70b57cec5SDimitry Andric //===----------------------------------------------------------------------===// 80b57cec5SDimitry Andric // 90b57cec5SDimitry Andric // This file implements __floatdixf for the compiler_rt library. 100b57cec5SDimitry Andric // 110b57cec5SDimitry Andric //===----------------------------------------------------------------------===// 120b57cec5SDimitry Andric 130b57cec5SDimitry Andric #if !_ARCH_PPC 140b57cec5SDimitry Andric 150b57cec5SDimitry Andric #include "int_lib.h" 160b57cec5SDimitry Andric 170b57cec5SDimitry Andric // Returns: convert a to a long double, rounding toward even. 180b57cec5SDimitry Andric 190b57cec5SDimitry Andric // Assumption: long double is a IEEE 80 bit floating point type padded to 128 200b57cec5SDimitry Andric // bits di_int is a 64 bit integral type 210b57cec5SDimitry Andric 220b57cec5SDimitry Andric // gggg gggg gggg gggg gggg gggg gggg gggg | gggg gggg gggg gggg seee eeee eeee 230b57cec5SDimitry Andric // eeee | 1mmm mmmm mmmm mmmm mmmm mmmm mmmm mmmm | mmmm mmmm mmmm mmmm mmmm 240b57cec5SDimitry Andric // mmmm mmmm mmmm 250b57cec5SDimitry Andric 26*5f757f3fSDimitry Andric COMPILER_RT_ABI xf_float __floatdixf(di_int a) { 270b57cec5SDimitry Andric if (a == 0) 280b57cec5SDimitry Andric return 0.0; 290b57cec5SDimitry Andric const unsigned N = sizeof(di_int) * CHAR_BIT; 300b57cec5SDimitry Andric const di_int s = a >> (N - 1); 310b57cec5SDimitry Andric a = (a ^ s) - s; 320b57cec5SDimitry Andric int clz = __builtin_clzll(a); 330b57cec5SDimitry Andric int e = (N - 1) - clz; // exponent 34*5f757f3fSDimitry Andric xf_bits fb; 350b57cec5SDimitry Andric fb.u.high.s.low = ((su_int)s & 0x00008000) | // sign 360b57cec5SDimitry Andric (e + 16383); // exponent 370b57cec5SDimitry Andric fb.u.low.all = a << clz; // mantissa 380b57cec5SDimitry Andric return fb.f; 390b57cec5SDimitry Andric } 400b57cec5SDimitry Andric 410b57cec5SDimitry Andric #endif // !_ARCH_PPC 42