-
Notifications
You must be signed in to change notification settings - Fork 441
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
Support for [lsb+:width] slices #4917
base: main
Are you sure you want to change the base?
Conversation
4a72192
to
422673f
Compare
379c843
to
7ad797d
Compare
- allows for non-const lsb slices (width must still be const) Signed-off-by: Chris Dodd <[email protected]>
7ad797d
to
b7579c6
Compare
static Expression make(Expression a, unsigned hi, unsigned lo); | ||
} | ||
|
||
class AbsSlice : Slice { |
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 name AbsSlice is a little unclear. I would write it out. Or change it to "ConstantSlice"?
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.
Abs here is short for Absolute, which seems a better, more descriptive name than Constant to me. I could make it AbsoluteSlice intead, but that just seems excessively wordy. Another possibility is something like FixedSlice. However, none of these names seem 100% correct as "this is obvious what it means"
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.
Hmm, I have begun to prefer explicit naming over abbreviations because it reduces the cognitive load slightly when dealing with a new code base.
So it looks like they are called Variable Slices in SystemVerilog. How about naming the base class AbstractSlice
, Slice
, VariableSlice
? Or AbstractSlice
Constant/Fixed/AbsoluteSlice
VariableSlice
.
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.
AbstractSlice, Slice, VariableSlice
I'd lean towards this naming if possible
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 was avoiding renaming the abstract base class (Slice
) so as to minimize changes to other parts of the code/backends that don't really care about the details of what kind of slice it is. I also used PlusSlice
in case we also wanted to add MinusSlice
for [msb-:width]
slices in the future.
Slice(Util::SourceInfo si, Expression a, int hi, int lo) | ||
: Operation_Ternary(si, IR::Type::Bits::get(hi-lo+1), a, new Constant(hi), new Constant(lo)) {} | ||
Slice { | ||
unsigned getH() const override { return e1->to<IR::Constant>()->asUnsigned(); } |
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.
Should be a checked cast?
: Operation_Ternary(si, IR::Type::Bits::get(hi-lo+1), a, new Constant(hi), new Constant(lo)) {} | ||
Slice { | ||
unsigned getH() const override { return e1->to<IR::Constant>()->asUnsigned(); } | ||
unsigned getL() const override { return e2->to<IR::Constant>()->asUnsigned(); } |
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.
Same here, checked cast.
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.
These weren't checked casts before, so I was just keeping the same behavior.
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.
Yes, but this seems to lead a nullpointer access if the cast does not work.
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.
Which has the same net result -- an internal compiler error.
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.
True, but checkedTo adds some more output to the error.
Initial support for Verilog-style
[lsb+:width]
slices, allowing variable index slices with a constant width.Most backends will probably require that these be strength-reduced to constant (normal) indexes, which will happen with eg. unrolled loops where the index depends on the loop index.