Skip to content
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

Expand nf fields in instr_dict.yaml #274

Merged
merged 1 commit into from
Aug 20, 2024
Merged
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
35 changes: 34 additions & 1 deletion parse.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#!/usr/bin/env python3

from constants import *
import copy
import re
import glob
import os
Expand Down Expand Up @@ -164,6 +165,37 @@ def extension_overlap_allowed(x, y):
def instruction_overlap_allowed(x, y):
return overlap_allowed(overlapping_instructions, x, y)

def add_segmented_vls_insn(instr_dict):
updated_dict = {}
for k, v in instr_dict.items():
if "nf" in v['variable_fields']:
for new_key, new_value in expand_nf_field(k,v):
updated_dict[new_key] = new_value
else:
updated_dict[k] = v
return updated_dict

def expand_nf_field(name, single_dict):
if "nf" not in single_dict['variable_fields']:
logging.error(f"Cannot expand nf field for instruction {name}")
raise SystemExit(1)

# nf no longer a variable field
single_dict['variable_fields'].remove("nf")
# include nf in mask
single_dict['mask'] = hex(int(single_dict['mask'],16) | 0b111 << 29)

name_expand_index = name.find('e')
expanded_instructions = []
for nf in range(0,8):
new_single_dict = copy.deepcopy(single_dict)
new_single_dict['match'] = hex(int(single_dict['match'],16) | nf << 29)
new_single_dict['encoding'] = format(nf, '03b') + single_dict['encoding'][3:]
new_name = name if nf == 0 else name[:name_expand_index] + "seg" + str(nf+1) + name[name_expand_index:]
expanded_instructions.append((new_name, new_single_dict))
return expanded_instructions


def create_inst_dict(file_filter, include_pseudo=False, include_pseudo_ops=[]):
'''
This function return a dictionary containing all instructions associated
Expand Down Expand Up @@ -1008,8 +1040,9 @@ def signed(value, width):
include_pseudo = True

instr_dict = create_inst_dict(extensions, include_pseudo)

with open('instr_dict.yaml', 'w') as outfile:
yaml.dump(instr_dict, outfile, default_flow_style=False)
yaml.dump(add_segmented_vls_insn(instr_dict), outfile, default_flow_style=False)
instr_dict = collections.OrderedDict(sorted(instr_dict.items()))

if '-c' in sys.argv[1:]:
Expand Down
Loading