From patchwork Mon Jun 17 16:51:04 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick O'Neill X-Patchwork-Id: 1948713 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=rivosinc-com.20230601.gappssmtp.com header.i=@rivosinc-com.20230601.gappssmtp.com header.a=rsa-sha256 header.s=20230601 header.b=idVW0ccF; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=8.43.85.97; helo=server2.sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=patchwork.ozlabs.org) Received: from server2.sourceware.org (server2.sourceware.org [8.43.85.97]) (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 4W2wrx13K3z20Ws for ; Tue, 18 Jun 2024 02:51:42 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 590D13858CDA for ; Mon, 17 Jun 2024 16:51:39 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-pl1-x631.google.com (mail-pl1-x631.google.com [IPv6:2607:f8b0:4864:20::631]) by sourceware.org (Postfix) with ESMTPS id 190313881874 for ; Mon, 17 Jun 2024 16:51:14 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 190313881874 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=rivosinc.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=rivosinc.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 190313881874 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::631 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1718643076; cv=none; b=cNXj+FVAzI/pzDyYG1kVeHcgKeWRsAiPVm5hazheu+vJ37duhrCSsDYVkYPJyT2I/hvXLZJ5lJL8daAwKZXpX7jjHyvOOxH1m1MDWa5B9W7zpnFyx76k5C521J7o96+LwApaCCcxgWSYccdJg70uXhhqjECWXT7Iqo12M/WHQxo= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1718643076; c=relaxed/simple; bh=mlqj+wxt5xI9iqQx02LCxM2aSMjKh6Yf0m57hgS1WzA=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=gBpPsbysqG9NzSLxIprH+fcIuv/wJ+NLHp3CbYGbiRv9Gj4jaUgmAxt9HKov98DFoEVwHRYOT60qHFXP/9IUZ/ROlbyRK6XLfnp+GGNf7hxjxyD3Z4+1scqIntiyBSdR2YfTnCgIjuYOs0yPoL/Pb6ePxmvg1/VOsbzAtNGfsAw= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-pl1-x631.google.com with SMTP id d9443c01a7336-1f4c7b022f8so39944215ad.1 for ; Mon, 17 Jun 2024 09:51:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1718643072; x=1719247872; darn=gcc.gnu.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=cYesb/Xh4zwSRiyOF5kIczW44u1PIk7SqJUqtEkad+Y=; b=idVW0ccFTLA1kQFodqi7oQ4NIwTonvRvvehG0KT0/NfEiKr09lY+jvVeoM+exTnSvR UHNlOF0nJMraPweAuaMRz4pNyT6aMrV86BmuzYrayq6za4sqi7/GmQMRiadNwNzsBG+u R0iJDHeXLgkSKJlQQ25x0MRHYStEnr+49DgjTGhy7jybL6ckQS8fXryZ2rKhWv6u82Nm lc9AGSKgAkQGhqxuGuj8FQnZaNmcXR/oa14oZe3DrtMC/lUHtWv/dqXTMomxFT50bM4D N2ajPTdE2BceJf9R1IwJeyIERoMcjXBWVUXZ10cCaJ5pOVX9aqQqvUhmP8g6//LNVLED iHkw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718643072; x=1719247872; 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=cYesb/Xh4zwSRiyOF5kIczW44u1PIk7SqJUqtEkad+Y=; b=kewfkiaJ0b3T3ws70BtKiTrr/dXd9HwiSLggleiiGqdJzrybPaAtCz9EfFKhyHeeDZ wy3eTzuH03ig3jkak/LU5nqh91/P4sNfCuFX8gCnxHK8+VFEB92CWTRgztz5l0Q1GlRD aDHEiyNEXE6Ct+7cmmZQDQuBzeuKvKo+Sod2hZkozNexRB8vu1e26g2gDwO9lv9wMnwR 8g+o507yovpBhyMgy5WjBg2WavMNiR8y281FRPzuyWQ5BRYDccQ+8snLH9sznqRtWkln sWyW1RCiPhviHV3FXpMxJ+y9x44O45FmRyDsJpDeG6nXVSO3WpwXEddMHqq2mIZbywLB 92GQ== X-Gm-Message-State: AOJu0YzlhtOwsWG72g+cjqHywsjLUmYDVlpMVwTJ+DEVpqDm5BITcgwU 4UN3WkMqcpgz9GtqBmOrK6H9QA5DS7kR7jAqJSCwcva3xeGYaeiUpc4KZEsbsD/ZdOXpv8D46RH U X-Google-Smtp-Source: AGHT+IH/X6AIuUwf3NeDobgS/FI3YsEDY7wm/aHX0f1yiub7YQOCKbVtdiQrl8sqOm0MJdE0Hua0IA== X-Received: by 2002:a17:903:234d:b0:1f7:126:5bab with SMTP id d9443c01a7336-1f8627f7133mr134656045ad.40.1718643072477; Mon, 17 Jun 2024 09:51:12 -0700 (PDT) Received: from patrick-ThinkPad-X1-Carbon-Gen-8.hq.rivosinc.com ([50.145.13.30]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-1f855ee9e3csm81499395ad.169.2024.06.17.09.51.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 17 Jun 2024 09:51:12 -0700 (PDT) From: Patrick O'Neill To: gcc-patches@gcc.gnu.org Cc: jeffreyalaw@gmail.com, Patrick O'Neill , Palmer Dabbelt Subject: [Committed] RISC-V: Add configure check for Zaamo/Zalrsc assembler support Date: Mon, 17 Jun 2024 09:51:04 -0700 Message-ID: <20240617165104.2529830-1-patrick@rivosinc.com> X-Mailer: git-send-email 2.43.2 MIME-Version: 1.0 X-Spam-Status: No, score=-11.5 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE 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: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org Binutils 2.42 and before don't support Zaamo/Zalrsc. Add a configure check to prevent emitting Zaamo/Zalrsc in the arch string when the assember does not support it. gcc/ChangeLog: * common/config/riscv/riscv-common.cc (riscv_subset_list::to_string): Skip zaamo/zalrsc when not supported by the assembler. * config.in: Regenerate. * configure: Regenerate. * configure.ac: Add zaamo/zalrsc assmeber check. Signed-off-by: Patrick O'Neill Acked-by: Palmer Dabbelt # RISC-V Reviewed-by: Palmer Dabbelt # RISC-V --- Tested using newlib rv64gc with binutils tip-of-tree and 2.42. This results in calls being emitted when compiling for _zaamo_zalrsc when the assember does not support these extensions. > cat amo.c void foo (int* bar, int* baz) { __atomic_add_fetch(bar, baz, __ATOMIC_RELAXED); } > gcc -march=rv64id_zaamo_zalrsc -O3 amo.c results in: foo: sext.w a1,a1 li a2,0 tail __atomic_fetch_add_4 As a result there are some testsuite failures on zalrsc specific testcases and when using an old version of binutils on non-a targets. Not a cause for concern imo but worth calling out. Also testcases that check for the default isa string will fail with the old binutils since zaamo/zalrsc aren't emitted anymore. --- gcc/common/config/riscv/riscv-common.cc | 11 +++++++++ gcc/config.in | 6 +++++ gcc/configure | 31 +++++++++++++++++++++++++ gcc/configure.ac | 5 ++++ 4 files changed, 53 insertions(+) diff --git a/gcc/common/config/riscv/riscv-common.cc b/gcc/common/config/riscv/riscv-common.cc index 78dfd6b1470..1dc1d9904c7 100644 --- a/gcc/common/config/riscv/riscv-common.cc +++ b/gcc/common/config/riscv/riscv-common.cc @@ -916,6 +916,7 @@ riscv_subset_list::to_string (bool version_p) const riscv_subset_t *subset; bool skip_zifencei = false; + bool skip_zaamo_zalrsc = false; bool skip_zicsr = false; bool i2p0 = false; @@ -943,6 +944,10 @@ riscv_subset_list::to_string (bool version_p) const a mistake in that binutils 2.35 supports zicsr but not zifencei. */ skip_zifencei = true; #endif +#ifndef HAVE_AS_MARCH_ZAAMO_ZALRSC + /* Skip since binutils 2.42 and earlier don't recognize zaamo/zalrsc. */ + skip_zaamo_zalrsc = true; +#endif for (subset = m_head; subset != NULL; subset = subset->next) { @@ -954,6 +959,12 @@ riscv_subset_list::to_string (bool version_p) const subset->name == "zicsr") continue; + if (skip_zaamo_zalrsc && subset->name == "zaamo") + continue; + + if (skip_zaamo_zalrsc && subset->name == "zalrsc") + continue; + /* For !version_p, we only separate extension with underline for multi-letter extension. */ if (!first && diff --git a/gcc/config.in b/gcc/config.in index e41b6dc97cd..acab3c0f126 100644 --- a/gcc/config.in +++ b/gcc/config.in @@ -629,6 +629,12 @@ #endif +/* Define if the assembler understands -march=rv*_zaamo_zalrsc. */ +#ifndef USED_FOR_TARGET +#undef HAVE_AS_MARCH_ZAAMO_ZALRSC +#endif + + /* Define if the assembler understands -march=rv*_zifencei. */ #ifndef USED_FOR_TARGET #undef HAVE_AS_MARCH_ZIFENCEI diff --git a/gcc/configure b/gcc/configure index 94970e24051..9dc0b65dfaa 100755 --- a/gcc/configure +++ b/gcc/configure @@ -30820,6 +30820,37 @@ if test $gcc_cv_as_riscv_march_zifencei = yes; then $as_echo "#define HAVE_AS_MARCH_ZIFENCEI 1" >>confdefs.h +fi + + { $as_echo "$as_me:${as_lineno-$LINENO}: checking assembler for -march=rv32i_zaamo_zalrsc support" >&5 +$as_echo_n "checking assembler for -march=rv32i_zaamo_zalrsc support... " >&6; } +if ${gcc_cv_as_riscv_march_zaamo_zalrsc+:} false; then : + $as_echo_n "(cached) " >&6 +else + gcc_cv_as_riscv_march_zaamo_zalrsc=no + if test x$gcc_cv_as != x; then + $as_echo '' > conftest.s + if { ac_try='$gcc_cv_as $gcc_cv_as_flags -march=rv32i_zaamo_zalrsc -o conftest.o conftest.s >&5' + { { eval echo "\"\$as_me\":${as_lineno-$LINENO}: \"$ac_try\""; } >&5 + (eval $ac_try) 2>&5 + ac_status=$? + $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 + test $ac_status = 0; }; } + then + gcc_cv_as_riscv_march_zaamo_zalrsc=yes + else + echo "configure: failed program was" >&5 + cat conftest.s >&5 + fi + rm -f conftest.o conftest.s + fi +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $gcc_cv_as_riscv_march_zaamo_zalrsc" >&5 +$as_echo "$gcc_cv_as_riscv_march_zaamo_zalrsc" >&6; } +if test $gcc_cv_as_riscv_march_zaamo_zalrsc = yes; then + +$as_echo "#define HAVE_AS_MARCH_ZAAMO_ZALRSC 1" >>confdefs.h + fi ;; diff --git a/gcc/configure.ac b/gcc/configure.ac index 35475cf5aae..b2243e9954a 100644 --- a/gcc/configure.ac +++ b/gcc/configure.ac @@ -5452,6 +5452,11 @@ configured with --enable-newlib-nano-formatted-io.]) [-march=rv32i_zifencei2p0],,, [AC_DEFINE(HAVE_AS_MARCH_ZIFENCEI, 1, [Define if the assembler understands -march=rv*_zifencei.])]) + gcc_GAS_CHECK_FEATURE([-march=rv32i_zaamo_zalrsc support], + gcc_cv_as_riscv_march_zaamo_zalrsc, + [-march=rv32i_zaamo_zalrsc],,, + [AC_DEFINE(HAVE_AS_MARCH_ZAAMO_ZALRSC, 1, + [Define if the assembler understands -march=rv*_zaamo_zalrsc.])]) ;; loongarch*-*-*) gcc_GAS_CHECK_FEATURE([.dtprelword support],