Update to wx3.0, add SSE optimizations based on target_cpu, fix compile warnings
[ctsim.git] / scripts / ax_ext.m4
1 # ===========================================================================
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
13 #   (only if compilator support it) (ie : if "sse2" is available "-msse2" is
14 #   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 /
23 #     HAVE_SSE41 / HAVE_SSE42 / HAVE_AVX
24 #
25 # LICENSE
26 #
27 #   Copyright (c) 2008 Christophe Tournayre <turn3r@users.sourceforge.net>
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 # MODIFIED
35 #   * March 23, 2012 Joseph D. Gaeddert <jgaedder@vt.edu>
36 #     Including tests for proper intrinsics header files in addition to cpu
37 #     capabilities.
38 #     MMX           :   mmintrin.h
39 #     SSE           :   xmmintrin.h
40 #     SSE2          :   emmintrin.h
41 #     SSE3          :   pmmintrin.h
42 #     SSSE3         :   tmmintrin.h
43 #     SSE4.1/4.2    :   smmintrin.h
44 #     AVX           :   immintrin.h
45
46 #serial 9
47
48 AC_DEFUN([AX_EXT],
49 [
50   AC_REQUIRE([AX_GCC_X86_CPUID])
51
52   AX_GCC_X86_CPUID(0x00000001)
53   ecx=0
54   edx=0
55   if test "$ax_cv_gcc_x86_cpuid_0x00000001" != "unknown";
56   then
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`
59   fi
60
61  AC_CHECK_HEADERS(mmintrin.h xmmintrin.h emmintrin.h pmmintrin.h tmmintrin.h smmintrin.h immintrin.h)
62
63  AC_CACHE_CHECK([whether mmx is supported], [ax_cv_have_mmx_ext],
64   [
65     ax_cv_have_mmx_ext=no
66     if test "$((0x$edx>>23&0x01))" = 1; then
67       ax_cv_have_mmx_ext=yes
68     fi
69   ])
70
71  AC_CACHE_CHECK([whether sse is supported], [ax_cv_have_sse_ext],
72   [
73     ax_cv_have_sse_ext=no
74     if test "$((0x$edx>>25&0x01))" = 1; then
75       ax_cv_have_sse_ext=yes
76     fi
77   ])
78
79  AC_CACHE_CHECK([whether sse2 is supported], [ax_cv_have_sse2_ext],
80   [
81     ax_cv_have_sse2_ext=no
82     if test "$((0x$edx>>26&0x01))" = 1; then
83       ax_cv_have_sse2_ext=yes
84     fi
85   ])
86
87  AC_CACHE_CHECK([whether sse3 is supported], [ax_cv_have_sse3_ext],
88   [
89     ax_cv_have_sse3_ext=no
90     if test "$((0x$ecx&0x01))" = 1; then
91       ax_cv_have_sse3_ext=yes
92     fi
93   ])
94
95  AC_CACHE_CHECK([whether ssse3 is supported], [ax_cv_have_ssse3_ext],
96   [
97     ax_cv_have_ssse3_ext=no
98     if test "$((0x$ecx>>9&0x01))" = 1; then
99       ax_cv_have_ssse3_ext=yes
100     fi
101   ])
102
103  AC_CACHE_CHECK([whether sse4.1 is supported], [ax_cv_have_sse41_ext],
104   [
105     ax_cv_have_sse41_ext=no
106     if test "$((0x$ecx>>19&0x01))" = 1; then
107       ax_cv_have_sse41_ext=yes
108     fi
109   ])
110
111  AC_CACHE_CHECK([whether sse4.2 is supported], [ax_cv_have_sse42_ext],
112   [
113     ax_cv_have_sse42_ext=no
114     if test "$((0x$ecx>>20&0x01))" = 1; then
115       ax_cv_have_sse42_ext=yes
116     fi
117   ])
118
119  AC_CACHE_CHECK([whether avx is supported], [ax_cv_have_avx_ext],
120   [
121     ax_cv_have_avx_ext=no
122     if test "$((0x$ecx>>28&0x01))" = 1; then
123       ax_cv_have_avx_ext=yes
124     fi
125   ])
126
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", [])
130   fi
131
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", [])
135   fi
136
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", [])
140   fi
141
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", [])
145   fi
146
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", [])
150   fi
151
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", [])
155   fi
156
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", [])
160   fi
161
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", [])
165   fi
166
167   AC_SUBST(SIMD_FLAGS)
168 ])