Debian Codegraph @

easel/m4/esl_neon.m4

raw
1 # ESL_NEON([ACTION-IF-FOUND], [ACTION-IF-NOT-FOUND])
2 #
3 # Check whether compiler supports features we need in our ARM NEON
4 # implementations.
5 #
6 # Tries to compile and link a test program using the current CC,
7 # CFLAGS, and (optionally) any NEON_CFLAGS passed by the user. If no
8 # NEON_CFLAGS are provided, then we try to determine them, by trying
9 # nothing (i.e. the compiler deals with ARM NEON intrinsics by
10 # default), then trying -mfpu=neon.
11 #
12 # If the platform supports NEON, additionally test if it supports
13 # AARCH64 (ARMv8) specific intrinsics; set $esl_have_neon_aarch64 if
14 # so.
15 #
16 # Sets $esl_have_neon = yes | no
17 # Sets $esl_have_neon_aarch64 = yes | no
18 # Sets $esl_neon_cflags to any needed CFLAGS, such as -mfpu-neon
19 #
20 # A typical ACTION-IF-FOUND might be:
21 # AC_DEFINE(HAVE_NEON)
22 # AS_VAR_IF([esl_have_neon_aarch64],[yes],AC_DEFINE(HAVE_NEON_AARCH64))
23 # NEON_CFLAGS=$esl_neon_cflags
24 # AC_SUBST(NEON_CFLAGS)
25 #
26 # (Note that this is correct even if user provided NEON_CFLAGS;
27 # because if they did, all the macro does is make sure that they
28 # work, and sets esl_neon_cflags=$NEON_CFLAGS.)
29 #
30 # Do not replace the AC_LINK with an AC_RUN test. This is a test for
31 # whether the _compiler_ supports NEON, 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_NEON], [
36 AC_MSG_CHECKING([whether $CC can compile our NEON code])
37 esl_have_neon=no
38 esl_have_neon_aarch64=no
39
40 if test "x$NEON_CFLAGS" != x; then
41 esl_neon_try_flags=$NEON_CFLAGS
42 else
43 esl_neon_try_flags="none -mfpu=neon"
44 fi
45
46 save_CFLAGS=$CFLAGS
47 for esl_neon_cflags in $esl_neon_try_flags; do
48 case $esl_neon_cflags in
49 none) CFLAGS=$save_CFLAGS;;
50 *) CFLAGS="$save_CFLAGS $esl_neon_cflags";;
51 esac
52
53 AC_LINK_IFELSE(
54 [AC_LANG_SOURCE([[
55 #include <stdint.h>
56 #include <arm_neon.h>
57 int stub_neon(void) {
58 int32x4_t v1 = vdupq_n_s32(42);
59 int32x4_t v2 = vdupq_n_s32(86);
60 union { int32x4_t v; int32_t x[4]; } v3;
61 v3.v = vaddq_s32(v1, v2);
62 return (int) v3.x[0];
63 }
64 int main(void) { if (stub_neon() != 128) return 1; else return 0; }
65 ]])], [ esl_have_neon=yes; break; ], [])
66 done
67
68
69 # Test for the AARCH64 (ARMv8) flavor of the NEON intrinsics,
70 # or at least the instructions we need from it, using the
71 # same CFLAGS we just figured out.
72 AC_LINK_IFELSE(
73 [AC_LANG_SOURCE([[
74 #include <stdint.h>
75 #include <arm_neon.h>
76 int main(void) {
77 int16x8_t a1 = { 1, 2, 8, 3, 4, 5, 6, 7 };
78 int16_t r1 = vmaxvq_s16(a1); // = 8 : horizontal max
79 uint8x16_t a2 = { 1, 2, 16, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 };
80 uint8_t r2 = vmaxvq_u8(a2); // = 16 : horizontal max
81 float32x4_t a3 = { 1.0, 2.0, 3.0, 4.0 };
82 float r3 = vaddvq_f32(a3); // = 10.0 : horizontal sum
83 return 0;
84 }
85 ]])], [esl_have_neon_aarch64=yes], [])
86
87 CFLAGS=$save_CFLAGS
88 if test "$esl_have_neon" = "no"; then
89 AC_MSG_RESULT([no])
90 esl_neon_cflags=
91 else
92 if test "$esl_have_neon_aarch64" = "no"; then
93 if test "$esl_neon_cflags" = "none"; then
94 AC_MSG_RESULT([yes, armv7 flavor])
95 esl_neon_cflags=
96 else
97 AC_MSG_RESULT([yes, armv7 flavor, with $esl_neon_cflags])
98 fi
99 else
100 if test "$esl_neon_cflags" = "none"; then
101 AC_MSG_RESULT([yes, aarch64 flavor])
102 esl_neon_cflags=
103 else
104 AC_MSG_RESULT([yes, aarch64 flavor, with $esl_neon_cflags])
105 fi
106 fi
107 fi
108
109 AS_VAR_IF([esl_have_neon],[yes],[$1],[$2])
110 ])
111
112
113