From cd81346bc8e31a5a77330b841d001e0efbf12f7f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Je=CC=81re=CC=81mie=20Dumas?= Date: Thu, 26 Aug 2021 14:40:51 -0700 Subject: [PATCH] Add CMake support + M1 support via SIMDE. --- CMakeLists.txt | 20 ++++++++++++++++ VM_SSEFunc.h | 19 ++++++++------- cmake/recipes/onetbb.cmake | 48 ++++++++++++++++++++++++++++++++++++++ cmake/recipes/simde.cmake | 22 +++++++++++++++++ 4 files changed, 101 insertions(+), 8 deletions(-) create mode 100644 CMakeLists.txt create mode 100644 cmake/recipes/onetbb.cmake create mode 100644 cmake/recipes/simde.cmake diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..64ac793 --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,20 @@ +cmake_minimum_required(VERSION 3.16) + +project(WindingNumber) + +list(PREPEND CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake/recipes) + +# WindingNumber library +file(GLOB SRC_FILES *.cpp *.h ) +add_library(WindingNumber ${SRC_FILES}) +add_library(WindingNumber::WindingNumber ALIAS WindingNumber) + +target_include_directories(WindingNumber PUBLIC .) + +include(onetbb) +include(simde) +target_link_libraries(WindingNumber PUBLIC TBB::tbb simde::simde) + +set_target_properties(WindingNumber PROPERTIES POSITION_INDEPENDENT_CODE ON) + +target_compile_features(WindingNumber PUBLIC cxx_std_11) diff --git a/VM_SSEFunc.h b/VM_SSEFunc.h index 464df84..063611e 100644 --- a/VM_SSEFunc.h +++ b/VM_SSEFunc.h @@ -35,22 +35,25 @@ #pragma warning(disable:4799) #endif -#define CPU_HAS_SIMD_INSTR 1 -#define VM_SSE_STYLE 1 +#include +#include -#include -typedef __m128 v4sf; -typedef __m128i v4si; +typedef __m128 v4sf; +typedef __m128i v4si; -#if defined(__SSE4_1__) +#define CPU_HAS_SIMD_INSTR 1 +#define VM_SSE_STYLE 1 #define VM_SSE41_STYLE 1 -#include -#endif #if defined(_MSC_VER) #pragma warning(pop) #endif +// Recent GCC define the macro in x86intrin.h +#ifndef _MM_MK_INSERTPS_NDX +#define _MM_MK_INSERTPS_NDX(srcField, dstField, zeroMask) (((srcField)<<6) | ((dstField)<<4) | (zeroMask)) +#endif + // Plain casting (no conversion) // MSVC has problems casting between __m128 and __m128i, so we implement a // custom casting routine specifically for windows. diff --git a/cmake/recipes/onetbb.cmake b/cmake/recipes/onetbb.cmake new file mode 100644 index 0000000..ac559b5 --- /dev/null +++ b/cmake/recipes/onetbb.cmake @@ -0,0 +1,48 @@ +if(TARGET TBB::tbb) + return() +endif() + +message(STATUS "Third-party: creating targets 'TBB::tbb'") + +include(FetchContent) +FetchContent_Declare( + tbb + GIT_REPOSITORY https://github.com/oneapi-src/oneTBB.git + GIT_TAG 1098f48187c718ef782b0aa01861184886906cf4 +) + +option(TBB_TEST "Enable testing" OFF) +option(TBB_EXAMPLES "Enable examples" OFF) +option(TBB_STRICT "Treat compiler warnings as errors" ON) +option(TBB_PREFER_STATIC "Use the static version of TBB for the alias target" ON) +unset(TBB_DIR CACHE) + +set(OLD_BUILD_SHARED_LIBS ${BUILD_SHARED_LIBS}) +if(TBB_PREFER_STATIC) + set(BUILD_SHARED_LIBS OFF CACHE STRING "Build shared library" FORCE) +else() + set(BUILD_SHARED_LIBS ON CACHE STRING "Build shared library" FORCE) +endif() + +set(CMAKE_INSTALL_DEFAULT_COMPONENT_NAME tbb) +FetchContent_MakeAvailable(tbb) + +set(BUILD_SHARED_LIBS ${OLD_BUILD_SHARED_LIBS} CACHE STRING "Build shared library" FORCE) + +if(NOT TARGET TBB::tbb) + message(FATAL_ERROR "TBB::tbb is still not defined!") +endif() + +foreach(name IN ITEMS tbb tbbmalloc tbbmalloc_proxy) + if(TARGET ${name}) + # Folder name for IDE + set_target_properties(${name} PROPERTIES FOLDER "third_party//tbb") + + # Force debug postfix for library name. Our pre-compiled MKL library expects "tbb12.dll" (without postfix). + set_target_properties(${name} PROPERTIES DEBUG_POSTFIX "") + + # Without this macro, TBB will explicitly link against "tbb12_debug.lib" in Debug configs. + # This is undesirable, since our pre-compiled version of MKL is linked against "tbb12.dll". + target_compile_definitions(${name} PUBLIC -D__TBB_NO_IMPLICIT_LINKAGE=1) + endif() +endforeach() diff --git a/cmake/recipes/simde.cmake b/cmake/recipes/simde.cmake new file mode 100644 index 0000000..32c868e --- /dev/null +++ b/cmake/recipes/simde.cmake @@ -0,0 +1,22 @@ +if(TARGET simde::simde) + return() +endif() + +message(STATUS "Third-party: creating target 'simde::simde'") + +include(FetchContent) +FetchContent_Declare( + simde + GIT_REPOSITORY https://github.com/simd-everywhere/simde.git + GIT_TAG 48edfa906d835525e2061fbf6062b7c326d66840 +) +FetchContent_MakeAvailable(simde) + +add_library(simde::simde INTERFACE IMPORTED GLOBAL) +target_include_directories(simde::simde INTERFACE "${simde_SOURCE_DIR}") + +# Enables native aliases. Not ideal but makes it easier to convert old code. +target_compile_definitions(simde::simde INTERFACE SIMDE_ENABLE_NATIVE_ALIASES) + +# Uncomment this line to ensure code can be compiled without native SIMD (i.e. emulates everything) +# target_compile_definitions(simde::simde INTERFACE SIMDE_NO_NATIVE)