22
22
23
23
#include "int_lib.h"
24
24
#include "int_math.h"
25
+ #include "int_types.h"
25
26
#include <limits.h>
26
27
#include <stdbool.h>
27
28
#include <stdint.h>
@@ -93,13 +94,14 @@ static __inline void wideMultiply(rep_t a, rep_t b, rep_t *hi, rep_t *lo) {
93
94
COMPILER_RT_ABI fp_t __adddf3 (fp_t a , fp_t b );
94
95
95
96
#elif defined QUAD_PRECISION
96
- #if defined(CRT_HAS_TF_MODE )
97
+ #if defined(CRT_HAS_F128 ) && defined( CRT_HAS_128BIT )
97
98
typedef uint64_t half_rep_t ;
98
99
typedef __uint128_t rep_t ;
99
100
typedef __int128_t srep_t ;
100
101
typedef tf_float fp_t ;
101
102
#define HALF_REP_C UINT64_C
102
103
#define REP_C (__uint128_t)
104
+ #if defined(CRT_HAS_IEEE_TF )
103
105
// Note: Since there is no explicit way to tell compiler the constant is a
104
106
// 128-bit integer, we let the constant be casted to 128-bit integer
105
107
#define significandBits 112
@@ -188,27 +190,17 @@ static __inline void wideMultiply(rep_t a, rep_t b, rep_t *hi, rep_t *lo) {
188
190
#undef Word_HiMask
189
191
#undef Word_LoMask
190
192
#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)
192
197
#else
193
198
#error SINGLE_PRECISION, DOUBLE_PRECISION or QUAD_PRECISION must be defined.
194
199
#endif
195
200
196
201
#if defined(SINGLE_PRECISION ) || defined(DOUBLE_PRECISION ) || \
197
202
(defined(QUAD_PRECISION ) && defined(CRT_HAS_TF_MODE ))
198
203
#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)
212
204
213
205
static __inline rep_t toRep (fp_t x ) {
214
206
const union {
@@ -226,6 +218,21 @@ static __inline fp_t fromRep(rep_t x) {
226
218
return rep .f ;
227
219
}
228
220
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
+
229
236
static __inline int normalize (rep_t * significand ) {
230
237
const int shift = rep_clz (* significand ) - rep_clz (implicitBit );
231
238
* significand <<= shift ;
@@ -328,6 +335,8 @@ static __inline fp_t __compiler_rt_scalbnX(fp_t x, int y) {
328
335
return fromRep (sign | ((rep_t )exp << significandBits ) | sig );
329
336
}
330
337
338
+ #endif // !defined(QUAD_PRECISION) || defined(CRT_HAS_IEEE_TF)
339
+
331
340
// Avoid using fmax from libm.
332
341
static __inline fp_t __compiler_rt_fmaxX (fp_t x , fp_t y ) {
333
342
// 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) {
405
414
#define __compiler_rt_logbl crt_logbl
406
415
#define __compiler_rt_scalbnl crt_scalbnl
407
416
#define __compiler_rt_fmaxl crt_fmaxl
417
+ #define crt_fabstf crt_fabsl
418
+ #define crt_copysigntf crt_copysignl
408
419
#else
409
420
#error Unsupported TF mode type
410
421
#endif
0 commit comments