Skip to content

Commit

Permalink
Better preprocessor directives for ARM, supports 32 and 64 bits.
Browse files Browse the repository at this point in the history
  • Loading branch information
aous72 committed May 22, 2024
1 parent 2754122 commit 23b5025
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 14 deletions.
8 changes: 8 additions & 0 deletions src/core/common/ojph_arch.h
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down
2 changes: 1 addition & 1 deletion src/core/common/ojph_version.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,4 @@

#define OPENJPH_VERSION_MAJOR 0
#define OPENJPH_VERSION_MINOR 13
#define OPENJPH_VERSION_PATCH 1
#define OPENJPH_VERSION_PATCH 2
45 changes: 34 additions & 11 deletions src/core/others/ojph_arch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 <sys/auxv.h>
#include <asm/hwcap.h>
#ifdef defined(__aarch64__) || defined(_M_ARM64) // 64 bit ARM

bool init_cpu_ext_level(int& level) {
unsigned long hwcaps= getauxval(AT_HWCAP);
#include <sys/auxv.h>
#include <asm/hwcap.h>

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 <sys/auxv.h>
#include <asm/hwcap.h>

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

Expand Down
4 changes: 2 additions & 2 deletions subprojects/js/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)

0 comments on commit 23b5025

Please sign in to comment.