mirror of
https://github.com/llvm/llvm-project.git
synced 2025-04-25 23:36:06 +00:00

Use of long double can be error-prone since it could be one of 80-bit extended precision float, IEEE 128-bit float, or IBM 128-bit float. Instead use an explicit xf_float typedef for the remaining cases where long double is being used in the implementation. This patch does not touch the PPC specializations which still use long double.
38 lines
1.2 KiB
C
38 lines
1.2 KiB
C
//===-- floatundixf.c - Implement __floatundixf ---------------------------===//
|
|
//
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
//
|
|
// This file implements __floatundixf for the compiler_rt library.
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
#if !_ARCH_PPC
|
|
|
|
#include "int_lib.h"
|
|
|
|
// Returns: convert a to a long double, rounding toward even.
|
|
|
|
// Assumption: long double is a IEEE 80 bit floating point type padded to 128
|
|
// bits du_int is a 64 bit integral type
|
|
|
|
// gggg gggg gggg gggg gggg gggg gggg gggg | gggg gggg gggg gggg seee eeee eeee
|
|
// eeee | 1mmm mmmm mmmm mmmm mmmm mmmm mmmm mmmm | mmmm mmmm mmmm mmmm mmmm
|
|
// mmmm mmmm mmmm
|
|
COMPILER_RT_ABI xf_float __floatundixf(du_int a) {
|
|
if (a == 0)
|
|
return 0.0;
|
|
const unsigned N = sizeof(du_int) * CHAR_BIT;
|
|
int clz = __builtin_clzll(a);
|
|
int e = (N - 1) - clz; // exponent
|
|
xf_bits fb;
|
|
fb.u.high.s.low = (e + 16383); // exponent
|
|
fb.u.low.all = a << clz; // mantissa
|
|
return fb.f;
|
|
}
|
|
|
|
#endif // _ARCH_PPC
|