Skip to content

Commit c1bff11

Browse files
committed
Add Zilsd/Zclsd Support
Co-authored-by: MingZhu Yan <[email protected]> Co-authored-by: Simona Costinescu <[email protected]>
1 parent 5f11038 commit c1bff11

6 files changed

+116
-1
lines changed

README.md

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

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

model/CMakeLists.txt

+2
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ foreach (xlen IN ITEMS 32 64)
6060
"riscv_insts_zcf.sail"
6161
"riscv_insts_dext.sail"
6262
"riscv_insts_zcd.sail"
63+
"riscv_insts_zclsd.sail"
6364
"riscv_insts_svinval.sail"
6465
"riscv_insts_zba.sail"
6566
"riscv_insts_zbb.sail"
@@ -78,6 +79,7 @@ foreach (xlen IN ITEMS 32 64)
7879
${vext_srcs}
7980
"riscv_insts_zicbom.sail"
8081
"riscv_insts_zicboz.sail"
82+
"riscv_insts_zilsd.sail"
8183
"riscv_insts_zvbb.sail"
8284
)
8385

model/riscv_extensions.sail

+4
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,10 @@ enum clause extension = Ext_Zcb
7171
enum clause extension = Ext_Zcd
7272
// Code Size Reduction: compressed single precision floating point loads and stores
7373
enum clause extension = Ext_Zcf
74+
// Load/Store Pair for RV32
75+
enum clause extension = Ext_Zilsd
76+
// Compressed Load/Store pair instructions
77+
enum clause extension = Ext_Zclsd
7478

7579
// Bit Manipulation: Address generation
7680
enum clause extension = Ext_Zba

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(extensionEnabled(Ext_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 & extensionEnabled(Ext_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) if extensionEnabled(Ext_Zclsd)
15+
<-> 0b011 @ ui5 : bits(1) @ rd @ ui43 : bits(2) @ ui86 : bits(3) @ 0b10 if extensionEnabled(Ext_Zclsd)
16+
17+
function clause execute (ZCLSD_C_LDSP(imm, rd)) = {
18+
execute(ZILSD_LD(zero_extend(imm), sp, rd))
19+
}
20+
21+
mapping clause assembly = ZCLSD_C_LDSP(uimm, rd)
22+
if xlen == 32
23+
<-> "c.ldsp" ^ spc() ^ reg_name(rd) ^ sep() ^ hex_bits_9(uimm)
24+
if 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) if extensionEnabled(Ext_Zclsd)
30+
<-> 0b111 @ ui53 : bits(3) @ ui86 : bits(3) @ rs2 @ 0b10 if extensionEnabled(Ext_Zclsd)
31+
32+
function clause execute (ZCLSD_C_SDSP(uimm, rs2)) = {
33+
execute(ZILSD_SD(zero_extend(uimm), rs2, sp))
34+
}
35+
36+
mapping clause assembly = ZCLSD_C_SDSP(uimm, rs2)
37+
if xlen == 32
38+
<-> "c.sdsp" ^ spc() ^ reg_name(rs2) ^ sep() ^ hex_bits_9(uimm)
39+
if 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) if extensionEnabled(Ext_Zclsd)
45+
<-> 0b011 @ ui53 : bits(3) @ rs1 @ ui76 : bits(2) @ rd @ 0b00 if extensionEnabled(Ext_Zclsd)
46+
47+
function clause execute (ZCLSD_C_LD(uimm, rsc, rdc)) = {
48+
let rd = creg2reg_idx(rdc);
49+
let rs = creg2reg_idx(rsc);
50+
execute(ZILSD_LD(zero_extend(uimm), rs, rd))
51+
}
52+
53+
mapping clause assembly = ZCLSD_C_LD(uimm, rsc, rdc)
54+
if xlen == 32
55+
<-> "c.ld" ^ spc() ^ creg_name(rdc) ^ sep() ^ creg_name(rsc) ^ sep() ^ hex_bits_8(uimm)
56+
if 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) if extensionEnabled(Ext_Zclsd)
62+
<-> 0b111 @ ui53 : bits(3) @ rs1 @ ui76 : bits(2) @ rs2 @ 0b00 if extensionEnabled(Ext_Zclsd)
63+
64+
function clause execute (ZCLSD_C_SD(uimm, rsc1, rsc2)) = {
65+
let rs1 = creg2reg_idx(rsc1);
66+
let rs2 = creg2reg_idx(rsc2);
67+
execute(ZILSD_SD(zero_extend(uimm), rs2, rs1))
68+
}
69+
70+
mapping clause assembly = ZCLSD_C_SD(uimm, rsc1, rsc2)
71+
if xlen == 32
72+
<-> "c.sd" ^ spc() ^ creg_name(rsc1) ^ sep() ^ creg_name(rsc2) ^ sep() ^ hex_bits_8(uimm)
73+
if xlen == 32

model/riscv_insts_zilsd.sail

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
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) = true & xlen == 32
10+
11+
/* ****************************************************************** */
12+
union clause ast = ZILSD_LD : (bits(12), regidx, regidx)
13+
14+
mapping clause encdec = ZILSD_LD(imm, rs1, rd) if extensionEnabled(Ext_Zilsd) & regidx_to_regno(rd) % 2 == 0
15+
<-> imm @ rs1 @ 0b011 @ rd @ 0b0000011 if extensionEnabled(Ext_Zilsd) & regidx_to_regno(rd) % 2 == 0
16+
17+
function clause execute ZILSD_LD(imm, rs1, rd) = {
18+
let _ = execute(LOAD(imm, rs1, rd, false, WORD, false, false));
19+
execute(LOAD(imm+4, rs1, rd+1, false, WORD, false, false))
20+
}
21+
22+
mapping clause assembly = ZILSD_LD(imm, rs1, rd) <-> "ld" ^ spc() ^ reg_name(rd) ^ sep() ^ hex_bits_signed_12(imm) ^ "(" ^ reg_name(rs1) ^ ")"
23+
24+
/* ****************************************************************** */
25+
union clause ast = ZILSD_SD : (bits(12), regidx, regidx)
26+
27+
mapping clause encdec = ZILSD_SD(imm7 @ imm5, rs2, rs1) if extensionEnabled(Ext_Zilsd) & regidx_to_regno(rs2) % 2 == 0
28+
<-> imm7 : bits(7) @ rs2 @ rs1 @ 0b011 @ imm5 : bits(5) @ 0b0100011 if extensionEnabled(Ext_Zilsd) & regidx_to_regno(rs2) % 2 == 0
29+
30+
function clause execute ZILSD_SD(imm, rs2, rs1) = {
31+
let _ = execute(STORE(imm, rs2, rs1, WORD, false, false));
32+
execute(STORE(imm+4, rs2+1, rs1, WORD, false, false))
33+
}
34+
35+
mapping clause assembly = ZILSD_SD(offset, rs2, rs1) <-> "sd" ^ spc() ^ reg_name(rs2) ^ sep() ^ hex_bits_signed_12(offset) ^ "(" ^ reg_name(rs1) ^ ")"

0 commit comments

Comments
 (0)