1156cd587Sjoerg /* ===-- floatdixf.c - Implement __floatdixf -------------------------------=== 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 __floatdixf 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 * di_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 */ 28156cd587Sjoerg 29*f7f78b33Sjoerg COMPILER_RT_ABI long double __floatdixf(di_int a)30156cd587Sjoerg__floatdixf(di_int a) 31156cd587Sjoerg { 32156cd587Sjoerg if (a == 0) 33156cd587Sjoerg return 0.0; 34156cd587Sjoerg const unsigned N = sizeof(di_int) * CHAR_BIT; 35156cd587Sjoerg const di_int s = a >> (N-1); 36156cd587Sjoerg a = (a ^ s) - s; 37156cd587Sjoerg int clz = __builtin_clzll(a); 38156cd587Sjoerg int e = (N - 1) - clz ; /* exponent */ 39156cd587Sjoerg long_double_bits fb; 40156cd587Sjoerg fb.u.high.s.low = ((su_int)s & 0x00008000) | /* sign */ 41156cd587Sjoerg (e + 16383); /* exponent */ 42156cd587Sjoerg fb.u.low.all = a << clz; /* mantissa */ 43156cd587Sjoerg return fb.f; 44156cd587Sjoerg } 45156cd587Sjoerg 46156cd587Sjoerg #endif /* !_ARCH_PPC */ 47