2009-08-08 04:30:09 +08:00
|
|
|
/* ===-- floatundixf.c - Implement __floatundixf ---------------------------===
|
|
|
|
*
|
|
|
|
* The LLVM Compiler Infrastructure
|
|
|
|
*
|
|
|
|
* This file is distributed under the University of Illinois Open Source
|
|
|
|
* License. See LICENSE.TXT for details.
|
|
|
|
*
|
|
|
|
* ===----------------------------------------------------------------------===
|
|
|
|
*
|
|
|
|
* This file implements __floatundixf 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
|
|
|
|
* du_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
|
|
|
|
__floatundixf(du_int a)
|
|
|
|
{
|
|
|
|
if (a == 0)
|
|
|
|
return 0.0;
|
|
|
|
const unsigned N = sizeof(du_int) * CHAR_BIT;
|
|
|
|
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 = (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-08 04:30:09 +08:00
|
|
|
#endif /* _ARCH_PPC */
|