Imported Upstream version 0.3.17
[platform/upstream/liboil.git] / m4 / as-intrinsics.m4
1 dnl as-intrinsics.m4 0.1.0
2
3 dnl autostars m4 macro for detection of gcc inline assembly
4
5 dnl David Schleef <ds@schleef.org>
6
7 dnl $Id: as-intrinsics.m4,v 1.5 2006-05-19 06:58:29 ds Exp $
8
9 dnl AS_MMX_INTRINSICS(CFLAGS, ACTION-IF-ACCEPTED, [ACTION-IF-NOT-ACCEPTED])
10 dnl Tries to compile with the given CFLAGS.
11 dnl Runs ACTION-IF-ACCEPTED if the compiler can compile with the flags,
12 dnl and ACTION-IF-NOT-ACCEPTED otherwise.
13
14 AC_DEFUN([AS_MMX_INTRINSICS],
15 [
16   AC_MSG_CHECKING([if compiler supports MMX intrinsics])
17
18   save_CFLAGS="$CFLAGS"
19   CFLAGS="$CFLAGS -mmmx"
20   AC_TRY_COMPILE([#include <mmintrin.h>], [_mm_empty()], [flag_ok=yes], [flag_ok=no])
21   CFLAGS="$save_CFLAGS"
22
23   $1="-mmmx"
24   if test "X$flag_ok" = Xyes ; then
25     $2
26     true
27   else
28     $3
29     true
30   fi
31   AC_MSG_RESULT([$flag_ok])
32 ])
33
34
35 dnl AS_SSE_INTRINSICS(CFLAGS, ACTION-IF-ACCEPTED, [ACTION-IF-NOT-ACCEPTED])
36 dnl Tries to compile with the given CFLAGS.
37 dnl Runs ACTION-IF-ACCEPTED if the compiler can compile with the flags,
38 dnl and ACTION-IF-NOT-ACCEPTED otherwise.
39
40 AC_DEFUN([AS_SSE_INTRINSICS],
41 [
42   AC_MSG_CHECKING([if compiler supports SSE intrinsics])
43
44   save_CFLAGS="$CFLAGS"
45   CFLAGS="$CFLAGS -msse"
46   AC_TRY_COMPILE([#include <xmmintrin.h>], [
47 #ifdef __GNUC_MINOR__
48 #if (__GNUC__ * 1000 + __GNUC_MINOR__) < 4002
49 #error GCC before 4.2 has critical bugs compiling SSE intrinsics
50 #endif
51 #endif
52 __m128 a; a = _mm_or_ps(a,a)], [flag_ok=yes], [flag_ok=no])
53   CFLAGS="$save_CFLAGS"
54
55   $1="-msse"
56   if test "X$flag_ok" = Xyes ; then
57     $2
58     true
59   else
60     $3
61     true
62   fi
63   AC_MSG_RESULT([$flag_ok])
64 ])
65
66
67 dnl AS_SSE2_INTRINSICS(CFLAGS, ACTION-IF-ACCEPTED, [ACTION-IF-NOT-ACCEPTED])
68 dnl Tries to compile with the given CFLAGS.
69 dnl Runs ACTION-IF-ACCEPTED if the compiler can compile with the flags,
70 dnl and ACTION-IF-NOT-ACCEPTED otherwise.
71
72 AC_DEFUN([AS_SSE2_INTRINSICS],
73 [
74   AC_MSG_CHECKING([if compiler supports SSE2 intrinsics])
75
76   save_CFLAGS="$CFLAGS"
77   CFLAGS="$CFLAGS -msse2"
78   AC_TRY_COMPILE([#include <emmintrin.h>], [
79 #ifdef __GNUC_MINOR__
80 #if (__GNUC__ * 1000 + __GNUC_MINOR__) < 4002
81 #error GCC before 4.2 has critical bugs compiling SSE2 intrinsics
82 #endif
83 #endif
84 __m128i a; a = _mm_setzero_si128(); a = _mm_srli_epi16(a,8)], [flag_ok=yes], [flag_ok=no])
85   CFLAGS="$save_CFLAGS"
86
87   $1="-msse2"
88   if test "X$flag_ok" = Xyes ; then
89     $2
90     true
91   else
92     $3
93     true
94   fi
95   AC_MSG_RESULT([$flag_ok])
96 ])
97
98
99 dnl AS_SSE3_INTRINSICS(CFLAGS, ACTION-IF-ACCEPTED, [ACTION-IF-NOT-ACCEPTED])
100 dnl Tries to compile with the given CFLAGS.
101 dnl Runs ACTION-IF-ACCEPTED if the compiler can compile with the flags,
102 dnl and ACTION-IF-NOT-ACCEPTED otherwise.
103
104 AC_DEFUN([AS_SSE3_INTRINSICS],
105 [
106   AC_MSG_CHECKING([if compiler supports SSE3 intrinsics])
107
108   save_CFLAGS="$CFLAGS"
109   CFLAGS="$CFLAGS -msse3"
110   AC_TRY_COMPILE([#include <pmmintrin.h>], [
111 #ifdef __GNUC_MINOR__
112 #if (__GNUC__ * 1000 + __GNUC_MINOR__) < 4002
113 #error GCC before 4.2 has critical bugs compiling SSE2 intrinsics
114 #endif
115 #endif
116 __m128 a; a = _mm_addsub_ps(a,a)], [flag_ok=yes], [flag_ok=no])
117   CFLAGS="$save_CFLAGS"
118
119   $1="-msse3"
120   if test "X$flag_ok" = Xyes ; then
121     $2
122     true
123   else
124     $3
125     true
126   fi
127   AC_MSG_RESULT([$flag_ok])
128 ])
129
130
131 dnl AS_3DNOW_INTRINSICS(CFLAGS, ACTION-IF-ACCEPTED, [ACTION-IF-NOT-ACCEPTED])
132 dnl Tries to compile with the given CFLAGS.
133 dnl Runs ACTION-IF-ACCEPTED if the compiler can compile with the flags,
134 dnl and ACTION-IF-NOT-ACCEPTED otherwise.
135
136 AC_DEFUN([AS_3DNOW_INTRINSICS],
137 [
138   AC_MSG_CHECKING([if compiler supports 3DNOW intrinsics])
139
140   save_CFLAGS="$CFLAGS"
141   CFLAGS="$CFLAGS -m3dnow"
142   AC_TRY_COMPILE([#include <mm3dnow.h>], [_m_femms()], [flag_ok=yes], [flag_ok=no])
143   CFLAGS="$save_CFLAGS"
144
145   $1="-m3dnow"
146   if test "X$flag_ok" = Xyes ; then
147     $2
148     true
149   else
150     $3
151     true
152   fi
153   AC_MSG_RESULT([$flag_ok])
154 ])
155
156
157 dnl AS_3DNOWEXT_INTRINSICS(CFLAGS, ACTION-IF-ACCEPTED, [ACTION-IF-NOT-ACCEPTED])
158 dnl Tries to compile with the given CFLAGS.
159 dnl Runs ACTION-IF-ACCEPTED if the compiler can compile with the flags,
160 dnl and ACTION-IF-NOT-ACCEPTED otherwise.
161
162 AC_DEFUN([AS_3DNOWEXT_INTRINSICS],
163 [
164   AC_MSG_CHECKING([if compiler supports 3DNOWEXT intrinsics])
165
166   save_CFLAGS="$CFLAGS"
167   CFLAGS="$CFLAGS -m3dnow -march=athlon"
168   AC_TRY_COMPILE([#include <mm3dnow.h>], [__m64 a;a=_m_pf2iw(a)], [flag_ok=yes], [flag_ok=no])
169   CFLAGS="$save_CFLAGS"
170
171   $1="-m3dnow -march=athlon"
172   if test "X$flag_ok" = Xyes ; then
173     $2
174     true
175   else
176     $3
177     true
178   fi
179   AC_MSG_RESULT([$flag_ok])
180 ])
181
182
183 dnl AS_ALTIVEC_INTRINSICS(CFLAGS, ACTION-IF-ACCEPTED, [ACTION-IF-NOT-ACCEPTED])
184 dnl Tries to compile with the given CFLAGS.
185 dnl Runs ACTION-IF-ACCEPTED if the compiler can compile with the flags,
186 dnl and ACTION-IF-NOT-ACCEPTED otherwise.
187
188 AC_DEFUN([AS_ALTIVEC_INTRINSICS],
189 [
190   AC_MSG_CHECKING([if compiler supports ALTIVEC intrinsics])
191
192   save_CFLAGS="$CFLAGS"
193   CFLAGS="$CFLAGS -maltivec"
194   AC_TRY_COMPILE([#include <altivec.h>], [__vector a; a = vec_or(a,a)], [flag_ok=yes], [flag_ok=no])
195   CFLAGS="$save_CFLAGS"
196
197   $1="-maltivec"
198   if test "X$flag_ok" = Xyes ; then
199     $2
200     true
201   else
202     $3
203     true
204   fi
205   AC_MSG_RESULT([$flag_ok])
206 ])
207