From 60e80a17a7019026dc7e2da9dc597c9fdf426e33 Mon Sep 17 00:00:00 2001 From: eastb233 Date: Wed, 31 May 2023 10:48:47 +0800 Subject: [PATCH 2/3] [libquadmath][refactor] Enable libquadmath on kunpeng This enable libquadmath on kunpeng platform to convenient users that migrating from x86 platform. libquadmath uses "__float128" as quad precision floating point type and with math functions with "q" suffix like "cosq". For those who do not need to adapt to x86 platform, you can use "long double" as quad precision floating point type and math functions with "l" suffix like "cosl" in libm for quad precision math. --- libquadmath/Makefile.am | 4 ++++ libquadmath/Makefile.in | 3 ++- libquadmath/configure | 28 ++++++++++++++++++++++++++-- libquadmath/configure.ac | 7 +++++++ libquadmath/quadmath.h | 13 +++++++++++-- 5 files changed, 50 insertions(+), 5 deletions(-) diff --git a/libquadmath/Makefile.am b/libquadmath/Makefile.am index 35dffb46f..bf0398d9c 100644 --- a/libquadmath/Makefile.am +++ b/libquadmath/Makefile.am @@ -2,6 +2,10 @@ AUTOMAKE_OPTIONS = foreign info-in-builddir +if ARCH_AARCH64 +DEFS += -D__float128="long double" +endif + ## Skip over everything if the quadlib is not available: if BUILD_LIBQUADMATH ACLOCAL_AMFLAGS = -I .. -I ../config diff --git a/libquadmath/Makefile.in b/libquadmath/Makefile.in index 8c0112122..449cc8a06 100644 --- a/libquadmath/Makefile.in +++ b/libquadmath/Makefile.in @@ -90,6 +90,7 @@ POST_UNINSTALL = : build_triplet = @build@ host_triplet = @host@ target_triplet = @target@ +@ARCH_AARCH64_TRUE@am__append_1 = -D__float128="long double" @BUILD_LIBQUADMATH_FALSE@libquadmath_la_DEPENDENCIES = subdir = . ACLOCAL_M4 = $(top_srcdir)/aclocal.m4 @@ -337,7 +338,7 @@ CFLAGS = @CFLAGS@ CPP = @CPP@ CPPFLAGS = @CPPFLAGS@ CYGPATH_W = @CYGPATH_W@ -DEFS = @DEFS@ +DEFS = @DEFS@ $(am__append_1) DEPDIR = @DEPDIR@ DSYMUTIL = @DSYMUTIL@ DUMPBIN = @DUMPBIN@ diff --git a/libquadmath/configure b/libquadmath/configure index b5b212c06..da41959ee 100644 --- a/libquadmath/configure +++ b/libquadmath/configure @@ -633,6 +633,8 @@ am__EXEEXT_TRUE LTLIBOBJS LIBOBJS get_gcc_base_ver +ARCH_AARCH64_FALSE +ARCH_AARCH64_TRUE GENINSRC_FALSE GENINSRC_TRUE XCFLAGS @@ -10816,7 +10818,7 @@ else lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2 lt_status=$lt_dlunknown cat > conftest.$ac_ext <<_LT_EOF -#line 10819 "configure" +#line 10821 "configure" #include "confdefs.h" #if HAVE_DLFCN_H @@ -10922,7 +10924,7 @@ else lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2 lt_status=$lt_dlunknown cat > conftest.$ac_ext <<_LT_EOF -#line 10925 "configure" +#line 10927 "configure" #include "confdefs.h" #if HAVE_DLFCN_H @@ -12715,6 +12717,11 @@ else cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ + #if defined(__aarch64__) + typedef long double __float128; + #define __builtin_huge_valq() (__extension__ 0x1.0p32767Q) + #endif + #if (!defined(_ARCH_PPC)) || defined(__LONG_DOUBLE_IEEE128__) typedef _Complex float __attribute__((mode(TC))) __complex128; #else @@ -12766,6 +12773,11 @@ fi cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ + #if defined(__aarch64__) + typedef long double __float128; + #define __builtin_huge_valq() (__extension__ 0x1.0p32767Q) + #endif + #if (!defined(_ARCH_PPC)) || defined(__LONG_DOUBLE_IEEE128__) typedef _Complex float __attribute__((mode(TC))) __complex128; #else @@ -13224,6 +13236,14 @@ else GENINSRC_FALSE= fi + if expr "$target_cpu" : "aarch64.*" > /dev/null; then + ARCH_AARCH64_TRUE= + ARCH_AARCH64_FALSE='#' +else + ARCH_AARCH64_TRUE='#' + ARCH_AARCH64_FALSE= +fi + # Determine what GCC version number to use in filesystem paths. @@ -13407,6 +13427,10 @@ if test -z "${GENINSRC_TRUE}" && test -z "${GENINSRC_FALSE}"; then as_fn_error $? "conditional \"GENINSRC\" was never defined. Usually this means the macro was only invoked conditionally." "$LINENO" 5 fi +if test -z "${ARCH_AARCH64_TRUE}" && test -z "${ARCH_AARCH64_FALSE}"; then + as_fn_error $? "conditional \"ARCH_AARCH64\" was never defined. +Usually this means the macro was only invoked conditionally." "$LINENO" 5 +fi : "${CONFIG_STATUS=./config.status}" ac_write_fail=0 diff --git a/libquadmath/configure.ac b/libquadmath/configure.ac index f9d745e60..0b8511f04 100644 --- a/libquadmath/configure.ac +++ b/libquadmath/configure.ac @@ -218,6 +218,11 @@ AM_CONDITIONAL(LIBQUAD_USE_SYMVER_SUN, [test "x$quadmath_use_symver" = xsun]) AC_CACHE_CHECK([whether __float128 is supported], [libquad_cv_have_float128], [GCC_TRY_COMPILE_OR_LINK([ + #if defined(__aarch64__) + typedef long double __float128; + #define __builtin_huge_valq() (__extension__ 0x1.0p32767Q) + #endif + #if (!defined(_ARCH_PPC)) || defined(__LONG_DOUBLE_IEEE128__) typedef _Complex float __attribute__((mode(TC))) __complex128; #else @@ -380,6 +385,8 @@ AS_HELP_STRING([--enable-generated-files-in-srcdir], [enable_generated_files_in_srcdir=no]) AC_MSG_RESULT($enable_generated_files_in_srcdir) AM_CONDITIONAL(GENINSRC, test "$enable_generated_files_in_srcdir" = yes) +AM_CONDITIONAL(ARCH_AARCH64, + [expr "$target_cpu" : "aarch64.*" > /dev/null]) # Determine what GCC version number to use in filesystem paths. GCC_BASE_VER diff --git a/libquadmath/quadmath.h b/libquadmath/quadmath.h index 81eb957d2..bb1b49df6 100644 --- a/libquadmath/quadmath.h +++ b/libquadmath/quadmath.h @@ -27,6 +27,12 @@ Boston, MA 02110-1301, USA. */ extern "C" { #endif +#if defined(__aarch64__) +#ifndef __float128 +typedef long double __float128; +#endif +#endif + /* Define the complex type corresponding to __float128 ("_Complex __float128" is not allowed) */ #if (!defined(_ARCH_PPC)) || defined(__LONG_DOUBLE_IEEE128__) @@ -160,10 +166,13 @@ extern int quadmath_snprintf (char *str, size_t size, #define FLT128_MAX_10_EXP 4932 -#define HUGE_VALQ __builtin_huge_valq() +#if defined(__aarch64__) /* The following alternative is valid, but brings the warning: (floating constant exceeds range of ‘__float128’) */ -/* #define HUGE_VALQ (__extension__ 0x1.0p32767Q) */ +# define HUGE_VALQ (__extension__ 0x1.0p32767Q) +#else +# define HUGE_VALQ __builtin_huge_valq() +#endif #define M_Eq 2.718281828459045235360287471352662498Q /* e */ #define M_LOG2Eq 1.442695040888963407359924681001892137Q /* log_2 e */ -- 2.33.0