floatunsidf.c revision 214152
1214152Sed//===-- lib/floatunsidf.c - uint -> double-precision conversion ---*- C -*-===// 2214152Sed// 3214152Sed// The LLVM Compiler Infrastructure 4214152Sed// 5214152Sed// This file is distributed under the University of Illinois Open Source 6214152Sed// License. See LICENSE.TXT for details. 7214152Sed// 8214152Sed//===----------------------------------------------------------------------===// 9214152Sed// 10214152Sed// This file implements unsigned integer to double-precision conversion for the 11214152Sed// compiler-rt library in the IEEE-754 default round-to-nearest, ties-to-even 12214152Sed// mode. 13214152Sed// 14214152Sed//===----------------------------------------------------------------------===// 15214152Sed 16214152Sed#define DOUBLE_PRECISION 17214152Sed#include "fp_lib.h" 18214152Sed 19214152Sedfp_t __floatunsidf(unsigned int a) { 20214152Sed 21214152Sed const int aWidth = sizeof a * CHAR_BIT; 22214152Sed 23214152Sed // Handle zero as a special case to protect clz 24214152Sed if (a == 0) return fromRep(0); 25214152Sed 26214152Sed // Exponent of (fp_t)a is the width of abs(a). 27214152Sed const int exponent = (aWidth - 1) - __builtin_clz(a); 28214152Sed rep_t result; 29214152Sed 30214152Sed // Shift a into the significand field and clear the implicit bit. 31214152Sed const int shift = significandBits - exponent; 32214152Sed result = (rep_t)a << shift ^ implicitBit; 33214152Sed 34214152Sed // Insert the exponent 35214152Sed result += (rep_t)(exponent + exponentBias) << significandBits; 36214152Sed return fromRep(result); 37214152Sed} 38