4
4
include (CheckCCompilerFlag)
5
5
include (CheckIncludeFile)
6
6
7
+ if (MSVC )
8
+ set (AWS_AVX2_FLAG "/arch:AVX2" )
9
+ set (AWS_AVX512_FLAG "/arch:AVX512" )
10
+ set (AWS_AVX512vL_FLAG "" )
11
+ set (AWS_CLMUL_FLAG "" )
12
+ set (AWS_SSE4_2_FLAG "" )
13
+ set (AWS_ARMv8_1_FLAG "/arch:arm8.1" )
14
+ set (WERROR_FLAG "" )
15
+ else ()
16
+ set (AWS_AVX2_FLAG "-mavx -mavx2" )
17
+ set (AWS_AVX512_FLAG "-mavx512f -mvpclmulqdq" )
18
+ set (AWS_AVX512vL_FLAG "-mavx512vl" )
19
+ set (AWS_CLMUL_FLAG "-mpclmul" )
20
+ set (AWS_SSE4_2_FLAG "-msse4.2" )
21
+ set (AWS_ARMv8_1_FLAG "-march=armv8-a+crc+crypto -mtune=neoverse-v1" )
22
+ set (WERROR_FLAG "-Werror" )
23
+ endif ()
24
+
7
25
if (USE_CPU_EXTENSIONS)
8
- if (MSVC )
9
- check_c_compiler_flag("/arch:AVX2" HAVE_M_AVX2_FLAG)
10
- if (HAVE_M_AVX2_FLAG)
11
- set (AVX_CFLAGS "/arch:AVX2" )
12
- endif ()
13
- else ()
14
- check_c_compiler_flag(-mavx2 HAVE_M_AVX2_FLAG)
15
- if (HAVE_M_AVX2_FLAG)
16
- set (AVX_CFLAGS "-mavx -mavx2" )
17
- endif ()
26
+ set (AVX_CFLAGS ${AWS_SSE4_2_FLAG} )
27
+
28
+ check_c_compiler_flag(${AWS_AVX2_FLAG} HAVE_M_AVX2_FLAG)
29
+ if (HAVE_M_AVX2_FLAG)
30
+ set (AVX_CFLAGS "${AWS_AVX2_FLAG} ${AVX_CFLAGS} " )
18
31
endif ()
19
32
20
- if (MSVC )
21
- check_c_compiler_flag("/arch:AVX512" HAVE_M_AVX512_FLAG)
22
- if (HAVE_M_AVX512_FLAG)
23
- # docs imply AVX512 brings in AVX2. And it will compile, but it will break at runtime on
24
- # instructions such as _mm256_load_si256(). Leave it on.
25
- set (AVX_CFLAGS "/arch:AVX512 /arch:AVX2" )
26
- endif ()
27
- else ()
28
- check_c_compiler_flag("-mavx512f -mvpclmulqdq" HAVE_M_AVX512_FLAG)
29
- if (HAVE_M_AVX512_FLAG)
30
- set (AVX_CFLAGS "-mavx512f -mvpclmulqdq -mpclmul -mavx -mavx2 -msse4.2" )
31
- endif ()
33
+ check_c_compiler_flag("${AWS_AVX512_FLAG} ${AWS_CLMUL_FLAG} " HAVE_M_AVX512_FLAG)
34
+ if (HAVE_M_AVX512_FLAG)
35
+ set (AVX_CFLAGS "${AWS_AVX512_FLAG} ${AWS_CLMUL_FLAG} ${AVX_CFLAGS} " )
32
36
endif ()
33
37
34
38
set (old_flags "${CMAKE_REQUIRED_FLAGS} " )
35
- set (CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} ${AVX_CFLAGS} " )
39
+ set (CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} ${AVX_CFLAGS} ${WERROR_FLAG} " )
36
40
37
41
check_c_source_compiles("
38
42
#include <immintrin.h>
@@ -68,7 +72,35 @@ if (USE_CPU_EXTENSIONS)
68
72
return (int)_mm256_extract_epi64(vec, 2);
69
73
}" AWS_HAVE_MM256_EXTRACT_EPI64)
70
74
75
+ check_c_source_compiles("
76
+ #include <wmmintrin.h>
77
+ #include <emmintrin.h>
78
+ int main() {
79
+ __m128i a = _mm_setzero_si128();
80
+ __m128i b = _mm_setzero_si128();
81
+ __m128i result = _mm_clmulepi64_si128(a, b, 0x00);
82
+ (void)result;
83
+ return 0;
84
+ }" AWS_HAVE_CLMUL)
85
+
86
+ set (CMAKE_REQUIRED_FLAGS "${old_flags} ${AWS_ARMv8_1_FLAG} ${WERROR_FLAG} " )
87
+ check_c_source_compiles("
88
+ #include <arm_acle.h>
89
+ int main() {
90
+ int crc = __crc32d(0, 1);
91
+ return 0;
92
+ }" AWS_HAVE_ARM32_CRC)
93
+
94
+ check_c_source_compiles("
95
+ #include <stdatomic.h>
96
+ int main() {
97
+ _Atomic int var = 0;
98
+ atomic_fetch_add_explicit(&var, 1, memory_order_relaxed);
99
+ return 0;
100
+ }" AWS_HAVE_ARMv8_1)
101
+
71
102
set (CMAKE_REQUIRED_FLAGS "${old_flags} " )
103
+
72
104
endif () # USE_CPU_EXTENSIONS
73
105
74
106
# The part where the definition is added to the compiler flags has been moved to config.h.in
@@ -80,6 +112,23 @@ endif() # USE_CPU_EXTENSIONS
80
112
function (simd_add_source_avx target )
81
113
foreach (file ${ARGN} )
82
114
target_sources (${target} PRIVATE ${file} )
83
- set_source_files_properties (${file} PROPERTIES COMPILE_FLAGS "${AVX_CFLAGS} " )
115
+ set_source_files_properties (${file} PROPERTIES COMPILE_FLAGS " ${AVX_CFLAGS} " )
84
116
endforeach ()
85
117
endfunction (simd_add_source_avx)
118
+
119
+ # The part where the definition is added to the compiler flags has been moved to config.h.in
120
+ # see git history for more details.
121
+
122
+ # Adds compiler flags to the source and adds the source to target.
123
+ # Unfortunately the flags have to be passed as strings. Predefined flags are
124
+ # at the top of this file.
125
+ # Usage: simd_append_source_and_features(target file1.c ${AWS_AVX512_FLAG} ${AWS_AVX2_FLAG} ...)
126
+ function (simd_append_source_and_features target file)
127
+ set (CC_FLAGS "" )
128
+ foreach (flag ${ARGN} )
129
+ set (CC_FLAGS "${CC_FLAGS} ${flag} " )
130
+ endforeach ()
131
+
132
+ target_sources (${target} PRIVATE ${file} )
133
+ set_source_files_properties (${file} PROPERTIES COMPILE_FLAGS " ${CC_FLAGS} " )
134
+ endfunction (simd_append_source_and_features)
0 commit comments