1 # ===========================================================================
2 # http://www.gnu.org/software/autoconf-archive/ax_ext.html
3 # ===========================================================================
11 # Find supported SIMD extensions by requesting cpuid. When an SIMD
12 # extension is found, the -m"simdextensionname" is added to SIMD_FLAGS
13 # (only if compilator support it) (ie : if "sse2" is available "-msse2" is
14 # added to SIMD_FLAGS)
18 # AC_SUBST(SIMD_FLAGS)
22 # HAVE_MMX / HAVE_SSE / HAVE_SSE2 / HAVE_SSE3 / HAVE_SSSE3 /
23 # HAVE_SSE41 / HAVE_SSE42 / HAVE_AVX
27 # Copyright (c) 2008 Christophe Tournayre <turn3r@users.sourceforge.net>
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
35 # * March 23, 2012 Joseph D. Gaeddert <jgaedder@vt.edu>
36 # Including tests for proper intrinsics header files in addition to cpu
43 # SSE4.1/4.2 : smmintrin.h
50 AC_REQUIRE([AX_GCC_X86_CPUID])
52 AX_GCC_X86_CPUID(0x00000001)
55 if test "$ax_cv_gcc_x86_cpuid_0x00000001" != "unknown";
57 ecx=`echo $ax_cv_gcc_x86_cpuid_0x00000001 | cut -d ":" -f 3`
58 edx=`echo $ax_cv_gcc_x86_cpuid_0x00000001 | cut -d ":" -f 4`
61 AC_CHECK_HEADERS(mmintrin.h xmmintrin.h emmintrin.h pmmintrin.h tmmintrin.h smmintrin.h immintrin.h)
63 AC_CACHE_CHECK([whether mmx is supported], [ax_cv_have_mmx_ext],
66 if test "$((0x$edx>>23&0x01))" = 1; then
67 ax_cv_have_mmx_ext=yes
71 AC_CACHE_CHECK([whether sse is supported], [ax_cv_have_sse_ext],
74 if test "$((0x$edx>>25&0x01))" = 1; then
75 ax_cv_have_sse_ext=yes
79 AC_CACHE_CHECK([whether sse2 is supported], [ax_cv_have_sse2_ext],
81 ax_cv_have_sse2_ext=no
82 if test "$((0x$edx>>26&0x01))" = 1; then
83 ax_cv_have_sse2_ext=yes
87 AC_CACHE_CHECK([whether sse3 is supported], [ax_cv_have_sse3_ext],
89 ax_cv_have_sse3_ext=no
90 if test "$((0x$ecx&0x01))" = 1; then
91 ax_cv_have_sse3_ext=yes
95 AC_CACHE_CHECK([whether ssse3 is supported], [ax_cv_have_ssse3_ext],
97 ax_cv_have_ssse3_ext=no
98 if test "$((0x$ecx>>9&0x01))" = 1; then
99 ax_cv_have_ssse3_ext=yes
103 AC_CACHE_CHECK([whether sse4.1 is supported], [ax_cv_have_sse41_ext],
105 ax_cv_have_sse41_ext=no
106 if test "$((0x$ecx>>19&0x01))" = 1; then
107 ax_cv_have_sse41_ext=yes
111 AC_CACHE_CHECK([whether sse4.2 is supported], [ax_cv_have_sse42_ext],
113 ax_cv_have_sse42_ext=no
114 if test "$((0x$ecx>>20&0x01))" = 1; then
115 ax_cv_have_sse42_ext=yes
119 AC_CACHE_CHECK([whether avx is supported], [ax_cv_have_avx_ext],
121 ax_cv_have_avx_ext=no
122 if test "$((0x$ecx>>28&0x01))" = 1; then
123 ax_cv_have_avx_ext=yes
127 if [ test "$ax_cv_have_mmx_ext" = yes && test "$ac_cv_header_mmintrin_h" = yes ]; then
128 AC_DEFINE(HAVE_MMX,, [Support MMX instructions])
129 AX_CHECK_COMPILE_FLAG(-mmmx, SIMD_FLAGS="$SIMD_FLAGS -mmmx", [])
132 if [ test "$ax_cv_have_sse_ext" = yes && test "$ac_cv_header_xmmintrin_h" = yes ]; then
133 AC_DEFINE(HAVE_SSE,, [Support SSE (Streaming SIMD Extensions) instructions])
134 AX_CHECK_COMPILE_FLAG(-msse, SIMD_FLAGS="$SIMD_FLAGS -msse", [])
137 if [ test "$ax_cv_have_sse2_ext" = yes && test "$ac_cv_header_emmintrin_h" = yes ]; then
138 AC_DEFINE(HAVE_SSE2,, [Support SSE2 (Streaming SIMD Extensions 2) instructions])
139 AX_CHECK_COMPILE_FLAG(-msse2, SIMD_FLAGS="$SIMD_FLAGS -msse2", [])
142 if [ test "$ax_cv_have_sse3_ext" = yes && test "$ac_cv_header_pmmintrin_h" = yes ]; then
143 AC_DEFINE(HAVE_SSE3,, [Support SSE3 (Streaming SIMD Extensions 3) instructions])
144 AX_CHECK_COMPILE_FLAG(-msse3, SIMD_FLAGS="$SIMD_FLAGS -msse3", [])
147 if [ test "$ax_cv_have_ssse3_ext" = yes && test "$ac_cv_header_tmmintrin_h" = yes ]; then
148 AC_DEFINE(HAVE_SSSE3,, [Support SSSE3 (Supplemental Streaming SIMD Extensions 3) instructions])
149 AX_CHECK_COMPILE_FLAG(-mssse3, SIMD_FLAGS="$SIMD_FLAGS -mssse3", [])
152 if [ test "$ax_cv_have_sse41_ext" = yes && test "$ac_cv_header_smmintrin_h" = yes ]; then
153 AC_DEFINE(HAVE_SSE41,, [Support SSE4.1 (Streaming SIMD Extensions 4.1) instructions])
154 AX_CHECK_COMPILE_FLAG(-msse4.1, SIMD_FLAGS="$SIMD_FLAGS -msse4.1", [])
157 if [ test "$ax_cv_have_sse42_ext" = yes && test "$ac_cv_header_smmintrin_h" = yes ]; then
158 AC_DEFINE(HAVE_SSE42, 1,[Support SSE4.2 (Streaming SIMD Extensions 4.2) instructions])
159 AX_CHECK_COMPILE_FLAG(-msse4.2, SIMD_FLAGS="$SIMD_FLAGS -msse4.2", [])
162 if [ test "$ax_cv_have_avx_ext" = yes && test "$ac_cv_header_immintrin_h" = yes ]; then
163 AC_DEFINE(HAVE_AVX,,[Support AVX (Advanced Vector Extensions) instructions])
164 AX_CHECK_COMPILE_FLAG(-mavx, SIMD_FLAGS="$SIMD_FLAGS -mavx", [])