From f42005ce5d12c11ed606b5c7dc246259409d49f0 Mon Sep 17 00:00:00 2001 From: momo5502 Date: Sat, 22 Mar 2025 17:23:53 +0100 Subject: [PATCH] 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)