-
Notifications
You must be signed in to change notification settings - Fork 894
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
Add muldiv_c
and muxadd
peepopts
#4740
base: main
Are you sure you want to change the base?
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.
Hi Akash, I looked over the muxadd pattern
std::swap(add_a, add_b); | ||
endcode | ||
|
||
match mux |
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.
We can also match on the case of swapped mux inputs
passes/pmgen/peepopt_muxadd.pmg
Outdated
match mux | ||
// Select mux of form s ? (a + b) : a, allow leading 0s when A_WIDTH != Y_WIDTH | ||
select mux->type == $mux | ||
index <SigSpec> port(mux, \A) === SigSpec({Const(State::S0, GetSize(add_y)-GetSize(add_a)), add_a}) |
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.
This should be zero-padded if !param(add, \A_SIGNED).bool()
and sign-extended otherwise (provided add_a
is the A
input)
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 I am not sure this doesn't crash on add_y < add_a
which I don't think we rule out anywhere
mux->setPort(\A, Const(State::S0, GetSize(add_b))); | ||
mux->setPort(\B, add_b); | ||
mux->setPort(\Y, mid); | ||
add->setPort(\B, mid); |
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.
Wrong side of the adder if the swap above was hit (we need to use add_a_id
instead)
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.
Err, more like add_b_id
Thanks for the feedback on |
std::swap(a, b_const); | ||
endcode | ||
|
||
match div |
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.
No check that the divider and multiplier are connected
Co-authored-by: Martin Povišer <[email protected]>
Co-authored-by: Martin Povišer <[email protected]>
What are the reasons/motivation for this change?
This PR adds two peep-hole optimizations that improve netlist quality:
muldiv_c
:y = (a * b_const) / c_const ===> a * eval(b_const / c_const)
ifb_const % c_const == 0
. This implements basic constant propagation for multipliers and dividers with divisible constants.muxadd
:y = s ? (a + b) : a ===> y = a + (s ? b : 0)
. This provides useful restructuring for improving logic optimization.s ? b : 0
can be optimized to a bitwise AND in subsequent optimizations.Explain how this is achieved.
passes/pmgen/peepopt_muldiv_c.pmg
:muldiv_c
peepoptpasses/pmgen/peepopt_muxadd.pmg
:muxadd
peepoptpasses/pmgen/peepopt.cc
: Add to docs and run peepopts duringpeepopt
passpasses/pmgen/Makefile.inc
: Add the new sourcesIf applicable, please suggest to reviewers how they can test the change.
equiv_opt
or FOSSeqy