Skip to content

Add type instructions and encodings as a separate schema #686

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 11 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 13 additions & 10 deletions arch/inst/Zba/add.uw.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,18 @@ description: |
zero-extended least-significant word of rs1.
definedBy: Zba
assembly: xd, xs1, xs2
encoding:
match: 0000100----------000-----0111011
variables:
- name: rs2
location: 24-20
- name: rs1
location: 19-15
- name: rd
location: 11-7
format:
$inherits:
- inst_subtype/R/R-x.yaml#
- inst_opcode/OP-32.yaml#
opcodes:
funct7:
display_name: ADD.UW
value: 0b0000100
funct3:
display_name: ADD.UW
value: 0b000
opcode: { $inherits: inst_opcode/OP-32.yaml#/data }
access:
s: always
u: always
Expand All @@ -32,7 +35,7 @@ operation(): |
raise (ExceptionCode::IllegalInstruction, mode(), $encoding);
}

X[rd] = X[rs2] + X[rs1][31:0];
X[xd] = X[xs2] + X[xs1][31:0];

# SPDX-SnippetBegin
# SPDX-FileCopyrightText: 2017-2025 Contributors to the RISCV Sail Model <https://github.com/riscv/sail-riscv/blob/master/LICENCE>
Expand Down
9 changes: 9 additions & 0 deletions arch/inst_opcode/OP-32.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# yaml-language-server: $schema=../../schemas/inst_opcode_schema.json#

$schema: inst_opcode_schema.json#
kind: instruction_opcode
name: OP-32

data:
display_name: OP-32
value: 0b0111011
8 changes: 8 additions & 0 deletions arch/inst_opcode/funct3.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# yaml-language-server: $schema=../../schemas/inst_opcode_schema.json#

$schema: inst_opcode_schema.json#
kind: instruction_opcode
name: funct3

data:
location: 14-12
Comment on lines +7 to +8
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unfortuntely, "funct3" is not always at this location. It depends on the format. For example, CI, CSS, CIW, CL, CS all have a "funct3" at 15-13.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would you prefer we just drop the indirection or call it something like R-funct3?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do you think about something like this?

  • arch/inst_type/R.yaml (unchanged)
  • arch/inst_subtype/R-x.yaml:
    data:
      type: { "$ref": "inst_type/R.yaml#" }
      subtype: { "$ref": "inst_subtype/R/R-x.yaml#" }
      $inherits:
        - inst_type/R.yaml#/opcodes
        - inst_var/xs2.yaml#/data
        - inst_var/xs1.yaml#/data
        - inst_var/xd.yaml#/data
  • arch/inst/Zba/add.uw.yaml:
    format:
      $inherits: inst_subtype/R/R-x.yaml#
      opcodes:
        funct7:
          display_name: ADD.UW
          value: 0b0000100
        funct3:
          display_name: ADD.UW
          value: 0b000
        opcode: { $inherits: inst_opcode/OP-32.yaml#/data }
  • arch/inst_var/xs2.yaml:
    data:
      $inherits: inst_type/R.yaml#/variables/rs2
      type: { "$ref": "inst_var_type/x_src_reg.yaml#" }

etc.

So, R-x subtype inherits opcodes from the base type, R.
And xs2 inherits attributes (just "location") from the base type R's rs2.
(I removed the top-level "inherits: OP-32" from "add.uw.yaml". Was that needed?)

8 changes: 8 additions & 0 deletions arch/inst_opcode/funct7.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# yaml-language-server: $schema=../../schemas/inst_opcode_schema.json#

$schema: inst_opcode_schema.json#
kind: instruction_opcode
name: funct7

data:
location: 31-25
8 changes: 8 additions & 0 deletions arch/inst_opcode/opcode.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# yaml-language-server: $schema=../../schemas/inst_opcode_schema.json#

$schema: inst_opcode_schema.json#
kind: instruction_opcode
name: opcode

data:
location: 6-0
16 changes: 16 additions & 0 deletions arch/inst_subtype/R/R-x.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# yaml-language-server: $schema=../../../schemas/inst_subtype_schema.json

$schema: inst_subtype_schema.json#
kind: instruction_subtype
name: R-x

data:
type: { "$ref": "inst_type/R.yaml#" }
subtype: { "$ref": "inst_subtype/R/R-x.yaml#" }
$inherits:
- inst_opcode/funct7.yaml#/data
- inst_opcode/funct3.yaml#/data
- inst_opcode/opcode.yaml#/data
- inst_var/xs2.yaml#/data
- inst_var/xs1.yaml#/data
- inst_var/xd.yaml#/data
20 changes: 20 additions & 0 deletions arch/inst_type/R.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# yaml-language-server: $schema=../../schemas/inst_type_schema.json#

$schema: inst_type_schema.json#
kind: instruction_type
name: R
description: R-type instructions usually have two source registers and one destination registers
opcodes:
funct7:
location: 31-25
funct3:
location: 14-12
opcode:
location: 6-0
variables:
rs2:
location: 24-20
rs1:
location: 19-15
rd:
location: 11-7
9 changes: 9 additions & 0 deletions arch/inst_var/xd.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# yaml-language-server: $schema=../../schemas/inst_var_schema.json#

$schema: inst_var_schema.json#
kind: instruction_variable
name: xd

data:
location: 11-7
type: { "$ref": "inst_var_type/x_dst_reg.yaml#" }
9 changes: 9 additions & 0 deletions arch/inst_var/xs1.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# yaml-language-server: $schema=../../schemas/inst_var_schema.json#

$schema: inst_var_schema.json#
kind: instruction_variable
name: xs1

data:
location: 19-15
type: { "$ref": "inst_var_type/x_src_reg.yaml#" }
9 changes: 9 additions & 0 deletions arch/inst_var/xs2.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# yaml-language-server: $schema=../../schemas/inst_var_schema.json#

$schema: inst_var_schema.json#
kind: instruction_variable
name: xs2

data:
location: 24-20
type: { "$ref": "inst_var_type/x_src_reg.yaml#" }
8 changes: 8 additions & 0 deletions arch/inst_var_type/x_dst_reg.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# yaml-language-server: $schema=../../schemas/inst_var_type_schema.json#

$schema: inst_var_type_schema.json#
kind: instruction_variable_type
name: x_dst_reg
type: register_reference
register_file: X
access: W
8 changes: 8 additions & 0 deletions arch/inst_var_type/x_src_reg.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# yaml-language-server: $schema=../../schemas/inst_var_type_schema.json#

$schema: inst_var_type_schema.json#
kind: instruction_variable_type
name: x_src_reg
type: register_reference
register_file: X
access: R
Loading
Loading