[ASan/Win tests] Bring back -GS- as SEH tests fail otherwise
[blocksruntime.git] / lib / builtins / floatundixf.c
blobca5e06d64dcdb6a86274b52017525641d381f9e8
1 /* ===-- floatundixf.c - Implement __floatundixf ---------------------------===
3 * The LLVM Compiler Infrastructure
5 * This file is dual licensed under the MIT and the University of Illinois Open
6 * Source Licenses. See LICENSE.TXT for details.
8 * ===----------------------------------------------------------------------===
10 * This file implements __floatundixf for the compiler_rt library.
12 * ===----------------------------------------------------------------------===
15 #if !_ARCH_PPC
17 #include "int_lib.h"
19 /* Returns: convert a to a long double, rounding toward even. */
21 /* Assumption: long double is a IEEE 80 bit floating point type padded to 128 bits
22 * du_int is a 64 bit integral type
25 /* gggg gggg gggg gggg gggg gggg gggg gggg | gggg gggg gggg gggg seee eeee eeee eeee |
26 * 1mmm mmmm mmmm mmmm mmmm mmmm mmmm mmmm | mmmm mmmm mmmm mmmm mmmm mmmm mmmm mmmm
28 COMPILER_RT_ABI long double
29 __floatundixf(du_int a)
31 if (a == 0)
32 return 0.0;
33 const unsigned N = sizeof(du_int) * CHAR_BIT;
34 int clz = __builtin_clzll(a);
35 int e = (N - 1) - clz ; /* exponent */
36 long_double_bits fb;
37 fb.u.high.s.low = (e + 16383); /* exponent */
38 fb.u.low.all = a << clz; /* mantissa */
39 return fb.f;
42 #endif /* _ARCH_PPC */