@@ -2,6 +2,7 @@ set(LLVM_BLAKE3_FILES
2
2
blake3.c
3
3
blake3_dispatch.c
4
4
blake3_portable.c
5
+ blake3_neon.c
5
6
)
6
7
7
8
if (LLVM_DISABLE_ASSEMBLY_FILES )
@@ -10,6 +11,10 @@ else()
10
11
set (CAN_USE_ASSEMBLER TRUE )
11
12
endif ()
12
13
14
+ macro (disable_blake3_x86_simd )
15
+ add_definitions (-DBLAKE3_NO_AVX512 -DBLAKE3_NO_AVX2 -DBLAKE3_NO_SSE41 -DBLAKE3_NO_SSE2 )
16
+ endmacro ()
17
+
13
18
# The BLAKE3 team recommends using the assembly versions, from the README:
14
19
#
15
20
# "For each of the x86 SIMD instruction sets, four versions are available:
@@ -18,70 +23,59 @@ endif()
18
23
# preferred. They perform better, they perform more consistently across
19
24
# different compilers, and they build more quickly."
20
25
21
- if (MSVC )
22
- check_symbol_exists (_M_X64 "" IS_X64 )
23
- check_symbol_exists (_M_ARM64 "" IS_ARM64 )
24
- else ()
25
- check_symbol_exists (__x86_64__ "" IS_X64 )
26
- check_symbol_exists (__aarch64__ "" IS_ARM64 )
27
-
28
- if (IS_X64 )
29
- # Clang-6 needs this flag.
30
- set_source_files_properties (blake3_avx512_x86-64_windows_gnu.S
31
- PROPERTIES COMPILE_OPTIONS "-mavx512vl" )
32
- set_source_files_properties (blake3_avx512_x86-64_unix.S
33
- PROPERTIES COMPILE_OPTIONS "-mavx512vl" )
34
- endif ()
35
- endif ()
36
-
37
- if (IS_X64 AND CAN_USE_ASSEMBLER )
26
+ if (CAN_USE_ASSEMBLER )
38
27
if (MSVC )
39
- enable_language (ASM_MASM )
40
- list (APPEND LLVM_BLAKE3_FILES
41
- blake3_sse2_x86-64_windows_msvc.asm
42
- blake3_sse41_x86-64_windows_msvc.asm
43
- blake3_avx2_x86-64_windows_msvc.asm
44
- blake3_avx512_x86-64_windows_msvc.asm
45
- )
28
+ check_symbol_exists (_M_X64 "" IS_X64 )
29
+ if (IS_X64 )
30
+ enable_language (ASM_MASM )
31
+ list (APPEND LLVM_BLAKE3_FILES
32
+ blake3_sse2_x86-64_windows_msvc.asm
33
+ blake3_sse41_x86-64_windows_msvc.asm
34
+ blake3_avx2_x86-64_windows_msvc.asm
35
+ blake3_avx512_x86-64_windows_msvc.asm
36
+ )
37
+ else ()
38
+ disable_blake3_x86_simd ()
39
+ endif ()
46
40
elseif (WIN32 OR CYGWIN )
47
- list (APPEND LLVM_BLAKE3_FILES
48
- blake3_sse2_x86-64_windows_gnu.S
49
- blake3_sse41_x86-64_windows_gnu.S
50
- blake3_avx2_x86-64_windows_gnu.S
51
- blake3_avx512_x86-64_windows_gnu.S
52
- )
41
+ check_symbol_exists (__x86_64__ "" IS_X64 )
42
+ if (IS_X64 )
43
+ list (APPEND LLVM_BLAKE3_FILES
44
+ blake3_sse2_x86-64_windows_gnu.S
45
+ blake3_sse41_x86-64_windows_gnu.S
46
+ blake3_avx2_x86-64_windows_gnu.S
47
+ blake3_avx512_x86-64_windows_gnu.S
48
+ )
49
+ # Clang-6 needs this flag.
50
+ set_source_files_properties (blake3_avx512_x86-64_windows_gnu.S
51
+ PROPERTIES COMPILE_OPTIONS "-mavx512vl" )
52
+ else ()
53
+ disable_blake3_x86_simd ()
54
+ endif ()
53
55
else ()
54
- list (APPEND LLVM_BLAKE3_FILES
55
- blake3_sse2_x86-64_unix.S
56
- blake3_sse41_x86-64_unix.S
57
- blake3_avx2_x86-64_unix.S
58
- blake3_avx512_x86-64_unix.S
59
- )
56
+ check_symbol_exists (__x86_64__ "" IS_X64 )
57
+ if (IS_X64 OR CMAKE_OSX_ARCHITECTURES )
58
+ # In a macOS Universal build (setting CMAKE_OSX_ARCHITECTURES to multiple
59
+ # values), compilation of the source files will target multiple architectures
60
+ # (each source file is internally compiled once for each architecture).
61
+ # To accomodate this configuration we include these assembly files without a
62
+ # CMake check but their source is guarded with architecture "#ifdef" checks.
63
+ list (APPEND LLVM_BLAKE3_FILES
64
+ blake3_sse2_x86-64_unix.S
65
+ blake3_sse41_x86-64_unix.S
66
+ blake3_avx2_x86-64_unix.S
67
+ blake3_avx512_x86-64_unix.S
68
+ )
69
+ # Clang-6 needs this flag.
70
+ set_source_files_properties (blake3_avx512_x86-64_unix.S
71
+ PROPERTIES COMPILE_OPTIONS "-mavx512vl" )
72
+ else ()
73
+ disable_blake3_x86_simd ()
74
+ endif ()
60
75
endif ()
61
76
else ()
62
- # In a macOS Universal build (setting CMAKE_OSX_ARCHITECTURES to multiple
63
- # values), IS_X64 and IS_ARM64 won't be set, but compilation of the source
64
- # files will consider targeting either of them (each source file is
65
- # internally compiled once for each architecture). Thus, if we on the CMake
66
- # level decide not to include the assembly files, tell the source to not
67
- # expect it to be present either.
68
- #
69
- # Also, if targeting i386, then the blake3 source code automatically enables
70
- # the SIMD implementations, but we don't provide those sources.
71
- #
72
- # FIXME: We could improve the CMAKE_OSX_ARCHITECTURES configuration by
73
- # including all SIMD implementation files that might be relevant, and
74
- # wrapping them in ifdefs like "#ifdef __x86_64__", to allow them to be
75
- # included in a build for any architecture.
76
- add_definitions (-DBLAKE3_NO_AVX512 -DBLAKE3_NO_AVX2 -DBLAKE3_NO_SSE41 -DBLAKE3_NO_SSE2 )
77
- endif ()
78
-
79
- if (IS_ARM64 )
80
- list (APPEND LLVM_BLAKE3_FILES
81
- blake3_neon.c
82
- )
83
- else ()
84
- add_definitions (-DBLAKE3_USE_NEON=0 )
77
+ # CAN_USE_ASSEMBLER == FALSE
78
+ disable_blake3_x86_simd ()
85
79
endif ()
86
80
87
81
add_library (LLVMSupportBlake3 OBJECT EXCLUDE_FROM_ALL ${LLVM_BLAKE3_FILES} )
0 commit comments