summaryrefslogtreecommitdiff
path: root/m4/ax_ext.m4
blob: 898f2bfd5111712cd9be9a11f85c88077f8310ad (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
# ===========================================================================
#                 http://autoconf-archive.cryp.to/ax_ext.html
# ===========================================================================
#
# SYNOPSIS
#
#   AX_EXT
#
# DESCRIPTION
#
#   Find supported SIMD extensions by requesting cpuid. When an SIMD
#   extension is found, the -m"simdextensionname" is added to SIMD_FLAGS
#   (only if compilator support it) (ie : if "sse2" is available "-msse2" is
#   added to SIMD_FLAGS)
#
#   This macro calls:
#
#     AC_SUBST(SIMD_FLAGS)
#
#   And defines:
#
#     HAVE_MMX / HAVE_SSE / HAVE_SSE2 / HAVE_SSE3 / HAVE_SSSE3
#
# LAST MODIFICATION
#
#   2008-04-12
#   2009-04-23  Mark Asbach <markasbach@users.sourceforge.net<
#               Renamed cache variables so they adhere naming convention
#               Corrected M4 quoting for AX_CHECK_COMPILER_FLAGS
#
# COPYLEFT
#
#   Copyright (c) 2008 Christophe Tournayre <turn3r@users.sourceforge.net>
#
#   Copying and distribution of this file, with or without modification, are
#   permitted in any medium without royalty provided the copyright notice
#   and this notice are preserved.

AC_DEFUN([AX_EXT],
[
  AC_REQUIRE([AX_GCC_X86_CPUID])
  
  AX_GCC_X86_CPUID([0x00000001])
  if test "$ax_cv_gcc_x86_cpuid_0x00000001" != "unknown"; then
    ecx=`echo $ax_cv_gcc_x86_cpuid_0x00000001 | cut -d ":" -f 3`
    edx=`echo $ax_cv_gcc_x86_cpuid_0x00000001 | cut -d ":" -f 4`
  fi
  
  AC_CACHE_CHECK([whether mmx is supported], [ax_cv_have_mmx_ext],
  [
    ax_cv_have_mmx_ext=no
    if test "$ax_cv_gcc_x86_cpuid_0x00000001" != "unknown"; then
      if test "$((0x$edx>>23&0x01))" = 1; then
        ax_cv_have_mmx_ext=yes
      fi
    fi
  ])

  AC_CACHE_CHECK([whether sse is supported], [ax_cv_have_sse_ext],
  [
    ax_cv_have_sse_ext=no
    if test "$ax_cv_gcc_x86_cpuid_0x00000001" != "unknown"; then
      if test "$((0x$edx>>25&0x01))" = 1; then
        ax_cv_have_sse_ext=yes
      fi
    fi
  ])

  AC_CACHE_CHECK([whether sse2 is supported], [ax_cv_have_sse2_ext],
  [
    ax_cv_have_sse2_ext=no
    if test "$ax_cv_gcc_x86_cpuid_0x00000001" != "unknown"; then
      if test "$((0x$edx>>26&0x01))" = 1; then
        ax_cv_have_sse2_ext=yes
      fi
    fi
  ])

  AC_CACHE_CHECK([whether sse3 is supported], [ax_cv_have_sse3_ext],
  [
    ax_cv_have_sse3_ext=no
    if test "$ax_cv_gcc_x86_cpuid_0x00000001" != "unknown"; then
      if test "$((0x$ecx&0x01))" = 1; then
        ax_cv_have_sse3_ext=yes
      fi
    fi
  ])

  AC_CACHE_CHECK([whether ssse3 is supported], [ax_cv_have_ssse3_ext],
  [
    ax_cv_have_ssse3_ext=no
    if test "$ax_cv_gcc_x86_cpuid_0x00000001" != "unknown"; then
      if test "$((0x$ecx>>9&0x01))" = 1; then
        ax_cv_have_ssse3_ext=yes
      fi
    fi
  ])

  if test "$ax_cv_have_mmx_ext" = yes; then
    AC_DEFINE(HAVE_MMX,,[Support mmx instructions])
    AX_CHECK_COMPILER_FLAGS([-mmmx], [SIMD_FLAGS="$SIMD_FLAGS -mmmx"], [])
  fi

  if test "$ax_cv_have_sse_ext" = yes; then
    AC_DEFINE(HAVE_SSE,,[Support SSE (Streaming SIMD Extensions) instructions])
    AX_CHECK_COMPILER_FLAGS([-msse], [SIMD_FLAGS="$SIMD_FLAGS -msse"], [])
  fi

  if test "$ax_cv_have_sse2_ext" = yes; then
    AC_DEFINE(HAVE_SSE2,,[Support SSE2 (Streaming SIMD Extensions 2) instructions])
    AX_CHECK_COMPILER_FLAGS([-msse2], [SIMD_FLAGS="$SIMD_FLAGS -msse2"], [])
  fi

  if test "$ax_cv_have_sse3_ext" = yes; then
    AC_DEFINE(HAVE_SSE3,,[Support SSE3 (Streaming SIMD Extensions 3) instructions])
    AX_CHECK_COMPILER_FLAGS([-msse3], [SIMD_FLAGS="$SIMD_FLAGS -msse3"], [])
  fi

  if test "$ax_cv_have_ssse3_ext" = yes; then
    AC_DEFINE(HAVE_SSSE3,,[Support SSSE3 (Supplemental Streaming SIMD Extensions 3) instructions])
  fi

  AC_SUBST(SIMD_FLAGS)
])