Debian Codegraph @

hmmer/easel/m4/esl_sse.m4

raw
1 # ESL_SSE([ACTION-IF-FOUND], [ACTION-IF-NOT-FOUND])
2 #
3 # Check whether compiler supports features we need in our SSE
4 # implementations. HMMER3 is an example.
5 #
6 # We call this "SSE" in the generic sense of the lab's vector
7 # implementations in Easel, HMMER, Infernal, etc. More precisely, what
8 # we call "SSE" means support for <=SSE2, and what we call "SSE4"
9 # means support for <=SSE4.1.
10 #
11 # Tries to compile and link a test program using the current CC,
12 # CFLAGS, and (optionally) any SSE_CFLAGS passed by the user. If no
13 # SSE_CFLAGS are provided, then we try to determine them, by trying
14 # nothing (i.e. most compilers now deal with SSE intrinsics by
15 # default), then trying -msse2.
16 #
17 # Sets $esl_have_sse = yes | no
18 # Sets $esl_sse_cflags to any needed CFLAGS, such as -msse4.1
19 #
20 # A typical ACTION-IF-FOUND might be:
21 # AC_DEFINE(eslENABLE_SSE)
22 # SSE_CFLAGS=$esl_sse_cflags
23 # AC_SUBST(SSE_CFLAGS)
24 #
25 # (Note that this is correct, even if user provided SSE_CFLAGS;
26 # because if they did, all the macro does is make sure that they
27 # work, and sets esl_sse_cflags=$SSE_CFLAGS.)
28 #
29 # Do not replace the AC_LINK with an AC_RUN test. This is a test for
30 # whether the _compiler_ supports SSE, 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_SSE], [
35 AC_MSG_CHECKING([whether $CC can compile our SSE code])
36 esl_have_sse=no
37
38 if test "x$SSE_CFLAGS" != x; then
39 esl_sse_try_flags=$SSE_CFLAGS
40 else
41 esl_sse_try_flags="none -msse2"
42 fi
43
44 save_CFLAGS=$CFLAGS
45 for esl_sse_cflags in $esl_sse_try_flags; do
46 case $esl_sse_cflags in
47 none) CFLAGS=$save_CFLAGS;;
48 *) CFLAGS="$save_CFLAGS $esl_sse_cflags";;
49 esac
50
51 AC_LINK_IFELSE(
52 [AC_LANG_SOURCE([[
53 #include <x86intrin.h>
54 #include <stdint.h>
55 int stub_sse(void) {
56 __m128i v1 = _mm_set1_epi32(42);
57 __m128i v2 = _mm_set1_epi32(86);
58 union { __m128i v; int32_t x[4]; } v3;
59 v3.v = _mm_add_epi32(v1, v2);
60 return (int) v3.x[0];
61 }
62 int main(void) { if (stub_sse() != 128) return 1; else return 0; }
63 ]])], [ esl_have_sse=yes; break; ], [])
64 done
65
66 CFLAGS=$save_CFLAGS
67 if test "$esl_have_sse" = "no"; then
68 AC_MSG_RESULT([no])
69 esl_sse_cflags=
70 else
71 if test "$esl_sse_cflags" = "none"; then
72 AC_MSG_RESULT([yes])
73 esl_sse_cflags=
74 else
75 AC_MSG_RESULT([yes, with $esl_sse_cflags])
76 fi
77 fi
78
79 AS_VAR_IF([esl_have_sse],[yes],[$1],[$2])
80 ])
81
82
83