From patchwork Tue Jul 25 18:01:58 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: 125748 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:9010:0:b0:3e4:2afc:c1 with SMTP id l16csp2644505vqg; Tue, 25 Jul 2023 11:05:36 -0700 (PDT) X-Google-Smtp-Source: APBJJlGvNGPUXWgcq398RDD+ObDG3X4/a0AS0okhUHQQAugvTiN1PG4/hCikB8TzlUXHeJZg7l/a X-Received: by 2002:a19:8c18:0:b0:4fe:958:88b0 with SMTP id o24-20020a198c18000000b004fe095888b0mr1507880lfd.8.1690308336314; Tue, 25 Jul 2023 11:05:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1690308336; cv=none; d=google.com; s=arc-20160816; b=NLVTxBeY20vne0lqGzBls3f3YV21VoCyDAW9psvYQwYJnfJDCk6absVrQ2cx44oz+1 KqSgA7DDa58jHdtBHW71Q3z4wamtsjQj3oOzu+ypJL+BdrzXPloQX2zdT5UjSctZKrgu BOm3JNH+trEJojZkOXoiaE3OnfbV2wfDVaPx9G5GNJONN8AG8cGKFNrSBtfj14ecI45i igoKYGKg2niywEw5Oaw5l1fqduLHMT6OeucpoV7fUHKQbFwkj6pWeUknX158gUs7LBfm QmlYGmGsSU5mlLHatogQ5WFWU72Amk6SzH7XteDkrs1D4NYDVGfq+oBQLdCOyVY2+d7O vcHA== 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=2ofWdQcfFFSIK74wTHfEqMvNNNb4MOojcPqR6fZeLpo=; fh=V424RJoyJREbwuNhiT0eP2mcXvcQgx7dP1gyRHYYn6Q=; b=nsJld4gbx9oEKumI2KNDZYhbZE5SQxAm5OGPXNw1GknrrYX0sZlFdYt0IEBWrZZ0W6 kfbyoqLt8llkvevq1SUKcJ3E6qG6s6tUXSDod484qCLGIhglkCVTayt1xNeIrSyvox1k YIGq7hVQejK7N0NOp9t8+NvLMTbP4BIyGxjb3j/jDhmSrw3XnTVz4aFc51hjYpXQpGlx ig9Toh0pwaUV39Fy7VGeeJ9o4P0x4n0xXBK4uQRQiKYe0ON9jC0FdTQdR9JQho2ejXgT 5vfuyY0Ql/RgRG5yeht00Ux6fWTYPuJ/X+wPdlku+BwNTNNjiBu/cRN9foKIXAbzVEfn 9FGg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@rivosinc-com.20221208.gappssmtp.com header.s=20221208 header.b=zxbvVW0W; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org" Received: from server2.sourceware.org (ip-8-43-85-97.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id t5-20020aa7d4c5000000b0051de55a2392si2885744edr.505.2023.07.25.11.05.36 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 25 Jul 2023 11:05:36 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@rivosinc-com.20221208.gappssmtp.com header.s=20221208 header.b=zxbvVW0W; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 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 8AA2C3896C35 for ; Tue, 25 Jul 2023 18:03:27 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-pl1-x634.google.com (mail-pl1-x634.google.com [IPv6:2607:f8b0:4864:20::634]) by sourceware.org (Postfix) with ESMTPS id B5382385C6E7 for ; Tue, 25 Jul 2023 18:02:30 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org B5382385C6E7 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-x634.google.com with SMTP id d9443c01a7336-1bbc87ded50so2043775ad.1 for ; Tue, 25 Jul 2023 11:02:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20221208.gappssmtp.com; s=20221208; t=1690308149; x=1690912949; 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=2ofWdQcfFFSIK74wTHfEqMvNNNb4MOojcPqR6fZeLpo=; b=zxbvVW0WskDjXMdx6QWbkXnSm//tyfSbT/IPWpqYgYEqNUw5LYr1nuIXRdlupVI04F R5WW3jgTiJNq3tftcwGxRpVSfW9KvuY40k9p2NIEbarZsBwzHbHRWy56dphEuvW5YERZ FDHYSex1BW/xfftVmp8G63Oz5PVH2AKSdqn+H+JBKY3Y9jToczEGHB6QEFwb+4dUevlQ 94P4MAE8GMeRRharQfKNW/Qf5OJrCx5lkBnK2GuF2PQJN+5D/+AWovCZWobtFS+sBhgl zSOt8D+W4RX/nKwsvMtjA6o8iRm86zUXZ5PU8GMERD5Es3SzDz6t4qO0rYP8wTTDBv9E 02bw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1690308149; x=1690912949; 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=2ofWdQcfFFSIK74wTHfEqMvNNNb4MOojcPqR6fZeLpo=; b=fYNjoX6qDVsIvjTooNnpoXSuW2BhejFB6l/Qn6AWMKds4x8khkpAWtgqlPoMAdtqCC saazwuoTpdDnZ9QgRZXJreGYF+c30gFAvk76I+upMqWGPNe60KNESZeDV6dXIwmdGkGp Z+mzLTDwBMk/8y9f42kkJl0fMoBTo3BHkGwKQq2/Sx8Zq5BJD7zkMeUxORpKzZ63cfO/ 3lnf0XC0wKAh1AsgHnWgg1T9g46FdOEVzOYdr1n5ltFrB+jIIq2HS+5R/a9JktEhr3ZC IbzQeJ0cq/i7sTHF9LmnJQvfp1P+htANXGsCp0Wox6erWlbQXyQnId2yMDX7kmN5MOtb +Wyw== X-Gm-Message-State: ABy/qLYKcUmNF/sR5NEqjt2owCSGiJ23yzrgimbp6SAYcRUG5LlROEuy w6jOIVlMxVFVgsV5e+amXUuuK+6alitLnMSZGIQ= X-Received: by 2002:a17:903:244a:b0:1b8:847d:973a with SMTP id l10-20020a170903244a00b001b8847d973amr14487910pls.46.1690308149162; Tue, 25 Jul 2023 11:02:29 -0700 (PDT) Received: from patrick-ThinkPad-X1-Carbon-Gen-8.hq.rivosinc.com ([50.221.140.188]) by smtp.gmail.com with ESMTPSA id p1-20020a1709028a8100b001b3ce619e2esm11283352plo.179.2023.07.25.11.02.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 25 Jul 2023 11:02:28 -0700 (PDT) From: Patrick O'Neill To: gcc-patches@gcc.gnu.org Cc: jeffreyalaw@gmail.com, palmer@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, Patrick O'Neill Subject: [gcc13 backport 04/12] RISC-V: Enforce atomic compare_exchange SEQ_CST Date: Tue, 25 Jul 2023 11:01:58 -0700 Message-Id: <20230725180206.284777-5-patrick@rivosinc.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230725180206.284777-1-patrick@rivosinc.com> References: <20230427162301.1151333-1-patrick@rivosinc.com> <20230725180206.284777-1-patrick@rivosinc.com> MIME-Version: 1.0 X-Spam-Status: No, score=-13.2 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: INBOX X-GMAIL-THRID: 1764347393674991321 X-GMAIL-MSGID: 1772416753966050996 This patch enforces SEQ_CST for atomic compare_exchange ops. Replace Fence/LR.aq/SC.aq pairs with SEQ_CST LR.aqrl/SC.rl pairs recommended by table A.6 of the ISA manual. 2023-04-27 Patrick O'Neill gcc/ChangeLog: * config/riscv/sync.md (atomic_cas_value_strong): Change FENCE/LR.aq/SC.aq into sequentially consistent LR.aqrl/SC.rl pair. Signed-off-by: Patrick O'Neill --- gcc/config/riscv/sync.md | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/gcc/config/riscv/sync.md b/gcc/config/riscv/sync.md index 0c83ef04607..5620d6ffa58 100644 --- a/gcc/config/riscv/sync.md +++ b/gcc/config/riscv/sync.md @@ -297,9 +297,16 @@ UNSPEC_COMPARE_AND_SWAP)) (clobber (match_scratch:GPR 6 "=&r"))] "TARGET_ATOMIC" - "%F5 1: lr.%A5 %0,%1; bne %0,%z2,1f; sc.%A4 %6,%z3,%1; bnez %6,1b; 1:" + { + return "1:\;" + "lr..aqrl\t%0,%1\;" + "bne\t%0,%z2,1f\;" + "sc..rl\t%6,%z3,%1\;" + "bnez\t%6,1b\;" + "1:"; + } [(set_attr "type" "atomic") - (set (attr "length") (const_int 20))]) + (set (attr "length") (const_int 16))]) (define_expand "atomic_compare_and_swap" [(match_operand:SI 0 "register_operand" "") ;; bool output