Message ID | 20230414170942.1695672-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 b10csp534756vqo; Fri, 14 Apr 2023 10:11:41 -0700 (PDT) X-Google-Smtp-Source: AKy350ZG8UjdMPHn8bazpjdFx1lXIqW+f/E4uAF72dKssFd8fz/RII+EZzYXe8CPVghAAKVLNwwn X-Received: by 2002:aa7:c407:0:b0:506:86a2:f574 with SMTP id j7-20020aa7c407000000b0050686a2f574mr1580351edq.34.1681492301136; Fri, 14 Apr 2023 10:11:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1681492301; cv=none; d=google.com; s=arc-20160816; b=JmAyzxCkooKZB2airRhoDKXsCo6QdQxi/eGlfq3I5EeIpgd2xCCk9bLk5Piq3wmDg+ ZS/tk/Quft4XA3Hc5iVIeJQNok0UsK2eu829qrBEPXh3Rbh/hHE9hiF+0OpZtg36qjjZ wc1XwauTraFJEvyGXi9iUDk0EcEpjbkIKRPZQnjedpLDhLk6A2fqictjJx0D2lnsC/Gd WYGVQGicxrf0uHteIpPoGAE6Yjq8FvH7cvcFENgRG4QCIoS5YEXq56u/HIRsgw6maqmL hWq7Dn+7ywA6DirI+NePz4KjkJk47MYjIlWAoGL/URkWJC32be7WjOEIKj5D1wnn4iaq EnCg== 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=5Yb52JQ72FKTjg1PyGP0iEr5p4PHJ5TPGkG0qHLQJGA=; b=ZhrEc4xS9lvuj9cb+UkBke6dX777da1hWq9RpirqQFrQFGT+oVeQtPzqdTOU9I1HPo aEB89BTN7eeLpKgaiR7GmGLqZ+0fZLmA/V0x7Gc7qboaHHt4lugdetLjKV8xNjrqURtU EsEeVhKOW+y6PW6PL0QPFeQqRFxKow3Zy2bRvFZ30gjp2d3SYMk3F7oqkZvvfwC91EQR zGjKLqFLyOr77LswOHAyl4Q03O/aMsBg5Zt/UjSnnSHCXgYV2xzxQluIEEbe+3r02F5+ tuRcCYs8KBH9+o/sDfE7tbsGohzkQ0Wpft5p1R0dlabFdRK/qfrNDcgVC1hwO6ogwfr7 ts0A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@rivosinc-com.20221208.gappssmtp.com header.s=20221208 header.b=0r0Ck15M; 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 (ip-8-43-85-97.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id ay23-20020a056402203700b00501d4f9e38esi4931551edb.595.2023.04.14.10.11.40 for <ouuuleilei@gmail.com> (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 14 Apr 2023 10:11:41 -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=0r0Ck15M; 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 5DA33385B507 for <ouuuleilei@gmail.com>; Fri, 14 Apr 2023 17:11:13 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-pl1-x642.google.com (mail-pl1-x642.google.com [IPv6:2607:f8b0:4864:20::642]) by sourceware.org (Postfix) with ESMTPS id 333263858C54 for <gcc-patches@gcc.gnu.org>; Fri, 14 Apr 2023 17:10:36 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 333263858C54 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-x642.google.com with SMTP id d9443c01a7336-1a516fb6523so15127065ad.3 for <gcc-patches@gcc.gnu.org>; Fri, 14 Apr 2023 10:10:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20221208.gappssmtp.com; s=20221208; t=1681492235; x=1684084235; 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=5Yb52JQ72FKTjg1PyGP0iEr5p4PHJ5TPGkG0qHLQJGA=; b=0r0Ck15M2S9JkQqGRitvMg5axjDlI7a2V8AIno8ZnpCF6yLwUfr+YnHKPwsRUv3IJz 0YOc6ARdgJzIf45Es+XaPnoRSkR/GQK5cY9I4WqtgJxXkbJWW1PYyBdwcI1Z8PrWYQk6 Jv3xVWCzOeR+Mf55IfeCJp3Y5tl+gZTeGaL52R/Oauuuf1p/txVhKdcqbtMV8KbbYGUE uVm9aMavGV2F54mizU3QxmvFcdAAaWDIj/f+p3nC2pBWqBXZLp9atz5qL1ZQrlV71ngt Pbmnrtdq/vDzRzNlRdnvtaDO03HbsLWqKnwEgds6WTC9/rZooJPkfPCzPbzBd6czAzJo PhwA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1681492235; x=1684084235; 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=5Yb52JQ72FKTjg1PyGP0iEr5p4PHJ5TPGkG0qHLQJGA=; b=Jzl+ZhmiDOZ+PCuPeaZf/3tFf8Po6JHGVTkEHqbjzifIqnr/Sd7x0xvtv3tsVSsysy bxIMLbtaScn0ijl8HcMrcAjbszO5ge9qb72cmh+0AKxzHdXCXrl8ee5cLqXETm8MYSnK mBJDlyAR3+5EPIvGsZPdROIZeakSAmU4i5zSsiDP1M3Nf1JkKdKK3s9jNLroywgQlQjL yJNHQ88eNa39qkEy8FGtjEQg33EQN3eDl+6Hn3VREml3pSjg24pCB+TtpQrUPlHsqssN jW4EJ2bmaiy+Rkq4cJgSVKYoaLPXziRw4+HjARim1tT7mxnXb4wirPXhpSZ9+013eGtt NuIA== X-Gm-Message-State: AAQBX9eHx1dMwyAikwvaUkT9cY8gzmJZCmc2pDx5KvbfYL/k//jfskcM rcx1/M7Lpk/xw6U97vjyppErUuRs2s6a0cTwbiRrHLqFWpE= X-Received: by 2002:a05:6a00:2d21:b0:63b:2102:9ecc with SMTP id fa33-20020a056a002d2100b0063b21029eccmr9397098pfb.13.1681492234620; Fri, 14 Apr 2023 10:10:34 -0700 (PDT) Received: from patrick-ThinkPad-X1-Carbon-Gen-8.hq.rivosinc.com ([50.221.140.188]) by smtp.gmail.com with ESMTPSA id 12-20020aa7924c000000b006258dd63a3fsm3271902pfp.56.2023.04.14.10.10.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 14 Apr 2023 10:10:33 -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, cmuellner@gcc.gnu.org, andrea@rivosinc.com, hboehm@google.com, jeffreyalaw@gmail.com, Patrick O'Neill <patrick@rivosinc.com> Subject: [PATCH v4 00/10] RISCV: Implement ISA Manual Table A.6 Mappings Date: Fri, 14 Apr 2023 10:09:32 -0700 Message-Id: <20230414170942.1695672-1-patrick@rivosinc.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230410182348.2168356-1-patrick@rivosinc.com> References: <20230410182348.2168356-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, 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 <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?1763172471013994126?= |
Series |
RISCV: Implement ISA Manual Table A.6 Mappings
|
|
Message
Patrick O'Neill
April 14, 2023, 5:09 p.m. UTC
This patchset aims to make the RISCV atomics implementation stronger than 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). In light of a proposal by Hans Boehm and to avoid an ABI break in the future, the mapping implemented is strictly stronger than the one in table A.6 in order to be compatible with table A.7. https://lists.riscv.org/g/tech-unprivileged/topic/risc_v_memory_model_topics/92916241 This change incurs a performance penalty on SEQ_CST stores due to the added trailing fence. Systems implementing table A.7 will have significant performance gains relative to table A.6 and are expected to be the standard memory model mapping in the RISCV ecosystem. Incurring this added cost now will make it significantly easier for compiled RISC-V binaries to transition to the A.7 memory model mapping. If Hans' proposal is accepted, it makes sense to migrate to the mapping recommended by table A.7. Since the stronger mapping in this patchset (provided by Hans Boehm) appears to be compatible with both A.6 and A.7, this transition should not result in an ABI break for GCC. Patch 1 simplifies the memmodel to ignore MEMMODEL_SYNC_* cases (legacy cases that aren't handled differently for RISC-V). Patches 2-5 make the mappings strictly stronger. Patches 5-9 weaken the mappings to be in line with table A.6 of the ISA manual. Patch 10 adds some basic conformance tests to ensure the implemented mapping matches table A.6 with stronger SEQ_CST stores. 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. Patchset v1: https://gcc.gnu.org/pipermail/gcc-patches/2022-April/592950.html Patchset v2: https://gcc.gnu.org/pipermail/gcc-patches/2023-April/615264.html Patchset v3: https://gcc.gnu.org/pipermail/gcc-patches/2023-April/615431.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 Changes for v3: * Use a trailing fence for atomic stores to be compatible with table A.7 * Emit an optimized fence r,rw following a SEQ_CST load * Consolidate tests in [PATCH v3 10/10] * Add tests for basic A.6 conformance Changes for v4: * Update cover letter to cover more of the reasoning behind moving to a compatability mapping * Improve conformance testcases patch assertions and add new compare-exchange testcases Patrick O'Neill (10): 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: Strengthen atomic stores RISCV: Eliminate AMO op fences RISCV: Weaken compare_exchange LR/SC pairs RISCV: Weaken mem_thread_fence RISCV: Weaken atomic loads RISCV: Table A.6 conformance tests gcc/config/riscv/riscv-protos.h | 3 + gcc/config/riscv/riscv.cc | 66 +++++++++++--- gcc/config/riscv/sync.md | 89 ++++++++++++++++--- .../riscv/amo-table-a-6-amo-add-1.c | 8 ++ .../riscv/amo-table-a-6-amo-add-2.c | 8 ++ .../riscv/amo-table-a-6-amo-add-3.c | 8 ++ .../riscv/amo-table-a-6-amo-add-4.c | 8 ++ .../riscv/amo-table-a-6-amo-add-5.c | 8 ++ .../riscv/amo-table-a-6-compare-exchange-1.c | 10 +++ .../riscv/amo-table-a-6-compare-exchange-2.c | 10 +++ .../riscv/amo-table-a-6-compare-exchange-3.c | 10 +++ .../riscv/amo-table-a-6-compare-exchange-4.c | 10 +++ .../riscv/amo-table-a-6-compare-exchange-5.c | 10 +++ .../riscv/amo-table-a-6-compare-exchange-6.c | 11 +++ .../riscv/amo-table-a-6-compare-exchange-7.c | 10 +++ .../gcc.target/riscv/amo-table-a-6-fence-1.c | 8 ++ .../gcc.target/riscv/amo-table-a-6-fence-2.c | 10 +++ .../gcc.target/riscv/amo-table-a-6-fence-3.c | 10 +++ .../gcc.target/riscv/amo-table-a-6-fence-4.c | 10 +++ .../gcc.target/riscv/amo-table-a-6-fence-5.c | 10 +++ .../gcc.target/riscv/amo-table-a-6-load-1.c | 9 ++ .../gcc.target/riscv/amo-table-a-6-load-2.c | 11 +++ .../gcc.target/riscv/amo-table-a-6-load-3.c | 11 +++ .../gcc.target/riscv/amo-table-a-6-store-1.c | 9 ++ .../gcc.target/riscv/amo-table-a-6-store-2.c | 11 +++ .../riscv/amo-table-a-6-store-compat-3.c | 11 +++ gcc/testsuite/gcc.target/riscv/pr89835.c | 9 ++ libgcc/config/riscv/atomic.c | 4 +- 28 files changed, 362 insertions(+), 30 deletions(-) create mode 100644 gcc/testsuite/gcc.target/riscv/amo-table-a-6-amo-add-1.c create mode 100644 gcc/testsuite/gcc.target/riscv/amo-table-a-6-amo-add-2.c create mode 100644 gcc/testsuite/gcc.target/riscv/amo-table-a-6-amo-add-3.c create mode 100644 gcc/testsuite/gcc.target/riscv/amo-table-a-6-amo-add-4.c create mode 100644 gcc/testsuite/gcc.target/riscv/amo-table-a-6-amo-add-5.c create mode 100644 gcc/testsuite/gcc.target/riscv/amo-table-a-6-compare-exchange-1.c create mode 100644 gcc/testsuite/gcc.target/riscv/amo-table-a-6-compare-exchange-2.c create mode 100644 gcc/testsuite/gcc.target/riscv/amo-table-a-6-compare-exchange-3.c create mode 100644 gcc/testsuite/gcc.target/riscv/amo-table-a-6-compare-exchange-4.c create mode 100644 gcc/testsuite/gcc.target/riscv/amo-table-a-6-compare-exchange-5.c create mode 100644 gcc/testsuite/gcc.target/riscv/amo-table-a-6-compare-exchange-6.c create mode 100644 gcc/testsuite/gcc.target/riscv/amo-table-a-6-compare-exchange-7.c create mode 100644 gcc/testsuite/gcc.target/riscv/amo-table-a-6-fence-1.c create mode 100644 gcc/testsuite/gcc.target/riscv/amo-table-a-6-fence-2.c create mode 100644 gcc/testsuite/gcc.target/riscv/amo-table-a-6-fence-3.c create mode 100644 gcc/testsuite/gcc.target/riscv/amo-table-a-6-fence-4.c create mode 100644 gcc/testsuite/gcc.target/riscv/amo-table-a-6-fence-5.c create mode 100644 gcc/testsuite/gcc.target/riscv/amo-table-a-6-load-1.c create mode 100644 gcc/testsuite/gcc.target/riscv/amo-table-a-6-load-2.c create mode 100644 gcc/testsuite/gcc.target/riscv/amo-table-a-6-load-3.c create mode 100644 gcc/testsuite/gcc.target/riscv/amo-table-a-6-store-1.c create mode 100644 gcc/testsuite/gcc.target/riscv/amo-table-a-6-store-2.c create mode 100644 gcc/testsuite/gcc.target/riscv/amo-table-a-6-store-compat-3.c create mode 100644 gcc/testsuite/gcc.target/riscv/pr89835.c