Skip to content

Commit faf7646

Browse files
feat(schema): add new instruction schema for types/subtypes (#686)
### Add instruction “type” schema & link sub‐types (closes #676) - **inst_schema.json**: - Introduce `type` object under `encoding` with a `$ref` to external `inst_type/...#.yaml` files - **inst_type_schema.json**: - Import of encoding schema for defining RV32/RV64 encodings for instruction types - Lays groundwork for sub‐types in R/I/B/S/U formats as discussed in #655 --------- Signed-off-by: Afonso Oliveira <Afonso.Oliveira@synopsys.com> Co-authored-by: Derek Hower <dhower@qti.qualcomm.com>
1 parent 5052790 commit faf7646

File tree

24 files changed

+1305
-144
lines changed

24 files changed

+1305
-144
lines changed

arch/inst/Zba/add.uw.yaml

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,17 @@ description: |
1010
zero-extended least-significant word of rs1.
1111
definedBy: Zba
1212
assembly: xd, xs1, xs2
13-
encoding:
14-
match: 0000100----------000-----0111011
15-
variables:
16-
- name: rs2
17-
location: 24-20
18-
- name: rs1
19-
location: 19-15
20-
- name: rd
21-
location: 11-7
13+
format:
14+
$inherits:
15+
- inst_subtype/R/R-x.yaml#/data
16+
opcodes:
17+
funct7:
18+
display_name: ADD.UW
19+
value: 0b0000100
20+
funct3:
21+
display_name: ADD.UW
22+
value: 0b000
23+
opcode: { $inherits: inst_opcode/OP-32.yaml#/data }
2224
access:
2325
s: always
2426
u: always
@@ -32,7 +34,7 @@ operation(): |
3234
raise (ExceptionCode::IllegalInstruction, mode(), $encoding);
3335
}
3436
35-
X[rd] = X[rs2] + X[rs1][31:0];
37+
X[xd] = X[xs2] + X[xs1][31:0];
3638
3739
# SPDX-SnippetBegin
3840
# SPDX-FileCopyrightText: 2017-2025 Contributors to the RISCV Sail Model <https://github.com/riscv/sail-riscv/blob/master/LICENCE>

arch/inst_opcode/OP-32.yaml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# yaml-language-server: $schema=../../schemas/inst_opcode_schema.json#
2+
3+
$schema: inst_opcode_schema.json#
4+
kind: instruction_opcode
5+
name: OP-32
6+
7+
data:
8+
display_name: OP-32
9+
value: 0b0111011

arch/inst_subtype/R/R-x.yaml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# yaml-language-server: $schema=../../../schemas/inst_subtype_schema.json
2+
3+
$schema: inst_subtype_schema.json#
4+
kind: instruction_subtype
5+
name: R-x
6+
7+
data:
8+
type: { "$ref": "inst_type/R.yaml#" }
9+
subtype: { "$ref": "inst_subtype/R/R-x.yaml#" }
10+
opcodes:
11+
$inherits: inst_type/R.yaml#/opcodes
12+
variables:
13+
xs2:
14+
$inherits: inst_var/xs2.yaml#/data
15+
xs1:
16+
$inherits: inst_var/xs1.yaml#/data
17+
xd:
18+
$inherits: inst_var/xd.yaml#/data

arch/inst_type/R.yaml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# yaml-language-server: $schema=../../schemas/inst_type_schema.json#
2+
3+
$schema: inst_type_schema.json#
4+
kind: instruction_type
5+
name: R
6+
description: R-type instructions usually have two source registers and one destination registers
7+
length: 32
8+
opcodes:
9+
funct7:
10+
location: 31-25
11+
funct3:
12+
location: 14-12
13+
opcode:
14+
location: 6-0
15+
variables:
16+
rs2:
17+
location: 24-20
18+
rs1:
19+
location: 19-15
20+
rd:
21+
location: 11-7

arch/inst_var/xd.yaml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# yaml-language-server: $schema=../../schemas/inst_var_schema.json#
2+
3+
$schema: inst_var_schema.json#
4+
kind: instruction_variable
5+
name: xd
6+
7+
data:
8+
$inherits: inst_type/R.yaml#/variables/rd
9+
type: { "$ref": "inst_var_type/x_dst_reg.yaml#" }

arch/inst_var/xs1.yaml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# yaml-language-server: $schema=../../schemas/inst_var_schema.json#
2+
3+
$schema: inst_var_schema.json#
4+
kind: instruction_variable
5+
name: xs1
6+
7+
data:
8+
$inherits: inst_type/R.yaml#/variables/rs1
9+
type: { "$ref": "inst_var_type/x_src_reg.yaml#" }

arch/inst_var/xs2.yaml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# yaml-language-server: $schema=../../schemas/inst_var_schema.json#
2+
3+
$schema: inst_var_schema.json#
4+
kind: instruction_variable
5+
name: xs2
6+
7+
data:
8+
$inherits: inst_type/R.yaml#/variables/rs2
9+
type: { "$ref": "inst_var_type/x_src_reg.yaml#" }

arch/inst_var_type/x_dst_reg.yaml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# yaml-language-server: $schema=../../schemas/inst_var_type_schema.json#
2+
3+
$schema: inst_var_type_schema.json#
4+
kind: instruction_variable_type
5+
name: x_dst_reg
6+
type: register_reference
7+
register_file: X
8+
access: W

arch/inst_var_type/x_src_reg.yaml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# yaml-language-server: $schema=../../schemas/inst_var_type_schema.json#
2+
3+
$schema: inst_var_type_schema.json#
4+
kind: instruction_variable_type
5+
name: x_src_reg
6+
type: register_reference
7+
register_file: X
8+
access: R

backends/cfg_html_doc/templates/inst.adoc.erb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ RV64::
3333
<%- else -%>
3434
[wavedrom, ,svg,subs='attributes',width="100%"]
3535
....
36-
<%= JSON.dump inst.wavedrom_desc(cfg_arch.param_values["MXLEN"]) %>
36+
<%= JSON.dump inst.wavedrom_desc(inst.base.nil? ? cfg_arch.param_values["MXLEN"] : inst.base) %>
3737
....
3838
<%- end -%>
3939

@@ -89,7 +89,7 @@ RV64::
8989
<%- else -%>
9090
[source,idl]
9191
----
92-
<%- inst.decode_variables(cfg_arch.param_values["MXLEN"]).each do |d| -%>
92+
<%- inst.decode_variables(inst.base.nil? ? cfg_arch.param_values["MXLEN"] : inst.base).each do |d| -%>
9393
<%= d.sext? ? 'signed ' : '' %>Bits<<%= d.size %>> <%= d.name %> = <%= d.extract %>;
9494
<%- end -%>
9595
----
@@ -120,7 +120,7 @@ Original::
120120
====
121121
<%- end -%>
122122

123-
<%- exception_list = inst.reachable_exceptions_str() -%>
123+
<%- exception_list = inst.reachable_exceptions_str(inst.base.nil? ? cfg_arch.param_values["MXLEN"] : inst.base) -%>
124124
<%- unless exception_list.empty? -%>
125125
== Exceptions
126126

0 commit comments

Comments
 (0)