Home | History | Annotate | Download | only in Arm
      1 /**
      2 University of Illinois/NCSA
      3 Open Source License
      4 
      5 Copyright (c) 2009-2014 by the contributors listed in CREDITS.TXT
      6 
      7 All rights reserved.
      8 
      9 Developed by:
     10 
     11     LLVM Team
     12 
     13     University of Illinois at Urbana-Champaign
     14 
     15     http://llvm.org
     16 
     17 Permission is hereby granted, free of charge, to any person obtaining a copy of
     18 this software and associated documentation files (the "Software"), to deal with
     19 the Software without restriction, including without limitation the rights to
     20 use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
     21 of the Software, and to permit persons to whom the Software is furnished to do
     22 so, 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 
     36 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
     37 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
     38 FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
     39 CONTRIBUTORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
     40 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
     41 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS WITH THE
     42 SOFTWARE.
     43 **/
     44 
     45 #define DOUBLE_PRECISION
     46 #include "fp_lib.h"
     47 
     48 #include "int_lib.h"
     49 
     50 ARM_EABI_FNALIAS(ui2d, floatunsidf)
     51 
     52 COMPILER_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