Vadim Yanitskiy | 2c3066e | 2017-04-30 19:41:56 +0700 | [diff] [blame] | 1 | # =========================================================================== |
| 2 | # http://www.gnu.org/software/autoconf-archive/ax_ext.html |
| 3 | # =========================================================================== |
| 4 | # |
| 5 | # SYNOPSIS |
| 6 | # |
| 7 | # AX_EXT |
| 8 | # |
| 9 | # DESCRIPTION |
| 10 | # |
| 11 | # Find supported SIMD extensions by requesting cpuid. When an SIMD |
| 12 | # extension is found, the -m"simdextensionname" is added to SIMD_FLAGS if |
| 13 | # compiler supports it. For example, if "sse2" is available, then "-msse2" |
| 14 | # is added to SIMD_FLAGS. |
| 15 | # |
| 16 | # This macro calls: |
| 17 | # |
| 18 | # AC_SUBST(SIMD_FLAGS) |
| 19 | # |
| 20 | # And defines: |
| 21 | # |
| 22 | # HAVE_AVX3 / HAVE_SSE3 / HAVE_SSE4.1 |
| 23 | # |
| 24 | # LICENSE |
| 25 | # |
| 26 | # Copyright (c) 2007 Christophe Tournayre <turn3r@users.sourceforge.net> |
| 27 | # Copyright (c) 2013 Michael Petch <mpetch@capp-sysware.com> |
| 28 | # |
| 29 | # Copying and distribution of this file, with or without modification, are |
| 30 | # permitted in any medium without royalty provided the copyright notice |
| 31 | # and this notice are preserved. This file is offered as-is, without any |
| 32 | # warranty. |
| 33 | # |
| 34 | # NOTE: The functionality that requests the cpuid has been stripped because |
| 35 | # this project detects the CPU capabilities during runtime. However, we |
| 36 | # still need to check if the compiler supports the requested SIMD flag. |
| 37 | |
| 38 | #serial 12 |
| 39 | |
| 40 | AC_DEFUN([AX_CHECK_SIMD], |
| 41 | [ |
| 42 | AC_REQUIRE([AC_CANONICAL_HOST]) |
| 43 | |
Vadim Yanitskiy | 13f4762 | 2017-05-10 01:01:13 +0700 | [diff] [blame] | 44 | AM_CONDITIONAL(HAVE_AVX2, false) |
| 45 | AM_CONDITIONAL(HAVE_SSE3, false) |
| 46 | AM_CONDITIONAL(HAVE_SSE4_1, false) |
| 47 | |
Vadim Yanitskiy | 2c3066e | 2017-04-30 19:41:56 +0700 | [diff] [blame] | 48 | case $host_cpu in |
| 49 | i[[3456]]86*|x86_64*|amd64*) |
| 50 | AX_CHECK_COMPILE_FLAG(-mavx2, ax_cv_support_avx2_ext=yes, []) |
| 51 | if test x"$ax_cv_support_avx2_ext" = x"yes"; then |
| 52 | SIMD_FLAGS="$SIMD_FLAGS -mavx2" |
| 53 | AC_DEFINE(HAVE_AVX2,, |
| 54 | [Support AVX2 (Advanced Vector Extensions 2) instructions]) |
| 55 | AM_CONDITIONAL(HAVE_AVX2, true) |
| 56 | else |
| 57 | AC_MSG_WARN([Your compiler does not support AVX2 instructions]) |
Vadim Yanitskiy | 2c3066e | 2017-04-30 19:41:56 +0700 | [diff] [blame] | 58 | fi |
| 59 | |
| 60 | AX_CHECK_COMPILE_FLAG(-msse3, ax_cv_support_sse3_ext=yes, []) |
| 61 | if test x"$ax_cv_support_sse3_ext" = x"yes"; then |
| 62 | SIMD_FLAGS="$SIMD_FLAGS -msse3" |
| 63 | AC_DEFINE(HAVE_SSE3,, |
| 64 | [Support SSE3 (Streaming SIMD Extensions 3) instructions]) |
| 65 | AM_CONDITIONAL(HAVE_SSE3, true) |
| 66 | else |
| 67 | AC_MSG_WARN([Your compiler does not support SSE3 instructions]) |
Vadim Yanitskiy | 2c3066e | 2017-04-30 19:41:56 +0700 | [diff] [blame] | 68 | fi |
| 69 | |
| 70 | AX_CHECK_COMPILE_FLAG(-msse4.1, ax_cv_support_sse41_ext=yes, []) |
| 71 | if test x"$ax_cv_support_sse41_ext" = x"yes"; then |
| 72 | SIMD_FLAGS="$SIMD_FLAGS -msse4.1" |
| 73 | AC_DEFINE(HAVE_SSE4_1,, |
| 74 | [Support SSE4.1 (Streaming SIMD Extensions 4.1) instructions]) |
| 75 | AM_CONDITIONAL(HAVE_SSE4_1, true) |
| 76 | else |
| 77 | AC_MSG_WARN([Your compiler does not support SSE4.1 instructions]) |
Vadim Yanitskiy | 2c3066e | 2017-04-30 19:41:56 +0700 | [diff] [blame] | 78 | fi |
| 79 | ;; |
| 80 | esac |
| 81 | |
| 82 | AC_SUBST(SIMD_FLAGS) |
| 83 | ]) |