Skip to content

Commit fb14b6b

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 4df8b30 commit fb14b6b

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},
@@ -1323,6 +1324,7 @@ static struct riscv_supported_ext riscv_supported_std_z_ext[] =
13231324
{"zcb", ISA_SPEC_CLASS_DRAFT, 1, 0, 0 },
13241325
{"zcf", ISA_SPEC_CLASS_DRAFT, 1, 0, 0 },
13251326
{"zcd", ISA_SPEC_CLASS_DRAFT, 1, 0, 0 },
1327+
{"zcmop", ISA_SPEC_CLASS_DRAFT, 0, 1, 0 },
13261328
{NULL, 0, 0, 0, 0}
13271329
};
13281330

@@ -2538,6 +2540,8 @@ riscv_multi_subset_supports (riscv_parse_subset_t *rps,
25382540
case INSN_CLASS_ZCB_AND_ZMMUL:
25392541
return (riscv_subset_supports (rps, "zcb")
25402542
&& riscv_subset_supports (rps, "zmmul"));
2543+
case INSN_CLASS_ZCMOP:
2544+
return riscv_subset_supports (rps, "zcmop");
25412545
case INSN_CLASS_SVINVAL:
25422546
return riscv_subset_supports (rps, "svinval");
25432547
case INSN_CLASS_H:
@@ -2780,6 +2784,8 @@ riscv_multi_subset_supports_ext (riscv_parse_subset_t *rps,
27802784
return _("zcb' and `zbb");
27812785
case INSN_CLASS_ZCB_AND_ZMMUL:
27822786
return _("zcb' and `zmmul', or `zcb' and `m");
2787+
case INSN_CLASS_ZCMOP:
2788+
return "zcmop";
27832789
case INSN_CLASS_SVINVAL:
27842790
return "svinval";
27852791
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
@@ -2401,6 +2401,23 @@
24012401
#define MASK_WRS_NTO 0xffffffff
24022402
#define MATCH_WRS_STO 0x01d00073
24032403
#define MASK_WRS_STO 0xffffffff
2404+
/* Zcmop "may be" operations. */
2405+
#define MATCH_C_MOP_0 0x6081
2406+
#define MASK_C_MOP_0 0xffff
2407+
#define MATCH_C_MOP_1 0x6181
2408+
#define MASK_C_MOP_1 0xffff
2409+
#define MATCH_C_MOP_2 0x6281
2410+
#define MASK_C_MOP_2 0xffff
2411+
#define MATCH_C_MOP_3 0x6381
2412+
#define MASK_C_MOP_3 0xffff
2413+
#define MATCH_C_MOP_4 0x6481
2414+
#define MASK_C_MOP_4 0xffff
2415+
#define MATCH_C_MOP_5 0x6581
2416+
#define MASK_C_MOP_5 0xffff
2417+
#define MATCH_C_MOP_6 0x6681
2418+
#define MASK_C_MOP_6 0xffff
2419+
#define MATCH_C_MOP_7 0x6781
2420+
#define MASK_C_MOP_7 0xffff
24042421
/* Vendor-specific (T-Head) XTheadBa instructions. */
24052422
#define MATCH_TH_ADDSL 0x0000100b
24062423
#define MASK_TH_ADDSL 0xf800707f
@@ -3553,6 +3570,15 @@ DECLARE_INSN(c_lhu, MATCH_C_LHU, MASK_C_LHU)
35533570
DECLARE_INSN(c_lh, MATCH_C_LH, MASK_C_LH)
35543571
DECLARE_INSN(c_sb, MATCH_C_SB, MASK_C_SB)
35553572
DECLARE_INSN(c_sh, MATCH_C_SH, MASK_C_SH)
3573+
/* Zcmop "may be" operations. */
3574+
DECLARE_INSN(c_mop_0, MATCH_C_MOP_0, MASK_C_MOP_0)
3575+
DECLARE_INSN(c_mop_1, MATCH_C_MOP_1, MASK_C_MOP_1)
3576+
DECLARE_INSN(c_mop_2, MATCH_C_MOP_2, MASK_C_MOP_2)
3577+
DECLARE_INSN(c_mop_3, MATCH_C_MOP_3, MASK_C_MOP_3)
3578+
DECLARE_INSN(c_mop_4, MATCH_C_MOP_4, MASK_C_MOP_4)
3579+
DECLARE_INSN(c_mop_5, MATCH_C_MOP_5, MASK_C_MOP_5)
3580+
DECLARE_INSN(c_mop_6, MATCH_C_MOP_6, MASK_C_MOP_6)
3581+
DECLARE_INSN(c_mop_7, MATCH_C_MOP_7, MASK_C_MOP_7)
35563582
/* Vendor-specific (T-Head) XTheadBa instructions. */
35573583
DECLARE_INSN(th_addsl, MATCH_TH_ADDSL, MASK_TH_ADDSL)
35583584
/* Vendor-specific (T-Head) XTheadBb instructions. */

include/opcode/riscv.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -439,6 +439,7 @@ enum riscv_insn_class
439439
INSN_CLASS_ZCB_AND_ZBA,
440440
INSN_CLASS_ZCB_AND_ZBB,
441441
INSN_CLASS_ZCB_AND_ZMMUL,
442+
INSN_CLASS_ZCMOP,
442443
INSN_CLASS_SVINVAL,
443444
INSN_CLASS_ZICBOM,
444445
INSN_CLASS_ZICBOP,

opcodes/riscv-opc.c

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

2024+
/* Zcmop "may be" operations. */
2025+
{"c.mop.0", 0, INSN_CLASS_ZCMOP, "", MATCH_C_MOP_0, MASK_C_MOP_0, match_opcode, 0 },
2026+
{"c.mop.1", 0, INSN_CLASS_ZCMOP, "", MATCH_C_MOP_1, MASK_C_MOP_1, match_opcode, 0 },
2027+
{"c.mop.2", 0, INSN_CLASS_ZCMOP, "", MATCH_C_MOP_2, MASK_C_MOP_2, match_opcode, 0 },
2028+
{"c.mop.3", 0, INSN_CLASS_ZCMOP, "", MATCH_C_MOP_3, MASK_C_MOP_3, match_opcode, 0 },
2029+
{"c.mop.4", 0, INSN_CLASS_ZCMOP, "", MATCH_C_MOP_4, MASK_C_MOP_4, match_opcode, 0 },
2030+
{"c.mop.5", 0, INSN_CLASS_ZCMOP, "", MATCH_C_MOP_5, MASK_C_MOP_5, match_opcode, 0 },
2031+
{"c.mop.6", 0, INSN_CLASS_ZCMOP, "", MATCH_C_MOP_6, MASK_C_MOP_6, match_opcode, 0 },
2032+
{"c.mop.7", 0, INSN_CLASS_ZCMOP, "", MATCH_C_MOP_7, MASK_C_MOP_7, match_opcode, 0 },
2033+
20242034
/* Supervisor instructions. */
20252035
{"csrr", 0, INSN_CLASS_ZICSR, "d,E", MATCH_CSRRS, MASK_CSRRS|MASK_RS1, match_opcode, INSN_ALIAS },
20262036
{"csrw", 0, INSN_CLASS_ZICSR, "E,s", MATCH_CSRRW, MASK_CSRRW|MASK_RD, match_opcode, INSN_ALIAS },

0 commit comments

Comments
 (0)