Skip to content

Commit

Permalink
UNRATIFIED RISC-V: Add 'ZiCond' extension
Browse files Browse the repository at this point in the history
[DO NOT MERGE]
Until 'ZiCond' extension is frozen/ratified and final version number is
determined, this patch should not be merged upstream.  This commit uses
version 1.0 as in the documentation.

This commit adds support for the latest draft of RISC-V Integer Conditional
(ZiCond) extension consisting of 2 new instructions.

This is based on the early draft of 'ZiCond' extension on GitHub:
<riscvarchive/riscv-zicond@e05301d>

bfd/ChangeLog:

	* elfxx-riscv.c (riscv_supported_std_z_ext): Add 'ZiCond'.
	(riscv_multi_subset_supports): Support new instruction class.
	(riscv_multi_subset_supports_ext): Likewise.

gas/ChangeLog:

	* testsuite/gas/riscv/zicond.s: New test for 'ZiCond'.
	* testsuite/gas/riscv/zicond.d: Likewise.
	* testsuite/gas/riscv/zicond-noarch.d: New test for
	architecture failure.
	* testsuite/gas/riscv/zicond-noarch.l: Likewise.

include/ChangeLog:

	* opcode/riscv-opc.h (MATCH_CZERO_EQZ, MASK_CZERO_EQZ,
	MATCH_CZERO_NEZ, MASK_CZERO_NEZ): New.
	* opcode/riscv.h (enum riscv_insn_class): Add new instruction
	class INSN_CLASS_ZICOND.

opcodes/ChangeLog:

	* riscv-opc.c (riscv_opcodes): Add new instructions from the
	'ZiCond' extension.
  • Loading branch information
a4lg committed Feb 8, 2023
1 parent 4170bc7 commit dcc2ddb
Show file tree
Hide file tree
Showing 8 changed files with 38 additions and 0 deletions.
5 changes: 5 additions & 0 deletions bfd/elfxx-riscv.c
Original file line number Diff line number Diff line change
Expand Up @@ -1168,6 +1168,7 @@ static struct riscv_supported_ext riscv_supported_std_z_ext[] =
{"zicbom", ISA_SPEC_CLASS_DRAFT, 1, 0, 0 },
{"zicbop", ISA_SPEC_CLASS_DRAFT, 1, 0, 0 },
{"zicboz", ISA_SPEC_CLASS_DRAFT, 1, 0, 0 },
{"zicond", ISA_SPEC_CLASS_DRAFT, 1, 0, 0 },
{"zicsr", ISA_SPEC_CLASS_20191213, 2, 0, 0 },
{"zicsr", ISA_SPEC_CLASS_20190608, 2, 0, 0 },
{"zifencei", ISA_SPEC_CLASS_20191213, 2, 0, 0 },
Expand Down Expand Up @@ -2258,6 +2259,8 @@ riscv_multi_subset_supports (riscv_parse_subset_t *rps,
return riscv_subset_supports (rps, "zicbop");
case INSN_CLASS_ZICBOZ:
return riscv_subset_supports (rps, "zicboz");
case INSN_CLASS_ZICOND:
return riscv_subset_supports (rps, "zicond");
case INSN_CLASS_ZICSR:
return riscv_subset_supports (rps, "zicsr");
case INSN_CLASS_ZIFENCEI:
Expand Down Expand Up @@ -2407,6 +2410,8 @@ riscv_multi_subset_supports_ext (riscv_parse_subset_t *rps,
return "zicbop";
case INSN_CLASS_ZICBOZ:
return "zicboz";
case INSN_CLASS_ZICOND:
return "zicond";
case INSN_CLASS_ZICSR:
return "zicsr";
case INSN_CLASS_ZIFENCEI:
Expand Down
3 changes: 3 additions & 0 deletions gas/testsuite/gas/riscv/zicond-noarch.d
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#as: -march=rv32i
#source: zicond.s
#error_output: zicond-noarch.l
3 changes: 3 additions & 0 deletions gas/testsuite/gas/riscv/zicond-noarch.l
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.*: Assembler messages:
.*: Error: unrecognized opcode `czero\.eqz a0,a1,a2', extension `zicond' required
.*: Error: unrecognized opcode `czero\.nez a3,a4,a5', extension `zicond' required
11 changes: 11 additions & 0 deletions gas/testsuite/gas/riscv/zicond.d
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#as: -march=rv32i_zicond
#source: zicond.s
#objdump: -d

.*:[ ]+file format .*

Disassembly of section .text:

0+000 <target>:
[ ]+[0-9a-f]+:[ ]+0ec5d533[ ]+czero\.eqz[ ]+a0,a1,a2
[ ]+[0-9a-f]+:[ ]+0ef776b3[ ]+czero\.nez[ ]+a3,a4,a5
3 changes: 3 additions & 0 deletions gas/testsuite/gas/riscv/zicond.s
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
target:
czero.eqz a0, a1, a2
czero.nez a3, a4, a5
8 changes: 8 additions & 0 deletions include/opcode/riscv-opc.h
Original file line number Diff line number Diff line change
Expand Up @@ -2113,6 +2113,11 @@
#define MASK_CBO_INVAL 0xfff07fff
#define MATCH_CBO_ZERO 0x40200f
#define MASK_CBO_ZERO 0xfff07fff
/* ZiCond instructions. */
#define MATCH_CZERO_EQZ 0xe005033
#define MASK_CZERO_EQZ 0xfe00707f
#define MATCH_CZERO_NEZ 0xe007033
#define MASK_CZERO_NEZ 0xfe00707f
/* Zawrs intructions. */
#define MATCH_WRS_NTO 0x00d00073
#define MASK_WRS_NTO 0xffffffff
Expand Down Expand Up @@ -3115,6 +3120,9 @@ DECLARE_INSN(cbo_clean, MATCH_CBO_CLEAN, MASK_CBO_CLEAN);
DECLARE_INSN(cbo_flush, MATCH_CBO_FLUSH, MASK_CBO_FLUSH);
DECLARE_INSN(cbo_inval, MATCH_CBO_INVAL, MASK_CBO_INVAL);
DECLARE_INSN(cbo_zero, MATCH_CBO_ZERO, MASK_CBO_ZERO);
/* ZiCond instructions. */
DECLARE_INSN(czero_eqz, MATCH_CZERO_EQZ, MASK_CZERO_EQZ)
DECLARE_INSN(czero_nez, MATCH_CZERO_NEZ, MASK_CZERO_NEZ)
/* Zawrs instructions. */
DECLARE_INSN(wrs_nto, MATCH_WRS_NTO, MASK_WRS_NTO)
DECLARE_INSN(wrs_sto, MATCH_WRS_STO, MASK_WRS_STO)
Expand Down
1 change: 1 addition & 0 deletions include/opcode/riscv.h
Original file line number Diff line number Diff line change
Expand Up @@ -375,6 +375,7 @@ enum riscv_insn_class
INSN_CLASS_Q,
INSN_CLASS_F_AND_C,
INSN_CLASS_D_AND_C,
INSN_CLASS_ZICOND,
INSN_CLASS_ZICSR,
INSN_CLASS_ZIFENCEI,
INSN_CLASS_ZIHINTPAUSE,
Expand Down
4 changes: 4 additions & 0 deletions opcodes/riscv-opc.c
Original file line number Diff line number Diff line change
Expand Up @@ -935,6 +935,10 @@ const struct riscv_opcode riscv_opcodes[] =
{"cbo.inval", 0, INSN_CLASS_ZICBOM, "0(s)", MATCH_CBO_INVAL, MASK_CBO_INVAL, match_opcode, 0 },
{"cbo.zero", 0, INSN_CLASS_ZICBOZ, "0(s)", MATCH_CBO_ZERO, MASK_CBO_ZERO, match_opcode, 0 },

/* ZiCond instructions. */
{"czero.eqz", 0, INSN_CLASS_ZICOND, "d,s,t", MATCH_CZERO_EQZ, MASK_CZERO_EQZ, match_opcode, 0 },
{"czero.nez", 0, INSN_CLASS_ZICOND, "d,s,t", MATCH_CZERO_NEZ, MASK_CZERO_NEZ, match_opcode, 0 },

/* Zawrs instructions. */
{"wrs.nto", 0, INSN_CLASS_ZAWRS, "", MATCH_WRS_NTO, MASK_WRS_NTO, match_opcode, 0 },
{"wrs.sto", 0, INSN_CLASS_ZAWRS, "", MATCH_WRS_STO, MASK_WRS_STO, match_opcode, 0 },
Expand Down

0 comments on commit dcc2ddb

Please sign in to comment.