13cab2bb3Spatrick //===-- lib/floatunsitf.c - uint -> quad-precision conversion -----*- C -*-===//
23cab2bb3Spatrick //
33cab2bb3Spatrick // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
43cab2bb3Spatrick // See https://llvm.org/LICENSE.txt for license information.
53cab2bb3Spatrick // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
63cab2bb3Spatrick //
73cab2bb3Spatrick //===----------------------------------------------------------------------===//
83cab2bb3Spatrick //
93cab2bb3Spatrick // This file implements unsigned integer to quad-precision conversion for the
103cab2bb3Spatrick // compiler-rt library in the IEEE-754 default round-to-nearest, ties-to-even
113cab2bb3Spatrick // mode.
123cab2bb3Spatrick //
133cab2bb3Spatrick //===----------------------------------------------------------------------===//
143cab2bb3Spatrick 
153cab2bb3Spatrick #define QUAD_PRECISION
163cab2bb3Spatrick #include "fp_lib.h"
173cab2bb3Spatrick 
183cab2bb3Spatrick #if defined(CRT_HAS_128BIT) && defined(CRT_LDBL_128BIT)
__floatunsitf(su_int a)19*810390e3Srobert COMPILER_RT_ABI fp_t __floatunsitf(su_int a) {
203cab2bb3Spatrick 
213cab2bb3Spatrick   const int aWidth = sizeof a * CHAR_BIT;
223cab2bb3Spatrick 
233cab2bb3Spatrick   // Handle zero as a special case to protect clz
243cab2bb3Spatrick   if (a == 0)
253cab2bb3Spatrick     return fromRep(0);
263cab2bb3Spatrick 
273cab2bb3Spatrick   // Exponent of (fp_t)a is the width of abs(a).
28*810390e3Srobert   const int exponent = (aWidth - 1) - clzsi(a);
293cab2bb3Spatrick   rep_t result;
303cab2bb3Spatrick 
313cab2bb3Spatrick   // Shift a into the significand field and clear the implicit bit.
323cab2bb3Spatrick   const int shift = significandBits - exponent;
333cab2bb3Spatrick   result = (rep_t)a << shift ^ implicitBit;
343cab2bb3Spatrick 
353cab2bb3Spatrick   // Insert the exponent
363cab2bb3Spatrick   result += (rep_t)(exponent + exponentBias) << significandBits;
373cab2bb3Spatrick   return fromRep(result);
383cab2bb3Spatrick }
393cab2bb3Spatrick 
403cab2bb3Spatrick #endif
41