2 # Modified from autoconf-archive to replace AC_REQUIRE([AX_GCC_X86_*]) with
3 # AX_REQUIRE_DEFINED(...).
5 # ===========================================================================
6 # http://www.gnu.org/software/autoconf-archive/ax_ext.html
7 # ===========================================================================
15 # Find supported SIMD extensions by requesting cpuid. When an SIMD
16 # extension is found, the -m"simdextensionname" is added to SIMD_FLAGS if
17 # compiler supports it. For example, if "sse2" is available, then "-msse2"
18 # is added to SIMD_FLAGS.
22 # AC_SUBST(SIMD_FLAGS)
26 # HAVE_MMX / HAVE_SSE / HAVE_SSE2 / HAVE_SSE3 / HAVE_SSSE3 / HAVE_SSE4.1 / HAVE_SSE4.2 / HAVE_AVX
30 # Copyright (c) 2007 Christophe Tournayre <turn3r@users.sourceforge.net>
31 # Copyright (c) 2013 Michael Petch <mpetch@capp-sysware.com>
33 # Copying and distribution of this file, with or without modification, are
34 # permitted in any medium without royalty provided the copyright notice
35 # and this notice are preserved. This file is offered as-is, without any
42 AC_REQUIRE([AC_CANONICAL_HOST])
46 AC_CACHE_CHECK([whether altivec is supported], [ax_cv_have_altivec_ext],
48 if test `/usr/sbin/sysctl -a 2>/dev/null| grep -c hw.optional.altivec` != 0; then
49 if test `/usr/sbin/sysctl -n hw.optional.altivec` = 1; then
50 ax_cv_have_altivec_ext=yes
55 if test "$ax_cv_have_altivec_ext" = yes; then
56 AC_DEFINE(HAVE_ALTIVEC,,[Support Altivec instructions])
57 AX_CHECK_COMPILE_FLAG(-faltivec, SIMD_FLAGS="$SIMD_FLAGS -faltivec", [])
62 i[[3456]]86*|x86_64*|amd64*)
64 AX_REQUIRE_DEFINED([AX_GCC_X86_CPUID])
65 AX_REQUIRE_DEFINED([AX_GCC_X86_AVX_XGETBV])
67 AX_GCC_X86_CPUID(0x00000001)
70 if test "$ax_cv_gcc_x86_cpuid_0x00000001" != "unknown";
72 ecx=`echo $ax_cv_gcc_x86_cpuid_0x00000001 | cut -d ":" -f 3`
73 edx=`echo $ax_cv_gcc_x86_cpuid_0x00000001 | cut -d ":" -f 4`
76 AC_CACHE_CHECK([whether mmx is supported], [ax_cv_have_mmx_ext],
79 if test "$((0x$edx>>23&0x01))" = 1; then
80 ax_cv_have_mmx_ext=yes
84 AC_CACHE_CHECK([whether sse is supported], [ax_cv_have_sse_ext],
87 if test "$((0x$edx>>25&0x01))" = 1; then
88 ax_cv_have_sse_ext=yes
92 AC_CACHE_CHECK([whether sse2 is supported], [ax_cv_have_sse2_ext],
94 ax_cv_have_sse2_ext=no
95 if test "$((0x$edx>>26&0x01))" = 1; then
96 ax_cv_have_sse2_ext=yes
100 AC_CACHE_CHECK([whether sse3 is supported], [ax_cv_have_sse3_ext],
102 ax_cv_have_sse3_ext=no
103 if test "$((0x$ecx&0x01))" = 1; then
104 ax_cv_have_sse3_ext=yes
108 AC_CACHE_CHECK([whether ssse3 is supported], [ax_cv_have_ssse3_ext],
110 ax_cv_have_ssse3_ext=no
111 if test "$((0x$ecx>>9&0x01))" = 1; then
112 ax_cv_have_ssse3_ext=yes
116 AC_CACHE_CHECK([whether sse4.1 is supported], [ax_cv_have_sse41_ext],
118 ax_cv_have_sse41_ext=no
119 if test "$((0x$ecx>>19&0x01))" = 1; then
120 ax_cv_have_sse41_ext=yes
124 AC_CACHE_CHECK([whether sse4.2 is supported], [ax_cv_have_sse42_ext],
126 ax_cv_have_sse42_ext=no
127 if test "$((0x$ecx>>20&0x01))" = 1; then
128 ax_cv_have_sse42_ext=yes
132 AC_CACHE_CHECK([whether avx is supported by processor], [ax_cv_have_avx_cpu_ext],
134 ax_cv_have_avx_cpu_ext=no
135 if test "$((0x$ecx>>28&0x01))" = 1; then
136 ax_cv_have_avx_cpu_ext=yes
140 if test x"$ax_cv_have_avx_cpu_ext" = x"yes"; then
141 AX_GCC_X86_AVX_XGETBV(0x00000000)
144 if test x"$ax_cv_gcc_x86_avx_xgetbv_0x00000000" != x"unknown"; then
145 xgetbv_eax=`echo $ax_cv_gcc_x86_avx_xgetbv_0x00000000 | cut -d ":" -f 1`
148 AC_CACHE_CHECK([whether avx is supported by operating system], [ax_cv_have_avx_ext],
150 ax_cv_have_avx_ext=no
152 if test "$((0x$ecx>>27&0x01))" = 1; then
153 if test "$((0x$xgetbv_eax&0x6))" = 6; then
154 ax_cv_have_avx_ext=yes
158 if test x"$ax_cv_have_avx_ext" = x"no"; then
159 AC_MSG_WARN([Your processor supports AVX, but your operating system doesn't])
163 if test "$ax_cv_have_mmx_ext" = yes; then
164 AX_CHECK_COMPILE_FLAG(-mmmx, ax_cv_support_mmx_ext=yes, [])
165 if test x"$ax_cv_support_mmx_ext" = x"yes"; then
166 SIMD_FLAGS="$SIMD_FLAGS -mmmx"
167 AC_DEFINE(HAVE_MMX,,[Support mmx instructions])
169 AC_MSG_WARN([Your processor supports mmx instructions but not your compiler, can you try another compiler?])
173 if test "$ax_cv_have_sse_ext" = yes; then
174 AX_CHECK_COMPILE_FLAG(-msse, ax_cv_support_sse_ext=yes, [])
175 if test x"$ax_cv_support_sse_ext" = x"yes"; then
176 SIMD_FLAGS="$SIMD_FLAGS -msse"
177 AC_DEFINE(HAVE_SSE,,[Support SSE (Streaming SIMD Extensions) instructions])
179 AC_MSG_WARN([Your processor supports sse instructions but not your compiler, can you try another compiler?])
183 if test "$ax_cv_have_sse2_ext" = yes; then
184 AX_CHECK_COMPILE_FLAG(-msse2, ax_cv_support_sse2_ext=yes, [])
185 if test x"$ax_cv_support_sse2_ext" = x"yes"; then
186 SIMD_FLAGS="$SIMD_FLAGS -msse2"
187 AC_DEFINE(HAVE_SSE2,,[Support SSE2 (Streaming SIMD Extensions 2) instructions])
189 AC_MSG_WARN([Your processor supports sse2 instructions but not your compiler, can you try another compiler?])
193 if test "$ax_cv_have_sse3_ext" = yes; then
194 AX_CHECK_COMPILE_FLAG(-msse3, ax_cv_support_sse3_ext=yes, [])
195 if test x"$ax_cv_support_sse3_ext" = x"yes"; then
196 SIMD_FLAGS="$SIMD_FLAGS -msse3"
197 AC_DEFINE(HAVE_SSE3,,[Support SSE3 (Streaming SIMD Extensions 3) instructions])
199 AC_MSG_WARN([Your processor supports sse3 instructions but not your compiler, can you try another compiler?])
203 if test "$ax_cv_have_ssse3_ext" = yes; then
204 AX_CHECK_COMPILE_FLAG(-mssse3, ax_cv_support_ssse3_ext=yes, [])
205 if test x"$ax_cv_support_ssse3_ext" = x"yes"; then
206 SIMD_FLAGS="$SIMD_FLAGS -mssse3"
207 AC_DEFINE(HAVE_SSSE3,,[Support SSSE3 (Supplemental Streaming SIMD Extensions 3) instructions])
209 AC_MSG_WARN([Your processor supports ssse3 instructions but not your compiler, can you try another compiler?])
213 if test "$ax_cv_have_sse41_ext" = yes; then
214 AX_CHECK_COMPILE_FLAG(-msse4.1, ax_cv_support_sse41_ext=yes, [])
215 if test x"$ax_cv_support_sse41_ext" = x"yes"; then
216 SIMD_FLAGS="$SIMD_FLAGS -msse4.1"
217 AC_DEFINE(HAVE_SSE4_1,,[Support SSSE4.1 (Streaming SIMD Extensions 4.1) instructions])
219 AC_MSG_WARN([Your processor supports sse4.1 instructions but not your compiler, can you try another compiler?])
223 if test "$ax_cv_have_sse42_ext" = yes; then
224 AX_CHECK_COMPILE_FLAG(-msse4.2, ax_cv_support_sse42_ext=yes, [])
225 if test x"$ax_cv_support_sse42_ext" = x"yes"; then
226 SIMD_FLAGS="$SIMD_FLAGS -msse4.2"
227 AC_DEFINE(HAVE_SSE4_2,,[Support SSSE4.2 (Streaming SIMD Extensions 4.2) instructions])
229 AC_MSG_WARN([Your processor supports sse4.2 instructions but not your compiler, can you try another compiler?])
233 if test "$ax_cv_have_avx_ext" = yes; then
234 AX_CHECK_COMPILE_FLAG(-mavx, ax_cv_support_avx_ext=yes, [])
235 if test x"$ax_cv_support_avx_ext" = x"yes"; then
236 SIMD_FLAGS="$SIMD_FLAGS -mavx"
237 AC_DEFINE(HAVE_AVX,,[Support AVX (Advanced Vector Extensions) instructions])
239 AC_MSG_WARN([Your processor supports avx instructions but not your compiler, can you try another compiler?])