1156cd587Sjoerg /* ===-- floatundixf.c - Implement __floatundixf ---------------------------=== 2156cd587Sjoerg * 3156cd587Sjoerg * The LLVM Compiler Infrastructure 4156cd587Sjoerg * 5156cd587Sjoerg * This file is dual licensed under the MIT and the University of Illinois Open 6156cd587Sjoerg * Source Licenses. See LICENSE.TXT for details. 7156cd587Sjoerg * 8156cd587Sjoerg * ===----------------------------------------------------------------------=== 9156cd587Sjoerg * 10156cd587Sjoerg * This file implements __floatundixf for the compiler_rt library. 11156cd587Sjoerg * 12156cd587Sjoerg * ===----------------------------------------------------------------------=== 13156cd587Sjoerg */ 14156cd587Sjoerg 15156cd587Sjoerg #if !_ARCH_PPC 16156cd587Sjoerg 17156cd587Sjoerg #include "int_lib.h" 18156cd587Sjoerg 19156cd587Sjoerg /* Returns: convert a to a long double, rounding toward even. */ 20156cd587Sjoerg 21156cd587Sjoerg /* Assumption: long double is a IEEE 80 bit floating point type padded to 128 bits 22156cd587Sjoerg * du_int is a 64 bit integral type 23156cd587Sjoerg */ 24156cd587Sjoerg 25156cd587Sjoerg /* gggg gggg gggg gggg gggg gggg gggg gggg | gggg gggg gggg gggg seee eeee eeee eeee | 26156cd587Sjoerg * 1mmm mmmm mmmm mmmm mmmm mmmm mmmm mmmm | mmmm mmmm mmmm mmmm mmmm mmmm mmmm mmmm 27156cd587Sjoerg */ 28*f7f78b33Sjoerg COMPILER_RT_ABI long double __floatundixf(du_int a)29156cd587Sjoerg__floatundixf(du_int a) 30156cd587Sjoerg { 31156cd587Sjoerg if (a == 0) 32156cd587Sjoerg return 0.0; 33156cd587Sjoerg const unsigned N = sizeof(du_int) * CHAR_BIT; 34156cd587Sjoerg int clz = __builtin_clzll(a); 35156cd587Sjoerg int e = (N - 1) - clz ; /* exponent */ 36156cd587Sjoerg long_double_bits fb; 37156cd587Sjoerg fb.u.high.s.low = (e + 16383); /* exponent */ 38156cd587Sjoerg fb.u.low.all = a << clz; /* mantissa */ 39156cd587Sjoerg return fb.f; 40156cd587Sjoerg } 41156cd587Sjoerg 42156cd587Sjoerg #endif /* _ARCH_PPC */ 43