From 16c5398aa1a4fa46bcac1febbcb7f2253f1d85a3 Mon Sep 17 00:00:00 2001 From: "David C. Partridge" Date: Tue, 3 Dec 2024 12:49:03 +0000 Subject: [PATCH] Allow use of qnumeric.h without needing Windows intrinsics Add a preprocessor variable Q_NUMERIC_NO_INTRINSICS to suppress inclusion of and fall back to the same behavior as other platforms Fixes: QTBUG-131757 Pick-to: 6.8 Change-Id: I8bcf912c0499897a8daf67951993cee22a86c590 Reviewed-by: Thiago Macieira --- src/corelib/global/qnumeric.h | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/src/corelib/global/qnumeric.h b/src/corelib/global/qnumeric.h index 521cf98b09d..5a25b1c2392 100644 --- a/src/corelib/global/qnumeric.h +++ b/src/corelib/global/qnumeric.h @@ -23,9 +23,17 @@ # undef max #endif -#if defined(Q_CC_MSVC) +// +// SIMDe (SIMD Everywhere) can't be used if intrin.h has been included as many definitions +// conflict. Defining Q_NUMERIC_NO_INTRINSICS allows SIMDe users to use Qt, at the cost of +// falling back to the prior implementations of qMulOverflow and qAddOverflow. +// +#if defined(Q_CC_MSVC) && !defined(Q_NUMERIC_NO_INTRINSICS) # include # include +# if defined(Q_PROCESSOR_X86) || defined(Q_PROCESSOR_X86_64) +# define Q_HAVE_ADDCARRY +# endif # if defined(Q_PROCESSOR_X86_64) || defined(Q_PROCESSOR_ARM_64) # define Q_INTRINSIC_MUL_OVERFLOW64 # define Q_UMULH(v1, v2) __umulh(v1, v2); @@ -223,7 +231,7 @@ template <> inline bool qMulOverflow(int64_t v1, int64_t v2, int64_t *r) # endif // OS_INTEGRITY ARM64 # endif // Q_INTRINSIC_MUL_OVERFLOW64 -# if defined(Q_CC_MSVC) && defined(Q_PROCESSOR_X86) +# if defined(Q_HAVE_ADDCARRY) && defined(Q_PROCESSOR_X86) // We can use intrinsics for the unsigned operations with MSVC template <> inline bool qAddOverflow(unsigned v1, unsigned v2, unsigned *r) { return _addcarry_u32(0, v1, v2, r); } @@ -242,7 +250,8 @@ template <> inline bool qAddOverflow(quint64 v1, quint64 v2, quint64 *r) return carry; # endif // !x86-64 } -# endif // MSVC X86 +# endif // HAVE ADDCARRY +#undef Q_HAVE_ADDCARRY #endif // !GCC // Implementations for addition, subtraction or multiplication by a