Debian Codegraph @

build/m4/aircrack_ng_simd.m4

raw
1 dnl Aircrack-ng
2 dnl
3 dnl Copyright (C) 2017 Joseph Benden <[email protected]>
4 dnl
5 dnl Autotool support was written by: Joseph Benden <[email protected]>
6 dnl
7 dnl This program is free software; you can redistribute it and/or modify
8 dnl it under the terms of the GNU General Public License as published by
9 dnl the Free Software Foundation; either version 2 of the License, or
10 dnl (at your option) any later version.
11 dnl
12 dnl This program is distributed in the hope that it will be useful,
13 dnl but WITHOUT ANY WARRANTY; without even the implied warranty of
14 dnl MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 dnl GNU General Public License for more details.
16 dnl
17 dnl You should have received a copy of the GNU General Public License
18 dnl along with this program; if not, write to the Free Software
19 dnl Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
20 dnl
21 dnl In addition, as a special exception, the copyright holders give
22 dnl permission to link the code of portions of this program with the
23 dnl OpenSSL library under certain conditions as described in each
24 dnl individual source file, and distribute linked combinations
25 dnl including the two.
26 dnl
27 dnl You must obey the GNU General Public License in all respects
28 dnl for all of the code used other than OpenSSL.
29 dnl
30 dnl If you modify file(s) with this exception, you may extend this
31 dnl exception to your dnl version of the file(s), but you are not obligated
32 dnl to do so.
33 dnl
34 dnl If you dnl do not wish to do so, delete this exception statement from your
35 dnl version.
36 dnl
37 dnl If you delete this exception statement from all source files in the
38 dnl program, then also delete it here.
39
40 AC_DEFUN([AIRCRACK_NG_SIMD], [
41 AX_REQUIRE_DEFINED([AX_COMPILER_VENDOR])
42 AX_REQUIRE_DEFINED([AX_COMPILER_VERSION])
43 AX_REQUIRE_DEFINED([AX_CHECK_COMPILE_FLAG])
44 AX_REQUIRE_DEFINED([AX_APPEND_FLAG])
45
46 AX_COMPILER_VENDOR
47 AX_COMPILER_VERSION
48
49 OPENBSD=0
50 IS_X86=0
51 IS_ARM=0
52 IS_PPC=0
53 IS_CROSS=0
54
55 if test "$cross_compiling" != yes
56 then
57 IS_CROSS=0
58 else
59 IS_CROSS=1
60 fi
61
62 case "$host_cpu" in
63 x86_64 | amd64 | i*86*)
64 IS_X86=1
65 ;;
66 *arm* | *aarch64*)
67 IS_ARM=1
68 ;;
69 *mips*)
70 IS_MIPS=1
71 ;;
72 powerpc*)
73 IS_PPC=1
74 ;;
75 esac
76
77 case "$host_os" in
78 *openbsd* | *OpenBSD*)
79 OPENBSD=1
80 ;;
81 esac
82
83 if test $IS_ARM -eq 1
84 then
85 AX_CHECK_COMPILE_FLAG([-Werror -mfpu=neon], [
86 AX_APPEND_FLAG(-mfpu=neon, [arm_neon_[]_AC_LANG_ABBREV[]flags])
87 AC_SUBST(arm_neon_[]_AC_LANG_ABBREV[]flags)
88 ])
89
90 AS_VAR_PUSHDEF([CACHEVAR], [ax_cv_neon_[]_AC_LANG_ABBREV[]flags])
91 AC_CACHE_CHECK([whether _AC_LANG compiler supports NEON instructions], CACHEVAR, [
92 ax_check_save_flags=$[]_AC_LANG_PREFIX[]FLAGS
93 _AC_LANG_PREFIX[]FLAGS="$arm_neon_[]_AC_LANG_ABBREV[]flags $[]_AC_LANG_PREFIX[]FLAGS"
94 AC_COMPILE_IFELSE([AC_LANG_SOURCE([[
95 #if !defined(__ARM_NEON) && !defined(__ARM_NEON__) && !defined(__aarch64) && !defined(__aarch64__)
96 #error macro not defined
97 #endif
98 ]])], [AS_VAR_SET(CACHEVAR,[yes])], [AS_VAR_SET(CACHEVAR,[no])])
99 _AC_LANG_PREFIX[]FLAGS=$ax_check_save_flags
100 ])
101 AS_IF([test x"AS_VAR_GET(CACHEVAR)" = xyes],
102 [NEON_FOUND=1], [NEON_FOUND=0])
103 AS_VAR_POPDEF([CACHEVAR])
104 fi
105
106 if test $IS_PPC -eq 1
107 then
108 AX_CHECK_COMPILE_FLAG([-finline-functions], [
109 AX_APPEND_FLAG(-finline-functions, [ppc_altivec_[]_AC_LANG_ABBREV[]flags])
110 AC_SUBST(ppc_altivec_[]_AC_LANG_ABBREV[]flags)
111 ])
112
113 AX_CHECK_COMPILE_FLAG([-finline-limit=4000], [
114 AX_APPEND_FLAG(-finline-limit=4000, [ppc_altivec_[]_AC_LANG_ABBREV[]flags])
115 AC_SUBST(ppc_altivec_[]_AC_LANG_ABBREV[]flags)
116 ])
117
118 AX_CHECK_COMPILE_FLAG([-fno-strict-aliasing], [
119 AX_APPEND_FLAG(-fno-strict-aliasing, [ppc_altivec_[]_AC_LANG_ABBREV[]flags])
120 AC_SUBST(ppc_altivec_[]_AC_LANG_ABBREV[]flags)
121 ])
122
123 AX_CHECK_COMPILE_FLAG([-maltivec], [
124 AX_APPEND_FLAG(-maltivec, [ppc_altivec_[]_AC_LANG_ABBREV[]flags])
125 AC_SUBST(ppc_altivec_[]_AC_LANG_ABBREV[]flags)
126 ])
127
128 AX_CHECK_COMPILE_FLAG([-mabi=altivec], [
129 AX_APPEND_FLAG(-mabi=altivec, [ppc_altivec_[]_AC_LANG_ABBREV[]flags])
130 AC_SUBST(ppc_altivec_[]_AC_LANG_ABBREV[]flags)
131 ])
132
133 AS_VAR_PUSHDEF([CACHEVAR], [ax_cv_altivec_[]_AC_LANG_ABBREV[]flags])
134 AC_CACHE_CHECK([whether _AC_LANG compiler supports VSX instructions], CACHEVAR, [
135 ax_check_save_flags=$[]_AC_LANG_PREFIX[]FLAGS
136 _AC_LANG_PREFIX[]FLAGS="$ppc_altivec_[]_AC_LANG_ABBREV[]flags -mvsx -mpower8-vector $[]_AC_LANG_PREFIX[]FLAGS"
137 AC_COMPILE_IFELSE([AC_LANG_SOURCE([[
138 #if !defined(__VSX__) && !defined(__POWER8_VECTOR__)
139 #error macro not defined
140 #endif
141 ]])], [AS_VAR_SET(CACHEVAR,[yes])], [AS_VAR_SET(CACHEVAR,[no])])
142 _AC_LANG_PREFIX[]FLAGS=$ax_check_save_flags
143 ])
144 AS_IF([test x"AS_VAR_GET(CACHEVAR)" = xyes],
145 [
146 ALTIVEC_FOUND=1
147 POWER8_FOUND=1
148 AX_APPEND_FLAG(-mvsx, [ppc_altivec_[]_AC_LANG_ABBREV[]flags])
149 AX_APPEND_FLAG(-mpower8-vector, [ppc_altivec_[]_AC_LANG_ABBREV[]flags])
150 AC_SUBST(ppc_altivec_[]_AC_LANG_ABBREV[]flags)
151 ], [
152 ALTIVEC_FOUND=0
153 POWER8_FOUND=0
154 ])
155 AS_VAR_POPDEF([CACHEVAR])
156 fi
157
158 if test $IS_X86 -eq 0
159 then
160 AC_CHECK_HEADERS([sys/auxv.h], [
161 AC_DEFINE([HAS_AUXV], [1], [Define if your system has sys/auxv.h header])
162 ])
163 fi
164
165 AC_ARG_WITH(cacheline-size,
166 [AS_HELP_STRING([--with-cacheline-size=[width]], [use specific CPU L1 cache-line size, in bytes. [default=64]])])
167
168 case $with_cacheline_size in
169 no | "") CACHELINE_SIZE=64;;
170 *) CACHELINE_SIZE=$with_cacheline_size;;
171 esac
172 AC_SUBST([CACHELINE_SIZE])
173
174 AC_DEFINE_UNQUOTED([CACHELINE_SIZE], [$CACHELINE_SIZE], [Define to set the specific CPU L1 cache-line size, in bytes.])
175
176 AC_ARG_WITH(static-simd,
177 [AS_HELP_STRING([--with-static-simd[[=x86-sse2|x86-avx|x86-avx2|x86-avx512|ppc-altivec|ppc-power8|arm-neon|arm-asimd]], [use specific SIMD implementation at static link, [default=none]]])])
178
179 case $with_static_simd in
180 no | "")
181 ;;
182 x86-sse2|x86-avx|x86-avx2|x86-avx512|ppc-altivec|ppc-power8|arm-neon|arm-asimd)
183 SIMD_SUFFIX=_$(echo $with_static_simd | tr '[a-z]' '[A-Z]' | tr '-' '_')
184 AC_SUBST([SIMD_SUFFIX])
185
186 case "$enable_static,$enable_shared" in
187 "yes,yes" | "no,yes" | "no,no" )
188 AC_MSG_ERROR([The --with-static-simd option is only valid with static builds.])
189 ;;
190 esac
191 ;;
192 *)
193 AC_MSG_ERROR([Invalid SIMD given to --with-static-simd option.])
194 ;;
195 esac
196
197 AC_ARG_WITH(avx512,
198 [AS_HELP_STRING([--with-avx512[[=yes|no]]], [use AVX-512F instruction set, [default=no]])])
199
200 if test $IS_X86 -eq 1
201 then
202 case $with_avx512 in
203 yes)
204 case "$ax_cv_[]_AC_LANG_ABBREV[]_compiler_vendor" in
205 intel)
206 AX_APPEND_FLAG(-march=skylake-avx512, [x86_avx512_[]_AC_LANG_ABBREV[]flags])
207 AC_SUBST(x86_avx512_[]_AC_LANG_ABBREV[]flags)
208 AVX512F_FOUND=1
209 AC_SUBST([AVX512F_FOUND], [1], [Define if your system supports AVX-512F])
210 ;;
211 *)
212 AX_CHECK_COMPILE_FLAG([-mavx512f], [
213 AX_APPEND_FLAG(-mavx512f, [x86_avx512_[]_AC_LANG_ABBREV[]flags])
214 AC_SUBST(x86_avx512_[]_AC_LANG_ABBREV[]flags)
215 AVX512F_FOUND=1
216 AC_SUBST([AVX512F_FOUND], [1], [Define if your system supports AVX-512F])
217 ])
218 ;;
219 esac
220
221 AC_DEFINE_UNQUOTED([AVX512F_FOUND], [$AVX512F_FOUND], [Define to enable AVX-512F buffers.])
222 ;;
223 esac
224
225 case "$ax_cv_[]_AC_LANG_ABBREV[]_compiler_vendor" in
226 intel)
227 AX_APPEND_FLAG(-march=core-avx2, [x86_avx2_[]_AC_LANG_ABBREV[]flags])
228 AC_SUBST(x86_avx2_[]_AC_LANG_ABBREV[]flags)
229
230 AX_APPEND_FLAG(-march=corei7-avx, [x86_avx_[]_AC_LANG_ABBREV[]flags])
231 AC_SUBST(x86_avx_[]_AC_LANG_ABBREV[]flags)
232
233 AX_APPEND_FLAG(-march=corei7, [x86_sse2_[]_AC_LANG_ABBREV[]flags])
234 AC_SUBST(x86_sse2_[]_AC_LANG_ABBREV[]flags)
235
236 AX_APPEND_FLAG(-march=pentiumii, [x86_mmx_[]_AC_LANG_ABBREV[]flags])
237 AC_SUBST(x86_mmx_[]_AC_LANG_ABBREV[]flags)
238 ;;
239 *)
240 AX_CHECK_COMPILE_FLAG([-mavx2], [
241 AX_APPEND_FLAG(-mavx2, [x86_avx2_[]_AC_LANG_ABBREV[]flags])
242 AC_SUBST(x86_avx2_[]_AC_LANG_ABBREV[]flags)
243 ])
244
245 AX_CHECK_COMPILE_FLAG([-mavx], [
246 AX_APPEND_FLAG(-mavx, [x86_avx_[]_AC_LANG_ABBREV[]flags])
247 AC_SUBST(x86_avx_[]_AC_LANG_ABBREV[]flags)
248 ])
249
250 AX_CHECK_COMPILE_FLAG([-msse2], [
251 AX_APPEND_FLAG(-msse2, [x86_sse2_[]_AC_LANG_ABBREV[]flags])
252 AC_SUBST(x86_sse2_[]_AC_LANG_ABBREV[]flags)
253 ])
254
255 AX_CHECK_COMPILE_FLAG([-mmmx], [
256 AX_APPEND_FLAG(-mmmx, [x86_mmx_[]_AC_LANG_ABBREV[]flags])
257 AC_SUBST(x86_mmx_[]_AC_LANG_ABBREV[]flags)
258 ])
259 ;;
260 esac
261 fi
262
263 AM_CONDITIONAL([X86], [test "$IS_X86" = 1])
264 AM_CONDITIONAL([ARM], [test "$IS_ARM" = 1])
265 AM_CONDITIONAL([PPC], [test "$IS_PPC" = 1])
266 AM_CONDITIONAL([NEON], [test "$NEON_FOUND" = 1])
267 AM_CONDITIONAL([AVX512F], [test "$AVX512F_FOUND" = 1])
268 AM_CONDITIONAL([ALTIVEC], [test "$ALTIVEC_FOUND" = 1])
269 AM_CONDITIONAL([POWER8], [test "$POWER8_FOUND" = 1])
270 ])
271
272 AC_DEFUN([AIRCRACK_NG_SIMD_C], [
273 AC_LANG_PUSH([C])
274 AIRCRACK_NG_SIMD
275 AC_LANG_POP([C])
276 ])
277
278 AC_DEFUN([AIRCRACK_NG_SIMD_CXX], [
279 AC_LANG_PUSH([C++])
280 AIRCRACK_NG_SIMD
281 AC_LANG_POP([C++])
282 ])