From 6065b3b4240d60fdb377185702ec7be41633d9bf Mon Sep 17 00:00:00 2001 From: Daniel Lemire Date: Thu, 12 Mar 2026 20:40:43 -0400 Subject: [PATCH] disabling loongson LASX runtime dispatching everywhere but GCC15+ (#2626) --- doc/implementation-selection.md | 3 +++ include/simdjson/compiler_check.h | 1 - include/simdjson/portability.h | 19 +++++++++++++++++++ 3 files changed, 22 insertions(+), 1 deletion(-) diff --git a/doc/implementation-selection.md b/doc/implementation-selection.md index 26b38b978..05e4dc109 100644 --- a/doc/implementation-selection.md +++ b/doc/implementation-selection.md @@ -33,6 +33,9 @@ compiles *all* the implementations into the executable. On Intel, it will includ (icelake, haswell, westmere and fallback), on 64-bit ARM it will include just one since running dispatching is unnecessary, and on PPC it will include 2 (ppc64 and fallback). +On Loongson processors, LASX runtime dispatching is only enabled on GCC 15+, not on LLVM or older versions of GCC. +Thus unless you compile specifically for LASX or use GCC 15+, you will not benefit from LASX support. + If you know more about where you're going to run and want to save the space, you can disable any of these implementations at compile time with `-DSIMDJSON_IMPLEMENTATION_X=0` (where X is ICELAKE, HASWELL, WESTMERE, ARM64, PPC64, LSX, LASX and FALLBACK). diff --git a/include/simdjson/compiler_check.h b/include/simdjson/compiler_check.h index 72400a30a..655f66318 100644 --- a/include/simdjson/compiler_check.h +++ b/include/simdjson/compiler_check.h @@ -119,5 +119,4 @@ #define SIMDJSON_CONSTEVAL 0 #endif // defined(__cpp_consteval) && __cpp_consteval >= 201811L && defined(__cpp_lib_constexpr_string) && __cpp_lib_constexpr_string >= 201907L #endif // !defined(SIMDJSON_CONSTEVAL) - #endif // SIMDJSON_COMPILER_CHECK_H diff --git a/include/simdjson/portability.h b/include/simdjson/portability.h index e6850d0f2..bff2163ba 100644 --- a/include/simdjson/portability.h +++ b/include/simdjson/portability.h @@ -66,6 +66,25 @@ using std::size_t; #define SIMDJSON_IS_LASX 1 // We can always run both #elif defined(__loongarch_sx) #define SIMDJSON_IS_LSX 1 + +// Adjust for runtime dispatching support. +#if defined(__GNUC__) && !defined(__clang__) && !defined(__INTEL_COMPILER) && !defined(__NVCOMPILER) +#if __GNUC__ > 15 || (__GNUC__ == 15 && __GNUC_MINOR__ >= 0) + // We are ok, we will support runtime dispatch for LASX. +#else + // We disable runtime dispatch for LASX, which means that we will not be able to use LASX + // even if it is supported by the hardware. + // Loongson users should update to GCC 15 or better. + #define SIMDJSON_IMPLEMENTATION_LASX 0 +#endif +#else + // We are not using GCC, so we assume that we can support runtime dispatch for LASX. + // https://godbolt.org/z/jcMnrjYhs + #define SIMDJSON_IMPLEMENTATION_LASX 0 +#endif + + + #endif #elif defined(__PPC64__) || defined(_M_PPC64) #define SIMDJSON_IS_PPC64 1