brintos

brintos / llvm-project-archived public Read only

0
0
Text · 1.2 KiB · 3e3c655 Raw
38 lines · c
1//===-- floatundixf.c - Implement __floatundixf ---------------------------===//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-exception6//7//===----------------------------------------------------------------------===//8//9// This file implements __floatundixf for the compiler_rt library.10//11//===----------------------------------------------------------------------===//12 13#if !_ARCH_PPC14 15#include "int_lib.h"16 17// Returns: convert a to a long double, rounding toward even.18 19// Assumption: long double is a IEEE 80 bit floating point type padded to 12820// bits du_int is a 64 bit integral type21 22// gggg gggg gggg gggg gggg gggg gggg gggg | gggg gggg gggg gggg seee eeee eeee23// eeee | 1mmm mmmm mmmm mmmm mmmm mmmm mmmm mmmm | mmmm mmmm mmmm mmmm mmmm24// mmmm mmmm mmmm25COMPILER_RT_ABI xf_float __floatundixf(du_int a) {26  if (a == 0)27    return 0.0;28  const unsigned N = sizeof(du_int) * CHAR_BIT;29  int clz = __builtin_clzll(a);30  int e = (N - 1) - clz; // exponent31  xf_bits fb;32  fb.u.high.s.low = (e + 16383); // exponent33  fb.u.low.all = a << clz;       // mantissa34  return fb.f;35}36 37#endif // _ARCH_PPC38