3
0
Fork 0
mirror of https://github.com/YosysHQ/yosys synced 2025-08-10 13:10:51 +00:00

muxadd and muldiv_c peepopt

This commit is contained in:
Alain Dargelas 2025-01-15 16:57:19 -08:00
parent 8dabfbe429
commit 31a5197a1c
9 changed files with 902 additions and 38 deletions

View file

@ -28,6 +28,9 @@ bool did_something;
// scratchpad configurations for pmgen
int shiftadd_max_ratio;
// Helper function, removes LSB 0s
SigSpec remove_bottom_padding(SigSpec sig);
#include "passes/pmgen/peepopt_pm.h"
struct PeepoptPass : public Pass {
@ -42,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");
@ -67,13 +68,17 @@ 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++)
{
@ -81,6 +86,10 @@ struct PeepoptPass : public Pass {
formalclk = true;
continue;
}
if (args[argidx] == "-withmuxadd") {
withmuxadd = true;
continue;
}
break;
}
extra_args(args, argidx, design);
@ -110,11 +119,21 @@ struct PeepoptPass : public Pass {
pm.run_shiftmul_left();
pm.run_muldiv();
pm.run_muldiv_c();
pm.run_muxadd();
if (withmuxadd)
pm.run_muxadd();
}
}
}
}
} PeepoptPass;
SigSpec remove_bottom_padding(SigSpec sig)
{
int i = 0;
for (; i < sig.size() - 1 && sig[i] == State::S0; i++) {
}
return sig.extract(i, sig.size() - i);
}
PRIVATE_NAMESPACE_END