From 23b5025765b834c0ff2ab48de4f28623075fae58 Mon Sep 17 00:00:00 2001 From: Aous Naman Date: Wed, 22 May 2024 16:38:50 +1000 Subject: [PATCH] Better preprocessor directives for ARM, supports 32 and 64 bits. --- src/core/common/ojph_arch.h | 8 ++++++ src/core/common/ojph_version.h | 2 +- src/core/others/ojph_arch.cpp | 45 +++++++++++++++++++++++++--------- subprojects/js/CMakeLists.txt | 4 +-- 4 files changed, 45 insertions(+), 14 deletions(-) diff --git a/src/core/common/ojph_arch.h b/src/core/common/ojph_arch.h index 1b61d0c0..947f25b0 100644 --- a/src/core/common/ojph_arch.h +++ b/src/core/common/ojph_arch.h @@ -140,6 +140,14 @@ namespace ojph { X86_CPU_EXT_LEVEL_AVX512 = 11, }; + enum : int { + ARM_CPU_EXT_LEVEL_GENERIC = 0, + ARM_CPU_EXT_LEVEL_NEON = 1, + ARM_CPU_EXT_LEVEL_ASIMD = 1, + ARM_CPU_EXT_LEVEL_SVE = 2, + ARM_CPU_EXT_LEVEL_SVE2 = 3, + }; + ///////////////////////////////////////////////////////////////////////////// static inline ui32 population_count(ui32 val) { diff --git a/src/core/common/ojph_version.h b/src/core/common/ojph_version.h index f4474d36..af3e398d 100644 --- a/src/core/common/ojph_version.h +++ b/src/core/common/ojph_version.h @@ -35,4 +35,4 @@ #define OPENJPH_VERSION_MAJOR 0 #define OPENJPH_VERSION_MINOR 13 -#define OPENJPH_VERSION_PATCH 1 +#define OPENJPH_VERSION_PATCH 2 diff --git a/src/core/others/ojph_arch.cpp b/src/core/others/ojph_arch.cpp index 8981e649..22b41348 100644 --- a/src/core/others/ojph_arch.cpp +++ b/src/core/others/ojph_arch.cpp @@ -164,24 +164,47 @@ namespace ojph { #ifndef OJPH_OS_LINUX //Windows/Apple/Android bool init_cpu_ext_level(int& level) { - level = 1; + level = ARM_CPU_EXT_LEVEL_ASIMD; return true; } #else // Linux - #include - #include + #ifdef defined(__aarch64__) || defined(_M_ARM64) // 64 bit ARM - bool init_cpu_ext_level(int& level) { - unsigned long hwcaps= getauxval(AT_HWCAP); + #include + #include - if (hwcaps & HWCAP_NEON) - level = 1; - else - level = 0; - return true; - } + bool init_cpu_ext_level(int& level) { + unsigned long hwcaps = getauxval(AT_HWCAP); + unsigned long hwcaps2 = getauxval(AT_HWCAP2); + + level = ARM_CPU_EXT_LEVEL_GENERIC; + if (hwcaps & HWCAP_ASIMD) { + level = ARM_CPU_EXT_LEVEL_ASIMD; + if (hwcaps & HWCAP_SVE) { + level = ARM_CPU_EXT_LEVEL_SVE; + if (hwcaps2 & HWCAP2_SVE2) + level = ARM_CPU_EXT_LEVEL_SVE2; + } + } + return true; + } + + #else // ARM 32 bit + + #include + #include + + bool init_cpu_ext_level(int& level) { + unsigned long hwcaps = getauxval(AT_HWCAP); + level = ARM_CPU_EXT_LEVEL_GENERIC; + if (hwcaps & HWCAP_NEON) + level = ARM_CPU_EXT_LEVEL_NEON; + return true; + } + + #endif // end of ARM 64 bit #endif diff --git a/subprojects/js/CMakeLists.txt b/subprojects/js/CMakeLists.txt index 1f79418c..ff7162b3 100644 --- a/subprojects/js/CMakeLists.txt +++ b/subprojects/js/CMakeLists.txt @@ -9,11 +9,11 @@ set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/../html) add_subdirectory("../.." openjph EXCLUDE_FROM_ALL) add_executable(libopenjph "src/ojph_wrapper.cpp") -set_target_properties(libopenjph PROPERTIES SUFFIX ".js" LINK_FLAGS "-O3 -s WASM=1 -s EXPORT_ES6=1 -s MODULARIZE=1 -s ENVIRONMENT=web -s EXPORTED_FUNCTIONS=[_free,_malloc] -s EXPORTED_RUNTIME_METHODS=[ccall,cwrap,writeArrayToMemory] -s NO_EXIT_RUNTIME=1 -s ALLOW_MEMORY_GROWTH=1") +set_target_properties(libopenjph PROPERTIES SUFFIX ".js" LINK_FLAGS "-O3 -s WASM=1 -s EXPORT_ES6=1 -s MODULARIZE=1 -s ENVIRONMENT=web -s EXPORTED_FUNCTIONS=[_free,_malloc] -s EXPORTED_RUNTIME_METHODS=[ccall,cwrap,writeArrayToMemory] -s NO_EXIT_RUNTIME=1 -s ALLOW_MEMORY_GROWTH=1 -s INITIAL_MEMORY=134217728") target_link_libraries(libopenjph PRIVATE openjph) add_executable(libopenjph_simd "src/ojph_wrapper.cpp" ) target_compile_options(libopenjph_simd PRIVATE -DOJPH_ENABLE_WASM_SIMD -msimd128) -set_target_properties(libopenjph_simd PROPERTIES SUFFIX ".js" LINK_FLAGS "-O3 -s WASM=1 -s EXPORT_ES6=1 -s MODULARIZE=1 -s ENVIRONMENT=web -s EXPORTED_FUNCTIONS=[_free,_malloc] -s EXPORTED_RUNTIME_METHODS=[ccall,cwrap,writeArrayToMemory] -s NO_EXIT_RUNTIME=1 -s ALLOW_MEMORY_GROWTH=1") +set_target_properties(libopenjph_simd PROPERTIES SUFFIX ".js" LINK_FLAGS "-O3 -s WASM=1 -s EXPORT_ES6=1 -s MODULARIZE=1 -s ENVIRONMENT=web -s EXPORTED_FUNCTIONS=[_free,_malloc] -s EXPORTED_RUNTIME_METHODS=[ccall,cwrap,writeArrayToMemory] -s NO_EXIT_RUNTIME=1 -s ALLOW_MEMORY_GROWTH=1 -s INITIAL_MEMORY=134217728") target_link_libraries(libopenjph_simd PRIVATE openjphsimd)