Debian Codegraph @

easel/m4/esl_avx.m4

raw
1 # ESL_AVX([ACTION-IF-FOUND], [ACTION-IF-NOT-FOUND])
2 #
3 # Checks whether compiler supports features we need in our AVX
4 # implementations (including AVX2).
5 #
6 # We call this "AVX" in the generic sense of the lab's vector
7 # implementations in Easel, HMMER, Infernal, etc; but more precisely,
8 # we're also checking for AVX2 intrinsic support.
9 #
10 # Tries to compile and link a test program using the current CC,
11 # CFLAGS, and (optionally) any AVX_CFLAGS passed by the user. If
12 # AVX_CFLAGS are not provided, then we try to determine them, by
13 # trying nothing (i.e. the compiler deals with AVX intrinsics by
14 # default), then trying:
15 # -mavx2
16 # -march=haswell
17 #
18 # Sets $esl_have_avx = yes | no
19 # Sets $esl_avx_cflags to any extra needed CFLAGS, such as -mavx2
20 #
21 # A typical ACTION-IF-FOUND might be:
22 # AC_DEFINE(HAVE_AVX)
23 # AVX_CFLAGS=$esl_avx_cflags
24 # AC_SUBST(AVX_CFLAGS)
25 #
26 # (Note that this is correct, even if user provided AVX_CFLAGS;
27 # because if they did, all the macro does is make sure that they
28 # work, and sets esl_avx_cflags=$AVX_CFLAGS.)
29 #
30 # Do not replace the AC_LINK with an AC_RUN test. This is a test for
31 # whether the _compiler_ supports AVX2, not whether the current
32 # processor does. Our code uses runtime dispatching to choose an
33 # appropriate ISA for the processor being used.
34 #
35 AC_DEFUN([ESL_AVX],[
36 AC_MSG_CHECKING([whether $CC can compile our AVX code])
37 esl_have_avx=no
38
39 if test "x$AVX_CFLAGS" != x; then
40 esl_avx_try_flags=$AVX_CFLAGS
41 else
42 esl_avx_try_flags="none -mavx2 -march=haswell"
43 fi
44
45 save_CFLAGS=$CFLAGS
46 for esl_avx_cflags in $esl_avx_try_flags; do
47 case $esl_avx_cflags in
48 none) CFLAGS=$save_CFLAGS;;
49 *) CFLAGS="$save_CFLAGS $esl_avx_cflags";;
50 esac
51
52 AC_LINK_IFELSE([AC_LANG_SOURCE([[
53 #include <x86intrin.h>
54 #include <stdio.h>
55 #include <stdint.h>
56 int main(void) {
57 __m256i v1 = _mm256_set1_epi32(42);
58 __m256i v2 = _mm256_set1_epi32(214);
59 union { __m256i v; int32_t x[8]; } v3;
60 v3.v = _mm256_add_epi32(v1, v2);
61 printf("%d\n", v3.x[2]);}
62 ]])], [ esl_have_avx=yes; break; ], [])
63 done
64
65 CFLAGS=$save_CFLAGS
66 if test "$esl_have_avx" = "no"; then
67 AC_MSG_RESULT([no])
68 esl_avx_cflags=
69 else
70 if test "$esl_avx_cflags" = "none"; then
71 AC_MSG_RESULT([yes])
72 esl_avx_cflags=
73 else
74 AC_MSG_RESULT([yes, with $esl_avx_cflags])
75 fi
76 fi
77
78 AS_VAR_IF([esl_have_avx],[yes],[$1],[$2])
79 ])