1 1.1 joerg //===-- lib/floatunsitf.c - uint -> quad-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 quad-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 QUAD_PRECISION 17 1.1 joerg #include "fp_lib.h" 18 1.1 joerg 19 1.1 joerg #if defined(CRT_HAS_128BIT) && defined(CRT_LDBL_128BIT) 20 1.1 joerg COMPILER_RT_ABI fp_t __floatunsitf(unsigned int a) { 21 1.1 joerg 22 1.1 joerg const int aWidth = sizeof a * CHAR_BIT; 23 1.1 joerg 24 1.1 joerg // Handle zero as a special case to protect clz 25 1.1 joerg if (a == 0) return fromRep(0); 26 1.1 joerg 27 1.1 joerg // Exponent of (fp_t)a is the width of abs(a). 28 1.1 joerg const int exponent = (aWidth - 1) - __builtin_clz(a); 29 1.1 joerg rep_t result; 30 1.1 joerg 31 1.1 joerg // Shift a into the significand field and clear the implicit bit. 32 1.1 joerg const int shift = significandBits - exponent; 33 1.1 joerg result = (rep_t)a << shift ^ implicitBit; 34 1.1 joerg 35 1.1 joerg // Insert the exponent 36 1.1 joerg result += (rep_t)(exponent + exponentBias) << significandBits; 37 1.1 joerg return fromRep(result); 38 1.1 joerg } 39 1.1 joerg 40 1.1 joerg #endif 41