From af2e6d55050fff82ad95e1175f72cb42df209762 Mon Sep 17 00:00:00 2001 From: Anish Khanzode Date: Sat, 18 Apr 2026 16:37:22 -0400 Subject: [PATCH] Fix bignum.cc build failure on GCC 8 (x86_64) The _addcarry_u64 and _subborrow_u64 intrinsics require the ADX instruction set extension, which GCC < 9 does not enable by default on x86_64. The existing #ifdef __x86_64__ guard is too broad. Replace with a stricter check that also verifies ADX support: - Clang (all versions support the intrinsics on x86_64) - GCC >= 9 (enables ADX by default) - Any compiler with -madx flag (__ADX__ is defined) On older GCC without ADX, falls through to the existing portable absl::uint128 arithmetic path with no functional change. Fixes #568 --- src/s2/util/math/exactfloat/bignum.cc | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/s2/util/math/exactfloat/bignum.cc b/src/s2/util/math/exactfloat/bignum.cc index 76774b6fa..61cdb8577 100644 --- a/src/s2/util/math/exactfloat/bignum.cc +++ b/src/s2/util/math/exactfloat/bignum.cc @@ -15,7 +15,7 @@ #include "s2/util/math/exactfloat/bignum.h" -#ifdef __x86_64__ +#if defined(__x86_64__) && (defined(__clang__) || (defined(__GNUC__) && __GNUC__ >= 9) || defined(__ADX__)) #include #endif @@ -292,7 +292,7 @@ inline Bigit AddBigit(Bigit a, Bigit b, Bigit* absl_nonnull carry) { // Godbolt link for comparison: // https://godbolt.org/z/cGnnfMbMn (no intrinsics) // https://godbolt.org/z/jnM1Y3Tjs (intrinsics) -#ifdef __x86_64__ +#if defined(__x86_64__) && (defined(__clang__) || (defined(__GNUC__) && __GNUC__ >= 9) || defined(__ADX__)) static_assert(sizeof(Bigit) == sizeof(unsigned long long)); Bigit out; *carry = @@ -311,7 +311,7 @@ inline Bigit AddBigit(Bigit a, Bigit b, Bigit* absl_nonnull carry) { inline Bigit SubBigit(Bigit a, Bigit b, Bigit* absl_nonnull borrow) { ABSL_DCHECK_LE(*borrow, Bigit(1)); // See notes in AddBigit on why using an intrinsic is the right choice here. -#ifdef __x86_64__ +#if defined(__x86_64__) && (defined(__clang__) || (defined(__GNUC__) && __GNUC__ >= 9) || defined(__ADX__)) Bigit out; *borrow = _subborrow_u64(static_cast(*borrow), a, b, reinterpret_cast(&out));