Message ID | 20230405210118.1969283-1-patrick@rivosinc.com |
---|---|
Headers |
Return-Path: <gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp588971vqo; Wed, 5 Apr 2023 14:04:44 -0700 (PDT) X-Google-Smtp-Source: AKy350bPjed6eqRJDW1FeLOY2UZuDBsmavZhaBjUtyuA6q+SsIRHTiRyY8mas1So5/eri5AndCnq X-Received: by 2002:a17:906:2a14:b0:92e:c4c9:7a43 with SMTP id j20-20020a1709062a1400b0092ec4c97a43mr3892594eje.25.1680728684535; Wed, 05 Apr 2023 14:04:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680728684; cv=none; d=google.com; s=arc-20160816; b=eYV23FjWp1D+oqBDkB1IOmfYnKO/zbFRMnxpGIG7CRs6uvlL54A2RGZZg3hzMVVxzE 8vvpvZIrYZFqJHs2SiBOK7IZoN3RzfiF94RJ+NrfdMyTkDylqArnEfsy5kboQen53DeO QzxRtTCPhFpzBeQkOzXYdyD6Geke1unjfSbgQTNcP7VRJc9LigWM1xTxv47sjQzmXt+8 FJaErvry5soLoV3tq+qkpK1vPAsDmS5asdb4l6GvsPKA06Owrt5q5HBLOW2Y9DNY+gqS OBAZtxCsxWxM2fC1U8C080nJ+xcAqfY5B/jF9oFqDhIN/baqb9jh/I2O7oHCD7+tDz6x NExQ== 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=0WR+kPhXlLSdTZPtK111vJky5UhaQcFD99YymCBb5Dk=; b=qPxD8tttCw93WCNiZCzBh+UykEXrnR11TX8/jzOOrkdFfGRG3fDRruGsFA3D0VCFWC s7sBavhlZb0hGwsRLwHcSsfEQo+E4IX31vxCGJQ2yLsSh/wQVYlus2YmWMJiqLLZ3RzG FOjk+Gk4vCs4Mgswi7pOwYxlpUDD0vWjo4xew1Se2sjgCp4Ra5VscgGbXnBH/oZb6OlH 6JX6T2YfKbBGXiPSp9mGlOCPavhpjOgqv9CJqbn275onZKzGGM8Gh+fzIyKjNSWZUh4t YszLSS2xg9PxOzmYnPMMWbTAnIKKQMnfHvaCuCMLjHvgZmw6KDYNRHxQpdCT6iritzhF zzUQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@rivosinc-com.20210112.gappssmtp.com header.s=20210112 header.b="FVoqVk/5"; 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 sourceware.org (server2.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id h18-20020a170906719200b009476ce976a3si918060ejk.130.2023.04.05.14.04.44 for <ouuuleilei@gmail.com> (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 05 Apr 2023 14:04:44 -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.20210112.gappssmtp.com header.s=20210112 header.b="FVoqVk/5"; 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 855CE385041E for <ouuuleilei@gmail.com>; Wed, 5 Apr 2023 21:03:30 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-pj1-x1043.google.com (mail-pj1-x1043.google.com [IPv6:2607:f8b0:4864:20::1043]) by sourceware.org (Postfix) with ESMTPS id 6295E3858439 for <gcc-patches@gcc.gnu.org>; Wed, 5 Apr 2023 21:03:00 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 6295E3858439 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-x1043.google.com with SMTP id gp15-20020a17090adf0f00b0023d1bbd9f9eso40861551pjb.0 for <gcc-patches@gcc.gnu.org>; Wed, 05 Apr 2023 14:03:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20210112.gappssmtp.com; s=20210112; t=1680728579; x=1683320579; 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=0WR+kPhXlLSdTZPtK111vJky5UhaQcFD99YymCBb5Dk=; b=FVoqVk/5AxaUYqs8Nmj7PJI7YlMLfUUllJIKkLhGA6I26gNWeWowv4P2cXhUGNE85h HIdww3345Ys+o70wD0oqb0Emvkj2icXCoU1MGEmRjVwWsGGvtXuDMR5g2Qa4txI8F3g/ eAg7auGZk3az4nmrDH+yt2X4KpEjrZezAxZ43IF+S7lEVWbu6BaF2SfpElCn8RinjTvZ JiKwbe4IcbwkDozgvGLEzj7XcmE0MGOdvXvCVa9g0v0ViSj6cO59wraE0lbir9si38ul +s99bDunz7uB67RwmZtaDzv2rn+kxl5DcAzglv1zu/PAWfMxIRIDCUSB5iRSzrY50t3q 295g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680728579; x=1683320579; 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=0WR+kPhXlLSdTZPtK111vJky5UhaQcFD99YymCBb5Dk=; b=hTEuuenZKSr5eZ1Iq2VEqIiwfiNpWYTqSnNPmZ5e6b/5+LnwN4CK0BvgSrqQjmL1v6 NuZlke4sdpIeJAveAJrTEa7+OqgXnjtvW0GWxPQF6qRjkYFzGHG54sjcttoWJ6kHxlC3 Q7cHDUkmZWZrCkJJ2RZNOPdxa82xGgS0bTCqycOHebmnFhBXT9OJu2aZIR5qPF2ESFoR sc4zYP+A0H/Fm23+2/uOjahyvOMPp9eCHfFxe9D00/DV8DiXoc6FCChWpGZj7s9VqhHn 8YY1hhyCm0iulPTJbXVvxRBL6qVYRVgET1aJOZsz0pnMfBXWoFt0Zd6JlJ4TabYRvyZr Pi/Q== X-Gm-Message-State: AAQBX9ep90WdVzuxTlJpGsfAGoUf9SDPB5A+wehbby9g/KClGYEK8puu yD5c/uRlKztTFXYq4NTyNMePPRxrA/sNXHoU0C0e6QokDEI= X-Received: by 2002:a17:90b:1e11:b0:23f:46a5:248e with SMTP id pg17-20020a17090b1e1100b0023f46a5248emr8066794pjb.44.1680728578981; Wed, 05 Apr 2023 14:02:58 -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.02.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 05 Apr 2023 14:02:58 -0700 (PDT) From: Patrick O'Neill <patrick@rivosinc.com> 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 <patrick@rivosinc.com> Subject: [PATCH v2 0/8] RISCV: Implement ISA Manual Table A.6 Mappings Date: Wed, 5 Apr 2023 14:01:10 -0700 Message-Id: <20230405210118.1969283-1-patrick@rivosinc.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220407182918.294892-1-patrick@rivosinc.com> References: <20220407182918.294892-1-patrick@rivosinc.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-3.2 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, 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 <gcc-patches.gcc.gnu.org> List-Unsubscribe: <https://gcc.gnu.org/mailman/options/gcc-patches>, <mailto:gcc-patches-request@gcc.gnu.org?subject=unsubscribe> List-Archive: <https://gcc.gnu.org/pipermail/gcc-patches/> List-Post: <mailto:gcc-patches@gcc.gnu.org> List-Help: <mailto:gcc-patches-request@gcc.gnu.org?subject=help> List-Subscribe: <https://gcc.gnu.org/mailman/listinfo/gcc-patches>, <mailto:gcc-patches-request@gcc.gnu.org?subject=subscribe> Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" <gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org> X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1762371760780938788?= X-GMAIL-MSGID: =?utf-8?q?1762371760780938788?= |
Series |
RISCV: Implement ISA Manual Table A.6 Mappings
|
|
Message
Patrick O'Neill
April 5, 2023, 9:01 p.m. UTC
This patchset aims to bring the RISCV atomics implementation in line with the recommended mapping present in table A.6 of the ISA manual. https://github.com/riscv/riscv-isa-manual/blob/c7cf84547b3aefacab5463add1734c1602b67a49/src/memory.tex#L1083-L1157 The current mapping in GCC is not internally consistent. Andrea Parri pointed this out here along with a litmus test: https://inbox.sourceware.org/gcc-patches/Y1GbJuhcBFpPGJQ0@andrea/ As a result, we have an opportunity to jump straight to the A.6 implementation (meaning we will be compatible with LLVM's mappings which are A.6). Ideally we move to the A.6 mappings before more binaries are built/distributed and it becomes more painful to switch. Patch 1 simplifies the memmodel to ignore MEMMODEL_SYNC_* cases (legacy cases that aren't handled differently for RISC-V). Patches 2-4 make the mappings strictly stronger. Patches 5-8 weaken the mappings to be in line with table A.6 of the ISA manual. Christoph Muellner also submitted a similar patchset here: https://gcc.gnu.org/pipermail/gcc-patches/2022-May/595712.html I used my previous patchset as a starting point since it was easier for me. LLVM mapping notes: * LLVM emits corresponding fences for atomic_signal_fence instructions. This seems to be an oversight since AFAIK atomic_signal_fence acts as a compiler directive. GCC does not emit any fences for atomic_signal_fence instructions. Remaining work: * After this patchset, GCC still emits a full fence rw,rw after a SEQ_CST load (fence r,rw is recommended by table A.6). This can be relaxed in a future patch as it is strictly stronger than A.6's recommendation - I wanted to get this series out to be considered for GCC 13. Patchset v1: https://gcc.gnu.org/pipermail/gcc-patches/2022-April/592950.html Changes for v2: * Use memmodel_base rather than a custom simplify_memmodel function (Inspired by Christoph Muellner's patch 1/9) * Move instruction styling change from [v1 5/7] to [v2 3/8] to reduce [v2 6/8]'s complexity * Eliminated %K flag for atomic store introduced in v1 in favor of if/else * Rebase/test * PR target/89835: The RISC-V target uses amoswap.w for relaxed stores Patrick O'Neill (8): RISCV: Eliminate SYNC memory models RISCV: Enforce Libatomic LR/SC SEQ_CST RISCV: Enforce atomic compare_exchange SEQ_CST RISCV: Add AMO release bits RISCV: Eliminate AMO op fences RISCV: Weaken compare_exchange LR/SC pairs RISCV: Weaken atomic stores RISCV: Weaken mem_thread_fence gcc/config/riscv/riscv-protos.h | 5 ++ gcc/config/riscv/riscv.cc | 70 ++++++++++++++----- gcc/config/riscv/sync.md | 62 +++++++++++----- .../gcc.target/riscv/amo-thread-fence-1.c | 6 ++ .../gcc.target/riscv/amo-thread-fence-2.c | 6 ++ .../gcc.target/riscv/amo-thread-fence-3.c | 6 ++ .../gcc.target/riscv/amo-thread-fence-4.c | 6 ++ .../gcc.target/riscv/amo-thread-fence-5.c | 6 ++ .../riscv/compare-exchange-atomics-model-1.c | 12 ++++ .../riscv/compare-exchange-atomics-model-2.c | 12 ++++ .../riscv/compare-exchange-atomics-model-3.c | 12 ++++ .../riscv/compare-exchange-atomics-model-4.c | 12 ++++ .../riscv/compare-exchange-atomics-model-5.c | 12 ++++ gcc/testsuite/gcc.target/riscv/pr89835.c | 9 +++ libgcc/config/riscv/atomic.c | 4 +- 15 files changed, 206 insertions(+), 34 deletions(-) create mode 100644 gcc/testsuite/gcc.target/riscv/amo-thread-fence-1.c create mode 100644 gcc/testsuite/gcc.target/riscv/amo-thread-fence-2.c create mode 100644 gcc/testsuite/gcc.target/riscv/amo-thread-fence-3.c create mode 100644 gcc/testsuite/gcc.target/riscv/amo-thread-fence-4.c create mode 100644 gcc/testsuite/gcc.target/riscv/amo-thread-fence-5.c create mode 100644 gcc/testsuite/gcc.target/riscv/compare-exchange-atomics-model-1.c create mode 100644 gcc/testsuite/gcc.target/riscv/compare-exchange-atomics-model-2.c create mode 100644 gcc/testsuite/gcc.target/riscv/compare-exchange-atomics-model-3.c create mode 100644 gcc/testsuite/gcc.target/riscv/compare-exchange-atomics-model-4.c create mode 100644 gcc/testsuite/gcc.target/riscv/compare-exchange-atomics-model-5.c create mode 100644 gcc/testsuite/gcc.target/riscv/pr89835.c