blob: 8d6911ec00dd624c92366e748294d5b49830aa0d [file] [log] [blame]
Daniel Dunbarfd089992009-06-26 16:47:03 +00001//===-- floatdixf.c - Implement __floatdixf -------------------------------===//
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 __floatdixf 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// di_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__floatdixf(di_int a)
28{
29 if (a == 0)
30 return 0.0;
31 const unsigned N = sizeof(di_int) * CHAR_BIT;
32 const di_int s = a >> (N-1);
33 a = (a ^ s) - s;
34 int clz = __builtin_clzll(a);
35 int e = (N - 1) - clz ; // exponent
36 long_double_bits fb;
37 fb.u.high.low = ((su_int)s & 0x00008000) | // sign
38 (e + 16383); // exponent
39 fb.u.low.all = a << clz; // mantissa
40 return fb.f;
41}
42
43#endif