blob: 6e8c4839f5d54b0194a4a4bf510bd6099e7b0599 [file] [log] [blame]
Daniel Dunbarfd089992009-06-26 16:47:03 +00001//===-- floatundixf.c - Implement __floatundixf ---------------------------===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9//
10// This file implements __floatundixf for the compiler_rt library.
11//
12//===----------------------------------------------------------------------===//
13
14#if !_ARCH_PPC
15
16#include "int_lib.h"
17
18// Returns: convert a to a long double, rounding toward even.
19
20// Assumption: long double is a IEEE 80 bit floating point type padded to 128 bits
21// du_int is a 64 bit integral type
22
23// gggg gggg gggg gggg gggg gggg gggg gggg | gggg gggg gggg gggg seee eeee eeee eeee |
24// 1mmm mmmm mmmm mmmm mmmm mmmm mmmm mmmm | mmmm mmmm mmmm mmmm mmmm mmmm mmmm mmmm
25
26long double
27__floatundixf(du_int a)
28{
29 if (a == 0)
30 return 0.0;
31 const unsigned N = sizeof(du_int) * CHAR_BIT;
32 int clz = __builtin_clzll(a);
33 int e = (N - 1) - clz ; // exponent
34 long_double_bits fb;
35 fb.u.high.low = (e + 16383); // exponent
36 fb.u.low.all = a << clz; // mantissa
37 return fb.f;
38}
39
40#endif