2222
2323#include "int_lib.h"
2424#include "int_math.h"
25+ #include "int_types.h"
2526#include <limits.h>
2627#include <stdbool.h>
2728#include <stdint.h>
@@ -93,13 +94,14 @@ static __inline void wideMultiply(rep_t a, rep_t b, rep_t *hi, rep_t *lo) {
9394COMPILER_RT_ABI fp_t __adddf3 (fp_t a , fp_t b );
9495
9596#elif defined QUAD_PRECISION
96- #if defined(CRT_HAS_TF_MODE )
97+ #if defined(CRT_HAS_F128 ) && defined( CRT_HAS_128BIT )
9798typedef uint64_t half_rep_t ;
9899typedef __uint128_t rep_t ;
99100typedef __int128_t srep_t ;
100101typedef tf_float fp_t ;
101102#define HALF_REP_C UINT64_C
102103#define REP_C (__uint128_t)
104+ #if defined(CRT_HAS_IEEE_TF )
103105// Note: Since there is no explicit way to tell compiler the constant is a
104106// 128-bit integer, we let the constant be casted to 128-bit integer
105107#define significandBits 112
@@ -188,27 +190,17 @@ static __inline void wideMultiply(rep_t a, rep_t b, rep_t *hi, rep_t *lo) {
188190#undef Word_HiMask
189191#undef Word_LoMask
190192#undef Word_FullMask
191- #endif // defined(CRT_HAS_TF_MODE)
193+ #endif // defined(CRT_HAS_IEEE_TF)
194+ #else
195+ typedef long double fp_t ;
196+ #endif // defined(CRT_HAS_F128) && defined(CRT_HAS_128BIT)
192197#else
193198#error SINGLE_PRECISION, DOUBLE_PRECISION or QUAD_PRECISION must be defined.
194199#endif
195200
196201#if defined(SINGLE_PRECISION ) || defined(DOUBLE_PRECISION ) || \
197202 (defined(QUAD_PRECISION ) && defined(CRT_HAS_TF_MODE ))
198203#define typeWidth (sizeof(rep_t) * CHAR_BIT)
199- #define exponentBits (typeWidth - significandBits - 1)
200- #define maxExponent ((1 << exponentBits) - 1)
201- #define exponentBias (maxExponent >> 1)
202-
203- #define implicitBit (REP_C(1) << significandBits)
204- #define significandMask (implicitBit - 1U)
205- #define signBit (REP_C(1) << (significandBits + exponentBits))
206- #define absMask (signBit - 1U)
207- #define exponentMask (absMask ^ significandMask)
208- #define oneRep ((rep_t)exponentBias << significandBits)
209- #define infRep exponentMask
210- #define quietBit (implicitBit >> 1)
211- #define qnanRep (exponentMask | quietBit)
212204
213205static __inline rep_t toRep (fp_t x ) {
214206 const union {
@@ -226,6 +218,21 @@ static __inline fp_t fromRep(rep_t x) {
226218 return rep .f ;
227219}
228220
221+ #if !defined(QUAD_PRECISION ) || defined(CRT_HAS_IEEE_TF )
222+ #define exponentBits (typeWidth - significandBits - 1)
223+ #define maxExponent ((1 << exponentBits) - 1)
224+ #define exponentBias (maxExponent >> 1)
225+
226+ #define implicitBit (REP_C(1) << significandBits)
227+ #define significandMask (implicitBit - 1U)
228+ #define signBit (REP_C(1) << (significandBits + exponentBits))
229+ #define absMask (signBit - 1U)
230+ #define exponentMask (absMask ^ significandMask)
231+ #define oneRep ((rep_t)exponentBias << significandBits)
232+ #define infRep exponentMask
233+ #define quietBit (implicitBit >> 1)
234+ #define qnanRep (exponentMask | quietBit)
235+
229236static __inline int normalize (rep_t * significand ) {
230237 const int shift = rep_clz (* significand ) - rep_clz (implicitBit );
231238 * significand <<= shift ;
@@ -328,6 +335,8 @@ static __inline fp_t __compiler_rt_scalbnX(fp_t x, int y) {
328335 return fromRep (sign | ((rep_t )exp << significandBits ) | sig );
329336}
330337
338+ #endif // !defined(QUAD_PRECISION) || defined(CRT_HAS_IEEE_TF)
339+
331340// Avoid using fmax from libm.
332341static __inline fp_t __compiler_rt_fmaxX (fp_t x , fp_t y ) {
333342 // If either argument is NaN, return the other argument. If both are NaN,
@@ -405,6 +414,8 @@ static __inline tf_float __compiler_rt_fmaxtf(tf_float x, tf_float y) {
405414#define __compiler_rt_logbl crt_logbl
406415#define __compiler_rt_scalbnl crt_scalbnl
407416#define __compiler_rt_fmaxl crt_fmaxl
417+ #define crt_fabstf crt_fabsl
418+ #define crt_copysigntf crt_copysignl
408419#else
409420#error Unsupported TF mode type
410421#endif
0 commit comments