Skip to content

Commit

Permalink
More stuff into acinclude.m4
Browse files Browse the repository at this point in the history
  • Loading branch information
albinahlback committed Feb 18, 2024
1 parent fbfabea commit bee681b
Show file tree
Hide file tree
Showing 2 changed files with 135 additions and 93 deletions.
168 changes: 129 additions & 39 deletions acinclude.m4
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,15 @@ dnl the terms of the GNU Lesser General Public License (LGPL) as published
dnl by the Free Software Foundation; either version 3 of the License, or
dnl (at your option) any later version. See <https://www.gnu.org/licenses/>.

define(X86_PATTERN,
[[i?86*-*-* | k[5-8]*-*-* | pentium*-*-* | athlon-*-* | viac3*-*-* | geode*-*-* | atom-*-*]])

define(X86_64_PATTERN,
[[athlon64-*-* | k8-*-* | k10-*-* | bobcat-*-* | jaguar*-*-* | bulldozer*-*-* | piledriver*-*-* | steamroller*-*-* | excavator*-*-* | zen*-*-* | pentium4-*-* | atom-*-* | silvermont-*-* | goldmont-*-* | tremont-*-* | core2-*-* | corei*-*-* | x86_64-*-* | nano-*-* | nehalem*-*-* | westmere*-*-* | sandybridge*-*-* | ivybridge*-*-* | haswell*-*-* | broadwell*-*-* | skylake*-*-* | kabylake*-*-* | icelake*-*-* | tigerlake*-*-* | rocketlake*-*-* | alderlake*-*-* | raptorlake*-*-*]])

define(ARM64_PATTERN,
[[aarch64-*-*]])

dnl FLINT_CHECK_GMP_H(MAJOR, MINOR, PATCHLEVEL)
dnl -----------------------
dnl Checks that gmp.h can be found and that its version fullfills the version
Expand Down Expand Up @@ -198,32 +207,33 @@ AC_COMPILE_IFELSE([AC_LANG_PROGRAM([],[
error
#endif
])],
flint_cv_system_v_abi=yes,
flint_cv_system_v_abi=no
[flint_cv_system_v_abi="yes"],
[flint_cv_system_v_abi="no"]
))
AS_VAR_IF(flint_cv_system_v_abi,yes,
AS_VAR_IF([flint_cv_system_v_abi],"yes",
[m4_default([$1], :)],
[m4_default([$2], :)])
])


dnl FLINT_HAVE_ADX([action-success][,action-fail])
dnl -----------------------
dnl Checks if CPU supports the ADX instruction set.
dnl Do "action-success" if this succeeds, "action-fail" if not.
dnl Checks if CPU supports the ADX instruction set. Will only run if CPU is
dnl x86_64. Do "action-success" if this succeeds, "action-fail" if not.

AC_DEFUN([FLINT_HAVE_ADX],
[AC_CACHE_CHECK([if ADX instruction set is supported by CPU],
flint_cv_have_adx,
AC_COMPILE_IFELSE([AC_LANG_PROGRAM([],[
#if !defined(__ADX__)
#error Dead man
error
#endif
])],
flint_cv_have_adx="yes",
flint_cv_have_adx="no")
)
[AS_VAR_IF([host_cpu],"x86_64",
[AC_CACHE_CHECK([if ADX instruction set is supported by CPU],
flint_cv_have_adx,
AC_COMPILE_IFELSE([AC_LANG_PROGRAM([],[
#if !defined(__ADX__)
#error Dead man
error
#endif
])],
flint_cv_have_adx="yes",
flint_cv_have_adx="no")
)])
AS_VAR_IF(flint_cv_have_adx,yes,
[m4_default([$1], :)],
[m4_default([$2], :)])
Expand All @@ -238,28 +248,117 @@ dnl Do "action-success" if this succeeds, "action-fail" if not.
AC_DEFUN([FLINT_HAVE_ASM],
[AC_REQUIRE([FLINT_ABI])
AC_REQUIRE([FLINT_SYSTEM_V_ABI])
case $host in
X86_64_PATTERN)
AC_REQUIRE([FLINT_HAVE_ADX])
;;
esac
AC_REQUIRE([FLINT_HAVE_ADX])
AC_CACHE_CHECK([if system can use FLINT's assembly],
flint_cv_have_asm,
[flint_cv_have_asm="no"
if test "$flint_cv_abi" = "64" && test "$flint_cv_system_v_abi" = "yes";
then
case $host in
X86_64_PATTERN)
if test "$flint_cv_have_adx" = "yes";
then
flint_cv_have_asm="yes"
fi
;;
esac
if test "$flint_cv_have_adx" = "yes";
then
flint_cv_have_asm="yes"
fi
fi])
AS_VAR_IF(flint_cv_have_asm,yes,
AS_VAR_IF([flint_cv_have_asm],"yes",
[m4_default([$1], :)],
[m4_default([$2], :)])
])


dnl FLINT_HAVE_FFT_SMALL_ARM_H
dnl -----------------------
dnl Checks if system have headers for fft_small on Arm. Will only run if on
dnl arm64.

AC_DEFUN([FLINT_HAVE_FFT_SMALL_ARM_H],
[AS_VAR_IF([host_cpu],"aarch64",
[AC_CHECK_HEADER([arm_neon.h],flint_cv_have_fft_small_arm_h="yes")]
)])


dnl FLINT_HAVE_FFT_SMALL_ARM_I
dnl -----------------------
dnl Checks if system supports Arm NEON instructions.

AC_DEFUN([FLINT_HAVE_FFT_SMALL_ARM_I],
[AS_VAR_IF([host_cpu],"aarch64",
[AC_CACHE_CHECK([if system have required Arm instruction set for fft_small],
flint_cv_have_fft_small_arm_i,
AC_COMPILE_IFELSE([AC_LANG_PROGRAM([],[
#ifndef __ARM_NEON
#error Dead man
error
#endif
])],
flint_cv_have_fft_small_arm_i="yes",
flint_cv_have_fft_small_arm_i="no")
)]
)])


dnl FLINT_HAVE_FFT_SMALL_X86_H
dnl -----------------------
dnl Checks if system have headers for fft_small on x86.

AC_DEFUN([FLINT_HAVE_FFT_SMALL_X86_H],
[AS_VAR_IF([host_cpu],"x86_64",
[AC_CHECK_HEADERS([x86gprintrin.h immintrin.h],
flint_cv_have_fft_small_x86_h="yes",
flint_cv_have_fft_small_x86_h="no")]
)])


dnl FLINT_HAVE_FFT_SMALL_X86_I
dnl -----------------------
dnl Checks if system supports AVX2 instructions.

AC_DEFUN([FLINT_HAVE_FFT_SMALL_X86_I],
[AS_VAR_IF([host_cpu],"x86_64",
[AC_CACHE_CHECK([if system have required x86_64 instruction set for fft_small],
flint_cv_have_fft_small_x86_i,
AC_COMPILE_IFELSE([AC_LANG_PROGRAM([],[
#if !defined(__AVX2__)
#error Dead man
error
#endif
])],
flint_cv_have_fft_small_x86_i="yes",
flint_cv_have_fft_small_x86_i="no")
)]
)])


dnl FLINT_CHECK_FFT_SMALL([action-success][,action-fail])
dnl -----------------------
dnl Checks if fft_small module is available.
dnl Do "action-success" if this succeeds, "action-fail" if not.

AC_DEFUN([FLINT_CHECK_FFT_SMALL],
[AC_REQUIRE([FLINT_ABI])
AC_REQUIRE([FLINT_HAVE_FFT_SMALL_ARM_H])
AC_REQUIRE([FLINT_HAVE_FFT_SMALL_ARM_I])
AC_REQUIRE([FLINT_HAVE_FFT_SMALL_X86_H])
AC_REQUIRE([FLINT_HAVE_FFT_SMALL_X86_I])
AC_CACHE_CHECK([if system can use FLINT's fft_small module],
flint_cv_check_fft_small,
[flint_cv_check_fft_small="no"
if test "$flint_cv_abi" = "64";
then
if test "$flint_cv_have_fft_small_arm_h" = "yes" && test "$flint_cv_have_fft_small_arm_i" = "yes";
then
flint_cv_check_fft_small="yes"
fi
if test "$flint_cv_have_fft_small_x86_h" = "yes" && test "$flint_cv_have_fft_small_x86_i" = "yes";
then
flint_cv_check_fft_small="yes"
fi
fi
])
AS_VAR_IF([flint_cv_check_fft_small],"yes",
[m4_default([$1], :)],
[m4_default([$2], :)])
])
Expand Down Expand Up @@ -296,15 +395,6 @@ dnl You should have received copies of the GNU General Public License and the
dnl GNU Lesser General Public License along with the GNU MP Library. If not,
dnl see https://www.gnu.org/licenses/.

define(X86_PATTERN,
[[i?86*-*-* | k[5-8]*-*-* | pentium*-*-* | athlon-*-* | viac3*-*-* | geode*-*-* | atom-*-*]])

define(X86_64_PATTERN,
[[athlon64-*-* | k8-*-* | k10-*-* | bobcat-*-* | jaguar*-*-* | bulldozer*-*-* | piledriver*-*-* | steamroller*-*-* | excavator*-*-* | zen*-*-* | pentium4-*-* | atom-*-* | silvermont-*-* | goldmont-*-* | tremont-*-* | core2-*-* | corei*-*-* | x86_64-*-* | nano-*-* | nehalem*-*-* | westmere*-*-* | sandybridge*-*-* | ivybridge*-*-* | haswell*-*-* | broadwell*-*-* | skylake*-*-* | kabylake*-*-* | icelake*-*-* | tigerlake*-*-* | rocketlake*-*-* | alderlake*-*-* | raptorlake*-*-*]])

define(ARM64_PATTERN,
[[aarch64-*-*]])

dnl GMP_INIT([M4-DEF-FILE])
dnl -----------------------
dnl Initializations for GMP config.m4 generation.
Expand Down
60 changes: 6 additions & 54 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -612,12 +612,9 @@ case "$host_os" in
cygwin|mingw*|msys)
if test "$DLLTOOL" = "false";
then
AC_MSG_ERROR(["Couldn't find any dlltool that is required to create import libraries for
Windows-type systems."])
AC_MSG_ERROR(["Couldn't find any dlltool that is required to create import libraries for Windows-type systems."])
fi
;;
*)
;;
esac

AC_MSG_CHECKING(for ldconfig)
Expand All @@ -631,8 +628,6 @@ case "$build_os" in
netbsd* | openbsd*)
dnl LDCONFIG_N="/sbin/ldconfig -m"
;;
*)
;;
esac
if test "x$LDCONFIG_N" = "x";
then
Expand Down Expand Up @@ -714,7 +709,7 @@ AC_CHECK_HEADERS([stdarg.h math.h float.h errno.h],,
# Optional headers
# The following headers are checked previously:
# unistd.h
AC_CHECK_HEADERS([fenv.h alloca.h malloc.h sys/param.h windows.h arm_neon.h x86intrin.h immintrin.h pthread_np.h])
AC_CHECK_HEADERS([fenv.h alloca.h malloc.h sys/param.h windows.h pthread_np.h])

if test "$enable_pthread" = "yes";
then
Expand Down Expand Up @@ -997,53 +992,10 @@ CPPFLAGS="-I./src $CPPFLAGS"
# fft_small module
################################################################################

enable_fft_small="no"

AC_MSG_CHECKING([whether fft_small module is available])

if test "$ac_cv_header_arm_neon_h" = "yes";
then
AC_COMPILE_IFELSE(
[AC_LANG_PROGRAM([],[
#ifndef __ARM_NEON
#error Dead man
error
#endif
])],
[AC_COMPILE_IFELSE(
[AC_LANG_PROGRAM([],[
#ifndef __GNUC__
#error Dead man
error
#endif
])],
[enable_fft_small="yes"]
)]
)
fi

if test "$ac_cv_header_x86intrin_h" = "yes" && test "$ac_cv_header_immintrin_h" = "yes" && test "$flint_cv_abi" = "64";
then
AC_COMPILE_IFELSE(
[AC_LANG_PROGRAM([],[
#if !defined(__AVX2__) || !defined(__GNUC__)
#error Dead man
error
#endif
])],
enable_fft_small="yes"
)
fi

AC_MSG_RESULT([$enable_fft_small])

if test "$enable_fft_small" = "yes";
then
AC_SUBST(FFT_SMALL, [fft_small\ \ \ ])
AC_DEFINE(FLINT_HAVE_FFT_SMALL, 1, [Define to use the fft_small module])
else
AC_SUBST(FFT_SMALL, [\ \ \ \ \ \ \ \ \ \ \ \ ])
fi
FLINT_CHECK_FFT_SMALL(
[AC_SUBST(FFT_SMALL, [fft_small\ \ \ ])
AC_DEFINE(FLINT_HAVE_FFT_SMALL, 1, [Define to use the fft_small module])],
[AC_SUBST(FFT_SMALL, [\ \ \ \ \ \ \ \ \ \ \ \ ])])

################################################################################
# Assembly
Expand Down

0 comments on commit bee681b

Please sign in to comment.