Skip to content

Commit

Permalink
Fix NEON errors on GCC and prevent cmake build unsupported SIMD on ARM
Browse files Browse the repository at this point in the history
  • Loading branch information
mx989 authored and Auburn committed Nov 2, 2022
1 parent 31a065f commit 24fc843
Show file tree
Hide file tree
Showing 4 changed files with 248 additions and 126 deletions.
22 changes: 22 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,28 @@ cmake_minimum_required(VERSION 3.7.1)
project(FastNoise2 VERSION 0.9.6)
set(CMAKE_CXX_STANDARD 17)



if(CMAKE_SYSTEM_PROCESSOR STREQUAL armv7-a)

set(FASTSIMD_COMPILE_ARMV7 true)
set(FASTSIMD_COMPILE_ARM true)
set(FASTSIMD_COMPILE_HAVE_NEON true)

elseif(CMAKE_SYSTEM_PROCESSOR STREQUAL aarch64)

set(FASTSIMD_COMPILE_AARCH64 true)
set(FASTSIMD_COMPILE_ARM true)
set(FASTSIMD_COMPILE_HAVE_NEON true)

elseif(CMAKE_SYSTEM_PROCESSOR STREQUAL arm)

set(FASTSIMD_COMPILE_ARM true)

endif()



# determine whether this is a standalone project or included by other projects
if (NOT DEFINED FASTNOISE2_STANDALONE_PROJECT)
if (CMAKE_CURRENT_SOURCE_DIR STREQUAL CMAKE_SOURCE_DIR)
Expand Down
98 changes: 67 additions & 31 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,40 @@ list(APPEND FastSIMD_headers ${FastSIMD_inline})
list(APPEND FastSIMD_headers ${FastSIMD_include_inl})
list(APPEND FastSIMD_internal_headers ${FastSIMD_internal_inl})

set(FastSIMD_sources
FastSIMD/FastSIMD.cpp
FastSIMD/FastSIMD_Level_AVX2.cpp
FastSIMD/FastSIMD_Level_AVX512.cpp
FastSIMD/FastSIMD_Level_NEON.cpp
FastSIMD/FastSIMD_Level_Scalar.cpp
FastSIMD/FastSIMD_Level_SSE2.cpp
FastSIMD/FastSIMD_Level_SSE3.cpp
FastSIMD/FastSIMD_Level_SSE41.cpp
FastSIMD/FastSIMD_Level_SSE42.cpp
FastSIMD/FastSIMD_Level_SSSE3.cpp
)


if(FASTSIMD_COMPILE_HAVE_NEON)

set(FastSIMD_sources
FastSIMD/FastSIMD.cpp
FastSIMD/FastSIMD_Level_NEON.cpp
FastSIMD/FastSIMD_Level_Scalar.cpp
)

elseif(FASTSIMD_COMPILE_ARM)

set(FastSIMD_sources
FastSIMD/FastSIMD.cpp
FastSIMD/FastSIMD_Level_Scalar.cpp
)

else()

set(FastSIMD_sources
FastSIMD/FastSIMD.cpp
FastSIMD/FastSIMD_Level_AVX2.cpp
FastSIMD/FastSIMD_Level_AVX512.cpp
FastSIMD/FastSIMD_Level_Scalar.cpp
FastSIMD/FastSIMD_Level_SSE2.cpp
FastSIMD/FastSIMD_Level_SSE3.cpp
FastSIMD/FastSIMD_Level_SSE41.cpp
FastSIMD/FastSIMD_Level_SSE42.cpp
FastSIMD/FastSIMD_Level_SSSE3.cpp
)

endif()



file(GLOB FastNoise_headers "../include/FastNoise/*.h")
file(GLOB FastNoise_inl "../include/FastNoise/*.inl")
Expand Down Expand Up @@ -79,33 +101,47 @@ set_target_properties(FastNoise PROPERTIES
if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC")
target_compile_options(FastNoise PRIVATE /GL- /GS- /fp:fast /wd4251)

if(CMAKE_SIZEOF_VOID_P EQUAL 4)
set_source_files_properties(FastSIMD/FastSIMD_Level_Scalar.cpp PROPERTIES COMPILE_FLAGS "/arch:SSE")
set_source_files_properties(FastSIMD/FastSIMD_Level_SSE2.cpp PROPERTIES COMPILE_FLAGS "/arch:SSE2")
set_source_files_properties(FastSIMD/FastSIMD_Level_SSE3.cpp PROPERTIES COMPILE_FLAGS "/arch:SSE2")
set_source_files_properties(FastSIMD/FastSIMD_Level_SSSE3.cpp PROPERTIES COMPILE_FLAGS "/arch:SSE2")
set_source_files_properties(FastSIMD/FastSIMD_Level_SSE41.cpp PROPERTIES COMPILE_FLAGS "/arch:SSE2")
set_source_files_properties(FastSIMD/FastSIMD_Level_SSE42.cpp PROPERTIES COMPILE_FLAGS "/arch:SSE2")
if(NOT FASTSIMD_COMPILE_ARM)

if(CMAKE_SIZEOF_VOID_P EQUAL 4)
set_source_files_properties(FastSIMD/FastSIMD_Level_Scalar.cpp PROPERTIES COMPILE_FLAGS "/arch:SSE")
set_source_files_properties(FastSIMD/FastSIMD_Level_SSE2.cpp PROPERTIES COMPILE_FLAGS "/arch:SSE2")
set_source_files_properties(FastSIMD/FastSIMD_Level_SSE3.cpp PROPERTIES COMPILE_FLAGS "/arch:SSE2")
set_source_files_properties(FastSIMD/FastSIMD_Level_SSSE3.cpp PROPERTIES COMPILE_FLAGS "/arch:SSE2")
set_source_files_properties(FastSIMD/FastSIMD_Level_SSE41.cpp PROPERTIES COMPILE_FLAGS "/arch:SSE2")
set_source_files_properties(FastSIMD/FastSIMD_Level_SSE42.cpp PROPERTIES COMPILE_FLAGS "/arch:SSE2")
endif()
set_source_files_properties(FastSIMD/FastSIMD_Level_AVX2.cpp PROPERTIES COMPILE_FLAGS "/arch:AVX2")
set_source_files_properties(FastSIMD/FastSIMD_Level_AVX512.cpp PROPERTIES COMPILE_FLAGS "/arch:AVX512")

elseif(FASTSIMD_COMPILE_ARMV7)
set_source_files_properties(FastSIMD/FastSIMD_Level_NEON.cpp PROPERTIES COMPILE_FLAGS "/arch:NEON")
endif()
set_source_files_properties(FastSIMD/FastSIMD_Level_AVX2.cpp PROPERTIES COMPILE_FLAGS "/arch:AVX2")
set_source_files_properties(FastSIMD/FastSIMD_Level_AVX512.cpp PROPERTIES COMPILE_FLAGS "/arch:AVX512")

elseif("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang" OR "${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU" OR "${CMAKE_CXX_COMPILER_ID}" STREQUAL "AppleClang")
if(MSVC)
target_compile_options(FastNoise PRIVATE /GL- /GS- /fp:fast)
else()
target_compile_options(FastNoise PRIVATE -ffast-math -fno-stack-protector)
endif()

if(CMAKE_SIZEOF_VOID_P EQUAL 4 OR "${CMAKE_CXX_FLAGS}" MATCHES "-m32")
set_source_files_properties(FastSIMD/FastSIMD_Level_Scalar.cpp PROPERTIES COMPILE_FLAGS "-msse")
set_source_files_properties(FastSIMD/FastSIMD_Level_SSE2.cpp PROPERTIES COMPILE_FLAGS "-msse2")

if(NOT FASTSIMD_COMPILE_ARM)

if(CMAKE_SIZEOF_VOID_P EQUAL 4 OR "${CMAKE_CXX_FLAGS}" MATCHES "-m32")
set_source_files_properties(FastSIMD/FastSIMD_Level_Scalar.cpp PROPERTIES COMPILE_FLAGS "-msse")
set_source_files_properties(FastSIMD/FastSIMD_Level_SSE2.cpp PROPERTIES COMPILE_FLAGS "-msse2")
endif()
set_source_files_properties(FastSIMD/FastSIMD_Level_SSE3.cpp PROPERTIES COMPILE_FLAGS "-msse3")
set_source_files_properties(FastSIMD/FastSIMD_Level_SSSE3.cpp PROPERTIES COMPILE_FLAGS "-mssse3")
set_source_files_properties(FastSIMD/FastSIMD_Level_SSE41.cpp PROPERTIES COMPILE_FLAGS "-msse4.1")
set_source_files_properties(FastSIMD/FastSIMD_Level_SSE42.cpp PROPERTIES COMPILE_FLAGS "-msse4.2")
set_source_files_properties(FastSIMD/FastSIMD_Level_AVX2.cpp PROPERTIES COMPILE_FLAGS "-mavx2 -mfma")
set_source_files_properties(FastSIMD/FastSIMD_Level_AVX512.cpp PROPERTIES COMPILE_FLAGS "-mavx512f -mavx512dq -mfma")

elseif(FASTSIMD_COMPILE_ARMV7)
set_source_files_properties(FastSIMD/FastSIMD_Level_NEON.cpp PROPERTIES COMPILE_FLAGS "-march=armv7-a -mfpu=neon")
endif()
set_source_files_properties(FastSIMD/FastSIMD_Level_SSE3.cpp PROPERTIES COMPILE_FLAGS "-msse3")
set_source_files_properties(FastSIMD/FastSIMD_Level_SSSE3.cpp PROPERTIES COMPILE_FLAGS "-mssse3")
set_source_files_properties(FastSIMD/FastSIMD_Level_SSE41.cpp PROPERTIES COMPILE_FLAGS "-msse4.1")
set_source_files_properties(FastSIMD/FastSIMD_Level_SSE42.cpp PROPERTIES COMPILE_FLAGS "-msse4.2")
set_source_files_properties(FastSIMD/FastSIMD_Level_AVX2.cpp PROPERTIES COMPILE_FLAGS "-mavx2 -mfma")
set_source_files_properties(FastSIMD/FastSIMD_Level_AVX512.cpp PROPERTIES COMPILE_FLAGS "-mavx512f -mavx512dq -mfma")


endif()

Loading

0 comments on commit 24fc843

Please sign in to comment.