From patchwork Thu Apr 27 16:22:56 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick O'Neill X-Patchwork-Id: 88309 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp388986vqo; Thu, 27 Apr 2023 09:26:33 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6mfr10ssTYCYBLikF3xPYOXkpw/1T4Vvh4/N7v7rEkUpyYZi8NstmG/q3lBtm1Y4rWuFkA X-Received: by 2002:a17:906:eec8:b0:93e:fa12:aa1a with SMTP id wu8-20020a170906eec800b0093efa12aa1amr2756915ejb.1.1682612793018; Thu, 27 Apr 2023 09:26:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1682612793; cv=none; d=google.com; s=arc-20160816; b=gJ8pEhybIwBZ8bltHeRRQnkO2N517t3eOXoK+zInNeOvZd3uaMYCQZbpDe9JWc9X6N tWw4ZsSO7bii17U0cWvgoMWeEp3fIkzDaOF2C5uA0FLk+enP7epVvm65sNh362rFJ3op YgIfkJ5fvby9U3v5YnDSlXuwXVH9/Qj6dn/DR4b8TnfhN6G3U3t3o3AKpP+wpf4orKLX 4Trxaf6wd77ChLRv4ZD04G52o5NYt+pleRideWiqX489avxzzXRE7/TYHFLEJxDVry0R TkLY9gszDc2LqhFYQO3m0sJYdObxq9OGXbncysSqiwDCwNFKfFZT/C2KJztisD2At8uM tpXA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature:dmarc-filter:delivered-to; bh=Fkgy1RpPD1W3gIeYbyfMEFXSyb13FWzwkogasS4gr10=; b=RrmeEebMVsCjeN4ytgKyvEEZjt059ZL7z80wYB9TsHFLFkxRtx36ETOgobyqXIAFKt RGLsAUP/Fs7UfUPpZXBYSIC2h6E5N2R5Yf5Pfwry8V4NSlLDaxoL/L1hS8lagCpLFgp5 iDaMtx1xeozCIGaALxzVlNID7Fn4S3tDa1a0qi/aol4QwrGPPzix+Iok7l9TxKdqfKxp P95hd9UqJj0B+pFAsB2huksPGmNRx40w/lS19tE4grpLI73QwvuoSdPVlFDmsCOBhEw4 rkx3C5DDtgva669BCWHjPZGBqiZ1xNykSoSN+Yr6pTzI4AoEjlbMKE4aC9kg1kpYPT86 RE7w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@rivosinc-com.20221208.gappssmtp.com header.s=20221208 header.b=kOnEh29K; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org" Received: from sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id b6-20020a1709065e4600b0094f5aa89fcdsi14313165eju.39.2023.04.27.09.26.32 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 27 Apr 2023 09:26:33 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; dkim=pass header.i=@rivosinc-com.20221208.gappssmtp.com header.s=20221208 header.b=kOnEh29K; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org" Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id A27AC3850210 for ; Thu, 27 Apr 2023 16:24:45 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-pl1-x644.google.com (mail-pl1-x644.google.com [IPv6:2607:f8b0:4864:20::644]) by sourceware.org (Postfix) with ESMTPS id 7539B385735A for ; Thu, 27 Apr 2023 16:24:18 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 7539B385735A Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=rivosinc.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=rivosinc.com Received: by mail-pl1-x644.google.com with SMTP id d9443c01a7336-1a68d61579bso65780255ad.1 for ; Thu, 27 Apr 2023 09:24:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20221208.gappssmtp.com; s=20221208; t=1682612657; x=1685204657; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=Fkgy1RpPD1W3gIeYbyfMEFXSyb13FWzwkogasS4gr10=; b=kOnEh29KgXdKALWhNxlywil5NdFguC+h9g1WFKJmblDieeRe7VlJJK1NBNlfW7kSW3 DB3hRG1fGDZZdUf1vjUqZxpp5Uqho6ErLwGblYc7c6PtNrWjZzsfgX5ahjuIZFHGFTpl mfFTAHZZa64oqv+PmcR9tODwGzAY8xTqS+Up6BM1H42GQYB1jrHQeg8bL4MmcBzJHWMC XbudEqt6mslAdPc6A3JwGOQriUDIbw7YyaUne7B2xXqOzFfGKYITW4+HoQqWgMUazaoc ybqaaVIpq7/r3dcCewMoqDhSOo3+VHDhENWckWqnXXMWjvhIGKvuArQEkXJdVPEYWx8r SFzg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1682612657; x=1685204657; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Fkgy1RpPD1W3gIeYbyfMEFXSyb13FWzwkogasS4gr10=; b=URx2sKw58hJZ7rOksWerS3ivL5rByFm7N/h4o8Gpl9FMH/4CJaoc3hwslZborZxTMD Ghy5PldsGiA9JW+fnP3FO+8W8xhQJELzbUm5yJQxS/zA1wGY2Xrj6v/nIKHSBUN2P9Z8 2hW0FjDhYkK36q/+kCFGSFtzWPtGfcZaQQM37hmx3pQrv+e/OAO03UiJGwGXPfK6aUWR ac+ZBmgYpVDygRgb0DJ3twiTbnuonnT3Fdld+dqvCPUGEHwAsrH/Ah5pi4+TiU1+2sSy hDYWhb8ALPhepii7IBm3HDmUBae3xHHLwHn9HLPQowL7wTQVJzP3JE32DHxJaTgnhKCW AbqA== X-Gm-Message-State: AC+VfDzAu1kUIEeeAbC+U7J/Itoc44TFAgDLn2mpYlD4yivG9n4elKDB KjQv3pPMnIr+I3ThvH3ycQBUAn1JAglutKqxMch21vSOHTA= X-Received: by 2002:a17:902:f684:b0:1a9:20d6:3c3f with SMTP id l4-20020a170902f68400b001a920d63c3fmr2296358plg.55.1682612657393; Thu, 27 Apr 2023 09:24:17 -0700 (PDT) Received: from patrick-ThinkPad-X1-Carbon-Gen-8.hq.rivosinc.com ([50.221.140.188]) by smtp.gmail.com with ESMTPSA id n19-20020a170902969300b001a6db2bef16sm11815906plp.303.2023.04.27.09.24.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 27 Apr 2023 09:24:17 -0700 (PDT) From: Patrick O'Neill To: gcc-patches@gcc.gnu.org Cc: palmer@rivosinc.com, gnu-toolchain@rivosinc.com, vineetg@rivosinc.com, andrew@sifive.com, kito.cheng@sifive.com, dlustig@nvidia.com, cmuellner@gcc.gnu.org, andrea@rivosinc.com, hboehm@google.com, jeffreyalaw@gmail.com, Patrick O'Neill Subject: [PATCH v5 06/11] RISC-V: Strengthen atomic stores Date: Thu, 27 Apr 2023 09:22:56 -0700 Message-Id: <20230427162301.1151333-7-patrick@rivosinc.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230427162301.1151333-1-patrick@rivosinc.com> References: <20230414170942.1695672-1-patrick@rivosinc.com> <20230427162301.1151333-1-patrick@rivosinc.com> MIME-Version: 1.0 X-Spam-Status: No, score=-12.8 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, GIT_PATCH_0, KAM_SHORT, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE autolearn=unavailable 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.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1764347392008617221?= X-GMAIL-MSGID: =?utf-8?q?1764347392008617221?= This change makes atomic stores strictly stronger than table A.6 of the ISA manual. This mapping makes the overall patchset compatible with table A.7 as well. 2023-04-27 Patrick O'Neill PR 89835 gcc/ChangeLog: * config/riscv/sync.md: gcc/testsuite/ChangeLog: * gcc.target/riscv/pr89835.c: New test. Signed-off-by: Patrick O'Neill --- gcc/config/riscv/sync.md | 21 ++++++++++++++++++--- gcc/testsuite/gcc.target/riscv/pr89835.c | 9 +++++++++ 2 files changed, 27 insertions(+), 3 deletions(-) create mode 100644 gcc/testsuite/gcc.target/riscv/pr89835.c diff --git a/gcc/config/riscv/sync.md b/gcc/config/riscv/sync.md index 5620d6ffa58..1acb78a9ae4 100644 --- a/gcc/config/riscv/sync.md +++ b/gcc/config/riscv/sync.md @@ -56,7 +56,9 @@ ;; Atomic memory operations. -;; Implement atomic stores with amoswap. Fall back to fences for atomic loads. +;; Implement atomic stores with conservative fences. Fall back to fences for +;; atomic loads. +;; This allows us to be compatible with the ISA manual Table A.6 and Table A.7. (define_insn "atomic_store" [(set (match_operand:GPR 0 "memory_operand" "=A") (unspec_volatile:GPR @@ -64,9 +66,22 @@ (match_operand:SI 2 "const_int_operand")] ;; model UNSPEC_ATOMIC_STORE))] "TARGET_ATOMIC" - "%F2amoswap.%A2 zero,%z1,%0" + { + enum memmodel model = (enum memmodel) INTVAL (operands[2]); + model = memmodel_base (model); + + if (model == MEMMODEL_SEQ_CST) + return "fence\trw,w\;" + "s\t%z1,%0\;" + "fence\trw,rw"; + if (model == MEMMODEL_RELEASE) + return "fence\trw,w\;" + "s\t%z1,%0"; + else + return "s\t%z1,%0"; + } [(set_attr "type" "atomic") - (set (attr "length") (const_int 8))]) + (set (attr "length") (const_int 12))]) (define_insn "atomic_" [(set (match_operand:GPR 0 "memory_operand" "+A") diff --git a/gcc/testsuite/gcc.target/riscv/pr89835.c b/gcc/testsuite/gcc.target/riscv/pr89835.c new file mode 100644 index 00000000000..ab190e11b60 --- /dev/null +++ b/gcc/testsuite/gcc.target/riscv/pr89835.c @@ -0,0 +1,9 @@ +/* { dg-do compile } */ +/* Verify that relaxed atomic stores use simple store instuctions. */ +/* { dg-final { scan-assembler-not "amoswap" } } */ + +void +foo(int bar, int baz) +{ + __atomic_store_n(&bar, baz, __ATOMIC_RELAXED); +}