2009-08-08 04:30:09 +08:00
|
|
|
/* ===-- floatdixf.c - Implement __floatdixf -------------------------------===
|
|
|
|
*
|
|
|
|
* The LLVM Compiler Infrastructure
|
|
|
|
*
|
2010-11-17 06:13:33 +08:00
|
|
|
* This file is dual licensed under the MIT and the University of Illinois Open
|
|
|
|
* Source Licenses. See LICENSE.TXT for details.
|
2009-08-08 04:30:09 +08:00
|
|
|
*
|
|
|
|
* ===----------------------------------------------------------------------===
|
|
|
|
*
|
|
|
|
* This file implements __floatdixf for the compiler_rt library.
|
|
|
|
*
|
|
|
|
* ===----------------------------------------------------------------------===
|
|
|
|
*/
|
2009-06-27 00:47:03 +08:00
|
|
|
|
|
|
|
#if !_ARCH_PPC
|
|
|
|
|
|
|
|
#include "int_lib.h"
|
|
|
|
|
2009-08-08 04:30:09 +08:00
|
|
|
/* Returns: convert a to a long double, rounding toward even. */
|
2009-06-27 00:47:03 +08:00
|
|
|
|
2009-08-08 04:30:09 +08:00
|
|
|
/* Assumption: long double is a IEEE 80 bit floating point type padded to 128 bits
|
|
|
|
* di_int is a 64 bit integral type
|
|
|
|
*/
|
2009-06-27 00:47:03 +08:00
|
|
|
|
2009-08-08 04:30:09 +08:00
|
|
|
/* gggg gggg gggg gggg gggg gggg gggg gggg | gggg gggg gggg gggg seee eeee eeee eeee |
|
|
|
|
* 1mmm mmmm mmmm mmmm mmmm mmmm mmmm mmmm | mmmm mmmm mmmm mmmm mmmm mmmm mmmm mmmm
|
|
|
|
*/
|
2009-06-27 00:47:03 +08:00
|
|
|
|
|
|
|
long double
|
|
|
|
__floatdixf(di_int a)
|
|
|
|
{
|
|
|
|
if (a == 0)
|
|
|
|
return 0.0;
|
|
|
|
const unsigned N = sizeof(di_int) * CHAR_BIT;
|
|
|
|
const di_int s = a >> (N-1);
|
|
|
|
a = (a ^ s) - s;
|
|
|
|
int clz = __builtin_clzll(a);
|
2009-08-08 04:30:09 +08:00
|
|
|
int e = (N - 1) - clz ; /* exponent */
|
2009-06-27 00:47:03 +08:00
|
|
|
long_double_bits fb;
|
2009-08-10 02:41:02 +08:00
|
|
|
fb.u.high.s.low = ((su_int)s & 0x00008000) | /* sign */
|
|
|
|
(e + 16383); /* exponent */
|
2009-08-08 04:30:09 +08:00
|
|
|
fb.u.low.all = a << clz; /* mantissa */
|
2009-06-27 00:47:03 +08:00
|
|
|
return fb.f;
|
|
|
|
}
|
|
|
|
|
2009-08-10 02:41:02 +08:00
|
|
|
#endif /* !_ARCH_PPC */
|