blob: 6158233a1da4cbd337f8fd75d75c0a8074f47dc8 [file] [log] [blame]
Joerg Sonnenberger086f46a2014-09-16 20:34:41 +00001//===-- lib/floatunsitf.c - uint -> quad-precision conversion -----*- C -*-===//
2//
Chandler Carruth7a739a02019-01-19 10:56:40 +00003// 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
Joerg Sonnenberger086f46a2014-09-16 20:34:41 +00006//
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.
12//
13//===----------------------------------------------------------------------===//
14
15#define QUAD_PRECISION
16#include "fp_lib.h"
17
18#if defined(CRT_HAS_128BIT) && defined(CRT_LDBL_128BIT)
19COMPILER_RT_ABI fp_t __floatunsitf(unsigned int a) {
20
21 const int aWidth = sizeof a * CHAR_BIT;
22
23 // Handle zero as a special case to protect clz
24 if (a == 0) return fromRep(0);
25
26 // Exponent of (fp_t)a is the width of abs(a).
27 const int exponent = (aWidth - 1) - __builtin_clz(a);
28 rep_t result;
29
30 // Shift a into the significand field and clear the implicit bit.
31 const int shift = significandBits - exponent;
32 result = (rep_t)a << shift ^ implicitBit;
33
34 // Insert the exponent
35 result += (rep_t)(exponent + exponentBias) << significandBits;
36 return fromRep(result);
37}
38
39#endif