Skip to content

Commit 99bf60a

Browse files
committed
UNRATIFIED RISC-V: Add 'Zcmop' extension
[DO NOT MERGE] Until the 'Zcmop' extension is frozen/ratified and final version number is determined, this patch should not be merged upstream. This commit uses version 0.1 as a placeholder. This commit adds support for the compressed "May Be Operations (MOP)" (Zcmop) extension which adds 8 compressed MOP instructions. By default, they are the same as NOP. However, if certain feature is supported (and optionally enabled), it is allowed to alter architectural state unlike HINT instructions. This commit is based on the TENTATIVE specification: <riscv/riscv-cfi#131> bfd/ChangeLog: * elfxx-riscv.c (riscv_implicit_subsets): Add 'Zcmop' -> 'Zca' implication. (riscv_supported_std_z_ext): Add 'Zcmop'. (riscv_multi_subset_supports): Support new instruction class. (riscv_multi_subset_supports_ext): Likewise. gas/ChangeLog: * testsuite/gas/riscv/zcmop.s: New test for 'Zcmop'. * testsuite/gas/riscv/zcmop.d: Likewise. include/ChangeLog: * opcode/riscv-opc.h ( MATCH_C_MOP_0, MASK_C_MOP_0, MATCH_C_MOP_1, MASK_C_MOP_1, MATCH_C_MOP_2, MASK_C_MOP_2, MATCH_C_MOP_3, MASK_C_MOP_3, MATCH_C_MOP_4, MASK_C_MOP_4, MATCH_C_MOP_5, MASK_C_MOP_5, MATCH_C_MOP_6, MASK_C_MOP_6, MATCH_C_MOP_7, MASK_C_MOP_7): New. * opcode/riscv.h (enum riscv_insn_class): Add new instruction class INSN_CLASS_ZCMOP. opcodes/ChangeLog: * riscv-opc.c (riscv_opcodes): Add new "may be" operations from the 'Zcmop' extension near the bottom.
1 parent 8cd0e4e commit 99bf60a

File tree

6 files changed

+68
-0
lines changed

6 files changed

+68
-0
lines changed

bfd/elfxx-riscv.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1182,6 +1182,7 @@ static struct riscv_implicit_subset riscv_implicit_subsets[] =
11821182
{"zcf", "zca", check_implicit_always},
11831183
{"zcd", "zca", check_implicit_always},
11841184
{"zcb", "zca", check_implicit_always},
1185+
{"zcmop", "zca", check_implicit_always},
11851186
{"smaia", "ssaia", check_implicit_always},
11861187
{"smstateen", "ssstateen", check_implicit_always},
11871188
{"smepmp", "zicsr", check_implicit_always},
@@ -1322,6 +1323,7 @@ static struct riscv_supported_ext riscv_supported_std_z_ext[] =
13221323
{"zcb", ISA_SPEC_CLASS_DRAFT, 1, 0, 0 },
13231324
{"zcf", ISA_SPEC_CLASS_DRAFT, 1, 0, 0 },
13241325
{"zcd", ISA_SPEC_CLASS_DRAFT, 1, 0, 0 },
1326+
{"zcmop", ISA_SPEC_CLASS_DRAFT, 0, 1, 0 },
13251327
{NULL, 0, 0, 0, 0}
13261328
};
13271329

@@ -2527,6 +2529,8 @@ riscv_multi_subset_supports (riscv_parse_subset_t *rps,
25272529
case INSN_CLASS_ZCB_AND_ZMMUL:
25282530
return (riscv_subset_supports (rps, "zcb")
25292531
&& riscv_subset_supports (rps, "zmmul"));
2532+
case INSN_CLASS_ZCMOP:
2533+
return riscv_subset_supports (rps, "zcmop");
25302534
case INSN_CLASS_SVINVAL:
25312535
return riscv_subset_supports (rps, "svinval");
25322536
case INSN_CLASS_H:
@@ -2745,6 +2749,8 @@ riscv_multi_subset_supports_ext (riscv_parse_subset_t *rps,
27452749
return _("zcb' and `zbb");
27462750
case INSN_CLASS_ZCB_AND_ZMMUL:
27472751
return _("zcb' and `zmmul', or `zcb' and `m");
2752+
case INSN_CLASS_ZCMOP:
2753+
return "zcmop";
27482754
case INSN_CLASS_SVINVAL:
27492755
return "svinval";
27502756
case INSN_CLASS_H:

gas/testsuite/gas/riscv/zcmop.d

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#as: -march=rv32i_zcmop
2+
#objdump: -d
3+
4+
.*:[ ]+file format .*
5+
6+
Disassembly of section .text:
7+
8+
0+000 <target>:
9+
[ ]+[0-9a-f]+:[ ]+6081[ ]+c\.mop\.0
10+
[ ]+[0-9a-f]+:[ ]+6181[ ]+c\.mop\.1
11+
[ ]+[0-9a-f]+:[ ]+6281[ ]+c\.mop\.2
12+
[ ]+[0-9a-f]+:[ ]+6381[ ]+c\.mop\.3
13+
[ ]+[0-9a-f]+:[ ]+6481[ ]+c\.mop\.4
14+
[ ]+[0-9a-f]+:[ ]+6581[ ]+c\.mop\.5
15+
[ ]+[0-9a-f]+:[ ]+6681[ ]+c\.mop\.6
16+
[ ]+[0-9a-f]+:[ ]+6781[ ]+c\.mop\.7

gas/testsuite/gas/riscv/zcmop.s

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
target:
2+
c.mop.0
3+
c.mop.1
4+
c.mop.2
5+
c.mop.3
6+
c.mop.4
7+
c.mop.5
8+
c.mop.6
9+
c.mop.7

include/opcode/riscv-opc.h

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2384,6 +2384,23 @@
23842384
#define MASK_WRS_NTO 0xffffffff
23852385
#define MATCH_WRS_STO 0x01d00073
23862386
#define MASK_WRS_STO 0xffffffff
2387+
/* Zcmop "may be" operations. */
2388+
#define MATCH_C_MOP_0 0x6081
2389+
#define MASK_C_MOP_0 0xffff
2390+
#define MATCH_C_MOP_1 0x6181
2391+
#define MASK_C_MOP_1 0xffff
2392+
#define MATCH_C_MOP_2 0x6281
2393+
#define MASK_C_MOP_2 0xffff
2394+
#define MATCH_C_MOP_3 0x6381
2395+
#define MASK_C_MOP_3 0xffff
2396+
#define MATCH_C_MOP_4 0x6481
2397+
#define MASK_C_MOP_4 0xffff
2398+
#define MATCH_C_MOP_5 0x6581
2399+
#define MASK_C_MOP_5 0xffff
2400+
#define MATCH_C_MOP_6 0x6681
2401+
#define MASK_C_MOP_6 0xffff
2402+
#define MATCH_C_MOP_7 0x6781
2403+
#define MASK_C_MOP_7 0xffff
23872404
/* Vendor-specific (T-Head) XTheadBa instructions. */
23882405
#define MATCH_TH_ADDSL 0x0000100b
23892406
#define MASK_TH_ADDSL 0xf800707f
@@ -3527,6 +3544,15 @@ DECLARE_INSN(c_lhu, MATCH_C_LHU, MASK_C_LHU)
35273544
DECLARE_INSN(c_lh, MATCH_C_LH, MASK_C_LH)
35283545
DECLARE_INSN(c_sb, MATCH_C_SB, MASK_C_SB)
35293546
DECLARE_INSN(c_sh, MATCH_C_SH, MASK_C_SH)
3547+
/* Zcmop "may be" operations. */
3548+
DECLARE_INSN(c_mop_0, MATCH_C_MOP_0, MASK_C_MOP_0)
3549+
DECLARE_INSN(c_mop_1, MATCH_C_MOP_1, MASK_C_MOP_1)
3550+
DECLARE_INSN(c_mop_2, MATCH_C_MOP_2, MASK_C_MOP_2)
3551+
DECLARE_INSN(c_mop_3, MATCH_C_MOP_3, MASK_C_MOP_3)
3552+
DECLARE_INSN(c_mop_4, MATCH_C_MOP_4, MASK_C_MOP_4)
3553+
DECLARE_INSN(c_mop_5, MATCH_C_MOP_5, MASK_C_MOP_5)
3554+
DECLARE_INSN(c_mop_6, MATCH_C_MOP_6, MASK_C_MOP_6)
3555+
DECLARE_INSN(c_mop_7, MATCH_C_MOP_7, MASK_C_MOP_7)
35303556
/* Vendor-specific (T-Head) XTheadBa instructions. */
35313557
DECLARE_INSN(th_addsl, MATCH_TH_ADDSL, MASK_TH_ADDSL)
35323558
/* Vendor-specific (T-Head) XTheadBb instructions. */

include/opcode/riscv.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -436,6 +436,7 @@ enum riscv_insn_class
436436
INSN_CLASS_ZCB_AND_ZBA,
437437
INSN_CLASS_ZCB_AND_ZBB,
438438
INSN_CLASS_ZCB_AND_ZMMUL,
439+
INSN_CLASS_ZCMOP,
439440
INSN_CLASS_SVINVAL,
440441
INSN_CLASS_ZICBOM,
441442
INSN_CLASS_ZICBOP,

opcodes/riscv-opc.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2009,6 +2009,16 @@ const struct riscv_opcode riscv_opcodes[] =
20092009
{"mop.rr.6", 0, INSN_CLASS_ZIMOP, "d,s,t", MATCH_MOP_RR_6, MASK_MOP_RR_6, match_opcode, 0 },
20102010
{"mop.rr.7", 0, INSN_CLASS_ZIMOP, "d,s,t", MATCH_MOP_RR_7, MASK_MOP_RR_7, match_opcode, 0 },
20112011

2012+
/* Zcmop "may be" operations. */
2013+
{"c.mop.0", 0, INSN_CLASS_ZCMOP, "", MATCH_C_MOP_0, MASK_C_MOP_0, match_opcode, 0 },
2014+
{"c.mop.1", 0, INSN_CLASS_ZCMOP, "", MATCH_C_MOP_1, MASK_C_MOP_1, match_opcode, 0 },
2015+
{"c.mop.2", 0, INSN_CLASS_ZCMOP, "", MATCH_C_MOP_2, MASK_C_MOP_2, match_opcode, 0 },
2016+
{"c.mop.3", 0, INSN_CLASS_ZCMOP, "", MATCH_C_MOP_3, MASK_C_MOP_3, match_opcode, 0 },
2017+
{"c.mop.4", 0, INSN_CLASS_ZCMOP, "", MATCH_C_MOP_4, MASK_C_MOP_4, match_opcode, 0 },
2018+
{"c.mop.5", 0, INSN_CLASS_ZCMOP, "", MATCH_C_MOP_5, MASK_C_MOP_5, match_opcode, 0 },
2019+
{"c.mop.6", 0, INSN_CLASS_ZCMOP, "", MATCH_C_MOP_6, MASK_C_MOP_6, match_opcode, 0 },
2020+
{"c.mop.7", 0, INSN_CLASS_ZCMOP, "", MATCH_C_MOP_7, MASK_C_MOP_7, match_opcode, 0 },
2021+
20122022
/* Supervisor instructions. */
20132023
{"csrr", 0, INSN_CLASS_ZICSR, "d,E", MATCH_CSRRS, MASK_CSRRS|MASK_RS1, match_opcode, INSN_ALIAS },
20142024
{"csrw", 0, INSN_CLASS_ZICSR, "E,s", MATCH_CSRRW, MASK_CSRRW|MASK_RD, match_opcode, INSN_ALIAS },

0 commit comments

Comments
 (0)