3
0
Fork 0
mirror of https://github.com/YosysHQ/yosys synced 2025-04-13 04:28:18 +00:00

Merge pull request #3924 from andyfox-rushc/master

multpass -- create Booth Encoded multipliers for
This commit is contained in:
Martin Povišer 2023-09-18 16:46:59 +02:00 committed by GitHub
commit 54be4aca90
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 1561 additions and 36 deletions

View file

@ -4,6 +4,7 @@ OBJS += passes/techmap/techmap.o
OBJS += passes/techmap/simplemap.o OBJS += passes/techmap/simplemap.o
OBJS += passes/techmap/dfflibmap.o OBJS += passes/techmap/dfflibmap.o
OBJS += passes/techmap/maccmap.o OBJS += passes/techmap/maccmap.o
OBJS += passes/techmap/booth.o
OBJS += passes/techmap/libparse.o OBJS += passes/techmap/libparse.o
ifeq ($(ENABLE_ABC),1) ifeq ($(ENABLE_ABC),1)

1524
passes/techmap/booth.cc Normal file

File diff suppressed because it is too large Load diff

View file

@ -17,17 +17,16 @@
* *
*/ */
#include "kernel/register.h"
#include "kernel/celltypes.h" #include "kernel/celltypes.h"
#include "kernel/rtlil.h"
#include "kernel/log.h" #include "kernel/log.h"
#include "kernel/register.h"
#include "kernel/rtlil.h"
USING_YOSYS_NAMESPACE USING_YOSYS_NAMESPACE
PRIVATE_NAMESPACE_BEGIN PRIVATE_NAMESPACE_BEGIN
struct SynthPass : public ScriptPass struct SynthPass : public ScriptPass {
{ SynthPass() : ScriptPass("synth", "generic synthesis script") {}
SynthPass() : ScriptPass("synth", "generic synthesis script") { }
void help() override void help() override
{ {
@ -60,6 +59,9 @@ struct SynthPass : public ScriptPass
log(" -noabc\n"); log(" -noabc\n");
log(" do not run abc (as if yosys was compiled without ABC support)\n"); log(" do not run abc (as if yosys was compiled without ABC support)\n");
log("\n"); log("\n");
log(" -booth\n");
log(" run the booth pass to convert $mul to Booth encoded multipliers");
log("\n");
log(" -noalumacc\n"); log(" -noalumacc\n");
log(" do not run 'alumacc' pass. i.e. keep arithmetic operators in\n"); log(" do not run 'alumacc' pass. i.e. keep arithmetic operators in\n");
log(" their direct form ($add, $sub, etc.).\n"); log(" their direct form ($add, $sub, etc.).\n");
@ -93,7 +95,8 @@ struct SynthPass : public ScriptPass
} }
string top_module, fsm_opts, memory_opts, abc; string top_module, fsm_opts, memory_opts, abc;
bool autotop, flatten, noalumacc, nofsm, noabc, noshare, flowmap; bool autotop, flatten, noalumacc, nofsm, noabc, noshare, flowmap, booth;
int lut; int lut;
void clear_flags() override void clear_flags() override
@ -110,6 +113,7 @@ struct SynthPass : public ScriptPass
noabc = false; noabc = false;
noshare = false; noshare = false;
flowmap = false; flowmap = false;
booth = false;
abc = "abc"; abc = "abc";
} }
@ -119,24 +123,23 @@ struct SynthPass : public ScriptPass
clear_flags(); clear_flags();
size_t argidx; size_t argidx;
for (argidx = 1; argidx < args.size(); argidx++) for (argidx = 1; argidx < args.size(); argidx++) {
{ if (args[argidx] == "-top" && argidx + 1 < args.size()) {
if (args[argidx] == "-top" && argidx+1 < args.size()) {
top_module = args[++argidx]; top_module = args[++argidx];
continue; continue;
} }
if (args[argidx] == "-encfile" && argidx+1 < args.size()) { if (args[argidx] == "-encfile" && argidx + 1 < args.size()) {
fsm_opts = " -encfile " + args[++argidx]; fsm_opts = " -encfile " + args[++argidx];
continue; continue;
} }
if (args[argidx] == "-run" && argidx+1 < args.size()) { if (args[argidx] == "-run" && argidx + 1 < args.size()) {
size_t pos = args[argidx+1].find(':'); size_t pos = args[argidx + 1].find(':');
if (pos == std::string::npos) { if (pos == std::string::npos) {
run_from = args[++argidx]; run_from = args[++argidx];
run_to = args[argidx]; run_to = args[argidx];
} else { } else {
run_from = args[++argidx].substr(0, pos); run_from = args[++argidx].substr(0, pos);
run_to = args[argidx].substr(pos+1); run_to = args[argidx].substr(pos + 1);
} }
continue; continue;
} }
@ -164,6 +167,11 @@ struct SynthPass : public ScriptPass
noalumacc = true; noalumacc = true;
continue; continue;
} }
if (args[argidx] == "-booth") {
booth = true;
continue;
}
if (args[argidx] == "-nordff") { if (args[argidx] == "-nordff") {
memory_opts += " -nordff"; memory_opts += " -nordff";
continue; continue;
@ -206,8 +214,7 @@ struct SynthPass : public ScriptPass
void script() override void script() override
{ {
if (check_label("begin")) if (check_label("begin")) {
{
if (help_mode) { if (help_mode) {
run("hierarchy -check [-top <top> | -auto-top]"); run("hierarchy -check [-top <top> | -auto-top]");
} else { } else {
@ -221,8 +228,7 @@ struct SynthPass : public ScriptPass
} }
} }
if (check_label("coarse")) if (check_label("coarse")) {
{
run("proc"); run("proc");
if (help_mode || flatten) if (help_mode || flatten)
run("flatten", " (if -flatten)"); run("flatten", " (if -flatten)");
@ -240,6 +246,8 @@ struct SynthPass : public ScriptPass
run("techmap -map +/cmp2lut.v -map +/cmp2lcu.v", " (if -lut)"); run("techmap -map +/cmp2lut.v -map +/cmp2lcu.v", " (if -lut)");
else if (lut) else if (lut)
run(stringf("techmap -map +/cmp2lut.v -map +/cmp2lcu.v -D LUT_WIDTH=%d", lut)); run(stringf("techmap -map +/cmp2lut.v -map +/cmp2lcu.v -D LUT_WIDTH=%d", lut));
if (booth)
run("booth");
if (!noalumacc) if (!noalumacc)
run("alumacc", " (unless -noalumacc)"); run("alumacc", " (unless -noalumacc)");
if (!noshare) if (!noshare)
@ -249,50 +257,40 @@ struct SynthPass : public ScriptPass
run("opt_clean"); run("opt_clean");
} }
if (check_label("fine")) if (check_label("fine")) {
{
run("opt -fast -full"); run("opt -fast -full");
run("memory_map"); run("memory_map");
run("opt -full"); run("opt -full");
run("techmap"); run("techmap");
if (help_mode) if (help_mode) {
{
run("techmap -map +/gate2lut.v", "(if -noabc and -lut)"); run("techmap -map +/gate2lut.v", "(if -noabc and -lut)");
run("clean; opt_lut", " (if -noabc and -lut)"); run("clean; opt_lut", " (if -noabc and -lut)");
run("flowmap -maxlut K", " (if -flowmap and -lut)"); run("flowmap -maxlut K", " (if -flowmap and -lut)");
} } else if (noabc && lut) {
else if (noabc && lut)
{
run(stringf("techmap -map +/gate2lut.v -D LUT_WIDTH=%d", lut)); run(stringf("techmap -map +/gate2lut.v -D LUT_WIDTH=%d", lut));
run("clean; opt_lut"); run("clean; opt_lut");
} } else if (flowmap) {
else if (flowmap)
{
run(stringf("flowmap -maxlut %d", lut)); run(stringf("flowmap -maxlut %d", lut));
} }
run("opt -fast"); run("opt -fast");
if (!noabc && !flowmap) { if (!noabc && !flowmap) {
#ifdef YOSYS_ENABLE_ABC #ifdef YOSYS_ENABLE_ABC
if (help_mode) if (help_mode) {
{
run(abc + " -fast", " (unless -noabc, unless -lut)"); run(abc + " -fast", " (unless -noabc, unless -lut)");
run(abc + " -fast -lut k", "(unless -noabc, if -lut)"); run(abc + " -fast -lut k", "(unless -noabc, if -lut)");
} } else {
else
{
if (lut) if (lut)
run(stringf("%s -fast -lut %d", abc.c_str(), lut)); run(stringf("%s -fast -lut %d", abc.c_str(), lut));
else else
run(abc + " -fast"); run(abc + " -fast");
} }
run("opt -fast", " (unless -noabc)"); run("opt -fast", " (unless -noabc)");
#endif #endif
} }
} }
if (check_label("check")) if (check_label("check")) {
{
run("hierarchy -check"); run("hierarchy -check");
run("stat"); run("stat");
run("check"); run("check");

1
tests/techmap/booth.ys Normal file
View file

@ -0,0 +1 @@
test_cell -s 1694091355 -n 1000 -script booth_map_script.ys_ $mul

View file

@ -0,0 +1 @@
booth