Skip to content
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

Compiles and transforms correctly, fails equiv #1

Merged
merged 2 commits into from
Dec 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 10 additions & 7 deletions passes/pmgen/peepopt_muxadd.pmg
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ pattern muxadd
// y = s ? (a + b) : a ===> y = a + (s ? b : 0)
//

state <SigSpec> add_a add_b add_y
state <bool> add_a_signed
state <SigSpec> add_a add_b add_y add_a_ext
state <Const> add_a_signed
state <IdString> add_a_id

match add
Expand All @@ -21,12 +21,13 @@ match add
set add_a_id A
endmatch

code add_y add_a add_b
code add_y add_a add_b add_a_ext
// Get adder signals
add_a = port(add, \A);
add_b = port(add, \B);
add_y = port(add, \Y);

add_a_ext = SigSpec(add_a);
add_a_ext.extend_u0(GetSize(add_y), param(add, \A_SIGNED).as_bool());
// Fanout of each adder Y bit should be 1 (no bit-split)
if (nusers(add_y) != 2)
reject;
Expand All @@ -39,7 +40,7 @@ endcode
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(!param(add, \A_SIGNED).bool() ? () : State::S0, GetSize(add_y)-GetSize(add_a)), add_a})
index <SigSpec> port(mux, \A) === add_a_ext
index <SigSpec> port(mux, \B) === add_y
endmatch

Expand All @@ -55,11 +56,13 @@ code
mux->setPort(\B, add_b);
mux->setPort(\Y, mid);
add->setPort(\B, mid);
add->setPort(\Y, mux_y);

add->setPort(\A, add_a);
add->setPort(\Y, add_y);
module->connect(mux_y, add_y);
// Log, fixup, accept
log("muxadd pattern in %s: mux=%s, add=%s\n", log_id(module), log_id(mux), log_id(add));
add->fixup_parameters();
mux->fixup_parameters();
did_something = true;
accept;
endcode
2 changes: 1 addition & 1 deletion tests/peepopt/muxadd.ys
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ module top(a, b, s, y);
endmodule
EOF
check -assert
equiv_opt -assert peepopt
equiv_opt -assert peepopt ;;;
design -load postopt
select -assert-any t:$add %co1 %a w:y %i # assert adder rewired

Expand Down