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