1353358Sdim//===-- floatundixf.c - Implement __floatundixf ---------------------------===//
2353358Sdim//
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
6353358Sdim//
7353358Sdim//===----------------------------------------------------------------------===//
8353358Sdim//
9353358Sdim// This file implements __floatundixf for the compiler_rt library.
10353358Sdim//
11353358Sdim//===----------------------------------------------------------------------===//
12276789Sdim
13276789Sdim#if !_ARCH_PPC
14276789Sdim
15276789Sdim#include "int_lib.h"
16276789Sdim
17353358Sdim// Returns: convert a to a long double, rounding toward even.
18276789Sdim
19353358Sdim// Assumption: long double is a IEEE 80 bit floating point type padded to 128
20353358Sdim// bits du_int is a 64 bit integral type
21276789Sdim
22353358Sdim// gggg gggg gggg gggg gggg gggg gggg gggg | gggg gggg gggg gggg seee eeee eeee
23353358Sdim// eeee | 1mmm mmmm mmmm mmmm mmmm mmmm mmmm mmmm | mmmm mmmm mmmm mmmm mmmm
24353358Sdim// mmmm mmmm mmmm
25353358SdimCOMPILER_RT_ABI long double __floatundixf(du_int a) {
26353358Sdim  if (a == 0)
27353358Sdim    return 0.0;
28353358Sdim  const unsigned N = sizeof(du_int) * CHAR_BIT;
29353358Sdim  int clz = __builtin_clzll(a);
30353358Sdim  int e = (N - 1) - clz; // exponent
31353358Sdim  long_double_bits fb;
32353358Sdim  fb.u.high.s.low = (e + 16383); // exponent
33353358Sdim  fb.u.low.all = a << clz;       // mantissa
34353358Sdim  return fb.f;
35276789Sdim}
36276789Sdim
37353358Sdim#endif // _ARCH_PPC
38