]>
git.proxmox.com Git - rustc.git/blob - vendor/compiler_builtins/compiler-rt/lib/builtins/floatunditf.c
1 //===-- lib/floatunditf.c - uint -> quad-precision conversion -----*- C -*-===//
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 du_int to quad-precision conversion for the
11 // compiler-rt library in the IEEE-754 default round-to-nearest, ties-to-even
14 //===----------------------------------------------------------------------===//
16 #define QUAD_PRECISION
19 #if defined(CRT_HAS_128BIT) && defined(CRT_LDBL_128BIT)
20 COMPILER_RT_ABI fp_t
__floatunditf(du_int a
) {
22 const int aWidth
= sizeof a
* CHAR_BIT
;
24 // Handle zero as a special case to protect clz
25 if (a
== 0) return fromRep(0);
27 // Exponent of (fp_t)a is the width of abs(a).
28 const int exponent
= (aWidth
- 1) - __builtin_clzll(a
);
31 // Shift a into the significand field and clear the implicit bit.
32 const int shift
= significandBits
- exponent
;
33 result
= (rep_t
)a
<< shift
^ implicitBit
;
35 // Insert the exponent
36 result
+= (rep_t
)(exponent
+ exponentBias
) << significandBits
;
37 return fromRep(result
);