From f42005ce5d12c11ed606b5c7dc246259409d49f0 Mon Sep 17 00:00:00 2001 From: momo5502 Date: Sat, 22 Mar 2025 17:23:53 +0100 Subject: [PATCH 1/4] Add avx2 support --- CMakeLists.txt | 1 + cmake/compiler-env.cmake | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index 2168ae43..f430a56c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -2,6 +2,7 @@ cmake_minimum_required(VERSION 3.26.4) ########################################## +option(MOMO_ENABLE_AVX2 "Enable AVX2 support" ON) option(MOMO_ENABLE_SANITIZER "Enable sanitizer" OFF) option(MOMO_ENABLE_CLANG_TIDY "Enable clang-tidy checks" OFF) option(MOMO_ENABLE_RUST_CODE "Enable code parts written in rust" ON) diff --git a/cmake/compiler-env.cmake b/cmake/compiler-env.cmake index 299ee317..c32645a6 100644 --- a/cmake/compiler-env.cmake +++ b/cmake/compiler-env.cmake @@ -1,4 +1,5 @@ include_guard() +include(CheckCXXCompilerFlag) ########################################## # System identification @@ -114,6 +115,24 @@ endif() ########################################## +if(MOMO_ENABLE_AVX2) + set(CMAKE_REQUIRED_FLAGS -Werror) + check_cxx_compiler_flag(-mavx2 COMPILER_SUPPORTS_MAVX2) + set(CMAKE_REQUIRED_FLAGS "") + + check_cxx_compiler_flag(/arch:AVX2 COMPILER_SUPPORTS_ARCH_AVX2) + + if(COMPILER_SUPPORTS_MAVX2) + momo_add_c_and_cxx_compile_options(-mavx2) + endif() + + if (COMPILER_SUPPORTS_ARCH_AVX2) + momo_add_c_and_cxx_compile_options(/arch:AVX2) + endif() +endif() + +########################################## + if(MOMO_ENABLE_SANITIZER) momo_add_c_and_cxx_compile_options(-fsanitize=address) add_link_options(-fsanitize=address) From b701d44e904b80352f5d9c5821b1b33f09d9dafc Mon Sep 17 00:00:00 2001 From: momo5502 Date: Sat, 22 Mar 2025 18:02:02 +0100 Subject: [PATCH 2/4] Disable AVX2 for samples --- cmake/utils.cmake | 14 +++++++++++++- src/samples/CMakeLists.txt | 10 ++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/cmake/utils.cmake b/cmake/utils.cmake index ee8c8987..4c9dc09b 100644 --- a/cmake/utils.cmake +++ b/cmake/utils.cmake @@ -109,12 +109,16 @@ macro(momo_target_remove_compile_option target option) get_target_property(target_flags ${target} COMPILE_OPTIONS) if(target_flags) list(REMOVE_ITEM target_flags ${option}) + list(REMOVE_ITEM target_flags "$<$:${option}>") + list(REMOVE_ITEM target_flags "$<$:${option}>") set_target_properties(${target} PROPERTIES COMPILE_OPTIONS "${target_flags}") endif() get_target_property(target_interface_flags ${target} INTERFACE_COMPILE_OPTIONS) if(target_interface_flags) list(REMOVE_ITEM target_interface_flags ${option}) + list(REMOVE_ITEM target_interface_flags "$<$:${option}>") + list(REMOVE_ITEM target_interface_flags "$<$:${option}>") set_target_properties(${target} PROPERTIES INTERFACE_COMPILE_OPTIONS "${target_interface_flags}") endif() endmacro() @@ -122,13 +126,21 @@ endmacro() ########################################## macro(momo_target_remove_compile_options target) - foreach(option ${ARGV}) + foreach(option ${ARGN}) momo_target_remove_compile_option(${target} ${option}) endforeach() endmacro() ########################################## +function(momo_targets_remove_compile_options targets) + foreach(target ${targets}) + momo_target_remove_compile_options(${target} ${ARGN}) + endforeach() +endfunction() + +########################################## + function(momo_add_compile_options language) foreach(option ${ARGN}) add_compile_options( diff --git a/src/samples/CMakeLists.txt b/src/samples/CMakeLists.txt index b9067a51..d4839797 100644 --- a/src/samples/CMakeLists.txt +++ b/src/samples/CMakeLists.txt @@ -1,2 +1,12 @@ +momo_get_all_targets(EXISTING_TARGETS) + +########################################## + add_subdirectory(bad-sample) add_subdirectory(test-sample) + +########################################## + +momo_get_all_targets(ALL_TARGETS) +momo_list_difference("${ALL_TARGETS}" "${EXISTING_TARGETS}" SAMPLE_TARGETS) +momo_targets_remove_compile_options("${SAMPLE_TARGETS}" /arch:AVX2 -mavx2) \ No newline at end of file From 35092b9cdfffb51702e43c2e16cba3438ec643e9 Mon Sep 17 00:00:00 2001 From: momo5502 Date: Sat, 12 Apr 2025 08:52:24 +0200 Subject: [PATCH 3/4] Use test-sample as analysis sample --- .github/workflows/build.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 1040725b..a9e1f9b0 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -340,7 +340,7 @@ jobs: env: EMULATOR_ROOT: ${{github.workspace}}/build/${{matrix.preset}}/artifacts/root EMULATOR_VERBOSE: ${{ github.event.inputs.verbose }} - ANALYSIS_SAMPLE: ${{github.workspace}}/build/${{matrix.preset}}/artifacts/dump-apiset.exe + ANALYSIS_SAMPLE: ${{github.workspace}}/build/${{matrix.preset}}/artifacts/test-sample.exe win-test: name: Windows Test From fb644b8bf13d5c0705d321e2c8cd5e6a8746f887 Mon Sep 17 00:00:00 2001 From: momo5502 Date: Sat, 12 Apr 2025 08:54:18 +0200 Subject: [PATCH 4/4] Disable avx2 for android --- cmake/compiler-env.cmake | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmake/compiler-env.cmake b/cmake/compiler-env.cmake index c32645a6..9238fee4 100644 --- a/cmake/compiler-env.cmake +++ b/cmake/compiler-env.cmake @@ -115,7 +115,7 @@ endif() ########################################## -if(MOMO_ENABLE_AVX2) +if(MOMO_ENABLE_AVX2 AND NOT (CMAKE_SYSTEM_NAME STREQUAL "Android")) set(CMAKE_REQUIRED_FLAGS -Werror) check_cxx_compiler_flag(-mavx2 COMPILER_SUPPORTS_MAVX2) set(CMAKE_REQUIRED_FLAGS "")