From patchwork Wed Apr 5 21:01:17 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: 79952 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:6358:3d4a:b0:114:e959:cc0c with SMTP id b10csp621866rwc; Wed, 5 Apr 2023 14:11:25 -0700 (PDT) X-Google-Smtp-Source: AKy350aLOIBMjn3LE3LiZSU+eZScYjwr7r4jtpn+H9JZoJxGfsF7BaJyTGKxmGw7O9ysoYD2gzf9 X-Received: by 2002:a05:6402:654:b0:502:3ff1:2fcc with SMTP id u20-20020a056402065400b005023ff12fccmr3247970edx.35.1680729085283; Wed, 05 Apr 2023 14:11:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680729085; cv=none; d=google.com; s=arc-20160816; b=0OcxubOCtOO1tSY04QIlRyKgmV4SYyFyr0K6kiWfcOt1HvoNJ5kYeDTIqR5VACYyHS APnpav8SgpffXSXmOUQWaeytIUUQ7v5j6z064FdhwiS02JUCsrgMk01GnEHccuwrSfDp ojLLtQDaKSLRu594itP/lJdEhU5Uso12jcxJPAG8PJTXpvMheeQU2iZ7TiyJkAIfrgU4 wMU+3eXvFCLEBJRcG0YI1b7Jn3/veLOkXdLZUjYLqeKAXHUM8zNPqSnoscCerYGONXTt UsQJmLvBzNRYDEd0lmHFAcZSEZO22sMnjGw61sGLM9pN5E8/MbgCPe8bWrEtaPj10uFT Fg4A== 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=XW2DnKFppEkAGSKDM0jdOFHADNtjMIpdUX7VE1gDmF8=; b=qCf7gV5AhiBxhRUClSsP3IQQP6TXRunZ3eKcsR8KHJWjvZApIy3w5ypnJhEWNm1zry Fjsrz/iKduF3HefvJIfYrvejstkRjsHIZlVMNhMYyrxJ4M1c1RLolv7PyT/ZjiIRfZiN 5VY6/V+snAzCI4YOnfbiXMjS3Hns65XvlDrbm50BaUQ2eIeg8rMJ4XxHQqpMvMg2/3Wb YPzGBPdnHPqJ1EG8tso95yR1BaU7/dSfwa7PoSw5brK4FxUbhjrlTwMa0EZPgsj2RAUX cstSJXvlN7c4c28Na7HaDg1A4V1ajmbX7cv3y+sr0n/1un3n8LYBKZsbXww3B4m/jkQb buWQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@rivosinc-com.20210112.gappssmtp.com header.s=20210112 header.b="gmEr/Xww"; 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 m19-20020aa7c2d3000000b004bc4597154dsi1061642edp.397.2023.04.05.14.11.24 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 05 Apr 2023 14:11:25 -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.20210112.gappssmtp.com header.s=20210112 header.b="gmEr/Xww"; 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 1CE1738A90A6 for ; Wed, 5 Apr 2023 21:05:46 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-pj1-x1041.google.com (mail-pj1-x1041.google.com [IPv6:2607:f8b0:4864:20::1041]) by sourceware.org (Postfix) with ESMTPS id F1F033856DD5 for ; Wed, 5 Apr 2023 21:03:07 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org F1F033856DD5 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-pj1-x1041.google.com with SMTP id j13so35295402pjd.1 for ; Wed, 05 Apr 2023 14:03:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20210112.gappssmtp.com; s=20210112; t=1680728587; x=1683320587; 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=XW2DnKFppEkAGSKDM0jdOFHADNtjMIpdUX7VE1gDmF8=; b=gmEr/Xwwpgdicq70GgXexZj2eAm7WCe84g/Oh1CkKX4gzolsHSWiB8/+tgnUj3slQN EvragcKozfNNO2WytIq9XpinigkjiVSSCvo13Y6ulbSRrrH0a/CMjdNJPkapBRUCARp0 ZtMLmSKbxECDBgza6Ns6+wAFpYlJh2HOfr6FQhj3xtpL4VyVgnf3GDGVV7u635YZNukZ e9HU6mq1UBHoHOY5Yo2v1+kOfQqRaI/q7RyVU8dfHMUGTatttmOjE238rt3k1JmzKj7Q mH2Ry0Skn9GtflmItuV5lJhr/sh925b4ZO8zepE9PuuhuId8Jq6njo/wK+FuQW5+zUJa Ekgw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680728587; x=1683320587; 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=XW2DnKFppEkAGSKDM0jdOFHADNtjMIpdUX7VE1gDmF8=; b=fJqEWHsZYfgbNuacbBhYOtcX33Ve/9AOJtibuqrxoub13DqqJq9SnxqZ/v4qaUhe0N qnDI7Dyn6KofgAksVgbHJt132uFxCNyOjWBVRzsVDRfEKoGExXIUCFpIiZr/hmjtGuHh 8BqGsXvnpFe1x1W8IY36G2BzGFOUVCOcM40z8d7LTwUQaf4yuSoxriTA2MHEnQtwCrIz ke0kWJQHj0CJVUMNMr0FYfpzwCdtrauCMEFJtDivjWWHFJQIvsxZt7d5PLrWRINSYw41 ZtKdpRsG8FxVlvJQ/wX8NludKb174NQAVHDwr1etdech7rOC1eYDeq/AlNl8sRBcBhOo 36Tg== X-Gm-Message-State: AAQBX9c67qe3+uGxyS9ncqydVbGi+UG8nIbz781OJu1EcDQkVar9ipL/ lSbrQ9FibHr9ZRKLPdxdhtCmoSKVofJDaIIS9wkxkl1ssvA= X-Received: by 2002:a17:90a:5e4d:b0:23f:e32:7e62 with SMTP id u13-20020a17090a5e4d00b0023f0e327e62mr8473701pji.12.1680728587309; Wed, 05 Apr 2023 14:03:07 -0700 (PDT) Received: from patrick-ThinkPad-X1-Carbon-Gen-8.hq.rivosinc.com ([50.221.140.188]) by smtp.gmail.com with ESMTPSA id e6-20020a17090a77c600b002342ccc8280sm1809477pjs.6.2023.04.05.14.03.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 05 Apr 2023 14:03:07 -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, jeffreyalaw@gmail.com, cmuellner@gcc.gnu.org, andrea@rivosinc.com, Patrick O'Neill Subject: [PATCH v2 7/8] RISCV: Weaken atomic stores Date: Wed, 5 Apr 2023 14:01:17 -0700 Message-Id: <20230405210118.1969283-8-patrick@rivosinc.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230405210118.1969283-1-patrick@rivosinc.com> References: <20220407182918.294892-1-patrick@rivosinc.com> <20230405210118.1969283-1-patrick@rivosinc.com> MIME-Version: 1.0 X-Spam-Status: No, score=-12.1 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 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.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?1762372181166795756?= X-GMAIL-MSGID: =?utf-8?q?1762372181166795756?= This change brings atomic stores in line with table A.6 of the ISA manual. 2023-04-05 Patrick O'Neill PR target/89835 * sync.md (atomic_store): Use simple store instruction in combination with a fence. * pr89835.c: New test. Signed-off-by: Patrick O'Neill --- gcc/config/riscv/sync.md | 17 ++++++++++++----- gcc/testsuite/gcc.target/riscv/pr89835.c | 9 +++++++++ 2 files changed, 21 insertions(+), 5 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 b1a12545a19..cdd227721e1 100644 --- a/gcc/config/riscv/sync.md +++ b/gcc/config/riscv/sync.md @@ -53,17 +53,24 @@ ;; Atomic memory operations. -;; Implement atomic stores with amoswap. Fall back to fences for atomic loads. +;; Implement atomic stores with a leading fence. Fall back to fences for atomic loads. (define_insn "atomic_store" [(set (match_operand:GPR 0 "memory_operand" "=A") (unspec_volatile:GPR [(match_operand:GPR 1 "reg_or_0_operand" "rJ") (match_operand:SI 2 "const_int_operand")] ;; model UNSPEC_ATOMIC_STORE))] - "TARGET_ATOMIC" - "amoswap.%A2 zero,%z1,%0" - [(set_attr "type" "atomic") - (set (attr "length") (const_int 4))]) + "" + { + enum memmodel model = (enum memmodel) INTVAL (operands[2]); + model = memmodel_base (model); + if (model == MEMMODEL_SEQ_CST || model == MEMMODEL_RELEASE) + return "fence\tr,rw\;" + "s\t%z1,%0"; + else + return "s\t%z1,%0\;"; + } + [(set (attr "length") (const_int 8))]) (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); +}