unofficial mirror of libc-alpha@sourceware.org
 help / color / mirror / Atom feed
From: "H.J. Lu" <hjl.tools@gmail.com>
To: libc-alpha@sourceware.org
Cc: fweimer@redhat.com
Subject: [PATCH] x86-64: Exclude FMA4 IFUNC functions for -mapxf
Date: Thu,  4 Apr 2024 15:43:50 -0700	[thread overview]
Message-ID: <20240404224350.1517977-1-hjl.tools@gmail.com> (raw)

When -mapxf is used to build glibc, the resulting glibc will never run
on FMA4 machines.  Exclude FMA4 IFUNC functions when -mapxf is used.
This requires GCC which defines __APX_F__ for -mapxf with commit:

1df56719bd8 x86: Define __APX_F__ for -mapxf
---
 config.h.in                                   |  3 ++
 sysdeps/x86_64/configure                      | 32 +++++++++++++++++++
 sysdeps/x86_64/configure.ac                   | 18 +++++++++++
 sysdeps/x86_64/fpu/multiarch/Makefile         | 22 +++++++------
 sysdeps/x86_64/fpu/multiarch/ifunc-avx-fma4.h |  2 ++
 sysdeps/x86_64/fpu/multiarch/ifunc-fma4.h     |  2 ++
 6 files changed, 70 insertions(+), 9 deletions(-)

diff --git a/config.h.in b/config.h.in
index 4108d9d460..7b008420dc 100644
--- a/config.h.in
+++ b/config.h.in
@@ -298,4 +298,7 @@
 /* Define if -mmovbe is enabled by default on x86.  */
 #undef HAVE_X86_MOVBE
 
+/* Define if -mapxf is enabled by default on x86.  */
+#undef HAVE_X86_APX
+
 #endif
diff --git a/sysdeps/x86_64/configure b/sysdeps/x86_64/configure
index 04a534fa12..07bdd40a37 100755
--- a/sysdeps/x86_64/configure
+++ b/sysdeps/x86_64/configure
@@ -162,6 +162,38 @@ printf "%s\n" "$libc_cv_x86_have_amx_tile" >&6; }
 config_vars="$config_vars
 have-mamx-tile = $libc_cv_x86_have_amx_tile"
 
+# Check if -mapxf is enabled.
+{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking whether -mapxf is enabled" >&5
+printf %s "checking whether -mapxf is enabled... " >&6; }
+if test ${libc_cv_x86_have_apx+y}
+then :
+  printf %s "(cached) " >&6
+else $as_nop
+  cat > conftest.c <<EOF
+#ifndef __APX_F__
+# error APX isn't enabled
+#endif
+EOF
+	       libc_cv_x86_have_apx=no
+	       if { ac_try='${CC-cc} -c $CFLAGS conftest.c -o conftest.o 1>&5'
+  { { eval echo "\"\$as_me\":${as_lineno-$LINENO}: \"$ac_try\""; } >&5
+  (eval $ac_try) 2>&5
+  ac_status=$?
+  printf "%s\n" "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
+  test $ac_status = 0; }; }; then
+		   libc_cv_x86_have_apx=yes
+	       fi
+	       rm -rf conftest*
+fi
+{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $libc_cv_x86_have_apx" >&5
+printf "%s\n" "$libc_cv_x86_have_apx" >&6; }
+if test $libc_cv_x86_have_apx = yes; then
+  printf "%s\n" "#define HAVE_X86_APX 1" >>confdefs.h
+
+fi
+config_vars="$config_vars
+have-x86-apx = $libc_cv_x86_have_apx"
+
 test -n "$critic_missing" && as_fn_error $? "
 *** $critic_missing" "$LINENO" 5
 
diff --git a/sysdeps/x86_64/configure.ac b/sysdeps/x86_64/configure.ac
index c714c47351..c7b68544a2 100644
--- a/sysdeps/x86_64/configure.ac
+++ b/sysdeps/x86_64/configure.ac
@@ -76,5 +76,23 @@ EOF
 	       rm -rf conftest*])
 LIBC_CONFIG_VAR([have-mamx-tile], [$libc_cv_x86_have_amx_tile])
 
+# Check if -mapxf is enabled.
+AC_CACHE_CHECK(whether -mapxf is enabled,
+	       libc_cv_x86_have_apx, [dnl
+cat > conftest.c <<EOF
+#ifndef __APX_F__
+# error APX isn't enabled
+#endif
+EOF
+	       libc_cv_x86_have_apx=no
+	       if AC_TRY_COMMAND(${CC-cc} -c $CFLAGS conftest.c -o conftest.o 1>&AS_MESSAGE_LOG_FD); then
+		   libc_cv_x86_have_apx=yes
+	       fi
+	       rm -rf conftest*])
+if test $libc_cv_x86_have_apx = yes; then
+  AC_DEFINE(HAVE_X86_APX)
+fi
+LIBC_CONFIG_VAR([have-x86-apx], [$libc_cv_x86_have_apx])
+
 test -n "$critic_missing" && AC_MSG_ERROR([
 *** $critic_missing])
diff --git a/sysdeps/x86_64/fpu/multiarch/Makefile b/sysdeps/x86_64/fpu/multiarch/Makefile
index 6ddd50240c..cbe09d49f4 100644
--- a/sysdeps/x86_64/fpu/multiarch/Makefile
+++ b/sysdeps/x86_64/fpu/multiarch/Makefile
@@ -38,29 +38,36 @@ libm-sysdep_routines += \
   s_truncf-avx \
 # libm-sysdep_routines
 else
+ifeq (no,$(have-x86-apx))
 libm-sysdep_routines += \
-  e_asin-fma \
   e_asin-fma4 \
+  e_atan2-fma4 \
+  e_exp-fma4 \
+  e_log-fma4 \
+  e_pow-fma4 \
+  s_atan-fma4 \
+  s_sin-fma4 \
+  s_sincos-fma4 \
+  s_tan-fma4 \
+# libm-sysdep_routines
+endif
+libm-sysdep_routines += \
+  e_asin-fma \
   e_atan2-avx \
   e_atan2-fma \
-  e_atan2-fma4 \
   e_exp-avx \
   e_exp-fma \
-  e_exp-fma4 \
   e_exp2f-fma \
   e_expf-fma \
   e_log-avx \
   e_log-fma \
-  e_log-fma4 \
   e_log2-fma \
   e_log2f-fma \
   e_logf-fma \
   e_pow-fma \
-  e_pow-fma4 \
   e_powf-fma \
   s_atan-avx \
   s_atan-fma \
-  s_atan-fma4 \
   s_ceil-sse4_1 \
   s_ceilf-sse4_1 \
   s_cosf-fma \
@@ -77,17 +84,14 @@ libm-sysdep_routines += \
   s_roundevenf-sse4_1 \
   s_sin-avx \
   s_sin-fma \
-  s_sin-fma4 \
   s_sincos-avx \
   s_sincos-fma \
-  s_sincos-fma4 \
   s_sincosf-fma \
   s_sincosf-sse2 \
   s_sinf-fma \
   s_sinf-sse2 \
   s_tan-avx \
   s_tan-fma \
-  s_tan-fma4 \
   s_trunc-sse4_1 \
   s_truncf-sse4_1 \
 # libm-sysdep_routines
diff --git a/sysdeps/x86_64/fpu/multiarch/ifunc-avx-fma4.h b/sysdeps/x86_64/fpu/multiarch/ifunc-avx-fma4.h
index 7719188888..d126cf9cd5 100644
--- a/sysdeps/x86_64/fpu/multiarch/ifunc-avx-fma4.h
+++ b/sysdeps/x86_64/fpu/multiarch/ifunc-avx-fma4.h
@@ -33,8 +33,10 @@ IFUNC_SELECTOR (void)
       && CPU_FEATURE_USABLE_P (cpu_features, AVX2))
     return OPTIMIZE (fma);
 
+#ifndef HAVE_X86_APX
   if (CPU_FEATURE_USABLE_P (cpu_features, FMA4))
     return OPTIMIZE (fma4);
+#endif
 
   if (CPU_FEATURE_USABLE_P (cpu_features, AVX))
     return OPTIMIZE (avx);
diff --git a/sysdeps/x86_64/fpu/multiarch/ifunc-fma4.h b/sysdeps/x86_64/fpu/multiarch/ifunc-fma4.h
index c35ba13845..18d372d25c 100644
--- a/sysdeps/x86_64/fpu/multiarch/ifunc-fma4.h
+++ b/sysdeps/x86_64/fpu/multiarch/ifunc-fma4.h
@@ -32,8 +32,10 @@ IFUNC_SELECTOR (void)
       && CPU_FEATURE_USABLE_P (cpu_features, AVX2))
     return OPTIMIZE (fma);
 
+#ifndef HAVE_X86_APX
   if (CPU_FEATURE_USABLE_P (cpu_features, FMA4))
     return OPTIMIZE (fma4);
+#endif
 
   return OPTIMIZE (sse2);
 }
-- 
2.44.0


             reply	other threads:[~2024-04-04 22:44 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-04-04 22:43 H.J. Lu [this message]
2024-04-05 21:34 ` [PATCH] x86-64: Exclude FMA4 IFUNC functions for -mapxf Sunil Pandey

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/libc/involved.html

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20240404224350.1517977-1-hjl.tools@gmail.com \
    --to=hjl.tools@gmail.com \
    --cc=fweimer@redhat.com \
    --cc=libc-alpha@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).