blob: d07d706fba59658a692b24f66784e9163bdd9c12 [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#
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
40AC_DEFUN([AX_CHECK_SIMD],
41[
42 AC_REQUIRE([AC_CANONICAL_HOST])
43
44 case $host_cpu in
45 i[[3456]]86*|x86_64*|amd64*)
46 AX_CHECK_COMPILE_FLAG(-mavx2, ax_cv_support_avx2_ext=yes, [])
47 if test x"$ax_cv_support_avx2_ext" = x"yes"; then
48 SIMD_FLAGS="$SIMD_FLAGS -mavx2"
49 AC_DEFINE(HAVE_AVX2,,
50 [Support AVX2 (Advanced Vector Extensions 2) instructions])
51 AM_CONDITIONAL(HAVE_AVX2, true)
52 else
53 AC_MSG_WARN([Your compiler does not support AVX2 instructions])
54 AM_CONDITIONAL(HAVE_AVX2, false)
55 fi
56
57 AX_CHECK_COMPILE_FLAG(-msse3, ax_cv_support_sse3_ext=yes, [])
58 if test x"$ax_cv_support_sse3_ext" = x"yes"; then
59 SIMD_FLAGS="$SIMD_FLAGS -msse3"
60 AC_DEFINE(HAVE_SSE3,,
61 [Support SSE3 (Streaming SIMD Extensions 3) instructions])
62 AM_CONDITIONAL(HAVE_SSE3, true)
63 else
64 AC_MSG_WARN([Your compiler does not support SSE3 instructions])
65 AM_CONDITIONAL(HAVE_SSE3, false)
66 fi
67
68 AX_CHECK_COMPILE_FLAG(-msse4.1, ax_cv_support_sse41_ext=yes, [])
69 if test x"$ax_cv_support_sse41_ext" = x"yes"; then
70 SIMD_FLAGS="$SIMD_FLAGS -msse4.1"
71 AC_DEFINE(HAVE_SSE4_1,,
72 [Support SSE4.1 (Streaming SIMD Extensions 4.1) instructions])
73 AM_CONDITIONAL(HAVE_SSE4_1, true)
74 else
75 AC_MSG_WARN([Your compiler does not support SSE4.1 instructions])
76 AM_CONDITIONAL(HAVE_SSE4_1, false)
77 fi
78 ;;
79 esac
80
81 AC_SUBST(SIMD_FLAGS)
82])