1 //===-- lib/floatsidf.c - integer -> double-precision conversion --*- C -*-===//
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
9 // This file implements integer to double-precision conversion for the
10 // compiler-rt library in the IEEE-754 default round-to-nearest, ties-to-even
13 //===----------------------------------------------------------------------===//
15 #define DOUBLE_PRECISION
20 COMPILER_RT_ABI fp_t
__floatsidf(si_int a
) {
22 const int aWidth
= sizeof a
* CHAR_BIT
;
24 // Handle zero as a special case to protect clz
28 // All other cases begin by extracting the sign and absolute value of a
35 // Exponent of (fp_t)a is the width of abs(a).
36 const int exponent
= (aWidth
- 1) - clzsi(a
);
39 // Shift a into the significand field and clear the implicit bit. Extra
40 // cast to unsigned int is necessary to get the correct behavior for
42 const int shift
= significandBits
- exponent
;
43 result
= (rep_t
)(su_int
)a
<< shift
^ implicitBit
;
45 // Insert the exponent
46 result
+= (rep_t
)(exponent
+ exponentBias
) << significandBits
;
47 // Insert the sign bit and return
48 return fromRep(result
| sign
);
51 #if defined(__ARM_EABI__)
52 #if defined(COMPILER_RT_ARMHF_TARGET)
53 AEABI_RTABI fp_t
__aeabi_i2d(si_int a
) { return __floatsidf(a
); }
55 COMPILER_RT_ALIAS(__floatsidf
, __aeabi_i2d
)