blob: daca2beb97811cbf6b940d341c00b9aa16c7dcd9 [file] [log] [blame]
Vadim Yanitskiy2c3066e2017-04-30 19:41:56 +07001# ===========================================================================
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#
Harald Welteb93f60f2017-11-17 11:41:34 +010022# HAVE_AVX3 / HAVE_SSSE3 / HAVE_SSE4.1
Vadim Yanitskiy2c3066e2017-04-30 19:41:56 +070023#
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
40AC_DEFUN([AX_CHECK_SIMD],
41[
42 AC_REQUIRE([AC_CANONICAL_HOST])
43
Vadim Yanitskiy13f47622017-05-10 01:01:13 +070044 AM_CONDITIONAL(HAVE_AVX2, false)
Harald Welteb93f60f2017-11-17 11:41:34 +010045 AM_CONDITIONAL(HAVE_SSSE3, false)
Vadim Yanitskiy13f47622017-05-10 01:01:13 +070046 AM_CONDITIONAL(HAVE_SSE4_1, false)
47
Vadim Yanitskiy2c3066e2017-04-30 19:41:56 +070048 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 Yanitskiy2c3066e2017-04-30 19:41:56 +070058 fi
59
Harald Welteb93f60f2017-11-17 11:41:34 +010060 AX_CHECK_COMPILE_FLAG(-mssse3, ax_cv_support_ssse3_ext=yes, [])
61 if test x"$ax_cv_support_ssse3_ext" = x"yes"; then
62 SIMD_FLAGS="$SIMD_FLAGS -mssse3"
63 AC_DEFINE(HAVE_SSSE3,,
64 [Support SSSE3 (Supplemental Streaming SIMD Extensions 3) instructions])
65 AM_CONDITIONAL(HAVE_SSSE3, true)
Vadim Yanitskiy2c3066e2017-04-30 19:41:56 +070066 else
Harald Welteb93f60f2017-11-17 11:41:34 +010067 AC_MSG_WARN([Your compiler does not support SSSE3 instructions])
Vadim Yanitskiy2c3066e2017-04-30 19:41:56 +070068 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 Yanitskiy2c3066e2017-04-30 19:41:56 +070078 fi
79 ;;
80 esac
81
82 AC_SUBST(SIMD_FLAGS)
83])