Skip to content

Commit c33a6f1

Browse files
authored
Merge pull request #206 from ptomsich/vrull/zicond
Add support for the Zicond extension
2 parents 4950e0d + 775188f commit c33a6f1

4 files changed

Lines changed: 43 additions & 2 deletions

File tree

Makefile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ SAIL_DEFAULT_INST += riscv_insts_zks.sail
3636
SAIL_DEFAULT_INST += riscv_insts_zbkb.sail
3737
SAIL_DEFAULT_INST += riscv_insts_zbkx.sail
3838

39+
SAIL_DEFAULT_INST += riscv_insts_zicond.sail
40+
3941
SAIL_SEQ_INST = $(SAIL_DEFAULT_INST) riscv_jalr_seq.sail
4042
SAIL_RMEM_INST = $(SAIL_DEFAULT_INST) riscv_jalr_rmem.sail riscv_insts_rmem.sail
4143

model/riscv_insts_zicond.sail

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
union clause ast = ZICOND_RTYPE : (regidx, regidx, regidx, zicondop)
2+
3+
mapping clause encdec = ZICOND_RTYPE(rs2, rs1, rd, RISCV_CZERO_EQZ) if haveZicond()
4+
<-> 0b0000111 @ rs2 @ rs1 @ 0b101 @ rd @ 0b0110011 if haveZicond()
5+
mapping clause encdec = ZICOND_RTYPE(rs2, rs1, rd, RISCV_CZERO_NEZ) if haveZicond()
6+
<-> 0b0000111 @ rs2 @ rs1 @ 0b111 @ rd @ 0b0110011 if haveZicond()
7+
8+
mapping zicond_mnemonic : zicondop <-> string = {
9+
RISCV_CZERO_EQZ <-> "czero.eqz",
10+
RISCV_CZERO_NEZ <-> "czero.nez"
11+
}
12+
13+
mapping clause assembly = ZICOND_RTYPE(rs2, rs1, rd, op)
14+
<-> zicond_mnemonic(op) ^ spc() ^ reg_name(rd) ^ sep() ^ reg_name(rs1) ^ sep() ^ reg_name(rs2)
15+
16+
function clause execute (ZICOND_RTYPE(rs2, rs1, rd, RISCV_CZERO_EQZ)) = {
17+
let value = X(rs1);
18+
let condition = X(rs2);
19+
let result : xlenbits = if condition == zeros() then zeros()
20+
else value;
21+
X(rd) = result;
22+
RETIRE_SUCCESS
23+
}
24+
25+
function clause execute (ZICOND_RTYPE(rs2, rs1, rd, RISCV_CZERO_NEZ)) = {
26+
let value = X(rs1);
27+
let condition = X(rs2);
28+
let result : xlenbits = if (condition != zeros()) then zeros()
29+
else value;
30+
X(rd) = result;
31+
RETIRE_SUCCESS
32+
}

model/riscv_sys_regs.sail

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
/* in the prover_snapshots directory (which include copies of their */
77
/* licences), is subject to the BSD two-clause licence below. */
88
/* */
9-
/* Copyright (c) 2017-2021 */
9+
/* Copyright (c) 2017-2023 */
1010
/* Prashanth Mundkur */
1111
/* Rishiyur S. Nikhil and Bluespec, Inc. */
1212
/* Jon French */
@@ -23,6 +23,7 @@
2323
/* Microsoft, for contributions by Robert Norton-Wright and Nathaniel Wesley Filardo */
2424
/* Peter Rugg */
2525
/* Aril Computer Corp., for contributions by Scott Johnson */
26+
/* VRULL GmbH, for contributions by Philipp Tomsich */
2627
/* */
2728
/* All rights reserved. */
2829
/* */
@@ -205,6 +206,9 @@ function haveZknd() -> bool = true
205206

206207
function haveZmmul() -> bool = true
207208

209+
/* Zicond extension support */
210+
function haveZicond() -> bool = true
211+
208212
bitfield Mstatush : bits(32) = {
209213
MBE : 5,
210214
SBE : 4

model/riscv_types.sail

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
/* in the prover_snapshots directory (which include copies of their */
77
/* licences), is subject to the BSD two-clause licence below. */
88
/* */
9-
/* Copyright (c) 2017-2021 */
9+
/* Copyright (c) 2017-2023 */
1010
/* Prashanth Mundkur */
1111
/* Rishiyur S. Nikhil and Bluespec, Inc. */
1212
/* Jon French */
@@ -23,6 +23,7 @@
2323
/* Microsoft, for contributions by Robert Norton-Wright and Nathaniel Wesley Filardo */
2424
/* Peter Rugg */
2525
/* Aril Computer Corp., for contributions by Scott Johnson */
26+
/* VRULL GmbH, for contributions by Philipp Tomsich */
2627
/* */
2728
/* All rights reserved. */
2829
/* */
@@ -415,6 +416,8 @@ enum biop_zbs = {RISCV_BCLRI, RISCV_BEXTI, RISCV_BINVI, RISCV_BSETI}
415416

416417
enum extop_zbb = {RISCV_SEXTB, RISCV_SEXTH, RISCV_ZEXTH}
417418

419+
enum zicondop = {RISCV_CZERO_EQZ, RISCV_CZERO_NEZ}
420+
418421
val sep : unit <-> string
419422
mapping sep : unit <-> string = {
420423
() <-> opt_spc() ^ "," ^ def_spc()

0 commit comments

Comments
 (0)