Skip to content

Add CMake support + M1 support via SIMDE. #3

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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)
19 changes: 11 additions & 8 deletions VM_SSEFunc.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,22 +35,25 @@
#pragma warning(disable:4799)
#endif

#define CPU_HAS_SIMD_INSTR 1
#define VM_SSE_STYLE 1
#include <simde/x86/sse.h>
#include <simde/x86/sse4.1.h>

#include <emmintrin.h>
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 <smmintrin.h>
#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.
Expand Down
48 changes: 48 additions & 0 deletions cmake/recipes/onetbb.cmake
Original file line number Diff line number Diff line change
@@ -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()
22 changes: 22 additions & 0 deletions cmake/recipes/simde.cmake
Original file line number Diff line number Diff line change
@@ -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)