blob: fbd10cc6cf429abb23179da242ff4c3e83f85d84 [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.
33
34#serial 12
35
36AC_DEFUN([AX_EXT],
37[
38 AC_REQUIRE([AC_CANONICAL_HOST])
39
40 case $host_cpu in
41 i[[3456]]86*|x86_64*|amd64*)
42
43 AC_REQUIRE([AX_GCC_X86_CPUID])
44 AC_REQUIRE([AX_GCC_X86_AVX_XGETBV])
45
46 AX_GCC_X86_CPUID(0x00000001)
47 ecx=`echo $ax_cv_gcc_x86_cpuid_0x00000001 | cut -d ":" -f 3`
48 edx=`echo $ax_cv_gcc_x86_cpuid_0x00000001 | cut -d ":" -f 4`
49
50 AC_CACHE_CHECK([whether mmx is supported], [ax_cv_have_mmx_ext],
51 [
52 ax_cv_have_mmx_ext=no
53 if test "$((0x$edx>>23&0x01))" = 1; then
54 ax_cv_have_mmx_ext=yes
55 fi
56 ])
57
58 AC_CACHE_CHECK([whether sse is supported], [ax_cv_have_sse_ext],
59 [
60 ax_cv_have_sse_ext=no
61 if test "$((0x$edx>>25&0x01))" = 1; then
62 ax_cv_have_sse_ext=yes
63 fi
64 ])
65
66 AC_CACHE_CHECK([whether sse2 is supported], [ax_cv_have_sse2_ext],
67 [
68 ax_cv_have_sse2_ext=no
69 if test "$((0x$edx>>26&0x01))" = 1; then
70 ax_cv_have_sse2_ext=yes
71 fi
72 ])
73
74 AC_CACHE_CHECK([whether sse3 is supported], [ax_cv_have_sse3_ext],
75 [
76 ax_cv_have_sse3_ext=no
77 if test "$((0x$ecx&0x01))" = 1; then
78 ax_cv_have_sse3_ext=yes
79 fi
80 ])
81
82 AC_CACHE_CHECK([whether ssse3 is supported], [ax_cv_have_ssse3_ext],
83 [
84 ax_cv_have_ssse3_ext=no
85 if test "$((0x$ecx>>9&0x01))" = 1; then
86 ax_cv_have_ssse3_ext=yes
87 fi
88 ])
89
90 AC_CACHE_CHECK([whether sse4.1 is supported], [ax_cv_have_sse41_ext],
91 [
92 ax_cv_have_sse41_ext=no
93 if test "$((0x$ecx>>19&0x01))" = 1; then
94 ax_cv_have_sse41_ext=yes
95 fi
96 ])
97
98 AC_CACHE_CHECK([whether sse4.2 is supported], [ax_cv_have_sse42_ext],
99 [
100 ax_cv_have_sse42_ext=no
101 if test "$((0x$ecx>>20&0x01))" = 1; then
102 ax_cv_have_sse42_ext=yes
103 fi
104 ])
105
106 AC_CACHE_CHECK([whether avx is supported by processor], [ax_cv_have_avx_cpu_ext],
107 [
108 ax_cv_have_avx_cpu_ext=no
109 if test "$((0x$ecx>>28&0x01))" = 1; then
110 ax_cv_have_avx_cpu_ext=yes
111 fi
112 ])
113
114 if test x"$ax_cv_have_avx_cpu_ext" = x"yes"; then
115 AX_GCC_X86_AVX_XGETBV(0x00000000)
116
117 xgetbv_eax="0"
118 if test x"$ax_cv_gcc_x86_avx_xgetbv_0x00000000" != x"unknown"; then
119 xgetbv_eax=`echo $ax_cv_gcc_x86_avx_xgetbv_0x00000000 | cut -d ":" -f 1`
120 fi
121
122 AC_CACHE_CHECK([whether avx is supported by operating system], [ax_cv_have_avx_ext],
123 [
124 ax_cv_have_avx_ext=no
125
126 if test "$((0x$ecx>>27&0x01))" = 1; then
127 if test "$((0x$xgetbv_eax&0x6))" = 6; then
128 ax_cv_have_avx_ext=yes
129 fi
130 fi
131 ])
132 if test x"$ax_cv_have_avx_ext" = x"no"; then
133 AC_MSG_WARN([Your processor supports AVX, but your operating system doesn't])
134 fi
135 fi
136
137 if test "$ax_cv_have_mmx_ext" = yes; then
138 AX_CHECK_COMPILE_FLAG(-mmmx, ax_cv_support_mmx_ext=yes, [])
139 if test x"$ax_cv_support_mmx_ext" = x"yes"; then
140 SIMD_FLAGS="$SIMD_FLAGS -mmmx"
141 AC_DEFINE(HAVE_MMX,,[Support mmx instructions])
142 else
143 AC_MSG_WARN([Your processor supports mmx instructions but not your compiler, can you try another compiler?])
144 fi
145 fi
146
147 if test "$ax_cv_have_sse_ext" = yes; then
148 AX_CHECK_COMPILE_FLAG(-msse, ax_cv_support_sse_ext=yes, [])
149 if test x"$ax_cv_support_sse_ext" = x"yes"; then
150 SIMD_FLAGS="$SIMD_FLAGS -msse"
151 AC_DEFINE(HAVE_SSE,,[Support SSE (Streaming SIMD Extensions) instructions])
152 else
153 AC_MSG_WARN([Your processor supports sse instructions but not your compiler, can you try another compiler?])
154 fi
155 fi
156
157 if test "$ax_cv_have_sse2_ext" = yes; then
158 AX_CHECK_COMPILE_FLAG(-msse2, ax_cv_support_sse2_ext=yes, [])
159 if test x"$ax_cv_support_sse2_ext" = x"yes"; then
160 SIMD_FLAGS="$SIMD_FLAGS -msse2"
161 AC_DEFINE(HAVE_SSE2,,[Support SSE2 (Streaming SIMD Extensions 2) instructions])
162 else
163 AC_MSG_WARN([Your processor supports sse2 instructions but not your compiler, can you try another compiler?])
164 fi
165 fi
166
167 if test "$ax_cv_have_sse3_ext" = yes; then
168 AX_CHECK_COMPILE_FLAG(-msse3, ax_cv_support_sse3_ext=yes, [])
169 if test x"$ax_cv_support_sse3_ext" = x"yes"; then
170 SIMD_FLAGS="$SIMD_FLAGS -msse3"
171 AC_DEFINE(HAVE_SSE3,,[Support SSE3 (Streaming SIMD Extensions 3) instructions])
172 else
173 AC_MSG_WARN([Your processor supports sse3 instructions but not your compiler, can you try another compiler?])
174 fi
175 fi
176
177 if test "$ax_cv_have_ssse3_ext" = yes; then
178 AX_CHECK_COMPILE_FLAG(-mssse3, ax_cv_support_ssse3_ext=yes, [])
179 if test x"$ax_cv_support_ssse3_ext" = x"yes"; then
180 SIMD_FLAGS="$SIMD_FLAGS -mssse3"
181 AC_DEFINE(HAVE_SSSE3,,[Support SSSE3 (Supplemental Streaming SIMD Extensions 3) instructions])
182 else
183 AC_MSG_WARN([Your processor supports ssse3 instructions but not your compiler, can you try another compiler?])
184 fi
185 fi
186
187 if test "$ax_cv_have_sse41_ext" = yes; then
188 AX_CHECK_COMPILE_FLAG(-msse4.1, ax_cv_support_sse41_ext=yes, [])
189 if test x"$ax_cv_support_sse41_ext" = x"yes"; then
190 SIMD_FLAGS="$SIMD_FLAGS -msse4.1"
191 AC_DEFINE(HAVE_SSE4_1,,[Support SSSE4.1 (Streaming SIMD Extensions 4.1) instructions])
192 else
193 AC_MSG_WARN([Your processor supports sse4.1 instructions but not your compiler, can you try another compiler?])
194 fi
195 fi
196
197 if test "$ax_cv_have_sse42_ext" = yes; then
198 AX_CHECK_COMPILE_FLAG(-msse4.2, ax_cv_support_sse42_ext=yes, [])
199 if test x"$ax_cv_support_sse42_ext" = x"yes"; then
200 SIMD_FLAGS="$SIMD_FLAGS -msse4.2"
201 AC_DEFINE(HAVE_SSE4_2,,[Support SSSE4.2 (Streaming SIMD Extensions 4.2) instructions])
202 else
203 AC_MSG_WARN([Your processor supports sse4.2 instructions but not your compiler, can you try another compiler?])
204 fi
205 fi
206
207 if test "$ax_cv_have_avx_ext" = yes; then
208 AX_CHECK_COMPILE_FLAG(-mavx, ax_cv_support_avx_ext=yes, [])
209 if test x"$ax_cv_support_avx_ext" = x"yes"; then
210 SIMD_FLAGS="$SIMD_FLAGS -mavx"
211 AC_DEFINE(HAVE_AVX,,[Support AVX (Advanced Vector Extensions) instructions])
212 else
213 AC_MSG_WARN([Your processor supports avx instructions but not your compiler, can you try another compiler?])
214 fi
215 fi
216
217 ;;
218 esac
219
220 AC_SUBST(SIMD_FLAGS)
221])