Skip to content

Commit 3cfb0d1

Browse files
committed
feat: mock-up of rules-based B extension
1 parent 48cbf1b commit 3cfb0d1

File tree

4 files changed

+202
-30
lines changed

4 files changed

+202
-30
lines changed

arch/csr/misa.yaml

Lines changed: 110 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,76 @@ address: 0x301
88
writable: true
99
priv_mode: M
1010
length: MXLEN
11-
description: Reports the XLEN and "major" extensions supported by the ISA.
1211
definedBy: Sm
12+
prose:
13+
Overview:
14+
- type: informative
15+
text: |
16+
`misa` reports the base register size in M-mode and the set of single-letter
17+
extensions supported by the hart.
18+
- type: informative
19+
text: |
20+
The entire register may be read-only-0 in an implementation.
21+
If `misa` is read-only-0, discovery of `misa` information should be provided through
22+
non-standard mechanisms.
1323
fields:
1424
MXL:
1525
location_rv32: 31-30
1626
location_rv64: 63-62
17-
description: XLEN in M-mode.
27+
synopsys: |
28+
When `misa` is implemented, `misa.MXL` encodes the native base integer ISA width in M-mode,
29+
called `MXLEN`, as follows:
30+
31+
|===
32+
| MXL | MXLEN
33+
34+
| 1 | 32
35+
| 2 | 64
36+
|===
37+
38+
Other values are reserved.
39+
rules:
40+
- type: must
41+
id: csr-misa.mxl-value-rv32
42+
text: |
43+
`misa.MXL` must be read-only-1
44+
when(): return MISA_CSR_IMPLEMENTED && MXLEN == 32;
45+
- type: must
46+
id: csr-misa.mxl-value-rv64
47+
text: |
48+
`misa.MXL` must be read-only-2
49+
when(): return MISA_CSR_IMPLEMENTED && MXLEN == 64;
50+
- type: must
51+
id: csr-misa.mxl-value-not-implemented
52+
text: |
53+
`misa.MXL` must be read-only-0
54+
when(): return !MISA_CSR_IMPLEMENTED;
55+
prose:
56+
- type: informative
57+
text: |
58+
XLEN is never greater than MXLEN, but XLEN might be smaller than MXLEN in less-privileged
59+
modes.
60+
61+
- type: informative
62+
text: |
63+
The base width can be quickly ascertained using branches on the sign of the returned `misa`
64+
value, and possibly a shift left by one and a second branch on the sign.
65+
These checks can be written in assembly code without knowing the register width (MXLEN)
66+
of the hart.
67+
The base width is given by MXLEN=2MXL+4.
68+
69+
The base width can also be found if `misa` is zero, by placing the immediate 4 in a
70+
register, then shifting the register left by 31 bits at a time.
71+
If zero after one shift, then the hart is RV32.
72+
If zero after two shifts, then the hart is RV64, else RV128.
1873
type: RO
1974
reset_value(): |
20-
return (MXLEN == 32) ? 2'b01 : 2'b10;
75+
if (MISA_CSR_IMPLEMENTED) {
76+
return (MXLEN == 32) ? 2'b01 : 2'b10;
77+
} else {
78+
return 0;
79+
}
80+
2181
A:
2282
location: 0
2383
description: |
@@ -30,18 +90,60 @@ fields:
3090
reset_value(): |
3191
return implemented?(ExtensionName::A) ? 1 : 0;
3292
definedBy: A
93+
3394
B:
3495
location: 1
35-
description: |
96+
synopsis: |
3697
Indicates support for the `B` (bitmanip) extension.
98+
rules:
99+
- type: must
100+
id: csr-misa.b-reset-set
101+
text: |
102+
When all of `Zba`, `Zbb`, and `Zbs` are implemented, bit 1 of the `misa` CSR (`misa.B`) MUST reset to 1.
103+
when(): return MISA_CSR_IMPLEMENTED;
104+
105+
- type: must
106+
id: csr-misa.b-reset-clear
107+
text: |
108+
When at least one of `Zba`, `Zbb`, and `Zbs` are not implemented, `misa.B` MUST be read-only-0.
109+
when(): return MISA_CSR_IMPLEMENTED;
110+
111+
- type: may
112+
id: csr-misa.b-mutable
113+
text: |
114+
If parameter `MUTABLE_MISA_B` is true, the `misa.B` bit is writable.
115+
when(): return MISA_CSR_IMPLEMENTED;
116+
117+
- type: must
118+
id: csr-misa.b-clear-effect
119+
text: |
120+
Decoding an instruction from `Zba`, `Zbb`, or `Zbs` when `misa.B` is clear causes an
121+
`IllegalInstruction`.
122+
when(): return MISA_CSR_IMPLEMENTED && !nonconforming_extensions_implemented?();
123+
124+
- type: must
125+
id: csr-misa.b-clear-effect-non-conforming
126+
text: |
127+
Decoding an instruction from `Zba`, `Zbb`, or `Zbs` will either
128+
cause an `IllegalInstruction` trap or execute a non-conforming instruction if
129+
a non-conforming extension is supported that has an overlapping instruction with one from
130+
`Zba`, `Zbb`, or `Zbs`.
131+
when(): return MISA_CSR_IMPLEMENTED && nonconforming_extensions_implemented?();
37132

38-
[when,"MUTABLE_MISA_B == true"]
39-
Writing 0 to this field will cause all bitmanip instructions to raise an `IllegalInstruction` exception.
40133
type(): |
41-
return (implemented?(ExtensionName::B) && MUTABLE_MISA_B) ? CsrFieldType::RW : CsrFieldType::RO;
134+
if (MISA_CSR_IMPLEMENTED) {
135+
return (implemented?(ExtensionName::B) && MUTABLE_MISA_B) ? CsrFieldType::RW : CsrFieldType::RO;
136+
} else {
137+
return CsrFieldType::RO;
138+
}
42139
reset_value(): |
43-
return implemented?(ExtensionName::B) ? 1 : 0;
140+
if (MISA_CSR_IMPLEMENTED) {
141+
return implemented?(ExtensionName::B) ? 1 : 0;
142+
} else {
143+
return 0;
144+
}
44145
definedBy: B
146+
45147
C:
46148
location: 2
47149
description: |

arch/ext/B.yaml

Lines changed: 64 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
# yaml-language-server: $schema=../../schemas/ext_schema.json
1+
# yaml-language-server: $schema=../../schemas/ext_schema_1.0.json
22

3-
$schema: "ext_schema.json#"
3+
$schema: ext_schema_1.0.json#
44
kind: extension
55
name: B
66
type: unprivileged
@@ -27,16 +27,71 @@ versions:
2727
version: "1.0.0"
2828
- name: Zbs
2929
version: "1.0.0"
30-
description: |
31-
The B standard extension comprises instructions provided by the `Zba`, `Zbb`, and `Zbs` extensions.
3230

33-
Bit 1 of the `misa` register encodes the presence of the B standard extension. When `misa.B` is 1,
34-
the implementation supports the instructions provided by the `Zba`, `Zbb`, and `Zbs` extensions.
35-
When `misa.B` is 0, it indicates that the implementation may not support one or more of the
36-
`Zba`, `Zbb`, or `Zbs` extensions.
31+
synposis: |
32+
The B (bitmanip) standard extension is an umbrella extension that
33+
34+
. implies the `Zba`, `Zbb`, and `Zbs` extensions, and
35+
. defines the `misa.B` field, which provides an optional way to detect the presence of `Zba`,
36+
`Zbb`, and `Zbs` and/or dynamically disable the instructions from those implied extensions.
37+
38+
prose:
39+
- section_name: Overview
40+
paragraphs:
41+
- type: motivational
42+
text: |
43+
The B extension is intended to provide some combination of code size reduction, performance
44+
improvement, and energy reduction compared to the standard base RISC-V instructions alone.
45+
46+
- type: informative
47+
text: Bit 1 of the `misa` register encodes the presence of the B standard extension.
48+
49+
- type: intentional
50+
text: |
51+
Most of the instructions are expected to be forward compatible with RV128.
52+
While the shift-immediate instructions are defined to have at most a 6-bit immediate field,
53+
a 7th bit is available in the encoding space should this be needed for RV128.
54+
55+
- section_name: Word Instructions
56+
paragraphs:
57+
- type: informative
58+
text: |
59+
The bitmanip extension follows the convention in RV64 that _w_-suffixed instructions
60+
(without a dot before the _w_) ignore the upper 32 bits of their inputs, operate on the
61+
least-significant 32-bits as signed values and produce a 32-bit signed result that is
62+
sign-extended to XLEN.
63+
64+
- type: informative
65+
text: |
66+
Bitmanip instructions with the suffix _.uw_ have one operand that is an unsigned 32-bit
67+
value that is extracted from the least significant 32 bits of the specified register.
68+
Other than that, these perform full XLEN operations.
69+
70+
- type: informative
71+
text: |
72+
Bitmanip instructions with the suffix _.b_, _.h_ and _.w_ only look at the least
73+
significant 8-bits, 16-bits and 32-bits of the input (respectively) and produce an XLEN-wide
74+
result that is sign-extended or zero-extended, based on the specific instruction.
75+
76+
rules:
77+
- type: must
78+
id: ext-b-implemented
79+
text: |
80+
When all of `Zba`, `Zbb`, and `Zbs` are implemented, the B extension must be also be
81+
implemented.
82+
83+
- type: must
84+
id: ext-b-not-implemented
85+
text: |
86+
When at least one of `Zba`, `Zbb`, or `Zbs` is not implemented, the B extension cannot be
87+
implemented and `misa.B` must be read-only-0.
88+
3789
params:
3890
MUTABLE_MISA_B:
3991
description: |
40-
Indicates whether or not the `B` extension can be disabled with the `misa.B` bit.
92+
When true, the `misa.B` bit is writable by software.
93+
When false, the `misa.B` bit read-only-1.
4194
schema:
4295
type: boolean
96+
when:
97+
param(): return MISA_CSR_IMPLEMENTED;

arch/ext/Zba.yaml

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,21 +3,34 @@
33
$schema: "ext_schema.json#"
44
kind: extension
55
name: Zba
6+
base: [32, 64]
67
long_name: Address generation instructions
7-
description: |
8+
9+
synopsis: |
810
The Zba instructions can be used to accelerate the generation of addresses that index into
911
arrays of basic types (halfword, word, doubleword) using both unsigned word-sized and
1012
XLEN-sized indices: a shifted index is added to a base address.
1113
12-
The shift and add instructions do a left shift of 1, 2, or 3 because these are commonly found
13-
in real-world code and because they can be implemented with a minimal amount of additional
14-
hardware beyond that of the simple adder. This avoids lengthening the critical path in
15-
implementations.
14+
prose:
15+
Overview:
16+
- type: motivational
17+
text: |
18+
The shift and add instructions do a left shift of 1, 2, or 3 because these are commonly
19+
found in real-world code and because they can be implemented with a minimal amount of
20+
additional hardware beyond that of the simple adder.
21+
This avoids lengthening the critical path in implementations.
22+
23+
- type: informative
24+
text: |
25+
While the shift and add instructions are limited to a maximum left shift of 3, the `slli`
26+
instruction (from the base ISA) can be used to perform similar shifts for indexing into
27+
arrays of wider elements.
28+
The `slli.uw` — added in this extension — can be used when the index is to be interpreted
29+
as an unsigned word.
30+
31+
# there are no extension-wide rules associated with Zba
32+
rules: []
1633

17-
While the shift and add instructions are limited to a maximum left shift of 3, the `slli`
18-
instruction (from the base ISA) can be used to perform similar shifts for indexing into arrays
19-
of wider elements. The `slli.uw` -- added in this extension -- can be used when the index is to
20-
be interpreted as an unsigned word.
2134
type: unprivileged
2235
company:
2336
name: RISC-V International

arch/inst/Zba/add.uw.yaml

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,11 @@ kind: instruction
55
name: add.uw
66
long_name: Add unsigned word
77
base: 64
8-
description: |
9-
Performs an XLEN-wide addition between rs2 and the
10-
zero-extended least-significant word of rs1.
8+
rules:
9+
- type: must
10+
text: |
11+
`add.uw` performs an XLEN-wide addition between X register xs2 and the
12+
zero-extended least-significant word of X register xs1.
1113
definedBy: Zba
1214
assembly: xd, xs1, xs2
1315
format:
@@ -30,7 +32,7 @@ pseudoinstructions:
3032
- when: rs2 == 0
3133
to: zext.w xd, xs1
3234
operation(): |
33-
if (implemented?(ExtensionName::B) && (CSR[misa].B == 1'b0)) {
35+
if (MISA_CSR_IMPLEMENTED && implemented?(ExtensionName::B) && (CSR[misa].B == 1'b0)) {
3436
raise (ExceptionCode::IllegalInstruction, mode(), $encoding);
3537
}
3638

0 commit comments

Comments
 (0)