From 1b9d2355e394e3ea978fdefc265170995903307e Mon Sep 17 00:00:00 2001 From: Yining Karl Li Date: Thu, 16 Mar 2023 09:50:19 -0700 Subject: [PATCH] Detect missing vst1q_f32_x2 and provide replacement if necessary Older versions of GCC (< 9) do not provide the vst1q_f32_x2 intrinsic on aarch64, so we must detect when vst1q_f32_x2 is not available and provide our own implementation instead. Signed-off-by: Yining Karl Li --- cmake/OpenEXRSetup.cmake | 18 ++++++++++++++++++ src/lib/OpenEXR/ImfSimd.h | 13 +++++++++++++ 2 files changed, 31 insertions(+) diff --git a/cmake/OpenEXRSetup.cmake b/cmake/OpenEXRSetup.cmake index 975e572f5..82d66cd31 100644 --- a/cmake/OpenEXRSetup.cmake +++ b/cmake/OpenEXRSetup.cmake @@ -312,3 +312,21 @@ else() message(STATUS "Imath interface dirs ${IMATH_HEADER_ONLY_INCLUDE_DIRS}") endif() endif() + +########################################### +# Check if we need to emulate vld1q_f32_x2 +########################################### + +if(CMAKE_SYSTEM_PROCESSOR MATCHES "aarch64") + include(CheckCSourceCompiles) + check_c_source_compiles("#include +int main() { + float a[] = {1.0, 1.0}; + vld1q_f32_x2(a); + return 0; +}" HAS_VLD1) + + if(NOT HAS_VLD1) + string(APPEND CMAKE_CXX_FLAGS " -DMISSING_ARM_VLD1") + endif() +endif() diff --git a/src/lib/OpenEXR/ImfSimd.h b/src/lib/OpenEXR/ImfSimd.h index 3053a5d4e..7d0fdb8fd 100644 --- a/src/lib/OpenEXR/ImfSimd.h +++ b/src/lib/OpenEXR/ImfSimd.h @@ -62,4 +62,17 @@ extern "C" { } +#if defined (MISSING_ARM_VLD1) +/* Workaround for missing vld1q_f32_x2 in older gcc versions. */ + +__extension__ extern __inline float32x4x2_t + __attribute__ ((__always_inline__, __gnu_inline__, __artificial__)) + vld1q_f32_x2 (const float32_t* __a) +{ + float32x4x2_t ret; + asm ("ld1 {%S0.4s - %T0.4s}, [%1]" : "=w"(ret) : "r"(__a) :); + return ret; +} +#endif + #endif