Skip to content

Commit 5864d1a

Browse files
committed
Add Zilsd/Zclsd Support
Co-authored-by: Simona Costinescu <simona.costinescu@nxp.com>
1 parent 0f291de commit 5864d1a

File tree

12 files changed

+496
-59
lines changed

12 files changed

+496
-59
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,7 @@ For booting operating system images, see the information under the
121121
- Zic64b extension for Cache block size is 64 bytes, v1.0
122122
- Zicbom, Zicbop and Zicboz extensions for cache-block management, v1.0
123123
- Zicfilp extension for Landing Pad Control Flow Integrity, v1.0
124+
- Zilsd and Zclsd extensions for RV32 Load/Store pair instructions, v1.0
124125
- Zimop extension for May-Be-Operations, v1.0
125126
- Zihintntl extension for Non-temporal Locality Hints, v1.0
126127
- Zihintpause extension for Pause Hint, v2.0

config/config.json.in

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,9 @@
261261
"Zihpm": {
262262
"supported": true
263263
},
264+
"Zilsd": {
265+
"supported": true
266+
},
264267
"Zimop": {
265268
"supported": true
266269
},
@@ -318,6 +321,9 @@
318321
"Zcb": {
319322
"supported": true
320323
},
324+
"Zclsd": {
325+
"supported": true
326+
},
321327
"Zcmop": {
322328
"supported": true
323329
},

model/core/extensions.sail

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,10 @@ function clause hartSupports(Ext_Zihintpause) = config extensions.Zihintpause.su
122122
enum clause extension = Ext_Zihpm
123123
mapping clause extensionName = Ext_Zihpm <-> "zihpm"
124124
function clause hartSupports(Ext_Zihpm) = config extensions.Zihpm.supported
125+
// Load/Store Pair for RV32
126+
enum clause extension = Ext_Zilsd
127+
mapping clause extensionName = Ext_Zilsd <-> "zilsd"
128+
function clause hartSupports(Ext_Zilsd) = config extensions.Zilsd.supported : bool & (xlen == 32)
125129
// May-Be-Operations
126130
enum clause extension = Ext_Zimop
127131
mapping clause extensionName = Ext_Zimop <-> "zimop"
@@ -244,6 +248,11 @@ enum clause extension = Ext_Zbs
244248
mapping clause extensionName = Ext_Zbs <-> "zbs"
245249
function clause hartSupports(Ext_Zbs) = config extensions.Zbs.supported
246250

251+
// Compressed Load/Store pair instructions
252+
enum clause extension = Ext_Zclsd
253+
mapping clause extensionName = Ext_Zclsd <-> "zclsd"
254+
function clause hartSupports(Ext_Zclsd) = config extensions.Zclsd.supported : bool & (xlen == 32)
255+
247256
// Scalar & Entropy Source Instructions: NIST Suite: AES Decryption
248257
enum clause extension = Ext_Zknd
249258
mapping clause extensionName = Ext_Zknd <-> "zknd"
@@ -607,6 +616,7 @@ let extensions_ordered_for_isa_string = [
607616
Ext_Zicntr,
608617
Ext_Zicond,
609618
Ext_Zicsr,
619+
Ext_Zilsd,
610620
Ext_Zifencei,
611621
Ext_Zihintntl,
612622
Ext_Zihintpause,
@@ -640,6 +650,7 @@ let extensions_ordered_for_isa_string = [
640650
Ext_Zcb,
641651
Ext_Zcd,
642652
Ext_Zcf,
653+
Ext_Zclsd,
643654
Ext_Zcmop,
644655

645656
// Zb

model/extensions/FD/zcf_insts.sail

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
// SPDX-License-Identifier: BSD-2-Clause
77
// =======================================================================================
88

9-
function clause currentlyEnabled(Ext_Zcf) = hartSupports(Ext_Zcf) & currentlyEnabled(Ext_F) & currentlyEnabled(Ext_Zca) & (currentlyEnabled(Ext_C) | not(hartSupports(Ext_C)))
9+
function clause currentlyEnabled(Ext_Zcf) = hartSupports(Ext_Zcf) & currentlyEnabled(Ext_F) & currentlyEnabled(Ext_Zca) & (currentlyEnabled(Ext_C) | not(hartSupports(Ext_C))) & not(currentlyEnabled(Ext_Zclsd))
1010

1111
union clause instruction = C_FLWSP : (bits(6), fregidx)
1212

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
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 currentlyEnabled(Ext_Zclsd) = hartSupports(Ext_Zilsd) & currentlyEnabled(Ext_Zca) & not(currentlyEnabled(Ext_Zcf)) & xlen == 32
10+
11+
/* ****************************************************************** */
12+
union clause instruction = ZCLSD_C_LDSP : (bits(9), regidx)
13+
14+
$[wavedrom "C.LDSP offset[5] dest offset[4:3|8:6] C2"]
15+
mapping clause encdec_compressed = ZCLSD_C_LDSP(ui86 @ ui5 @ ui43 @ 0b000, rd)
16+
<-> 0b011 @ ui5 : bits(1) @ encdec_reg(rd) @ ui43 : bits(2) @ ui86 : bits(3) @ 0b10
17+
when currentlyEnabled(Ext_Zclsd)
18+
19+
function clause execute (ZCLSD_C_LDSP(imm, rd)) = {
20+
execute(ZILSD_LD(zero_extend(imm), sp, rd))
21+
}
22+
23+
mapping clause assembly = ZCLSD_C_LDSP(uimm, rd)
24+
<-> "c.ldsp" ^ spc() ^ reg_name(rd) ^ sep() ^ hex_bits_9(uimm)
25+
when xlen == 32
26+
27+
/* ****************************************************************** */
28+
union clause instruction = ZCLSD_C_SDSP : (bits(9), regidx)
29+
30+
$[wavedrom "C.SDSP offset[5:3|8:6] src C2"]
31+
mapping clause encdec_compressed = ZCLSD_C_SDSP(ui86 @ ui53 @ 0b000, rs2)
32+
<-> 0b111 @ ui53 : bits(3) @ ui86 : bits(3) @ encdec_reg(rs2) @ 0b10
33+
when currentlyEnabled(Ext_Zclsd)
34+
35+
function clause execute (ZCLSD_C_SDSP(uimm, rs2)) = {
36+
execute(ZILSD_SD(zero_extend(uimm), rs2, sp))
37+
}
38+
39+
mapping clause assembly = ZCLSD_C_SDSP(uimm, rs2)
40+
<-> "c.sdsp" ^ spc() ^ reg_name(rs2) ^ sep() ^ hex_bits_9(uimm)
41+
when xlen == 32
42+
43+
/* ****************************************************************** */
44+
union clause instruction = ZCLSD_C_LD : (bits(8), cregidx, cregidx)
45+
46+
$[wavedrom "C.LD offset[5:3] base offset[7:6] dest C0"]
47+
mapping clause encdec_compressed = ZCLSD_C_LD(ui76 @ ui53 @ 0b000, rs1, rd)
48+
<-> 0b011 @ ui53 : bits(3) @ encdec_creg(rs1) @ ui76 : bits(2) @ encdec_creg(rd) @ 0b00
49+
when currentlyEnabled(Ext_Zclsd)
50+
51+
function clause execute (ZCLSD_C_LD(uimm, rsc, rdc)) = {
52+
let rd = creg2reg_idx(rdc);
53+
let rs = creg2reg_idx(rsc);
54+
execute(ZILSD_LD(zero_extend(uimm), rs, rd))
55+
}
56+
57+
mapping clause assembly = ZCLSD_C_LD(uimm, rsc, rdc)
58+
<-> "c.ld" ^ spc() ^ creg_name(rdc) ^ sep() ^ creg_name(rsc) ^ sep() ^ hex_bits_8(uimm)
59+
when xlen == 32
60+
61+
/* ****************************************************************** */
62+
union clause instruction = ZCLSD_C_SD : (bits(8), cregidx, cregidx)
63+
64+
$[wavedrom "C.SD offset[5:3] base offset[7:6] src C0"]
65+
mapping clause encdec_compressed = ZCLSD_C_SD(ui76 @ ui53 @ 0b000, rs1, rs2)
66+
<-> 0b111 @ ui53 : bits(3) @ encdec_creg(rs1) @ ui76 : bits(2) @ encdec_creg(rs2) @ 0b00
67+
when currentlyEnabled(Ext_Zclsd)
68+
69+
function clause execute (ZCLSD_C_SD(uimm, rsc1, rsc2)) = {
70+
let rs1 = creg2reg_idx(rsc1);
71+
let rs2 = creg2reg_idx(rsc2);
72+
execute(ZILSD_SD(zero_extend(uimm), rs2, rs1))
73+
}
74+
75+
mapping clause assembly = ZCLSD_C_SD(uimm, rsc1, rsc2)
76+
<-> "c.sd" ^ spc() ^ creg_name(rsc1) ^ sep() ^ creg_name(rsc2) ^ sep() ^ hex_bits_8(uimm)
77+
when xlen == 32
Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
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 currentlyEnabled(Ext_Zilsd) = hartSupports(Ext_Zilsd) & xlen == 32
10+
11+
/* ****************************************************************** */
12+
union clause instruction = ZILSD_LD : (bits(12), regidx, regidx)
13+
14+
$[wavedrom "offset[11:5] src base _ width imm[4:0] STORE"]
15+
mapping clause encdec = ZILSD_LD(imm, rs1, rd)
16+
<-> imm @ encdec_reg(rs1) @ 0b011 @ encdec_reg(rd) @ 0b0000011
17+
when currentlyEnabled(Ext_Zilsd) & not(bit_to_bool(encdec_reg(rd)[0]))
18+
19+
private function load_imm(vaddr: virtaddr, width : word_width, rd : regidx) -> option(ExceptionType) = {
20+
assert(width <= xlen_bytes);
21+
22+
if check_misaligned(vaddr, width)
23+
then Some(E_Load_Addr_Align())
24+
else match translateAddr(vaddr, Load(Data)) {
25+
Err(e, _) => Some(e),
26+
Ok(paddr, _) => {
27+
match mem_read(Load(Data), paddr, width, false, false, false) {
28+
Ok(result) => { X(rd) = extend_value(false, result); None() },
29+
Err(e) => Some(e),
30+
}
31+
},
32+
}
33+
}
34+
35+
function clause execute ZILSD_LD(imm, rs1, rd) = {
36+
if rd == zreg then {
37+
return RETIRE_SUCCESS;
38+
};
39+
let base_addr = X(rs1);
40+
let vaddr = Virtaddr(base_addr + sign_extend(imm));
41+
match load_imm(vaddr, 4, rd) {
42+
Some(e) => Memory_Exception(vaddr, e),
43+
None() => {
44+
let vaddr = Virtaddr(base_addr + sign_extend(imm + 4));
45+
match load_imm(vaddr, 4, rd+1) {
46+
Some(e) => Memory_Exception(vaddr, e),
47+
None() => RETIRE_SUCCESS,
48+
}
49+
}
50+
}
51+
}
52+
mapping clause assembly = ZILSD_LD(imm, rs1, rd) <-> "ld" ^ spc() ^ reg_name(rd) ^ sep() ^ hex_bits_signed_12(imm) ^ "(" ^ reg_name(rs1) ^ ")"
53+
54+
55+
/* ****************************************************************** */
56+
union clause instruction = ZILSD_SD : (bits(12), regidx, regidx)
57+
58+
$[wavedrom "offset[11:0] base _ width dest LOAD"]
59+
mapping clause encdec = ZILSD_SD(imm7 @ imm5, rs2, rs1)
60+
<-> imm7 : bits(7) @ encdec_reg(rs2) @ encdec_reg(rs1) @ 0b011 @ imm5 : bits(5) @ 0b0100011
61+
when currentlyEnabled(Ext_Zilsd) & not(bit_to_bool(encdec_reg(rs2)[0]))
62+
63+
private function store_imm(vaddr: virtaddr, width : word_width, rs2_val : xlenbits) -> option(ExceptionType) = {
64+
assert(width <= xlen_bytes);
65+
if check_misaligned(vaddr, width)
66+
then Some(E_SAMO_Addr_Align())
67+
else match translateAddr(vaddr, Store(Data)) {
68+
Err(e, _) => Some(e),
69+
Ok(paddr, _) => match mem_write_ea(paddr, width, false, false, false) {
70+
Err(e) => Some(e),
71+
Ok(_) => match mem_write_value(paddr, width, rs2_val[width * 8 - 1 .. 0], false, false, false) {
72+
Ok(true) => None(),
73+
Ok(false) => internal_error(__FILE__, __LINE__, "store got false from mem_write_value"),
74+
Err(e) => Some(e)
75+
}
76+
}
77+
}
78+
}
79+
80+
function clause execute ZILSD_SD(imm, rs2, rs1) = {
81+
let base_addr = X(rs1);
82+
let rs2_val = X(rs2);
83+
let rs2_pair_val = if rs2 != zreg then X(rs2+1) else rs2_val;
84+
85+
let vaddr = Virtaddr(base_addr + sign_extend(imm));
86+
match store_imm(vaddr, 4, rs2_val) {
87+
Some(e) => Memory_Exception(vaddr, e),
88+
None() => {
89+
let vaddr = Virtaddr(base_addr + sign_extend(imm + 4));
90+
match store_imm(vaddr, 4, rs2_pair_val) {
91+
Some(e) => Memory_Exception(vaddr, e),
92+
None() => RETIRE_SUCCESS,
93+
}
94+
}
95+
}
96+
}
97+
98+
mapping clause assembly = ZILSD_SD(offset, rs2, rs1) <-> "sd" ^ spc() ^ reg_name(rs2) ^ sep() ^ hex_bits_signed_12(offset) ^ "(" ^ reg_name(rs1) ^ ")"

model/riscv.sail_project

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -356,6 +356,11 @@ extensions {
356356
}
357357
}
358358

359+
Zclsd {
360+
requires core, sys, Zilsd
361+
files extensions/Zclsd/zclsd_insts.sail
362+
}
363+
359364
Zicond {
360365
requires core
361366

@@ -440,6 +445,11 @@ extensions {
440445
files extensions/Zihintpause/zihintpause_insts.sail
441446
}
442447

448+
Zilsd {
449+
requires core, sys, I_insts
450+
files extensions/Zilsd/zilsd_insts.sail
451+
}
452+
443453
Ssqosid {
444454
requires core
445455
files extensions/Ssqosid/ssqosid.sail

0 commit comments

Comments
 (0)