Message ID | cover.1669617534.git.research_trasio@irq.a4lg.com |
---|---|
Headers |
Return-Path: <binutils-bounces+ouuuleilei=gmail.com@sourceware.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp5469241wrr; Sun, 27 Nov 2022 22:39:59 -0800 (PST) X-Google-Smtp-Source: AA0mqf4SXC5kp691iayl9xtwC2c+dhfqHln80ShliBqnH1Q3rKjTlyxGwcsam+/T7rlN8+J1xYjs X-Received: by 2002:a05:6402:b55:b0:469:bd35:655c with SMTP id bx21-20020a0564020b5500b00469bd35655cmr30433238edb.245.1669617598945; Sun, 27 Nov 2022 22:39:58 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669617598; cv=none; d=google.com; s=arc-20160816; b=GcuTGEp7051Bi+OjS0dzI/lv7JIhNZx23Q+vmHY2ULLwk0bMZJHN199h2XZ6+GVw9n ODkKRMDfljkot5NBOYXBGTEECW2bAN1ZBhlvtBc1KT+oh5DZ+0BhqBkcvtt2Xh8INDLw IpUamMNTyNuQn5N+YxrzYyhMYG1mU4VpU8TgYVuEyNFdYZ7vr+ME7Va/iqVZyKnyYCYe WnKiyjpwlppSN8LJKJwpAc7YioQVm/UNy5VMGSKEp/lCbhlAQ18CG+6eH1hyFWljWiFp 08zsBmA7KxoARwxVotIBNA1XBOdVW9/+luFo5miPD80aRq3wf9JhnBSkuEG1KwECx8Rc ooCQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:reply-to:from:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence :content-transfer-encoding:mime-version:message-id:date:subject:cc :to:dmarc-filter:delivered-to:dkim-signature:dkim-filter; bh=TRP/XBEHcy2jaxF7nDO6Qj7Aqo5A2Yt0mTvU3QCPp7w=; b=csVh9X3BEMTFzX8PCFiNBRi5InwlIZYeew/8Tglqxk24XOuUwYMb+kgcKucWD2pA2a 3fAOH5GOG2awbBpjNO75EZaQQqbOXgzw8gDf/VvSvfXeL8Y7rzy1Mo1YSolrRiIRfI7Z 4e6uPfot2wcEpSabEepK+GMb+v+Rhl4fXV+AIqexInro0m2NHAoJsRILjyNiE0AlebPw fnDBsHFQhnp1FSNmfn19CuwI/kLXgHqnIf/smjxMHKX2RugKrgP/cd2rHdDRGBWIhoUH odcRsk72lskpcIBpSdUARimjznTGW/RcyggTAZwkEO/AHhW2sKLorG3X4fUp/byQcHZm vqqQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@sourceware.org header.s=default header.b=O27xh7Mj; spf=pass (google.com: domain of binutils-bounces+ouuuleilei=gmail.com@sourceware.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="binutils-bounces+ouuuleilei=gmail.com@sourceware.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=sourceware.org Received: from sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id ev13-20020a056402540d00b0046b1c38c13dsi2473021edb.122.2022.11.27.22.39.58 for <ouuuleilei@gmail.com> (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 27 Nov 2022 22:39:58 -0800 (PST) Received-SPF: pass (google.com: domain of binutils-bounces+ouuuleilei=gmail.com@sourceware.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=@sourceware.org header.s=default header.b=O27xh7Mj; spf=pass (google.com: domain of binutils-bounces+ouuuleilei=gmail.com@sourceware.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="binutils-bounces+ouuuleilei=gmail.com@sourceware.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id BFBD93858426 for <ouuuleilei@gmail.com>; Mon, 28 Nov 2022 06:39:57 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org BFBD93858426 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1669617597; bh=TRP/XBEHcy2jaxF7nDO6Qj7Aqo5A2Yt0mTvU3QCPp7w=; h=To:Cc:Subject:Date:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From:Reply-To:From; b=O27xh7MjP6QTNSBXmuZsakRYlxo4tgEi6rfV/nqljXNF2YeGJLP4VAYXJNRzkJD1p kNtK1yg1uxIhzCnlcABsXhBY7bPhpYqxanlpQrSAox1dtxAZh/RvR/qw9HaQA+OGa+ rUTkcDm4Fo3kBpb1CgsKrM91gQtZOjT5SIsSUnnU= X-Original-To: binutils@sourceware.org Delivered-To: binutils@sourceware.org Received: from mail-sender-0.a4lg.com (mail-sender.a4lg.com [153.120.152.154]) by sourceware.org (Postfix) with ESMTPS id 1F5713858D3C for <binutils@sourceware.org>; Mon, 28 Nov 2022 06:39:48 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 1F5713858D3C Received: from [127.0.0.1] (localhost [127.0.0.1]) by mail-sender-0.a4lg.com (Postfix) with ESMTPSA id C1C27300089; Mon, 28 Nov 2022 06:39:45 +0000 (UTC) To: Tsukasa OI <research_trasio@irq.a4lg.com>, Nelson Chu <nelson@rivosinc.com>, Kito Cheng <kito.cheng@sifive.com>, Palmer Dabbelt <palmer@dabbelt.com> Cc: binutils@sourceware.org Subject: [PATCH 0/3] RISC-V: Support non-standard encodings (on widening FP ops) Date: Mon, 28 Nov 2022 06:39:31 +0000 Message-Id: <cover.1669617534.git.research_trasio@irq.a4lg.com> Mime-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-6.1 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, 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: binutils@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Binutils mailing list <binutils.sourceware.org> List-Unsubscribe: <https://sourceware.org/mailman/options/binutils>, <mailto:binutils-request@sourceware.org?subject=unsubscribe> List-Archive: <https://sourceware.org/pipermail/binutils/> List-Post: <mailto:binutils@sourceware.org> List-Help: <mailto:binutils-request@sourceware.org?subject=help> List-Subscribe: <https://sourceware.org/mailman/listinfo/binutils>, <mailto:binutils-request@sourceware.org?subject=subscribe> From: Tsukasa OI via Binutils <binutils@sourceware.org> Reply-To: Tsukasa OI <research_trasio@irq.a4lg.com> Errors-To: binutils-bounces+ouuuleilei=gmail.com@sourceware.org Sender: "Binutils" <binutils-bounces+ouuuleilei=gmail.com@sourceware.org> X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1750720943223208399?= X-GMAIL-MSGID: =?utf-8?q?1750720943223208399?= |
Series |
RISC-V: Support non-standard encodings (on widening FP ops)
|
|
Message
Tsukasa OI
Nov. 28, 2022, 6:39 a.m. UTC
Hello, Some of the floating point instructions does not depend on the rounding mode despite the existence of rm (rounding mode) field. Such examples are widening conversion instructions. Quoting "11.2 Floating-Point Control and Status Register" from the RISC-V ISA Manual (version 20191213): > Some instructions, including widening conversions, have the rm field but > are nevertheless unaffected by the rounding mode; software should set > their rm field to RNE (000). The latest draft of the ISA Manual is clarified further: Quoting "13.2 Floating-Point Control and Status Register" from the RISC-V ISA Manual (version draft-20221119-5234c63): > Some instructions, including widening conversions, have the rm field but > are nevertheless mathematically unaffected by the rounding mode; software > should set their rm field to RNE (000) but implementations must treat the > rm field as usual (in particular, with regard to decoding legal vs. > reserved encodings). For instance, to encode a FCVT.D.S instruction, we should set its rm field to RNE (0b000). However, FCVT.D.S instruction with non-RNE rm field is still a valid instruction (despite that GAS does not allow specifying any rounding modes on FCVT.D.S) and must handle as a valid instruction when disassembled unless an invalid rounding mode is specified. However, current GNU Binutils only supports disassembling widening conversion instructions with rm field of RNE (0b000) except FCVT.Q.L and FCVT.Q.LU instructions (two instructions supported specifying rounding modes for historical reasons). This patchset (in specific, PATCH 3/3) enables special handling of such instructions by adding two new operand types: 1. "WfM": optional rounding mode where specifying rounding mode is not supported in the past. 2. "Wfm": optional rounding mode where specifying rounding mode is supported in the past (used in FCVT.Q.L and FCVT.Q.LU). I designed this patchset to be configurable (allow implementing S Pawan Kumar's proposal if needed) but the behavior in this patchset is as follows: Disassembler: Optional (non-RNE [!= 0b000]) rounding mode is printed only if: (a) "no-aliases" disassembler option is specified, or (b) the rounding mode is invalid (0b101 / 0b110). I think removing condition (a) might be an option. Because, despite that we can now see the actual rounding mode with condition (a), it's not valid as an assembler mnemonic. Condition (b) is an intentional choice to detect invalid encodings. Still, it could be removed, too (I don't recommend though). Assembler: Specifying optional rounding mode is prohibited (except FCVT.Q.L and FCVT.Q.LU) or accepted with a warning (FCVT.Q.L and FCVT.Q.LU). c.f. S Pawan Kumar's proposal: <https://github.com/riscv-collab/riscv-gnu-toolchain/issues/1089> # Before this patchset: objdump -d (with my comment) 8000002c: 42058553 fcvt.d.s fa0,fa1 80000030: 42059553 .4byte 0x42059553 # Valid (but not recommended) encoding of FCVT.D.S 80000034: 4205a553 .4byte 0x4205a553 # Valid (but not recommended) encoding of FCVT.D.S 80000038: 4205b553 .4byte 0x4205b553 # Valid (but not recommended) encoding of FCVT.D.S 8000003c: 4205c553 .4byte 0x4205c553 # Valid (but not recommended) encoding of FCVT.D.S 80000040: 4205f553 .4byte 0x4205f553 # Valid (but not recommended) encoding of FCVT.D.S 80000044: 4205d553 .4byte 0x4205d553 # Invalid FCVT.D.S (reserved rounding mode 0b101) 80000048: 4205e553 .4byte 0x4205e553 # Invalid FCVT.D.S (reserved rounding mode 0b110) # After this patchset: objdump -d 8000002c: 42058553 fcvt.d.s fa0,fa1 80000030: 42059553 fcvt.d.s fa0,fa1 80000034: 4205a553 fcvt.d.s fa0,fa1 80000038: 4205b553 fcvt.d.s fa0,fa1 8000003c: 4205c553 fcvt.d.s fa0,fa1 80000040: 4205f553 fcvt.d.s fa0,fa1 80000044: 4205d553 fcvt.d.s fa0,fa1,unknown 80000048: 4205e553 fcvt.d.s fa0,fa1,unknown # After this patchset: objdump -M no-aliases -d 8000002c: 42058553 fcvt.d.s fa0,fa1 80000030: 42059553 fcvt.d.s fa0,fa1,rtz 80000034: 4205a553 fcvt.d.s fa0,fa1,rdn 80000038: 4205b553 fcvt.d.s fa0,fa1,rup 8000003c: 4205c553 fcvt.d.s fa0,fa1,rmm 80000040: 4205f553 fcvt.d.s fa0,fa1,dyn 80000044: 4205d553 fcvt.d.s fa0,fa1,unknown 80000048: 4205e553 fcvt.d.s fa0,fa1,unknown Due to my development process, it now depends on the commit ("RISC-V: Allocate "various" operand type": PATCH 1/3) which adds "Wif" operand type (not just "WfM" and "Wfm" which is added by PATCH 3/3). PATCH 1/3 is the same patch as this: <https://sourceware.org/pipermail/binutils/2022-October/123884.html> If requested, I can remove the dependency to PATCH 1/3 (in that case my local development branches will be a bit complex but nothing else happens). Thanks, Tsukasa Tsukasa OI (3): RISC-V: Allocate "various" operand type RISC-V: Reorganize invalid rounding mode test RISC-V: Rounding mode on widening instructions gas/config/tc-riscv.c | 107 +++++++++++++++--- gas/testsuite/gas/riscv/rouding-fail.d | 3 - gas/testsuite/gas/riscv/rouding-fail.l | 3 - gas/testsuite/gas/riscv/rouding-fail.s | 3 - .../gas/riscv/rounding-dis-widening-noalias.d | 13 +++ .../gas/riscv/rounding-dis-widening.d | 13 +++ .../gas/riscv/rounding-dis-widening.s | 8 ++ gas/testsuite/gas/riscv/rounding-fail.d | 3 + gas/testsuite/gas/riscv/rounding-fail.l | 16 +++ gas/testsuite/gas/riscv/rounding-fail.s | 22 ++++ .../gas/riscv/rounding-fcvt.q.l-noalias.d | 15 +++ gas/testsuite/gas/riscv/rounding-fcvt.q.l.d | 15 +++ gas/testsuite/gas/riscv/rounding-fcvt.q.l.l | 3 + gas/testsuite/gas/riscv/rounding-fcvt.q.l.s | 5 + opcodes/riscv-dis.c | 48 +++++++- opcodes/riscv-opc.c | 32 +++--- 16 files changed, 261 insertions(+), 48 deletions(-) delete mode 100644 gas/testsuite/gas/riscv/rouding-fail.d delete mode 100644 gas/testsuite/gas/riscv/rouding-fail.l delete mode 100644 gas/testsuite/gas/riscv/rouding-fail.s create mode 100644 gas/testsuite/gas/riscv/rounding-dis-widening-noalias.d create mode 100644 gas/testsuite/gas/riscv/rounding-dis-widening.d create mode 100644 gas/testsuite/gas/riscv/rounding-dis-widening.s create mode 100644 gas/testsuite/gas/riscv/rounding-fail.d create mode 100644 gas/testsuite/gas/riscv/rounding-fail.l create mode 100644 gas/testsuite/gas/riscv/rounding-fail.s create mode 100644 gas/testsuite/gas/riscv/rounding-fcvt.q.l-noalias.d create mode 100644 gas/testsuite/gas/riscv/rounding-fcvt.q.l.d create mode 100644 gas/testsuite/gas/riscv/rounding-fcvt.q.l.l create mode 100644 gas/testsuite/gas/riscv/rounding-fcvt.q.l.s base-commit: c341f4676af4f9922ca61e1b093d103ed808ae6e