Update to 2.0.0 tree from current Fremantle build
[opencv] / autotools / aclocal / ax_ext.m4
1 # ===========================================================================
2 #                 http://autoconf-archive.cryp.to/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 #
24 # LAST MODIFICATION
25 #
26 #   2008-04-12
27 #   2009-04-23  Mark Asbach <markasbach@users.sourceforge.net<
28 #               Renamed cache variables so they adhere naming convention
29 #               Corrected M4 quoting for AX_CHECK_COMPILER_FLAGS
30 #
31 # COPYLEFT
32 #
33 #   Copyright (c) 2008 Christophe Tournayre <turn3r@users.sourceforge.net>
34 #
35 #   Copying and distribution of this file, with or without modification, are
36 #   permitted in any medium without royalty provided the copyright notice
37 #   and this notice are preserved.
38
39 AC_DEFUN([AX_EXT],
40 [
41   AC_REQUIRE([AX_GCC_X86_CPUID])
42   
43   AX_GCC_X86_CPUID([0x00000001])
44   if test "$ax_cv_gcc_x86_cpuid_0x00000001" != "unknown"; then
45     ecx=`echo $ax_cv_gcc_x86_cpuid_0x00000001 | cut -d ":" -f 3`
46     edx=`echo $ax_cv_gcc_x86_cpuid_0x00000001 | cut -d ":" -f 4`
47   fi
48   
49   AC_CACHE_CHECK([whether mmx is supported], [ax_cv_have_mmx_ext],
50   [
51     ax_cv_have_mmx_ext=no
52     if test "$ax_cv_gcc_x86_cpuid_0x00000001" != "unknown"; then
53       if test "$((0x$edx>>23&0x01))" = 1; then
54         ax_cv_have_mmx_ext=yes
55       fi
56     fi
57   ])
58
59   AC_CACHE_CHECK([whether sse is supported], [ax_cv_have_sse_ext],
60   [
61     ax_cv_have_sse_ext=no
62     if test "$ax_cv_gcc_x86_cpuid_0x00000001" != "unknown"; then
63       if test "$((0x$edx>>25&0x01))" = 1; then
64         ax_cv_have_sse_ext=yes
65       fi
66     fi
67   ])
68
69   AC_CACHE_CHECK([whether sse2 is supported], [ax_cv_have_sse2_ext],
70   [
71     ax_cv_have_sse2_ext=no
72     if test "$((0x$edx>>26&0x01))" = 1; then
73       ax_cv_have_sse2_ext=yes
74     fi
75   ])
76
77   AC_CACHE_CHECK([whether sse3 is supported], [ax_cv_have_sse3_ext],
78   [
79     ax_cv_have_sse3_ext=no
80     if test "$ax_cv_gcc_x86_cpuid_0x00000001" != "unknown"; then
81       if test "$((0x$ecx&0x01))" = 1; then
82         ax_cv_have_sse3_ext=yes
83       fi
84     fi
85   ])
86
87   AC_CACHE_CHECK([whether ssse3 is supported], [ax_cv_have_ssse3_ext],
88   [
89     ax_cv_have_ssse3_ext=no
90     if test "$ax_cv_gcc_x86_cpuid_0x00000001" != "unknown"; then
91       if test "$((0x$ecx>>9&0x01))" = 1; then
92         ax_cv_have_ssse3_ext=yes
93       fi
94     fi
95   ])
96
97   if test "$ax_cv_have_mmx_ext" = yes; then
98     AC_DEFINE(HAVE_MMX,,[Support mmx instructions])
99     AX_CHECK_COMPILER_FLAGS([-mmmx], [SIMD_FLAGS="$SIMD_FLAGS -mmmx"], [])
100   fi
101
102   if test "$ax_cv_have_sse_ext" = yes; then
103     AC_DEFINE(HAVE_SSE,,[Support SSE (Streaming SIMD Extensions) instructions])
104     AX_CHECK_COMPILER_FLAGS([-msse], [SIMD_FLAGS="$SIMD_FLAGS -msse"], [])
105   fi
106
107   if test "$ax_cv_have_sse2_ext" = yes; then
108     AC_DEFINE(HAVE_SSE2,,[Support SSE2 (Streaming SIMD Extensions 2) instructions])
109     AX_CHECK_COMPILER_FLAGS([-msse2], [SIMD_FLAGS="$SIMD_FLAGS -msse2"], [])
110   fi
111
112   if test "$ax_cv_have_sse3_ext" = yes; then
113     AC_DEFINE(HAVE_SSE3,,[Support SSE3 (Streaming SIMD Extensions 3) instructions])
114     AX_CHECK_COMPILER_FLAGS([-msse3], [SIMD_FLAGS="$SIMD_FLAGS -msse3"], [])
115   fi
116
117   if test "$ax_cv_have_ssse3_ext" = yes; then
118     AC_DEFINE(HAVE_SSSE3,,[Support SSSE3 (Supplemental Streaming SIMD Extensions 3) instructions])
119   fi
120
121   AC_SUBST(SIMD_FLAGS)
122 ])