1 1.1 joerg //===-- lib/floatunsidf.c - uint -> double-precision conversion ---*- C -*-===// 2 1.1 joerg // 3 1.1 joerg // The LLVM Compiler Infrastructure 4 1.1 joerg // 5 1.1 joerg // This file is dual licensed under the MIT and the University of Illinois Open 6 1.1 joerg // Source Licenses. See LICENSE.TXT for details. 7 1.1 joerg // 8 1.1 joerg //===----------------------------------------------------------------------===// 9 1.1 joerg // 10 1.1 joerg // This file implements unsigned integer to double-precision conversion for the 11 1.1 joerg // compiler-rt library in the IEEE-754 default round-to-nearest, ties-to-even 12 1.1 joerg // mode. 13 1.1 joerg // 14 1.1 joerg //===----------------------------------------------------------------------===// 15 1.1 joerg 16 1.1 joerg #define DOUBLE_PRECISION 17 1.1 joerg #include "fp_lib.h" 18 1.1 joerg 19 1.1 joerg #include "int_lib.h" 20 1.1 joerg 21 1.2 rin COMPILER_RT_ABI fp_t 22 1.2 rin __floatunsidf(unsigned int a) { 23 1.1 joerg 24 1.1 joerg const int aWidth = sizeof a * CHAR_BIT; 25 1.1 joerg 26 1.1 joerg // Handle zero as a special case to protect clz 27 1.1 joerg if (a == 0) return fromRep(0); 28 1.1 joerg 29 1.1 joerg // Exponent of (fp_t)a is the width of abs(a). 30 1.1 joerg const int exponent = (aWidth - 1) - __builtin_clz(a); 31 1.1 joerg rep_t result; 32 1.1 joerg 33 1.1 joerg // Shift a into the significand field and clear the implicit bit. 34 1.1 joerg const int shift = significandBits - exponent; 35 1.1 joerg result = (rep_t)a << shift ^ implicitBit; 36 1.1 joerg 37 1.1 joerg // Insert the exponent 38 1.1 joerg result += (rep_t)(exponent + exponentBias) << significandBits; 39 1.1 joerg return fromRep(result); 40 1.1 joerg } 41 1.2 rin 42 1.2 rin #if defined(__ARM_EABI__) 43 1.3 rin #if defined(COMPILER_RT_ARMHF_TARGET) 44 1.2 rin AEABI_RTABI fp_t __aeabi_ui2d(unsigned int a) { 45 1.2 rin return __floatunsidf(a); 46 1.2 rin } 47 1.3 rin #else 48 1.3 rin AEABI_RTABI fp_t __aeabi_ui2d(unsigned int a) COMPILER_RT_ALIAS(__floatunsidf); 49 1.3 rin #endif 50 1.2 rin #endif 51