From patchwork Thu Apr 4 22:43:50 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "H.J. Lu" X-Patchwork-Id: 1919976 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=cThRDt8w; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=sourceware.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=server2.sourceware.org; envelope-from=libc-alpha-bounces+incoming=patchwork.ozlabs.org@sourceware.org; receiver=patchwork.ozlabs.org) Received: from server2.sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4V9c9n0DXnz1yYf for ; Fri, 5 Apr 2024 09:44:12 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 7257F3858C33 for ; Thu, 4 Apr 2024 22:44:10 +0000 (GMT) X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-pl1-x633.google.com (mail-pl1-x633.google.com [IPv6:2607:f8b0:4864:20::633]) by sourceware.org (Postfix) with ESMTPS id 5FF1F3858C98 for ; Thu, 4 Apr 2024 22:43:53 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 5FF1F3858C98 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 5FF1F3858C98 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::633 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1712270636; cv=none; b=fI+2njVYrQlO7OHjxlCY8ZeYazTc7guHUZNM087DuF84lmQOv89AzCS5aYv60DfucqreJDX3SuZPjWWtvs4K72DqoqVKehXabgblFr+IrGjsOgecf89YC/cQz4MlhygeARmyA2+4gA2I2gZNWZ1M4fnqhsYcnlynub5PYJncZ7E= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1712270636; c=relaxed/simple; bh=ZIWgG1uycsOkElwmlgGIorb0XesWefH0QaBljzMmFtk=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=dKRgeoMXyk9A0MKaRuaNxZPgPV0TDHmnTa7XoYfo+uAY/TXoyjs6ADpd6xKPSSq5w3khDOUpWzBDUg3TQdm3FTuil5fF0cYPC6P7SwYmH1Vdh5p/+RbcyunF2oej3/EPXsu1EwZsyo1s+JRM+J9TztOJAEUVBi/U2ZsfvQEXEao= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-pl1-x633.google.com with SMTP id d9443c01a7336-1def89f0cfdso20367815ad.0 for ; Thu, 04 Apr 2024 15:43:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1712270632; x=1712875432; darn=sourceware.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=pEk1YPK/XT9+TaWwl/zNk6/W0Jilk8UHE37GQ8zo4KE=; b=cThRDt8w7BKi4AC18eJYcobUnRBpRJvyXh4WrMjU6WRgzgtl9hrEvRxowo4tlPEaQA lPQ4rdB2YEIjcvAiTYFAX9pVZv5x9P2+PN5GpzM/FfM4CFKqSeSTk8Ck5ZhWtR+oUDt0 dXW7ecoBFILRUa3Gr35pYC9YZO09AoC3IB5qDmhWnsNAOTBE8Bmjkcc74TadvGyE9zSn xDzeU1GGm4N49U1QtnxBURlBfF6enrVpbHz43e3f2V2p88cWTaEedTltiyKDhZZJAjh2 +CoEkUjsY/bWBOqWyzCmlYNTJLQKG5ouBmtC2XUT7HTo+OO+m4v180B8MCzpEQConxt5 iMmA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1712270632; x=1712875432; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=pEk1YPK/XT9+TaWwl/zNk6/W0Jilk8UHE37GQ8zo4KE=; b=eJhqys3CAp8IKueJMGg1nW3ejwcSF4+jLAHlzWFp7VEJnH0M9HxlCZIFDm6oTo9UFJ u8/q1HMrCHzaFQUoYozQapVUBoyH5xIpoejybKznx9XMVK0wXgRgR0qcdUQMORRP9ajK g+SGdbdO1EIlfNyLqgoOEe5/KtqRUhM2Su0YF2LHoQ+RX4xfN0T00hp5p5hFNUTG9NEg x38sk+H7ALSjCth+icrJB3lXM3Y9iZHd9dsXk2+aYUlrKFzN9p+aaBtjV+lvONs9Kj0v F5F97yPoNXOGf0Op6A4u8vtu3z5dwGTwQKWCQYanOt2v7Krb5TjR8O3yr5G1ygNqc32N ongA== X-Gm-Message-State: AOJu0YxpCjOUMevsqzbxahM513BV7mOvSkykpITYXLmg46DLnf9K52de HSKvMpX9KPnSp4gKGPp0/6+rBQ8IxWoNZIXdpfMx3T3vrsZVDJzF+4cMNguY X-Google-Smtp-Source: AGHT+IHNtG46s2ZExWwI1B1iY4Uh+JRSqhHP+V8I8jiaDwtDhUarlsEPtvM//k6PdZinvSaeml//MA== X-Received: by 2002:a17:902:650e:b0:1dd:8ed0:59d0 with SMTP id b14-20020a170902650e00b001dd8ed059d0mr794629plk.17.1712270632277; Thu, 04 Apr 2024 15:43:52 -0700 (PDT) Received: from gnu-cfl-3.localdomain ([172.56.169.48]) by smtp.gmail.com with ESMTPSA id x5-20020a170902ec8500b001e0eaf9ac5dsm151036plg.36.2024.04.04.15.43.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 04 Apr 2024 15:43:51 -0700 (PDT) Received: from gnu-cfl-3.. (localhost [IPv6:::1]) by gnu-cfl-3.localdomain (Postfix) with ESMTP id D7F3D74019D; Thu, 4 Apr 2024 15:43:50 -0700 (PDT) From: "H.J. Lu" 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 Message-ID: <20240404224350.1517977-1-hjl.tools@gmail.com> X-Mailer: git-send-email 2.44.0 MIME-Version: 1.0 X-Spam-Status: No, score=-3018.7 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, GIT_PATCH_0, RCVD_IN_ABUSEAT, RCVD_IN_DNSWL_NONE, RCVD_IN_SBL_CSS, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libc-alpha-bounces+incoming=patchwork.ozlabs.org@sourceware.org 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 Reviewed-by: Sunil K Pandey --- 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 <&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 <&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); }