1281223Semaste//===-- lib/floatunditf.c - uint -> quad-precision conversion -----*- C -*-===// 2281223Semaste// 3353358Sdim// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4353358Sdim// See https://llvm.org/LICENSE.txt for license information. 5353358Sdim// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6281223Semaste// 7281223Semaste//===----------------------------------------------------------------------===// 8281223Semaste// 9281223Semaste// This file implements du_int to quad-precision conversion for the 10281223Semaste// compiler-rt library in the IEEE-754 default round-to-nearest, ties-to-even 11281223Semaste// mode. 12281223Semaste// 13281223Semaste//===----------------------------------------------------------------------===// 14281223Semaste 15281223Semaste#define QUAD_PRECISION 16281223Semaste#include "fp_lib.h" 17281223Semaste 18281223Semaste#if defined(CRT_HAS_128BIT) && defined(CRT_LDBL_128BIT) 19281223SemasteCOMPILER_RT_ABI fp_t __floatunditf(du_int a) { 20281223Semaste 21353358Sdim const int aWidth = sizeof a * CHAR_BIT; 22281223Semaste 23353358Sdim // Handle zero as a special case to protect clz 24353358Sdim if (a == 0) 25353358Sdim return fromRep(0); 26281223Semaste 27353358Sdim // Exponent of (fp_t)a is the width of abs(a). 28353358Sdim const int exponent = (aWidth - 1) - __builtin_clzll(a); 29353358Sdim rep_t result; 30281223Semaste 31353358Sdim // Shift a into the significand field and clear the implicit bit. 32353358Sdim const int shift = significandBits - exponent; 33353358Sdim result = (rep_t)a << shift ^ implicitBit; 34281223Semaste 35353358Sdim // Insert the exponent 36353358Sdim result += (rep_t)(exponent + exponentBias) << significandBits; 37353358Sdim return fromRep(result); 38281223Semaste} 39281223Semaste 40281223Semaste#endif 41