Skip to content

Commit

Permalink
[fusion] unify detection scheme to the best one that we have (which w…
Browse files Browse the repository at this point in the history
…e have had in h2o)
  • Loading branch information
kazuho committed Oct 30, 2023
1 parent 9fa382d commit 7c9c82b
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 9 deletions.
12 changes: 3 additions & 9 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,12 @@ IF (CMAKE_VERSION VERSION_LESS 3.13.0)
ENDIF ()

FIND_PACKAGE(PkgConfig REQUIRED)
INCLUDE(cmake/dtrace-utils.cmake)
INCLUDE(cmake/boringssl-adjust.cmake)
INCLUDE(cmake/dtrace-utils.cmake)
INCLUDE(cmake/fusion.cmake)

CHECK_DTRACE(${PROJECT_SOURCE_DIR}/picotls-probes.d)
IF ((CMAKE_SIZEOF_VOID_P EQUAL 8) AND
(CMAKE_SYSTEM_PROCESSOR STREQUAL "x86_64") OR
(CMAKE_SYSTEM_PROCESSOR STREQUAL "amd64") OR
(CMAKE_SYSTEM_PROCESSOR STREQUAL "AMD64"))
SET(WITH_FUSION_DEFAULT "ON")
ELSE ()
SET(WITH_FUSION_DEFAULT "OFF")
ENDIF ()
CHECK_FUSION_PREREQUISITES()

OPTION(WITH_DTRACE "use USDT (userspace Dtrace probes)" ${HAVE_DTRACE})
OPTION(WITH_FUSION "build 'fusion' AES-GCM engine" ${WITH_FUSION_DEFAULT})
Expand Down
29 changes: 29 additions & 0 deletions cmake/fusion.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
INCLUDE(CheckCSourceCompiles)
INCLUDE(CMakePushCheckState)

FUNCTION (CHECK_FUSION_PREREQUISITES)
MESSAGE(STATUS "Detecting fusion support")

CMAKE_PUSH_CHECK_STATE()
SET(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -mavx2 -maes -mpclmul -mvaes -mvpclmulqdq")
CHECK_C_SOURCE_COMPILES("
#include <emmintrin.h>
#include <immintrin.h>
int main(void) {
__m256i ord0, ord1, ord2, ord3 = _mm256_setzero_si256();
ord0 = _mm256_aesenc_epi128(ord1, ord2);
ord3 = _mm256_aesenclast_epi128(ord0, ord1);
ord1 = _mm256_clmulepi64_epi128(ord3, ord2, 0x00);
return 0;
}
" CC_HAS_AESNI256)
CMAKE_POP_CHECK_STATE()

IF (CC_HAS_AESNI256)
MESSAGE(STATUS "Can use fusion")
SET(WITH_FUSION_DEFAULT "ON" PARENT_SCOPE)
ELSE ()
MESSAGE(STATUS "Cannot use fusion")
SET(WITH_FUSION_DEFAULT "OFF" PARENT_SCOPE)
ENDIF ()
ENDFUNCTION ()
2 changes: 2 additions & 0 deletions picotls.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,7 @@
081F00CC291A358800534A86 /* asn1.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = asn1.h; sourceTree = "<group>"; };
081F00CD291A358800534A86 /* pembase64.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = pembase64.h; sourceTree = "<group>"; };
081F00CE291A358800534A86 /* ptlsbcrypt.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ptlsbcrypt.h; sourceTree = "<group>"; };
0883D3272AEF8F2500B711CC /* fusion.cmake */ = {isa = PBXFileReference; lastKnownFileType = text; path = fusion.cmake; sourceTree = "<group>"; };
08A835E12995E04100D872CE /* chacha20poly1305.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = chacha20poly1305.h; sourceTree = "<group>"; };
08A835EB2996971300D872CE /* boringssl-adjust.cmake */ = {isa = PBXFileReference; lastKnownFileType = text; path = "boringssl-adjust.cmake"; sourceTree = "<group>"; };
08B3298229419DFC009D6766 /* ech-live.t */ = {isa = PBXFileReference; lastKnownFileType = text; path = "ech-live.t"; sourceTree = "<group>"; xcLanguageSpecificationIdentifier = xcode.lang.perl; };
Expand Down Expand Up @@ -527,6 +528,7 @@
children = (
08A835EB2996971300D872CE /* boringssl-adjust.cmake */,
E95EBCCA227EA0180022C32D /* dtrace-utils.cmake */,
0883D3272AEF8F2500B711CC /* fusion.cmake */,
);
path = cmake;
sourceTree = "<group>";
Expand Down

0 comments on commit 7c9c82b

Please sign in to comment.