Skip to content

Commit

Permalink
Add AVX for windows
Browse files Browse the repository at this point in the history
  • Loading branch information
larshg committed Mar 3, 2021
1 parent 04de594 commit d64a7da
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 1 deletion.
8 changes: 7 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,12 @@ if(PCL_ENABLE_SSE AND "${CMAKE_CXX_FLAGS}" STREQUAL "${CMAKE_CXX_FLAGS_DEFAULT}"
PCL_CHECK_FOR_SSE()
endif()

# check for AVX flags for windows
if(PCL_ENABLE_AVX AND "${CMAKE_CXX_FLAGS}" STREQUAL "${CMAKE_CXX_FLAGS_DEFAULT}")
include("${PCL_SOURCE_DIR}/cmake/pcl_find_avx.cmake")
PCL_CHECK_FOR_AVX()
endif()

# ---[ Unix/Darwin/Windows specific flags
if(CMAKE_COMPILER_IS_GNUCXX)
if("${CMAKE_CXX_FLAGS}" STREQUAL "${CMAKE_CXX_FLAGS_DEFAULT}")
Expand Down Expand Up @@ -127,7 +133,7 @@ if(CMAKE_COMPILER_IS_MSVC)
add_compile_options(/bigobj)

if("${CMAKE_CXX_FLAGS}" STREQUAL "${CMAKE_CXX_FLAGS_DEFAULT}")
string(APPEND CMAKE_CXX_FLAGS " /fp:precise /wd4800 /wd4521 /wd4251 /wd4275 /wd4305 /wd4355 ${SSE_FLAGS_STR}")
string(APPEND CMAKE_CXX_FLAGS " /fp:precise /wd4800 /wd4521 /wd4251 /wd4275 /wd4305 /wd4355 ${SSE_FLAGS_STR} ${AVX_FLAGS}")

# Add extra code generation/link optimizations
if(CMAKE_MSVC_CODE_LINK_OPTIMIZATION AND (NOT BUILD_CUDA) AND (NOT BUILD_GPU))
Expand Down
37 changes: 37 additions & 0 deletions cmake/pcl_find_avx.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
###############################################################################
# Check for the presence of AVX and figure out the flags to use for it.
function(PCL_CHECK_FOR_AVX)
set(AVX_FLAGS)

include(CheckCXXSourceRuns)

check_cxx_source_runs("
#include <immintrin.h>
int main()
{
__m256i a = {0};
a = _mm256_abs_epi16(a);
return 0;
}"
HAVE_AVX2)

if(NOT HAVE_AVX2)
check_cxx_source_runs("
#include <immintrin.h>
int main()
{
__m256 a;
a = _mm256_set1_ps(0);
return 0;
}"
HAVE_AVX)
endif()

if(MSVC)
if(HAVE_AVX2)
set(AVX_FLAGS "/arch:AVX2" PARENT_SCOPE)
elseif(HAVE_AVX)
set(AVX_FLAGS "/arch:AVX" PARENT_SCOPE)
endif()
endif()
endfunction()
6 changes: 6 additions & 0 deletions cmake/pcl_options.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,12 @@ mark_as_advanced(PCL_NO_PRECOMPILE)
option(PCL_ENABLE_SSE "Enable or Disable SSE optimizations." ON)
mark_as_advanced(PCL_ENABLE_SSE)

if(WIN32)
# Enable or Disable the check for AVX optimizations
option(PCL_ENABLE_AVX "Enable or Disable AVX optimizations." ON)
mark_as_advanced(PCL_ENABLE_AVX)
endif()

# Allow the user to enable compiler cache
option(PCL_ENABLE_CCACHE "Enable using compiler cache for compilation" OFF)
mark_as_advanced(PCL_ENABLE_CCACHE)
Expand Down

0 comments on commit d64a7da

Please sign in to comment.