]> git.ipfire.org Git - thirdparty/gcc.git/blobdiff - libgfortran/acinclude.m4
aix: Use $(AR) without -X32_64 to build FAT libraries.
[thirdparty/gcc.git] / libgfortran / acinclude.m4
index 7280bc37a0bd2fb3f4727b788b3fefa28ca78c10..5b0c094e71697e73a3845cf1f22fae326dc90c30 100644 (file)
@@ -1,6 +1,9 @@
 m4_include(../config/acx.m4)
 m4_include(../config/no-executables.m4)
 m4_include(../config/math.m4)
+m4_include(../config/ax_check_define.m4)
+m4_include(../config/enable.m4)
+m4_include(../config/cet.m4)
 
 dnl Check that we have a working GNU Fortran compiler
 AC_DEFUN([LIBGFOR_WORKING_GFORTRAN], [
@@ -56,17 +59,17 @@ extern void bar(void) __attribute__((alias("foo")));]],
       [Define to 1 if the target supports __attribute__((alias(...))).])
   fi])
 
-dnl Check whether the target supports __sync_fetch_and_add.
-AC_DEFUN([LIBGFOR_CHECK_SYNC_FETCH_AND_ADD], [
-  AC_CACHE_CHECK([whether the target supports __sync_fetch_and_add],
-                libgfor_cv_have_sync_fetch_and_add, [
+dnl Check whether the target supports __atomic_fetch_add.
+AC_DEFUN([LIBGFOR_CHECK_ATOMIC_FETCH_ADD], [
+  AC_CACHE_CHECK([whether the target supports __atomic_fetch_add],
+                libgfor_cv_have_atomic_fetch_add, [
   AC_LINK_IFELSE([AC_LANG_PROGRAM([[int foovar = 0;]], [[
-if (foovar <= 0) return __sync_fetch_and_add (&foovar, 1);
-if (foovar > 10) return __sync_add_and_fetch (&foovar, -1);]])],
-             libgfor_cv_have_sync_fetch_and_add=yes, libgfor_cv_have_sync_fetch_and_add=no)])
-  if test $libgfor_cv_have_sync_fetch_and_add = yes; then
-    AC_DEFINE(HAVE_SYNC_FETCH_AND_ADD, 1,
-             [Define to 1 if the target supports __sync_fetch_and_add])
+if (foovar <= 0) return __atomic_fetch_add (&foovar, 1, __ATOMIC_ACQ_REL);
+if (foovar > 10) return __atomic_add_fetch (&foovar, -1, __ATOMIC_ACQ_REL);]])],
+             libgfor_cv_have_atomic_fetch_add=yes, libgfor_cv_have_atomic_fetch_add=no)])
+  if test $libgfor_cv_have_atomic_fetch_add = yes; then
+    AC_DEFINE(HAVE_ATOMIC_FETCH_ADD, 1,
+             [Define to 1 if the target supports __atomic_fetch_add])
   fi])
 
 dnl Check for pragma weak.
@@ -393,3 +396,117 @@ AC_DEFUN([LIBGFOR_CHECK_STRERROR_R], [
                  [Define if strerror_r takes two arguments and is available in <string.h>.]),)
   CFLAGS="$ac_save_CFLAGS"
 ])
+
+dnl Check for AVX
+
+AC_DEFUN([LIBGFOR_CHECK_AVX], [
+  ac_save_CFLAGS="$CFLAGS"
+  CFLAGS="-O2 -mavx"
+  AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
+  void _mm256_zeroall (void)
+        {
+           __builtin_ia32_vzeroall ();
+        }]], [[]])],
+       AC_DEFINE(HAVE_AVX, 1,
+       [Define if AVX instructions can be compiled.]),
+       [])
+  CFLAGS="$ac_save_CFLAGS"
+])
+
+dnl Check for AVX2
+
+AC_DEFUN([LIBGFOR_CHECK_AVX2], [
+  ac_save_CFLAGS="$CFLAGS"
+  CFLAGS="-O2 -mavx2"
+  AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
+  typedef long long __v4di __attribute__ ((__vector_size__ (32)));
+       __v4di
+       mm256_is32_andnotsi256  (__v4di __X, __v4di __Y)
+        {
+          return __builtin_ia32_andnotsi256 (__X, __Y);
+        }]], [[]])],
+       AC_DEFINE(HAVE_AVX2, 1,
+       [Define if AVX2 instructions can be compiled.]),
+       [])
+  CFLAGS="$ac_save_CFLAGS"
+])
+
+dnl Check for AVX512f
+
+AC_DEFUN([LIBGFOR_CHECK_AVX512F], [
+  ac_save_CFLAGS="$CFLAGS"
+  CFLAGS="-O2 -mavx512f"
+  AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
+       typedef double __m512d __attribute__ ((__vector_size__ (64)));
+       __m512d _mm512_add (__m512d a)
+       {
+         __m512d b = __builtin_ia32_addpd512_mask (a, a, a, 1, 4);
+         /* For -m64/-mx32 also verify that code will work even if
+            the target uses call saved zmm16+ and needs to emit
+            unwind info for them (e.g. on mingw).  See PR79127.  */
+#ifdef __x86_64__
+         asm volatile ("" : : : "zmm16", "zmm17", "zmm18", "zmm19");
+#endif
+         return b;
+        }]], [[]])],
+       AC_DEFINE(HAVE_AVX512F, 1,
+       [Define if AVX512f instructions can be compiled.]),
+       [])
+  CFLAGS="$ac_save_CFLAGS"
+])
+
+dnl Check for FMA3
+dnl
+AC_DEFUN([LIBGFOR_CHECK_FMA3], [
+  ac_save_CFLAGS="$CFLAGS"
+  CFLAGS="-O2 -mfma -mno-fma4"
+  AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
+        typedef float __m128 __attribute__ ((__vector_size__ (16)));
+       typedef float __v4sf __attribute__ ((__vector_size__ (16)));
+       __m128 _mm_macc_ps(__m128 __A, __m128 __B, __m128 __C)
+       {
+           return (__m128) __builtin_ia32_vfmaddps ((__v4sf)__A,
+                                                    (__v4sf)__B,
+                                                    (__v4sf)__C);
+        }]], [[]])],
+       AC_DEFINE(HAVE_FMA3, 1,
+       [Define if FMA3 instructions can be compiled.]),
+       [])
+  CFLAGS="$ac_save_CFLAGS"
+])
+
+dnl Check for FMA4
+dnl
+AC_DEFUN([LIBGFOR_CHECK_FMA4], [
+  ac_save_CFLAGS="$CFLAGS"
+  CFLAGS="-O2 -mfma4 -mno-fma"
+  AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
+        typedef float __m128 __attribute__ ((__vector_size__ (16)));
+       typedef float __v4sf __attribute__ ((__vector_size__ (16)));
+       __m128 _mm_macc_ps(__m128 __A, __m128 __B, __m128 __C)
+       {
+           return (__m128) __builtin_ia32_vfmaddps ((__v4sf)__A,
+                                                    (__v4sf)__B,
+                                                    (__v4sf)__C);
+        }]], [[]])],
+       AC_DEFINE(HAVE_FMA4, 1,
+       [Define if FMA4 instructions can be compiled.]),
+       [])
+  CFLAGS="$ac_save_CFLAGS"
+])
+
+dnl Check for -mprefer-avx128
+dnl This also defines an automake conditional.
+AC_DEFUN([LIBGFOR_CHECK_AVX128], [
+  ac_save_CFLAGS="$CFLAGS"
+  CFLAGS="-O2 -mavx -mprefer-avx128"
+  AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
+        void foo()
+       {
+        }]], [[]])],
+       AC_DEFINE(HAVE_AVX128, 1,
+       [Define if -mprefer-avx128 is supported.])
+       AM_CONDITIONAL([HAVE_AVX128],true),
+       [AM_CONDITIONAL([HAVE_AVX128],false)])
+  CFLAGS="$ac_save_CFLAGS"
+])