-
Notifications
You must be signed in to change notification settings - Fork 12
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
Added parse.py, constants.py and Makefile modifications to generate yaml files. #21
base: main
Are you sure you want to change the base?
Added parse.py, constants.py and Makefile modifications to generate yaml files. #21
Conversation
Sorry for the ammount of pushes, but this is a more clean structure with fewer LoC, reutilizing the riscv-opcode submodule |
Signed-off-by: Afonso Oliveira <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instructions with a full (no variables) encoding have a YAML format error. The match field starts with a single quote, but isn't terminated. For example:
ecall:
long_name: No synopsis available.
description: |
No description available.
definedBy: [I]
assembly: ecall
encoding:
match: '00000000000000000000000001110011
variables: []
access:
s: TODO
u: TODO
vs: TODO
vu: TODO
operation(): |
FYI, the auto-inst YAML files were very useful finding some errors in the hand-written instruction encodings. Most have been fixed in the pr/AFOliveira/21 branch. The remaining issues fall into two categories:
Details:
|
This should be solved on the new branch with my most recent commit.
This was already solved it was only a bug when I converted the files to this structure, I will fix it and upload it |
Getting Back on this, my latest commit, added the possiblity to add left_shift encapsulation to variables.
|
I think almost all the issues are now adressed on the PR branch with the exception of "sign_extend"=>true , which can be solved in the same way of the left_shift if you also agree so. I would like to know if there are any other instructions that were already hand-written on arch, so that I could add to the left_shift, which as of now is still pretty incomplete. |
Great! Like we discussed, we can just forget about sign_extend; it isn't being used and I will just get rid of it in existing files. |
@dhower-qc can I PR that separate branch or do you prefer to keep it on the side? |
I'm still seeing three left shift discrepancies:
|
When there is a field that has a value restriction, e.g.:
riscv-unified-db is expecting a "not" field, like so:
Is that something we can do automatically? |
This the case because there were only three left shifts in the .yaml and therefore I decided to wait for more instructions before properly handling all of them. The back-end is already done for them though. |
Yes, it can. I forgot to mention it, my bad. What happened was that I could not find any examples on how this was being handled, but it can definitely be done automatically. I'll handle as soon as I can, thank you for pointing that out! |
This is now done! |
I just found an way of automating the left_shift that I believe will be applicable for all instructions. |
Left_shift is now fully automated for all instructions. |
@dhower-qc I'm still doing some changes on this to see if we possibly could indeed move a significant number of instructions in before the RISC-V Summit NA and I wanted to ask how should we describe pseudoinstructions other than on the the origininstructions. For fence as an example:
Is this enough to be able to generate a subsequent index for pseudo instructions as well or should we also print those pseudo instruction wish a flag of some type in order to identify them? |
Here is the checker script I've been using. When placed in ext/auto-instr, I run it like this (to use the container enviornment): command ./bin/ruby ext/auto-instr/compare.rb compare.rb require 'pathname'
require 'yaml'
root = Pathname.new(__FILE__).dirname.realpath
arch_path = (root / '..' / '..' /'arch').realpath
auto_path = (root / 'yaml_output').realpath
def compare_variables(inst_name, auto_vars, arch_vars)
auto_vars.each do |var|
warn "No variables for #{inst_name}?" if arch_vars.nil?
unless arch_vars.include?(var)
arch_var = arch_vars.find { |v| v["name"] == var["name"]}
warn "No variable '#{var["name"]}' for #{inst_name} in arch (#{arch_vars})" if arch_var.nil?
if var["location"] == "#{arch_var["location"]}-#{arch_var["location"]}"
next # ok, just written differently
end
warn "Variable mismatch for #{inst_name}:"
warn " auto: #{var}"
warn " arch: #{arch_var}"
end
end
end
Dir.glob("#{auto_path}/**/*.yaml") do |f|
inst_name = File.basename(f, ".yaml")
matches = arch_path.glob("**/#{inst_name}.yaml")
next if matches.empty?
auto_yaml = YAML.load_file(f)
arch_yaml = YAML.load_file(matches.first)
if !auto_yaml[inst_name]["encoding"]["RV32"].nil?
if arch_yaml[inst_name]["encoding"]["RV32"].nil?
warn "Encoding mismatch for #{inst_name}: Auto splits by XLEN, but arch does not"
next
elsif auto_yaml[inst_name]["encoding"]["RV32"]["match"] != arch_yaml[inst_name]["encoding"]["RV32"]["match"]
warn "Encoding mismatch for #{inst_name}, RV32"
warn " auto: #{auto_yaml[inst_name]["encoding"]["RV32"]["match"]}"
warn " arch: #{arch_yaml[inst_name]["encoding"]["RV32"]["match"]}"
next
elsif auto_yaml[inst_name]["encoding"]["RV64"]["match"] != arch_yaml[inst_name]["encoding"]["RV64"]["match"]
warn "Encoding mismatch for #{inst_name}, RV32"
warn " auto: #{auto_yaml[inst_name]["encoding"]["RV64"]["match"]}"
warn " arch: #{arch_yaml[inst_name]["encoding"]["RV64"]["match"]}"
next
end
elsif !arch_yaml[inst_name]["encoding"]["RV32"].nil?
if auto_yaml[inst_name]["encoding"]["RV32"].nil?
warn "Encoding mismatch for #{inst_name}: Auto does not split by XLEN, but arch does"
next
elsif auto_yaml[inst_name]["encoding"]["RV32"]["match"] != arch_yaml[inst_name]["encoding"]["RV32"]["match"]
warn "Encoding mismatch for #{inst_name}, RV32"
warn " auto: #{auto_yaml[inst_name]["encoding"]["RV32"]["match"]}"
warn " arch: #{arch_yaml[inst_name]["encoding"]["RV32"]["match"]}"
next
elsif auto_yaml[inst_name]["encoding"]["RV64"]["match"] != arch_yaml[inst_name]["encoding"]["RV64"]["match"]
warn "Encoding mismatch for #{inst_name}, RV32"
warn " auto: #{auto_yaml[inst_name]["encoding"]["RV64"]["match"]}"
warn " arch: #{arch_yaml[inst_name]["encoding"]["RV64"]["match"]}"
next
end
elsif auto_yaml[inst_name]["encoding"]["match"] != arch_yaml[inst_name]["encoding"]["match"]
warn "Encoding mismatch for #{inst_name}"
warn " auto: #{auto_yaml[inst_name]["encoding"]["match"]}"
warn " arch: #{arch_yaml[inst_name]["encoding"]["match"]}"
next
end
# check variables
if !auto_yaml[inst_name]["encoding"]["RV32"].nil?
compare_variables(inst_name, auto_yaml[inst_name]["encoding"]["RV32"]["variables"], arch_yaml[inst_name]["encoding"]["RV32"]["variables"])
compare_variables(inst_name, auto_yaml[inst_name]["encoding"]["RV64"]["variables"], arch_yaml[inst_name]["encoding"]["RV64"]["variables"])
else
compare_variables(inst_name, auto_yaml[inst_name]["encoding"]["variables"], arch_yaml[inst_name]["encoding"]["variables"])
end
end |
Thank you! |
I believe that this type of file organization is a good workaround to not having everything in the upstream repo yet.
This version still has some bugs namely on pseudoinstructions and on some assembly code. I will be working on those and I'll submit a new PR when they're solved.