1214152Sed/* ===-- floatundixf.c - Implement __floatundixf ---------------------------=== 2214152Sed * 3214152Sed * The LLVM Compiler Infrastructure 4214152Sed * 5222656Sed * This file is dual licensed under the MIT and the University of Illinois Open 6222656Sed * Source Licenses. See LICENSE.TXT for details. 7214152Sed * 8214152Sed * ===----------------------------------------------------------------------=== 9214152Sed * 10214152Sed * This file implements __floatundixf for the compiler_rt library. 11214152Sed * 12214152Sed * ===----------------------------------------------------------------------=== 13214152Sed */ 14214152Sed 15214152Sed#if !_ARCH_PPC 16214152Sed 17214152Sed#include "int_lib.h" 18214152Sed 19214152Sed/* Returns: convert a to a long double, rounding toward even. */ 20214152Sed 21214152Sed/* Assumption: long double is a IEEE 80 bit floating point type padded to 128 bits 22214152Sed * du_int is a 64 bit integral type 23214152Sed */ 24214152Sed 25214152Sed/* gggg gggg gggg gggg gggg gggg gggg gggg | gggg gggg gggg gggg seee eeee eeee eeee | 26214152Sed * 1mmm mmmm mmmm mmmm mmmm mmmm mmmm mmmm | mmmm mmmm mmmm mmmm mmmm mmmm mmmm mmmm 27214152Sed */ 28214152Sedlong double 29214152Sed__floatundixf(du_int a) 30214152Sed{ 31214152Sed if (a == 0) 32214152Sed return 0.0; 33214152Sed const unsigned N = sizeof(du_int) * CHAR_BIT; 34214152Sed int clz = __builtin_clzll(a); 35214152Sed int e = (N - 1) - clz ; /* exponent */ 36214152Sed long_double_bits fb; 37214152Sed fb.u.high.s.low = (e + 16383); /* exponent */ 38214152Sed fb.u.low.all = a << clz; /* mantissa */ 39214152Sed return fb.f; 40214152Sed} 41214152Sed 42214152Sed#endif /* _ARCH_PPC */ 43