1/** 2University of Illinois/NCSA 3Open Source License 4 5Copyright (c) 2009-2014 by the contributors listed in CREDITS.TXT 6 7All rights reserved. 8 9Developed by: 10 11 LLVM Team 12 13 University of Illinois at Urbana-Champaign 14 15 http://llvm.org 16 17Permission is hereby granted, free of charge, to any person obtaining a copy of 18this software and associated documentation files (the "Software"), to deal with 19the Software without restriction, including without limitation the rights to 20use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies 21of the Software, and to permit persons to whom the Software is furnished to do 22so, subject to the following conditions: 23 24 * Redistributions of source code must retain the above copyright notice, 25 this list of conditions and the following disclaimers. 26 27 * Redistributions in binary form must reproduce the above copyright notice, 28 this list of conditions and the following disclaimers in the 29 documentation and/or other materials provided with the distribution. 30 31 * Neither the names of the LLVM Team, University of Illinois at 32 Urbana-Champaign, nor the names of its contributors may be used to 33 endorse or promote products derived from this Software without specific 34 prior written permission. 35 36THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 37IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 38FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 39CONTRIBUTORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 40LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 41OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS WITH THE 42SOFTWARE. 43**/ 44 45#define DOUBLE_PRECISION 46#include "fp_lib.h" 47 48#include "int_lib.h" 49 50ARM_EABI_FNALIAS(ui2d, floatunsidf) 51 52COMPILER_RT_ABI fp_t 53__floatunsidf(unsigned int a) { 54 55 const int aWidth = sizeof a * CHAR_BIT; 56 57 // Handle zero as a special case to protect clz 58 if (a == 0) return fromRep(0); 59 60 // Exponent of (fp_t)a is the width of abs(a). 61 const int exponent = (aWidth - 1) - __builtin_clz(a); 62 rep_t result; 63 64 // Shift a into the significand field and clear the implicit bit. 65 const int shift = significandBits - exponent; 66 result = (rep_t)a << shift ^ implicitBit; 67 68 // Insert the exponent 69 result += (rep_t)(exponent + exponentBias) << significandBits; 70 return fromRep(result); 71} 72