Skip to content

Commit 19610a6

Browse files
committed
Add JAL corner case
Signed-off-by: Afonso Oliveira <[email protected]>
1 parent c216ca2 commit 19610a6

File tree

1 file changed

+31
-13
lines changed

1 file changed

+31
-13
lines changed

backends/opcodes_maker/yaml_to_json.py

Lines changed: 31 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -82,29 +82,26 @@ def canonical_immediate_names(
8282
Given a YAML immediate variable (its base name and location), return a list of canonical
8383
field names from fieldo.
8484
85-
This function supports several formats:
85+
Supports several formats:
8686
87-
1. Standard composite format of the form "X-Y|Z-W" (e.g. "31-25|11-7").
88-
For branch instructions (when var_name is "imm" and instr_name starts with "b"),
89-
the prefix is forced to "bimm".
87+
1. For branch instructions (name starts with 'b') and a 4-part compound format,
88+
e.g. "31|7|30-25|11-8", it extracts the two parts using 'bimm' as the prefix.
9089
91-
2. A new compound format with four parts separated by "|" (e.g. "31|7|30-25|11-8").
92-
In that case, we derive:
93-
- High part: MSB from the first part and LSB from the lower end of the third part.
94-
- Low part: MSB from the first number in the fourth part and LSB from the second part.
95-
For branch instructions, the prefix is forced to "bimm".
90+
2. For jump instructions (name starts with 'j') with a 4-part compound format,
91+
e.g. "31|19-12|20|30-21", it extracts the overall high (from part 0) and low (from part 1)
92+
and uses the 'jimm' prefix.
9693
97-
3. Non-composite locations in the form "X-Y".
94+
3. For a standard composite format "X-Y|Z-W", it compares the two ranges.
95+
4. For non-composite formats "X-Y", it does a simple lookup.
9896
"""
9997
parts = location.split("|")
10098
if len(parts) == 4 and var_name == "imm" and instr_name.lower().startswith("b"):
101-
# New compound format, e.g.: "31|7|30-25|11-8"
99+
# Branch compound format, e.g.: "31|7|30-25|11-8"
102100
try:
103-
# For the high part: take the first part as MSB and the lower end of the third part as LSB.
104101
high_msb = int(parts[0])
105102
high_lsb = int(parts[2].split("-")[-1])
106-
# For the low part: take the first number of the fourth part as MSB and the second part as LSB.
107103
low_msb = int(parts[3].split("-")[0])
104+
# parts[1] should be a simple number when converting for branch immediates.
108105
low_lsb = int(parts[1])
109106
except Exception as e:
110107
print(
@@ -123,6 +120,27 @@ def canonical_immediate_names(
123120
)
124121
return []
125122
return [hi_candidate, lo_candidate]
123+
elif len(parts) == 4 and var_name == "imm" and instr_name.lower().startswith("j"):
124+
# Jump compound format, e.g.: "31|19-12|20|30-21"
125+
try:
126+
# For jump immediates, the canonical field typically covers the whole range.
127+
# We extract the overall high (first part) and the lower end of the second part.
128+
high = int(parts[0])
129+
low = int(parts[1].split("-")[1])
130+
except Exception as e:
131+
print(
132+
f"Warning: invalid jump compound immediate format in location '{location}': {e}"
133+
)
134+
return []
135+
candidate = lookup_immediate_by_range(
136+
"jimm", high, low, instr_name, left_shift=left_shift
137+
)
138+
if candidate is None:
139+
print(
140+
f"Warning: jump compound immediate candidate not found in fieldo for {var_name} with location {location}"
141+
)
142+
return []
143+
return [candidate]
126144
elif "|" in location:
127145
# Standard composite format, e.g.: "31-25|11-7"
128146
import re

0 commit comments

Comments
 (0)