From c29b85a82a8bdcf3375657cab45050187c511edf Mon Sep 17 00:00:00 2001 From: Carles Fernandez Date: Fri, 24 Jan 2025 12:18:45 +0100 Subject: [PATCH] Update cpu_features to Dec24 --- .../volk_gnsssdr/cpu_features/CMakeLists.txt | 8 +------ .../include/cpu_features_macros.h | 12 +++++++---- ..._freebsd.c => hwcaps_freebsd_or_openbsd.c} | 6 +++--- .../cpu_features/src/impl_aarch64_cpuid.c | 10 ++++----- ...sd.c => impl_aarch64_freebsd_or_openbsd.c} | 6 +++--- .../src/utils/list_cpu_features.c | 6 +++++- .../cpu_features/test/CMakeLists.txt | 4 ++-- .../cpu_features/test/cpuinfo_aarch64_test.cc | 21 ++++++++----------- 8 files changed, 35 insertions(+), 38 deletions(-) rename src/algorithms/libs/volk_gnsssdr_module/volk_gnsssdr/cpu_features/src/{hwcaps_freebsd.c => hwcaps_freebsd_or_openbsd.c} (85%) rename src/algorithms/libs/volk_gnsssdr_module/volk_gnsssdr/cpu_features/src/{impl_aarch64_freebsd.c => impl_aarch64_freebsd_or_openbsd.c} (86%) diff --git a/src/algorithms/libs/volk_gnsssdr_module/volk_gnsssdr/cpu_features/CMakeLists.txt b/src/algorithms/libs/volk_gnsssdr_module/volk_gnsssdr/cpu_features/CMakeLists.txt index 7e7f7b90b..354ea80fe 100644 --- a/src/algorithms/libs/volk_gnsssdr_module/volk_gnsssdr/cpu_features/CMakeLists.txt +++ b/src/algorithms/libs/volk_gnsssdr_module/volk_gnsssdr/cpu_features/CMakeLists.txt @@ -3,12 +3,6 @@ cmake_minimum_required(VERSION 3.13) -# option() honors normal variables. -# see: https://cmake.org/cmake/help/git-stage/policy/CMP0077.html -if(POLICY CMP0077) - cmake_policy(SET CMP0077 NEW) -endif() - project(CpuFeatures VERSION 0.9.0 LANGUAGES C) set(CMAKE_C_STANDARD 99) @@ -151,7 +145,7 @@ if(UNIX) add_library(unix_based_hardware_detection OBJECT ${PROJECT_SOURCE_DIR}/include/internal/hwcaps.h ${PROJECT_SOURCE_DIR}/src/hwcaps_linux_or_android.c - ${PROJECT_SOURCE_DIR}/src/hwcaps_freebsd.c + ${PROJECT_SOURCE_DIR}/src/hwcaps_freebsd_or_openbsd.c ${PROJECT_SOURCE_DIR}/src/hwcaps.c ) setup_include_and_definitions(unix_based_hardware_detection) diff --git a/src/algorithms/libs/volk_gnsssdr_module/volk_gnsssdr/cpu_features/include/cpu_features_macros.h b/src/algorithms/libs/volk_gnsssdr_module/volk_gnsssdr/cpu_features/include/cpu_features_macros.h index b595a22f2..020c3d09f 100644 --- a/src/algorithms/libs/volk_gnsssdr_module/volk_gnsssdr/cpu_features/include/cpu_features_macros.h +++ b/src/algorithms/libs/volk_gnsssdr_module/volk_gnsssdr/cpu_features/include/cpu_features_macros.h @@ -4,7 +4,6 @@ #ifndef CPU_FEATURES_INCLUDE_CPU_FEATURES_MACROS_H_ #define CPU_FEATURES_INCLUDE_CPU_FEATURES_MACROS_H_ -#include //////////////////////////////////////////////////////////////////////////////// // Architectures //////////////////////////////////////////////////////////////////////////////// @@ -85,6 +84,10 @@ #define CPU_FEATURES_OS_FREEBSD #endif +#if defined(__OpenBSD__) +#define CPU_FEATURES_OS_OPENBSD +#endif + #if defined(__ANDROID__) #define CPU_FEATURES_OS_ANDROID #endif @@ -226,14 +229,15 @@ #endif // defined(CPU_FEATURES_ARCH_X86) +#if defined(CPU_FEATURES_ARCH_ANY_ARM) // Note: MSVC targeting ARM does not define `__ARM_NEON` but Windows on ARM // requires it. In that case we force NEON detection. -#if defined(__ARM_NEON) || \ - (defined(CPU_FEATURES_COMPILER_MSC) && defined(CPU_FEATURES_ARCH_ANY_ARM)) +#if defined(__ARM_NEON) || defined(CPU_FEATURES_COMPILER_MSC) #define CPU_FEATURES_COMPILED_ANY_ARM_NEON 1 #else #define CPU_FEATURES_COMPILED_ANY_ARM_NEON 0 -#endif +#endif // defined(__ARM_NEON) || defined(CPU_FEATURES_COMPILER_MSC) +#endif // defined(CPU_FEATURES_ARCH_ANY_ARM) #if defined(CPU_FEATURES_ARCH_MIPS) #if defined(__mips_msa) diff --git a/src/algorithms/libs/volk_gnsssdr_module/volk_gnsssdr/cpu_features/src/hwcaps_freebsd.c b/src/algorithms/libs/volk_gnsssdr_module/volk_gnsssdr/cpu_features/src/hwcaps_freebsd_or_openbsd.c similarity index 85% rename from src/algorithms/libs/volk_gnsssdr_module/volk_gnsssdr/cpu_features/src/hwcaps_freebsd.c rename to src/algorithms/libs/volk_gnsssdr_module/volk_gnsssdr/cpu_features/src/hwcaps_freebsd_or_openbsd.c index 34c29e7ae..8756c4c30 100644 --- a/src/algorithms/libs/volk_gnsssdr_module/volk_gnsssdr/cpu_features/src/hwcaps_freebsd.c +++ b/src/algorithms/libs/volk_gnsssdr_module/volk_gnsssdr/cpu_features/src/hwcaps_freebsd_or_openbsd.c @@ -3,7 +3,7 @@ #include "cpu_features_macros.h" -#ifdef CPU_FEATURES_OS_FREEBSD +#if defined(CPU_FEATURES_OS_FREEBSD) || defined(CPU_FEATURES_OS_OPENBSD) #include "internal/hwcaps.h" @@ -38,8 +38,8 @@ const char *CpuFeatures_GetPlatformPointer(void) { return NULL; } const char *CpuFeatures_GetBasePlatformPointer(void) { return NULL; } #else -#error "FreeBSD needs support for elf_aux_info" +#error "FreeBSD / OpenBSD needs support for elf_aux_info" #endif // HAVE_STRONG_ELF_AUX_INFO #endif // CPU_FEATURES_TEST -#endif // CPU_FEATURES_OS_FREEBSD \ No newline at end of file +#endif // CPU_FEATURES_OS_FREEBSD || CPU_FEATURES_OS_OPENBSD \ No newline at end of file diff --git a/src/algorithms/libs/volk_gnsssdr_module/volk_gnsssdr/cpu_features/src/impl_aarch64_cpuid.c b/src/algorithms/libs/volk_gnsssdr_module/volk_gnsssdr/cpu_features/src/impl_aarch64_cpuid.c index 5ae3a1df7..d6245a127 100644 --- a/src/algorithms/libs/volk_gnsssdr_module/volk_gnsssdr/cpu_features/src/impl_aarch64_cpuid.c +++ b/src/algorithms/libs/volk_gnsssdr_module/volk_gnsssdr/cpu_features/src/impl_aarch64_cpuid.c @@ -4,8 +4,8 @@ #include "cpu_features_macros.h" #ifdef CPU_FEATURES_ARCH_AARCH64 -#if (defined(CPU_FEATURES_OS_FREEBSD) || defined(CPU_FEATURES_OS_LINUX) || \ - defined(CPU_FEATURES_OS_ANDROID)) +#if (defined(CPU_FEATURES_OS_FREEBSD) || defined(CPU_FEATURES_OS_OPENBSD) || \ + defined(CPU_FEATURES_OS_LINUX) || defined(CPU_FEATURES_OS_ANDROID)) #if (defined(CPU_FEATURES_COMPILER_GCC) || defined(CPU_FEATURES_COMPILER_CLANG)) #include "internal/cpuid_aarch64.h" @@ -16,9 +16,7 @@ uint64_t GetMidrEl1(void) { uint64_t midr_el1; - // clang-format off __asm("mrs %0, MIDR_EL1" : "=r"(midr_el1)); - // clang-format on return midr_el1; } #endif // CPU_FEATURES_MOCK_CPUID_AARCH64 @@ -27,6 +25,6 @@ uint64_t GetMidrEl1(void) #error "Unsupported compiler, aarch64 cpuid requires either GCC or Clang." #endif // (defined(CPU_FEATURES_COMPILER_GCC) || // defined(CPU_FEATURES_COMPILER_CLANG)) -#endif // (defined(CPU_FEATURES_OS_FREEBSD) || defined(CPU_FEATURES_OS_LINUX) - // || defined(CPU_FEATURES_OS_ANDROID)) +#endif // (defined(CPU_FEATURES_OS_FREEBSD) || defined(CPU_FEATURES_OS_OPENBSD) + // || defined(CPU_FEATURES_OS_LINUX) || defined(CPU_FEATURES_OS_ANDROID)) #endif // CPU_FEATURES_ARCH_AARCH64 \ No newline at end of file diff --git a/src/algorithms/libs/volk_gnsssdr_module/volk_gnsssdr/cpu_features/src/impl_aarch64_freebsd.c b/src/algorithms/libs/volk_gnsssdr_module/volk_gnsssdr/cpu_features/src/impl_aarch64_freebsd_or_openbsd.c similarity index 86% rename from src/algorithms/libs/volk_gnsssdr_module/volk_gnsssdr/cpu_features/src/impl_aarch64_freebsd.c rename to src/algorithms/libs/volk_gnsssdr_module/volk_gnsssdr/cpu_features/src/impl_aarch64_freebsd_or_openbsd.c index 7360da790..3a63c35fc 100644 --- a/src/algorithms/libs/volk_gnsssdr_module/volk_gnsssdr/cpu_features/src/impl_aarch64_freebsd.c +++ b/src/algorithms/libs/volk_gnsssdr_module/volk_gnsssdr/cpu_features/src/impl_aarch64_freebsd_or_openbsd.c @@ -4,7 +4,7 @@ #include "cpu_features_macros.h" #ifdef CPU_FEATURES_ARCH_AARCH64 -#ifdef CPU_FEATURES_OS_FREEBSD +#if defined(CPU_FEATURES_OS_FREEBSD) || defined(CPU_FEATURES_OS_OPENBSD) #include "cpuinfo_aarch64.h" #include "internal/cpuid_aarch64.h" @@ -35,5 +35,5 @@ Aarch64Info GetAarch64Info(void) return info; } -#endif // CPU_FEATURES_OS_FREEBSD -#endif // CPU_FEATURES_ARCH_AARCH64 +#endif // CPU_FEATURES_OS_FREEBSD || CPU_FEATURES_OS_OPENBSD +#endif // CPU_FEATURES_ARCH_AARCH64 \ No newline at end of file diff --git a/src/algorithms/libs/volk_gnsssdr_module/volk_gnsssdr/cpu_features/src/utils/list_cpu_features.c b/src/algorithms/libs/volk_gnsssdr_module/volk_gnsssdr/cpu_features/src/utils/list_cpu_features.c index fdbb1ba51..a559b4d78 100644 --- a/src/algorithms/libs/volk_gnsssdr_module/volk_gnsssdr/cpu_features/src/utils/list_cpu_features.c +++ b/src/algorithms/libs/volk_gnsssdr_module/volk_gnsssdr/cpu_features/src/utils/list_cpu_features.c @@ -148,7 +148,11 @@ static Node* CreatePrintfString(const char* format, ...) const int written = vsnprintf(ptr, gBumpAllocator.size, format, arglist); va_end(arglist); if (written < 0 || written >= (int)gBumpAllocator.size) internal_error(); - return CreateConstantString((char*)BA_Bump(written)); + // `vsnprintf` does not set `\0` when no characters are to be written. + if (written == 0) *ptr = '\0'; + // `vsnprintf` returns the number of printed characters excluding `\0`. + const int null_terminated_written = written + 1; + return CreateConstantString((char*)BA_Bump(null_terminated_written)); } // Adds a string node. diff --git a/src/algorithms/libs/volk_gnsssdr_module/volk_gnsssdr/cpu_features/test/CMakeLists.txt b/src/algorithms/libs/volk_gnsssdr_module/volk_gnsssdr/cpu_features/test/CMakeLists.txt index 71ae6527c..01a67a026 100644 --- a/src/algorithms/libs/volk_gnsssdr_module/volk_gnsssdr/cpu_features/test/CMakeLists.txt +++ b/src/algorithms/libs/volk_gnsssdr_module/volk_gnsssdr/cpu_features/test/CMakeLists.txt @@ -28,7 +28,7 @@ target_link_libraries(stack_line_reader_for_test string_view filesystem_for_test add_library(all_libraries ../src/hwcaps.c ../src/hwcaps_linux_or_android.c - ../src/hwcaps_freebsd.c + ../src/hwcaps_freebsd_or_openbsd.c ../src/stack_line_reader.c) target_link_libraries(all_libraries hwcaps_for_testing stack_line_reader string_view) @@ -84,7 +84,7 @@ if(PROCESSOR_IS_AARCH64) ../src/impl_aarch64_linux_or_android.c ../src/impl_aarch64_windows.c ../src/impl_aarch64_macos_or_iphone.c - ../src/impl_aarch64_freebsd.c + ../src/impl_aarch64_freebsd_or_openbsd.c ) if(APPLE) target_compile_definitions(cpuinfo_aarch64_test PUBLIC CPU_FEATURES_MOCK_SYSCTL_AARCH64) diff --git a/src/algorithms/libs/volk_gnsssdr_module/volk_gnsssdr/cpu_features/test/cpuinfo_aarch64_test.cc b/src/algorithms/libs/volk_gnsssdr_module/volk_gnsssdr/cpu_features/test/cpuinfo_aarch64_test.cc index 637cb676b..c3f0dfc71 100644 --- a/src/algorithms/libs/volk_gnsssdr_module/volk_gnsssdr/cpu_features/test/cpuinfo_aarch64_test.cc +++ b/src/algorithms/libs/volk_gnsssdr_module/volk_gnsssdr/cpu_features/test/cpuinfo_aarch64_test.cc @@ -9,15 +9,15 @@ #if defined(CPU_FEATURES_OS_WINDOWS) #include "internal/windows_utils.h" #endif // CPU_FEATURES_OS_WINDOWS -#if defined(CPU_FEATURES_OS_FREEBSD) || defined(CPU_FEATURES_OS_LINUX) +#if defined(CPU_FEATURES_OS_FREEBSD) || defined(CPU_FEATURES_OS_OPENBSD) || defined(CPU_FEATURES_OS_LINUX) #include "internal/cpuid_aarch64.h" -#endif // defined(CPU_FEATURES_OS_FREEBSD) || defined(CPU_FEATURES_OS_LINUX) +#endif // defined(CPU_FEATURES_OS_FREEBSD) || defined(CPU_FEATURES_OS_OPENBSD) || defined(CPU_FEATURES_OS_LINUX) namespace cpu_features { class FakeCpuAarch64 { -#if defined(CPU_FEATURES_OS_FREEBSD) || defined(CPU_FEATURES_OS_LINUX) +#if defined(CPU_FEATURES_OS_FREEBSD) || defined(CPU_FEATURES_OS_OPENBSD) || defined(CPU_FEATURES_OS_LINUX) public: uint64_t GetMidrEl1() const { return _midr_el1; } @@ -87,11 +87,8 @@ static FakeCpuAarch64& cpu() } // Define OS dependent mock functions -#if defined(CPU_FEATURES_OS_FREEBSD) || defined(CPU_FEATURES_OS_LINUX) -extern "C" uint64_t GetMidrEl1(void) -{ - return cpu().GetMidrEl1(); -} +#if defined(CPU_FEATURES_OS_FREEBSD) || defined(CPU_FEATURES_OS_OPENBSD) || defined(CPU_FEATURES_OS_LINUX) +extern "C" uint64_t GetMidrEl1(void) { return cpu().GetMidrEl1(); } #elif defined(CPU_FEATURES_OS_MACOS) extern "C" bool GetDarwinSysCtlByName(const char* name) { @@ -148,7 +145,7 @@ TEST_F(CpuidAarch64Test, Aarch64FeaturesEnum) } // AT_HWCAP tests -#if defined(CPU_FEATURES_OS_LINUX) || defined(CPU_FEATURES_OS_FREEBSD) +#if defined(CPU_FEATURES_OS_LINUX) || defined(CPU_FEATURES_OS_FREEBSD) || defined(CPU_FEATURES_OS_OPENBSD) TEST_F(CpuidAarch64Test, FromHardwareCap) { ResetHwcaps(); @@ -218,7 +215,7 @@ TEST_F(CpuidAarch64Test, FromHardwareCap2) EXPECT_FALSE(info.features.dgh); EXPECT_FALSE(info.features.rng); } -#endif // defined(CPU_FEATURES_OS_LINUX) || defined(CPU_FEATURES_OS_FREEBSD) +#endif // defined(CPU_FEATURES_OS_LINUX) || defined(CPU_FEATURES_OS_FREEBSD) || defined(CPU_FEATURES_OS_OPENBSD) // OS dependent tests #if defined(CPU_FEATURES_OS_LINUX) @@ -431,7 +428,7 @@ TEST_F(CpuidAarch64Test, WINDOWS_AARCH64_RPI4) EXPECT_FALSE(info.features.jscvt); EXPECT_FALSE(info.features.lrcpc); } -#elif defined(CPU_FEATURES_OS_FREEBSD) +#elif defined(CPU_FEATURES_OS_FREEBSD) || defined(CPU_FEATURES_OS_OPENBSD) TEST_F(CpuidAarch64Test, MrsMidrEl1_RPI4) { ResetHwcaps(); @@ -465,4 +462,4 @@ TEST_F(CpuidAarch64Test, MrsMidrEl1_RPI4) } #endif // CPU_FEATURES_OS_FREEBSD } // namespace -} // namespace cpu_features +} // namespace cpu_features \ No newline at end of file