1
0
mirror of https://github.com/BLAKE2/libb2 synced 2025-09-02 22:20:57 +02:00

Remove SSE compiler feature detection

The SSE compiler feature detection was always flaky and would need to be
maintained in spite of the fact that it doesn't add much value as the
compilation would just fail if the user incorrectly assumes that his
compiler supports the required instruction sets.

- Enable cmake test support.
This commit is contained in:
Henrik S. Gaßmann 2017-10-03 06:07:10 +02:00
parent 55ff642dc6
commit 23b583d990
3 changed files with 27 additions and 217 deletions

@ -1,4 +1,4 @@
# Written in 2015 by Henrik Steffen Gaßmann henrik@gassmann.onl
# Written in 2015 by Henrik Steffen Gaßmann henrik@gassmann.onl
#
# To the extent possible under law, the author(s) have dedicated all
# copyright and related and neighboring rights to this software to the
@ -13,7 +13,7 @@
cmake_minimum_required(VERSION 3.0)
cmake_policy(VERSION 3.0)
cmake_policy(SET CMP0054 NEW)
project(libb2 VERSION 0.97)
project(libb2 VERSION 0.97 LANGUAGES C)
if(${CMAKE_SOURCE_DIR} STREQUAL ${CMAKE_BINARY_DIR})
message(FATAL_ERROR "in-source builds are not supported!")
@ -36,27 +36,9 @@ include(TestBigEndian)
TEST_BIG_ENDIAN(BLAKE2_BIG_ENDIAN)
# SSE feature level
include(CheckSSESupport)
set(BLAKE2_SSE_LEVELS NO_SSE) #0
if(SSE2_AVAILABLE)
list(APPEND BLAKE2_SSE_LEVELS SSE2) #1
if(SSSE3_AVAILABLE)
list(APPEND BLAKE2_SSE_LEVELS SSSE3) #2
if(SSE41_AVAILABLE)
list(APPEND BLAKE2_SSE_LEVELS SSE4_1) #3
if (AVX_AVAILABLE)
list(APPEND BLAKE2_SSE_LEVELS AVX) #4
if (XOP_AVAILABLE)
list(APPEND BLAKE2_SSE_LEVELS XOP) #5
endif()
endif()
endif()
endif()
endif()
set(BLAKE2_SSE_LEVELS NO_SSE SSE2 SSSE3 SSE4_1 AVX XOP)
if (XOP_AVAILABLE)
option(BLAKE2_FAT_BINARIES "build fat binaries with all available SSE code paths." ON)
endif()
option(BLAKE2_FAT_BINARIES "build fat binaries with all available SSE code paths." ON)
if (BLAKE2_FAT_BINARIES)
list(FIND BLAKE2_SSE_LEVELS XOP BLAKE2_EIS_IDX)
else()
@ -74,6 +56,10 @@ endif()
option(BLAKE2_BUILD_TESTS "")
option(BLAKE2_SHARED_OBJECT "build a dynamic link library instead of a static one")
if (BLAKE2_BUILD_TESTS)
enable_testing()
endif()
########################################################################
# add project
add_subdirectory(src)

@ -1,180 +0,0 @@
# Written in 2015 by Henrik Steffen Gaßmann henrik@gassmann.onl
#
# To the extent possible under law, the author(s) have dedicated all
# copyright and related and neighboring rights to this software to the
# public domain worldwide. This software is distributed without any warranty.
#
# You should have received a copy of the CC0 Public Domain Dedication
# along with this software. If not, see
#
# http://creativecommons.org/publicdomain/zero/1.0/
#
########################################################################
include(CheckCSourceCompiles)
set(O_FLAGS ${CMAKE_REQUIRED_FLAGS})
set(O_DEFS ${CMAKE_REQUIRED_DEFINITIONS})
set(SSE2_CODE "
#ifdef _MSC_VER
#include <intrin.h>
#endif
#include <emmintrin.h>
int main()
{
__m128i m128i;
/* common intrinsics */
_mm_loadu_si128(&m128i);
_mm_storeu_si128(&m128i, m128i);
_MM_SHUFFLE(0,3,2,1);
/* blake2s intrinsics */
_mm_set_epi32(0,0,0,0);
_mm_xor_si128(m128i,m128i);
_mm_srli_epi32(m128i,0);
_mm_slli_epi32(m128i,0);
_mm_add_epi32(m128i,m128i);
_mm_shuffle_epi32(m128i,0);
_mm_setr_epi32(0,0,0,0);
/* blake2b intrinsics */
return 0;
}
")
set(SSSE3_CODE "
#ifdef _MSC_VER
#include <intrin.h>
#endif
#include <emmintrin.h>
#include <tmmintrin.h>
int main()
{
__m128 m128;
__m128i m128i;
/* common intrinsics */
_mm_castsi128_ps(m128i);
_mm_castps_si128(m128);
/* blake2s intrinsics */
_mm_shuffle_epi8(m128i,m128i);
/* blake2b intrinsics */
return 0;
}
")
set(SSE41_CODE "
#ifdef _MSC_VER
#include <intrin.h>
#endif
#include <emmintrin.h>
#include <tmmintrin.h>
#include <smmintrin.h>
int main()
{
__m128 m128;
__m128i m128i;
/* blake2s intrinsics */
_mm_shuffle_ps(m128, m128, 0);
_mm_blend_epi16(m128i, m128i, 0);
_mm_slli_si128(m128i, 0); /*SSE2*/
_mm_srli_si128(m128i, 0); /*SSE2*/
_mm_shufflehi_epi16(m128i, 0); /*SSE2*/
_mm_unpacklo_epi32(m128i, m128i); /*SSE2*/
_mm_unpacklo_epi64(m128i, m128i); /*SSE2*/
_mm_unpackhi_epi32(m128i, m128i); /*SSE2*/
_mm_unpackhi_epi64(m128i, m128i); /*SSE2*/
/* blake2b intrinsics */
return 0;
}
")
# correct this if i'm wrong, but I couldn't find any AVX intrinsics :(
#set(AVX_CODE "
# #ifdef _MSC_VER
# #include <intrin.h>
# #endif
# #include <emmintrin.h>
# #include <tmmintrin.h>
# #include <smmintrin.h>
# #include <immintrin.h>
#
# int main()
# {
# __m128i m128;
# //blake2s intrinsics
#
# //blake2b intrinsics
#
#
# return 0;
# }
#")
set(XOP_CODE "
#ifdef _MSC_VER
#include <intrin.h>
#include <ammintrin.h>
#else
#include <x86intrin.h>
#endif
#include <emmintrin.h>
#include <tmmintrin.h>
#include <smmintrin.h>
#include <immintrin.h>
int main()
{
__m128i m128i;
/* blake2s intrinsics */
_mm_roti_epi32(m128i,0);
_mm_perm_epi8(m128i,m128i,m128i);
/* blake2b intrinsics */
return 0;
}
")
if(CMAKE_COMPILER_IS_GNUCC OR ("${CMAKE_C_COMPILER_ID}" STREQUAL "Clang"))
set(CMAKE_REQUIRED_FLAGS "${O_FLAGS} -msse2")
endif()
check_c_source_compiles("${SSE2_CODE}" SSE2_AVAILABLE)
if(CMAKE_COMPILER_IS_GNUCC OR "${CMAKE_C_COMPILER_ID}" STREQUAL "Clang")
set(CMAKE_REQUIRED_FLAGS "${O_FLAGS} -msse2 -mssse3")
endif()
check_c_source_compiles("${SSSE3_CODE}" SSSE3_AVAILABLE)
if(CMAKE_COMPILER_IS_GNUCC OR "${CMAKE_C_COMPILER_ID}" STREQUAL "Clang")
set(CMAKE_REQUIRED_FLAGS "${O_FLAGS} -msse2 -mssse3 -msse4.1")
endif()
check_c_source_compiles("${SSE41_CODE}" SSE41_AVAILABLE)
#if(CMAKE_COMPILER_IS_GNUCC)
# set(CMAKE_REQUIRED_FLAGS "${O_FLAGS} -msse2 -mssse3 -msse4.1 -mavx")
#endif()
#check_c_source_compiles("${AVX_CODE}" AVX_AVAILABLE)
set(AVX_AVAILABLE 1)
if(CMAKE_COMPILER_IS_GNUCC OR "${CMAKE_C_COMPILER_ID}" STREQUAL "Clang")
set(CMAKE_REQUIRED_FLAGS "${O_FLAGS} -msse2 -mssse3 -msse4.1 -mxop")
endif()
check_c_source_compiles("${XOP_CODE}" XOP_AVAILABLE)
unset(XOP_CODE)
#unset(AVX_CODE)
unset(SSE41_CODE)
unset(SSSE3_CODE)
unset(SSE2_CODE)
unset(O_DEFS)
unset(O_FLAGS)

@ -1,4 +1,4 @@
# Written in 2015 by Henrik Steffen Gaßmann henrik@gassmann.onl
# Written in 2015 by Henrik Steffen Gaßmann henrik@gassmann.onl
#
# To the extent possible under law, the author(s) have dedicated all
# copyright and related and neighboring rights to this software to the
@ -25,12 +25,12 @@ set(LIBB2_SUFFIX_LIST _sse2 _ssse3 _sse41 _avx _xop)
set(COUNTER 0)
while(COUNTER LESS BLAKE2_EIS_IDX)
list(GET LIBB2_SUFFIX_LIST ${COUNTER} _CURR_SUFFIX)
list(GET LIBB2_SUFFIX_LIST ${COUNTER} _CURR_SUFFIX)
MATH(EXPR COUNTER "0${COUNTER}+1")
list(GET BLAKE2_SSE_LEVELS ${COUNTER} _CURR_LEVEL)
#list(APPEND BLAKE2_IMPL_LIST ${_CURR_LEVEL})
set(_CURR_B2S_FILE "${CMAKE_CURRENT_BINARY_DIR}/blake2s_${_CURR_LEVEL}.c")
set(_CURR_B2B_FILE "${CMAKE_CURRENT_BINARY_DIR}/blake2b_${_CURR_LEVEL}.c")
configure_file("blake2s.c"
@ -43,7 +43,7 @@ while(COUNTER LESS BLAKE2_EIS_IDX)
)
set(_CURR_FILES ${_CURR_B2S_FILE} ${_CURR_B2B_FILE})
list(APPEND BLAKE2_IMPL_SOURCES ${_CURR_FILES})
if(COUNTER GREATER 0)
list(APPEND FEATURE_DEFS HAVE_${_CURR_LEVEL})
if (CMAKE_COMPILER_IS_GNUCC OR "${CMAKE_C_COMPILER_ID}" STREQUAL "Clang")
@ -60,12 +60,12 @@ while(COUNTER LESS BLAKE2_EIS_IDX)
endif()
endif()
endif()
set_source_files_properties(${_CURR_FILES} PROPERTIES
COMPILE_FLAGS "${FEATURE_FLAGS}"
COMPILE_DEFINITIONS "SUFFIX=${_CURR_SUFFIX};${FEATURE_DEFS}"
)
unset(_CURR_FILES)
unset(_CURR_B2B_FILE)
unset(_CURR_B2S_FILE)
@ -91,24 +91,24 @@ add_library(libb2 ${BLAKE2_SHARED_LIBRARY_DEF}
blake2-config.h
blake2-impl.h
$<$<NOT:$<EQUAL:${BLAKE2_EIS_IDX},0>>:blake2-dispatch.c>
blake2b-ref.c
blake2b-round.h
blake2b-load-sse2.h
blake2b-load-sse41.h
blake2bp.c
blake2s-ref.c
blake2s-round.h
blake2s-load-sse2.h
blake2s-load-sse41.h
blake2s-load-xop.h
blake2sp.c
${BLAKE2_IMPL_SOURCES}
)
@ -124,7 +124,7 @@ target_compile_definitions(libb2
NO_CONFIG
$<$<NOT:$<BOOL:${BLAKE2_BIG_ENDIAN}>>:NATIVE_LITTLE_ENDIAN>
$<${BLAKE2_SHARED_LIBRARY_VAL}:BLAKE2_DLL_EXPORTS>
PUBLIC
$<${BLAKE2_SHARED_LIBRARY_VAL}:BLAKE2_DLL>
)
@ -160,6 +160,7 @@ if(BLAKE2_BUILD_TESTS)
blake2-kat.h
)
target_link_libraries(blake2b_test PRIVATE libb2)
add_test(NAME blake2b COMMAND blake2b_test)
# BLAKE2 S
add_executable(blake2s_test
@ -167,6 +168,7 @@ if(BLAKE2_BUILD_TESTS)
blake2-kat.h
)
target_link_libraries(blake2s_test PRIVATE libb2)
add_test(NAME blake2s COMMAND blake2s_test)
# BLAKE2 BP
add_executable(blake2bp_test
@ -174,6 +176,7 @@ if(BLAKE2_BUILD_TESTS)
blake2-kat.h
)
target_link_libraries(blake2bp_test PRIVATE libb2)
add_test(NAME blake2bp COMMAND blake2bp_test)
# BLAKE2 SP
add_executable(blake2sp_test
@ -181,5 +184,6 @@ if(BLAKE2_BUILD_TESTS)
blake2-kat.h
)
target_link_libraries(blake2sp_test PRIVATE libb2)
add_test(NAME blake2sp COMMAND blake2sp_test)
endif()