Skip to content

Commit 179b3be

Browse files
committed
Add Zilsd/Zclsd Support
Co-authored-by: Simona Costinescu <[email protected]>
1 parent 1057974 commit 179b3be

8 files changed

+179
-1
lines changed

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,7 @@ Supported RISC-V ISA features
126126
- Svinval extension for fine-grained address-translation cache invalidation, v1.0
127127
- Sv32, Sv39, Sv48 and Sv57 page-based virtual-memory systems
128128
- Physical Memory Protection (PMP)
129+
- Zilsd and Zclsd extensions for RV32 Load/Store pair instructions, v1.0
129130

130131
**For a list of unsupported extensions and features, see the [Extension Roadmap](https://github.com/riscv/sail-riscv/wiki/Extension-Roadmap).**
131132

config/default.json

+6
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,12 @@
6868
"Zicboz" : {
6969
"enabled" : false
7070
},
71+
"Zilsd": {
72+
"enabled": true
73+
},
74+
"Zclsd": {
75+
"enabled": true
76+
},
7177
"Zvkb" : {
7278
"enabled" : false
7379
},

model/CMakeLists.txt

+2
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,8 @@ foreach (xlen IN ITEMS 32 64)
7878
${vext_srcs}
7979
"riscv_insts_zicbom.sail"
8080
"riscv_insts_zicboz.sail"
81+
"riscv_insts_zilsd.sail"
82+
"riscv_insts_zclsd.sail"
8183
"riscv_insts_zvbb.sail"
8284
"riscv_insts_zvbc.sail"
8385
# Zimop and Zcmop should be at the end so they can be overridden by earlier extensions

model/riscv_insts_zcf.sail

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515

1616
/* ****************************************************************** */
1717

18-
function clause extensionEnabled(Ext_Zcf) = extensionEnabled(Ext_Zca) & extensionEnabled(Ext_F) & xlen == 32
18+
function clause extensionEnabled(Ext_Zcf) = extensionEnabled(Ext_Zca) & extensionEnabled(Ext_F) & not(sys_enable_zclsd()) & (xlen == 32)
1919

2020
union clause ast = C_FLWSP : (bits(6), fregidx)
2121

model/riscv_insts_zclsd.sail

+73
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
/*=======================================================================================*/
2+
/* This Sail RISC-V architecture model, comprising all files and */
3+
/* directories except where otherwise noted is subject the BSD */
4+
/* two-clause license in the LICENSE file. */
5+
/* */
6+
/* SPDX-License-Identifier: BSD-2-Clause */
7+
/*=======================================================================================*/
8+
9+
function clause extensionEnabled(Ext_Zclsd) = true & sys_enable_zilsd() & extensionEnabled(Ext_Zca) & not(extensionEnabled(Ext_Zcf)) & xlen == 32
10+
11+
/* ****************************************************************** */
12+
union clause ast = ZCLSD_C_LDSP : (bits(9), regidx)
13+
14+
mapping clause encdec_compressed = ZCLSD_C_LDSP(ui86 @ ui5 @ ui43 @ 0b000, rd)
15+
<-> 0b011 @ ui5 : bits(1) @ encdec_reg(rd) @ ui43 : bits(2) @ ui86 : bits(3) @ 0b10
16+
when extensionEnabled(Ext_Zclsd)
17+
18+
function clause execute (ZCLSD_C_LDSP(imm, rd)) = {
19+
execute(ZILSD_LD(zero_extend(imm), sp, rd))
20+
}
21+
22+
mapping clause assembly = ZCLSD_C_LDSP(uimm, rd)
23+
<-> "c.ldsp" ^ spc() ^ reg_name(rd) ^ sep() ^ hex_bits_9(uimm)
24+
when xlen == 32
25+
26+
/* ****************************************************************** */
27+
union clause ast = ZCLSD_C_SDSP : (bits(9), regidx)
28+
29+
mapping clause encdec_compressed = ZCLSD_C_SDSP(ui86 @ ui53 @ 0b000, rs2)
30+
<-> 0b111 @ ui53 : bits(3) @ ui86 : bits(3) @ encdec_reg(rs2) @ 0b10
31+
when extensionEnabled(Ext_Zclsd)
32+
33+
function clause execute (ZCLSD_C_SDSP(uimm, rs2)) = {
34+
execute(ZILSD_SD(zero_extend(uimm), rs2, sp))
35+
}
36+
37+
mapping clause assembly = ZCLSD_C_SDSP(uimm, rs2)
38+
<-> "c.sdsp" ^ spc() ^ reg_name(rs2) ^ sep() ^ hex_bits_9(uimm)
39+
when xlen == 32
40+
41+
/* ****************************************************************** */
42+
union clause ast = ZCLSD_C_LD : (bits(8), cregidx, cregidx)
43+
44+
mapping clause encdec_compressed = ZCLSD_C_LD(ui76 @ ui53 @ 0b000, rs1, rd)
45+
<-> 0b011 @ ui53 : bits(3) @ encdec_creg(rs1) @ ui76 : bits(2) @ encdec_creg(rd) @ 0b00
46+
when extensionEnabled(Ext_Zclsd)
47+
48+
function clause execute (ZCLSD_C_LD(uimm, rsc, rdc)) = {
49+
let rd = creg2reg_idx(rdc);
50+
let rs = creg2reg_idx(rsc);
51+
execute(ZILSD_LD(zero_extend(uimm), rs, rd))
52+
}
53+
54+
mapping clause assembly = ZCLSD_C_LD(uimm, rsc, rdc)
55+
<-> "c.ld" ^ spc() ^ creg_name(rdc) ^ sep() ^ creg_name(rsc) ^ sep() ^ hex_bits_8(uimm)
56+
when xlen == 32
57+
58+
/* ****************************************************************** */
59+
union clause ast = ZCLSD_C_SD : (bits(8), cregidx, cregidx)
60+
61+
mapping clause encdec_compressed = ZCLSD_C_SD(ui76 @ ui53 @ 0b000, rs1, rs2)
62+
<-> 0b111 @ ui53 : bits(3) @ encdec_creg(rs1) @ ui76 : bits(2) @ encdec_creg(rs2) @ 0b00
63+
when extensionEnabled(Ext_Zclsd)
64+
65+
function clause execute (ZCLSD_C_SD(uimm, rsc1, rsc2)) = {
66+
let rs1 = creg2reg_idx(rsc1);
67+
let rs2 = creg2reg_idx(rsc2);
68+
execute(ZILSD_SD(zero_extend(uimm), rs2, rs1))
69+
}
70+
71+
mapping clause assembly = ZCLSD_C_SD(uimm, rsc1, rsc2)
72+
<-> "c.sd" ^ spc() ^ creg_name(rsc1) ^ sep() ^ creg_name(rsc2) ^ sep() ^ hex_bits_8(uimm)
73+
when xlen == 32

model/riscv_insts_zilsd.sail

+89
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
/*=======================================================================================*/
2+
/* This Sail RISC-V architecture model, comprising all files and */
3+
/* directories except where otherwise noted is subject the BSD */
4+
/* two-clause license in the LICENSE file. */
5+
/* */
6+
/* SPDX-License-Identifier: BSD-2-Clause */
7+
/*=======================================================================================*/
8+
9+
function clause extensionEnabled(Ext_Zilsd) = sys_enable_zilsd() & xlen == 32
10+
11+
/* ****************************************************************** */
12+
union clause ast = ZILSD_LD : (bits(12), regidx, regidx)
13+
14+
mapping clause encdec = ZILSD_LD(imm, rs1, rd)
15+
<-> imm @ encdec_reg(rs1) @ 0b011 @ encdec_reg(rd) @ 0b0000011
16+
when extensionEnabled(Ext_Zilsd) & not(bit_to_bool(encdec_reg(rd)[0]))
17+
18+
function load_imm(imm : bits(12), base_val : xlenbits, rd : regidx, width : word_width) -> Retired = {
19+
let offset : xlenbits = sign_extend(imm);
20+
let width_bytes = size_bytes(width);
21+
assert(width_bytes <= xlen_bytes);
22+
23+
let vaddr = Virtaddr(base_val + offset);
24+
if check_misaligned(vaddr, width)
25+
then { handle_mem_exception(vaddr, E_Load_Addr_Align()); RETIRE_FAIL }
26+
else match translateAddr(vaddr, Read(Data)) {
27+
TR_Failure(e, _) => { handle_mem_exception(vaddr, e); RETIRE_FAIL },
28+
TR_Address(paddr, _) => {
29+
match mem_read(Read(Data), paddr, width_bytes, false, false, false) {
30+
Ok(result) => { X(rd) = extend_value(false, result); RETIRE_SUCCESS },
31+
Err(e) => { handle_mem_exception(vaddr, e); RETIRE_FAIL },
32+
}
33+
},
34+
}
35+
}
36+
37+
function clause execute ZILSD_LD(imm, rs1, rd) = {
38+
if rd != zreg then {
39+
let base_val = X(rs1);
40+
let _ = load_imm(imm, base_val, rd, WORD);
41+
load_imm(imm+4, base_val, rd+1, WORD)
42+
} else {
43+
RETIRE_SUCCESS
44+
}
45+
}
46+
mapping clause assembly = ZILSD_LD(imm, rs1, rd) <-> "ld" ^ spc() ^ reg_name(rd) ^ sep() ^ hex_bits_signed_12(imm) ^ "(" ^ reg_name(rs1) ^ ")"
47+
48+
49+
/* ****************************************************************** */
50+
union clause ast = ZILSD_SD : (bits(12), regidx, regidx)
51+
52+
mapping clause encdec = ZILSD_SD(imm7 @ imm5, rs2, rs1)
53+
<-> imm7 : bits(7) @ encdec_reg(rs2) @ encdec_reg(rs1) @ 0b011 @ imm5 : bits(5) @ 0b0100011
54+
when extensionEnabled(Ext_Zilsd) & not(bit_to_bool(encdec_reg(rs2)[0]))
55+
56+
function store_imm(imm : bits(12), rs2_val : xlenbits, base_val : xlenbits, width : word_width) -> Retired = {
57+
let offset : xlenbits = sign_extend(imm);
58+
let width_bytes = size_bytes(width);
59+
assert(width_bytes <= xlen_bytes);
60+
61+
let vaddr = Virtaddr(base_val + offset);
62+
if check_misaligned(vaddr, width)
63+
then { handle_mem_exception(vaddr, E_SAMO_Addr_Align()); RETIRE_FAIL }
64+
else match translateAddr(vaddr, Write(Data)) {
65+
TR_Failure(e, _) => { handle_mem_exception(vaddr, e); RETIRE_FAIL },
66+
TR_Address(paddr, _) => {
67+
match mem_write_ea(paddr, width_bytes, false, false, false) {
68+
Err(e) => { handle_mem_exception(vaddr, e); RETIRE_FAIL },
69+
Ok(_) => {
70+
match mem_write_value(paddr, width_bytes, rs2_val[width_bytes * 8 - 1 .. 0], false, false, false) {
71+
Ok(true) => RETIRE_SUCCESS,
72+
Ok(false) => internal_error(__FILE__, __LINE__, "store got false from mem_write_value"),
73+
Err(e) => { handle_mem_exception(vaddr, e); RETIRE_FAIL }
74+
}
75+
}
76+
}
77+
}
78+
}
79+
}
80+
81+
function clause execute ZILSD_SD(imm, rs2, rs1) = {
82+
let base_val = X(rs1);
83+
let rs2_val = X(rs2);
84+
let rs2_pair_val = if rs2 != zreg then X(rs2+1) else rs2_val;
85+
let _ = store_imm(imm, rs2_val, base_val, WORD);
86+
store_imm(imm+4, rs2_pair_val, base_val, WORD)
87+
}
88+
89+
mapping clause assembly = ZILSD_SD(offset, rs2, rs1) <-> "sd" ^ spc() ^ reg_name(rs2) ^ sep() ^ hex_bits_signed_12(offset) ^ "(" ^ reg_name(rs1) ^ ")"

model/riscv_sys_regs.sail

+4
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,10 @@ function sys_enable_bext() -> bool = config extensions.B.enabled
125125
function sys_enable_zicbom() -> bool = config extensions.Zicbom.enabled
126126
function sys_enable_zicboz() -> bool = config extensions.Zicboz.enabled
127127

128+
// "Zilsd", "Zclsd" Extensions for Load/Store pair for RV32
129+
function sys_enable_zilsd() -> bool = config extensions.Zilsd.enabled
130+
function sys_enable_zclsd() -> bool = config extensions.Zclsd.enabled
131+
128132
// Is the Zvkb extension supported.
129133
function sys_enable_zvkb() -> bool = config extensions.Zvkb.enabled
130134

model/riscv_types.sail

+3
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,9 @@ newtype regidx = Regidx : bits(5) /* uncompressed register identifiers */
3737
newtype cregidx = Cregidx : bits(3) /* identifiers in RVC instructions */
3838
type csreg = bits(12) /* CSR addressing */
3939

40+
function add_regidx_int(Regidx(reg) : regidx, offset : int) -> regidx = Regidx(reg + offset)
41+
overload operator + = { add_regidx_int }
42+
4043
function regidx_offset(Regidx(r) : regidx, o : bits(5)) -> regidx = Regidx(r + o)
4144
function regidx_bits (Regidx(b) : regidx) -> bits(5) = b
4245

0 commit comments

Comments
 (0)