diff --git a/compiler-rt/lib/builtins/addtf3.c b/compiler-rt/lib/builtins/addtf3.c --- a/compiler-rt/lib/builtins/addtf3.c +++ b/compiler-rt/lib/builtins/addtf3.c @@ -13,7 +13,7 @@ #define QUAD_PRECISION #include "fp_lib.h" -#if defined(CRT_HAS_128BIT) && defined(CRT_LDBL_128BIT) +#if defined(CRT_HAS_128BIT) && defined(CRT_HAS_F128) #include "fp_add_impl.inc" COMPILER_RT_ABI fp_t __addtf3(fp_t a, fp_t b) { diff --git a/compiler-rt/lib/builtins/comparetf2.c b/compiler-rt/lib/builtins/comparetf2.c --- a/compiler-rt/lib/builtins/comparetf2.c +++ b/compiler-rt/lib/builtins/comparetf2.c @@ -39,7 +39,7 @@ #define QUAD_PRECISION #include "fp_lib.h" -#if defined(CRT_HAS_128BIT) && defined(CRT_LDBL_128BIT) +#if defined(CRT_HAS_128BIT) && defined(CRT_HAS_F128) #include "fp_compare_impl.inc" COMPILER_RT_ABI CMP_RESULT __letf2(fp_t a, fp_t b) { return __leXf2__(a, b); } diff --git a/compiler-rt/lib/builtins/divtc3.c b/compiler-rt/lib/builtins/divtc3.c --- a/compiler-rt/lib/builtins/divtc3.c +++ b/compiler-rt/lib/builtins/divtc3.c @@ -12,44 +12,45 @@ #define QUAD_PRECISION #include "fp_lib.h" -#include "int_lib.h" -#include "int_math.h" + +#if defined(CRT_HAS_F128) // Returns: the quotient of (a + ib) / (c + id) -COMPILER_RT_ABI Lcomplex __divtc3(long double __a, long double __b, - long double __c, long double __d) { +COMPILER_RT_ABI Qcomplex __divtc3(f128 __a, f128 __b, f128 __c, f128 __d) { int __ilogbw = 0; - long double __logbw = - __compiler_rt_logbl(__compiler_rt_fmaxl(crt_fabsl(__c), crt_fabsl(__d))); + f128 __logbw = __compiler_rt_logbf128( + __compiler_rt_fmaxf128(crt_fabsf128(__c), crt_fabsf128(__d))); if (crt_isfinite(__logbw)) { __ilogbw = (int)__logbw; - __c = __compiler_rt_scalbnl(__c, -__ilogbw); - __d = __compiler_rt_scalbnl(__d, -__ilogbw); + __c = __compiler_rt_scalbnf128(__c, -__ilogbw); + __d = __compiler_rt_scalbnf128(__d, -__ilogbw); } - long double __denom = __c * __c + __d * __d; - Lcomplex z; - COMPLEX_REAL(z) = - __compiler_rt_scalbnl((__a * __c + __b * __d) / __denom, -__ilogbw); - COMPLEX_IMAGINARY(z) = - __compiler_rt_scalbnl((__b * __c - __a * __d) / __denom, -__ilogbw); - if (crt_isnan(COMPLEX_REAL(z)) && crt_isnan(COMPLEX_IMAGINARY(z))) { + f128 __denom = __c * __c + __d * __d; + Qcomplex z; + COMPLEX128_REAL(z) = + __compiler_rt_scalbnf128((__a * __c + __b * __d) / __denom, -__ilogbw); + COMPLEX128_IMAGINARY(z) = + __compiler_rt_scalbnf128((__b * __c - __a * __d) / __denom, -__ilogbw); + if (crt_isnan(COMPLEX128_REAL(z)) && crt_isnan(COMPLEX128_IMAGINARY(z))) { if ((__denom == 0.0) && (!crt_isnan(__a) || !crt_isnan(__b))) { - COMPLEX_REAL(z) = crt_copysignl(CRT_INFINITY, __c) * __a; - COMPLEX_IMAGINARY(z) = crt_copysignl(CRT_INFINITY, __c) * __b; + COMPLEX128_REAL(z) = crt_copysignf128(CRT_INFINITY, __c) * __a; + COMPLEX128_IMAGINARY(z) = crt_copysignf128(CRT_INFINITY, __c) * __b; } else if ((crt_isinf(__a) || crt_isinf(__b)) && crt_isfinite(__c) && crt_isfinite(__d)) { - __a = crt_copysignl(crt_isinf(__a) ? 1.0 : 0.0, __a); - __b = crt_copysignl(crt_isinf(__b) ? 1.0 : 0.0, __b); - COMPLEX_REAL(z) = CRT_INFINITY * (__a * __c + __b * __d); - COMPLEX_IMAGINARY(z) = CRT_INFINITY * (__b * __c - __a * __d); + __a = crt_copysignf128(crt_isinf(__a) ? (f128)1.0 : (f128)0.0, __a); + __b = crt_copysignf128(crt_isinf(__b) ? (f128)1.0 : (f128)0.0, __b); + COMPLEX128_REAL(z) = CRT_INFINITY * (__a * __c + __b * __d); + COMPLEX128_IMAGINARY(z) = CRT_INFINITY * (__b * __c - __a * __d); } else if (crt_isinf(__logbw) && __logbw > 0.0 && crt_isfinite(__a) && crt_isfinite(__b)) { - __c = crt_copysignl(crt_isinf(__c) ? 1.0 : 0.0, __c); - __d = crt_copysignl(crt_isinf(__d) ? 1.0 : 0.0, __d); - COMPLEX_REAL(z) = 0.0 * (__a * __c + __b * __d); - COMPLEX_IMAGINARY(z) = 0.0 * (__b * __c - __a * __d); + __c = crt_copysignf128(crt_isinf(__c) ? (f128)1.0 : (f128)0.0, __c); + __d = crt_copysignf128(crt_isinf(__d) ? (f128)1.0 : (f128)0.0, __d); + COMPLEX128_REAL(z) = 0.0 * (__a * __c + __b * __d); + COMPLEX128_IMAGINARY(z) = 0.0 * (__b * __c - __a * __d); } } return z; } + +#endif diff --git a/compiler-rt/lib/builtins/divtf3.c b/compiler-rt/lib/builtins/divtf3.c --- a/compiler-rt/lib/builtins/divtf3.c +++ b/compiler-rt/lib/builtins/divtf3.c @@ -14,7 +14,7 @@ #define QUAD_PRECISION #include "fp_lib.h" -#if defined(CRT_HAS_128BIT) && defined(CRT_LDBL_128BIT) +#if defined(CRT_HAS_128BIT) && defined(CRT_HAS_F128) #define NUMBER_OF_HALF_ITERATIONS 4 #define NUMBER_OF_FULL_ITERATIONS 1 diff --git a/compiler-rt/lib/builtins/extenddftf2.c b/compiler-rt/lib/builtins/extenddftf2.c --- a/compiler-rt/lib/builtins/extenddftf2.c +++ b/compiler-rt/lib/builtins/extenddftf2.c @@ -9,12 +9,12 @@ #define QUAD_PRECISION #include "fp_lib.h" -#if defined(CRT_HAS_128BIT) && defined(CRT_LDBL_128BIT) +#if defined(CRT_HAS_128BIT) && defined(CRT_HAS_F128) #define SRC_DOUBLE #define DST_QUAD #include "fp_extend_impl.inc" -COMPILER_RT_ABI fp_t __extenddftf2(double a) { +COMPILER_RT_ABI f128 __extenddftf2(double a) { return __extendXfYf2__(a); } diff --git a/compiler-rt/lib/builtins/extendhftf2.c b/compiler-rt/lib/builtins/extendhftf2.c --- a/compiler-rt/lib/builtins/extendhftf2.c +++ b/compiler-rt/lib/builtins/extendhftf2.c @@ -10,13 +10,12 @@ #define QUAD_PRECISION #include "fp_lib.h" -#if defined(CRT_HAS_128BIT) && defined(CRT_LDBL_128BIT) && \ - defined(COMPILER_RT_HAS_FLOAT16) +#if defined(CRT_HAS_128BIT) && defined(CRT_HAS_F128) #define SRC_HALF #define DST_QUAD #include "fp_extend_impl.inc" -COMPILER_RT_ABI long double __extendhftf2(_Float16 a) { +COMPILER_RT_ABI f128 __extendhftf2(src_t a) { return __extendXfYf2__(a); } diff --git a/compiler-rt/lib/builtins/extendsftf2.c b/compiler-rt/lib/builtins/extendsftf2.c --- a/compiler-rt/lib/builtins/extendsftf2.c +++ b/compiler-rt/lib/builtins/extendsftf2.c @@ -9,12 +9,12 @@ #define QUAD_PRECISION #include "fp_lib.h" -#if defined(CRT_HAS_128BIT) && defined(CRT_LDBL_128BIT) +#if defined(CRT_HAS_128BIT) && defined(CRT_HAS_F128) #define SRC_SINGLE #define DST_QUAD #include "fp_extend_impl.inc" -COMPILER_RT_ABI fp_t __extendsftf2(float a) { +COMPILER_RT_ABI f128 __extendsftf2(float a) { return __extendXfYf2__(a); } diff --git a/compiler-rt/lib/builtins/fixtfdi.c b/compiler-rt/lib/builtins/fixtfdi.c --- a/compiler-rt/lib/builtins/fixtfdi.c +++ b/compiler-rt/lib/builtins/fixtfdi.c @@ -9,7 +9,7 @@ #define QUAD_PRECISION #include "fp_lib.h" -#if defined(CRT_HAS_128BIT) && defined(CRT_LDBL_128BIT) +#if defined(CRT_HAS_128BIT) && defined(CRT_HAS_F128) typedef di_int fixint_t; typedef du_int fixuint_t; #include "fp_fixint_impl.inc" diff --git a/compiler-rt/lib/builtins/fixtfsi.c b/compiler-rt/lib/builtins/fixtfsi.c --- a/compiler-rt/lib/builtins/fixtfsi.c +++ b/compiler-rt/lib/builtins/fixtfsi.c @@ -9,7 +9,7 @@ #define QUAD_PRECISION #include "fp_lib.h" -#if defined(CRT_HAS_128BIT) && defined(CRT_LDBL_128BIT) +#if defined(CRT_HAS_128BIT) && defined(CRT_HAS_F128) typedef si_int fixint_t; typedef su_int fixuint_t; #include "fp_fixint_impl.inc" diff --git a/compiler-rt/lib/builtins/fixtfti.c b/compiler-rt/lib/builtins/fixtfti.c --- a/compiler-rt/lib/builtins/fixtfti.c +++ b/compiler-rt/lib/builtins/fixtfti.c @@ -9,7 +9,7 @@ #define QUAD_PRECISION #include "fp_lib.h" -#if defined(CRT_HAS_128BIT) && defined(CRT_LDBL_128BIT) +#if defined(CRT_HAS_128BIT) && defined(CRT_HAS_F128) typedef ti_int fixint_t; typedef tu_int fixuint_t; #include "fp_fixint_impl.inc" diff --git a/compiler-rt/lib/builtins/fixunstfdi.c b/compiler-rt/lib/builtins/fixunstfdi.c --- a/compiler-rt/lib/builtins/fixunstfdi.c +++ b/compiler-rt/lib/builtins/fixunstfdi.c @@ -9,7 +9,7 @@ #define QUAD_PRECISION #include "fp_lib.h" -#if defined(CRT_HAS_128BIT) && defined(CRT_LDBL_128BIT) +#if defined(CRT_HAS_128BIT) && defined(CRT_HAS_F128) typedef du_int fixuint_t; #include "fp_fixuint_impl.inc" diff --git a/compiler-rt/lib/builtins/fixunstfsi.c b/compiler-rt/lib/builtins/fixunstfsi.c --- a/compiler-rt/lib/builtins/fixunstfsi.c +++ b/compiler-rt/lib/builtins/fixunstfsi.c @@ -9,7 +9,7 @@ #define QUAD_PRECISION #include "fp_lib.h" -#if defined(CRT_HAS_128BIT) && defined(CRT_LDBL_128BIT) +#if defined(CRT_HAS_128BIT) && defined(CRT_HAS_F128) typedef su_int fixuint_t; #include "fp_fixuint_impl.inc" diff --git a/compiler-rt/lib/builtins/fixunstfti.c b/compiler-rt/lib/builtins/fixunstfti.c --- a/compiler-rt/lib/builtins/fixunstfti.c +++ b/compiler-rt/lib/builtins/fixunstfti.c @@ -9,7 +9,7 @@ #define QUAD_PRECISION #include "fp_lib.h" -#if defined(CRT_HAS_128BIT) && defined(CRT_LDBL_128BIT) +#if defined(CRT_HAS_128BIT) && defined(CRT_HAS_F128) typedef tu_int fixuint_t; #include "fp_fixuint_impl.inc" diff --git a/compiler-rt/lib/builtins/floatditf.c b/compiler-rt/lib/builtins/floatditf.c --- a/compiler-rt/lib/builtins/floatditf.c +++ b/compiler-rt/lib/builtins/floatditf.c @@ -15,7 +15,7 @@ #define QUAD_PRECISION #include "fp_lib.h" -#if defined(CRT_HAS_128BIT) && defined(CRT_LDBL_128BIT) +#if defined(CRT_HAS_128BIT) && defined(CRT_HAS_F128) COMPILER_RT_ABI fp_t __floatditf(di_int a) { const int aWidth = sizeof a * CHAR_BIT; diff --git a/compiler-rt/lib/builtins/floatsitf.c b/compiler-rt/lib/builtins/floatsitf.c --- a/compiler-rt/lib/builtins/floatsitf.c +++ b/compiler-rt/lib/builtins/floatsitf.c @@ -15,7 +15,7 @@ #define QUAD_PRECISION #include "fp_lib.h" -#if defined(CRT_HAS_128BIT) && defined(CRT_LDBL_128BIT) +#if defined(CRT_HAS_128BIT) && defined(CRT_HAS_F128) COMPILER_RT_ABI fp_t __floatsitf(int a) { const int aWidth = sizeof a * CHAR_BIT; diff --git a/compiler-rt/lib/builtins/floattitf.c b/compiler-rt/lib/builtins/floattitf.c --- a/compiler-rt/lib/builtins/floattitf.c +++ b/compiler-rt/lib/builtins/floattitf.c @@ -25,7 +25,7 @@ // mmmm | mmmm mmmm mmmm mmmm mmmm mmmm mmmm mmmm | mmmm mmmm mmmm mmmm mmmm // mmmm mmmm mmmm -#if defined(CRT_HAS_128BIT) && defined(CRT_LDBL_128BIT) +#if defined(CRT_HAS_128BIT) && defined(CRT_HAS_F128) COMPILER_RT_ABI fp_t __floattitf(ti_int a) { if (a == 0) return 0.0; diff --git a/compiler-rt/lib/builtins/floatunditf.c b/compiler-rt/lib/builtins/floatunditf.c --- a/compiler-rt/lib/builtins/floatunditf.c +++ b/compiler-rt/lib/builtins/floatunditf.c @@ -15,7 +15,7 @@ #define QUAD_PRECISION #include "fp_lib.h" -#if defined(CRT_HAS_128BIT) && defined(CRT_LDBL_128BIT) +#if defined(CRT_HAS_128BIT) && defined(CRT_HAS_F128) COMPILER_RT_ABI fp_t __floatunditf(du_int a) { const int aWidth = sizeof a * CHAR_BIT; diff --git a/compiler-rt/lib/builtins/floatunsitf.c b/compiler-rt/lib/builtins/floatunsitf.c --- a/compiler-rt/lib/builtins/floatunsitf.c +++ b/compiler-rt/lib/builtins/floatunsitf.c @@ -15,7 +15,7 @@ #define QUAD_PRECISION #include "fp_lib.h" -#if defined(CRT_HAS_128BIT) && defined(CRT_LDBL_128BIT) +#if defined(CRT_HAS_128BIT) && defined(CRT_HAS_F128) COMPILER_RT_ABI fp_t __floatunsitf(unsigned int a) { const int aWidth = sizeof a * CHAR_BIT; diff --git a/compiler-rt/lib/builtins/floatuntitf.c b/compiler-rt/lib/builtins/floatuntitf.c --- a/compiler-rt/lib/builtins/floatuntitf.c +++ b/compiler-rt/lib/builtins/floatuntitf.c @@ -25,7 +25,7 @@ // mmmm | mmmm mmmm mmmm mmmm mmmm mmmm mmmm mmmm | mmmm mmmm mmmm mmmm mmmm // mmmm mmmm mmmm -#if defined(CRT_HAS_128BIT) && defined(CRT_LDBL_128BIT) +#if defined(CRT_HAS_128BIT) && defined(CRT_HAS_F128) COMPILER_RT_ABI fp_t __floatuntitf(tu_int a) { if (a == 0) return 0.0; diff --git a/compiler-rt/lib/builtins/fp_extend.h b/compiler-rt/lib/builtins/fp_extend.h --- a/compiler-rt/lib/builtins/fp_extend.h +++ b/compiler-rt/lib/builtins/fp_extend.h @@ -67,7 +67,7 @@ static const int dstSigBits = 52; #elif defined DST_QUAD -typedef long double dst_t; +typedef f128 dst_t; typedef __uint128_t dst_rep_t; #define DST_REP_C (__uint128_t) static const int dstSigBits = 112; diff --git a/compiler-rt/lib/builtins/fp_lib.h b/compiler-rt/lib/builtins/fp_lib.h --- a/compiler-rt/lib/builtins/fp_lib.h +++ b/compiler-rt/lib/builtins/fp_lib.h @@ -105,12 +105,12 @@ COMPILER_RT_ABI fp_t __adddf3(fp_t a, fp_t b); #elif defined QUAD_PRECISION -#if __LDBL_MANT_DIG__ == 113 && defined(__SIZEOF_INT128__) -#define CRT_LDBL_128BIT +#if defined(__SIZEOF_INT128__) && defined(CRT_HAS_F128) +#define CRT_HAS_F128 typedef uint64_t half_rep_t; typedef __uint128_t rep_t; typedef __int128_t srep_t; -typedef long double fp_t; +typedef f128 fp_t; #define HALF_REP_C UINT64_C #define REP_C (__uint128_t) // Note: Since there is no explicit way to tell compiler the constant is a @@ -200,13 +200,13 @@ #undef Word_HiMask #undef Word_LoMask #undef Word_FullMask -#endif // __LDBL_MANT_DIG__ == 113 && __SIZEOF_INT128__ +#endif // defined(__SIZEOF_INT128__) && defined(CRT_HAS_F128) #else #error SINGLE_PRECISION, DOUBLE_PRECISION or QUAD_PRECISION must be defined. #endif #if defined(SINGLE_PRECISION) || defined(DOUBLE_PRECISION) || \ - defined(CRT_LDBL_128BIT) + defined(CRT_HAS_F128) #define typeWidth (sizeof(rep_t) * CHAR_BIT) #define exponentBits (typeWidth - significandBits - 1) #define maxExponent ((1 << exponentBits) - 1) @@ -388,14 +388,14 @@ #elif defined(QUAD_PRECISION) -#if defined(CRT_LDBL_128BIT) -static __inline fp_t __compiler_rt_logbl(fp_t x) { +#if defined(CRT_HAS_F128) +static __inline f128 __compiler_rt_logbf128(f128 x) { return __compiler_rt_logbX(x); } -static __inline fp_t __compiler_rt_scalbnl(fp_t x, int y) { +static __inline f128 __compiler_rt_scalbnf128(f128 x, int y) { return __compiler_rt_scalbnX(x, y); } -static __inline fp_t __compiler_rt_fmaxl(fp_t x, fp_t y) { +static __inline f128 __compiler_rt_fmaxf128(f128 x, f128 y) { return __compiler_rt_fmaxX(x, y); } #else @@ -410,7 +410,7 @@ static __inline long double __compiler_rt_fmaxl(long double x, long double y) { return crt_fmaxl(x, y); } -#endif // CRT_LDBL_128BIT +#endif // CRT_HAS_F128 #endif // *_PRECISION diff --git a/compiler-rt/lib/builtins/fp_trunc.h b/compiler-rt/lib/builtins/fp_trunc.h --- a/compiler-rt/lib/builtins/fp_trunc.h +++ b/compiler-rt/lib/builtins/fp_trunc.h @@ -28,7 +28,7 @@ static const int srcSigBits = 52; #elif defined SRC_QUAD -typedef long double src_t; +typedef f128 src_t; typedef __uint128_t src_rep_t; #define SRC_REP_C (__uint128_t) static const int srcSigBits = 112; diff --git a/compiler-rt/lib/builtins/int_math.h b/compiler-rt/lib/builtins/int_math.h --- a/compiler-rt/lib/builtins/int_math.h +++ b/compiler-rt/lib/builtins/int_math.h @@ -65,6 +65,12 @@ #define crt_copysign(x, y) __builtin_copysign((x), (y)) #define crt_copysignf(x, y) __builtin_copysignf((x), (y)) #define crt_copysignl(x, y) __builtin_copysignl((x), (y)) +#if __has_builtin(__builtin_copysignf128) +#define crt_copysignf128(x, y) __builtin_copysignf128((x), (y)) +#elif __has_builtin(__builtin_copysignq) || (defined(__GNUC__) && __GNUC__ >= 7) +#define crt_copysignf128(x, y) __builtin_copysignq((x), (y)) +#elif +#endif #endif #if defined(_MSC_VER) && !defined(__clang__) @@ -75,6 +81,11 @@ #define crt_fabs(x) __builtin_fabs((x)) #define crt_fabsf(x) __builtin_fabsf((x)) #define crt_fabsl(x) __builtin_fabsl((x)) +#if __has_builtin(__builtin_fabsf128) +#define crt_fabsf128(x) __builtin_fabsf128((x)) +#elif __has_builtin(__builtin_fabsq) || (defined(__GNUC__) && __GNUC__ >= 7) +#define crt_fabsf128(x) __builtin_fabsq((x)) +#endif #endif #if defined(_MSC_VER) && !defined(__clang__) diff --git a/compiler-rt/lib/builtins/int_types.h b/compiler-rt/lib/builtins/int_types.h --- a/compiler-rt/lib/builtins/int_types.h +++ b/compiler-rt/lib/builtins/int_types.h @@ -165,6 +165,16 @@ #define HAS_80_BIT_LONG_DOUBLE 0 #endif +#if __LDBL_MANT_DIG__ == 113 +#define CRT_LDBL_128BIT +#define CRT_HAS_F128 +typedef long double f128; +#elif defined(__FLOAT128__) || defined(__SIZEOF_FLOAT128__) +#define CRT_HAS___FLOAT128_KEYWORD +#define CRT_HAS_F128 +typedef __float128 f128; +#endif + #if CRT_HAS_FLOATING_POINT typedef union { uqwords u; @@ -175,6 +185,20 @@ typedef float _Complex Fcomplex; typedef double _Complex Dcomplex; typedef long double _Complex Lcomplex; +#if defined(CRT_LDBL_128BIT) +typedef Lcomplex Qcomplex; +#define CRT_HAS_NATIVE_COMPLEX_F128 +#elif defined(CRT_HAS___FLOAT128_KEYWORD) +#if defined(__clang_major__) && __clang_major__ > 10 +// Clang prior to 11 did not support __float128 _Complex. +typedef __float128 _Complex Qcomplex; +#define CRT_HAS_NATIVE_COMPLEX_F128 +#elif defined(__GNUC__) && __GNUC__ >= 7 +// GCC does not allow __float128 _Complex, but accepts _Float128 _Complex. +typedef _Float128 _Complex Qcomplex; +#define CRT_HAS_NATIVE_COMPLEX_F128 +#endif +#endif #define COMPLEX_REAL(x) __real__(x) #define COMPLEX_IMAGINARY(x) __imag__(x) @@ -194,5 +218,17 @@ #define COMPLEX_REAL(x) (x).real #define COMPLEX_IMAGINARY(x) (x).imaginary #endif + +#ifdef CRT_HAS_NATIVE_COMPLEX_F128 +#define COMPLEX128_REAL(x) __real__(x) +#define COMPLEX128_IMAGINARY(x) __imag__(x) +#elif defined(CRT_HAS_F128) +typedef struct { + f128 real, imaginary; +} Qcomplex; +#define COMPLEX128_REAL(x) (x).real +#define COMPLEX128_IMAGINARY(x) (x).imaginary +#endif + #endif #endif // INT_TYPES_H diff --git a/compiler-rt/lib/builtins/multc3.c b/compiler-rt/lib/builtins/multc3.c --- a/compiler-rt/lib/builtins/multc3.c +++ b/compiler-rt/lib/builtins/multc3.c @@ -10,56 +10,61 @@ // //===----------------------------------------------------------------------===// +#define QUAD_PRECISION #include "int_lib.h" #include "int_math.h" +#include "fp_lib.h" + +#if defined(CRT_HAS_F128) // Returns: the product of a + ib and c + id -COMPILER_RT_ABI long double _Complex __multc3(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; - long double _Complex z; - __real__ z = ac - bd; - __imag__ z = ad + bc; - if (crt_isnan(__real__ z) && crt_isnan(__imag__ z)) { +COMPILER_RT_ABI Qcomplex __multc3(f128 a, f128 b, f128 c, f128 d) { + f128 ac = a * c; + f128 bd = b * d; + f128 ad = a * d; + f128 bc = b * c; + Qcomplex z; + COMPLEX128_REAL(z) = ac - bd; + COMPLEX128_IMAGINARY(z) = ad + bc; + if (crt_isnan(COMPLEX128_REAL(z)) && crt_isnan(COMPLEX128_IMAGINARY(z))) { int recalc = 0; if (crt_isinf(a) || crt_isinf(b)) { - a = crt_copysignl(crt_isinf(a) ? 1 : 0, a); - b = crt_copysignl(crt_isinf(b) ? 1 : 0, b); + a = crt_copysignf128(crt_isinf(a) ? 1 : 0, a); + b = crt_copysignf128(crt_isinf(b) ? 1 : 0, b); if (crt_isnan(c)) - c = crt_copysignl(0, c); + c = crt_copysignf128(0, c); if (crt_isnan(d)) - d = crt_copysignl(0, d); + d = crt_copysignf128(0, d); recalc = 1; } if (crt_isinf(c) || crt_isinf(d)) { - c = crt_copysignl(crt_isinf(c) ? 1 : 0, c); - d = crt_copysignl(crt_isinf(d) ? 1 : 0, d); + c = crt_copysignf128(crt_isinf(c) ? 1 : 0, c); + d = crt_copysignf128(crt_isinf(d) ? 1 : 0, d); if (crt_isnan(a)) - a = crt_copysignl(0, a); + a = crt_copysignf128(0, a); if (crt_isnan(b)) - b = crt_copysignl(0, b); + b = crt_copysignf128(0, b); recalc = 1; } if (!recalc && (crt_isinf(ac) || crt_isinf(bd) || crt_isinf(ad) || crt_isinf(bc))) { if (crt_isnan(a)) - a = crt_copysignl(0, a); + a = crt_copysignf128(0, a); if (crt_isnan(b)) - b = crt_copysignl(0, b); + b = crt_copysignf128(0, b); if (crt_isnan(c)) - c = crt_copysignl(0, c); + c = crt_copysignf128(0, c); if (crt_isnan(d)) - d = crt_copysignl(0, d); + d = crt_copysignf128(0, d); recalc = 1; } if (recalc) { - __real__ z = CRT_INFINITY * (a * c - b * d); - __imag__ z = CRT_INFINITY * (a * d + b * c); + COMPLEX128_REAL(z) = CRT_INFINITY * (a * c - b * d); + COMPLEX128_IMAGINARY(z) = CRT_INFINITY * (a * d + b * c); } } return z; } + +#endif diff --git a/compiler-rt/lib/builtins/multf3.c b/compiler-rt/lib/builtins/multf3.c --- a/compiler-rt/lib/builtins/multf3.c +++ b/compiler-rt/lib/builtins/multf3.c @@ -14,7 +14,7 @@ #define QUAD_PRECISION #include "fp_lib.h" -#if defined(CRT_HAS_128BIT) && defined(CRT_LDBL_128BIT) +#if defined(CRT_HAS_128BIT) && defined(CRT_HAS_F128) #include "fp_mul_impl.inc" COMPILER_RT_ABI fp_t __multf3(fp_t a, fp_t b) { return __mulXf3__(a, b); } diff --git a/compiler-rt/lib/builtins/powitf2.c b/compiler-rt/lib/builtins/powitf2.c --- a/compiler-rt/lib/builtins/powitf2.c +++ b/compiler-rt/lib/builtins/powitf2.c @@ -13,13 +13,13 @@ #define QUAD_PRECISION #include "fp_lib.h" -#if defined(CRT_HAS_128BIT) && defined(CRT_LDBL_128BIT) +#if defined(CRT_HAS_128BIT) && defined(CRT_HAS_F128) // Returns: a ^ b -COMPILER_RT_ABI long double __powitf2(long double a, int b) { +COMPILER_RT_ABI f128 __powitf2(f128 a, int b) { const int recip = b < 0; - long double r = 1; + f128 r = 1; while (1) { if (b & 1) r *= a; diff --git a/compiler-rt/lib/builtins/subtf3.c b/compiler-rt/lib/builtins/subtf3.c --- a/compiler-rt/lib/builtins/subtf3.c +++ b/compiler-rt/lib/builtins/subtf3.c @@ -13,7 +13,7 @@ #define QUAD_PRECISION #include "fp_lib.h" -#if defined(CRT_HAS_128BIT) && defined(CRT_LDBL_128BIT) +#if defined(CRT_HAS_128BIT) && defined(CRT_HAS_F128) COMPILER_RT_ABI fp_t __addtf3(fp_t a, fp_t b); // Subtraction; flip the sign bit of b and add. diff --git a/compiler-rt/lib/builtins/trunctfdf2.c b/compiler-rt/lib/builtins/trunctfdf2.c --- a/compiler-rt/lib/builtins/trunctfdf2.c +++ b/compiler-rt/lib/builtins/trunctfdf2.c @@ -9,11 +9,11 @@ #define QUAD_PRECISION #include "fp_lib.h" -#if defined(CRT_HAS_128BIT) && defined(CRT_LDBL_128BIT) +#if defined(CRT_HAS_128BIT) && defined(CRT_HAS_F128) #define SRC_QUAD #define DST_DOUBLE #include "fp_trunc_impl.inc" -COMPILER_RT_ABI double __trunctfdf2(long double a) { return __truncXfYf2__(a); } +COMPILER_RT_ABI double __trunctfdf2(f128 a) { return __truncXfYf2__(a); } #endif diff --git a/compiler-rt/lib/builtins/trunctfhf2.c b/compiler-rt/lib/builtins/trunctfhf2.c --- a/compiler-rt/lib/builtins/trunctfhf2.c +++ b/compiler-rt/lib/builtins/trunctfhf2.c @@ -10,13 +10,12 @@ #define QUAD_PRECISION #include "fp_lib.h" -#if defined(CRT_HAS_128BIT) && defined(CRT_LDBL_128BIT) && \ - defined(COMPILER_RT_HAS_FLOAT16) +#if defined(CRT_HAS_128BIT) && defined(CRT_HAS_F128) #define SRC_QUAD #define DST_HALF #include "fp_trunc_impl.inc" -COMPILER_RT_ABI _Float16 __trunctfhf2(long double a) { +COMPILER_RT_ABI dst_t __trunctfhf2(f128 a) { return __truncXfYf2__(a); } diff --git a/compiler-rt/lib/builtins/trunctfsf2.c b/compiler-rt/lib/builtins/trunctfsf2.c --- a/compiler-rt/lib/builtins/trunctfsf2.c +++ b/compiler-rt/lib/builtins/trunctfsf2.c @@ -9,11 +9,11 @@ #define QUAD_PRECISION #include "fp_lib.h" -#if defined(CRT_HAS_128BIT) && defined(CRT_LDBL_128BIT) +#if defined(CRT_HAS_128BIT) && defined(CRT_HAS_F128) #define SRC_QUAD #define DST_SINGLE #include "fp_trunc_impl.inc" -COMPILER_RT_ABI float __trunctfsf2(long double a) { return __truncXfYf2__(a); } +COMPILER_RT_ABI float __trunctfsf2(f128 a) { return __truncXfYf2__(a); } #endif diff --git a/compiler-rt/test/builtins/Unit/addtf3_test.c b/compiler-rt/test/builtins/Unit/addtf3_test.c --- a/compiler-rt/test/builtins/Unit/addtf3_test.c +++ b/compiler-rt/test/builtins/Unit/addtf3_test.c @@ -1,104 +1,100 @@ -// RUN: %clang_builtins %s %librt -o %t && %run %t +// RUN: %clang_builtins %s %librt -Wall -Wextra -Werror=format -o %t && %run %t // REQUIRES: librt_has_addtf3 #include #include -#if __LDBL_MANT_DIG__ == 113 - #include "int_lib.h" #include "fp_test.h" -// Returns: a + b -COMPILER_RT_ABI long double __addtf3(long double a, long double b); - -int test__addtf3(long double a, long double b, - uint64_t expectedHi, uint64_t expectedLo) -{ - long double x = __addtf3(a, b); - int ret = compareResultLD(x, expectedHi, expectedLo); - - if (ret){ - printf("error in test__addtf3(%.20Lf, %.20Lf) = %.20Lf, " - "expected %.20Lf\n", a, b, x, - fromRep128(expectedHi, expectedLo)); - } - - return ret; +#if !defined(CRT_HAS_F128) +int main() { + fprintf(stderr, "Missing f128 support - skipping.\n"); + return 1; } +#else -char assumption_1[sizeof(long double) * CHAR_BIT == 128] = {0}; - -#endif - -int main() -{ -#if __LDBL_MANT_DIG__ == 113 - // qNaN + any = qNaN - if (test__addtf3(makeQNaN128(), - 0x1.23456789abcdefp+5L, - UINT64_C(0x7fff800000000000), - UINT64_C(0x0))) - return 1; - // NaN + any = NaN - if (test__addtf3(makeNaN128(UINT64_C(0x800030000000)), - 0x1.23456789abcdefp+5L, - UINT64_C(0x7fff800000000000), - UINT64_C(0x0))) - return 1; - // inf + inf = inf - if (test__addtf3(makeInf128(), - makeInf128(), - UINT64_C(0x7fff000000000000), - UINT64_C(0x0))) - return 1; - // inf + any = inf - if (test__addtf3(makeInf128(), - 0x1.2335653452436234723489432abcdefp+5L, - UINT64_C(0x7fff000000000000), - UINT64_C(0x0))) - return 1; - // any + any - if (test__addtf3(0x1.23456734245345543849abcdefp+5L, - 0x1.edcba52449872455634654321fp-1L, - UINT64_C(0x40042afc95c8b579), - UINT64_C(0x61e58dd6c51eb77c))) - return 1; +// Returns: a + b +COMPILER_RT_ABI f128 __addtf3(f128 a, f128 b); + +int _test__addtf3(int line, f128 a, f128 b, + uint64_t expectedHi, uint64_t expectedLo) { + f128 x = __addtf3(a, b); + int ret = compareResultF128(x, expectedHi, expectedLo); + if (ret) { + printMismatchF128TwoArg(__FILE__, line, "__addtf3", a, b, x, + expectedHi, expectedLo); + } + return ret; +} +#define test__addtf3(...) _test__addtf3(__LINE__, __VA_ARGS__) + +int main() { + // qNaN + any = qNaN + if (test__addtf3(makeQNaN128(), + 0x1.23456789abcdefp+5Q, + UINT64_C(0x7fff800000000000), + UINT64_C(0x0))) + return 1; + // NaN + any = NaN + if (test__addtf3(makeNaN128(UINT64_C(0x800030000000)), + 0x1.23456789abcdefp+5Q, + UINT64_C(0x7fff800000000000), + UINT64_C(0x0))) + return 1; + // inf + inf = inf + if (test__addtf3(makeInf128(), + makeInf128(), + UINT64_C(0x7fff000000000000), + UINT64_C(0x0))) + return 1; + // inf + any = inf + if (test__addtf3(makeInf128(), + 0x1.2335653452436234723489432abcdefp+5Q, + UINT64_C(0x7fff000000000000), + UINT64_C(0x0))) + return 1; + // any + any + + if (test__addtf3(/* 0x1.23456734245345543849abcdefp+5Q */ + fromRep128(UINT64_C(0x4004234567342453), UINT64_C(0x45543849abcdef00)), + /* 0x1.edcba52449872455634654321fp-1Q */ + fromRep128(UINT64_C(0x3ffeedcba5244987), UINT64_C(0x2455634654321f00)), + UINT64_C(0x40042afc95c8b579), + UINT64_C(0x61e58dd6c51eb77c))) + return 1; #if (defined(__arm__) || defined(__aarch64__)) && defined(__ARM_FP) || \ defined(i386) || defined(__x86_64__) - // Rounding mode tests on supported architectures - const long double m = 1234.0L, n = 0.01L; - - fesetround(FE_UPWARD); - if (test__addtf3(m, n, - UINT64_C(0x40093480a3d70a3d), - UINT64_C(0x70a3d70a3d70a3d8))) - return 1; - - fesetround(FE_DOWNWARD); - if (test__addtf3(m, n, - UINT64_C(0x40093480a3d70a3d), - UINT64_C(0x70a3d70a3d70a3d7))) - return 1; - - - fesetround(FE_TOWARDZERO); - if (test__addtf3(m, n, - UINT64_C(0x40093480a3d70a3d), - UINT64_C(0x70a3d70a3d70a3d7))) - return 1; - - fesetround(FE_TONEAREST); - if (test__addtf3(m, n, - UINT64_C(0x40093480a3d70a3d), - UINT64_C(0x70a3d70a3d70a3d7))) - return 1; + // Rounding mode tests on supported architectures + const f128 m = assertF128Representation(1234.0Q, UINT64_C(0x4009348000000000), UINT64_C(0x0000000000000000)); + // Closest approximation of 0.1 for f128: + const f128 n = assertF128Representation(0.1Q, UINT64_C(0x3ffb999999999999), UINT64_C(0x999999999999999a)); + fesetround(FE_UPWARD); + if (test__addtf3(m, n, + UINT64_C(0x4009348666666666), + UINT64_C(0x6666666666666667))) + return 1; + + fesetround(FE_DOWNWARD); + if (test__addtf3(m, n, + UINT64_C(0x4009348666666666), + UINT64_C(0x6666666666666666))) + return 1; + + fesetround(FE_TOWARDZERO); + if (test__addtf3(m, n, + UINT64_C(0x4009348666666666), + UINT64_C(0x6666666666666666))) + return 1; + + fesetround(FE_TONEAREST); + if (test__addtf3(m, n, + UINT64_C(0x4009348666666666), + UINT64_C(0x6666666666666666))) + return 1; #endif - -#else - printf("skipped\n"); + return 0; +} #endif - return 0; -} diff --git a/compiler-rt/test/builtins/Unit/divtc3_test.c b/compiler-rt/test/builtins/Unit/divtc3_test.c --- a/compiler-rt/test/builtins/Unit/divtc3_test.c +++ b/compiler-rt/test/builtins/Unit/divtc3_test.c @@ -9,362 +9,372 @@ #include #include "int_lib.h" -#include +#include "int_math.h" +#include "fp_test.h" #include +#include +#if !defined(CRT_HAS_F128) +int main() { + fprintf(stderr, "Missing f128 support - skipping.\n"); + return 1; +} +#else -// Returns: the quotient of (a + ib) / (c + id) +COMPILER_RT_ABI Qcomplex __divtc3(f128 __a, f128 __b, f128 __c, f128 __d); -COMPILER_RT_ABI long double _Complex -__divtc3(long double __a, long double __b, long double __c, long double __d); +enum { zero, + non_zero, + inf, + NaN, + non_zero_nan }; -enum {zero, non_zero, inf, NaN, non_zero_nan}; +static int classify(Qcomplex x) { + f128 real = COMPLEX128_REAL(x); + f128 imag = COMPLEX128_IMAGINARY(x); + if (real == 0.0 && imag == 0.0) + return zero; + if (crt_isinf(real) || crt_isinf(imag)) + return inf; + if (crt_isnan(real) && crt_isnan(imag)) + return NaN; + if (crt_isnan(real)) { + if (imag == 0.0) + return NaN; + return non_zero_nan; + } + if (crt_isnan(imag)) { + if (real == 0.0) + return NaN; + return non_zero_nan; + } + return non_zero; +} -int -classify(long double _Complex x) -{ - if (x == 0) - return zero; - if (isinf(creall(x)) || isinf(cimagl(x))) - return inf; - if (isnan(creall(x)) && isnan(cimagl(x))) - return NaN; - if (isnan(creall(x))) - { - if (cimagl(x) == 0) - return NaN; - return non_zero_nan; +static int test__divtc3(f128 a, f128 b, f128 c, f128 d) { + Qcomplex r = __divtc3(a, b, c, d); + // printf("test__divtc3(%Lf, %Lf, %Lf, %Lf) = %Lf + I%Lf\n", + // a, b, c, d, COMPLEX128_REAL(r), COMPLEX128_IMAGINARY(r)); + + Qcomplex dividend; + Qcomplex divisor; + + COMPLEX128_REAL(dividend) = a; + COMPLEX128_IMAGINARY(dividend) = b; + COMPLEX128_REAL(divisor) = c; + COMPLEX128_IMAGINARY(divisor) = d; + + switch (classify(dividend)) { + case zero: + switch (classify(divisor)) { + case zero: + if (classify(r) != NaN) + return 1; + break; + case non_zero: + if (classify(r) != zero) + return 1; + break; + case inf: + if (classify(r) != zero) + return 1; + break; + case NaN: + if (classify(r) != NaN) + return 1; + break; + case non_zero_nan: + if (classify(r) != NaN) + return 1; + break; } - if (isnan(cimagl(x))) - { - if (creall(x) == 0) - return NaN; - return non_zero_nan; + break; + case non_zero: + switch (classify(divisor)) { + case zero: + if (classify(r) != inf) + return 1; + break; + case non_zero: + if (classify(r) != non_zero) + return 1; + { + f128 zReal = (a * c + b * d) / (c * c + d * d); + f128 zImag = (b * c - a * d) / (c * c + d * d); + Qcomplex diff = __divtc3(COMPLEX128_REAL(r) - zReal, COMPLEX128_IMAGINARY(r) - zImag, + COMPLEX128_REAL(r), COMPLEX128_IMAGINARY(r)); + // cabsl(z) == hypotl(creall(z), cimagl(z)) +#ifdef CRT_LDBL_128BIT + if (hypotl(COMPLEX128_REAL(diff), COMPLEX128_IMAGINARY(diff)) > 1.e-6) +#else + // Avoid dependency on __trunctfxf2 for ld80 platforms and use double instead. + if (hypot(COMPLEX128_REAL(diff), COMPLEX128_IMAGINARY(diff)) > 1.e-6) +#endif + return 1; + } + break; + case inf: + if (classify(r) != zero) + return 1; + break; + case NaN: + if (classify(r) != NaN) + return 1; + break; + case non_zero_nan: + if (classify(r) != NaN) + return 1; + break; } - return non_zero; -} - -int test__divtc3(long double a, long double b, long double c, long double d) -{ - long double _Complex r = __divtc3(a, b, c, d); -// printf("test__divtc3(%Lf, %Lf, %Lf, %Lf) = %Lf + I%Lf\n", -// a, b, c, d, creall(r), cimagl(r)); - - long double _Complex dividend; - long double _Complex divisor; - - __real__ dividend = a; - __imag__ dividend = b; - __real__ divisor = c; - __imag__ divisor = d; - - switch (classify(dividend)) - { + break; + case inf: + switch (classify(divisor)) { + case zero: + if (classify(r) != inf) + return 1; + break; + case non_zero: + if (classify(r) != inf) + return 1; + break; + case inf: + if (classify(r) != NaN) + return 1; + break; + case NaN: + if (classify(r) != NaN) + return 1; + break; + case non_zero_nan: + if (classify(r) != NaN) + return 1; + break; + } + break; + case NaN: + switch (classify(divisor)) { case zero: - switch (classify(divisor)) - { - case zero: - if (classify(r) != NaN) - return 1; - break; - case non_zero: - if (classify(r) != zero) - return 1; - break; - case inf: - if (classify(r) != zero) - return 1; - break; - case NaN: - if (classify(r) != NaN) - return 1; - break; - case non_zero_nan: - if (classify(r) != NaN) - return 1; - break; - } - break; + if (classify(r) != NaN) + return 1; + break; case non_zero: - switch (classify(divisor)) - { - case zero: - if (classify(r) != inf) - return 1; - break; - case non_zero: - if (classify(r) != non_zero) - return 1; - { - long double _Complex z = (a * c + b * d) / (c * c + d * d) - + (b * c - a * d) / (c * c + d * d) * _Complex_I; - if (cabsl((r - z)/r) > 1.e-6) - return 1; - } - break; - case inf: - if (classify(r) != zero) - return 1; - break; - case NaN: - if (classify(r) != NaN) - return 1; - break; - case non_zero_nan: - if (classify(r) != NaN) - return 1; - break; - } - break; + if (classify(r) != NaN) + return 1; + break; case inf: - switch (classify(divisor)) - { - case zero: - if (classify(r) != inf) - return 1; - break; - case non_zero: - if (classify(r) != inf) - return 1; - break; - case inf: - if (classify(r) != NaN) - return 1; - break; - case NaN: - if (classify(r) != NaN) - return 1; - break; - case non_zero_nan: - if (classify(r) != NaN) - return 1; - break; - } - break; + if (classify(r) != NaN) + return 1; + break; case NaN: - switch (classify(divisor)) - { - case zero: - if (classify(r) != NaN) - return 1; - break; - case non_zero: - if (classify(r) != NaN) - return 1; - break; - case inf: - if (classify(r) != NaN) - return 1; - break; - case NaN: - if (classify(r) != NaN) - return 1; - break; - case non_zero_nan: - if (classify(r) != NaN) - return 1; - break; - } - break; + if (classify(r) != NaN) + return 1; + break; case non_zero_nan: - switch (classify(divisor)) - { - case zero: - if (classify(r) != inf) - return 1; - break; - case non_zero: - if (classify(r) != NaN) - return 1; - break; - case inf: - if (classify(r) != NaN) - return 1; - break; - case NaN: - if (classify(r) != NaN) - return 1; - break; - case non_zero_nan: - if (classify(r) != NaN) - return 1; - break; - } - break; + if (classify(r) != NaN) + return 1; + break; } - - return 0; + break; + case non_zero_nan: + switch (classify(divisor)) { + case zero: + if (classify(r) != inf) + return 1; + break; + case non_zero: + if (classify(r) != NaN) + return 1; + break; + case inf: + if (classify(r) != NaN) + return 1; + break; + case NaN: + if (classify(r) != NaN) + return 1; + break; + case non_zero_nan: + if (classify(r) != NaN) + return 1; + break; + } + break; + } + + return 0; } -long double x[][2] = -{ - { 1.e-6, 1.e-6}, - {-1.e-6, 1.e-6}, - {-1.e-6, -1.e-6}, - { 1.e-6, -1.e-6}, +static f128 x[][2] = + { + {1.e-6, 1.e-6}, + {-1.e-6, 1.e-6}, + {-1.e-6, -1.e-6}, + {1.e-6, -1.e-6}, - { 1.e+6, 1.e-6}, - {-1.e+6, 1.e-6}, - {-1.e+6, -1.e-6}, - { 1.e+6, -1.e-6}, + {1.e+6, 1.e-6}, + {-1.e+6, 1.e-6}, + {-1.e+6, -1.e-6}, + {1.e+6, -1.e-6}, - { 1.e-6, 1.e+6}, - {-1.e-6, 1.e+6}, - {-1.e-6, -1.e+6}, - { 1.e-6, -1.e+6}, + {1.e-6, 1.e+6}, + {-1.e-6, 1.e+6}, + {-1.e-6, -1.e+6}, + {1.e-6, -1.e+6}, - { 1.e+6, 1.e+6}, - {-1.e+6, 1.e+6}, - {-1.e+6, -1.e+6}, - { 1.e+6, -1.e+6}, + {1.e+6, 1.e+6}, + {-1.e+6, 1.e+6}, + {-1.e+6, -1.e+6}, + {1.e+6, -1.e+6}, - {NAN, NAN}, - {-INFINITY, NAN}, - {-2, NAN}, - {-1, NAN}, - {-0.5, NAN}, - {-0., NAN}, - {+0., NAN}, - {0.5, NAN}, - {1, NAN}, - {2, NAN}, - {INFINITY, NAN}, + {NAN, NAN}, + {-INFINITY, NAN}, + {-2, NAN}, + {-1, NAN}, + {-0.5, NAN}, + {-0., NAN}, + {+0., NAN}, + {0.5, NAN}, + {1, NAN}, + {2, NAN}, + {INFINITY, NAN}, - {NAN, -INFINITY}, - {-INFINITY, -INFINITY}, - {-2, -INFINITY}, - {-1, -INFINITY}, - {-0.5, -INFINITY}, - {-0., -INFINITY}, - {+0., -INFINITY}, - {0.5, -INFINITY}, - {1, -INFINITY}, - {2, -INFINITY}, - {INFINITY, -INFINITY}, + {NAN, -INFINITY}, + {-INFINITY, -INFINITY}, + {-2, -INFINITY}, + {-1, -INFINITY}, + {-0.5, -INFINITY}, + {-0., -INFINITY}, + {+0., -INFINITY}, + {0.5, -INFINITY}, + {1, -INFINITY}, + {2, -INFINITY}, + {INFINITY, -INFINITY}, - {NAN, -2}, - {-INFINITY, -2}, - {-2, -2}, - {-1, -2}, - {-0.5, -2}, - {-0., -2}, - {+0., -2}, - {0.5, -2}, - {1, -2}, - {2, -2}, - {INFINITY, -2}, + {NAN, -2}, + {-INFINITY, -2}, + {-2, -2}, + {-1, -2}, + {-0.5, -2}, + {-0., -2}, + {+0., -2}, + {0.5, -2}, + {1, -2}, + {2, -2}, + {INFINITY, -2}, - {NAN, -1}, - {-INFINITY, -1}, - {-2, -1}, - {-1, -1}, - {-0.5, -1}, - {-0., -1}, - {+0., -1}, - {0.5, -1}, - {1, -1}, - {2, -1}, - {INFINITY, -1}, + {NAN, -1}, + {-INFINITY, -1}, + {-2, -1}, + {-1, -1}, + {-0.5, -1}, + {-0., -1}, + {+0., -1}, + {0.5, -1}, + {1, -1}, + {2, -1}, + {INFINITY, -1}, - {NAN, -0.5}, - {-INFINITY, -0.5}, - {-2, -0.5}, - {-1, -0.5}, - {-0.5, -0.5}, - {-0., -0.5}, - {+0., -0.5}, - {0.5, -0.5}, - {1, -0.5}, - {2, -0.5}, - {INFINITY, -0.5}, + {NAN, -0.5}, + {-INFINITY, -0.5}, + {-2, -0.5}, + {-1, -0.5}, + {-0.5, -0.5}, + {-0., -0.5}, + {+0., -0.5}, + {0.5, -0.5}, + {1, -0.5}, + {2, -0.5}, + {INFINITY, -0.5}, - {NAN, -0.}, - {-INFINITY, -0.}, - {-2, -0.}, - {-1, -0.}, - {-0.5, -0.}, - {-0., -0.}, - {+0., -0.}, - {0.5, -0.}, - {1, -0.}, - {2, -0.}, - {INFINITY, -0.}, + {NAN, -0.}, + {-INFINITY, -0.}, + {-2, -0.}, + {-1, -0.}, + {-0.5, -0.}, + {-0., -0.}, + {+0., -0.}, + {0.5, -0.}, + {1, -0.}, + {2, -0.}, + {INFINITY, -0.}, - {NAN, 0.}, - {-INFINITY, 0.}, - {-2, 0.}, - {-1, 0.}, - {-0.5, 0.}, - {-0., 0.}, - {+0., 0.}, - {0.5, 0.}, - {1, 0.}, - {2, 0.}, - {INFINITY, 0.}, + {NAN, 0.}, + {-INFINITY, 0.}, + {-2, 0.}, + {-1, 0.}, + {-0.5, 0.}, + {-0., 0.}, + {+0., 0.}, + {0.5, 0.}, + {1, 0.}, + {2, 0.}, + {INFINITY, 0.}, - {NAN, 0.5}, - {-INFINITY, 0.5}, - {-2, 0.5}, - {-1, 0.5}, - {-0.5, 0.5}, - {-0., 0.5}, - {+0., 0.5}, - {0.5, 0.5}, - {1, 0.5}, - {2, 0.5}, - {INFINITY, 0.5}, + {NAN, 0.5}, + {-INFINITY, 0.5}, + {-2, 0.5}, + {-1, 0.5}, + {-0.5, 0.5}, + {-0., 0.5}, + {+0., 0.5}, + {0.5, 0.5}, + {1, 0.5}, + {2, 0.5}, + {INFINITY, 0.5}, - {NAN, 1}, - {-INFINITY, 1}, - {-2, 1}, - {-1, 1}, - {-0.5, 1}, - {-0., 1}, - {+0., 1}, - {0.5, 1}, - {1, 1}, - {2, 1}, - {INFINITY, 1}, + {NAN, 1}, + {-INFINITY, 1}, + {-2, 1}, + {-1, 1}, + {-0.5, 1}, + {-0., 1}, + {+0., 1}, + {0.5, 1}, + {1, 1}, + {2, 1}, + {INFINITY, 1}, - {NAN, 2}, - {-INFINITY, 2}, - {-2, 2}, - {-1, 2}, - {-0.5, 2}, - {-0., 2}, - {+0., 2}, - {0.5, 2}, - {1, 2}, - {2, 2}, - {INFINITY, 2}, + {NAN, 2}, + {-INFINITY, 2}, + {-2, 2}, + {-1, 2}, + {-0.5, 2}, + {-0., 2}, + {+0., 2}, + {0.5, 2}, + {1, 2}, + {2, 2}, + {INFINITY, 2}, - {NAN, INFINITY}, - {-INFINITY, INFINITY}, - {-2, INFINITY}, - {-1, INFINITY}, - {-0.5, INFINITY}, - {-0., INFINITY}, - {+0., INFINITY}, - {0.5, INFINITY}, - {1, INFINITY}, - {2, INFINITY}, - {INFINITY, INFINITY} + {NAN, INFINITY}, + {-INFINITY, INFINITY}, + {-2, INFINITY}, + {-1, INFINITY}, + {-0.5, INFINITY}, + {-0., INFINITY}, + {+0., INFINITY}, + {0.5, INFINITY}, + {1, INFINITY}, + {2, INFINITY}, + {INFINITY, INFINITY} }; -int main() -{ - const unsigned N = sizeof(x) / sizeof(x[0]); - unsigned i, j; - for (i = 0; i < N; ++i) - { - for (j = 0; j < N; ++j) - { - if (test__divtc3(x[i][0], x[i][1], x[j][0], x[j][1])) - return 1; - } +int main() { + const unsigned N = sizeof(x) / sizeof(x[0]); + unsigned i, j; + for (i = 0; i < N; ++i) { + for (j = 0; j < N; ++j) { + if (test__divtc3(x[i][0], x[i][1], x[j][0], x[j][1])) { + fprintf(stderr, "Failed for %g, %g, %g, %g\n", + (double)x[i][0], (double)x[i][1], + (double)x[j][0], (double)x[j][1]); + return 1; + } } + } -// printf("No errors found.\n"); - return 0; + fprintf(stderr, "No errors found.\n"); + return 0; } +#endif diff --git a/compiler-rt/test/builtins/Unit/divtf3_test.c b/compiler-rt/test/builtins/Unit/divtf3_test.c --- a/compiler-rt/test/builtins/Unit/divtf3_test.c +++ b/compiler-rt/test/builtins/Unit/divtf3_test.c @@ -4,190 +4,184 @@ #include "int_lib.h" #include -#if __LDBL_MANT_DIG__ == 113 - #include "fp_test.h" +#if !defined(CRT_HAS_F128) +int main() { + fprintf(stderr, "Missing f128 support - skipping.\n"); + return 1; +} +#else // Returns: a / b -COMPILER_RT_ABI long double __divtf3(long double a, long double b); - -int test__divtf3(long double a, long double b, - uint64_t expectedHi, uint64_t expectedLo) -{ - long double x = __divtf3(a, b); - int ret = compareResultLD(x, expectedHi, expectedLo); - - if (ret){ - printf("error in test__divtf3(%.20Le, %.20Le) = %.20Le, " - "expected %.20Le\n", a, b, x, - fromRep128(expectedHi, expectedLo)); - } - return ret; +COMPILER_RT_ABI f128 __divtf3(f128 a, f128 b); + +int _test__divtf3(int line, f128 a, f128 b, + uint64_t expectedHi, uint64_t expectedLo) { + f128 x = __divtf3(a, b); + int ret = compareResultF128(x, expectedHi, expectedLo); + if (ret) { + printMismatchF128TwoArg(__FILE__, line, "__divtf3", a, b, x, + expectedHi, expectedLo); + } + return ret; +} +#define test__divtf3(...) _test__divtf3(__LINE__, __VA_ARGS__) + +int main() { + // Returned NaNs are assumed to be qNaN by default + + // qNaN / any = qNaN + if (test__divtf3(makeQNaN128(), + 0x1.23456789abcdefp+5Q, + UINT64_C(0x7fff800000000000), + UINT64_C(0x0))) + return 1; + // NaN / any = NaN + if (test__divtf3(makeNaN128(UINT64_C(0x30000000)), + 0x1.23456789abcdefp+5Q, + UINT64_C(0x7fff800000000000), + UINT64_C(0x0))) + return 1; + // any / qNaN = qNaN + if (test__divtf3(0x1.23456789abcdefp+5Q, + makeQNaN128(), + UINT64_C(0x7fff800000000000), + UINT64_C(0x0))) + return 1; + // any / NaN = NaN + if (test__divtf3(0x1.23456789abcdefp+5Q, + makeNaN128(UINT64_C(0x30000000)), + UINT64_C(0x7fff800000000000), + UINT64_C(0x0))) + return 1; + + // +Inf / positive = +Inf + if (test__divtf3(makeInf128(), 3.Q, + UINT64_C(0x7fff000000000000), + UINT64_C(0x0))) + return 1; + // +Inf / negative = -Inf + if (test__divtf3(makeInf128(), -3.Q, + UINT64_C(0xffff000000000000), + UINT64_C(0x0))) + return 1; + // -Inf / positive = -Inf + if (test__divtf3(makeNegativeInf128(), 3.Q, + UINT64_C(0xffff000000000000), + UINT64_C(0x0))) + return 1; + // -Inf / negative = +Inf + if (test__divtf3(makeNegativeInf128(), -3.Q, + UINT64_C(0x7fff000000000000), + UINT64_C(0x0))) + return 1; + + // Inf / Inf = NaN + if (test__divtf3(makeInf128(), makeInf128(), + UINT64_C(0x7fff800000000000), + UINT64_C(0x0))) + return 1; + // 0.0 / 0.0 = NaN + if (test__divtf3(+0x0.0p+0Q, +0x0.0p+0Q, + UINT64_C(0x7fff800000000000), + UINT64_C(0x0))) + return 1; + // +0.0 / +Inf = +0.0 + if (test__divtf3(+0x0.0p+0Q, makeInf128(), + UINT64_C(0x0), + UINT64_C(0x0))) + return 1; + // +Inf / +0.0 = +Inf + if (test__divtf3(makeInf128(), +0x0.0p+0Q, + UINT64_C(0x7fff000000000000), + UINT64_C(0x0))) + return 1; + + // positive / +0.0 = +Inf + if (test__divtf3(+1.0Q, +0x0.0p+0Q, + UINT64_C(0x7fff000000000000), + UINT64_C(0x0))) + return 1; + // positive / -0.0 = -Inf + if (test__divtf3(+1.0Q, -0x0.0p+0Q, + UINT64_C(0xffff000000000000), + UINT64_C(0x0))) + return 1; + // negative / +0.0 = -Inf + if (test__divtf3(-1.0Q, +0x0.0p+0Q, + UINT64_C(0xffff000000000000), + UINT64_C(0x0))) + return 1; + // negative / -0.0 = +Inf + if (test__divtf3(-1.0Q, -0x0.0p+0Q, + UINT64_C(0x7fff000000000000), + UINT64_C(0x0))) + return 1; + + // 1/3 + if (test__divtf3(1.Q, 3.Q, + UINT64_C(0x3ffd555555555555), + UINT64_C(0x5555555555555555))) + return 1; + // smallest normal result + if (test__divtf3(0x1.0p-16381Q, 2.Q, + UINT64_C(0x0001000000000000), + UINT64_C(0x0))) + return 1; + + // divisor is exactly 1.0 + if (test__divtf3(0x1.0p+0Q, + 0x1.0p+0Q, + UINT64_C(0x3fff000000000000), + UINT64_C(0x0))) + return 1; + // divisor is truncated to exactly 1.0 in UQ1.63 + if (test__divtf3(0x1.0p+0Q, + 0x1.0000000000000001p+0Q, + UINT64_C(0x3ffeffffffffffff), + UINT64_C(0xfffe000000000000))) + return 1; + + // smallest normal value divided by 2.0 + if (test__divtf3(0x1.0p-16382Q, 2.Q, UINT64_C(0x0000800000000000), UINT64_C(0x0))) + return 1; + // smallest subnormal result + if (test__divtf3(0x1.0p-16382Q, 0x1p+112Q, UINT64_C(0x0), UINT64_C(0x1))) + return 1; + + // any / any + if (test__divtf3(0x1.a23b45362464523375893ab4cdefp+5Q, + 0x1.eedcbaba3a94546558237654321fp-1Q, + UINT64_C(0x4004b0b72924d407), + UINT64_C(0x0717e84356c6eba2))) + return 1; + if (test__divtf3(0x1.a2b34c56d745382f9abf2c3dfeffp-50Q, + 0x1.ed2c3ba15935332532287654321fp-9Q, + UINT64_C(0x3fd5b2af3f828c9b), + UINT64_C(0x40e51f64cde8b1f2))) + return 15; + if (test__divtf3(0x1.2345f6aaaa786555f42432abcdefp+456Q, + 0x1.edacbba9874f765463544dd3621fp+6400Q, + UINT64_C(0x28c62e15dc464466), + UINT64_C(0xb5a07586348557ac))) + return 1; + if (test__divtf3(0x1.2d3456f789ba6322bc665544edefp-234Q, + 0x1.eddcdba39f3c8b7a36564354321fp-4455Q, + UINT64_C(0x507b38442b539266), + UINT64_C(0x22ce0f1d024e1252))) + return 1; + if (test__divtf3(0x1.2345f6b77b7a8953365433abcdefp+234Q, + 0x1.edcba987d6bb3aa467754354321fp-4055Q, + UINT64_C(0x50bf2e02f0798d36), + UINT64_C(0x5e6fcb6b60044078))) + return 1; + if (test__divtf3(6.72420628622418701252535563464350521E-4932Q, + 2.Q, + UINT64_C(0x0001000000000000), + UINT64_C(0))) + return 1; + + return 0; } - -char assumption_1[sizeof(long double) * CHAR_BIT == 128] = {0}; - -#endif - -int main() -{ -#if __LDBL_MANT_DIG__ == 113 - // Returned NaNs are assumed to be qNaN by default - - // qNaN / any = qNaN - if (test__divtf3(makeQNaN128(), - 0x1.23456789abcdefp+5L, - UINT64_C(0x7fff800000000000), - UINT64_C(0x0))) - return 1; - // NaN / any = NaN - if (test__divtf3(makeNaN128(UINT64_C(0x30000000)), - 0x1.23456789abcdefp+5L, - UINT64_C(0x7fff800000000000), - UINT64_C(0x0))) - return 1; - // any / qNaN = qNaN - if (test__divtf3(0x1.23456789abcdefp+5L, - makeQNaN128(), - UINT64_C(0x7fff800000000000), - UINT64_C(0x0))) - return 1; - // any / NaN = NaN - if (test__divtf3(0x1.23456789abcdefp+5L, - makeNaN128(UINT64_C(0x30000000)), - UINT64_C(0x7fff800000000000), - UINT64_C(0x0))) - return 1; - - // +Inf / positive = +Inf - if (test__divtf3(makeInf128(), 3.L, - UINT64_C(0x7fff000000000000), - UINT64_C(0x0))) - return 1; - // +Inf / negative = -Inf - if (test__divtf3(makeInf128(), -3.L, - UINT64_C(0xffff000000000000), - UINT64_C(0x0))) - return 1; - // -Inf / positive = -Inf - if (test__divtf3(makeNegativeInf128(), 3.L, - UINT64_C(0xffff000000000000), - UINT64_C(0x0))) - return 1; - // -Inf / negative = +Inf - if (test__divtf3(makeNegativeInf128(), -3.L, - UINT64_C(0x7fff000000000000), - UINT64_C(0x0))) - return 1; - - // Inf / Inf = NaN - if (test__divtf3(makeInf128(), makeInf128(), - UINT64_C(0x7fff800000000000), - UINT64_C(0x0))) - return 1; - // 0.0 / 0.0 = NaN - if (test__divtf3(+0x0.0p+0L, +0x0.0p+0L, - UINT64_C(0x7fff800000000000), - UINT64_C(0x0))) - return 1; - // +0.0 / +Inf = +0.0 - if (test__divtf3(+0x0.0p+0L, makeInf128(), - UINT64_C(0x0), - UINT64_C(0x0))) - return 1; - // +Inf / +0.0 = +Inf - if (test__divtf3(makeInf128(), +0x0.0p+0L, - UINT64_C(0x7fff000000000000), - UINT64_C(0x0))) - return 1; - - // positive / +0.0 = +Inf - if (test__divtf3(+1.0L, +0x0.0p+0L, - UINT64_C(0x7fff000000000000), - UINT64_C(0x0))) - return 1; - // positive / -0.0 = -Inf - if (test__divtf3(+1.0L, -0x0.0p+0L, - UINT64_C(0xffff000000000000), - UINT64_C(0x0))) - return 1; - // negative / +0.0 = -Inf - if (test__divtf3(-1.0L, +0x0.0p+0L, - UINT64_C(0xffff000000000000), - UINT64_C(0x0))) - return 1; - // negative / -0.0 = +Inf - if (test__divtf3(-1.0L, -0x0.0p+0L, - UINT64_C(0x7fff000000000000), - UINT64_C(0x0))) - return 1; - - // 1/3 - if (test__divtf3(1.L, 3.L, - UINT64_C(0x3ffd555555555555), - UINT64_C(0x5555555555555555))) - return 1; - // smallest normal result - if (test__divtf3(0x1.0p-16381L, 2.L, - UINT64_C(0x0001000000000000), - UINT64_C(0x0))) - return 1; - - // divisor is exactly 1.0 - if (test__divtf3(0x1.0p+0L, - 0x1.0p+0L, - UINT64_C(0x3fff000000000000), - UINT64_C(0x0))) - return 1; - // divisor is truncated to exactly 1.0 in UQ1.63 - if (test__divtf3(0x1.0p+0L, - 0x1.0000000000000001p+0L, - UINT64_C(0x3ffeffffffffffff), - UINT64_C(0xfffe000000000000))) - return 1; - - // smallest normal value divided by 2.0 - if (test__divtf3(0x1.0p-16382L, 2.L, UINT64_C(0x0000800000000000), UINT64_C(0x0))) - return 1; - // smallest subnormal result - if (test__divtf3(0x1.0p-16382L, 0x1p+112L, UINT64_C(0x0), UINT64_C(0x1))) - return 1; - - // any / any - if (test__divtf3(0x1.a23b45362464523375893ab4cdefp+5L, - 0x1.eedcbaba3a94546558237654321fp-1L, - UINT64_C(0x4004b0b72924d407), - UINT64_C(0x0717e84356c6eba2))) - return 1; - if (test__divtf3(0x1.a2b34c56d745382f9abf2c3dfeffp-50L, - 0x1.ed2c3ba15935332532287654321fp-9L, - UINT64_C(0x3fd5b2af3f828c9b), - UINT64_C(0x40e51f64cde8b1f2))) - return 15; - if (test__divtf3(0x1.2345f6aaaa786555f42432abcdefp+456L, - 0x1.edacbba9874f765463544dd3621fp+6400L, - UINT64_C(0x28c62e15dc464466), - UINT64_C(0xb5a07586348557ac))) - return 1; - if (test__divtf3(0x1.2d3456f789ba6322bc665544edefp-234L, - 0x1.eddcdba39f3c8b7a36564354321fp-4455L, - UINT64_C(0x507b38442b539266), - UINT64_C(0x22ce0f1d024e1252))) - return 1; - if (test__divtf3(0x1.2345f6b77b7a8953365433abcdefp+234L, - 0x1.edcba987d6bb3aa467754354321fp-4055L, - UINT64_C(0x50bf2e02f0798d36), - UINT64_C(0x5e6fcb6b60044078))) - return 1; - if (test__divtf3(6.72420628622418701252535563464350521E-4932L, - 2.L, - UINT64_C(0x0001000000000000), - UINT64_C(0))) - return 1; - -#else - printf("skipped\n"); #endif - return 0; -} diff --git a/compiler-rt/test/builtins/Unit/eqtf2_test.c b/compiler-rt/test/builtins/Unit/eqtf2_test.c --- a/compiler-rt/test/builtins/Unit/eqtf2_test.c +++ b/compiler-rt/test/builtins/Unit/eqtf2_test.c @@ -3,15 +3,18 @@ #include -#if __LP64__ && __LDBL_MANT_DIG__ == 113 - #include "fp_test.h" +#if !defined(CRT_HAS_F128) +int main() { + fprintf(stderr, "Missing f128 support - skipping.\n"); + return 1; +} +#else +long __eqtf2(f128 a, f128 b); -int __eqtf2(long double a, long double b); - -int test__eqtf2(long double a, long double b, enum EXPECTED_RESULT expected) +int test__eqtf2(f128 a, f128 b, enum EXPECTED_RESULT expected) { - int x = __eqtf2(a, b); + long x = __eqtf2(a, b); int ret = compareResultCMP(x, expected); if (ret){ @@ -21,13 +24,10 @@ return ret; } -char assumption_1[sizeof(long double) * CHAR_BIT == 128] = {0}; - -#endif +char assumption_1[sizeof(f128) * CHAR_BIT == 128] = {0}; int main() { -#if __LP64__ && __LDBL_MANT_DIG__ == 113 // NaN if (test__eqtf2(makeQNaN128(), 0x1.234567890abcdef1234567890abcp+3L, @@ -71,9 +71,6 @@ NEQUAL_0)) return 1; -#else - printf("skipped\n"); - -#endif return 0; } +#endif diff --git a/compiler-rt/test/builtins/Unit/extenddftf2_test.c b/compiler-rt/test/builtins/Unit/extenddftf2_test.c --- a/compiler-rt/test/builtins/Unit/extenddftf2_test.c +++ b/compiler-rt/test/builtins/Unit/extenddftf2_test.c @@ -2,33 +2,34 @@ // REQUIRES: librt_has_extenddftf2 #include "int_lib.h" -#include - -#if __LDBL_MANT_DIG__ == 113 - #include "fp_test.h" +#include -COMPILER_RT_ABI long double __extenddftf2(double a); +#if !defined(CRT_HAS_F128) +int main() { + fprintf(stderr, "Missing f128 support - skipping.\n"); + return 1; +} +#else +COMPILER_RT_ABI f128 __extenddftf2(double a); -int test__extenddftf2(double a, uint64_t expectedHi, uint64_t expectedLo) +int _test__extenddftf2(int line, double a, uint64_t expectedHi, uint64_t expectedLo) { - long double x = __extenddftf2(a); - int ret = compareResultLD(x, expectedHi, expectedLo); + f128 x = __extenddftf2(a); + int ret = compareResultF128(x, expectedHi, expectedLo); if (ret){ - printf("error in test__extenddftf2(%f) = %.20Lf, " - "expected %.20Lf\n", a, x, fromRep128(expectedHi, expectedLo)); + fprintf(stderr, "%s:%d: error in test__extenddftf2(%f): ", __FILE__, line, a); + printMismatchF128(x, expectedHi, expectedLo); } return ret; } -char assumption_1[sizeof(long double) * CHAR_BIT == 128] = {0}; +#define test__extenddftf2(...) _test__extenddftf2(__LINE__, __VA_ARGS__) -#endif int main() { -#if __LDBL_MANT_DIG__ == 113 // qNaN if (test__extenddftf2(makeQNaN64(), UINT64_C(0x7fff800000000000), @@ -65,9 +66,6 @@ UINT64_C(0x2000000000000000))) return 1; -#else - printf("skipped\n"); - -#endif return 0; } +#endif diff --git a/compiler-rt/test/builtins/Unit/extendhfsf2_test.c b/compiler-rt/test/builtins/Unit/extendhfsf2_test.c --- a/compiler-rt/test/builtins/Unit/extendhfsf2_test.c +++ b/compiler-rt/test/builtins/Unit/extendhfsf2_test.c @@ -7,18 +7,20 @@ float __extendhfsf2(TYPE_FP16 a); -int test__extendhfsf2(TYPE_FP16 a, uint32_t expected) +int _test__extendhfsf2(int line, TYPE_FP16 a, uint32_t expected) { float x = __extendhfsf2(a); int ret = compareResultF(x, expected); if (ret){ - printf("error in test__extendhfsf2(%#.4x) = %f, " - "expected %f\n", toRep16(a), x, fromRep32(expected)); + printf("%s:%d: error in test__extendhfsf2(%#.4x) = %f, " + "expected %f\n", __FILE__, line, toRep16(a), x, fromRep32(expected)); } return ret; } +#define test__extendhfsf2(...) _test__extendhfsf2(__LINE__, __VA_ARGS__) + char assumption_1[sizeof(TYPE_FP16) * CHAR_BIT == 16] = {0}; int main() @@ -32,11 +34,11 @@ UINT32_C(0x7ff00000))) return 1; // inf - if (test__extendhfsf2(fromRep16(0x7c00), + if (test__extendhfsf2(makeInf16(), UINT32_C(0x7f800000))) return 1; // -inf - if (test__extendhfsf2(fromRep16(0xfc00), + if (test__extendhfsf2(makeNegativeInf16(), UINT32_C(0xff800000))) return 1; // zero diff --git a/compiler-rt/test/builtins/Unit/extendhftf2_test.c b/compiler-rt/test/builtins/Unit/extendhftf2_test.c --- a/compiler-rt/test/builtins/Unit/extendhftf2_test.c +++ b/compiler-rt/test/builtins/Unit/extendhftf2_test.c @@ -3,32 +3,33 @@ #include "int_lib.h" #include - -#if __LDBL_MANT_DIG__ == 113 && defined(COMPILER_RT_HAS_FLOAT16) - #include "fp_test.h" -COMPILER_RT_ABI long double __extendhftf2(TYPE_FP16 a); +#if !defined(CRT_HAS_F128) +int main() { + fprintf(stderr, "Missing f128 support - skipping.\n"); + return 1; +} +#else +COMPILER_RT_ABI f128 __extendhftf2(TYPE_FP16 a); -int test__extendhftf2(TYPE_FP16 a, uint64_t expectedHi, uint64_t expectedLo) { - long double x = __extendhftf2(a); - int ret = compareResultLD(x, expectedHi, expectedLo); +int _test__extendhftf2(int line, TYPE_FP16 a, uint64_t expectedHi, uint64_t expectedLo) { + f128 x = __extendhftf2(a); + int ret = compareResultF128(x, expectedHi, expectedLo); if (ret) { - printf("error in test__extendhftf2(%#.4x) = %.20Lf, " - "expected %.20Lf\n", - toRep16(a), x, - fromRep128(expectedHi, expectedLo)); + fprintf(stderr, "%s:%d: error in test__extendhftf2(%#.4x/%g): ", + __FILE__, line, toRep16(a), (double)a); + printMismatchF128(x, expectedHi, expectedLo); } return ret; } +#define test__extendhftf2(...) _test__extendhftf2(__LINE__, __VA_ARGS__) -char assumption_1[sizeof(TYPE_FP16) * CHAR_BIT == 16] = {0}; -#endif +char assumption_1[sizeof(TYPE_FP16) * CHAR_BIT == 16] = {0}; int main() { -#if __LDBL_MANT_DIG__ == 113 && defined(COMPILER_RT_HAS_FLOAT16) // qNaN if (test__extendhftf2(makeQNaN16(), UINT64_C(0x7fff800000000000), @@ -44,7 +45,7 @@ UINT64_C(0x7fff000000000000), UINT64_C(0x0))) return 1; - if (test__extendhftf2(-makeInf16(), + if (test__extendhftf2(makeNegativeInf16(), UINT64_C(0xffff000000000000), UINT64_C(0x0))) return 1; @@ -88,8 +89,5 @@ UINT64_C(0x3ff6edc000000000), UINT64_C(0x0))) return 1; -#else - printf("skipped\n"); -#endif - return 0; } +#endif diff --git a/compiler-rt/test/builtins/Unit/extendsftf2_test.c b/compiler-rt/test/builtins/Unit/extendsftf2_test.c --- a/compiler-rt/test/builtins/Unit/extendsftf2_test.c +++ b/compiler-rt/test/builtins/Unit/extendsftf2_test.c @@ -4,32 +4,31 @@ #include "int_lib.h" #include -#if __LDBL_MANT_DIG__ == 113 - #include "fp_test.h" +#if !defined(CRT_HAS_F128) +int main() { + fprintf(stderr, "Missing f128 support - skipping.\n"); + return 1; +} +#else +COMPILER_RT_ABI f128 __extendsftf2(float a); -COMPILER_RT_ABI long double __extendsftf2(float a); - -int test__extendsftf2(float a, uint64_t expectedHi, uint64_t expectedLo) -{ - long double x = __extendsftf2(a); - int ret = compareResultLD(x, expectedHi, expectedLo); +int _test__extendsftf2(int line, float a, uint64_t expectedHi, uint64_t expectedLo) { + f128 x = __extendsftf2(a); + int ret = compareResultF128(x, expectedHi, expectedLo); - if (ret) - { - printf("error in test__extendsftf2(%f) = %.20Lf, " - "expected %.20Lf\n", a, x, fromRep128(expectedHi, expectedLo)); - } - return ret; + if (ret) { + printf("%s:%d: error in __extendsftf2(%f): ", __FILE__, line, a); + printMismatchF128(x, expectedHi, expectedLo); + } + return ret; } -char assumption_1[sizeof(long double) * CHAR_BIT == 128] = {0}; +#define test__extendsftf2(...) _test__extendsftf2(__LINE__, __VA_ARGS__) -#endif int main() { -#if __LDBL_MANT_DIG__ == 113 // qNaN if (test__extendsftf2(makeQNaN32(), UINT64_C(0x7fff800000000000), @@ -66,9 +65,6 @@ UINT64_C(0x0))) return 1; -#else - printf("skipped\n"); - -#endif return 0; } +#endif diff --git a/compiler-rt/test/builtins/Unit/fixtfdi_test.c b/compiler-rt/test/builtins/Unit/fixtfdi_test.c --- a/compiler-rt/test/builtins/Unit/fixtfdi_test.c +++ b/compiler-rt/test/builtins/Unit/fixtfdi_test.c @@ -4,13 +4,16 @@ #include "int_lib.h" #include -#if __LDBL_MANT_DIG__ == 113 - #include "fp_test.h" +#if !defined(CRT_HAS_F128) +int main() { + fprintf(stderr, "Missing f128 support - skipping.\n"); + return 1; +} +#else +di_int __fixtfdi(f128 a); -di_int __fixtfdi(long double a); - -int test__fixtfdi(long double a, di_int expected) +int test__fixtfdi(f128 a, di_int expected) { di_int x = __fixtfdi(a); int ret = (x != expected); @@ -23,13 +26,10 @@ return ret; } -char assumption_1[sizeof(long double) * CHAR_BIT == 128] = {0}; - -#endif +char assumption_1[sizeof(f128) * CHAR_BIT == 128] = {0}; int main() { -#if __LDBL_MANT_DIG__ == 113 if (test__fixtfdi(makeInf128(), 0x7fffffffffffffffLL)) return 1; if (test__fixtfdi(0, 0x0)) @@ -53,9 +53,8 @@ if (test__fixtfdi(-0x1.23456789abcdefp+256L, 0x8000000000000000LL)) return 1; -#else printf("skipped\n"); -#endif return 0; } +#endif diff --git a/compiler-rt/test/builtins/Unit/fixtfsi_test.c b/compiler-rt/test/builtins/Unit/fixtfsi_test.c --- a/compiler-rt/test/builtins/Unit/fixtfsi_test.c +++ b/compiler-rt/test/builtins/Unit/fixtfsi_test.c @@ -3,13 +3,16 @@ #include -#if __LDBL_MANT_DIG__ == 113 - #include "fp_test.h" +#if !defined(CRT_HAS_F128) +int main() { + fprintf(stderr, "Missing f128 support - skipping.\n"); + return 1; +} +#else +int __fixtfsi(f128 a); -int __fixtfsi(long double a); - -int test__fixtfsi(long double a, int expected) +int test__fixtfsi(f128 a, int expected) { int x = __fixtfsi(a); int ret = (x != expected); @@ -21,13 +24,10 @@ return ret; } -char assumption_1[sizeof(long double) * CHAR_BIT == 128] = {0}; - -#endif +char assumption_1[sizeof(f128) * CHAR_BIT == 128] = {0}; int main() { -#if __LDBL_MANT_DIG__ == 113 if (test__fixtfsi(makeInf128(), 0x7fffffff)) return 1; if (test__fixtfsi(0, 0x0)) @@ -47,9 +47,6 @@ if (test__fixtfsi(-0x1.23456789abcdefp+40, 0x80000000)) return 1; -#else - printf("skipped\n"); - -#endif return 0; } +#endif diff --git a/compiler-rt/test/builtins/Unit/fixtfti_test.c b/compiler-rt/test/builtins/Unit/fixtfti_test.c --- a/compiler-rt/test/builtins/Unit/fixtfti_test.c +++ b/compiler-rt/test/builtins/Unit/fixtfti_test.c @@ -4,13 +4,16 @@ #include "int_lib.h" #include -#if __LDBL_MANT_DIG__ == 113 - #include "fp_test.h" +#if !defined(CRT_HAS_F128) +int main() { + fprintf(stderr, "Missing f128 support - skipping.\n"); + return 1; +} +#else +ti_int __fixtfti(f128 a); -ti_int __fixtfti(long double a); - -int test__fixtfti(long double a, ti_int expected) +int test__fixtfti(f128 a, ti_int expected) { ti_int x = __fixtfti(a); int ret = (x != expected); @@ -23,51 +26,45 @@ twords expectedt; expectedt.all = expected; - printf("error in test__fixtfti(%.20Lf) = 0x%.16llX%.16llX, " + printf("error in test__fixtfti(%.20f) = 0x%.16llX%.16llX, " "expected 0x%.16llX%.16llX\n", - a, xt.s.high, xt.s.low, expectedt.s.high, expectedt.s.low); + (double)a, xt.s.high, xt.s.low, expectedt.s.high, expectedt.s.low); } return ret; } -char assumption_1[sizeof(long double) * CHAR_BIT == 128] = {0}; - -#endif +char assumption_1[sizeof(f128) * CHAR_BIT == 128] = {0}; int main() { -#if __LDBL_MANT_DIG__ == 113 if (test__fixtfti(makeInf128(), make_ti(0x7fffffffffffffffLL, 0xffffffffffffffffLL))) return 1; if (test__fixtfti(0, make_ti(0x0LL, 0x0LL))) return 1; - if (test__fixtfti(0x1.23456789abcdefp+5L, make_ti(0x0LL, 0x24LL))) + if (test__fixtfti(0x1.23456789abcdefp+5Q, make_ti(0x0LL, 0x24LL))) return 1; - if (test__fixtfti(0x1.23456789abcdefp-3L, make_ti(0x0LL, 0x0LL))) + if (test__fixtfti(0x1.23456789abcdefp-3Q, make_ti(0x0LL, 0x0LL))) return 1; - if (test__fixtfti(0x1.23456789abcdef12345678p+20L, + if (test__fixtfti(0x1.23456789abcdef12345678p+20Q, make_ti(0x0LL, 0x123456LL))) return 1; - if (test__fixtfti(0x1.23456789abcdef123456789abcdep+112L, + if (test__fixtfti(0x1.23456789abcdef123456789abcdep+112Q, make_ti(0x123456789abcdLL, 0xef123456789abcdeLL))) return 1; - if (test__fixtfti(-0x1.23456789abcdef123456789abcdep+112L, + if (test__fixtfti(-0x1.23456789abcdef123456789abcdep+112Q, make_ti(0xFFFEDCBA98765432LL, 0x10EDCBA987654322LL))) return 1; - if (test__fixtfti(0x1.23456789abcdefp+256L, make_ti(0x7fffffffffffffffLL, + if (test__fixtfti(0x1.23456789abcdefp+256Q, make_ti(0x7fffffffffffffffLL, 0xffffffffffffffffLL))) return 1; - if (test__fixtfti(-0x1.23456789abcdefp+20L, make_ti(0xffffffffffffffffLL, + if (test__fixtfti(-0x1.23456789abcdefp+20Q, make_ti(0xffffffffffffffffLL, 0xffffffffffedcbaaLL))) return 1; - if (test__fixtfti(-0x1.23456789abcdefp+256L, make_ti(0x8000000000000000LL, + if (test__fixtfti(-0x1.23456789abcdefp+256Q, make_ti(0x8000000000000000LL, 0x0))) return 1; -#else - printf("skipped\n"); - -#endif return 0; } +#endif diff --git a/compiler-rt/test/builtins/Unit/fixunstfdi_test.c b/compiler-rt/test/builtins/Unit/fixunstfdi_test.c --- a/compiler-rt/test/builtins/Unit/fixunstfdi_test.c +++ b/compiler-rt/test/builtins/Unit/fixunstfdi_test.c @@ -10,14 +10,14 @@ // Returns: convert a to a unsigned long long, rounding toward zero. // Negative values all become zero. -// Assumption: long double is a 128 bit floating point type +// Assumption: f128 is a 128 bit floating point type // du_int is a 64 bit integral type -// value in long double is representable in du_int or is negative +// value in f128 is representable in du_int or is negative // (no range checking performed) -COMPILER_RT_ABI du_int __fixunstfdi(long double a); +COMPILER_RT_ABI du_int __fixunstfdi(f128 a); -int test__fixunstfdi(long double a, du_int expected) +int test__fixunstfdi(f128 a, du_int expected) { du_int x = __fixunstfdi(a); if (x != expected) @@ -28,7 +28,7 @@ char assumption_1[sizeof(du_int) == 2*sizeof(su_int)] = {0}; char assumption_2[sizeof(du_int)*CHAR_BIT == 64] = {0}; -char assumption_3[sizeof(long double)*CHAR_BIT == 128] = {0}; +char assumption_3[sizeof(f128)*CHAR_BIT == 128] = {0}; #endif diff --git a/compiler-rt/test/builtins/Unit/fixunstfsi_test.c b/compiler-rt/test/builtins/Unit/fixunstfsi_test.c --- a/compiler-rt/test/builtins/Unit/fixunstfsi_test.c +++ b/compiler-rt/test/builtins/Unit/fixunstfsi_test.c @@ -3,13 +3,16 @@ #include -#if __LDBL_MANT_DIG__ == 113 - #include "fp_test.h" +#if !defined(CRT_HAS_F128) +int main() { + fprintf(stderr, "Missing f128 support - skipping.\n"); + return 1; +} +#else +unsigned int __fixunstfsi(f128 a); -unsigned int __fixunstfsi(long double a); - -int test__fixunstfsi(long double a, unsigned int expected) +int test__fixunstfsi(f128 a, unsigned int expected) { unsigned int x = __fixunstfsi(a); int ret = (x != expected); @@ -22,13 +25,10 @@ return ret; } -char assumption_1[sizeof(long double) * CHAR_BIT == 128] = {0}; - -#endif +char assumption_1[sizeof(f128) * CHAR_BIT == 128] = {0}; int main() { -#if __LDBL_MANT_DIG__ == 113 if (test__fixunstfsi(makeInf128(), UINT32_C(0xffffffff))) return 1; if (test__fixunstfsi(0, UINT32_C(0x0))) @@ -49,9 +49,6 @@ if (test__fixunstfsi(0x1.p+32, 0xFFFFFFFFLL)) return 1; -#else - printf("skipped\n"); - -#endif return 0; } +#endif diff --git a/compiler-rt/test/builtins/Unit/fixunstfti_test.c b/compiler-rt/test/builtins/Unit/fixunstfti_test.c --- a/compiler-rt/test/builtins/Unit/fixunstfti_test.c +++ b/compiler-rt/test/builtins/Unit/fixunstfti_test.c @@ -4,23 +4,26 @@ #include - -#if __LDBL_MANT_DIG__ == 113 - #include "fp_test.h" +#if !defined(CRT_HAS_F128) +int main() { + fprintf(stderr, "Missing f128 support - skipping.\n"); + return 1; +} +#else #include "int_lib.h" // Returns: convert a to a unsigned long long, rounding toward zero. // Negative values all become zero. -// Assumption: long double is a 128 bit floating point type +// Assumption: f128 is a 128 bit floating point type // tu_int is a 128 bit integral type -// value in long double is representable in tu_int or is negative +// value in f128 is representable in tu_int or is negative // (no range checking performed) -COMPILER_RT_ABI tu_int __fixunstfti(long double a); +COMPILER_RT_ABI tu_int __fixunstfti(f128 a); -int test__fixunstfti(long double a, tu_int expected) +int test__fixunstfti(f128 a, tu_int expected) { tu_int x = __fixunstfti(a); if (x != expected) @@ -40,13 +43,10 @@ char assumption_1[sizeof(tu_int) == 4*sizeof(su_int)] = {0}; char assumption_2[sizeof(tu_int)*CHAR_BIT == 128] = {0}; -char assumption_3[sizeof(long double)*CHAR_BIT == 128] = {0}; - -#endif +char assumption_3[sizeof(f128)*CHAR_BIT == 128] = {0}; int main() { -#if __LDBL_MANT_DIG__ == 113 if (test__fixunstfti(makeInf128(), make_ti(0xffffffffffffffffLL, 0xffffffffffffffffLL))) return 1; @@ -88,8 +88,6 @@ 0xffffffffffffffffLL))) return 1; -#else - printf("skipped\n"); -#endif return 0; } +#endif diff --git a/compiler-rt/test/builtins/Unit/floatditf_test.c b/compiler-rt/test/builtins/Unit/floatditf_test.c --- a/compiler-rt/test/builtins/Unit/floatditf_test.c +++ b/compiler-rt/test/builtins/Unit/floatditf_test.c @@ -6,18 +6,21 @@ #include #include -#if __LDBL_MANT_DIG__ == 113 - #include "fp_test.h" +#if !defined(CRT_HAS_F128) +int main() { + fprintf(stderr, "Missing f128 support - skipping.\n"); + return 1; +} +#else +// Returns: long integer converted to f128 -// Returns: long integer converted to long double - -COMPILER_RT_ABI long double __floatditf(long long a); +COMPILER_RT_ABI f128 __floatditf(long long a); int test__floatditf(long long a, uint64_t expectedHi, uint64_t expectedLo) { - long double x = __floatditf(a); - int ret = compareResultLD(x, expectedHi, expectedLo); + f128 x = __floatditf(a); + int ret = compareResultF128(x, expectedHi, expectedLo); if (ret) printf("error in __floatditf(%Ld) = %.20Lf, " @@ -25,13 +28,10 @@ return ret; } -char assumption_1[sizeof(long double) * CHAR_BIT == 128] = {0}; - -#endif +char assumption_1[sizeof(f128) * CHAR_BIT == 128] = {0}; int main() { -#if __LDBL_MANT_DIG__ == 113 if (test__floatditf(0x7fffffffffffffff, UINT64_C(0x403dffffffffffff), UINT64_C(0xfffc000000000000))) return 1; if (test__floatditf(0x123456789abcdef1, UINT64_C(0x403b23456789abcd), UINT64_C(0xef10000000000000))) @@ -51,9 +51,6 @@ if (test__floatditf(0x8000000000000000, UINT64_C(0xc03e000000000000), UINT64_C(0x0))) return 1; -#else - printf("skipped\n"); - -#endif return 0; } +#endif diff --git a/compiler-rt/test/builtins/Unit/floatsitf_test.c b/compiler-rt/test/builtins/Unit/floatsitf_test.c --- a/compiler-rt/test/builtins/Unit/floatsitf_test.c +++ b/compiler-rt/test/builtins/Unit/floatsitf_test.c @@ -4,16 +4,20 @@ #include "int_lib.h" #include -#if __LDBL_MANT_DIG__ == 113 - #include "fp_test.h" +#if !defined(CRT_HAS_F128) +int main() { + fprintf(stderr, "Missing f128 support - skipping.\n"); + return 1; +} +#else -long COMPILER_RT_ABI double __floatsitf(int a); +COMPILER_RT_ABI f128 __floatsitf(int a); int test__floatsitf(int a, uint64_t expectedHi, uint64_t expectedLo) { - long double x = __floatsitf(a); - int ret = compareResultLD(x, expectedHi, expectedLo); + f128 x = __floatsitf(a); + int ret = compareResultF128(x, expectedHi, expectedLo); if (ret) { @@ -23,13 +27,10 @@ return ret; } -char assumption_1[sizeof(long double) * CHAR_BIT == 128] = {0}; - -#endif +char assumption_1[sizeof(f128) * CHAR_BIT == 128] = {0}; int main() { -#if __LDBL_MANT_DIG__ == 113 if (test__floatsitf(0x80000000, UINT64_C(0xc01e000000000000), UINT64_C(0x0))) return 1; if (test__floatsitf(0x7fffffff, UINT64_C(0x401dfffffffc0000), UINT64_C(0x0))) @@ -42,10 +43,6 @@ return 1; if (test__floatsitf(-0x12345678, UINT64_C(0xc01b234567800000), UINT64_C(0x0))) return 1; - -#else - printf("skipped\n"); - -#endif return 0; } +#endif diff --git a/compiler-rt/test/builtins/Unit/floatunditf_test.c b/compiler-rt/test/builtins/Unit/floatunditf_test.c --- a/compiler-rt/test/builtins/Unit/floatunditf_test.c +++ b/compiler-rt/test/builtins/Unit/floatunditf_test.c @@ -6,18 +6,21 @@ #include #include -#if __LDBL_MANT_DIG__ == 113 - #include "fp_test.h" +#if !defined(CRT_HAS_F128) +int main() { + fprintf(stderr, "Missing f128 support - skipping.\n"); + return 1; +} +#else +// Returns: long integer converted to f128 -// Returns: long integer converted to long double - -COMPILER_RT_ABI long double __floatunditf(unsigned long long a); +COMPILER_RT_ABI f128 __floatunditf(unsigned long long a); int test__floatunditf(unsigned long long a, uint64_t expectedHi, uint64_t expectedLo) { - long double x = __floatunditf(a); - int ret = compareResultLD(x, expectedHi, expectedLo); + f128 x = __floatunditf(a); + int ret = compareResultF128(x, expectedHi, expectedLo); if (ret) printf("error in __floatunditf(%Lu) = %.20Lf, " @@ -25,13 +28,10 @@ return ret; } -char assumption_1[sizeof(long double) * CHAR_BIT == 128] = {0}; - -#endif +char assumption_1[sizeof(f128) * CHAR_BIT == 128] = {0}; int main() { -#if __LDBL_MANT_DIG__ == 113 if (test__floatunditf(0xffffffffffffffffULL, UINT64_C(0x403effffffffffff), UINT64_C(0xfffe000000000000))) return 1; if (test__floatunditf(0xfffffffffffffffeULL, UINT64_C(0x403effffffffffff), UINT64_C(0xfffc000000000000))) @@ -49,9 +49,6 @@ if (test__floatunditf(0x0ULL, UINT64_C(0x0), UINT64_C(0x0))) return 1; -#else - printf("skipped\n"); - -#endif return 0; } +#endif diff --git a/compiler-rt/test/builtins/Unit/floatunsitf_test.c b/compiler-rt/test/builtins/Unit/floatunsitf_test.c --- a/compiler-rt/test/builtins/Unit/floatunsitf_test.c +++ b/compiler-rt/test/builtins/Unit/floatunsitf_test.c @@ -4,16 +4,19 @@ #include "int_lib.h" #include -#if __LDBL_MANT_DIG__ == 113 - #include "fp_test.h" - -COMPILER_RT_ABI long double __floatunsitf(unsigned int a); +#if !defined(CRT_HAS_F128) +int main() { + fprintf(stderr, "Missing f128 support - skipping.\n"); + return 1; +} +#else +COMPILER_RT_ABI f128 __floatunsitf(unsigned int a); int test__floatunsitf(unsigned int a, uint64_t expectedHi, uint64_t expectedLo) { - long double x = __floatunsitf(a); - int ret = compareResultLD(x, expectedHi, expectedLo); + f128 x = __floatunsitf(a); + int ret = compareResultF128(x, expectedHi, expectedLo); if (ret){ printf("error in test__floatunsitf(%u) = %.20Lf, " @@ -22,13 +25,10 @@ return ret; } -char assumption_1[sizeof(long double) * CHAR_BIT == 128] = {0}; - -#endif +char assumption_1[sizeof(f128) * CHAR_BIT == 128] = {0}; int main() { -#if __LDBL_MANT_DIG__ == 113 if (test__floatunsitf(0x7fffffff, UINT64_C(0x401dfffffffc0000), UINT64_C(0x0))) return 1; if (test__floatunsitf(0, UINT64_C(0x0), UINT64_C(0x0))) @@ -38,9 +38,6 @@ if (test__floatunsitf(0x12345678, UINT64_C(0x401b234567800000), UINT64_C(0x0))) return 1; -#else - printf("skipped\n"); - -#endif return 0; } +#endif diff --git a/compiler-rt/test/builtins/Unit/fp_test.h b/compiler-rt/test/builtins/Unit/fp_test.h --- a/compiler-rt/test/builtins/Unit/fp_test.h +++ b/compiler-rt/test/builtins/Unit/fp_test.h @@ -1,7 +1,10 @@ -#include #include -#include #include +#include +#include +#include + +#include "int_types.h" #ifdef COMPILER_RT_HAS_FLOAT16 #define TYPE_FP16 _Float16 @@ -9,6 +12,10 @@ #define TYPE_FP16 uint16_t #endif +#ifdef CRT_HAS_F128 +_Static_assert(sizeof(f128) == 16, ""); +#endif + enum EXPECTED_RESULT { LESS_0, LESS_EQUAL_0, EQUAL_0, GREATER_0, GREATER_EQUAL_0, NEQUAL_0 }; @@ -38,13 +45,12 @@ return ret; } -#if __LDBL_MANT_DIG__ == 113 -static inline long double fromRep128(uint64_t hi, uint64_t lo) -{ - __uint128_t x = ((__uint128_t)hi << 64) + lo; - long double ret; - memcpy(&ret, &x, 16); - return ret; +#ifdef CRT_HAS_F128 +static inline f128 fromRep128(uint64_t hi, uint64_t lo) { + __uint128_t x = ((__uint128_t)hi << 64) + lo; + f128 ret; + memcpy(&ret, &x, 16); + return ret; } #endif @@ -73,12 +79,11 @@ return ret; } -#if __LDBL_MANT_DIG__ == 113 -static inline __uint128_t toRep128(long double x) -{ - __uint128_t ret; - memcpy(&ret, &x, 16); - return ret; +#ifdef CRT_HAS_F128 +static inline __uint128_t toRep128(f128 x) { + __uint128_t ret; + memcpy(&ret, &x, 16); + return ret; } #endif @@ -136,64 +141,117 @@ return 1; } -#if __LDBL_MANT_DIG__ == 113 +#ifdef CRT_HAS_F128 // return 0 if equal // use two 64-bit integers intead of one 128-bit integer // because 128-bit integer constant can't be assigned directly -static inline int compareResultLD(long double result, - uint64_t expectedHi, - uint64_t expectedLo) -{ - __uint128_t rep = toRep128(result); - uint64_t hi = rep >> 64; - uint64_t lo = rep; - - if (hi == expectedHi && lo == expectedLo){ - return 0; - } - // test other possible NaN representation(signal NaN) - else if (expectedHi == 0x7fff800000000000UL && expectedLo == 0x0UL){ - if ((hi & 0x7fff000000000000UL) == 0x7fff000000000000UL && - ((hi & 0xffffffffffffUL) > 0 || lo > 0)){ - return 0; - } +static inline int compareResultF128(f128 result, + uint64_t expectedHi, + uint64_t expectedLo) { + __uint128_t rep = toRep128(result); + uint64_t hi = rep >> 64; + uint64_t lo = rep; + + if (hi == expectedHi && lo == expectedLo) { + return 0; + } + // test other possible NaN representation(signal NaN) + else if (expectedHi == 0x7fff800000000000UL && expectedLo == 0x0UL) { + if ((hi & 0x7fff000000000000UL) == 0x7fff000000000000UL && + ((hi & 0xffffffffffffUL) > 0 || lo > 0)) { + return 0; } - return 1; + } + return 1; } + +#if __LDBL_MANT_DIG__ != 113 +// Cast to double instead of long double in the printf() call to avoid +// calling __trunctfxf2 since we don't have an implementation for that yet. +#define F128_ARG(x, xrep) ((double)(x)), (unsigned long long)(xrep >> 64), (unsigned long)(xrep) +#define F128_FMT "%.20g / 0x%016llx%016llx" +#else +#define F128_ARG(x, xrep) ((long double)(x)), (unsigned long long)(xrep >> 64), (unsigned long)(xrep) +#define F128_FMT "%.20Lg / 0x%016llx%016llx" #endif -static inline int compareResultCMP(int result, - enum EXPECTED_RESULT expected) -{ - switch(expected){ - case LESS_0: - if (result < 0) - return 0; - break; - case LESS_EQUAL_0: - if (result <= 0) - return 0; - break; - case EQUAL_0: - if (result == 0) - return 0; - break; - case NEQUAL_0: - if (result != 0) - return 0; - break; - case GREATER_EQUAL_0: - if (result >= 0) - return 0; - break; - case GREATER_0: - if (result > 0) - return 0; - break; - default: - return 1; - } +static inline void printMismatchF128(f128 result, uint64_t expectedHi, + uint64_t expectedLo) { + __uint128_t resultRep = toRep128(result); + __uint128_t expectedRep = ((__uint128_t)expectedHi << 64) | expectedLo; + f128 expected = fromRep128(expectedHi, expectedLo); + fprintf(stderr, "expected " F128_FMT " but got " F128_FMT "\n", + F128_ARG(expected, expectedRep), + F128_ARG(result, resultRep)); +} + +static inline void printMismatchF128OneArg(const char *file, int line, const char *func, + f128 arg1, f128 result, + uint64_t expectedHi, uint64_t expectedLo) { + __uint128_t arg1Rep = toRep128(arg1); + fprintf(stderr, "%s:%d: error in %s(" F128_FMT "): ", + file, line, func, F128_ARG(arg1, arg1Rep)); + printMismatchF128(result, expectedHi, expectedLo); +} + +static inline void printMismatchF128TwoArg(const char *file, int line, const char *func, + f128 arg1, f128 arg2, f128 result, + uint64_t expectedHi, uint64_t expectedLo) { + __uint128_t arg1Rep = toRep128(arg1); + __uint128_t arg2Rep = toRep128(arg2); + fprintf(stderr, "%s:%d: error in %s(" F128_FMT ", " F128_FMT "): ", + file, line, func, F128_ARG(arg1, arg1Rep), + F128_ARG(arg2, arg2Rep)); + printMismatchF128(result, expectedHi, expectedLo); +} + +#undef F128_ARG +#undef F128_FMT + +static inline f128 _assertF128Representation(const char *str, f128 value, uint64_t expectedHi, + uint64_t expectedLo) { + if (compareResultF128(value, expectedHi, expectedLo)) { + fprintf(stderr, "Unexpected representation of %s:", str); + printMismatchF128(value, expectedHi, expectedLo); + abort(); + } + return value; +} +#define assertF128Representation(value, ...) _assertF128Representation(#value, value, __VA_ARGS__) + +#endif + +static inline int compareResultCMP(long result, + enum EXPECTED_RESULT expected) { + switch (expected) { + case LESS_0: + if (result < 0) + return 0; + break; + case LESS_EQUAL_0: + if (result <= 0) + return 0; + break; + case EQUAL_0: + if (result == 0) + return 0; + break; + case NEQUAL_0: + if (result != 0) + return 0; + break; + case GREATER_EQUAL_0: + if (result >= 0) + return 0; + break; + case GREATER_0: + if (result > 0) + return 0; + break; + default: return 1; + } + return 1; } static inline char *expectedStr(enum EXPECTED_RESULT expected) @@ -232,10 +290,9 @@ return fromRep64(0x7ff8000000000000UL); } -#if __LDBL_MANT_DIG__ == 113 -static inline long double makeQNaN128(void) -{ - return fromRep128(0x7fff800000000000UL, 0x0UL); +#ifdef CRT_HAS_F128 +static inline f128 makeQNaN128(void) { + return fromRep128(0x7fff800000000000UL, 0x0UL); } #endif @@ -254,10 +311,9 @@ return fromRep64(0x7ff0000000000000UL | (rand & 0xfffffffffffffUL)); } -#if __LDBL_MANT_DIG__ == 113 -static inline long double makeNaN128(uint64_t rand) -{ - return fromRep128(0x7fff000000000000UL | (rand & 0xffffffffffffUL), 0x0UL); +#ifdef CRT_HAS_F128 +static inline f128 makeNaN128(uint64_t rand) { + return fromRep128(0x7fff000000000000UL | (rand & 0xffffffffffffUL), 0x0UL); } #endif @@ -266,6 +322,10 @@ return fromRep16(0x7c00U); } +static inline TYPE_FP16 makeNegativeInf16(void) { + return fromRep16(0xfc00U); +} + static inline float makeInf32(void) { return fromRep32(0x7f800000U); @@ -286,14 +346,12 @@ return fromRep64(0xfff0000000000000UL); } -#if __LDBL_MANT_DIG__ == 113 -static inline long double makeInf128(void) -{ - return fromRep128(0x7fff000000000000UL, 0x0UL); +#ifdef CRT_HAS_F128 +static inline f128 makeInf128(void) { + return fromRep128(0x7fff000000000000UL, 0x0UL); } -static inline long double makeNegativeInf128(void) -{ - return fromRep128(0xffff000000000000UL, 0x0UL); +static inline f128 makeNegativeInf128(void) { + return fromRep128(0xffff000000000000UL, 0x0UL); } #endif diff --git a/compiler-rt/test/builtins/Unit/getf2_test.c b/compiler-rt/test/builtins/Unit/getf2_test.c --- a/compiler-rt/test/builtins/Unit/getf2_test.c +++ b/compiler-rt/test/builtins/Unit/getf2_test.c @@ -3,15 +3,18 @@ #include -#if __LP64__ && __LDBL_MANT_DIG__ == 113 - #include "fp_test.h" +#if !defined(CRT_HAS_F128) +int main() { + fprintf(stderr, "Missing f128 support - skipping.\n"); + return 1; +} +#else +long __getf2(f128 a, f128 b); -int __getf2(long double a, long double b); - -int test__getf2(long double a, long double b, enum EXPECTED_RESULT expected) +int test__getf2(f128 a, f128 b, enum EXPECTED_RESULT expected) { - int x = __getf2(a, b); + long x = __getf2(a, b); int ret = compareResultCMP(x, expected); if (ret){ @@ -21,13 +24,10 @@ return ret; } -char assumption_1[sizeof(long double) * CHAR_BIT == 128] = {0}; - -#endif +char assumption_1[sizeof(f128) * CHAR_BIT == 128] = {0}; int main() { -#if __LP64__ && __LDBL_MANT_DIG__ == 113 // NaN if (test__getf2(makeQNaN128(), 0x1.234567890abcdef1234567890abcp+3L, @@ -71,9 +71,6 @@ GREATER_EQUAL_0)) return 1; -#else - printf("skipped\n"); - -#endif return 0; } +#endif diff --git a/compiler-rt/test/builtins/Unit/gttf2_test.c b/compiler-rt/test/builtins/Unit/gttf2_test.c --- a/compiler-rt/test/builtins/Unit/gttf2_test.c +++ b/compiler-rt/test/builtins/Unit/gttf2_test.c @@ -3,15 +3,18 @@ #include -#if __LP64__ && __LDBL_MANT_DIG__ == 113 - #include "fp_test.h" +#if !defined(CRT_HAS_F128) +int main() { + fprintf(stderr, "Missing f128 support - skipping.\n"); + return 1; +} +#else +long __gttf2(f128 a, f128 b); -int __gttf2(long double a, long double b); - -int test__gttf2(long double a, long double b, enum EXPECTED_RESULT expected) +int test__gttf2(f128 a, f128 b, enum EXPECTED_RESULT expected) { - int x = __gttf2(a, b); + long x = __gttf2(a, b); int ret = compareResultCMP(x, expected); if (ret){ @@ -21,13 +24,10 @@ return ret; } -char assumption_1[sizeof(long double) * CHAR_BIT == 128] = {0}; - -#endif +char assumption_1[sizeof(f128) * CHAR_BIT == 128] = {0}; int main() { -#if __LP64__ && __LDBL_MANT_DIG__ == 113 // NaN if (test__gttf2(makeQNaN128(), 0x1.234567890abcdef1234567890abcp+3L, @@ -71,9 +71,6 @@ GREATER_0)) return 1; -#else - printf("skipped\n"); - -#endif return 0; } +#endif diff --git a/compiler-rt/test/builtins/Unit/letf2_test.c b/compiler-rt/test/builtins/Unit/letf2_test.c --- a/compiler-rt/test/builtins/Unit/letf2_test.c +++ b/compiler-rt/test/builtins/Unit/letf2_test.c @@ -3,15 +3,18 @@ #include -#if __LP64__ && __LDBL_MANT_DIG__ == 113 - #include "fp_test.h" +#if !defined(CRT_HAS_F128) +int main() { + fprintf(stderr, "Missing f128 support - skipping.\n"); + return 1; +} +#else +long __letf2(f128 a, f128 b); -int __letf2(long double a, long double b); - -int test__letf2(long double a, long double b, enum EXPECTED_RESULT expected) +int test__letf2(f128 a, f128 b, enum EXPECTED_RESULT expected) { - int x = __letf2(a, b); + long x = __letf2(a, b); int ret = compareResultCMP(x, expected); if (ret){ @@ -21,13 +24,10 @@ return ret; } -char assumption_1[sizeof(long double) * CHAR_BIT == 128] = {0}; - -#endif +char assumption_1[sizeof(f128) * CHAR_BIT == 128] = {0}; int main() { -#if __LP64__ && __LDBL_MANT_DIG__ == 113 // NaN if (test__letf2(makeQNaN128(), 0x1.234567890abcdef1234567890abcp+3L, @@ -71,9 +71,6 @@ GREATER_0)) return 1; -#else - printf("skipped\n"); - -#endif return 0; } +#endif diff --git a/compiler-rt/test/builtins/Unit/lttf2_test.c b/compiler-rt/test/builtins/Unit/lttf2_test.c --- a/compiler-rt/test/builtins/Unit/lttf2_test.c +++ b/compiler-rt/test/builtins/Unit/lttf2_test.c @@ -3,15 +3,18 @@ #include -#if __LP64__ && __LDBL_MANT_DIG__ == 113 - #include "fp_test.h" +#if !defined(CRT_HAS_F128) +int main() { + fprintf(stderr, "Missing f128 support - skipping.\n"); + return 1; +} +#else +long __lttf2(f128 a, f128 b); -int __lttf2(long double a, long double b); - -int test__lttf2(long double a, long double b, enum EXPECTED_RESULT expected) +int test__lttf2(f128 a, f128 b, enum EXPECTED_RESULT expected) { - int x = __lttf2(a, b); + long x = __lttf2(a, b); int ret = compareResultCMP(x, expected); if (ret){ @@ -21,13 +24,10 @@ return ret; } -char assumption_1[sizeof(long double) * CHAR_BIT == 128] = {0}; - -#endif +char assumption_1[sizeof(f128) * CHAR_BIT == 128] = {0}; int main() { -#if __LP64__ && __LDBL_MANT_DIG__ == 113 // NaN if (test__lttf2(makeQNaN128(), 0x1.234567890abcdef1234567890abcp+3L, @@ -71,9 +71,6 @@ GREATER_EQUAL_0)) return 1; -#else - printf("skipped\n"); - -#endif return 0; } +#endif diff --git a/compiler-rt/test/builtins/Unit/multc3_test.c b/compiler-rt/test/builtins/Unit/multc3_test.c --- a/compiler-rt/test/builtins/Unit/multc3_test.c +++ b/compiler-rt/test/builtins/Unit/multc3_test.c @@ -3,363 +3,362 @@ #include -#if _ARCH_PPC || __aarch64__ - #include "int_lib.h" -#include +#include "int_math.h" +#include "fp_test.h" #include +#include +#if !defined(CRT_HAS_F128) +int main() { + fprintf(stderr, "Missing f128 support - skipping.\n"); + return 1; +} +#else // Returns: the product of a + ib and c + id +COMPILER_RT_ABI Qcomplex +__multc3(f128 __a, f128 __b, f128 __c, f128 __d); -COMPILER_RT_ABI long double _Complex -__multc3(long double __a, long double __b, long double __c, long double __d); +enum { zero, + non_zero, + inf, + NaN, + non_zero_nan }; -enum {zero, non_zero, inf, NaN, non_zero_nan}; +int classify(Qcomplex x) { + f128 real = COMPLEX128_REAL(x); + f128 imag = COMPLEX128_IMAGINARY(x); + if (real == 0.0 && imag == 0.0) + return zero; + if (crt_isinf(real) || crt_isinf(imag)) + return inf; + if (crt_isnan(real) && crt_isnan(imag)) + return NaN; + if (crt_isnan(real)) { + if (imag == 0.0) + return NaN; + return non_zero_nan; + } + if (crt_isnan(imag)) { + if (real == 0.0) + return NaN; + return non_zero_nan; + } + return non_zero; +} -int -classify(long double _Complex x) -{ - if (x == 0) - return zero; - if (isinf(creall(x)) || isinf(cimagl(x))) - return inf; - if (isnan(creall(x)) && isnan(cimagl(x))) - return NaN; - if (isnan(creall(x))) - { - if (cimagl(x) == 0) - return NaN; - return non_zero_nan; +static int test__multc3(f128 a, f128 b, f128 c, f128 d) { + Qcomplex r = __multc3(a, b, c, d); + // printf("test__multc3(%Lf, %Lf, %Lf, %Lf) = %Lf + I%Lf\n", + // a, b, c, d, creall(r), cimagl(r)); + Qcomplex dividend; + Qcomplex divisor; + + COMPLEX128_REAL(dividend) = a; + COMPLEX128_IMAGINARY(dividend) = b; + COMPLEX128_REAL(divisor) = c; + COMPLEX128_IMAGINARY(divisor) = d; + + switch (classify(dividend)) { + case zero: + switch (classify(divisor)) { + case zero: + if (classify(r) != zero) + return 1; + break; + case non_zero: + if (classify(r) != zero) + return 1; + break; + case inf: + if (classify(r) != NaN) + return 1; + break; + case NaN: + if (classify(r) != NaN) + return 1; + break; + case non_zero_nan: + if (classify(r) != NaN) + return 1; + break; } - if (isnan(cimagl(x))) - { - if (creall(x) == 0) - return NaN; - return non_zero_nan; + break; + case non_zero: + switch (classify(divisor)) { + case zero: + if (classify(r) != zero) + return 1; + break; + case non_zero: + if (classify(r) != non_zero) + return 1; + if ((COMPLEX128_REAL(r) != a * c - b * d) || + (COMPLEX128_IMAGINARY(r) != a * d + b * c)) + return 1; + break; + case inf: + if (classify(r) != inf) + return 1; + break; + case NaN: + if (classify(r) != NaN) + return 1; + break; + case non_zero_nan: + if (classify(r) != NaN) + return 1; + break; } - return non_zero; -} - -int test__multc3(long double a, long double b, long double c, long double d) -{ - long double _Complex r = __multc3(a, b, c, d); -// printf("test__multc3(%Lf, %Lf, %Lf, %Lf) = %Lf + I%Lf\n", -// a, b, c, d, creall(r), cimagl(r)); - long double _Complex dividend; - long double _Complex divisor; - - __real__ dividend = a; - __imag__ dividend = b; - __real__ divisor = c; - __imag__ divisor = d; - - switch (classify(dividend)) - { + break; + case inf: + switch (classify(divisor)) { + case zero: + if (classify(r) != NaN) + return 1; + break; + case non_zero: + if (classify(r) != inf) + return 1; + break; + case inf: + if (classify(r) != inf) + return 1; + break; + case NaN: + if (classify(r) != NaN) + return 1; + break; + case non_zero_nan: + if (classify(r) != inf) + return 1; + break; + } + break; + case NaN: + switch (classify(divisor)) { + case zero: + if (classify(r) != NaN) + return 1; + break; + case non_zero: + if (classify(r) != NaN) + return 1; + break; + case inf: + if (classify(r) != NaN) + return 1; + break; + case NaN: + if (classify(r) != NaN) + return 1; + break; + case non_zero_nan: + if (classify(r) != NaN) + return 1; + break; + } + break; + case non_zero_nan: + switch (classify(divisor)) { case zero: - switch (classify(divisor)) - { - case zero: - if (classify(r) != zero) - return 1; - break; - case non_zero: - if (classify(r) != zero) - return 1; - break; - case inf: - if (classify(r) != NaN) - return 1; - break; - case NaN: - if (classify(r) != NaN) - return 1; - break; - case non_zero_nan: - if (classify(r) != NaN) - return 1; - break; - } - break; + if (classify(r) != NaN) + return 1; + break; case non_zero: - switch (classify(divisor)) - { - case zero: - if (classify(r) != zero) - return 1; - break; - case non_zero: - if (classify(r) != non_zero) - return 1; - if (r != a * c - b * d + _Complex_I*(a * d + b * c)) - return 1; - break; - case inf: - if (classify(r) != inf) - return 1; - break; - case NaN: - if (classify(r) != NaN) - return 1; - break; - case non_zero_nan: - if (classify(r) != NaN) - return 1; - break; - } - break; + if (classify(r) != NaN) + return 1; + break; case inf: - switch (classify(divisor)) - { - case zero: - if (classify(r) != NaN) - return 1; - break; - case non_zero: - if (classify(r) != inf) - return 1; - break; - case inf: - if (classify(r) != inf) - return 1; - break; - case NaN: - if (classify(r) != NaN) - return 1; - break; - case non_zero_nan: - if (classify(r) != inf) - return 1; - break; - } - break; + if (classify(r) != inf) + return 1; + break; case NaN: - switch (classify(divisor)) - { - case zero: - if (classify(r) != NaN) - return 1; - break; - case non_zero: - if (classify(r) != NaN) - return 1; - break; - case inf: - if (classify(r) != NaN) - return 1; - break; - case NaN: - if (classify(r) != NaN) - return 1; - break; - case non_zero_nan: - if (classify(r) != NaN) - return 1; - break; - } - break; + if (classify(r) != NaN) + return 1; + break; case non_zero_nan: - switch (classify(divisor)) - { - case zero: - if (classify(r) != NaN) - return 1; - break; - case non_zero: - if (classify(r) != NaN) - return 1; - break; - case inf: - if (classify(r) != inf) - return 1; - break; - case NaN: - if (classify(r) != NaN) - return 1; - break; - case non_zero_nan: - if (classify(r) != NaN) - return 1; - break; - } - break; + if (classify(r) != NaN) + return 1; + break; } - - return 0; + break; + } + + return 0; } -long double x[][2] = -{ - { 1.e-6, 1.e-6}, - {-1.e-6, 1.e-6}, - {-1.e-6, -1.e-6}, - { 1.e-6, -1.e-6}, +static f128 x[][2] = + { + {1.e-6, 1.e-6}, + {-1.e-6, 1.e-6}, + {-1.e-6, -1.e-6}, + {1.e-6, -1.e-6}, - { 1.e+6, 1.e-6}, - {-1.e+6, 1.e-6}, - {-1.e+6, -1.e-6}, - { 1.e+6, -1.e-6}, + {1.e+6, 1.e-6}, + {-1.e+6, 1.e-6}, + {-1.e+6, -1.e-6}, + {1.e+6, -1.e-6}, - { 1.e-6, 1.e+6}, - {-1.e-6, 1.e+6}, - {-1.e-6, -1.e+6}, - { 1.e-6, -1.e+6}, + {1.e-6, 1.e+6}, + {-1.e-6, 1.e+6}, + {-1.e-6, -1.e+6}, + {1.e-6, -1.e+6}, - { 1.e+6, 1.e+6}, - {-1.e+6, 1.e+6}, - {-1.e+6, -1.e+6}, - { 1.e+6, -1.e+6}, + {1.e+6, 1.e+6}, + {-1.e+6, 1.e+6}, + {-1.e+6, -1.e+6}, + {1.e+6, -1.e+6}, - {NAN, NAN}, - {-INFINITY, NAN}, - {-2, NAN}, - {-1, NAN}, - {-0.5, NAN}, - {-0., NAN}, - {+0., NAN}, - {0.5, NAN}, - {1, NAN}, - {2, NAN}, - {INFINITY, NAN}, + {NAN, NAN}, + {-INFINITY, NAN}, + {-2, NAN}, + {-1, NAN}, + {-0.5, NAN}, + {-0., NAN}, + {+0., NAN}, + {0.5, NAN}, + {1, NAN}, + {2, NAN}, + {INFINITY, NAN}, - {NAN, -INFINITY}, - {-INFINITY, -INFINITY}, - {-2, -INFINITY}, - {-1, -INFINITY}, - {-0.5, -INFINITY}, - {-0., -INFINITY}, - {+0., -INFINITY}, - {0.5, -INFINITY}, - {1, -INFINITY}, - {2, -INFINITY}, - {INFINITY, -INFINITY}, + {NAN, -INFINITY}, + {-INFINITY, -INFINITY}, + {-2, -INFINITY}, + {-1, -INFINITY}, + {-0.5, -INFINITY}, + {-0., -INFINITY}, + {+0., -INFINITY}, + {0.5, -INFINITY}, + {1, -INFINITY}, + {2, -INFINITY}, + {INFINITY, -INFINITY}, - {NAN, -2}, - {-INFINITY, -2}, - {-2, -2}, - {-1, -2}, - {-0.5, -2}, - {-0., -2}, - {+0., -2}, - {0.5, -2}, - {1, -2}, - {2, -2}, - {INFINITY, -2}, + {NAN, -2}, + {-INFINITY, -2}, + {-2, -2}, + {-1, -2}, + {-0.5, -2}, + {-0., -2}, + {+0., -2}, + {0.5, -2}, + {1, -2}, + {2, -2}, + {INFINITY, -2}, - {NAN, -1}, - {-INFINITY, -1}, - {-2, -1}, - {-1, -1}, - {-0.5, -1}, - {-0., -1}, - {+0., -1}, - {0.5, -1}, - {1, -1}, - {2, -1}, - {INFINITY, -1}, + {NAN, -1}, + {-INFINITY, -1}, + {-2, -1}, + {-1, -1}, + {-0.5, -1}, + {-0., -1}, + {+0., -1}, + {0.5, -1}, + {1, -1}, + {2, -1}, + {INFINITY, -1}, - {NAN, -0.5}, - {-INFINITY, -0.5}, - {-2, -0.5}, - {-1, -0.5}, - {-0.5, -0.5}, - {-0., -0.5}, - {+0., -0.5}, - {0.5, -0.5}, - {1, -0.5}, - {2, -0.5}, - {INFINITY, -0.5}, + {NAN, -0.5}, + {-INFINITY, -0.5}, + {-2, -0.5}, + {-1, -0.5}, + {-0.5, -0.5}, + {-0., -0.5}, + {+0., -0.5}, + {0.5, -0.5}, + {1, -0.5}, + {2, -0.5}, + {INFINITY, -0.5}, - {NAN, -0.}, - {-INFINITY, -0.}, - {-2, -0.}, - {-1, -0.}, - {-0.5, -0.}, - {-0., -0.}, - {+0., -0.}, - {0.5, -0.}, - {1, -0.}, - {2, -0.}, - {INFINITY, -0.}, + {NAN, -0.}, + {-INFINITY, -0.}, + {-2, -0.}, + {-1, -0.}, + {-0.5, -0.}, + {-0., -0.}, + {+0., -0.}, + {0.5, -0.}, + {1, -0.}, + {2, -0.}, + {INFINITY, -0.}, - {NAN, 0.}, - {-INFINITY, 0.}, - {-2, 0.}, - {-1, 0.}, - {-0.5, 0.}, - {-0., 0.}, - {+0., 0.}, - {0.5, 0.}, - {1, 0.}, - {2, 0.}, - {INFINITY, 0.}, + {NAN, 0.}, + {-INFINITY, 0.}, + {-2, 0.}, + {-1, 0.}, + {-0.5, 0.}, + {-0., 0.}, + {+0., 0.}, + {0.5, 0.}, + {1, 0.}, + {2, 0.}, + {INFINITY, 0.}, - {NAN, 0.5}, - {-INFINITY, 0.5}, - {-2, 0.5}, - {-1, 0.5}, - {-0.5, 0.5}, - {-0., 0.5}, - {+0., 0.5}, - {0.5, 0.5}, - {1, 0.5}, - {2, 0.5}, - {INFINITY, 0.5}, + {NAN, 0.5}, + {-INFINITY, 0.5}, + {-2, 0.5}, + {-1, 0.5}, + {-0.5, 0.5}, + {-0., 0.5}, + {+0., 0.5}, + {0.5, 0.5}, + {1, 0.5}, + {2, 0.5}, + {INFINITY, 0.5}, - {NAN, 1}, - {-INFINITY, 1}, - {-2, 1}, - {-1, 1}, - {-0.5, 1}, - {-0., 1}, - {+0., 1}, - {0.5, 1}, - {1, 1}, - {2, 1}, - {INFINITY, 1}, + {NAN, 1}, + {-INFINITY, 1}, + {-2, 1}, + {-1, 1}, + {-0.5, 1}, + {-0., 1}, + {+0., 1}, + {0.5, 1}, + {1, 1}, + {2, 1}, + {INFINITY, 1}, - {NAN, 2}, - {-INFINITY, 2}, - {-2, 2}, - {-1, 2}, - {-0.5, 2}, - {-0., 2}, - {+0., 2}, - {0.5, 2}, - {1, 2}, - {2, 2}, - {INFINITY, 2}, + {NAN, 2}, + {-INFINITY, 2}, + {-2, 2}, + {-1, 2}, + {-0.5, 2}, + {-0., 2}, + {+0., 2}, + {0.5, 2}, + {1, 2}, + {2, 2}, + {INFINITY, 2}, - {NAN, INFINITY}, - {-INFINITY, INFINITY}, - {-2, INFINITY}, - {-1, INFINITY}, - {-0.5, INFINITY}, - {-0., INFINITY}, - {+0., INFINITY}, - {0.5, INFINITY}, - {1, INFINITY}, - {2, INFINITY}, - {INFINITY, INFINITY} + {NAN, INFINITY}, + {-INFINITY, INFINITY}, + {-2, INFINITY}, + {-1, INFINITY}, + {-0.5, INFINITY}, + {-0., INFINITY}, + {+0., INFINITY}, + {0.5, INFINITY}, + {1, INFINITY}, + {2, INFINITY}, + {INFINITY, INFINITY} }; -#endif - -int main() -{ -#if _ARCH_PPC || __aarch64__ - const unsigned N = sizeof(x) / sizeof(x[0]); - unsigned i, j; - for (i = 0; i < N; ++i) - { - for (j = 0; j < N; ++j) - { - if (test__multc3(x[i][0], x[i][1], x[j][0], x[j][1])) - return 1; - } +int main() { + const unsigned N = sizeof(x) / sizeof(x[0]); + unsigned i, j; + for (i = 0; i < N; ++i) { + for (j = 0; j < N; ++j) { + if (test__multc3(x[i][0], x[i][1], x[j][0], x[j][1])) { + fprintf(stderr, "Failed for %g, %g, %g, %g\n", + (double)x[i][0], (double)x[i][1], + (double)x[j][0], (double)x[j][1]); + return 1; + } } -#else - printf("skipped\n"); -#endif - return 0; + } + + fprintf(stderr, "No errors found.\n"); + return 0; } +#endif diff --git a/compiler-rt/test/builtins/Unit/multf3_test.c b/compiler-rt/test/builtins/Unit/multf3_test.c --- a/compiler-rt/test/builtins/Unit/multf3_test.c +++ b/compiler-rt/test/builtins/Unit/multf3_test.c @@ -3,84 +3,81 @@ #include -#if __LDBL_MANT_DIG__ == 113 - #include "int_lib.h" #include "fp_test.h" +#if !defined(CRT_HAS_F128) +int main() { + fprintf(stderr, "Missing f128 support - skipping.\n"); + return 1; +} +#else + // Returns: a * b -COMPILER_RT_ABI long double __multf3(long double a, long double b); +COMPILER_RT_ABI f128 __multf3(f128 a, f128 b); -int test__multf3(long double a, long double b, - uint64_t expectedHi, uint64_t expectedLo) -{ - long double x = __multf3(a, b); - int ret = compareResultLD(x, expectedHi, expectedLo); +int _test__multf3(int line, f128 a, f128 b, + uint64_t expectedHi, uint64_t expectedLo) { + f128 x = __multf3(a, b); + int ret = compareResultF128(x, expectedHi, expectedLo); - if (ret){ - printf("error in test__multf3(%.20Lf, %.20Lf) = %.20Lf, " - "expected %.20Lf\n", a, b, x, - fromRep128(expectedHi, expectedLo)); - } - return ret; + if (ret) { + printMismatchF128TwoArg(__FILE__, line, "__multf3", a, b, x, + expectedHi, expectedLo); + } + return ret; } - -char assumption_1[sizeof(long double) * CHAR_BIT == 128] = {0}; - -#endif +#define test__multf3(...) _test__multf3(__LINE__, __VA_ARGS__) int main() { -#if __LDBL_MANT_DIG__ == 113 // qNaN * any = qNaN if (test__multf3(makeQNaN128(), - 0x1.23456789abcdefp+5L, + 0x1.23456789abcdefp+5Q, UINT64_C(0x7fff800000000000), UINT64_C(0x0))) return 1; // NaN * any = NaN if (test__multf3(makeNaN128(UINT64_C(0x800030000000)), - 0x1.23456789abcdefp+5L, + 0x1.23456789abcdefp+5Q, UINT64_C(0x7fff800000000000), UINT64_C(0x0))) return 1; // inf * any = inf if (test__multf3(makeInf128(), - 0x1.23456789abcdefp+5L, + 0x1.23456789abcdefp+5Q, UINT64_C(0x7fff000000000000), UINT64_C(0x0))) return 1; // any * any - if (test__multf3(0x1.2eab345678439abcdefea56782346p+5L, - 0x1.edcb34a235253948765432134674fp-1L, + if (test__multf3(0x1.2eab345678439abcdefea56782346p+5Q, + 0x1.edcb34a235253948765432134674fp-1Q, UINT64_C(0x400423e7f9e3c9fc), UINT64_C(0xd906c2c2a85777c4))) return 1; - if (test__multf3(0x1.353e45674d89abacc3a2ebf3ff4ffp-50L, - 0x1.ed8764648369535adf4be3214567fp-9L, + if (test__multf3(0x1.353e45674d89abacc3a2ebf3ff4ffp-50Q, + 0x1.ed8764648369535adf4be3214567fp-9Q, UINT64_C(0x3fc52a163c6223fc), UINT64_C(0xc94c4bf0430768b4))) return 1; - if (test__multf3(0x1.234425696abcad34a35eeffefdcbap+456L, - 0x451.ed98d76e5d46e5f24323dff21ffp+600L, + if (test__multf3(0x1.234425696abcad34a35eeffefdcbap+456Q, + 0x451.ed98d76e5d46e5f24323dff21ffp+600Q, UINT64_C(0x44293a91de5e0e94), UINT64_C(0xe8ed17cc2cdf64ac))) return 1; - if (test__multf3(0x1.4356473c82a9fabf2d22ace345defp-234L, - 0x1.eda98765476743ab21da23d45678fp-455L, + if (test__multf3(0x1.4356473c82a9fabf2d22ace345defp-234Q, + 0x1.eda98765476743ab21da23d45678fp-455Q, UINT64_C(0x3d4f37c1a3137cae), UINT64_C(0xfc6807048bc2836a))) return 1; // underflow - if (test__multf3(0x1.23456734245345p-10000L, - 0x1.edcba524498724p-6497L, + if (test__multf3(0x1.23456734245345p-10000Q, + 0x1.edcba524498724p-6497Q, UINT64_C(0x0), UINT64_C(0x0))) return 1; -#else - printf("skipped\n"); - -#endif return 0; } + +#endif diff --git a/compiler-rt/test/builtins/Unit/netf2_test.c b/compiler-rt/test/builtins/Unit/netf2_test.c --- a/compiler-rt/test/builtins/Unit/netf2_test.c +++ b/compiler-rt/test/builtins/Unit/netf2_test.c @@ -3,15 +3,18 @@ #include -#if __LP64__ && __LDBL_MANT_DIG__ == 113 - #include "fp_test.h" +#if !defined(CRT_HAS_F128) +int main() { + fprintf(stderr, "Missing f128 support - skipping.\n"); + return 1; +} +#else +long __netf2(f128 a, f128 b); -int __netf2(long double a, long double b); - -int test__netf2(long double a, long double b, enum EXPECTED_RESULT expected) +int test__netf2(f128 a, f128 b, enum EXPECTED_RESULT expected) { - int x = __netf2(a, b); + long x = __netf2(a, b); int ret = compareResultCMP(x, expected); if (ret){ @@ -21,13 +24,10 @@ return ret; } -char assumption_1[sizeof(long double) * CHAR_BIT == 128] = {0}; - -#endif +char assumption_1[sizeof(f128) * CHAR_BIT == 128] = {0}; int main() { -#if __LP64__ && __LDBL_MANT_DIG__ == 113 // NaN if (test__netf2(makeQNaN128(), 0x1.234567890abcdef1234567890abcp+3L, @@ -71,9 +71,6 @@ NEQUAL_0)) return 1; -#else - printf("skipped\n"); - -#endif return 0; } +#endif diff --git a/compiler-rt/test/builtins/Unit/powitf2_test.c b/compiler-rt/test/builtins/Unit/powitf2_test.c --- a/compiler-rt/test/builtins/Unit/powitf2_test.c +++ b/compiler-rt/test/builtins/Unit/powitf2_test.c @@ -3,221 +3,223 @@ #include -#if __LDBL_MANT_DIG__ == 113 - #include "int_lib.h" #include // Returns: a ^ b -COMPILER_RT_ABI long double __powitf2(long double a, int b); - -int test__powitf2(long double a, int b, long double expected) -{ - long double x = __powitf2(a, b); - int correct = (x == expected) && (signbit(x) == signbit(expected)); - if (!correct) - printf("error in __powitf2(%Lf, %d) = %Lf, expected %Lf\n", - a, b, x, expected); - return !correct; +#include "fp_test.h" +#if !defined(CRT_HAS_F128) +int main() { + fprintf(stderr, "Missing f128 support - skipping.\n"); + return 1; } - -#endif - -int main() -{ -#if __LDBL_MANT_DIG__ == 113 - if (test__powitf2(0, 0, 1)) - return 1; - if (test__powitf2(1, 0, 1)) - return 1; - if (test__powitf2(1.5, 0, 1)) - return 1; - if (test__powitf2(2, 0, 1)) - return 1; - if (test__powitf2(INFINITY, 0, 1)) - return 1; - - if (test__powitf2(-0., 0, 1)) - return 1; - if (test__powitf2(-1, 0, 1)) - return 1; - if (test__powitf2(-1.5, 0, 1)) - return 1; - if (test__powitf2(-2, 0, 1)) - return 1; - if (test__powitf2(-INFINITY, 0, 1)) - return 1; - - if (test__powitf2(0, 1, 0)) - return 1; - if (test__powitf2(0, 2, 0)) - return 1; - if (test__powitf2(0, 3, 0)) - return 1; - if (test__powitf2(0, 4, 0)) - return 1; - if (test__powitf2(0, INT_MAX - 1, 0)) - return 1; - if (test__powitf2(0, INT_MAX, 0)) - return 1; - - if (test__powitf2(-0., 1, -0.)) - return 1; - if (test__powitf2(-0., 2, 0)) - return 1; - if (test__powitf2(-0., 3, -0.)) - return 1; - if (test__powitf2(-0., 4, 0)) - return 1; - if (test__powitf2(-0., INT_MAX - 1, 0)) - return 1; - if (test__powitf2(-0., INT_MAX, -0.)) - return 1; - - if (test__powitf2(1, 1, 1)) - return 1; - if (test__powitf2(1, 2, 1)) - return 1; - if (test__powitf2(1, 3, 1)) - return 1; - if (test__powitf2(1, 4, 1)) - return 1; - if (test__powitf2(1, INT_MAX - 1, 1)) - return 1; - if (test__powitf2(1, INT_MAX, 1)) - return 1; - - if (test__powitf2(INFINITY, 1, INFINITY)) - return 1; - if (test__powitf2(INFINITY, 2, INFINITY)) - return 1; - if (test__powitf2(INFINITY, 3, INFINITY)) - return 1; - if (test__powitf2(INFINITY, 4, INFINITY)) - return 1; - if (test__powitf2(INFINITY, INT_MAX - 1, INFINITY)) - return 1; - if (test__powitf2(INFINITY, INT_MAX, INFINITY)) - return 1; - - if (test__powitf2(-INFINITY, 1, -INFINITY)) - return 1; - if (test__powitf2(-INFINITY, 2, INFINITY)) - return 1; - if (test__powitf2(-INFINITY, 3, -INFINITY)) - return 1; - if (test__powitf2(-INFINITY, 4, INFINITY)) - return 1; - if (test__powitf2(-INFINITY, INT_MAX - 1, INFINITY)) - return 1; - if (test__powitf2(-INFINITY, INT_MAX, -INFINITY)) - return 1; - - if (test__powitf2(0, -1, INFINITY)) - return 1; - if (test__powitf2(0, -2, INFINITY)) - return 1; - if (test__powitf2(0, -3, INFINITY)) - return 1; - if (test__powitf2(0, -4, INFINITY)) - return 1; - if (test__powitf2(0, INT_MIN + 2, INFINITY)) - return 1; - if (test__powitf2(0, INT_MIN + 1, INFINITY)) - return 1; - if (test__powitf2(0, INT_MIN, INFINITY)) - return 1; - - if (test__powitf2(-0., -1, -INFINITY)) - return 1; - if (test__powitf2(-0., -2, INFINITY)) - return 1; - if (test__powitf2(-0., -3, -INFINITY)) - return 1; - if (test__powitf2(-0., -4, INFINITY)) - return 1; - if (test__powitf2(-0., INT_MIN + 2, INFINITY)) - return 1; - if (test__powitf2(-0., INT_MIN + 1, -INFINITY)) - return 1; - if (test__powitf2(-0., INT_MIN, INFINITY)) - return 1; - - if (test__powitf2(1, -1, 1)) - return 1; - if (test__powitf2(1, -2, 1)) - return 1; - if (test__powitf2(1, -3, 1)) - return 1; - if (test__powitf2(1, -4, 1)) - return 1; - if (test__powitf2(1, INT_MIN + 2, 1)) - return 1; - if (test__powitf2(1, INT_MIN + 1, 1)) - return 1; - if (test__powitf2(1, INT_MIN, 1)) - return 1; - - if (test__powitf2(INFINITY, -1, 0)) - return 1; - if (test__powitf2(INFINITY, -2, 0)) - return 1; - if (test__powitf2(INFINITY, -3, 0)) - return 1; - if (test__powitf2(INFINITY, -4, 0)) - return 1; - if (test__powitf2(INFINITY, INT_MIN + 2, 0)) - return 1; - if (test__powitf2(INFINITY, INT_MIN + 1, 0)) - return 1; - if (test__powitf2(INFINITY, INT_MIN, 0)) - return 1; - - if (test__powitf2(-INFINITY, -1, -0.)) - return 1; - if (test__powitf2(-INFINITY, -2, 0)) - return 1; - if (test__powitf2(-INFINITY, -3, -0.)) - return 1; - if (test__powitf2(-INFINITY, -4, 0)) - return 1; - if (test__powitf2(-INFINITY, INT_MIN + 2, 0)) - return 1; - if (test__powitf2(-INFINITY, INT_MIN + 1, -0.)) - return 1; - if (test__powitf2(-INFINITY, INT_MIN, 0)) - return 1; - - if (test__powitf2(2, 10, 1024.)) - return 1; - if (test__powitf2(-2, 10, 1024.)) - return 1; - if (test__powitf2(2, -10, 1/1024.)) - return 1; - if (test__powitf2(-2, -10, 1/1024.)) - return 1; - - if (test__powitf2(2, 19, 524288.)) - return 1; - if (test__powitf2(-2, 19, -524288.)) - return 1; - if (test__powitf2(2, -19, 1/524288.)) - return 1; - if (test__powitf2(-2, -19, -1/524288.)) - return 1; - - if (test__powitf2(2, 31, 2147483648.)) - return 1; - if (test__powitf2(-2, 31, -2147483648.)) - return 1; - if (test__powitf2(2, -31, 1/2147483648.)) - return 1; - if (test__powitf2(-2, -31, -1/2147483648.)) - return 1; - #else - printf("skipped\n"); -#endif - return 0; +COMPILER_RT_ABI f128 __powitf2(f128 a, int b); + +int _test__powitf2(int line, f128 a, int b, f128 expected) { + f128 x = __powitf2(a, b); + // Note: We use __builtin_signbit() here to avoid a potential long double conversion. + int correct = (x == expected) && (__builtin_signbit(x) == __builtin_signbit(expected)); + if (!correct) { + printMismatchF128TwoArg(__FILE__, line, "__powitf2", a, b, x, + toRep128(expected) >> 64, (uint64_t)toRep128(expected)); + } + return !correct; } + +#define test__powitf2(...) _test__powitf2(__LINE__, __VA_ARGS__) + +int main() { + if (test__powitf2(0, 0, 1)) + return 1; + if (test__powitf2(1, 0, 1)) + return 1; + if (test__powitf2(1.5, 0, 1)) + return 1; + if (test__powitf2(2, 0, 1)) + return 1; + if (test__powitf2(INFINITY, 0, 1)) + return 1; + + if (test__powitf2(-0., 0, 1)) + return 1; + if (test__powitf2(-1, 0, 1)) + return 1; + if (test__powitf2(-1.5, 0, 1)) + return 1; + if (test__powitf2(-2, 0, 1)) + return 1; + if (test__powitf2(-INFINITY, 0, 1)) + return 1; + + if (test__powitf2(0, 1, 0)) + return 1; + if (test__powitf2(0, 2, 0)) + return 1; + if (test__powitf2(0, 3, 0)) + return 1; + if (test__powitf2(0, 4, 0)) + return 1; + if (test__powitf2(0, INT_MAX - 1, 0)) + return 1; + if (test__powitf2(0, INT_MAX, 0)) + return 1; + + if (test__powitf2(-0., 1, -0.)) + return 1; + if (test__powitf2(-0., 2, 0)) + return 1; + if (test__powitf2(-0., 3, -0.)) + return 1; + if (test__powitf2(-0., 4, 0)) + return 1; + if (test__powitf2(-0., INT_MAX - 1, 0)) + return 1; + if (test__powitf2(-0., INT_MAX, -0.)) + return 1; + + if (test__powitf2(1, 1, 1)) + return 1; + if (test__powitf2(1, 2, 1)) + return 1; + if (test__powitf2(1, 3, 1)) + return 1; + if (test__powitf2(1, 4, 1)) + return 1; + if (test__powitf2(1, INT_MAX - 1, 1)) + return 1; + if (test__powitf2(1, INT_MAX, 1)) + return 1; + + if (test__powitf2(INFINITY, 1, INFINITY)) + return 1; + if (test__powitf2(INFINITY, 2, INFINITY)) + return 1; + if (test__powitf2(INFINITY, 3, INFINITY)) + return 1; + if (test__powitf2(INFINITY, 4, INFINITY)) + return 1; + if (test__powitf2(INFINITY, INT_MAX - 1, INFINITY)) + return 1; + if (test__powitf2(INFINITY, INT_MAX, INFINITY)) + return 1; + + if (test__powitf2(-INFINITY, 1, -INFINITY)) + return 1; + if (test__powitf2(-INFINITY, 2, INFINITY)) + return 1; + if (test__powitf2(-INFINITY, 3, -INFINITY)) + return 1; + if (test__powitf2(-INFINITY, 4, INFINITY)) + return 1; + if (test__powitf2(-INFINITY, INT_MAX - 1, INFINITY)) + return 1; + if (test__powitf2(-INFINITY, INT_MAX, -INFINITY)) + return 1; + + if (test__powitf2(0, -1, INFINITY)) + return 1; + if (test__powitf2(0, -2, INFINITY)) + return 1; + if (test__powitf2(0, -3, INFINITY)) + return 1; + if (test__powitf2(0, -4, INFINITY)) + return 1; + if (test__powitf2(0, INT_MIN + 2, INFINITY)) + return 1; + if (test__powitf2(0, INT_MIN + 1, INFINITY)) + return 1; + if (test__powitf2(0, INT_MIN, INFINITY)) + return 1; + + if (test__powitf2(-0., -1, -INFINITY)) + return 1; + if (test__powitf2(-0., -2, INFINITY)) + return 1; + if (test__powitf2(-0., -3, -INFINITY)) + return 1; + if (test__powitf2(-0., -4, INFINITY)) + return 1; + if (test__powitf2(-0., INT_MIN + 2, INFINITY)) + return 1; + if (test__powitf2(-0., INT_MIN + 1, -INFINITY)) + return 1; + if (test__powitf2(-0., INT_MIN, INFINITY)) + return 1; + + if (test__powitf2(1, -1, 1)) + return 1; + if (test__powitf2(1, -2, 1)) + return 1; + if (test__powitf2(1, -3, 1)) + return 1; + if (test__powitf2(1, -4, 1)) + return 1; + if (test__powitf2(1, INT_MIN + 2, 1)) + return 1; + if (test__powitf2(1, INT_MIN + 1, 1)) + return 1; + if (test__powitf2(1, INT_MIN, 1)) + return 1; + + if (test__powitf2(INFINITY, -1, 0)) + return 1; + if (test__powitf2(INFINITY, -2, 0)) + return 1; + if (test__powitf2(INFINITY, -3, 0)) + return 1; + if (test__powitf2(INFINITY, -4, 0)) + return 1; + if (test__powitf2(INFINITY, INT_MIN + 2, 0)) + return 1; + if (test__powitf2(INFINITY, INT_MIN + 1, 0)) + return 1; + if (test__powitf2(INFINITY, INT_MIN, 0)) + return 1; + + if (test__powitf2(-INFINITY, -1, -0.)) + return 1; + if (test__powitf2(-INFINITY, -2, 0)) + return 1; + if (test__powitf2(-INFINITY, -3, -0.)) + return 1; + if (test__powitf2(-INFINITY, -4, 0)) + return 1; + if (test__powitf2(-INFINITY, INT_MIN + 2, 0)) + return 1; + if (test__powitf2(-INFINITY, INT_MIN + 1, -0.)) + return 1; + if (test__powitf2(-INFINITY, INT_MIN, 0)) + return 1; + + if (test__powitf2(2, 10, 1024.Q)) + return 1; + if (test__powitf2(-2, 10, 1024.Q)) + return 1; + if (test__powitf2(2, -10, 1 / 1024.Q)) + return 1; + if (test__powitf2(-2, -10, 1 / 1024.Q)) + return 1; + + if (test__powitf2(2, 19, 524288.)) + return 1; + if (test__powitf2(-2, 19, -524288.)) + return 1; + if (test__powitf2(2, -19, 1 / 524288.Q)) + return 1; + if (test__powitf2(-2, -19, -1 / 524288.Q)) + return 1; + + if (test__powitf2(2, 31, 2147483648.Q)) + return 1; + if (test__powitf2(-2, 31, -2147483648.Q)) + return 1; + if (test__powitf2(2, -31, 1 / 2147483648.Q)) + return 1; + if (test__powitf2(-2, -31, -1 / 2147483648.Q)) + return 1; + + return 0; +} +#endif diff --git a/compiler-rt/test/builtins/Unit/subtf3_test.c b/compiler-rt/test/builtins/Unit/subtf3_test.c --- a/compiler-rt/test/builtins/Unit/subtf3_test.c +++ b/compiler-rt/test/builtins/Unit/subtf3_test.c @@ -4,93 +4,88 @@ #include #include -#if __LDBL_MANT_DIG__ == 113 - #include "int_lib.h" #include "fp_test.h" -// Returns: a - b -COMPILER_RT_ABI long double __subtf3(long double a, long double b); - -int test__subtf3(long double a, long double b, - uint64_t expectedHi, uint64_t expectedLo) -{ - long double x = __subtf3(a, b); - int ret = compareResultLD(x, expectedHi, expectedLo); - - if (ret){ - printf("error in test__subtf3(%.20Lf, %.20Lf) = %.20Lf, " - "expected %.20Lf\n", a, b, x, - fromRep128(expectedHi, expectedLo)); - } - return ret; +#if !defined(CRT_HAS_F128) +int main() { + fprintf(stderr, "Missing f128 support - skipping.\n"); + return 1; } +#else -char assumption_1[sizeof(long double) * CHAR_BIT == 128] = {0}; - -#endif +// Returns: a - b +COMPILER_RT_ABI f128 __subtf3(f128 a, f128 b); + +int _test__subtf3(int line, f128 a, f128 b, + uint64_t expectedHi, uint64_t expectedLo) { + f128 x = __subtf3(a, b); + int ret = compareResultF128(x, expectedHi, expectedLo); + if (ret) { + printMismatchF128TwoArg(__FILE__, line, "__subtf3", a, b, x, + expectedHi, expectedLo); + } + return ret; +} -int main() -{ -#if __LDBL_MANT_DIG__ == 113 - // qNaN - any = qNaN - if (test__subtf3(makeQNaN128(), - 0x1.23456789abcdefp+5L, - UINT64_C(0x7fff800000000000), - UINT64_C(0x0))) - return 1; - // NaN - any = NaN - if (test__subtf3(makeNaN128(UINT64_C(0x800030000000)), - 0x1.23456789abcdefp+5L, - UINT64_C(0x7fff800000000000), - UINT64_C(0x0))) - return 1; - // inf - any = inf - if (test__subtf3(makeInf128(), - 0x1.23456789abcdefp+5L, - UINT64_C(0x7fff000000000000), - UINT64_C(0x0))) - return 1; - // any - any - if (test__subtf3(0x1.234567829a3bcdef5678ade36734p+5L, - 0x1.ee9d7c52354a6936ab8d7654321fp-1L, - UINT64_C(0x40041b8af1915166), - UINT64_C(0xa44a7bca780a166c))) - return 1; +#define test__subtf3(...) _test__subtf3(__LINE__, __VA_ARGS__) + +int main() { + // qNaN - any = qNaN + if (test__subtf3(makeQNaN128(), + 0x1.23456789abcdefp+5Q, + UINT64_C(0x7fff800000000000), + UINT64_C(0x0))) + return 1; + // NaN - any = NaN + if (test__subtf3(makeNaN128(UINT64_C(0x800030000000)), + 0x1.23456789abcdefp+5Q, + UINT64_C(0x7fff800000000000), + UINT64_C(0x0))) + return 1; + // inf - any = inf + if (test__subtf3(makeInf128(), + 0x1.23456789abcdefp+5Q, + UINT64_C(0x7fff000000000000), + UINT64_C(0x0))) + return 1; + // any - any + if (test__subtf3(0x1.234567829a3bcdef5678ade36734p+5Q, + 0x1.ee9d7c52354a6936ab8d7654321fp-1Q, + UINT64_C(0x40041b8af1915166), + UINT64_C(0xa44a7bca780a166c))) + return 1; #if (defined(__arm__) || defined(__aarch64__)) && defined(__ARM_FP) || \ defined(i386) || defined(__x86_64__) - // Rounding mode tests on supported architectures - const long double m = 1234.02L, n = 0.01L; + // Rounding mode tests on supported architectures + const f128 m = assertF128Representation(1234.02Q, UINT64_C(0x4009348147ae147a), UINT64_C(0xe147ae147ae147ae)); + const f128 n = assertF128Representation(0.01Q, UINT64_C(0x3ff847ae147ae147), UINT64_C(0xae147ae147ae147b)); fesetround(FE_UPWARD); if (test__subtf3(m, n, UINT64_C(0x40093480a3d70a3d), UINT64_C(0x70a3d70a3d70a3d7))) - return 1; + return 1; fesetround(FE_DOWNWARD); if (test__subtf3(m, n, UINT64_C(0x40093480a3d70a3d), UINT64_C(0x70a3d70a3d70a3d6))) - return 1; + return 1; fesetround(FE_TOWARDZERO); if (test__subtf3(m, n, UINT64_C(0x40093480a3d70a3d), UINT64_C(0x70a3d70a3d70a3d6))) - return 1; + return 1; fesetround(FE_TONEAREST); if (test__subtf3(m, n, UINT64_C(0x40093480a3d70a3d), UINT64_C(0x70a3d70a3d70a3d7))) - return 1; -#endif - -#else - printf("skipped\n"); - + return 1; #endif return 0; } +#endif diff --git a/compiler-rt/test/builtins/Unit/truncdfhf2_test.c b/compiler-rt/test/builtins/Unit/truncdfhf2_test.c --- a/compiler-rt/test/builtins/Unit/truncdfhf2_test.c +++ b/compiler-rt/test/builtins/Unit/truncdfhf2_test.c @@ -19,7 +19,7 @@ return ret; } -char assumption_1[sizeof(__fp16) * CHAR_BIT == 16] = {0}; +char assumption_1[sizeof(TYPE_FP16) * CHAR_BIT == 16] = {0}; int main() { diff --git a/compiler-rt/test/builtins/Unit/truncsfhf2_test.c b/compiler-rt/test/builtins/Unit/truncsfhf2_test.c --- a/compiler-rt/test/builtins/Unit/truncsfhf2_test.c +++ b/compiler-rt/test/builtins/Unit/truncsfhf2_test.c @@ -19,7 +19,7 @@ return ret; } -char assumption_1[sizeof(__fp16) * CHAR_BIT == 16] = {0}; +char assumption_1[sizeof(TYPE_FP16) * CHAR_BIT == 16] = {0}; int main() { diff --git a/compiler-rt/test/builtins/Unit/trunctfdf2_test.c b/compiler-rt/test/builtins/Unit/trunctfdf2_test.c --- a/compiler-rt/test/builtins/Unit/trunctfdf2_test.c +++ b/compiler-rt/test/builtins/Unit/trunctfdf2_test.c @@ -4,13 +4,16 @@ #include "int_lib.h" #include -#if __LDBL_MANT_DIG__ == 113 - #include "fp_test.h" +#if !defined(CRT_HAS_F128) +int main() { + fprintf(stderr, "Missing f128 support - skipping.\n"); + return 1; +} +#else +COMPILER_RT_ABI double __trunctfdf2(f128 a); -COMPILER_RT_ABI double __trunctfdf2(long double a); - -int test__trunctfdf2(long double a, uint64_t expected) +int test__trunctfdf2(f128 a, uint64_t expected) { double x = __trunctfdf2(a); int ret = compareResultD(x, expected); @@ -23,13 +26,10 @@ return ret; } -char assumption_1[sizeof(long double) * CHAR_BIT == 128] = {0}; - -#endif +char assumption_1[sizeof(f128) * CHAR_BIT == 128] = {0}; int main() { -#if __LDBL_MANT_DIG__ == 113 // qNaN if (test__trunctfdf2(makeQNaN128(), UINT64_C(0x7ff8000000000000))) @@ -59,9 +59,6 @@ UINT64_C(0x24cedcbff8ad76ab))) return 1; -#else - printf("skipped\n"); - -#endif return 0; } +#endif diff --git a/compiler-rt/test/builtins/Unit/trunctfhf2_test.c b/compiler-rt/test/builtins/Unit/trunctfhf2_test.c --- a/compiler-rt/test/builtins/Unit/trunctfhf2_test.c +++ b/compiler-rt/test/builtins/Unit/trunctfhf2_test.c @@ -4,13 +4,16 @@ #include "int_lib.h" #include -#if __LDBL_MANT_DIG__ == 113 && defined(COMPILER_RT_HAS_FLOAT16) - #include "fp_test.h" +#if !defined(CRT_HAS_F128) +int main() { + fprintf(stderr, "Missing f128 support - skipping.\n"); + return 1; +} +#else +TYPE_FP16 __trunctfhf2(f128 a); -TYPE_FP16 __trunctfhf2(long double a); - -int test__trunctfhf2(long double a, uint16_t expected) { +int test__trunctfhf2(f128 a, uint16_t expected) { TYPE_FP16 x = __trunctfhf2(a); int ret = compareResultH(x, expected); @@ -24,10 +27,7 @@ char assumption_1[sizeof(TYPE_FP16) * CHAR_BIT == 16] = {0}; -#endif - int main() { -#if __LDBL_MANT_DIG__ == 113 && defined(COMPILER_RT_HAS_FLOAT16) // qNaN if (test__trunctfhf2(makeQNaN128(), UINT16_C(0x7e00))) @@ -118,8 +118,6 @@ if (test__trunctfhf2(0x1.edcba9bb8c76a5a43dd21f334634p-43L, UINT16_C(0x0))) return 1; -#else - printf("skipped\n"); -#endif return 0; } +#endif diff --git a/compiler-rt/test/builtins/Unit/trunctfsf2_test.c b/compiler-rt/test/builtins/Unit/trunctfsf2_test.c --- a/compiler-rt/test/builtins/Unit/trunctfsf2_test.c +++ b/compiler-rt/test/builtins/Unit/trunctfsf2_test.c @@ -4,13 +4,16 @@ #include "int_lib.h" #include -#if __LDBL_MANT_DIG__ == 113 - #include "fp_test.h" +#if !defined(CRT_HAS_F128) +int main() { + fprintf(stderr, "Missing f128 support - skipping.\n"); + return 1; +} +#else +COMPILER_RT_ABI float __trunctfsf2(f128 a); -COMPILER_RT_ABI float __trunctfsf2(long double a); - -int test__trunctfsf2(long double a, uint32_t expected) +int test__trunctfsf2(f128 a, uint32_t expected) { float x = __trunctfsf2(a); int ret = compareResultF(x, expected); @@ -22,13 +25,10 @@ return ret; } -char assumption_1[sizeof(long double) * CHAR_BIT == 128] = {0}; - -#endif +char assumption_1[sizeof(f128) * CHAR_BIT == 128] = {0}; int main() { -#if __LDBL_MANT_DIG__ == 113 // qNaN if (test__trunctfsf2(makeQNaN128(), UINT32_C(0x7fc00000))) @@ -58,9 +58,6 @@ UINT32_C(0x0))) return 1; -#else - printf("skipped\n"); - -#endif return 0; } +#endif diff --git a/compiler-rt/test/builtins/Unit/unordtf2_test.c b/compiler-rt/test/builtins/Unit/unordtf2_test.c --- a/compiler-rt/test/builtins/Unit/unordtf2_test.c +++ b/compiler-rt/test/builtins/Unit/unordtf2_test.c @@ -3,15 +3,18 @@ #include -#if __LP64__ && __LDBL_MANT_DIG__ == 113 - #include "fp_test.h" +#if !defined(CRT_HAS_F128) +int main() { + fprintf(stderr, "Missing f128 support - skipping.\n"); + return 1; +} +#else +long __unordtf2(f128 a, f128 b); -int __unordtf2(long double a, long double b); - -int test__unordtf2(long double a, long double b, enum EXPECTED_RESULT expected) +int test__unordtf2(f128 a, f128 b, enum EXPECTED_RESULT expected) { - int x = __unordtf2(a, b); + long x = __unordtf2(a, b); int ret = compareResultCMP(x, expected); if (ret){ @@ -21,13 +24,10 @@ return ret; } -char assumption_1[sizeof(long double) * CHAR_BIT == 128] = {0}; - -#endif +char assumption_1[sizeof(f128) * CHAR_BIT == 128] = {0}; int main() { -#if __LP64__ && __LDBL_MANT_DIG__ == 113 // NaN if (test__unordtf2(makeQNaN128(), 0x1.234567890abcdef1234567890abcp+3L, @@ -47,9 +47,6 @@ EQUAL_0)) return 1; -#else - printf("skipped\n"); - -#endif return 0; } +#endif