Skip to content

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

Merged
Dantali0n merged 3 commits intomainfrom
32-set-avx-compile-flags
Oct 29, 2025
Merged

32: Set AVX and AVX2 flags using CMake checks#34
Dantali0n merged 3 commits intomainfrom
32-set-avx-compile-flags

Conversation

@Dantali0n
Copy link
Copy Markdown
Contributor

Closes: 32

This add the checks to enable avx and avx2

@Dantali0n
Copy link
Copy Markdown
Contributor Author

It would be nice if could run the linting checks locally easily. Especially given they fail on files I haven't touched.

@csbnw
Copy link
Copy Markdown
Contributor

csbnw commented Oct 9, 2025

You can simply run pre-commit run -a in the top-level directory of the repository to run the linters. I am not sure what happened to that file, but this PR fixes it. I suggest to merge it first, then rebase your branch onto the new main.

@csbnw csbnw self-requested a review October 9, 2025 10:04
@csbnw csbnw added the enhancement New feature or request label Oct 9, 2025
@Dantali0n Dantali0n force-pushed the 32-set-avx-compile-flags branch from 1c76cb9 to 3b574c5 Compare October 10, 2025 08:32
Comment thread src/CMakeLists.txt Outdated
@Dantali0n Dantali0n force-pushed the 32-set-avx-compile-flags branch from 3b574c5 to 81446de Compare October 22, 2025 17:40
@Dantali0n Dantali0n force-pushed the 32-set-avx-compile-flags branch from 81446de to 681bc16 Compare October 22, 2025 17:42
@Dantali0n
Copy link
Copy Markdown
Contributor Author

Seem icpx compiler doesn't understand CORE-AVX:

make[2]: *** Waiting for unfinished jobs....
icpx: error: language not recognized: 'CORE-AVX'
icpx: error: language not recognized: 'CORE-AVX'

@Dantali0n Dantali0n force-pushed the 32-set-avx-compile-flags branch from 681bc16 to ec65499 Compare October 28, 2025 07:21
@Dantali0n
Copy link
Copy Markdown
Contributor Author

Dantali0n commented Oct 28, 2025

icpx compiler wants flag -mavx for AVX not axCORE-AVX that is only for AVX2.

@Dantali0n Dantali0n requested a review from csbnw October 28, 2025 07:24
@csbnw
Copy link
Copy Markdown
Contributor

csbnw commented Oct 28, 2025

According to this documentation, it should be AVX for AVX and CORE-AVX2 for AVX2.
The Intel compiler doesn't like to have both flags, so i would suggest using:

diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index a152ef5..97ea8e1 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -2,11 +2,6 @@ include(FetchContent)
 include(FindAVX)
 add_library(trigdx reference.cpp lookup.cpp)
 
-if(HAVE_AVX)
-  target_compile_definitions(trigdx PUBLIC HAVE_AVX)
-  target_compile_options(trigdx PUBLIC -mavx)
-endif()
-
 if(HAVE_AVX2)
   target_compile_definitions(trigdx PUBLIC HAVE_AVX2)
   if(CMAKE_CXX_COMPILER_ID STREQUAL "Intel" OR CMAKE_CXX_COMPILER_ID STREQUAL
@@ -15,6 +10,14 @@ if(HAVE_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)

@Dantali0n Dantali0n force-pushed the 32-set-avx-compile-flags branch from ec65499 to 03723c2 Compare October 28, 2025 14:52
Comment thread src/lookup_avx.cpp Outdated
I swear I had fixed this already mmh

Co-authored-by: Bram Veenboer <bram.veenboer@gmail.com>
@Dantali0n Dantali0n requested a review from csbnw October 29, 2025 07:48
@Dantali0n Dantali0n changed the title 32: Set mavx and mavx2 based on CMake checks 32: Set AVX and AVX2 flags using CMake checks Oct 29, 2025
@Dantali0n Dantali0n merged commit 58bc640 into main Oct 29, 2025
10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants