blob: ed4d223891114ee144825d0cf13eda9052c913ce [file] [log] [blame]
Thomas Tsou3eaae802013-08-20 19:31:14 -04001# ===========================================================================
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_MMX / HAVE_SSE / HAVE_SSE2 / HAVE_SSE3 / HAVE_SSSE3 / HAVE_SSE4.1 / HAVE_SSE4.2 / HAVE_AVX
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.
Philipp Maierf5bf33b2017-03-16 13:12:07 +010033#
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
Thomas Tsou3eaae802013-08-20 19:31:14 -040037
38#serial 12
39
Philipp Maiere8ae9fc2017-03-20 12:08:42 +010040AC_DEFUN([AX_SSE],
Thomas Tsou3eaae802013-08-20 19:31:14 -040041[
42 AC_REQUIRE([AC_CANONICAL_HOST])
43
44 case $host_cpu in
45 i[[3456]]86*|x86_64*|amd64*)
46
47 AC_REQUIRE([AX_GCC_X86_CPUID])
48 AC_REQUIRE([AX_GCC_X86_AVX_XGETBV])
49
50 AX_GCC_X86_CPUID(0x00000001)
Thomas Tsou3eaae802013-08-20 19:31:14 -040051
Philipp Maierf5bf33b2017-03-16 13:12:07 +010052 AX_CHECK_COMPILE_FLAG(-msse3, ax_cv_support_sse3_ext=yes, [])
53 if test x"$ax_cv_support_sse3_ext" = x"yes"; then
54 SIMD_FLAGS="$SIMD_FLAGS -msse3"
55 AC_DEFINE(HAVE_SSE3,,[Support SSE3 (Streaming SIMD Extensions 3) instructions])
Philipp Maiere8ae9fc2017-03-20 12:08:42 +010056 AM_CONDITIONAL(HAVE_SSE3, true)
Philipp Maierf5bf33b2017-03-16 13:12:07 +010057 else
58 AC_MSG_WARN([Your compiler does not support sse3 instructions, can you try another compiler?])
Philipp Maiere8ae9fc2017-03-20 12:08:42 +010059 AM_CONDITIONAL(HAVE_SSE3, false)
Thomas Tsou3eaae802013-08-20 19:31:14 -040060 fi
61
Philipp Maierf5bf33b2017-03-16 13:12:07 +010062 AX_CHECK_COMPILE_FLAG(-msse4.1, ax_cv_support_sse41_ext=yes, [])
63 if test x"$ax_cv_support_sse41_ext" = x"yes"; then
64 SIMD_FLAGS="$SIMD_FLAGS -msse4.1"
65 AC_DEFINE(HAVE_SSE4_1,,[Support SSE4.1 (Streaming SIMD Extensions 4.1) instructions])
Philipp Maiere8ae9fc2017-03-20 12:08:42 +010066 AM_CONDITIONAL(HAVE_SSE4_1, true)
Philipp Maierf5bf33b2017-03-16 13:12:07 +010067 else
68 AC_MSG_WARN([Your compiler does not support sse4.1 instructions, can you try another compiler?])
Philipp Maiere8ae9fc2017-03-20 12:08:42 +010069 AM_CONDITIONAL(HAVE_SSE4_1, false)
Thomas Tsou3eaae802013-08-20 19:31:14 -040070 fi
Thomas Tsou3eaae802013-08-20 19:31:14 -040071 ;;
72 esac
73
74 AC_SUBST(SIMD_FLAGS)
75])