32: Set AVX and AVX2 flags using CMake checks (#34)

* 32: Set mavx and mavx2 based on CMake checks
* 32: Update flags for Intel compiler
* Fix: AVX2 instead of AVX__2

Co-authored-by: Bram Veenboer <bram.veenboer@gmail.com>
Co-authored-by: lukken <lukken@astron.nl>
This commit is contained in:
Dantali0n
2025-10-29 09:18:43 +01:00
committed by GitHub
parent 5f00c5d304
commit 58bc640d6d
2 changed files with 28 additions and 0 deletions

View File

@@ -2,6 +2,24 @@ include(FetchContent)
include(FindAVX)
add_library(trigdx reference.cpp lookup.cpp)
if(HAVE_AVX2)
target_compile_definitions(trigdx PUBLIC HAVE_AVX2)
if(CMAKE_CXX_COMPILER_ID STREQUAL "Intel" OR CMAKE_CXX_COMPILER_ID STREQUAL
"IntelLLVM")
target_compile_options(trigdx PUBLIC -xCORE-AVX2)
else()
target_compile_options(trigdx PUBLIC -mavx2)
endif()
elseif(HAVE_AVX)
target_compile_definitions(trigdx PUBLIC HAVE_AVX)
if(CMAKE_CXX_COMPILER_ID STREQUAL "Intel" OR CMAKE_CXX_COMPILER_ID STREQUAL
"IntelLLVM")
target_compile_options(trigdx PUBLIC -xAVX)
else()
target_compile_options(trigdx PUBLIC -mavx)
endif()
endif()
target_include_directories(trigdx PUBLIC ${PROJECT_SOURCE_DIR}/include)
if(HAVE_AVX)

View File

@@ -6,6 +6,16 @@
#include "trigdx/lookup_avx.hpp"
#if defined(HAVE_AVX) && !defined(__AVX__)
static_assert(HAVE_AVX == 0, "__AVX__ should be defined when HAVE_AVX is "
"defined");
#endif
#if defined(HAVE_AVX2) && !defined(__AVX2__)
static_assert(HAVE_AVX2 == 0, "__AVX2__ should be defined when HAVE_AVX2 is "
"defined");
#endif
template <std::size_t NR_SAMPLES> struct LookupAVXBackend<NR_SAMPLES>::Impl {
std::vector<float> lookup;
static constexpr std::size_t MASK = NR_SAMPLES - 1;