From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-ej1-x630.google.com (mail-ej1-x630.google.com [IPv6:2a00:1450:4864:20::630]) by sourceware.org (Postfix) with ESMTPS id 4C8773850866 for ; Tue, 6 Sep 2022 12:22:34 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 4C8773850866 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=vrull.eu Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=vrull.eu Received: by mail-ej1-x630.google.com with SMTP id fy31so22808742ejc.6 for ; Tue, 06 Sep 2022 05:22:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=vrull.eu; s=google; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date; bh=/Ay/tBMzAp3wjyQTsLRo+EvXACv+7bbMBTaicvrOKR4=; b=Q3CqFpNUN+Zf6b1j/5CLUysSeZ/ytf/kRulWG9J03bX6up7v3C+BKZHLiObW99zwSo AFIkUmNrWK946nr1TY+b72BX1XvKS3gFnNAP0qe5PkEUdbMYnovKoM2kp8S4YmQUUGxt hPKMH0l6/xwvtFABaMbiMHleMS4lYTnR18svwPzfZnOnd85s598HJhB1liDKtwtY4vc4 oIuBRBB/tSWZjriozyW4mukW+CI7LK5jrhjS+oto33H3lwPJ2XgLq2WH/OyMXZrINpxT Uge5DSS75IrN35ChoWHDs/frTJ9+cO17jJwMoRpidl1bT627dgY5/uCBt50VaqUrKP42 nqSw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; 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; bh=/Ay/tBMzAp3wjyQTsLRo+EvXACv+7bbMBTaicvrOKR4=; b=NFhDGw9UcwlQ/RsR3/qQ/tsY9jqzyzVoaCwiBNq+C7My4aG2ZVP/bFMImFLq4jTLno znb0VvrX4OCBRys2YEyQvQQ4NbukYtFqrOEgDqgAfPAVIlH4ImcDlJ1KkXT7mEnJeSP0 tN+qO445b5Bh3ea1heEAiZkWScRsvaMBZBiCaO+7S+6apOiYfg/tsVhD6lRaZx/pGPGB Kq8pKKQedvzDOcmcZ3Rz+O8Fb2dct6iZinjC9FM9QxmS4lI54ighoumcdBl2UIGnvEx4 HJjyeepHiSILUw2oQvwiOLSjoHlmeGnV/qBXMEalD5v/aFto/cF41V7PH0IBvj5WYbum wtag== X-Gm-Message-State: ACgBeo3cJ3No/wjpnlNLaonfaq2MnbyFgSIykZRdRQ9JXKnk01GBQAX2 AxdDBMKZf+d5uywpIutBfDnA7AYiRRULpA== X-Google-Smtp-Source: AA6agR5+OFVzgSQGSbajSce6PBBlPUIPw5n8Lkq2LA/SwuSpoFyPZpANNYzz3yVAbKzuNBLvpiK2RQ== X-Received: by 2002:a17:907:2ce9:b0:76f:a83b:d1a7 with SMTP id hz9-20020a1709072ce900b0076fa83bd1a7mr980632ejc.655.1662466953593; Tue, 06 Sep 2022 05:22:33 -0700 (PDT) Received: from beast.fritz.box (62-178-148-172.cable.dynamic.surfer.at. [62.178.148.172]) by smtp.gmail.com with ESMTPSA id y21-20020a170906525500b0073d7e58b1bcsm6571632ejm.157.2022.09.06.05.22.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 06 Sep 2022 05:22:32 -0700 (PDT) From: Christoph Muellner To: binutils@sourceware.org, Nelson Chu , Kito Cheng , Jim Wilson , Philipp Tomsich , Palmer Dabbelt , Cooper Qu , Lifang Xia , Yunhai Shang , Zhiwei Liu Cc: =?UTF-8?q?Christoph=20M=C3=BCllner?= Subject: [PATCH 11/13] RISC-V: Add T-Head MemPair vendor extension Date: Tue, 6 Sep 2022 14:22:11 +0200 Message-Id: <20220906122213.1243129-12-christoph.muellner@vrull.eu> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20220906122213.1243129-1-christoph.muellner@vrull.eu> References: <20220906122213.1243129-1-christoph.muellner@vrull.eu> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-11.7 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,JMQ_SPF_NEUTRAL,KAM_MANYTO,RCVD_IN_DNSWL_NONE,SCC_10_SHORT_WORD_LINES,SCC_5_SHORT_WORD_LINES,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: From: Christoph Müllner T-Head has a range of vendor-specific instructions. Therefore it makes sense to group them into smaller chunks in form of vendor extensions. This patch adds the XTheadMemPair extension, a collection of T-Head specific two-GP-register memory operations. The 'th' prefix and the "XTheadMemPair" extension are documented in a PR for the RISC-V toolchain conventions ([1]). [1] https://github.com/riscv-non-isa/riscv-toolchain-conventions/pull/19 Signed-off-by: Christoph Müllner --- bfd/elfxx-riscv.c | 3 ++ gas/doc/c-riscv.texi | 5 ++++ .../gas/riscv/x-thead-mempair-fail.d | 3 ++ .../gas/riscv/x-thead-mempair-fail.l | 30 +++++++++++++++++++ .../gas/riscv/x-thead-mempair-fail.s | 30 +++++++++++++++++++ gas/testsuite/gas/riscv/x-thead-mempair.d | 14 +++++++++ gas/testsuite/gas/riscv/x-thead-mempair.s | 6 ++++ include/opcode/riscv-opc.h | 17 +++++++++++ include/opcode/riscv.h | 1 + opcodes/riscv-opc.c | 24 +++++++++++++++ 10 files changed, 133 insertions(+) create mode 100644 gas/testsuite/gas/riscv/x-thead-mempair-fail.d create mode 100644 gas/testsuite/gas/riscv/x-thead-mempair-fail.l create mode 100644 gas/testsuite/gas/riscv/x-thead-mempair-fail.s create mode 100644 gas/testsuite/gas/riscv/x-thead-mempair.d create mode 100644 gas/testsuite/gas/riscv/x-thead-mempair.s diff --git a/bfd/elfxx-riscv.c b/bfd/elfxx-riscv.c index f64d0e3ab14..bd188a393a3 100644 --- a/bfd/elfxx-riscv.c +++ b/bfd/elfxx-riscv.c @@ -1231,6 +1231,7 @@ static struct riscv_supported_ext riscv_supported_vendor_x_ext[] = {"xtheadfmemidx", ISA_SPEC_CLASS_DRAFT, 1, 0, 0 }, {"xtheadmac", ISA_SPEC_CLASS_DRAFT, 1, 0, 0 }, {"xtheadmemidx", ISA_SPEC_CLASS_DRAFT, 1, 0, 0 }, + {"xtheadmempair", ISA_SPEC_CLASS_DRAFT, 1, 0, 0 }, {"xtheadsync", ISA_SPEC_CLASS_DRAFT, 1, 0, 0 }, {NULL, 0, 0, 0, 0} }; @@ -2410,6 +2411,8 @@ riscv_multi_subset_supports (riscv_parse_subset_t *rps, return riscv_subset_supports (rps, "xtheadmac"); case INSN_CLASS_XTHEADMEMIDX: return riscv_subset_supports (rps, "xtheadmemidx"); + case INSN_CLASS_XTHEADMEMPAIR: + return riscv_subset_supports (rps, "xtheadmempair"); case INSN_CLASS_XTHEADSYNC: return riscv_subset_supports (rps, "xtheadsync"); default: diff --git a/gas/doc/c-riscv.texi b/gas/doc/c-riscv.texi index ed3d98962e4..cc63760cb80 100644 --- a/gas/doc/c-riscv.texi +++ b/gas/doc/c-riscv.texi @@ -744,6 +744,11 @@ The XTheadMemIdx extension provides GPR memory operations. It is documented in @url{https://github.com/T-head-Semi/thead-extension-spec/releases/download/2.0.0/xthead-2022-09-05-2.0.0.pdf}. +@item XTheadMemPair +The XTheadMemPair extension provides two-GP-register memory operations. + +It is documented in @url{https://github.com/T-head-Semi/thead-extension-spec/releases/download/2.0.0/xthead-2022-09-05-2.0.0.pdf}. + @item XTheadSync The XTheadSync extension provides instructions for multi-processor synchronization. diff --git a/gas/testsuite/gas/riscv/x-thead-mempair-fail.d b/gas/testsuite/gas/riscv/x-thead-mempair-fail.d new file mode 100644 index 00000000000..e05f370f082 --- /dev/null +++ b/gas/testsuite/gas/riscv/x-thead-mempair-fail.d @@ -0,0 +1,3 @@ +#as: -march=rv64gc_xtheadmempair +#source: x-thead-mempair-fail.s +#error_output: x-thead-mempair-fail.l diff --git a/gas/testsuite/gas/riscv/x-thead-mempair-fail.l b/gas/testsuite/gas/riscv/x-thead-mempair-fail.l new file mode 100644 index 00000000000..32d98f47501 --- /dev/null +++ b/gas/testsuite/gas/riscv/x-thead-mempair-fail.l @@ -0,0 +1,30 @@ +.*: Assembler messages: +.*: Error: illegal operands `th.ldd a0,a1,\(a2\),0' +.*: Error: illegal operands `th.lwd a0,a1,\(a2\),1' +.*: Error: illegal operands `th.lwud a0,a1,\(a2\),2' +.*: Error: illegal operands `th.sdd a0,a1,\(a2\),3' +.*: Error: illegal operands `th.swd a0,a1,\(a2\),0' + +.*: Error: improper immediate value \(18446744073709551615\) +.*: Error: improper immediate value \(4\) +.*: Error: unexpected literal \(3\) + +.*: Error: improper immediate value \(18446744073709551615\) +.*: Error: improper immediate value \(4\) +.*: Error: unexpected literal \(4\) + +.*: Error: improper immediate value \(18446744073709551615\) +.*: Error: improper immediate value \(4\) +.*: Error: unexpected literal \(4\) + +.*: Error: improper immediate value \(18446744073709551615\) +.*: Error: improper immediate value \(4\) +.*: Error: unexpected literal \(3\) + +.*: Error: improper immediate value \(18446744073709551615\) +.*: Error: improper immediate value \(4\) +.*: Error: unexpected literal \(4\) + +.*: Error: illegal operands `th.ldd a0,a0,\(a1\),0' +.*: Error: illegal operands `th.ldd a0,a1,\(a0\),0' +.*: Error: illegal operands `th.ldd a1,a0,\(a0\),0' diff --git a/gas/testsuite/gas/riscv/x-thead-mempair-fail.s b/gas/testsuite/gas/riscv/x-thead-mempair-fail.s new file mode 100644 index 00000000000..5936ea70fed --- /dev/null +++ b/gas/testsuite/gas/riscv/x-thead-mempair-fail.s @@ -0,0 +1,30 @@ +target: + th.ldd a0, a1, (a2), 0 + th.lwd a0, a1, (a2), 1 + th.lwud a0, a1, (a2), 2 + th.sdd a0, a1, (a2), 3 + th.swd a0, a1, (a2), 0 + + th.ldd a0, a1, (a2), -1, 4 + th.ldd a0, a1, (a2), 4, 4 + th.ldd a0, a1, (a2), 0, 3 + + th.lwd a0, a1, (a2), -1, 3 + th.lwd a0, a1, (a2), 4, 3 + th.lwd a0, a1, (a2), 0, 4 + + th.lwud a0, a1, (a2), -1, 3 + th.lwud a0, a1, (a2), 4, 3 + th.lwud a0, a1, (a2), 0, 4 + + th.sdd a0, a1, (a2), -1, 4 + th.sdd a0, a1, (a2), 4, 4 + th.sdd a0, a1, (a2), 0, 3 + + th.swd a0, a1, (a2), -1, 3 + th.swd a0, a1, (a2), 4, 3 + th.swd a0, a1, (a2), 0, 4 + + th.ldd a0, a0, (a1), 0 + th.ldd a0, a1, (a0), 0 + th.ldd a1, a0, (a0), 0 diff --git a/gas/testsuite/gas/riscv/x-thead-mempair.d b/gas/testsuite/gas/riscv/x-thead-mempair.d new file mode 100644 index 00000000000..8f62044e9b7 --- /dev/null +++ b/gas/testsuite/gas/riscv/x-thead-mempair.d @@ -0,0 +1,14 @@ +#as: -march=rv64gc_xtheadmempair +#source: x-thead-mempair.s +#objdump: -dr + +.*:[ ]+file format .* + +Disassembly of section .text: + +0+000 : +[ ]+[0-9a-f]+:[ ]+f8b6450b[ ]+th.ldd[ ]+a0,a1,\(a2\),0,4 +[ ]+[0-9a-f]+:[ ]+e2b6450b[ ]+th.lwd[ ]+a0,a1,\(a2\),1,3 +[ ]+[0-9a-f]+:[ ]+f4b6450b[ ]+th.lwud[ ]+a0,a1,\(a2\),2,3 +[ ]+[0-9a-f]+:[ ]+feb6550b[ ]+th.sdd[ ]+a0,a1,\(a2\),3,4 +[ ]+[0-9a-f]+:[ ]+e0b6550b[ ]+th.swd[ ]+a0,a1,\(a2\),0,3 diff --git a/gas/testsuite/gas/riscv/x-thead-mempair.s b/gas/testsuite/gas/riscv/x-thead-mempair.s new file mode 100644 index 00000000000..4ee203971fa --- /dev/null +++ b/gas/testsuite/gas/riscv/x-thead-mempair.s @@ -0,0 +1,6 @@ +target: + th.ldd a0, a1, (a2), 0, 4 + th.lwd a0, a1, (a2), 1, 3 + th.lwud a0, a1, (a2), 2, 3 + th.sdd a0, a1, (a2), 3, 4 + th.swd a0, a1, (a2), 0, 3 diff --git a/include/opcode/riscv-opc.h b/include/opcode/riscv-opc.h index ab87be248f4..43a6bef5863 100644 --- a/include/opcode/riscv-opc.h +++ b/include/opcode/riscv-opc.h @@ -2216,6 +2216,17 @@ #define MASK_TH_MULSH 0xfe00707f #define MATCH_TH_MULSW 0x2600100b #define MASK_TH_MULSW 0xfe00707f +/* Vendor-specific (T-Head) XTheadMemPair instructions. */ +#define MATCH_TH_LDD 0xf800400b +#define MASK_TH_LDD 0xf800707f +#define MATCH_TH_LWD 0xe000400b +#define MASK_TH_LWD 0xf800707f +#define MATCH_TH_LWUD 0xf000400b +#define MASK_TH_LWUD 0xf800707f +#define MATCH_TH_SDD 0xf800500b +#define MASK_TH_SDD 0xf800707f +#define MATCH_TH_SWD 0xe000500b +#define MASK_TH_SWD 0xf800707f /* Vendor-specific (T-Head) XTheadMemIdx instructions. */ #define MATCH_TH_LDIA 0x7800400b #define MASK_TH_LDIA 0xf800707f @@ -3155,6 +3166,12 @@ DECLARE_INSN(th_surd, MATCH_TH_SURD, MASK_TH_SURD) DECLARE_INSN(th_surw, MATCH_TH_SURW, MASK_TH_SURW) DECLARE_INSN(th_surh, MATCH_TH_SURH, MASK_TH_SURH) DECLARE_INSN(th_surb, MATCH_TH_SURB, MASK_TH_SURB) +/* Vendor-specific (T-Head) XTheadMemPair instructions. */ +DECLARE_INSN(th_ldd, MATCH_TH_LDD, MASK_TH_LDD) +DECLARE_INSN(th_lwd, MATCH_TH_LWD, MASK_TH_LWD) +DECLARE_INSN(th_lwud, MATCH_TH_LWUD, MASK_TH_LWUD) +DECLARE_INSN(th_sdd, MATCH_TH_SDD, MASK_TH_SDD) +DECLARE_INSN(th_swd, MATCH_TH_SWD, MASK_TH_SWD) /* Vendor-specific (T-Head) XTheadSync instructions. */ DECLARE_INSN(th_sfence_vmas, MATCH_TH_SFENCE_VMAS, MASK_TH_SFENCE_VMAS) DECLARE_INSN(th_sync, MATCH_TH_SYNC, MASK_TH_SYNC) diff --git a/include/opcode/riscv.h b/include/opcode/riscv.h index 2546d6ce8d5..1b329ef1557 100644 --- a/include/opcode/riscv.h +++ b/include/opcode/riscv.h @@ -423,6 +423,7 @@ enum riscv_insn_class INSN_CLASS_XTHEADFMEMIDX, INSN_CLASS_XTHEADMAC, INSN_CLASS_XTHEADMEMIDX, + INSN_CLASS_XTHEADMEMPAIR, INSN_CLASS_XTHEADSYNC, }; diff --git a/opcodes/riscv-opc.c b/opcodes/riscv-opc.c index 5aed98c1003..0c0db9fd021 100644 --- a/opcodes/riscv-opc.c +++ b/opcodes/riscv-opc.c @@ -278,6 +278,23 @@ match_th_load_inc(const struct riscv_opcode *op, return rd != rs1 && match_opcode (op, insn); } +static int +match_th_load_pair(const struct riscv_opcode *op, + insn_t insn) +{ + /* Load pair instructions use the following encoding: + * - rd1 = RD (insn[11:7]) + * - rd2 = RS2 (insn[24:20]) + * - rs = RS1 ([19:15]) + * This function matches if the following restriction is met: + * The values of rd1, rd2, and rs1 must not be the same. */ + int rd1 = (insn & MASK_RD) >> OP_SH_RD; + int rd2 = (insn & MASK_RS2) >> OP_SH_RS2; + int rs = (insn & MASK_RS1) >> OP_SH_RS1; + + return rd1 != rd2 && rd1 != rs && rd2 != rs && match_opcode (op, insn); +} + const struct riscv_opcode riscv_opcodes[] = { /* name, xlen, isa, operands, match, mask, match_func, pinfo. */ @@ -1941,6 +1958,13 @@ const struct riscv_opcode riscv_opcodes[] = {"th.surh", 0, INSN_CLASS_XTHEADMEMIDX, "d,s,t,Xu2@25", MATCH_TH_SURH, MASK_TH_SURH, match_opcode, 0}, {"th.surb", 0, INSN_CLASS_XTHEADMEMIDX, "d,s,t,Xu2@25", MATCH_TH_SURB, MASK_TH_SURB, match_opcode, 0}, +/* Vendor-specific (T-Head) XTheadMemPair instructions. */ +{"th.ldd", 64, INSN_CLASS_XTHEADMEMPAIR, "d,t,(s),Xu2@25,L4", MATCH_TH_LDD, MASK_TH_LDD, match_th_load_pair, 0}, +{"th.lwd", 0, INSN_CLASS_XTHEADMEMPAIR, "d,t,(s),Xu2@25,L3", MATCH_TH_LWD, MASK_TH_LWD, match_th_load_pair, 0}, +{"th.lwud", 0, INSN_CLASS_XTHEADMEMPAIR, "d,t,(s),Xu2@25,L3", MATCH_TH_LWUD, MASK_TH_LWUD, match_th_load_pair, 0}, +{"th.sdd", 64, INSN_CLASS_XTHEADMEMPAIR, "d,t,(s),Xu2@25,L4", MATCH_TH_SDD, MASK_TH_SDD, match_opcode, 0}, +{"th.swd", 0, INSN_CLASS_XTHEADMEMPAIR, "d,t,(s),Xu2@25,L3", MATCH_TH_SWD, MASK_TH_SWD, match_opcode, 0}, + /* Vendor-specific (T-Head) XTheadMac instructions. */ {"th.mula", 0, INSN_CLASS_XTHEADMAC, "d,s,t", MATCH_TH_MULA, MASK_TH_MULA, match_opcode, 0}, {"th.mulah", 0, INSN_CLASS_XTHEADMAC, "d,s,t", MATCH_TH_MULAH, MASK_TH_MULAH, match_opcode, 0}, -- 2.37.2