Skip to content

Commit a979234

Browse files
committed
Add Zilsd/Zclsd Support
1 parent 2dfc4ff commit a979234

5 files changed

+119
-1
lines changed

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
)
8284

8385
if (variant STREQUAL "rmem")

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), regidx)
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 = C_LDSP_RV32 : (bits(9), regidx)
13+
14+
mapping clause encdec_compressed = C_LDSP_RV32(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 (C_LDSP_RV32(imm, rd)) = {
18+
execute(LOAD_RV32(zero_extend(imm), sp, rd))
19+
}
20+
21+
mapping clause assembly = C_LDSP_RV32(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 = C_SDSP_RV32 : (bits(9), regidx)
28+
29+
mapping clause encdec_compressed = C_SDSP_RV32(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 (C_SDSP_RV32(uimm, rs2)) = {
33+
execute(STORE_RV32(zero_extend(uimm), rs2, sp))
34+
}
35+
36+
mapping clause assembly = C_SDSP_RV32(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 = C_LD_RV32 : (bits(8), cregidx, cregidx)
43+
44+
mapping clause encdec_compressed = C_LD_RV32(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 (C_LD_RV32(uimm, rsc, rdc)) = {
48+
let rd = creg2reg_idx(rdc);
49+
let rs = creg2reg_idx(rsc);
50+
execute(LOAD_RV32(zero_extend(uimm), rs, rd))
51+
}
52+
53+
mapping clause assembly = C_LD_RV32(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 = C_SD_RV32 : (bits(8), cregidx, cregidx)
60+
61+
mapping clause encdec_compressed = C_SD_RV32(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 (C_SD_RV32(uimm, rsc1, rsc2)) = {
65+
let rs1 = creg2reg_idx(rsc1);
66+
let rs2 = creg2reg_idx(rsc2);
67+
execute(STORE_RV32(zero_extend(uimm), rs2, rs1))
68+
}
69+
70+
mapping clause assembly = C_SD_RV32(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

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
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 = LOAD_RV32 : (bits(12), regidx, regidx)
13+
14+
mapping clause encdec = LOAD_RV32(imm, rs1, rd) if extensionEnabled(Ext_Zilsd)
15+
<-> imm @ rs1 @ 0b011 @ rd @ 0b0000011 if extensionEnabled(Ext_Zilsd)
16+
17+
function clause execute LOAD_RV32(imm, rs1, rd) = {
18+
// Use of misaligned (odd-numbered) registers is reserved.
19+
assert(regidx_to_regno(rd) % 2 == 0);
20+
execute(LOAD(imm, rs1, rd, false, WORD, false, false))
21+
execute(LOAD(imm+4, rs1, rd+1, false, WORD, false, false))
22+
}
23+
24+
mapping clause assembly = LOAD_RV32(imm, rs1, rd) <-> "ld" ^ spc() ^ reg_name(rd) ^ sep() ^ hex_bits_signed_12(imm) ^ "(" ^ reg_name(rs1) ^ ")"
25+
26+
/* ****************************************************************** */
27+
union clause ast = STORE_RV32 : (bits(12), regidx, regidx)
28+
29+
mapping clause encdec = STORE_RV32(imm7 @ imm5, rs2, rs1) if extensionEnabled(Ext_Zilsd)
30+
<-> imm7 : bits(7) @ rs2 @ rs1 @ 0b011 @ imm5 : bits(5) @ 0b0100011 if extensionEnabled(Ext_Zilsd)
31+
32+
function clause execute STORE_RV32(imm, rs2, rs1) = {
33+
// Use of misaligned (odd-numbered) registers is reserved.
34+
assert(regidx_to_regno(rs2) % 2 == 0);
35+
execute(STORE(imm, rs2, rs1, WORD, false, false))
36+
execute(STORE(imm+4, rs2+1, rs1, WORD, false, false))
37+
}
38+
39+
mapping clause assembly = STORE_RV32(offset, rs2, rs1) <-> "sd" ^ spc() ^ reg_name(rs2) ^ sep() ^ hex_bits_signed_12(offset) ^ "(" ^ reg_name(rs1) ^ ")"

0 commit comments

Comments
 (0)