From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-sender-0.a4lg.com (mail-sender.a4lg.com [153.120.152.154]) by sourceware.org (Postfix) with ESMTPS id 84C8B3858C2F for ; Thu, 27 Jul 2023 00:30:35 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 84C8B3858C2F Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=irq.a4lg.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=irq.a4lg.com Received: from [127.0.0.1] (localhost [127.0.0.1]) by mail-sender-0.a4lg.com (Postfix) with ESMTPSA id 9FDE1300089; Thu, 27 Jul 2023 00:30:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=irq.a4lg.com; s=2017s01; t=1690417829; bh=HrA0P6fPqvPNS2d0hXQXtHWZ4qN5FimybkT8ZzI7QvU=; h=From:To:Cc:Subject:Date:Message-ID:Mime-Version: Content-Transfer-Encoding; b=WKlmPmED5TEZ9VRWBqt/yYB1K0ZE6h/n3pDYiVFo3UP+J0waStljtgneIlagpUy2H zewvrqltDefowpSxdo1aIlrFTH9jnCZRYVc4XFb4FxY05fLHxhLgMdRTVexY9sGNBM 1IYPGgXNRsFwoKFeZxMz9asLs9MxctdYkEKR/9lc= From: Tsukasa OI To: Tsukasa OI , Palmer Dabbelt , Andrew Waterman , Jim Wilson , Nelson Chu , Kito Cheng Cc: binutils@sourceware.org Subject: [RFC PATCH 0/3] RISC-V: Add complex extension implications (incl. 'C'+'[FD]') Date: Thu, 27 Jul 2023 00:30:18 +0000 Message-ID: Mime-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-6.0 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,KAM_MANYTO,SPF_HELO_NONE,SPF_PASS,TXREP,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: Hi, This patch set reflects rather complex implications derived from 'C' and either 'F' or 'D'. [PATCH 1-2] They are the expansions related in this context: 'C' == 'C' + 'Zca' 'C' + 'F' == 'C' + 'Zca' + 'Zcf' + 'F' (RV32) 'C' + 'F' == 'C' + 'Zca' + 'F' (RV64) 'C' + 'F' + 'D' == 'C' + 'Zca' + 'Zcf' + 'Zcd' + 'F' + 'D' (RV32) 'C' + 'F' + 'D' == 'C' + 'Zca' + 'Zcd' + 'F' + 'D' (RV64) (they exclude dependencies from 'F' and 'D') I first thought implementing this is hard (as the implication list get more complex). However, thanks to the commit 48558a5e5471 ("RISC-V: Allow nested implications for extensions"), things got a lot easier (we have an option to rescan the implication list). I haven't depended on this looping behavior in *this* patch set but this loop will be useful in the future. All we have to do is: 1. Give more information to "check_func" when checking an implied extension and 2. Implement custom "check_func" for such conditions. "check_implicit_for_d_c" corresponds to the implication 'D' -> 'Zcd' and returns true if the extension 'C' is *also* available. It makes following expansions: 1. 'C' == 'C' 2. 'C' + 'D' == 'C' + 'Zcd' + 'D' "check_implicit_for_f_c" (which corresponds to the implication 'F' -> 'Zcf') depends on "check_implicit_for_d_c" but does extra XLEN check (returns true only when XLEN == 32). It makes following expansions: 1. 'C' == 'C' 2a. 'C' + 'F' == 'C' + 'Zcf' + 'F' (RV32) 2b. 'C' + 'F' == 'C' + 'F' (RV64) Existing "check_implicit_always" does following expansion: 1. 'C' == 'C' + 'Zca' With all three combined, we can get the full expansions I listed above. [PATCH 3] It also requires some changes to the ".option norvc" half-deprecated (or completely deprecated?) compatibility directive in the assembler. I stated that it disables the 'C' extension and its subsets ('Zca', 'Zcf' and 'Zcd'). If some extensions depend on 'C' or 'Zc*' are enabled, we cannot emit compressed instructions but some garbage will remain in the RISC-V attributes and mapping symbols. Quick Example: .attribute arch, "rv32i" .option rvc .option arch, +zcb # ... .option norvc # The final architecture string will contain 'Zcb' (not disabled by # the ".option norvc" directive) and 'Zca' ('Zcb' depends on it). [Others may need this change] For instance, the draft 'Zicfiss' extension in the RISC-V CFI specification draft might need this kind of complex implications. This is because, not only the instructions in that extension depends on the existence of compressed instructions, uncompressed/compressed encodings of the extension depend on 'Zimop' (uncompressed) and 'Zcmop' (compressed), respectively. cf. (for 'Zicfiss') (for 'Zimop' and 'Zcmop') 'Zicfiss'-related dependency: * 'Zicfiss' (uncompressed encodings) -> 'Zimop' * 'Zicfiss' (compressed encodings) -> 'Zcmop' -> 'Zca' (compressed forms must be enabled when either 'C' or 'Zca' is enabled.) Example implementing the dependency using complex implications (assuming this patch set is applied): 1. 'Zicfiss' -> 'Zimop' 2. 'Zicfiss' + 'Zca' -> 'Zcmop' (check 'Zca' in custom "check_func") 3. 'Zcmop' -> 'Zca' [My Thoughts] I had to modify some test cases that use ".option arch, -c" to disable compressed instructions because ".option arch, -c" alone will not turn off its subsets. It suggests that this kind of behavior might be possibly breaking on some programs. We should monitor the situation and investigate existing programs to minimize breaking others' work. That's why this patch set is now an RFC (despite that it's ready for the upstream merge; especially PATCH 1). Thanks, Tsukasa Tsukasa OI (3): RISC-V: Base for complex extension implications RISC-V: Add complex implications from 'C'+'[DF]' RISC-V: ".option norvc" to disable 'C' and subsets bfd/elfxx-riscv.c | 66 +++++++++++++++---- gas/config/tc-riscv.c | 6 +- gas/testsuite/gas/riscv/attribute-10.d | 2 +- .../gas/riscv/dis-addr-overflow-32.d | 2 +- .../gas/riscv/dis-addr-overflow-64.d | 2 +- gas/testsuite/gas/riscv/dis-addr-overflow.s | 4 +- gas/testsuite/gas/riscv/mapping-symbols.d | 22 +++---- gas/testsuite/gas/riscv/mapping.s | 48 +++++++------- gas/testsuite/gas/riscv/march-imply-c-d-32.d | 6 ++ gas/testsuite/gas/riscv/march-imply-c-d-64.d | 6 ++ gas/testsuite/gas/riscv/march-imply-c.d | 6 ++ gas/testsuite/gas/riscv/march-ok-reorder.d | 2 +- gas/testsuite/gas/riscv/option-arch-01.s | 4 +- gas/testsuite/gas/riscv/option-arch-01b.d | 2 +- gas/testsuite/gas/riscv/option-arch-02.d | 2 +- gas/testsuite/gas/riscv/option-arch-02.s | 4 +- gas/testsuite/gas/riscv/option-arch-03.d | 2 +- gas/testsuite/gas/riscv/option-arch-03.s | 4 +- 18 files changed, 125 insertions(+), 65 deletions(-) create mode 100644 gas/testsuite/gas/riscv/march-imply-c-d-32.d create mode 100644 gas/testsuite/gas/riscv/march-imply-c-d-64.d create mode 100644 gas/testsuite/gas/riscv/march-imply-c.d base-commit: 513c7e5f3e859be8670c7aa7aae41f78f860918f -- 2.41.0