Skip to content

Commit 275934e

Browse files
committed
zig.h: workaround for gcc f128 miscompilations
1 parent e9d7939 commit 275934e

File tree

2 files changed

+24
-12
lines changed

2 files changed

+24
-12
lines changed

lib/zig.h

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,12 @@ typedef char bool;
6161
#define zig_gnuc
6262
#endif
6363

64+
#if defined(zig_gnuc) && (defined(__i386__) || defined(__x86_64__))
65+
#define zig_f128_has_miscompilations 1
66+
#else
67+
#define zig_f128_has_miscompilations 0
68+
#endif
69+
6470
#if _MSC_VER
6571
#define zig_const_arr
6672
#define zig_callconv(c) __##c
@@ -3155,22 +3161,22 @@ typedef zig_u128 zig_f80;
31553161
#define zig_has_f128 1
31563162
#define zig_libc_name_f128(name) name##q
31573163
#define zig_init_special_f128(sign, name, arg, repr) zig_make_special_f128(sign, name, arg, repr)
3158-
#if FLT_MANT_DIG == 113
3164+
#if !zig_f128_has_miscompilations && FLT_MANT_DIG == 113
31593165
typedef float zig_f128;
31603166
#define zig_make_f128(fp, repr) fp##f
3161-
#elif DBL_MANT_DIG == 113
3167+
#elif !zig_f128_has_miscompilations && DBL_MANT_DIG == 113
31623168
typedef double zig_f128;
31633169
#define zig_make_f128(fp, repr) fp
3164-
#elif LDBL_MANT_DIG == 113
3170+
#elif !zig_f128_has_miscompilations && LDBL_MANT_DIG == 113
31653171
typedef long double zig_f128;
31663172
#define zig_make_f128(fp, repr) fp##l
3167-
#elif FLT128_MANT_DIG == 113
3173+
#elif !zig_f128_has_miscompilations && FLT128_MANT_DIG == 113
31683174
typedef _Float128 zig_f128;
31693175
#define zig_make_f128(fp, repr) fp##f128
3170-
#elif FLT64X_MANT_DIG == 113
3176+
#elif !zig_f128_has_miscompilations && FLT64X_MANT_DIG == 113
31713177
typedef _Float64x zig_f128;
31723178
#define zig_make_f128(fp, repr) fp##f64x
3173-
#elif defined(__SIZEOF_FLOAT128__)
3179+
#elif !zig_f128_has_miscompilations && defined(__SIZEOF_FLOAT128__)
31743180
typedef __float128 zig_f128;
31753181
#define zig_make_f128(fp, repr) fp##q
31763182
#undef zig_make_special_f128

stage1/zig.h

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,12 @@ typedef char bool;
6161
#define zig_gnuc
6262
#endif
6363

64+
#if defined(zig_gnuc) && (defined(__i386__) || defined(__x86_64__))
65+
#define zig_f128_has_miscompilations 1
66+
#else
67+
#define zig_f128_has_miscompilations 0
68+
#endif
69+
6470
#if _MSC_VER
6571
#define zig_const_arr
6672
#define zig_callconv(c) __##c
@@ -3155,22 +3161,22 @@ typedef zig_u128 zig_f80;
31553161
#define zig_has_f128 1
31563162
#define zig_libc_name_f128(name) name##q
31573163
#define zig_init_special_f128(sign, name, arg, repr) zig_make_special_f128(sign, name, arg, repr)
3158-
#if FLT_MANT_DIG == 113
3164+
#if !zig_f128_has_miscompilations && FLT_MANT_DIG == 113
31593165
typedef float zig_f128;
31603166
#define zig_make_f128(fp, repr) fp##f
3161-
#elif DBL_MANT_DIG == 113
3167+
#elif !zig_f128_has_miscompilations && DBL_MANT_DIG == 113
31623168
typedef double zig_f128;
31633169
#define zig_make_f128(fp, repr) fp
3164-
#elif LDBL_MANT_DIG == 113
3170+
#elif !zig_f128_has_miscompilations && LDBL_MANT_DIG == 113
31653171
typedef long double zig_f128;
31663172
#define zig_make_f128(fp, repr) fp##l
3167-
#elif FLT128_MANT_DIG == 113
3173+
#elif !zig_f128_has_miscompilations && FLT128_MANT_DIG == 113
31683174
typedef _Float128 zig_f128;
31693175
#define zig_make_f128(fp, repr) fp##f128
3170-
#elif FLT64X_MANT_DIG == 113
3176+
#elif !zig_f128_has_miscompilations && FLT64X_MANT_DIG == 113
31713177
typedef _Float64x zig_f128;
31723178
#define zig_make_f128(fp, repr) fp##f64x
3173-
#elif defined(__SIZEOF_FLOAT128__)
3179+
#elif !zig_f128_has_miscompilations && defined(__SIZEOF_FLOAT128__)
31743180
typedef __float128 zig_f128;
31753181
#define zig_make_f128(fp, repr) fp##q
31763182
#undef zig_make_special_f128

0 commit comments

Comments
 (0)