[docs] Update HowToReleaseLLVM documentation.
[llvm-project.git] / compiler-rt / lib / builtins / floatunsitf.c
blob7ba1fb6000dcc1f5a9dff159ed7b336013c7e1eb
1 //===-- lib/floatunsitf.c - uint -> quad-precision conversion -----*- C -*-===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // This file implements unsigned integer to quad-precision conversion for the
10 // compiler-rt library in the IEEE-754 default round-to-nearest, ties-to-even
11 // mode.
13 //===----------------------------------------------------------------------===//
15 #define QUAD_PRECISION
16 #include "fp_lib.h"
18 #if defined(CRT_HAS_128BIT) && defined(CRT_LDBL_128BIT)
19 COMPILER_RT_ABI fp_t __floatunsitf(su_int a) {
21 const int aWidth = sizeof a * CHAR_BIT;
23 // Handle zero as a special case to protect clz
24 if (a == 0)
25 return fromRep(0);
27 // Exponent of (fp_t)a is the width of abs(a).
28 const int exponent = (aWidth - 1) - clzsi(a);
29 rep_t result;
31 // Shift a into the significand field and clear the implicit bit.
32 const int shift = significandBits - exponent;
33 result = (rep_t)a << shift ^ implicitBit;
35 // Insert the exponent
36 result += (rep_t)(exponent + exponentBias) << significandBits;
37 return fromRep(result);
40 #endif