1
1
mirror of https://github.com/BLAKE2/BLAKE2 synced 2024-11-08 14:59:19 +01:00

Adds start for MSVC

This commit is contained in:
Mark Jan van Kampen 2020-03-15 13:56:23 +01:00
parent 77797d9a1c
commit b4809c7454
No known key found for this signature in database
GPG Key ID: 64ED1D7C3283AD86
2 changed files with 71 additions and 27 deletions

@ -1,6 +1,5 @@
macro(enableXOP)
if ( XOP_ENABLED )
check_c_compiler_flag(-mxop XOP_SUPPORTED)
if( XOP_SUPPORTED )
set(COMMON_C_FLAGS ${COMMON_C_FLAGS} -mxop)
message(STATUS "Enabled XOP")
@ -30,7 +29,11 @@ set(CMAKE_C_STANDARD_REQUIRED ON)
set(CMAKE_C_EXTENSIONS OFF)
# Set flags used in all builds
set(COMMON_C_FLAGS -Wall -Wextra -Wno-long-long -pedantic)
if(NOT MSVC)
set(COMMON_C_FLAGS -Wall -Wextra -Wno-long-long -pedantic)
else()
set(COMMON_C_FLAGS -Wall -pedantic)
endif()
# Check if the compiler supports SSE or NEON flags
include(CheckCCompilerFlag)
@ -47,11 +50,39 @@ set(XOP_ENABLED OFF CACHE BOOL "Adds XOP extension")
set(BUILD_B2SUM ON CACHE BOOL "Build b2sum executable")
if(MSVC AND BUILD_B2SUM)
message(FATAL_ERROR "B2sum not supported with MSVC")
endif()
if(MSVC)
include(CheckIncludeFile)
include(CheckSymbolExists)
check_include_file(emmintrin.h SSE2_SUPPORTED)
check_include_file(pmmintrin.h SSE3_SUPPORTED)
check_include_file(smmintrin.h SSE41_SUPPORTED)
check_c_compiler_flag(/arch:AVX AVX_SUPPORTED)
check_c_compiler_flag(/arch:AVX2 AVX2_SUPPORTED)
check_include_file(ammintrin.h HAVE_AMMINTRIN_H)
if(HAVE_AMMINTRIN_H)
check_symbol_exists(_mm_perm_epi8 ammintrin.h XOP_SUPPORTED)
endif()
check_c_compiler_flag(/arch:VFPv4 NEON_SUPPORTED)
else()
check_c_compiler_flag(-msse2 SSE2_SUPPORTED)
check_c_compiler_flag(-mssse3 SSSE3_SUPPORTED)
check_c_compiler_flag(-msse4.1 SSE41_SUPPORTED)
check_c_compiler_flag(-mavx AVX_SUPPORTED)
check_c_compiler_flag(-mavx2 AVX2_SUPPORTED)
check_c_compiler_flag(-mxop XOP_SUPPORTED)
check_c_compiler_flag(-mfpu=neon-vfpv4 NEON_SUPPORTED)
endif()
# Check for user ISA extension setting
if ( ISA_EXTENSION STREQUAL "SSE2" )
check_c_compiler_flag(-msse2 SSE2_SUPPORTED)
if ( SSE2_SUPPORTED )
set(COMMON_C_FLAGS ${COMMON_C_FLAGS} -msse2)
if(NOT MSVC)
set(COMMON_C_FLAGS ${COMMON_C_FLAGS} -msse2)
endif()
set( SSE_BUILD ON )
message(STATUS "Selected SSE2")
enableXOP()
@ -59,9 +90,10 @@ if ( ISA_EXTENSION STREQUAL "SSE2" )
message(FATAL_ERROR "SSE2 not supported by compiler!")
endif()
elseif ( ISA_EXTENSION STREQUAL "SSSE3" )
check_c_compiler_flag(-mssse3 SSSE3_SUPPORTED)
if ( SSSE3_SUPPORTED )
set(COMMON_C_FLAGS ${COMMON_C_FLAGS} -mssse3)
if(NOT MSVC)
set(COMMON_C_FLAGS ${COMMON_C_FLAGS} -mssse3)
endif()
set( SSE_BUILD ON )
message(STATUS "Selected SSSE3")
enableXOP()
@ -69,9 +101,10 @@ elseif ( ISA_EXTENSION STREQUAL "SSSE3" )
message(FATAL_ERROR "SSSE2 not supported by compiler!")
endif()
elseif ( ISA_EXTENSION STREQUAL "SSE4.1" )
check_c_compiler_flag(-msse4.1 SSE41_SUPPORTED)
if ( SSE41_SUPPORTED )
set(COMMON_C_FLAGS ${COMMON_C_FLAGS} -msse4.1)
if(NOT MSVC)
set(COMMON_C_FLAGS ${COMMON_C_FLAGS} -msse4.1)
endif()
set( SSE_BUILD ON )
message(STATUS "Selected SSE4.1")
enableXOP()
@ -79,9 +112,12 @@ elseif ( ISA_EXTENSION STREQUAL "SSE4.1" )
message(FATAL_ERROR "SSE41 not supported by compiler!")
endif()
elseif ( ISA_EXTENSION STREQUAL "AVX" )
check_c_compiler_flag(-mavx AVX_SUPPORTED)
if ( AVX_SUPPORTED )
set(COMMON_C_FLAGS ${COMMON_C_FLAGS} -mavx)
if(NOT MSVC)
set(COMMON_C_FLAGS ${COMMON_C_FLAGS} -mavx)
else()
set(COMMON_C_FLAGS ${COMMON_C_FLAGS} /arch:AVX)
endif()
set( SSE_BUILD ON )
message(STATUS "Selected AVX")
enableXOP()
@ -89,9 +125,8 @@ elseif ( ISA_EXTENSION STREQUAL "AVX" )
message(FATAL_ERROR "AVX not supported by compiler!")
endif()
elseif ( ISA_EXTENSION STREQUAL "AVX2" )
check_c_compiler_flag(-mavx2 AVX2_SUPPORTED)
if ( AVX2_SUPPORTED )
set(COMMON_C_FLAGS ${COMMON_C_FLAGS} -mavx2)
set(COMMON_C_FLAGS ${COMMON_C_FLAGS} /arch:AVX2)
set( SSE_BUILD ON )
message(STATUS "Selected AVX2")
enableXOP()
@ -99,7 +134,6 @@ elseif ( ISA_EXTENSION STREQUAL "AVX2" )
message(FATAL_ERROR "AVX2 not supported by compiler!")
endif()
elseif ( ISA_EXTENSION STREQUAL "Neon" )
check_c_compiler_flag(-mfpu=neon-vfpv4 NEON_SUPPORTED)
if ( NEON_SUPPORTED )
set( NEON_BUILD ON )
message(STATUS "Selected Neon")
@ -112,14 +146,6 @@ elseif ( ISA_EXTENSION STREQUAL "None" )
elseif( ISA_EXTENSION STREQUAL "Best" )
message(STATUS "Finding best ISA extension...")
check_c_compiler_flag(-msse2 SSE2_SUPPORTED)
check_c_compiler_flag(-mssse3 SSSE3_SUPPORTED)
check_c_compiler_flag(-msse4.1 SSE41_SUPPORTED)
check_c_compiler_flag(-mavx AVX_SUPPORTED)
check_c_compiler_flag(-mavx2 AVX2_SUPPORTED)
check_c_compiler_flag(-mxop XOP_SUPPORTED)
check_c_compiler_flag(-mfpu=neon-vfpv4 NEON_SUPPORTED)
if ( SSE2_SUPPORTED AND NEON_SUPPORTED )
message(FATAL_ERROR "Cannot select best as SSE and NEON are available!")
endif()
@ -128,27 +154,41 @@ elseif( ISA_EXTENSION STREQUAL "Best" )
set(NEON_BUILD ON)
message(STATUS "Selected Neon")
elseif( AVX2_SUPPORTED )
set(COMMON_C_FLAGS ${COMMON_C_FLAGS} -mavx2)
if(NOT MSVC)
set(COMMON_C_FLAGS ${COMMON_C_FLAGS} -mavx2)
else()
set(COMMON_C_FLAGS ${COMMON_C_FLAGS} /arch:AVX2)
endif()
set( SSE_BUILD ON )
message(STATUS "Selected AVX2")
enableXOP()
elseif( AVX_SUPPORTED )
set(COMMON_C_FLAGS ${COMMON_C_FLAGS} -mavx)
if(NOT MSVC)
set(COMMON_C_FLAGS ${COMMON_C_FLAGS} -mavx)
else()
set(COMMON_C_FLAGS ${COMMON_C_FLAGS} /arch:AVX)
endif()
set( SSE_BUILD ON )
message(STATUS "Selected AVX")
enableXOP()
elseif( SSE41_SUPPORTED )
set(COMMON_C_FLAGS ${COMMON_C_FLAGS} -msse4.1)
if(NOT MSVC)
set(COMMON_C_FLAGS ${COMMON_C_FLAGS} -msse4.1)
endif()
set( SSE_BUILD ON )
message(STATUS "Selected SSE4.1")
enableXOP()
elseif( SSSE3_SUPPORTED )
set(COMMON_C_FLAGS ${COMMON_C_FLAGS} -mssse3)
if(NOT MSVC)
set(COMMON_C_FLAGS ${COMMON_C_FLAGS} -mssse3)
endif()
set( SSE_BUILD ON )
message(STATUS "Selected SSSE3")
enableXOP()
elseif( SSE2_SUPPORTED )
set(COMMON_C_FLAGS ${COMMON_C_FLAGS} -msse2)
if(NOT MSVC)
set(COMMON_C_FLAGS ${COMMON_C_FLAGS} -msse2)
endif()
set( SSE_BUILD ON )
message(STATUS "Selected SSE2")
enableXOP()

@ -1,4 +1,8 @@
set(B2_COMPILE_OPTIONS -O3 -Wall -Wextra -Wno-long-long -march=native)
if(NOT MSVC)
set(B2_COMPILE_OPTIONS -O3 -Wall -Wextra -Wno-long-long -march=native)
else()
set(B2_COMPILE_OPTIONS -Wall)
endif()
add_executable(b2sum "")