Skip to content

[builtins] Avoid using long double in generic sources #69754

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions compiler-rt/lib/builtins/divxc3.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,16 @@

// Returns: the quotient of (a + ib) / (c + id)

COMPILER_RT_ABI Lcomplex __divxc3(long double __a, long double __b,
long double __c, long double __d) {
COMPILER_RT_ABI Lcomplex __divxc3(xf_float __a, xf_float __b, xf_float __c,
xf_float __d) {
int __ilogbw = 0;
long double __logbw = crt_logbl(crt_fmaxl(crt_fabsl(__c), crt_fabsl(__d)));
xf_float __logbw = crt_logbl(crt_fmaxl(crt_fabsl(__c), crt_fabsl(__d)));
if (crt_isfinite(__logbw)) {
__ilogbw = (int)__logbw;
__c = crt_scalbnl(__c, -__ilogbw);
__d = crt_scalbnl(__d, -__ilogbw);
}
long double __denom = __c * __c + __d * __d;
xf_float __denom = __c * __c + __d * __d;
Lcomplex z;
COMPLEX_REAL(z) = crt_scalbnl((__a * __c + __b * __d) / __denom, -__ilogbw);
COMPLEX_IMAGINARY(z) =
Expand Down
2 changes: 1 addition & 1 deletion compiler-rt/lib/builtins/extendxftf2.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
#define DST_QUAD
#include "fp_extend_impl.inc"

COMPILER_RT_ABI tf_float __extendxftf2(long double a) {
COMPILER_RT_ABI tf_float __extendxftf2(xf_float a) {
return __extendXfYf2__(a);
}

Expand Down
4 changes: 2 additions & 2 deletions compiler-rt/lib/builtins/fixunsxfdi.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@
#pragma warning(disable : 4700)
#endif

COMPILER_RT_ABI du_int __fixunsxfdi(long double a) {
long_double_bits fb;
COMPILER_RT_ABI du_int __fixunsxfdi(xf_float a) {
xf_bits fb;
fb.f = a;
int e = (fb.u.high.s.low & 0x00007FFF) - 16383;
if (e < 0 || (fb.u.high.s.low & 0x00008000))
Expand Down
4 changes: 2 additions & 2 deletions compiler-rt/lib/builtins/fixunsxfsi.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@
#pragma warning(disable : 4700)
#endif

COMPILER_RT_ABI su_int __fixunsxfsi(long double a) {
long_double_bits fb;
COMPILER_RT_ABI su_int __fixunsxfsi(xf_float a) {
xf_bits fb;
fb.f = a;
int e = (fb.u.high.s.low & 0x00007FFF) - 16383;
if (e < 0 || (fb.u.high.s.low & 0x00008000))
Expand Down
4 changes: 2 additions & 2 deletions compiler-rt/lib/builtins/fixunsxfti.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@
// eeee | 1mmm mmmm mmmm mmmm mmmm mmmm mmmm mmmm | mmmm mmmm mmmm mmmm mmmm
// mmmm mmmm mmmm

COMPILER_RT_ABI tu_int __fixunsxfti(long double a) {
long_double_bits fb;
COMPILER_RT_ABI tu_int __fixunsxfti(xf_float a) {
xf_bits fb;
fb.f = a;
int e = (fb.u.high.s.low & 0x00007FFF) - 16383;
if (e < 0 || (fb.u.high.s.low & 0x00008000))
Expand Down
4 changes: 2 additions & 2 deletions compiler-rt/lib/builtins/fixxfdi.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,10 @@
#pragma warning(disable : 4700)
#endif

COMPILER_RT_ABI di_int __fixxfdi(long double a) {
COMPILER_RT_ABI di_int __fixxfdi(xf_float a) {
const di_int di_max = (di_int)((~(du_int)0) / 2);
const di_int di_min = -di_max - 1;
long_double_bits fb;
xf_bits fb;
fb.f = a;
int e = (fb.u.high.s.low & 0x00007FFF) - 16383;
if (e < 0)
Expand Down
4 changes: 2 additions & 2 deletions compiler-rt/lib/builtins/fixxfti.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@
// eeee | 1mmm mmmm mmmm mmmm mmmm mmmm mmmm mmmm | mmmm mmmm mmmm mmmm mmmm
// mmmm mmmm mmmm

COMPILER_RT_ABI ti_int __fixxfti(long double a) {
COMPILER_RT_ABI ti_int __fixxfti(xf_float a) {
const ti_int ti_max = (ti_int)((~(tu_int)0) / 2);
const ti_int ti_min = -ti_max - 1;
long_double_bits fb;
xf_bits fb;
fb.f = a;
int e = (fb.u.high.s.low & 0x00007FFF) - 16383;
if (e < 0)
Expand Down
4 changes: 2 additions & 2 deletions compiler-rt/lib/builtins/floatdixf.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,15 @@
// eeee | 1mmm mmmm mmmm mmmm mmmm mmmm mmmm mmmm | mmmm mmmm mmmm mmmm mmmm
// mmmm mmmm mmmm

COMPILER_RT_ABI long double __floatdixf(di_int a) {
COMPILER_RT_ABI xf_float __floatdixf(di_int a) {
if (a == 0)
return 0.0;
const unsigned N = sizeof(di_int) * CHAR_BIT;
const di_int s = a >> (N - 1);
a = (a ^ s) - s;
int clz = __builtin_clzll(a);
int e = (N - 1) - clz; // exponent
long_double_bits fb;
xf_bits fb;
fb.u.high.s.low = ((su_int)s & 0x00008000) | // sign
(e + 16383); // exponent
fb.u.low.all = a << clz; // mantissa
Expand Down
4 changes: 2 additions & 2 deletions compiler-rt/lib/builtins/floattixf.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
// eeee | 1mmm mmmm mmmm mmmm mmmm mmmm mmmm mmmm | mmmm mmmm mmmm mmmm mmmm
// mmmm mmmm mmmm

COMPILER_RT_ABI long double __floattixf(ti_int a) {
COMPILER_RT_ABI xf_float __floattixf(ti_int a) {
if (a == 0)
return 0.0;
const unsigned N = sizeof(ti_int) * CHAR_BIT;
Expand Down Expand Up @@ -63,7 +63,7 @@ COMPILER_RT_ABI long double __floattixf(ti_int a) {
a <<= (LDBL_MANT_DIG - sd);
// a is now rounded to LDBL_MANT_DIG bits
}
long_double_bits fb;
xf_bits fb;
fb.u.high.s.low = ((su_int)s & 0x8000) | // sign
(e + 16383); // exponent
fb.u.low.all = (du_int)a; // mantissa
Expand Down
4 changes: 2 additions & 2 deletions compiler-rt/lib/builtins/floatundixf.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,13 @@
// 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 long double __floatundixf(du_int a) {
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
long_double_bits fb;
xf_bits fb;
fb.u.high.s.low = (e + 16383); // exponent
fb.u.low.all = a << clz; // mantissa
return fb.f;
Expand Down
4 changes: 2 additions & 2 deletions compiler-rt/lib/builtins/floatuntixf.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
// eeee | 1mmm mmmm mmmm mmmm mmmm mmmm mmmm mmmm | mmmm mmmm mmmm mmmm mmmm
// mmmm mmmm mmmm

COMPILER_RT_ABI long double __floatuntixf(tu_int a) {
COMPILER_RT_ABI xf_float __floatuntixf(tu_int a) {
if (a == 0)
return 0.0;
const unsigned N = sizeof(tu_int) * CHAR_BIT;
Expand Down Expand Up @@ -61,7 +61,7 @@ COMPILER_RT_ABI long double __floatuntixf(tu_int a) {
a <<= (LDBL_MANT_DIG - sd);
// a is now rounded to LDBL_MANT_DIG bits
}
long_double_bits fb;
xf_bits fb;
fb.u.high.s.low = (e + 16383); // exponent
fb.u.low.all = (du_int)a; // mantissa
return fb.f;
Expand Down
2 changes: 1 addition & 1 deletion compiler-rt/lib/builtins/fp_extend.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ static inline int src_rep_t_clz_impl(src_rep_t a) {
#define src_rep_t_clz src_rep_t_clz_impl

#elif defined SRC_80
typedef long double src_t;
typedef xf_float src_t;
typedef __uint128_t src_rep_t;
#define SRC_REP_C (__uint128_t)
// sign bit, exponent and significand occupy the lower 80 bits.
Expand Down
2 changes: 1 addition & 1 deletion compiler-rt/lib/builtins/fp_trunc.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ static const int dstSigFracBits = 52;
static const int dstExpBits = 11;

#elif defined DST_80
typedef long double dst_t;
typedef xf_float dst_t;
typedef __uint128_t dst_rep_t;
#define DST_REP_C (__uint128_t)
static const int dstBits = 80;
Expand Down
2 changes: 1 addition & 1 deletion compiler-rt/lib/builtins/i386/floatdixf.S
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

#include "../assembly.h"

// long double __floatdixf(di_int a);
// xf_float __floatdixf(di_int a);

#ifdef __i386__

Expand Down
2 changes: 1 addition & 1 deletion compiler-rt/lib/builtins/i386/floatundixf.S
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

#include "../assembly.h"

// long double __floatundixf(du_int a);16
// xf_float __floatundixf(du_int a);16

#ifdef __i386__

Expand Down
13 changes: 8 additions & 5 deletions compiler-rt/lib/builtins/int_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,14 @@ typedef struct {
#define HAS_80_BIT_LONG_DOUBLE 0
#endif

#if HAS_80_BIT_LONG_DOUBLE
typedef long double xf_float;
typedef union {
uqwords u;
xf_float f;
} xf_bits;
#endif

#ifdef __powerpc64__
// From https://gcc.gnu.org/wiki/Ieee128PowerPC:
// PowerPC64 uses the following suffixes:
Expand Down Expand Up @@ -213,11 +221,6 @@ typedef union {
#endif

#if CRT_HAS_FLOATING_POINT
typedef union {
uqwords u;
long double f;
} long_double_bits;

#if __STDC_VERSION__ >= 199901L
typedef float _Complex Fcomplex;
typedef double _Complex Dcomplex;
Expand Down
12 changes: 6 additions & 6 deletions compiler-rt/lib/builtins/mulxc3.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@

// Returns: the product of a + ib and c + id

COMPILER_RT_ABI Lcomplex __mulxc3(long double __a, long double __b,
long double __c, long double __d) {
long double __ac = __a * __c;
long double __bd = __b * __d;
long double __ad = __a * __d;
long double __bc = __b * __c;
COMPILER_RT_ABI Lcomplex __mulxc3(xf_float __a, xf_float __b, xf_float __c,
xf_float __d) {
xf_float __ac = __a * __c;
xf_float __bd = __b * __d;
xf_float __ad = __a * __d;
xf_float __bc = __b * __c;
Lcomplex z;
COMPLEX_REAL(z) = __ac - __bd;
COMPLEX_IMAGINARY(z) = __ad + __bc;
Expand Down
4 changes: 2 additions & 2 deletions compiler-rt/lib/builtins/powixf2.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@

// Returns: a ^ b

COMPILER_RT_ABI long double __powixf2(long double a, int b) {
COMPILER_RT_ABI xf_float __powixf2(xf_float a, int b) {
const int recip = b < 0;
long double r = 1;
xf_float r = 1;
while (1) {
if (b & 1)
r *= a;
Expand Down
3 changes: 1 addition & 2 deletions compiler-rt/lib/builtins/ppc/multc3.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@
} \
}

long double _Complex __multc3(long double a, long double b, long double c,
long double d) {
xf_float _Complex __multc3(xf_float a, xf_float b, xf_float c, xf_float d) {
long double ac = __gcc_qmul(a, c);
long double bd = __gcc_qmul(b, d);
long double ad = __gcc_qmul(a, d);
Expand Down
4 changes: 1 addition & 3 deletions compiler-rt/lib/builtins/trunctfxf2.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@
#define DST_80
#include "fp_trunc_impl.inc"

COMPILER_RT_ABI long double __trunctfxf2(tf_float a) {
return __truncXfYf2__(a);
}
COMPILER_RT_ABI xf_float __trunctfxf2(tf_float a) { return __truncXfYf2__(a); }

#endif
4 changes: 2 additions & 2 deletions compiler-rt/lib/builtins/x86_64/floatdixf.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception

// long double __floatdixf(di_int a);
// xf_float __floatdixf(di_int a);

#ifdef __x86_64__

#include "../int_lib.h"

long double __floatdixf(int64_t a) { return (long double)a; }
xf_float __floatdixf(int64_t a) { return (xf_float)a; }

#endif // __i386__
2 changes: 1 addition & 1 deletion compiler-rt/lib/builtins/x86_64/floatundixf.S
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

#include "../assembly.h"

// long double __floatundixf(du_int a);
// xf_float __floatundixf(du_int a);

#ifdef __x86_64__

Expand Down