1156cd587Sjoerg //===-- lib/floatunsidf.c - uint -> double-precision conversion ---*- C -*-===// 2156cd587Sjoerg // 3156cd587Sjoerg // The LLVM Compiler Infrastructure 4156cd587Sjoerg // 5156cd587Sjoerg // This file is dual licensed under the MIT and the University of Illinois Open 6156cd587Sjoerg // Source Licenses. See LICENSE.TXT for details. 7156cd587Sjoerg // 8156cd587Sjoerg //===----------------------------------------------------------------------===// 9156cd587Sjoerg // 10156cd587Sjoerg // This file implements unsigned integer to double-precision conversion for the 11156cd587Sjoerg // compiler-rt library in the IEEE-754 default round-to-nearest, ties-to-even 12156cd587Sjoerg // mode. 13156cd587Sjoerg // 14156cd587Sjoerg //===----------------------------------------------------------------------===// 15156cd587Sjoerg 16156cd587Sjoerg #define DOUBLE_PRECISION 17156cd587Sjoerg #include "fp_lib.h" 18156cd587Sjoerg 19156cd587Sjoerg #include "int_lib.h" 20156cd587Sjoerg 21f7f78b33Sjoerg COMPILER_RT_ABI fp_t __floatunsidf(unsigned int a)22f7f78b33Sjoerg__floatunsidf(unsigned int a) { 23156cd587Sjoerg 24156cd587Sjoerg const int aWidth = sizeof a * CHAR_BIT; 25156cd587Sjoerg 26156cd587Sjoerg // Handle zero as a special case to protect clz 27156cd587Sjoerg if (a == 0) return fromRep(0); 28156cd587Sjoerg 29156cd587Sjoerg // Exponent of (fp_t)a is the width of abs(a). 30156cd587Sjoerg const int exponent = (aWidth - 1) - __builtin_clz(a); 31156cd587Sjoerg rep_t result; 32156cd587Sjoerg 33156cd587Sjoerg // Shift a into the significand field and clear the implicit bit. 34156cd587Sjoerg const int shift = significandBits - exponent; 35156cd587Sjoerg result = (rep_t)a << shift ^ implicitBit; 36156cd587Sjoerg 37156cd587Sjoerg // Insert the exponent 38156cd587Sjoerg result += (rep_t)(exponent + exponentBias) << significandBits; 39156cd587Sjoerg return fromRep(result); 40156cd587Sjoerg } 413044ee7eSrin 423044ee7eSrin #if defined(__ARM_EABI__) 43*d3143459Srin #if defined(COMPILER_RT_ARMHF_TARGET) __aeabi_ui2d(unsigned int a)443044ee7eSrinAEABI_RTABI fp_t __aeabi_ui2d(unsigned int a) { 453044ee7eSrin return __floatunsidf(a); 463044ee7eSrin } 47*d3143459Srin #else 48*d3143459Srin AEABI_RTABI fp_t __aeabi_ui2d(unsigned int a) COMPILER_RT_ALIAS(__floatunsidf); 493044ee7eSrin #endif 50*d3143459Srin #endif 51