]>
Commit | Line | Data |
---|---|---|
891c05b1 JJ |
1 | m4_include(../config/acx.m4) |
2 | m4_include(../config/no-executables.m4) | |
db9f46a9 | 3 | m4_include(../config/math.m4) |
7b32a8f6 | 4 | m4_include(../config/ax_check_define.m4) |
26724ef9 IT |
5 | m4_include(../config/enable.m4) |
6 | m4_include(../config/cet.m4) | |
891c05b1 | 7 | |
15e92535 FXC |
8 | dnl Check that we have a working GNU Fortran compiler |
9 | AC_DEFUN([LIBGFOR_WORKING_GFORTRAN], [ | |
10 | AC_MSG_CHECKING([whether the GNU Fortran compiler is working]) | |
11 | AC_LANG_PUSH([Fortran]) | |
12 | AC_COMPILE_IFELSE([[ | |
13 | program foo | |
14 | real, parameter :: bar = sin (12.34 / 2.5) | |
15 | end program foo]], | |
16 | [AC_MSG_RESULT([yes])], | |
17 | [AC_MSG_RESULT([no]) | |
18 | AC_MSG_ERROR([GNU Fortran is not working; please report a bug in http://gcc.gnu.org/bugzilla, attaching $PWD/config.log]) | |
19 | ]) | |
20 | AC_LANG_POP([Fortran]) | |
21 | ]) | |
22 | ||
23 | ||
6de9cd9a DN |
24 | sinclude(../libtool.m4) |
25 | dnl The lines below arrange for aclocal not to bring an installed | |
26 | dnl libtool.m4 into aclocal.m4, while still arranging for automake to | |
27 | dnl add a definition of LIBTOOL to Makefile.in. | |
28 | ifelse(,,,[AC_SUBST(LIBTOOL) | |
29 | AC_DEFUN([AM_PROG_LIBTOOL]) | |
30 | AC_DEFUN([AC_LIBTOOL_DLOPEN]) | |
31 | AC_DEFUN([AC_PROG_LD]) | |
32 | ]) | |
33 | ||
7d7b8bfe RH |
34 | dnl Check whether the target supports hidden visibility. |
35 | AC_DEFUN([LIBGFOR_CHECK_ATTRIBUTE_VISIBILITY], [ | |
36 | AC_CACHE_CHECK([whether the target supports hidden visibility], | |
6d26724a | 37 | libgfor_cv_have_attribute_visibility, [ |
7d7b8bfe RH |
38 | save_CFLAGS="$CFLAGS" |
39 | CFLAGS="$CFLAGS -Werror" | |
de15ea94 FXC |
40 | AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[void __attribute__((visibility("hidden"))) foo(void) { }]], [])], |
41 | libgfor_cv_have_attribute_visibility=yes, | |
42 | libgfor_cv_have_attribute_visibility=no) | |
7d7b8bfe | 43 | CFLAGS="$save_CFLAGS"]) |
6d26724a | 44 | if test $libgfor_cv_have_attribute_visibility = yes; then |
7d7b8bfe RH |
45 | AC_DEFINE(HAVE_ATTRIBUTE_VISIBILITY, 1, |
46 | [Define to 1 if the target supports __attribute__((visibility(...))).]) | |
47 | fi]) | |
48 | ||
7d7b8bfe RH |
49 | dnl Check whether the target supports symbol aliases. |
50 | AC_DEFUN([LIBGFOR_CHECK_ATTRIBUTE_ALIAS], [ | |
51 | AC_CACHE_CHECK([whether the target supports symbol aliases], | |
6d26724a | 52 | libgfor_cv_have_attribute_alias, [ |
de15ea94 | 53 | AC_LINK_IFELSE([AC_LANG_PROGRAM([[ |
7d7b8bfe | 54 | void foo(void) { } |
de15ea94 FXC |
55 | extern void bar(void) __attribute__((alias("foo")));]], |
56 | [[bar();]])], libgfor_cv_have_attribute_alias=yes, libgfor_cv_have_attribute_alias=no)]) | |
6d26724a | 57 | if test $libgfor_cv_have_attribute_alias = yes; then |
7d7b8bfe RH |
58 | AC_DEFINE(HAVE_ATTRIBUTE_ALIAS, 1, |
59 | [Define to 1 if the target supports __attribute__((alias(...))).]) | |
60 | fi]) | |
10c682a0 | 61 | |
0536d5b3 JB |
62 | dnl Check whether the target supports __atomic_fetch_add. |
63 | AC_DEFUN([LIBGFOR_CHECK_ATOMIC_FETCH_ADD], [ | |
64 | AC_CACHE_CHECK([whether the target supports __atomic_fetch_add], | |
65 | libgfor_cv_have_atomic_fetch_add, [ | |
de15ea94 | 66 | AC_LINK_IFELSE([AC_LANG_PROGRAM([[int foovar = 0;]], [[ |
0536d5b3 JB |
67 | if (foovar <= 0) return __atomic_fetch_add (&foovar, 1, __ATOMIC_ACQ_REL); |
68 | if (foovar > 10) return __atomic_add_fetch (&foovar, -1, __ATOMIC_ACQ_REL);]])], | |
69 | libgfor_cv_have_atomic_fetch_add=yes, libgfor_cv_have_atomic_fetch_add=no)]) | |
70 | if test $libgfor_cv_have_atomic_fetch_add = yes; then | |
71 | AC_DEFINE(HAVE_ATOMIC_FETCH_ADD, 1, | |
72 | [Define to 1 if the target supports __atomic_fetch_add]) | |
5e805e44 JJ |
73 | fi]) |
74 | ||
6a822a74 FXC |
75 | dnl Check for pragma weak. |
76 | AC_DEFUN([LIBGFOR_GTHREAD_WEAK], [ | |
77 | AC_CACHE_CHECK([whether pragma weak works], | |
78 | libgfor_cv_have_pragma_weak, [ | |
79 | gfor_save_CFLAGS="$CFLAGS" | |
80 | CFLAGS="$CFLAGS -Wunknown-pragmas" | |
81 | AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[ | |
82 | void foo (void); | |
83 | #pragma weak foo | |
84 | ]], [[if (foo) foo ();]])], | |
85 | libgfor_cv_have_pragma_weak=yes, libgfor_cv_have_pragma_weak=no)]) | |
86 | if test $libgfor_cv_have_pragma_weak = yes; then | |
87 | AC_DEFINE(SUPPORTS_WEAK, 1, | |
88 | [Define to 1 if the target supports #pragma weak]) | |
89 | fi | |
90 | case "$host" in | |
91 | *-*-darwin* | *-*-hpux* | *-*-cygwin* | *-*-mingw* | *-*-musl* ) | |
92 | AC_DEFINE(GTHREAD_USE_WEAK, 0, | |
93 | [Define to 0 if the target shouldn't use #pragma weak]) | |
94 | ;; | |
95 | esac]) | |
96 | ||
e7854993 FXC |
97 | dnl Check whether target effectively supports weakref |
98 | AC_DEFUN([LIBGFOR_CHECK_WEAKREF], [ | |
99 | AC_CACHE_CHECK([whether the target supports weakref], | |
100 | libgfor_cv_have_weakref, [ | |
101 | save_CFLAGS="$CFLAGS" | |
102 | CFLAGS="$CFLAGS -Wunknown-pragmas -Werror" | |
103 | AC_LINK_IFELSE([AC_LANG_PROGRAM([[ | |
104 | static int mytoto (int) __attribute__((__weakref__("toto"))); | |
105 | ]], [[return (mytoto != 0);]])], | |
106 | libgfor_cv_have_weakref=yes, libgfor_cv_have_weakref=no) | |
107 | CFLAGS="$save_CFLAGS"]) | |
108 | if test $libgfor_cv_have_weakref = yes; then | |
109 | AC_DEFINE(SUPPORTS_WEAKREF, 1, | |
110 | [Define to 1 if the target supports weakref]) | |
111 | fi]) | |
5e805e44 | 112 | |
10c682a0 FXC |
113 | dnl Check whether target can unlink a file still open. |
114 | AC_DEFUN([LIBGFOR_CHECK_UNLINK_OPEN_FILE], [ | |
115 | AC_CACHE_CHECK([whether the target can unlink an open file], | |
6d26724a | 116 | libgfor_cv_have_unlink_open_file, [ |
de15ea94 | 117 | AC_RUN_IFELSE([AC_LANG_SOURCE([[ |
10c682a0 FXC |
118 | #include <errno.h> |
119 | #include <fcntl.h> | |
120 | #include <unistd.h> | |
121 | #include <sys/stat.h> | |
122 | ||
123 | int main () | |
124 | { | |
125 | int fd; | |
126 | ||
42dfafa9 | 127 | fd = open ("testfile", O_RDWR | O_CREAT, S_IWUSR | S_IRUSR); |
10c682a0 FXC |
128 | if (fd <= 0) |
129 | return 0; | |
130 | if (unlink ("testfile") == -1) | |
131 | return 1; | |
132 | write (fd, "This is a test\n", 15); | |
133 | close (fd); | |
134 | ||
42dfafa9 | 135 | if (open ("testfile", O_RDONLY) == -1 && errno == ENOENT) |
10c682a0 FXC |
136 | return 0; |
137 | else | |
138 | return 1; | |
de15ea94 | 139 | }]])], libgfor_cv_have_unlink_open_file=yes, libgfor_cv_have_unlink_open_file=no, [ |
10c682a0 | 140 | case "${target}" in |
6d26724a RW |
141 | *mingw*) libgfor_cv_have_unlink_open_file=no ;; |
142 | *) libgfor_cv_have_unlink_open_file=yes;; | |
10c682a0 | 143 | esac])]) |
6d26724a | 144 | if test x"$libgfor_cv_have_unlink_open_file" = xyes; then |
10c682a0 FXC |
145 | AC_DEFINE(HAVE_UNLINK_OPEN_FILE, 1, [Define if target can unlink open files.]) |
146 | fi]) | |
3c127520 FXC |
147 | |
148 | dnl Check whether CRLF is the line terminator | |
149 | AC_DEFUN([LIBGFOR_CHECK_CRLF], [ | |
150 | AC_CACHE_CHECK([whether the target has CRLF as line terminator], | |
6d26724a | 151 | libgfor_cv_have_crlf, [ |
de15ea94 | 152 | AC_RUN_IFELSE([AC_LANG_SOURCE([[ |
3c127520 FXC |
153 | /* This test program should exit with status 0 if system uses a CRLF as |
154 | line terminator, and status 1 otherwise. | |
155 | Since it is used to check for mingw systems, and should return 0 in any | |
156 | other case, in case of a failure we will not use CRLF. */ | |
157 | #include <sys/stat.h> | |
158 | #include <stdlib.h> | |
159 | #include <fcntl.h> | |
160 | #include <stdio.h> | |
161 | ||
162 | int main () | |
163 | { | |
164 | #ifndef O_BINARY | |
165 | exit(1); | |
166 | #else | |
167 | int fd, bytes; | |
168 | char buff[5]; | |
169 | ||
170 | fd = open ("foo", O_WRONLY | O_CREAT | O_TRUNC, S_IRWXU); | |
171 | if (fd < 0) | |
172 | exit(1); | |
173 | if (write (fd, "\n", 1) < 0) | |
174 | perror ("write"); | |
175 | ||
176 | close (fd); | |
177 | ||
178 | if ((fd = open ("foo", O_RDONLY | O_BINARY, S_IRWXU)) < 0) | |
179 | exit(1); | |
180 | bytes = read (fd, buff, 5); | |
181 | if (bytes == 2 && buff[0] == '\r' && buff[1] == '\n') | |
182 | exit(0); | |
183 | else | |
184 | exit(1); | |
185 | #endif | |
de15ea94 | 186 | }]])], libgfor_cv_have_crlf=yes, libgfor_cv_have_crlf=no, [ |
3c127520 | 187 | case "${target}" in |
6d26724a RW |
188 | *mingw*) libgfor_cv_have_crlf=yes ;; |
189 | *) libgfor_cv_have_crlf=no;; | |
3c127520 | 190 | esac])]) |
6d26724a | 191 | if test x"$libgfor_cv_have_crlf" = xyes; then |
3c127520 FXC |
192 | AC_DEFINE(HAVE_CRLF, 1, [Define if CRLF is line terminator.]) |
193 | fi]) | |
118ea208 | 194 | |
ad238e4f FXC |
195 | dnl Check whether the st_ino and st_dev stat fields taken together uniquely |
196 | dnl identify the file within the system. This is should be true for POSIX | |
197 | dnl systems; it is known to be false on mingw32. | |
198 | AC_DEFUN([LIBGFOR_CHECK_WORKING_STAT], [ | |
199 | AC_CACHE_CHECK([whether the target stat is reliable], | |
6d26724a | 200 | libgfor_cv_have_working_stat, [ |
de15ea94 | 201 | AC_RUN_IFELSE([AC_LANG_SOURCE([[ |
ad238e4f FXC |
202 | #include <stdio.h> |
203 | #include <sys/types.h> | |
204 | #include <sys/stat.h> | |
205 | #include <unistd.h> | |
206 | ||
207 | int main () | |
208 | { | |
209 | FILE *f, *g; | |
210 | struct stat st1, st2; | |
211 | ||
212 | f = fopen ("foo", "w"); | |
213 | g = fopen ("bar", "w"); | |
214 | if (stat ("foo", &st1) != 0 || stat ("bar", &st2)) | |
215 | return 1; | |
216 | if (st1.st_dev == st2.st_dev && st1.st_ino == st2.st_ino) | |
217 | return 1; | |
218 | fclose(f); | |
219 | fclose(g); | |
220 | return 0; | |
de15ea94 | 221 | }]])], libgfor_cv_have_working_stat=yes, libgfor_cv_have_working_stat=no, [ |
ad238e4f | 222 | case "${target}" in |
6d26724a RW |
223 | *mingw*) libgfor_cv_have_working_stat=no ;; |
224 | *) libgfor_cv_have_working_stat=yes;; | |
ad238e4f | 225 | esac])]) |
6d26724a | 226 | if test x"$libgfor_cv_have_working_stat" = xyes; then |
ad238e4f FXC |
227 | AC_DEFINE(HAVE_WORKING_STAT, 1, [Define if target has a reliable stat.]) |
228 | fi]) | |
3b14f664 FXC |
229 | |
230 | dnl Checks for fpsetmask function. | |
231 | AC_DEFUN([LIBGFOR_CHECK_FPSETMASK], [ | |
6d26724a | 232 | AC_CACHE_CHECK([whether fpsetmask is present], libgfor_cv_have_fpsetmask, [ |
de15ea94 | 233 | AC_LINK_IFELSE([AC_LANG_PROGRAM([[ |
3b14f664 FXC |
234 | #if HAVE_FLOATINGPOINT_H |
235 | # include <floatingpoint.h> | |
236 | #endif /* HAVE_FLOATINGPOINT_H */ | |
237 | #if HAVE_IEEEFP_H | |
238 | # include <ieeefp.h> | |
de15ea94 | 239 | #endif /* HAVE_IEEEFP_H */]],[[fpsetmask(0);]])], |
6d26724a | 240 | eval "libgfor_cv_have_fpsetmask=yes", eval "libgfor_cv_have_fpsetmask=no") |
3b14f664 | 241 | ]) |
6d26724a | 242 | if test x"$libgfor_cv_have_fpsetmask" = xyes; then |
1b9fef3e | 243 | have_fpsetmask=yes |
3b14f664 FXC |
244 | AC_DEFINE(HAVE_FPSETMASK, 1, [Define if you have fpsetmask.]) |
245 | fi | |
246 | ]) | |
db8092dc FXC |
247 | |
248 | dnl Check whether we have a mingw that provides a __mingw_snprintf function | |
249 | AC_DEFUN([LIBGFOR_CHECK_MINGW_SNPRINTF], [ | |
6d26724a | 250 | AC_CACHE_CHECK([whether __mingw_snprintf is present], libgfor_cv_have_mingw_snprintf, [ |
de15ea94 | 251 | AC_LINK_IFELSE([AC_LANG_PROGRAM([[ |
db8092dc FXC |
252 | #include <stdio.h> |
253 | extern int __mingw_snprintf (char *, size_t, const char *, ...); | |
de15ea94 | 254 | ]],[[ |
db8092dc | 255 | __mingw_snprintf (NULL, 0, "%d\n", 1); |
de15ea94 | 256 | ]])], |
6d26724a | 257 | eval "libgfor_cv_have_mingw_snprintf=yes", eval "libgfor_cv_have_mingw_snprintf=no") |
db8092dc | 258 | ]) |
6d26724a | 259 | if test x"$libgfor_cv_have_mingw_snprintf" = xyes; then |
db8092dc FXC |
260 | AC_DEFINE(HAVE_MINGW_SNPRINTF, 1, [Define if you have __mingw_snprintf.]) |
261 | fi | |
262 | ]) | |
c0c3c409 | 263 | |
1ec601bf FXC |
264 | dnl Check whether we have a __float128 type |
265 | AC_DEFUN([LIBGFOR_CHECK_FLOAT128], [ | |
266 | LIBQUADSPEC= | |
87e6d9dc TB |
267 | |
268 | if test "x$enable_libquadmath_support" != xno; then | |
269 | ||
1ec601bf FXC |
270 | AC_CACHE_CHECK([whether we have a usable __float128 type], |
271 | libgfor_cv_have_float128, [ | |
69eb61d4 TB |
272 | GCC_TRY_COMPILE_OR_LINK([ |
273 | typedef _Complex float __attribute__((mode(TC))) __complex128; | |
1ec601bf | 274 | |
69eb61d4 TB |
275 | __float128 foo (__float128 x) |
276 | { | |
1ec601bf | 277 | |
69eb61d4 | 278 | __complex128 z1, z2; |
1ec601bf | 279 | |
69eb61d4 TB |
280 | z1 = x; |
281 | z2 = x / 7.Q; | |
282 | z2 /= z1; | |
283 | ||
284 | return (__float128) z2; | |
285 | } | |
286 | ||
287 | __float128 bar (__float128 x) | |
288 | { | |
289 | return x * __builtin_huge_valq (); | |
290 | } | |
291 | ],[ | |
292 | foo (1.2Q); | |
293 | bar (1.2Q); | |
294 | ],[ | |
295 | libgfor_cv_have_float128=yes | |
296 | ],[ | |
297 | libgfor_cv_have_float128=no | |
298 | ])]) | |
1ec601bf FXC |
299 | |
300 | if test "x$libgfor_cv_have_float128" = xyes; then | |
301 | AC_DEFINE(HAVE_FLOAT128, 1, [Define if have a usable __float128 type.]) | |
302 | ||
828012a5 | 303 | dnl Check whether -Wl,--as-needed resp. -Wl,-zignore is supported |
1ec601bf FXC |
304 | dnl |
305 | dnl Turn warnings into error to avoid testsuite breakage. So enable | |
306 | dnl AC_LANG_WERROR, but there's currently (autoconf 2.64) no way to turn | |
307 | dnl it off again. As a workaround, save and restore werror flag like | |
308 | dnl AC_PATH_XTRA. | |
309 | dnl Cf. http://gcc.gnu.org/ml/gcc-patches/2010-05/msg01889.html | |
310 | ac_xsave_[]_AC_LANG_ABBREV[]_werror_flag=$ac_[]_AC_LANG_ABBREV[]_werror_flag | |
828012a5 | 311 | AC_CACHE_CHECK([whether --as-needed/-z ignore works], |
1ec601bf FXC |
312 | [libgfor_cv_have_as_needed], |
313 | [ | |
828012a5 RO |
314 | # Test for native Solaris options first. |
315 | # No whitespace after -z to pass it through -Wl. | |
316 | libgfor_cv_as_needed_option="-zignore" | |
317 | libgfor_cv_no_as_needed_option="-zrecord" | |
1ec601bf | 318 | save_LDFLAGS="$LDFLAGS" |
828012a5 | 319 | LDFLAGS="$LDFLAGS -Wl,$libgfor_cv_as_needed_option -lm -Wl,$libgfor_cv_no_as_needed_option" |
1ec601bf FXC |
320 | libgfor_cv_have_as_needed=no |
321 | AC_LANG_WERROR | |
322 | AC_LINK_IFELSE([AC_LANG_PROGRAM([])], | |
323 | [libgfor_cv_have_as_needed=yes], | |
324 | [libgfor_cv_have_as_needed=no]) | |
325 | LDFLAGS="$save_LDFLAGS" | |
828012a5 RO |
326 | if test "x$libgfor_cv_have_as_needed" = xno; then |
327 | libgfor_cv_as_needed_option="--as-needed" | |
328 | libgfor_cv_no_as_needed_option="--no-as-needed" | |
329 | save_LDFLAGS="$LDFLAGS" | |
330 | LDFLAGS="$LDFLAGS -Wl,$libgfor_cv_as_needed_option -lm -Wl,$libgfor_cv_no_as_needed_option" | |
331 | libgfor_cv_have_as_needed=no | |
332 | AC_LANG_WERROR | |
333 | AC_LINK_IFELSE([AC_LANG_PROGRAM([])], | |
334 | [libgfor_cv_have_as_needed=yes], | |
335 | [libgfor_cv_have_as_needed=no]) | |
336 | LDFLAGS="$save_LDFLAGS" | |
337 | fi | |
1ec601bf FXC |
338 | ac_[]_AC_LANG_ABBREV[]_werror_flag=$ac_xsave_[]_AC_LANG_ABBREV[]_werror_flag |
339 | ]) | |
340 | ||
341 | dnl For static libgfortran linkage, depend on libquadmath only if needed. | |
342 | if test "x$libgfor_cv_have_as_needed" = xyes; then | |
828012a5 | 343 | LIBQUADSPEC="%{static-libgfortran:$libgfor_cv_as_needed_option} -lquadmath %{static-libgfortran:$libgfor_cv_no_as_needed_option}" |
1ec601bf FXC |
344 | else |
345 | LIBQUADSPEC="-lquadmath" | |
346 | fi | |
347 | if test -f ../libquadmath/libquadmath.la; then | |
348 | LIBQUADLIB=../libquadmath/libquadmath.la | |
349 | LIBQUADLIB_DEP=../libquadmath/libquadmath.la | |
350 | LIBQUADINCLUDE='-I$(srcdir)/../libquadmath' | |
351 | else | |
352 | LIBQUADLIB="-lquadmath" | |
353 | LIBQUADLIB_DEP= | |
354 | LIBQUADINCLUDE= | |
355 | fi | |
356 | fi | |
87e6d9dc TB |
357 | else |
358 | # for --disable-quadmath | |
359 | LIBQUADLIB= | |
360 | LIBQUADLIB_DEP= | |
361 | LIBQUADINCLUDE= | |
362 | fi | |
1ec601bf FXC |
363 | |
364 | dnl For the spec file | |
365 | AC_SUBST(LIBQUADSPEC) | |
366 | AC_SUBST(LIBQUADLIB) | |
367 | AC_SUBST(LIBQUADLIB_DEP) | |
368 | AC_SUBST(LIBQUADINCLUDE) | |
369 | ||
370 | dnl We need a conditional for the Makefile | |
371 | AM_CONDITIONAL(LIBGFOR_BUILD_QUAD, [test "x$libgfor_cv_have_float128" = xyes]) | |
372 | ]) | |
4179e59a TB |
373 | |
374 | ||
375 | dnl Check whether we have strerror_r | |
376 | AC_DEFUN([LIBGFOR_CHECK_STRERROR_R], [ | |
377 | dnl Check for three-argument POSIX version of strerror_r | |
378 | ac_save_CFLAGS="$CFLAGS" | |
379 | CFLAGS="-Wimplicit-function-declaration -Werror" | |
380 | AC_TRY_COMPILE([#define _GNU_SOURCE 1 | |
381 | #include <string.h> | |
382 | #include <locale.h>], | |
383 | [char s[128]; strerror_r(5, s, 128);], | |
384 | AC_DEFINE(HAVE_STRERROR_R, 1, | |
385 | [Define if strerror_r is available in <string.h>.]),) | |
386 | CFLAGS="$ac_save_CFLAGS" | |
387 | ||
388 | dnl Check for two-argument version of strerror_r (e.g. for VxWorks) | |
389 | ac_save_CFLAGS="$CFLAGS" | |
390 | CFLAGS="-Wimplicit-function-declaration -Werror" | |
391 | AC_TRY_COMPILE([#define _GNU_SOURCE 1 | |
392 | #include <string.h> | |
393 | #include <locale.h>], | |
394 | [char s[128]; strerror_r(5, s);], | |
395 | AC_DEFINE(HAVE_STRERROR_R_2ARGS, 1, | |
396 | [Define if strerror_r takes two arguments and is available in <string.h>.]),) | |
397 | CFLAGS="$ac_save_CFLAGS" | |
398 | ]) | |
31cfd832 TK |
399 | |
400 | dnl Check for AVX | |
401 | ||
402 | AC_DEFUN([LIBGFOR_CHECK_AVX], [ | |
403 | ac_save_CFLAGS="$CFLAGS" | |
404 | CFLAGS="-O2 -mavx" | |
405 | AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[ | |
406 | void _mm256_zeroall (void) | |
407 | { | |
408 | __builtin_ia32_vzeroall (); | |
409 | }]], [[]])], | |
410 | AC_DEFINE(HAVE_AVX, 1, | |
411 | [Define if AVX instructions can be compiled.]), | |
412 | []) | |
413 | CFLAGS="$ac_save_CFLAGS" | |
414 | ]) | |
415 | ||
416 | dnl Check for AVX2 | |
417 | ||
418 | AC_DEFUN([LIBGFOR_CHECK_AVX2], [ | |
419 | ac_save_CFLAGS="$CFLAGS" | |
420 | CFLAGS="-O2 -mavx2" | |
421 | AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[ | |
422 | typedef long long __v4di __attribute__ ((__vector_size__ (32))); | |
423 | __v4di | |
424 | mm256_is32_andnotsi256 (__v4di __X, __v4di __Y) | |
425 | { | |
426 | return __builtin_ia32_andnotsi256 (__X, __Y); | |
427 | }]], [[]])], | |
428 | AC_DEFINE(HAVE_AVX2, 1, | |
429 | [Define if AVX2 instructions can be compiled.]), | |
430 | []) | |
431 | CFLAGS="$ac_save_CFLAGS" | |
432 | ]) | |
433 | ||
434 | dnl Check for AVX512f | |
435 | ||
436 | AC_DEFUN([LIBGFOR_CHECK_AVX512F], [ | |
437 | ac_save_CFLAGS="$CFLAGS" | |
438 | CFLAGS="-O2 -mavx512f" | |
439 | AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[ | |
440 | typedef double __m512d __attribute__ ((__vector_size__ (64))); | |
441 | __m512d _mm512_add (__m512d a) | |
442 | { | |
9db0a8c2 JJ |
443 | __m512d b = __builtin_ia32_addpd512_mask (a, a, a, 1, 4); |
444 | /* For -m64/-mx32 also verify that code will work even if | |
445 | the target uses call saved zmm16+ and needs to emit | |
446 | unwind info for them (e.g. on mingw). See PR79127. */ | |
447 | #ifdef __x86_64__ | |
448 | asm volatile ("" : : : "zmm16", "zmm17", "zmm18", "zmm19"); | |
449 | #endif | |
450 | return b; | |
31cfd832 TK |
451 | }]], [[]])], |
452 | AC_DEFINE(HAVE_AVX512F, 1, | |
453 | [Define if AVX512f instructions can be compiled.]), | |
454 | []) | |
455 | CFLAGS="$ac_save_CFLAGS" | |
456 | ]) | |
1d5cf7fc TK |
457 | |
458 | dnl Check for FMA3 | |
459 | dnl | |
460 | AC_DEFUN([LIBGFOR_CHECK_FMA3], [ | |
461 | ac_save_CFLAGS="$CFLAGS" | |
462 | CFLAGS="-O2 -mfma -mno-fma4" | |
463 | AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[ | |
9698e1bb RO |
464 | typedef float __m128 __attribute__ ((__vector_size__ (16))); |
465 | typedef float __v4sf __attribute__ ((__vector_size__ (16))); | |
466 | __m128 _mm_macc_ps(__m128 __A, __m128 __B, __m128 __C) | |
1d5cf7fc | 467 | { |
9698e1bb RO |
468 | return (__m128) __builtin_ia32_vfmaddps ((__v4sf)__A, |
469 | (__v4sf)__B, | |
470 | (__v4sf)__C); | |
1d5cf7fc TK |
471 | }]], [[]])], |
472 | AC_DEFINE(HAVE_FMA3, 1, | |
473 | [Define if FMA3 instructions can be compiled.]), | |
474 | []) | |
475 | CFLAGS="$ac_save_CFLAGS" | |
476 | ]) | |
477 | ||
478 | dnl Check for FMA4 | |
479 | dnl | |
480 | AC_DEFUN([LIBGFOR_CHECK_FMA4], [ | |
481 | ac_save_CFLAGS="$CFLAGS" | |
482 | CFLAGS="-O2 -mfma4 -mno-fma" | |
483 | AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[ | |
9698e1bb RO |
484 | typedef float __m128 __attribute__ ((__vector_size__ (16))); |
485 | typedef float __v4sf __attribute__ ((__vector_size__ (16))); | |
486 | __m128 _mm_macc_ps(__m128 __A, __m128 __B, __m128 __C) | |
1d5cf7fc | 487 | { |
9698e1bb RO |
488 | return (__m128) __builtin_ia32_vfmaddps ((__v4sf)__A, |
489 | (__v4sf)__B, | |
490 | (__v4sf)__C); | |
1d5cf7fc TK |
491 | }]], [[]])], |
492 | AC_DEFINE(HAVE_FMA4, 1, | |
493 | [Define if FMA4 instructions can be compiled.]), | |
494 | []) | |
495 | CFLAGS="$ac_save_CFLAGS" | |
496 | ]) | |
497 | ||
498 | dnl Check for -mprefer-avx128 | |
499 | dnl This also defines an automake conditional. | |
500 | AC_DEFUN([LIBGFOR_CHECK_AVX128], [ | |
501 | ac_save_CFLAGS="$CFLAGS" | |
502 | CFLAGS="-O2 -mavx -mprefer-avx128" | |
503 | AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[ | |
504 | void foo() | |
505 | { | |
506 | }]], [[]])], | |
507 | AC_DEFINE(HAVE_AVX128, 1, | |
508 | [Define if -mprefer-avx128 is supported.]) | |
509 | AM_CONDITIONAL([HAVE_AVX128],true), | |
5596d26a | 510 | [AM_CONDITIONAL([HAVE_AVX128],false)]) |
1d5cf7fc TK |
511 | CFLAGS="$ac_save_CFLAGS" |
512 | ]) |