From 987e16820cc02ac29d29ca37229963ce84e0405f Mon Sep 17 00:00:00 2001 From: Federico Busato Date: Thu, 14 Jul 2022 12:04:32 -0700 Subject: [PATCH] Fixes IBM XLC behavior with uint128 fallback --- include/fmt/core.h | 12 ++++++++++++ include/fmt/format.h | 7 +++++-- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/include/fmt/core.h b/include/fmt/core.h index 1e8ecad1..fbde339f 100644 --- a/include/fmt/core.h +++ b/include/fmt/core.h @@ -49,6 +49,18 @@ # define FMT_ICC_VERSION 0 #endif +#ifdef __xlC_ver__ +# define FMT_XLC_VERSION __xlC_ver__ +#elif defined(__xlC__) +# define FMT_XLC_VERSION __xlC__ +#elif defined(__IBMC__) +# define FMT_XLC_VERSION __IBMC__ +#elif defined(__IBMCPP__) +# define FMT_XLC_VERSION __IBMCPP__ +#else +# define FMT_XLC_VERSION 0 +#endif + #ifdef _MSC_VER # define FMT_MSC_VERSION _MSC_VER # define FMT_MSC_WARNING(...) __pragma(warning(__VA_ARGS__)) diff --git a/include/fmt/format.h b/include/fmt/format.h index 6516975e..d6bf02ee 100644 --- a/include/fmt/format.h +++ b/include/fmt/format.h @@ -391,11 +391,14 @@ class uint128_fallback { hi_ += (lo_ < n ? 1 : 0); return *this; } -#if FMT_HAS_BUILTIN(__builtin_addcll) +#if FMT_XLC_VERSION && defined(_ARCH_PWR9) && defined(_ARCH_PPC64) + lo_ = __addex(lo_, n, 0, &carry); + hi_ += carry; +#elif FMT_HAS_BUILTIN(__builtin_addcll) && !FMT_XLC_VERSION unsigned long long carry; lo_ = __builtin_addcll(lo_, n, 0, &carry); hi_ += carry; -#elif FMT_HAS_BUILTIN(__builtin_ia32_addcarryx_u64) +#elif FMT_HAS_BUILTIN(__builtin_ia32_addcarryx_u64) && !FMT_XLC_VERSION unsigned long long result; auto carry = __builtin_ia32_addcarryx_u64(0, lo_, n, &result); lo_ = result;