Debian Codegraph @

hmmer/easel/m4/esl_sse4.m4

raw
1 # ESL_SSE4([ACTION-IF-FOUND], [ACTION-IF-NOT-FOUND])
2 #
3 # Check whether compiler supports features we need in an SSE4 vector
4 # implementation. HMMER4 is an example.
5 #
6 # We call this "SSE4" in the generic sense of the lab's vector
7 # implementations, which we classify as "SSE" (<= SSE2 support),
8 # "SSE4" (<= SSE4.1), "AVX" (<= AVX2), "AVX512". More precisely, we
9 # check for support of intrinsics up to and including SSE4.1.
10 #
11 # Tries to compile and link a test program using the current CC,
12 # CFLAGS, and (optionally) any SSE4_CFLAGS passed by the user. If no
13 # SSE4_CFLAGS are provided, then we try to determine them, by trying
14 # nothing (i.e. the compiler deals with SSE intrinsics by default),
15 # then trying -msse4.1.
16 #
17 # Sets $esl_have_sse4 = yes | no
18 # Sets $esl_sse4_cflags to any needed CFLAGS, such as -msse4.1
19 #
20 # A typical ACTION-IF-FOUND might be:
21 # AC_DEFINE(eslENABLE_SSE4)
22 # SSE_CFLAGS=$esl_sse4_cflags
23 # AC_SUBST(SSE4_CFLAGS)
24 #
25 # (Note that this is correct, even if user provided SSE4_CFLAGS;
26 # because if they did, all the macro does is make sure that they
27 # work, and sets esl_sse4_cflags=$SSE4_CFLAGS.)
28 #
29 # Do not replace the AC_LINK with an AC_RUN test. This is a test for
30 # whether the _compiler_ supports SSE4.1, not whether the current
31 # processor does. Our code uses runtime dispatching to choose an
32 # appropriate ISA for the processor being used.
33 #
34 AC_DEFUN([ESL_SSE4], [
35 AC_MSG_CHECKING([whether $CC can compile our SSE4 code])
36 esl_have_sse4=no
37
38 if test "x$SSE4_CFLAGS" != x; then
39 esl_sse4_try_flags=$SSE4_CFLAGS
40 else
41 esl_sse4_try_flags="none -msse4.1"
42 fi
43
44 save_CFLAGS=$CFLAGS
45 for esl_sse4_cflags in $esl_sse4_try_flags; do
46 case $esl_sse4_cflags in
47 none) CFLAGS=$save_CFLAGS;;
48 *) CFLAGS="$save_CFLAGS $esl_sse4_cflags";;
49 esac
50
51 AC_LINK_IFELSE(
52 [AC_LANG_SOURCE([[
53 #include <x86intrin.h>
54 #include <stdint.h>
55 int stub_sse4(void) {
56 __m128i v1 = _mm_set1_epi8(-42);
57 __m128i v2 = _mm_set1_epi8(-86);
58 union { __m128i v; int8_t x[16]; } v3;
59 v3.v = _mm_adds_epi8(v1, v2);
60 v2 = _mm_max_epi8(v1, v1);
61 return (int) -v3.x[0];
62 }
63 int main(void) { if (stub_sse4() != 128) return 1; else return 0; }
64 ]])], [ esl_have_sse4=yes; break; ], [])
65 done
66
67 CFLAGS=$save_CFLAGS
68 if test "$esl_have_sse4" = "no"; then
69 AC_MSG_RESULT([no])
70 esl_sse4_cflags=
71 else
72 if test "$esl_sse4_cflags" = "none"; then
73 AC_MSG_RESULT([yes])
74 esl_sse4_cflags=
75 else
76 AC_MSG_RESULT([yes, with $esl_sse4_cflags])
77 fi
78 fi
79
80 AS_VAR_IF([esl_have_sse4],[yes],[$1],[$2])
81 ])
82
83
84