Add AVX2 support (#195)

This commit is contained in:
Maurice Heumann
2025-04-12 09:11:18 +02:00
committed by GitHub
5 changed files with 44 additions and 2 deletions

View File

@@ -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

View File

@@ -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)

View File

@@ -1,4 +1,5 @@
include_guard()
include(CheckCXXCompilerFlag)
##########################################
# System identification
@@ -114,6 +115,24 @@ endif()
##########################################
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 "")
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)

View File

@@ -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 "$<$<COMPILE_LANGUAGE:C>:${option}>")
list(REMOVE_ITEM target_flags "$<$<COMPILE_LANGUAGE:CXX>:${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 "$<$<COMPILE_LANGUAGE:C>:${option}>")
list(REMOVE_ITEM target_interface_flags "$<$<COMPILE_LANGUAGE:CXX>:${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(

View File

@@ -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)