registers.py: Fix subtractions in generated C code#1099
Open
JanMatCodasip wants to merge 2 commits intoriscv:mainfrom
Open
registers.py: Fix subtractions in generated C code#1099JanMatCodasip wants to merge 2 commits intoriscv:mainfrom
JanMatCodasip wants to merge 2 commits intoriscv:mainfrom
Conversation
6b8b91d to
065f527
Compare
Contributor
Author
|
For an easier review, attached are the generated files before and after this change: |
Contributor
Author
|
@en-sc Would you please have a moment for this review? Thank you. |
rtwfroody
requested changes
Feb 17, 2025
registers.py
Outdated
Comment on lines
+485
to
+489
| negative_constant = arg.is_constant() and (arg < 0) | ||
| result += " - " if negative_constant else " + " | ||
| if negative_constant: | ||
| arg = -arg # flip to positive | ||
| result += stc(arg) |
Collaborator
There was a problem hiding this comment.
This seems simpler to read:
Suggested change
| negative_constant = arg.is_constant() and (arg < 0) | |
| result += " - " if negative_constant else " + " | |
| if negative_constant: | |
| arg = -arg # flip to positive | |
| result += stc(arg) | |
| if arg.is_constant() and (arg < 0): | |
| result += " - %s" % stc(-arg) | |
| else: | |
| result += " + %s" % stc(arg) |
Contributor
Author
There was a problem hiding this comment.
I agree, that is much cleaner. I have adopted the suggestion. Thanks.
The registers.py generator outputs expressions with subtractions
into the C code of debug_defines.{h,c} in this form:
```
((XLEN) + -6ULL)
```
Such code may look awkward to code readers and also triggers GCC's
-Wconversion warnings (when enabled).
Fix the generator to produce the expressions with subtraction
in a natural form:
```
((XLEN) - 6ULL)
```
065f527 to
972156c
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The registers.py generator outputs expressions with subtractions into the C code of debug_defines.{h,c} in this form:
Such code may look awkward to code readers and also triggers GCC's
-Wconversionwarnings in the projects that will include these generated C files.Fix the generator to produce expressions with subtraction in a natural form: