From d92e539f8b4366fed71a7d90d8bb85b9ff16ca0b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Albin=20Ahlb=C3=A4ck?= Date: Sun, 19 Nov 2023 19:53:29 +0100 Subject: [PATCH] Set longlong.h during configuration --- CMakeLists.txt | 407 +++++++++++++++++++++++++++++++++++++++++++++++++ Makefile.in | 3 + acinclude.m4 | 48 ++++++ configure.ac | 85 ++++++++++- 4 files changed, 542 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index efd744a0e1..cae9d44192 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -217,6 +217,413 @@ check_c_source_compiles([[#include #endif void main(){};]] LONG_LONG_LIMB) +# longlong.h configuration +set(CMAKE_REQUIRED_INCLUDES ${GMP_INCLUDE_DIRS}) +check_c_source_compiles([[#include +typedef mp_limb_t ulong; +#define FLINT_ASSERT(x) +#define FLINT_DLL +#define FLINT_BITS GMP_LIMB_BITS +#include "${CMAKE_CURRENT_SOURCE_DIR}/src/longlong-x86_64.h.in" +#if !defined(__GNUC__) || GMP_LIMB_BITS != 64 || !defined(__amd64__) +# error +error +#endif +int main(void) +{ + ulong s3, s2, s1, s0; + ulong a3, a2, a1, a0; + ulong b3, b2, b1, b0; + + a0 = 19827; + a1 = 1872; + a2 = 338237; + a3 = 98080; + b0 = 1798291; + b1 = 719271; + b2 = 891; + b3 = 9112; + + s0 = flint_clz(a0); + s1 = flint_ctz(a0); + add_ssaaaa(s1, s0, a1, a0, b1, b0); + add_sssaaaaaa(s2, s1, s0, a2, a1, a0, b2, b1, b0); + add_ssssaaaaaaaa(s3, s2, s1, s0, a3, a2, a1, a0, b3, b2, b1, b0); + sub_ddmmss(s1, s0, a1, a0, b1, b0); + sub_dddmmmsss(s2, s1, s0, a2, a1, a0, b2, b1, b0); + umul_ppmm(s1, s0, a0, b0); + smul_ppmm(s1, s0, a0, b0); + udiv_qrnnd(s1, s0, a1, a0, b0); + sdiv_qrnnd(s1, s0, a1, a0, b0); + byte_swap(s2); + /* udiv_qrnnd_preinv is the same for every header */ + return 0; +}]] LONGLONG_X86_64) + +if(LONGLONG_X86_64) + set(LONGLONG ON) + configure_file( + ${CMAKE_CURRENT_SOURCE_DIR}/src/longlong-x86_64.h.in + ${CMAKE_CURRENT_SOURCE_DIR}/src/longlong.h + COPYONLY) +endif() + +if(NOT LONGLONG) + check_c_source_compiles([[#include +typedef mp_limb_t ulong; +#define FLINT_ASSERT(x) +#define FLINT_DLL +#define FLINT_BITS GMP_LIMB_BITS +#include "${CMAKE_CURRENT_SOURCE_DIR}/src/longlong-arm64.h.in" +#if !defined(__GNUC__) || GMP_LIMB_BITS != 64 || !defined(__arm64__) +# error +error +#endif +int main(void) +{ + ulong s3, s2, s1, s0; + ulong a3, a2, a1, a0; + ulong b3, b2, b1, b0; + + a0 = 19827; + a1 = 1872; + a2 = 338237; + a3 = 98080; + b0 = 1798291; + b1 = 719271; + b2 = 891; + b3 = 9112; + + s0 = flint_clz(a0); + s1 = flint_ctz(a0); + add_ssaaaa(s1, s0, a1, a0, b1, b0); + add_sssaaaaaa(s2, s1, s0, a2, a1, a0, b2, b1, b0); + add_ssssaaaaaaaa(s3, s2, s1, s0, a3, a2, a1, a0, b3, b2, b1, b0); + sub_ddmmss(s1, s0, a1, a0, b1, b0); + sub_dddmmmsss(s2, s1, s0, a2, a1, a0, b2, b1, b0); + umul_ppmm(s1, s0, a0, b0); + smul_ppmm(s1, s0, a0, b0); + udiv_qrnnd(s1, s0, a1, a0, b0); + sdiv_qrnnd(s1, s0, a1, a0, b0); + byte_swap(s2); + /* udiv_qrnnd_preinv is the same for every header */ + return 0; +}]] LONGLONG_ARM64) + + if(LONGLONG_ARM64) + set(LONGLONG ON) + configure_file( + ${CMAKE_CURRENT_SOURCE_DIR}/src/longlong-arm64.h.in + ${CMAKE_CURRENT_SOURCE_DIR}/src/longlong.h + COPYONLY) + endif() +endif() + +if(NOT LONGLONG) + check_c_source_compiles([[#include +typedef mp_limb_t ulong; +#define FLINT_ASSERT(x) +#define FLINT_DLL +#define FLINT_BITS GMP_LIMB_BITS +#include "${CMAKE_CURRENT_SOURCE_DIR}/src/longlong-x86.h.in" +#if !defined(__GNUC__) || GMP_LIMB_BITS != 32 || !(defined (__i386__) || defined (__i486__) || defined(__amd64__)) +# error +error +#endif +int main(void) +{ + ulong s3, s2, s1, s0; + ulong a3, a2, a1, a0; + ulong b3, b2, b1, b0; + + a0 = 19827; + a1 = 1872; + a2 = 338237; + a3 = 98080; + b0 = 1798291; + b1 = 719271; + b2 = 891; + b3 = 9112; + + s0 = flint_clz(a0); + s1 = flint_ctz(a0); + add_ssaaaa(s1, s0, a1, a0, b1, b0); + add_sssaaaaaa(s2, s1, s0, a2, a1, a0, b2, b1, b0); + add_ssssaaaaaaaa(s3, s2, s1, s0, a3, a2, a1, a0, b3, b2, b1, b0); + sub_ddmmss(s1, s0, a1, a0, b1, b0); + sub_dddmmmsss(s2, s1, s0, a2, a1, a0, b2, b1, b0); + umul_ppmm(s1, s0, a0, b0); + smul_ppmm(s1, s0, a0, b0); + udiv_qrnnd(s1, s0, a1, a0, b0); + sdiv_qrnnd(s1, s0, a1, a0, b0); + byte_swap(s2); + /* udiv_qrnnd_preinv is the same for every header */ + return 0; +}]] LONGLONG_X86) + + if(LONGLONG_X86) + set(LONGLONG ON) + configure_file( + ${CMAKE_CURRENT_SOURCE_DIR}/src/longlong-x86.h.in + ${CMAKE_CURRENT_SOURCE_DIR}/src/longlong.h + COPYONLY) + endif() +endif() + +if(NOT LONGLONG) + check_c_source_compiles([[#include +typedef mp_limb_t ulong; +#define FLINT_ASSERT(x) +#define FLINT_DLL +#define FLINT_BITS GMP_LIMB_BITS +#include "${CMAKE_CURRENT_SOURCE_DIR}/src/longlong-arm.h.in" +#if !defined(__GNUC__) || GMP_LIMB_BITS != 32 || !defined(__arm__) +# error +error +#endif +int main(void) +{ + ulong s3, s2, s1, s0; + ulong a3, a2, a1, a0; + ulong b3, b2, b1, b0; + + a0 = 19827; + a1 = 1872; + a2 = 338237; + a3 = 98080; + b0 = 1798291; + b1 = 719271; + b2 = 891; + b3 = 9112; + + s0 = flint_clz(a0); + s1 = flint_ctz(a0); + add_ssaaaa(s1, s0, a1, a0, b1, b0); + add_sssaaaaaa(s2, s1, s0, a2, a1, a0, b2, b1, b0); + add_ssssaaaaaaaa(s3, s2, s1, s0, a3, a2, a1, a0, b3, b2, b1, b0); + sub_ddmmss(s1, s0, a1, a0, b1, b0); + sub_dddmmmsss(s2, s1, s0, a2, a1, a0, b2, b1, b0); + umul_ppmm(s1, s0, a0, b0); + smul_ppmm(s1, s0, a0, b0); + udiv_qrnnd(s1, s0, a1, a0, b0); + sdiv_qrnnd(s1, s0, a1, a0, b0); + byte_swap(s2); + /* udiv_qrnnd_preinv is the same for every header */ + return 0; +}]] LONGLONG_ARM) + + if(LONGLONG_ARM) + set(LONGLONG ON) + configure_file( + ${CMAKE_CURRENT_SOURCE_DIR}/src/longlong-arm.h.in + ${CMAKE_CURRENT_SOURCE_DIR}/src/longlong.h + COPYONLY) + endif() +endif() + +if(NOT LONGLONG) + check_c_source_compiles([[#include +typedef mp_limb_t ulong; +#define FLINT_ASSERT(x) +#define FLINT_DLL +#define FLINT_BITS GMP_LIMB_BITS +#include "${CMAKE_CURRENT_SOURCE_DIR}/src/longlong-generic_gnu.h.in" +#if !defined(__GNUC__) +# error +error +#endif +int main(void) +{ + ulong s3, s2, s1, s0; + ulong a3, a2, a1, a0; + ulong b3, b2, b1, b0; + + a0 = 19827; + a1 = 1872; + a2 = 338237; + a3 = 98080; + b0 = 1798291; + b1 = 719271; + b2 = 891; + b3 = 9112; + + s0 = flint_clz(a0); + s1 = flint_ctz(a0); + add_ssaaaa(s1, s0, a1, a0, b1, b0); + add_sssaaaaaa(s2, s1, s0, a2, a1, a0, b2, b1, b0); + add_ssssaaaaaaaa(s3, s2, s1, s0, a3, a2, a1, a0, b3, b2, b1, b0); + sub_ddmmss(s1, s0, a1, a0, b1, b0); + sub_dddmmmsss(s2, s1, s0, a2, a1, a0, b2, b1, b0); + umul_ppmm(s1, s0, a0, b0); + smul_ppmm(s1, s0, a0, b0); + udiv_qrnnd(s1, s0, a1, a0, b0); + sdiv_qrnnd(s1, s0, a1, a0, b0); + byte_swap(s2); + /* udiv_qrnnd_preinv is the same for every header */ + return 0; +}]] LONGLONG_GENERIC_GNU) + + if(LONGLONG_GENERIC_GNU) + set(LONGLONG ON) + configure_file( + ${CMAKE_CURRENT_SOURCE_DIR}/src/longlong-generic_gnu.h.in + ${CMAKE_CURRENT_SOURCE_DIR}/src/longlong.h + COPYONLY) + endif() +endif() + +if(NOT LONGLONG) + check_c_source_compiles([[#include +typedef mp_limb_t ulong; +#define FLINT_ASSERT(x) +#define FLINT_DLL +#define FLINT_BITS GMP_LIMB_BITS +#include "${CMAKE_CURRENT_SOURCE_DIR}/src/longlong-x86_win.h.in" +#if !(defined(_WIN32) || defined(_WIN64)) || !(defined(_M_X64) || defined(_M_IX86)) +# error +error +#endif +int main(void) +{ + ulong s3, s2, s1, s0; + ulong a3, a2, a1, a0; + ulong b3, b2, b1, b0; + + a0 = 19827; + a1 = 1872; + a2 = 338237; + a3 = 98080; + b0 = 1798291; + b1 = 719271; + b2 = 891; + b3 = 9112; + + s0 = flint_clz(a0); + s1 = flint_ctz(a0); + add_ssaaaa(s1, s0, a1, a0, b1, b0); + add_sssaaaaaa(s2, s1, s0, a2, a1, a0, b2, b1, b0); + add_ssssaaaaaaaa(s3, s2, s1, s0, a3, a2, a1, a0, b3, b2, b1, b0); + sub_ddmmss(s1, s0, a1, a0, b1, b0); + sub_dddmmmsss(s2, s1, s0, a2, a1, a0, b2, b1, b0); + umul_ppmm(s1, s0, a0, b0); + smul_ppmm(s1, s0, a0, b0); + udiv_qrnnd(s1, s0, a1, a0, b0); + sdiv_qrnnd(s1, s0, a1, a0, b0); + byte_swap(s2); + /* udiv_qrnnd_preinv is the same for every header */ + return 0; +}]] LONGLONG_X86_WIN) + + if(LONGLONG_X86_WIN) + set(LONGLONG ON) + configure_file( + ${CMAKE_CURRENT_SOURCE_DIR}/src/longlong-x86_win.h.in + ${CMAKE_CURRENT_SOURCE_DIR}/src/longlong.h + COPYONLY) + endif() +endif() + +if(NOT LONGLONG) + check_c_source_compiles([[#include +typedef mp_limb_t ulong; +#define FLINT_ASSERT(x) +#define FLINT_DLL +#define FLINT_BITS GMP_LIMB_BITS +#include "${CMAKE_CURRENT_SOURCE_DIR}/src/longlong-arm_win.h.in" +#if !(defined(_WIN32) || defined(_WIN64)) || !(defined(_M_ARM) || defined(_M_ARM64) || defined(_M_ARM_ARMV7VE) || defined(_M_ARM_FP) || defined(_M_ARM64EC)) +# error +error +#endif +int main(void) +{ + ulong s3, s2, s1, s0; + ulong a3, a2, a1, a0; + ulong b3, b2, b1, b0; + + a0 = 19827; + a1 = 1872; + a2 = 338237; + a3 = 98080; + b0 = 1798291; + b1 = 719271; + b2 = 891; + b3 = 9112; + + s0 = flint_clz(a0); + s1 = flint_ctz(a0); + add_ssaaaa(s1, s0, a1, a0, b1, b0); + add_sssaaaaaa(s2, s1, s0, a2, a1, a0, b2, b1, b0); + add_ssssaaaaaaaa(s3, s2, s1, s0, a3, a2, a1, a0, b3, b2, b1, b0); + sub_ddmmss(s1, s0, a1, a0, b1, b0); + sub_dddmmmsss(s2, s1, s0, a2, a1, a0, b2, b1, b0); + umul_ppmm(s1, s0, a0, b0); + smul_ppmm(s1, s0, a0, b0); + udiv_qrnnd(s1, s0, a1, a0, b0); + sdiv_qrnnd(s1, s0, a1, a0, b0); + byte_swap(s2); + /* udiv_qrnnd_preinv is the same for every header */ + return 0; +}]] LONGLONG_ARM_WIN) + + if(LONGLONG_ARM_WIN) + set(LONGLONG ON) + configure_file( + ${CMAKE_CURRENT_SOURCE_DIR}/src/longlong-arm_win.h.in + ${CMAKE_CURRENT_SOURCE_DIR}/src/longlong.h + COPYONLY) + endif() +endif() + +if(NOT LONGLONG) + check_c_source_compiles([[#include +typedef mp_limb_t ulong; +#define FLINT_ASSERT(x) +#define FLINT_DLL +#define FLINT_BITS GMP_LIMB_BITS +#include "${CMAKE_CURRENT_SOURCE_DIR}/src/longlong-generic.h.in" +int main(void) +{ + ulong s3, s2, s1, s0; + ulong a3, a2, a1, a0; + ulong b3, b2, b1, b0; + + a0 = 19827; + a1 = 1872; + a2 = 338237; + a3 = 98080; + b0 = 1798291; + b1 = 719271; + b2 = 891; + b3 = 9112; + + s0 = flint_clz(a0); + s1 = flint_ctz(a0); + add_ssaaaa(s1, s0, a1, a0, b1, b0); + add_sssaaaaaa(s2, s1, s0, a2, a1, a0, b2, b1, b0); + add_ssssaaaaaaaa(s3, s2, s1, s0, a3, a2, a1, a0, b3, b2, b1, b0); + sub_ddmmss(s1, s0, a1, a0, b1, b0); + sub_dddmmmsss(s2, s1, s0, a2, a1, a0, b2, b1, b0); + umul_ppmm(s1, s0, a0, b0); + smul_ppmm(s1, s0, a0, b0); + udiv_qrnnd(s1, s0, a1, a0, b0); + sdiv_qrnnd(s1, s0, a1, a0, b0); + byte_swap(s2); + /* udiv_qrnnd_preinv is the same for every header */ + return 0; +}]] LONGLONG_GENERIC) + + if(LONGLONG_GENERIC) + set(LONGLONG ON) + configure_file( + ${CMAKE_CURRENT_SOURCE_DIR}/src/longlong-generic.h.in + ${CMAKE_CURRENT_SOURCE_DIR}/src/longlong.h + COPYONLY) + else() + message(FATAL_ERROR "Could not find a suitable longlong.h that would compile.") + endif() +endif() + + # Populate headers configure_file( ${CMAKE_CURRENT_SOURCE_DIR}/CMake/cmake_config.h.in diff --git a/Makefile.in b/Makefile.in index b962a10670..41beff98e5 100644 --- a/Makefile.in +++ b/Makefile.in @@ -833,6 +833,9 @@ src/fmpz/fmpz.c: @FMPZ_C_IN@ config.status src/gmpcompat.h: src/@GMPCOMPAT_H_IN@ config.status ./config.status $@ +src/longlong.h: src/@LONGLONG_H_IN@ config.status + ./config.status $@ + ################################################################################ # maintainer stuff ################################################################################ diff --git a/acinclude.m4 b/acinclude.m4 index 63cc07e6cd..6ea5dda83e 100644 --- a/acinclude.m4 +++ b/acinclude.m4 @@ -53,3 +53,51 @@ AS_VAR_IF(CACHEVAR,yes, [m4_default([$3], :)]) AS_VAR_POPDEF([CACHEVAR])dnl ])dnl AX_CHECK_COMPILE_FLAGS + +# AX_CHECK_LONGLONG_HEADER(FLAG, [ACTION-SUCCESS], [ACTION-FAILURE], [EXTRA-PROLOGUE]) +AC_DEFUN([AX_CHECK_LONGLONG_HEADER], +[AS_VAR_PUSHDEF([CACHEVAR],[ax_cv_check_$1])dnl +AC_CACHE_CHECK([whether system can compile with $1], CACHEVAR, [ +AC_COMPILE_IFELSE( + [AC_LANG_PROGRAM( + [[#include + typedef mp_limb_t ulong; + #define FLINT_ASSERT(x) + #define FLINT_DLL + #define FLINT_BITS GMP_LIMB_BITS + #include "$1" + $4]], + [[ulong s3, s2, s1, s0; + ulong a3, a2, a1, a0; + ulong b3, b2, b1, b0; + + a0 = 19827; + a1 = 1872; + a2 = 338237; + a3 = 98080; + b0 = 1798291; + b1 = 719271; + b2 = 891; + b3 = 9112; + + s0 = flint_clz(a0); + s1 = flint_ctz(a0); + add_ssaaaa(s1, s0, a1, a0, b1, b0); + add_sssaaaaaa(s2, s1, s0, a2, a1, a0, b2, b1, b0); + add_ssssaaaaaaaa(s3, s2, s1, s0, a3, a2, a1, a0, b3, b2, b1, b0); + sub_ddmmss(s1, s0, a1, a0, b1, b0); + sub_dddmmmsss(s2, s1, s0, a2, a1, a0, b2, b1, b0); + umul_ppmm(s1, s0, a0, b0); + smul_ppmm(s1, s0, a0, b0); + udiv_qrnnd(s1, s0, a1, a0, b0); + sdiv_qrnnd(s1, s0, a1, a0, b0); + byte_swap(s2); + /* udiv_qrnnd_preinv is the same for every header */]] + )], + [AS_VAR_SET(CACHEVAR,[yes])], + [AS_VAR_SET(CACHEVAR,[no])])]) +AS_VAR_IF(CACHEVAR,yes, + [m4_default([$2], :)], + [m4_default([$3], :)]) +AS_VAR_POPDEF([CACHEVAR])dnl +])dnl AX_CHECK_LONGLONG_HEADER diff --git a/configure.ac b/configure.ac index f1b58b7e18..2e23f720d2 100644 --- a/configure.ac +++ b/configure.ac @@ -919,7 +919,6 @@ then AX_CHECK_COMPILE_FLAG([-march=native],[DEFAULT_CFLAGS="-march=native $DEFAULT_CFLAGS"]) fi AX_CHECK_COMPILE_FLAG([-std=c11],[DEFAULT_CFLAGS="-std=c11 $DEFAULT_CFLAGS"]) -AX_CHECK_COMPILE_FLAG([-pedantic],[DEFAULT_CFLAGS="-pedantic $DEFAULT_CFLAGS"]) dnl NOTE: The following flags shouldn't be default. They are leftovers from dnl previous configure script @@ -942,6 +941,90 @@ fi CPPFLAGS="-I./src $CPPFLAGS" +################################################################################ +# check which longlong.h to use +################################################################################ + +save_CFLAGS="$CFLAGS" +CFLAGS="-Wall" + +AX_CHECK_LONGLONG_HEADER([src/longlong-x86_64.h.in], + [longlong_h_in="src/longlong-x86_64.h.in"],[], + [#if !defined(__GNUC__) || GMP_LIMB_BITS != 64 || !defined(__amd64__) + # error + error + #endif]) +if test ! -n "$longlong_h_in"; +then + AX_CHECK_LONGLONG_HEADER([src/longlong-arm64.h.in], + [longlong_h_in="src/longlong-arm64.h.in"],[], + [#if !defined(__GNUC__) || GMP_LIMB_BITS != 64 || !(defined(__aarch64__) || defined(__ARM_ARCH_ISA_A64)) + # error + error + #endif]) +fi +if test ! -n "$longlong_h_in"; +then +AX_CHECK_LONGLONG_HEADER([src/longlong-x86.h.in], + [longlong_h_in="src/longlong-x86.h.in"],[], + [#if !defined(__GNUC__) || GMP_LIMB_BITS != 32 || !(defined (__i386__) || defined (__i486__) || defined(__amd64__)) + # error + error + #endif]) +fi +if test ! -n "$longlong_h_in"; +then +AX_CHECK_LONGLONG_HEADER([src/longlong-arm.h.in], + [longlong_h_in="src/longlong-arm.h.in"],[], + [#if !defined(__GNUC__) || GMP_LIMB_BITS != 32 || !defined(__arm__) + # error + error + #endif]) +fi +if test ! -n "$longlong_h_in"; +then +AX_CHECK_LONGLONG_HEADER([src/longlong-generic_gnu.h.in], + [longlong_h_in="src/longlong-generic_gnu.h.in"],[], + [#if !defined(__GNUC__) + # error + error + #endif]) +fi +if test ! -n "$longlong_h_in"; +then +AX_CHECK_LONGLONG_HEADER([src/longlong-x86_win.h.in], + [longlong_h_in="src/longlong-x86_win.h.in"],[], + [#if !(defined(_WIN32) || defined(_WIN64)) || !(defined(_M_X64) || defined(_M_IX86)) + # error + error + #endif]) +fi +if test ! -n "$longlong_h_in"; +then +AX_CHECK_LONGLONG_HEADER([src/longlong-arm_win.h.in], + [longlong_h_in="src/longlong-arm_win.h.in"],[], + [#if !(defined(_WIN32) || defined(_WIN64)) || !(defined(_M_ARM) || defined(_M_ARM64) || defined(_M_ARM_ARMV7VE) || defined(_M_ARM_FP) || defined(_M_ARM64EC)) + # error + error + #endif]) +fi +if test ! -n "$longlong_h_in"; +then +AX_CHECK_LONGLONG_HEADER([src/longlong-generic.h.in], + [longlong_h_in="src/longlong-generic.h.in"]) +fi + +if test ! -n "$longlong_h_in"; +then + AC_MSG_ERROR([Could not find a suitable longlong.h. Please submit a bug report to + and specify your operating system.]) +fi + +AC_CONFIG_FILES([src/longlong.h:$longlong_h_in],[],[longlong_h_in="$longlong_h_in"]) +AC_SUBST(LONGLONG_H_IN, $longlong_h_in) + +CFLAGS="$save_CFLAGS" + ################################################################################ # fft_small module ################################################################################