Skip to content

Commit

Permalink
muxadd breaks Quicklogic dsp inference, make it optional
Browse files Browse the repository at this point in the history
  • Loading branch information
Alain Dargelas committed Dec 21, 2024
1 parent 11e4446 commit 41a7c72
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 22 deletions.
15 changes: 11 additions & 4 deletions passes/pmgen/peepopt.cc
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,6 @@ struct PeepoptPass : public Pass {
log("\n");
log("This pass employs the following rules by default:\n");
log("\n");
log(" * muxadd - Replace S?(A+B):A with A+(S?B:0)\n");
log("\n");
log(" * muldiv - Replace (A*B)/B with A\n");
log("\n");
log(" * muldiv_c - Replace (A*B)/C with A*(B/C) when C is a const divisible by B.\n");
Expand All @@ -70,20 +68,28 @@ struct PeepoptPass : public Pass {
log(" based pattern to prevent combinational paths from the\n");
log(" output to the enable input after running clk2fflogic.\n");
log("\n");
log("If -withmuxadd is specified it adds the following rule:\n");
log("\n");
log(" * muxadd - Replace S?(A+B):A with A+(S?B:0)\n");
log("\n");
}
void execute(std::vector<std::string> args, RTLIL::Design *design) override
{
log_header(design, "Executing PEEPOPT pass (run peephole optimizers).\n");

bool formalclk = false;

bool withmuxadd = false;
size_t argidx;
for (argidx = 1; argidx < args.size(); argidx++)
{
if (args[argidx] == "-formalclk") {
formalclk = true;
continue;
}
if (args[argidx] == "-withmuxadd") {
withmuxadd = true;
continue;
}
break;
}
extra_args(args, argidx, design);
Expand Down Expand Up @@ -113,7 +119,8 @@ struct PeepoptPass : public Pass {
pm.run_shiftmul_left();
pm.run_muldiv();
pm.run_muldiv_c();
pm.run_muxadd();
if (withmuxadd)
pm.run_muxadd();
}
}
}
Expand Down
41 changes: 23 additions & 18 deletions tests/peepopt/muxadd.ys
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@


log -header "Test basic s?(a+b):a pattern gets transformed (a,b module inputs)"
log -push
design -reset
log -header "Test basic s?(a+b):a pattern gets transformed (a,b module inputs)"
log -push
design -reset
Expand All @@ -13,7 +18,7 @@ module top(a, b, s, y);
endmodule
EOF
check -assert
equiv_opt -assert peepopt
equiv_opt -assert peepopt -withmuxadd
design -load postopt
select -assert-any t:$add %co1 %a w:y %i # assert adder rewired
log -pop
Expand All @@ -31,7 +36,7 @@ module top(a, b, s, y);
endmodule
EOF
check -assert
equiv_opt -assert peepopt
equiv_opt -assert peepopt -withmuxadd
design -load postopt
select -assert-any t:$add %co1 %a w:y %i # assert adder rewired
log -pop
Expand All @@ -51,7 +56,7 @@ module top(a, b, s, y);
endmodule
EOF
check -assert
equiv_opt -assert peepopt
equiv_opt -assert peepopt -withmuxadd
design -load postopt
select -assert-any t:$add %co1 %a w:y %i # assert adder rewired
log -pop
Expand All @@ -72,7 +77,7 @@ module top(a_, b, s, y);
endmodule
EOF
check -assert
equiv_opt -assert peepopt
equiv_opt -assert peepopt -withmuxadd
design -load postopt
select -assert-any t:$add %co1 %a w:y %i # assert adder rewired
log -pop
Expand All @@ -96,7 +101,7 @@ module top(a, b_, f, s, y_);
endmodule
EOF
check -assert
equiv_opt -assert peepopt
equiv_opt -assert peepopt -withmuxadd
design -load postopt
select -assert-any t:$add %co1 %a w:y %i # assert adder rewired
log -pop
Expand All @@ -116,7 +121,7 @@ module top(a, b, ab, s, y);
endmodule
EOF
check -assert
equiv_opt -assert peepopt
equiv_opt -assert peepopt -withmuxadd
design -load postopt
select -assert-none t:$add %co1 %a w:y %i
log -pop
Expand All @@ -136,7 +141,7 @@ module top(a, b, s, y, z);
endmodule
EOF
check -assert
equiv_opt -assert peepopt
equiv_opt -assert peepopt -withmuxadd
design -load postopt
select -assert-none t:$add %co1 %a w:y %i

Expand All @@ -157,7 +162,7 @@ EOF
check -assert
wreduce
opt_clean
equiv_opt -assert peepopt
equiv_opt -assert peepopt -withmuxadd
design -load postopt
select -assert-none t:$add %co1 %a w:y %i

Expand All @@ -178,7 +183,7 @@ EOF
check -assert
wreduce
opt_clean
equiv_opt -assert peepopt
equiv_opt -assert peepopt -withmuxadd
design -load postopt
select -assert-none t:$add %co1 %a w:y %i

Expand All @@ -199,7 +204,7 @@ EOF
check -assert
wreduce
opt_clean
equiv_opt -assert peepopt
equiv_opt -assert peepopt -withmuxadd
design -load postopt
select -assert-none t:$add %co1 %a w:y %i

Expand All @@ -221,7 +226,7 @@ EOF
check -assert
wreduce
opt_clean
equiv_opt -assert peepopt
equiv_opt -assert peepopt -withmuxadd
design -load postopt
select -assert-none t:$add %co1 %a w:y %i

Expand All @@ -242,7 +247,7 @@ EOF
check -assert
wreduce
opt_clean
equiv_opt -assert peepopt
equiv_opt -assert peepopt -withmuxadd
design -load postopt
select -assert-any t:$add %co1 %a w:y %i

Expand All @@ -263,7 +268,7 @@ EOF
check -assert
wreduce
opt_clean
equiv_opt -assert peepopt
equiv_opt -assert peepopt -withmuxadd
design -load postopt
select -assert-any t:$add %co1 %a w:y %i

Expand All @@ -284,7 +289,7 @@ EOF
check -assert
wreduce
opt_clean
equiv_opt -assert peepopt
equiv_opt -assert peepopt -withmuxadd
design -load postopt
select -assert-any t:$add %co1 %a w:y %i # assert adder rewired

Expand All @@ -305,7 +310,7 @@ EOF
check -assert
wreduce
opt_clean
equiv_opt -assert peepopt
equiv_opt -assert peepopt -withmuxadd
design -load postopt
select -assert-any t:$add %co1 %a w:y %i # assert adder rewired

Expand All @@ -326,7 +331,7 @@ EOF
check -assert
wreduce
opt_clean
equiv_opt -assert peepopt
equiv_opt -assert peepopt -withmuxadd
design -load postopt
select -assert-any t:$add %co1 %a w:y %i # assert adder rewired

Expand All @@ -347,7 +352,7 @@ EOF
check -assert
wreduce
opt_clean
equiv_opt -assert peepopt
equiv_opt -assert peepopt -withmuxadd
design -load postopt
select -assert-any t:$add %co1 %a w:y %i # assert adder rewired

Expand All @@ -368,6 +373,6 @@ EOF
check -assert
wreduce
opt_clean
equiv_opt -assert peepopt
equiv_opt -assert peepopt -withmuxadd
design -load postopt
select -assert-any t:$add %co1 %a w:y %i # assert adder rewired

0 comments on commit 41a7c72

Please sign in to comment.