Skip to content

Commit 2d79d0c

Browse files
fix: align GPR register files with review feedback
Changes: - rename schema from register_schema.json to register_file_schema.json, remove "$ref": "#/$defs/register_file" from bottom of the schema, and introduce register_file_name. - drop per-register length and index fields, make abi mnemonics an array, and add 'caller_saved'/'callee_saved' booleans with default value of 'false'. - remove the 'count' helper in favor of conditioning individual register entries directly and infer indices from position. - fix the description for XLEN behavior and remove empty role arrays. - update the register-file section of README.adoc so the example mirrors the new schema. - register_file.rb: expose register data via '#data' and return Sorbet enum values for roles. Signed-off-by: Animesh Agarwal <[email protected]>
1 parent c386c70 commit 2d79d0c

File tree

6 files changed

+199
-213
lines changed

6 files changed

+199
-213
lines changed

spec/schemas/register_schema.json renamed to spec/schemas/register_file_schema.json

Lines changed: 31 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -5,50 +5,46 @@
55
"description": "Schema for describing a register file",
66

77
"$defs": {
8-
"count_variant": {
9-
"type": "object",
10-
"required": ["value", "when"],
11-
"additionalProperties": false,
12-
"properties": {
13-
"value": {
14-
"type": "integer",
15-
"description": "Override count when condition is satisfied"
16-
},
17-
"when": {
18-
"$ref": "schema_defs.json#/$defs/requires_entry"
19-
},
20-
"description": {
21-
"$ref": "schema_defs.json#/$defs/spec_text"
22-
}
23-
}
24-
},
258
"register_entry": {
269
"type": "object",
27-
"required": ["name", "index"],
10+
"required": ["name"],
2811
"additionalProperties": false,
2912
"properties": {
3013
"name": {
3114
"$ref": "schema_defs.json#/$defs/register_name"
3215
},
33-
"abi_mnemonic": {
34-
"$ref": "schema_defs.json#/$defs/register_alias"
35-
},
36-
"index": {
37-
"type": "integer",
38-
"minimum": 0,
39-
"description": "Register index"
16+
"abi_mnemonics": {
17+
"type": "array",
18+
"items": {
19+
"$ref": "schema_defs.json#/$defs/register_alias"
20+
},
21+
"minItems": 1,
22+
"uniqueItems": true,
23+
"description": "ABI mnemonic names for the register"
4024
},
4125
"description": {
4226
"$ref": "schema_defs.json#/$defs/spec_text"
4327
},
44-
"definedBy": {
45-
"$ref": "schema_defs.json#/$defs/requires_entry"
46-
},
4728
"when": {
4829
"$ref": "schema_defs.json#/$defs/requires_entry"
4930
},
50-
"length": {
51-
"$ref": "schema_defs.json#/$defs/bit_length_value"
31+
"sw_read()": {
32+
"type": "string",
33+
"description": "Function that returns the value of the register when read by software. Use this to define special behavior for registers (e.g., x0 always reads as zero)."
34+
},
35+
"sw_write(value)": {
36+
"type": "string",
37+
"description": "Function implementing custom write behavior for the register. Given a 'value', return either the value to be written or a modified value. Use this to define special behavior for registers (e.g., x0 ignores writes)."
38+
},
39+
"caller_saved": {
40+
"type": "boolean",
41+
"default": false,
42+
"description": "Whether the register is caller-saved"
43+
},
44+
"callee_saved": {
45+
"type": "boolean",
46+
"default": false,
47+
"description": "Whether the register is callee-saved"
5248
},
5349
"roles": {
5450
"type": "array",
@@ -63,8 +59,6 @@
6359
"frame_pointer",
6460
"return_value",
6561
"argument",
66-
"caller_saved",
67-
"callee_saved",
6862
"temporary"
6963
]
7064
},
@@ -80,23 +74,23 @@
8074
"name",
8175
"long_name",
8276
"description",
83-
"length",
77+
"register_length",
8478
"registers"
8579
],
8680
"additionalProperties": false,
8781
"properties": {
8882
"$schema": {
8983
"type": "string",
9084
"format": "uri-reference",
91-
"const": "register_schema.json#",
85+
"const": "register_file_schema.json#",
9286
"description": "Path to schema, relative to <UDB ROOT>/schemas"
9387
},
9488
"kind": {
9589
"type": "string",
9690
"const": "register_file"
9791
},
9892
"name": {
99-
"$ref": "schema_defs.json#/$defs/register_name"
93+
"$ref": "schema_defs.json#/$defs/register_file_name"
10094
},
10195
"long_name": {
10296
"type": "string"
@@ -111,34 +105,9 @@
111105
"type": "string",
112106
"enum": ["general_purpose", "floating_point", "vector"]
113107
},
114-
"length": {
108+
"register_length": {
115109
"$ref": "schema_defs.json#/$defs/bit_length_value"
116110
},
117-
"count": {
118-
"oneOf": [
119-
{
120-
"type": "integer",
121-
"minimum": 0
122-
},
123-
{
124-
"type": "object",
125-
"required": ["default"],
126-
"additionalProperties": false,
127-
"properties": {
128-
"default": {
129-
"type": "integer",
130-
"minimum": 0
131-
},
132-
"variants": {
133-
"type": "array",
134-
"items": {
135-
"$ref": "#/$defs/count_variant"
136-
}
137-
}
138-
}
139-
}
140-
]
141-
},
142111
"registers": {
143112
"type": "array",
144113
"minItems": 1,
@@ -152,6 +121,5 @@
152121
}
153122
}
154123
}
155-
},
156-
"$ref": "#/$defs/register_file"
124+
}
157125
}

spec/schemas/schema_defs.json

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,8 @@
5252
},
5353
{
5454
"type": "string",
55-
"minLength": 1
55+
"minLength": 1,
56+
"enum": ["MXLEN"]
5657
}
5758
]
5859
},
@@ -61,6 +62,11 @@
6162
"pattern": "^[A-Za-z][A-Za-z0-9_.-]*$",
6263
"description": "Register name"
6364
},
65+
"register_file_name": {
66+
"type": "string",
67+
"pattern": "^[A-Za-z][A-Za-z0-9_.-]*$",
68+
"description": "Register file name"
69+
},
6470
"register_alias": {
6571
"type": "string",
6672
"pattern": "^[A-Za-z][A-Za-z0-9_.-]*$",

spec/std/isa/README.adoc

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@ Three standard configs are present:
2929
* `rv64`: A configuration where only `MXLEN` is known to be 64, i.e., the RV64 ISA.
3030

3131
The architecture is specified in a series of https://en.wikipedia.org/wiki/YAML[YAML]
32-
files for _Extensions_, _Instructions_, _Registers_, and _Control and Status Registers (CSRs)_.
33-
Each extension/instruction/register/CSR has its own file.
32+
files for _Extensions_, _Instructions_, _RegFiles_, and _Control and Status Registers (CSRs)_.
33+
Each extension/instruction/regfile/CSR has its own file.
3434

3535
== Flow
3636

@@ -142,38 +142,39 @@ H: # <1>
142142

143143
=== Instructions
144144

145-
=== Registers
145+
=== Register Files
146146

147147
.Example register file specification
148148
[source,yaml]
149149
----
150-
$schema: register_schema.json#
150+
$schema: register_file_schema.json#
151151
kind: register_file
152152
name: X
153153
long_name: Integer General Purpose Registers
154154
definedBy: I
155155
register_class: general_purpose
156-
length: XLEN # <1>
157-
count:
158-
default: 32
159-
variants:
160-
- value: 16
161-
when: { name: E } # <2>
156+
register_length: MXLEN # <1>
162157
registers:
163-
- name: x0
164-
index: 0
165-
abi_mnemonic: zero # <3>
158+
- name: x0 # <2>
159+
abi_mnemonics: [zero] # <3>
166160
roles: [zero]
161+
sw_read(): | # <4>
162+
return 0;
163+
sw_write(value): |
164+
# x0 ignores all writes
167165
- name: x1
168-
index: 1
169-
abi_mnemonic: ra
166+
abi_mnemonics: [ra]
170167
roles: [return_address]
168+
- name: x8
169+
abi_mnemonics: [s0, fp] # <5>
170+
roles: [callee_saved, frame_pointer]
171171
----
172172

173-
<1> Register files are defined independently of the resolved XLEN; individual register entries
174-
may override the default bit length when necessary.
175-
<2> Conditional presence uses the same `when`/`definedBy` semantics as other database objects.
176-
<3> Entries can record ABI mnemonics and semantic roles.
173+
<1> Registers can have either a fixed architecture width or take their width from a parameter (e.g., MXLEN, VLEN).
174+
<2> Each register has a unique name (e.g., x0, x1, x2, etc.). The register's index is inferred from its position in the array (starting from 0).
175+
<3> Registers can optionally have ABI mnemonics (e.g., ra, sp, fp, etc.).
176+
<4> Individual registers can define `sw_read()` and `sw_write()` for special behavior (e.g., x0 hardwired to zero).
177+
<5> A register can have multiple ABI mnemonics (e.g., x8 is known as both s0 and fp).
177178

178179
[source,yaml]
179180
----

0 commit comments

Comments
 (0)