2026-02-10 23:33:37 +01:00
|
|
|
/*
|
|
|
|
|
* yosys -- Yosys Open SYnthesis Suite
|
|
|
|
|
*
|
|
|
|
|
* Copyright (C) 2024 Silimate Inc.
|
|
|
|
|
*
|
|
|
|
|
* Permission to use, copy, modify, and/or distribute this software for any
|
|
|
|
|
* purpose with or without fee is hereby granted, provided that the above
|
|
|
|
|
* copyright notice and this permission notice appear in all copies.
|
|
|
|
|
*
|
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
|
|
|
|
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
|
|
|
|
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
|
|
|
|
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
|
|
|
|
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
|
|
|
|
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
|
|
|
|
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include "kernel/yosys.h"
|
|
|
|
|
#include "kernel/sigtools.h"
|
2026-02-11 19:56:07 +01:00
|
|
|
#include "kernel/ff.h"
|
|
|
|
|
#include <fstream>
|
2026-02-10 23:33:37 +01:00
|
|
|
|
|
|
|
|
USING_YOSYS_NAMESPACE
|
|
|
|
|
PRIVATE_NAMESPACE_BEGIN
|
|
|
|
|
|
2026-02-11 19:56:07 +01:00
|
|
|
void dump_flipflops_to_file(RTLIL::Design *design, const std::string &filename)
|
|
|
|
|
{
|
|
|
|
|
std::ofstream outfile(filename);
|
|
|
|
|
if (!outfile.is_open()) {
|
|
|
|
|
log_error("Cannot open file %s for writing\n", filename.c_str());
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for (auto module : design->selected_modules()) {
|
|
|
|
|
outfile << "Module: " << log_id(module) << "\n";
|
|
|
|
|
log("Module: %s\n", log_id(module));
|
|
|
|
|
|
|
|
|
|
for (auto cell : module->cells()) {
|
|
|
|
|
if (cell->is_builtin_ff()) {
|
|
|
|
|
outfile << " FF: " << log_id(cell) << " (type: " << log_id(cell->type) << ")\n";
|
|
|
|
|
log(" FF: %s (type: %s)\n", log_id(cell), log_id(cell->type));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
outfile << "\n";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
outfile.close();
|
|
|
|
|
log("Wrote flip-flop list to %s\n", filename.c_str());
|
|
|
|
|
}
|
|
|
|
|
|
2026-02-10 23:33:37 +01:00
|
|
|
struct SatClockgatePass : public Pass {
|
2026-02-11 19:56:07 +01:00
|
|
|
SatClockgatePass() : Pass("sat_clockgate", "SAT-based inferred clock gating") { }
|
2026-02-10 23:33:37 +01:00
|
|
|
|
|
|
|
|
void help() override
|
|
|
|
|
{
|
|
|
|
|
log("\n");
|
2026-02-11 19:56:07 +01:00
|
|
|
log(" sat_clockgate [options] [selection]\n");
|
|
|
|
|
log("\n");
|
|
|
|
|
log("This command performs SAT-based inferred clock gating insertion.\n");
|
2026-02-10 23:33:37 +01:00
|
|
|
log("\n");
|
2026-02-11 19:56:07 +01:00
|
|
|
log(" -threshold <n>\n");
|
|
|
|
|
log(" minimum number of clock cycles that must match for clock gating\n");
|
|
|
|
|
log(" to be inserted (default: 1)\n");
|
2026-02-10 23:33:37 +01:00
|
|
|
log("\n");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void execute(std::vector<std::string> args, RTLIL::Design *design) override
|
|
|
|
|
{
|
|
|
|
|
log_header(design, "Executing SAT_CLOCKGATE pass.\n");
|
|
|
|
|
|
2026-02-11 19:56:07 +01:00
|
|
|
int threshold = 1;
|
|
|
|
|
|
2026-02-10 23:33:37 +01:00
|
|
|
size_t argidx;
|
|
|
|
|
for (argidx = 1; argidx < args.size(); argidx++) {
|
2026-02-11 19:56:07 +01:00
|
|
|
if (args[argidx] == "-threshold" && argidx+1 < args.size()) {
|
|
|
|
|
threshold = std::stoi(args[++argidx]);
|
|
|
|
|
continue;
|
|
|
|
|
}
|
2026-02-10 23:33:37 +01:00
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
extra_args(args, argidx, design);
|
|
|
|
|
|
2026-02-11 19:56:07 +01:00
|
|
|
log("Using threshold: %d\n", threshold);
|
|
|
|
|
|
|
|
|
|
// Dump all flip-flops to file
|
|
|
|
|
dump_flipflops_to_file(design, "flip_flops.txt");
|
|
|
|
|
|
2026-02-10 23:33:37 +01:00
|
|
|
for (auto module : design->selected_modules()) {
|
|
|
|
|
log("Processing module %s...\n", log_id(module));
|
|
|
|
|
// TODO: Implement SAT-based clock gating logic
|
2026-02-11 19:56:07 +01:00
|
|
|
|
|
|
|
|
// Example: calling SAT pass
|
|
|
|
|
// Pass::call(design, stringf("sat -verify -prove <signal> 1 %s", log_id(module)));
|
2026-02-10 23:33:37 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
} SatClockgatePass;
|
|
|
|
|
|
|
|
|
|
PRIVATE_NAMESPACE_END
|