Skip to content

Commit 3e10a3f

Browse files
committed
add Zclsd instructions
1 parent abc4553 commit 3e10a3f

File tree

5 files changed

+117
-5
lines changed

5 files changed

+117
-5
lines changed

arch/ext/Zclsd.yaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ description: |
77
This specification adds load and store instructions using register pairs. It does so by reusing existing instruction encodings which are RV64-only. The specification defines 16-bit encodings.
88
Load and store instructions will use the same definition of even-odd pairs as defined by the Zdinx extension.
99
The extension improves static code density, by replacing two separate load or store instructions with a single one. In addition, it can provide a performance improvement for implementations that can make use of a wider than XLEN memory interface.
10-
Zclsd depends on Zilsd and Zca. It has overlapping encodings with Zcf and is thus incompatible with Zcf.
1110
type: unprivileged
1211
versions:
1312
- version: "1.0"

arch/inst/C/c.ld.yaml

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,12 @@ description: |
99
It computes an effective address by adding the zero-extended offset, scaled by 8,
1010
to the base address in register rs1.
1111
It expands to `ld` `rd, offset(rs1)`.
12+
For RV32, if the Zclsd extension is enabled, this instruction operates on register pairs.
13+
1214
definedBy:
1315
anyOf:
1416
- C
1517
- Zca
16-
base: 64
1718
assembly: xd, imm(xs1)
1819
encoding:
1920
match: 011-----------00
@@ -32,13 +33,17 @@ access:
3233
vu: always
3334
operation(): |
3435
if (implemented?(ExtensionName::C) && (CSR[misa].C == 1'b0)) {
35-
raise(ExceptionCode::IllegalInstruction, mode(), $encoding);
36+
raise(ExceptionCode::IllegalInstruction, mode(), $encoding);
3637
}
3738
38-
XReg virtual_address = X[rs1] + imm;
39+
if (XLEN == 32 && implemented?(ExtensionName::Zclsd)) {
3940
41+
X[rd] = sext(read_memory<64>(X[rs1] + imm, $encoding), 64);
42+
X[rd + 1] = sext(read_memory<64>(X[rs1] + imm + 8, $encoding), 64);
43+
} else {
44+
XReg virtual_address = X[rs1] + imm;
4045
X[rd] = sext(read_memory<64>(virtual_address, $encoding), 64);
41-
46+
}
4247
sail(): |
4348
{
4449
let offset : xlenbits = sign_extend(imm);

arch/inst/Zclsd/c.ldsp.yaml

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# yaml-language-server: $schema=../../../schemas/inst_schema.json
2+
3+
$schema: "inst_schema.json#"
4+
kind: instruction
5+
name: c.ldsp
6+
long_name: Stack-pointer based load doubleword to even/odd register pair
7+
description: |
8+
Loads stack-pointer relative 64-bit value into registers rd' and rd'+1. It computes its effective
9+
address by adding the zero-extended offset, scaled by 8, to the stack pointer, x2. It expands to ld
10+
rd, offset(x2). C.LDSP is only valid when rd≠x0; the code points with rd=x0 are reserved.
11+
definedBy: Zclsd
12+
assembly: rd, offset(rs1)
13+
encoding:
14+
match: 011-----------01
15+
variables:
16+
- name: rd
17+
location: 11-7
18+
not: [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29, 31]
19+
- name: imm
20+
location: 4-2|12|6-5
21+
left_shift: 3
22+
access:
23+
s: always
24+
u: always
25+
vs: always
26+
vu: always
27+
operation(): |
28+
29+
Bits<XLEN> base = X[2];
30+
Bits<XLEN> offset = imm;
31+
Bits<XLEN> eff_addr = base + offset;
32+
33+
Bits<64> data = read_memory<64>(eff_addr, $encoding);
34+
35+
X[rd] = data[31:0];
36+
X[rd+1] = data[63:32];
37+
sail(): "" #not implemented in the sail model yet

arch/inst/Zclsd/c.sd.yaml

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# yaml-language-server: $schema=../../../schemas/inst_schema.json
2+
3+
$schema: "inst_schema.json#"
4+
kind: instruction
5+
name: c.sd
6+
long_name: Store doubleword from even/odd register pair
7+
description: |
8+
Stores a 64-bit value from registers rs2' and rs2'+1. It computes an effective address by adding
9+
the zero-extended offset, scaled by 8, to the base address in register rs1'. It expands to sd rs2',
10+
offset(rs1').
11+
definedBy: Zclsd
12+
assembly: c.sd rs2, offset(rs1)
13+
encoding:
14+
match: 111-----------00
15+
variables:
16+
- name: rs2
17+
location: 4-2
18+
- name: rs1
19+
location: 9-7
20+
- name: imm
21+
location: 12-10|6-5
22+
access:
23+
s: always
24+
u: always
25+
vs: always
26+
vu: always
27+
operation(): |
28+
29+
Bits<XLEN> base = X[2];
30+
Bits<XLEN> offset = imm << 3;
31+
Bits<XLEN> eff_addr = base + offset;
32+
33+
Bits<64> data = {X[rs2+1], X[rs2]};
34+
35+
write_memory<64>(eff_addr, data, $encoding);
36+
sail(): "" #not implemented in the sail model yet

arch/inst/Zclsd/c.sdsp.yaml

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# yaml-language-server: $schema=../../../schemas/inst_schema.json
2+
3+
$schema: "inst_schema.json#"
4+
kind: instruction
5+
name: c.sdsp
6+
long_name: Stack-pointer based store doubleword from even/odd register pair
7+
description: |
8+
Stores a stack-pointer relative 64-bit value from registers rs2' and rs2'+1. It computes an effective
9+
address by adding the zero-extended offset, scaled by 8, to the stack pointer, x2. It expands to sd
10+
rs2, offset(x2).
11+
definedBy: Zclsd
12+
assembly: c.sdsp rs2, offset(sp)
13+
encoding:
14+
match: 111-----------10
15+
variables:
16+
- name: rs2
17+
location: 6-2
18+
- name: imm
19+
location: 9-7|12-10
20+
left_shift: 3
21+
access:
22+
s: always
23+
u: always
24+
vs: always
25+
vu: always
26+
operation(): |
27+
28+
Bits<XLEN> base = X[2];
29+
Bits<XLEN> offset = imm;
30+
Bits<XLEN> eff_addr = base + offset;
31+
32+
Bits<64> data = {X[rs2+1], X[rs2]};
33+
34+
write_memory<64>(eff_addr, data, $encoding);
35+
sail(): "" #not implemented in the sail model yet

0 commit comments

Comments
 (0)