-
Notifications
You must be signed in to change notification settings - Fork 73
fix(gen): support subtype-based encodings in C header generator #904
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
fix(gen): support subtype-based encodings in C header generator #904
Conversation
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.
There are WAY too many unrelated changes to easily review this. Could you create a single commit with just the necessary changes to address the issue?
@ThinkOpenly pls see now |
I don't think these changes have any impact. Are you seeing some problems being resolved? I would expect that instead of finding the needed "match" string directly, you'd need to compute it by going into the "format" attribute and its children "opcodes" and "variables". Note that these changes would likely appear in
Part of your mission is to make those error messages go away. The current code just extracts the value of the "match" attribute, but you'll need to compute it. |
@ThinkOpenly would do that |
Thanks for the contribution! Like @ThinkOpenly said, you'll need to build up what used to be explicit in 'match'. Basically, start with an instruction-length string of '-'s and then replace any position that is occupied by an opcode value. So if you have: # andn.yaml
format:
funct7:
display_name: ANDN
location: 31-25
value: 0b0100000
funct3:
display_name: ANDN
location: 14-12
value: 0b111
opcode:
display_name: OP
location: 6-0
value: 0b0110011 You want to wind up with the string:
|
@dhower-qc thanks for help would make the changes as req |
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.
Thanks again for your efforts. Good code. Comments/questions inline.
backends/generators/generator.py
Outdated
encoding_filtered += 1 | ||
continue | ||
|
||
continue |
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.
does this have any effect?
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.
@blazethunderstorm can you see this review? It also seems randomly placed to me
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.
The continue
statement is still there, but looking again it does have a purpose: the code above handles the "format" case, and the code below handles the "encoding" case. These are mutually exclusive, so OK.
Nit: could you remove the extra blank line above the continue
statement?
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.
still there :-)
@blazethunderstorm I believe @ThinkOpenly comments were not addressed. |
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.
@blazethunderstorm not to this one, I thin k
backends/generators/generator.py
Outdated
encoding_filtered += 1 | ||
continue | ||
|
||
continue |
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.
@blazethunderstorm can you see this review? It also seems randomly placed to me
@blazethunderstorm You still have not addressed @ThinkOpenly comments, can you please take a look at them? |
@ThinkOpenly @AFOliveira pls review |
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.
Please finish that small loose end. I plan to re-test Golang generation and C Header this week to see if we are finaly close enough, and getting this PR in before I try it, would be great!
@ThinkOpenly comment. |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #904 +/- ##
=======================================
Coverage 46.05% 46.05%
=======================================
Files 11 11
Lines 4942 4942
Branches 1345 1345
=======================================
Hits 2276 2276
Misses 2666 2666
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
CI is failing, complaining about the extra blank line and three other formatting issues. |
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.
Looks good to me, please fix the commit history!
backends/generators/generator.py
Outdated
encoding_filtered += 1 | ||
continue | ||
|
||
match_bits = ["-" for _ in range(32)] |
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.
Does this work for compressed (extension "C" and friends) instructions? For example:
match: 000-----------01 |
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.
fixed pls review
backends/generators/generator.py
Outdated
) | ||
val_bin = bin(val_int)[2:].zfill(width) | ||
|
||
match_bits[31 - hi : 32 - lo + 1] = list(val_bin) |
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.
Also needs to accommodate compressed instructions (16 bit encoding)
This comment was marked as off-topic.
This comment was marked as off-topic.
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.
I don't think the recent changes work in practice.
To determine the actual length of the instruction encoding you probably need to:
- For instructions which have been converted to "format" style
- Access the instruction type's "length" attribute:
- Get the instruction's subtype.
- Get the subtype's type.
- Get the type's length.
- Or, compute the instruction's length by walking through all of the "opcodes" and "variables" and accounting for all of the bits.
- Access the instruction type's "length" attribute:
- For instructions which have not been converted to "format" and still use "encoding", get the length of the "match" field.
|
||
match_bits = ["-" for _ in range(32)] | ||
bit_length = 32 | ||
if "length" in data: |
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.
Is this ever true?
pass | ||
elif "C" in enabled_extensions: | ||
if any( | ||
loc.get("location", "").startswith("0..15") |
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.
Is this ever true?
val_bin = bin(val_int)[2:].zfill(width) | ||
|
||
match_bits[31 - hi : 32 - lo + 1] = list(val_bin) | ||
inst_width = 16 if encoding.get("compressed", False) else 32 |
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.
Is encoding.get("compressed"...
ever true?
What do you seek, @AFOliveira , given that the merge queue will squash everything? |
Nevermind, I'm just not used to the merge queue squash. |
Superceded by #1051 |
Fixes #893
Updated the generator.py to correctly detect instruction encodings when using the new type/subtype schema. Previously, it looked only for the old encoding field, so some instructions were skipped. Now it checks subtype fields and extracts encoding info from there.