Wire Sysio Wire Sysion 1.0.0
Loading...
Searching...
No Matches
floatuntidf.c
Go to the documentation of this file.
1/* ===-- floatuntidf.c - Implement __floatuntidf ---------------------------===
2 *
3 * The LLVM Compiler Infrastructure
4 *
5 * This file is dual licensed under the MIT and the University of Illinois Open
6 * Source Licenses. See LICENSE.TXT for details.
7 *
8 * ===----------------------------------------------------------------------===
9 *
10 * This file implements __floatuntidf for the compiler_rt library.
11 *
12 * ===----------------------------------------------------------------------===
13 */
14
15#include "int_t.h"
16#include <float.h>
17
18/* Returns: convert a to a double, rounding toward even. */
19
20/* Assumption: double is a IEEE 64 bit floating point type
21 * tu_int is a 128 bit integral type
22 */
23
24/* seee eeee eeee mmmm mmmm mmmm mmmm mmmm | mmmm mmmm mmmm mmmm mmmm mmmm mmmm mmmm */
25
27{
28 if (a == 0)
29 return 0.0;
30 const unsigned N = sizeof(tu_int) * CHAR_BIT;
31 int sd = N - __clzti2(a); /* number of significant digits */
32 int e = sd - 1; /* exponent */
33 if (sd > DBL_MANT_DIG)
34 {
35 /* start: 0000000000000000000001xxxxxxxxxxxxxxxxxxxxxxPQxxxxxxxxxxxxxxxxxx
36 * finish: 000000000000000000000000000000000000001xxxxxxxxxxxxxxxxxxxxxxPQR
37 * 12345678901234567890123456
38 * 1 = msb 1 bit
39 * P = bit DBL_MANT_DIG-1 bits to the right of 1
40 * Q = bit DBL_MANT_DIG bits to the right of 1
41 * R = "or" of all bits to the right of Q
42 */
43 switch (sd)
44 {
45 case DBL_MANT_DIG + 1:
46 a <<= 1;
47 break;
48 case DBL_MANT_DIG + 2:
49 break;
50 default:
51 a = (a >> (sd - (DBL_MANT_DIG+2))) |
52 ((a & ((tu_int)(-1) >> ((N + DBL_MANT_DIG+2) - sd))) != 0);
53 };
54 /* finish: */
55 a |= (a & 4) != 0; /* Or P into R */
56 ++a; /* round - this step may add a significant bit */
57 a >>= 2; /* dump Q and R */
58 /* a is now rounded to DBL_MANT_DIG or DBL_MANT_DIG+1 bits */
59 if (a & ((tu_int)1 << DBL_MANT_DIG))
60 {
61 a >>= 1;
62 ++e;
63 }
64 /* a is now rounded to DBL_MANT_DIG bits */
65 }
66 else
67 {
68 a <<= (DBL_MANT_DIG - sd);
69 /* a is now rounded to DBL_MANT_DIG bits */
70 }
71 double_bits fb;
72 fb.u.s.high = ((e + 1023) << 20) | /* exponent */
73 ((uint32_t)(a >> 32) & 0x000FFFFF); /* mantissa-high */
74 fb.u.s.low = (uint32_t)a; /* mantissa-low */
75 return fb.f;
76}
unsigned __int128 tu_int
Definition fixunstfti.c:15
double ___floatuntidf(tu_int a)
Definition floatuntidf.c:26
__int128 __clzti2(__int128 a)
Definition int_t.h:45
const GenericPointer< typename T::ValueType > T2 T::AllocatorType & a
Definition pointer.h:1181
const int N
Definition quantize.cpp:54
unsigned int uint32_t
Definition stdint.h:126
double f
Definition int_t.h:39
udwords u
Definition int_t.h:38
struct udwords::@2 s