2014-01-17 16:14:36 -06:00
|
|
|
/*
|
|
|
|
* yosys -- Yosys Open SYnthesis Suite
|
|
|
|
*
|
2021-06-07 17:39:36 -05:00
|
|
|
* Copyright (C) 2012 Claire Xenia Wolf <claire@yosyshq.com>
|
2015-07-02 04:14:30 -05:00
|
|
|
*
|
2014-01-17 16:14:36 -06:00
|
|
|
* 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.
|
2015-07-02 04:14:30 -05:00
|
|
|
*
|
2014-01-17 16:14:36 -06:00
|
|
|
* 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/register.h"
|
|
|
|
#include "kernel/celltypes.h"
|
|
|
|
#include "kernel/sigtools.h"
|
2022-08-02 08:36:29 -05:00
|
|
|
#include "kernel/mem.h"
|
2014-01-17 16:14:36 -06:00
|
|
|
#include "kernel/rtlil.h"
|
|
|
|
#include "kernel/log.h"
|
|
|
|
|
2018-06-01 04:49:58 -05:00
|
|
|
#define MODE_ZERO 0
|
|
|
|
#define MODE_ONE 1
|
|
|
|
#define MODE_UNDEF 2
|
|
|
|
#define MODE_RANDOM 3
|
|
|
|
#define MODE_ANYSEQ 4
|
|
|
|
#define MODE_ANYCONST 5
|
|
|
|
|
2014-09-27 09:17:53 -05:00
|
|
|
USING_YOSYS_NAMESPACE
|
|
|
|
PRIVATE_NAMESPACE_BEGIN
|
|
|
|
|
2018-08-17 22:38:07 -05:00
|
|
|
static RTLIL::Wire * add_wire(RTLIL::Module *module, std::string name, int width, bool flag_input, bool flag_output)
|
2018-05-13 19:13:54 -05:00
|
|
|
{
|
2018-08-17 22:38:07 -05:00
|
|
|
RTLIL::Wire *wire = NULL;
|
|
|
|
name = RTLIL::escape_id(name);
|
|
|
|
|
|
|
|
if (module->count_id(name) != 0)
|
|
|
|
{
|
|
|
|
log("Module %s already has such an object %s.\n", module->name.c_str(), name.c_str());
|
|
|
|
name += "$";
|
|
|
|
return add_wire(module, name, width, flag_input, flag_output);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
wire = module->addWire(name, width);
|
|
|
|
wire->port_input = flag_input;
|
|
|
|
wire->port_output = flag_output;
|
|
|
|
|
|
|
|
if (flag_input || flag_output) {
|
|
|
|
wire->port_id = module->wires_.size();
|
|
|
|
module->fixup_ports();
|
|
|
|
}
|
|
|
|
|
|
|
|
log("Added wire %s to module %s.\n", name.c_str(), module->name.c_str());
|
|
|
|
}
|
|
|
|
|
|
|
|
return wire;
|
2018-05-13 19:13:54 -05:00
|
|
|
}
|
|
|
|
|
2014-07-23 08:36:09 -05:00
|
|
|
struct SetundefWorker
|
2014-01-17 16:14:36 -06:00
|
|
|
{
|
2014-07-23 08:36:09 -05:00
|
|
|
int next_bit_mode;
|
|
|
|
uint32_t next_bit_state;
|
2017-05-28 04:59:05 -05:00
|
|
|
vector<SigSpec*> siglist;
|
2014-01-17 16:14:36 -06:00
|
|
|
|
2014-07-23 08:36:09 -05:00
|
|
|
RTLIL::State next_bit()
|
|
|
|
{
|
2018-06-01 04:49:58 -05:00
|
|
|
if (next_bit_mode == MODE_ZERO)
|
2014-07-23 08:36:09 -05:00
|
|
|
return RTLIL::State::S0;
|
2014-01-17 16:14:36 -06:00
|
|
|
|
2018-06-01 04:49:58 -05:00
|
|
|
if (next_bit_mode == MODE_ONE)
|
2014-07-23 08:36:09 -05:00
|
|
|
return RTLIL::State::S1;
|
2014-01-17 16:14:36 -06:00
|
|
|
|
2018-06-01 04:49:58 -05:00
|
|
|
if (next_bit_mode == MODE_UNDEF)
|
2018-03-12 07:52:35 -05:00
|
|
|
return RTLIL::State::Sx;
|
|
|
|
|
2018-06-01 04:49:58 -05:00
|
|
|
if (next_bit_mode == MODE_RANDOM)
|
|
|
|
{
|
|
|
|
// xorshift32
|
|
|
|
next_bit_state ^= next_bit_state << 13;
|
|
|
|
next_bit_state ^= next_bit_state >> 17;
|
|
|
|
next_bit_state ^= next_bit_state << 5;
|
|
|
|
log_assert(next_bit_state != 0);
|
|
|
|
|
|
|
|
return ((next_bit_state >> (next_bit_state & 15)) & 16) ? RTLIL::State::S0 : RTLIL::State::S1;
|
|
|
|
}
|
2014-07-23 08:36:09 -05:00
|
|
|
|
2018-06-01 04:49:58 -05:00
|
|
|
log_abort();
|
2014-07-23 08:36:09 -05:00
|
|
|
}
|
2014-01-17 16:14:36 -06:00
|
|
|
|
|
|
|
void operator()(RTLIL::SigSpec &sig)
|
|
|
|
{
|
2018-06-01 04:49:58 -05:00
|
|
|
if (next_bit_mode == MODE_ANYSEQ || next_bit_mode == MODE_ANYCONST) {
|
2017-05-28 04:59:05 -05:00
|
|
|
siglist.push_back(&sig);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-07-23 08:36:09 -05:00
|
|
|
for (auto &bit : sig)
|
|
|
|
if (bit.wire == NULL && bit.data > RTLIL::State::S1)
|
|
|
|
bit = next_bit();
|
2014-01-17 16:14:36 -06:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
struct SetundefPass : public Pass {
|
|
|
|
SetundefPass() : Pass("setundef", "replace undef values with defined constants") { }
|
2020-06-18 18:34:52 -05:00
|
|
|
void help() override
|
2014-01-17 16:14:36 -06:00
|
|
|
{
|
|
|
|
// |---v---|---v---|---v---|---v---|---v---|---v---|---v---|---v---|---v---|---v---|
|
|
|
|
log("\n");
|
|
|
|
log(" setundef [options] [selection]\n");
|
|
|
|
log("\n");
|
2017-05-28 04:31:35 -05:00
|
|
|
log("This command replaces undef (x) constants with defined (0/1) constants.\n");
|
2014-01-17 16:14:36 -06:00
|
|
|
log("\n");
|
|
|
|
log(" -undriven\n");
|
|
|
|
log(" also set undriven nets to constant values\n");
|
|
|
|
log("\n");
|
2018-05-13 15:53:35 -05:00
|
|
|
log(" -expose\n");
|
2018-07-04 14:14:28 -05:00
|
|
|
log(" also expose undriven nets as inputs (use with -undriven)\n");
|
2018-05-13 15:53:35 -05:00
|
|
|
log("\n");
|
2014-01-17 16:14:36 -06:00
|
|
|
log(" -zero\n");
|
|
|
|
log(" replace with bits cleared (0)\n");
|
|
|
|
log("\n");
|
|
|
|
log(" -one\n");
|
|
|
|
log(" replace with bits set (1)\n");
|
|
|
|
log("\n");
|
2018-03-12 07:52:35 -05:00
|
|
|
log(" -undef\n");
|
|
|
|
log(" replace with undef (x) bits, may be used with -undriven\n");
|
|
|
|
log("\n");
|
2017-05-28 04:59:05 -05:00
|
|
|
log(" -anyseq\n");
|
|
|
|
log(" replace with $anyseq drivers (for formal)\n");
|
|
|
|
log("\n");
|
2018-06-01 04:49:58 -05:00
|
|
|
log(" -anyconst\n");
|
|
|
|
log(" replace with $anyconst drivers (for formal)\n");
|
|
|
|
log("\n");
|
2014-01-17 16:14:36 -06:00
|
|
|
log(" -random <seed>\n");
|
2018-12-07 13:14:07 -06:00
|
|
|
log(" replace with random bits using the specified integer as seed\n");
|
2014-01-17 16:14:36 -06:00
|
|
|
log(" value for the random number generator.\n");
|
|
|
|
log("\n");
|
2016-06-03 04:38:31 -05:00
|
|
|
log(" -init\n");
|
|
|
|
log(" also create/update init values for flip-flops\n");
|
|
|
|
log("\n");
|
2019-02-21 12:16:38 -06:00
|
|
|
log(" -params\n");
|
|
|
|
log(" replace undef in cell parameters\n");
|
|
|
|
log("\n");
|
2014-01-17 16:14:36 -06:00
|
|
|
}
|
2020-06-18 18:34:52 -05:00
|
|
|
void execute(std::vector<std::string> args, RTLIL::Design *design) override
|
2014-01-17 16:14:36 -06:00
|
|
|
{
|
2020-04-15 09:12:34 -05:00
|
|
|
int got_value = 0;
|
2014-01-17 16:14:36 -06:00
|
|
|
bool undriven_mode = false;
|
2018-05-13 15:53:35 -05:00
|
|
|
bool expose_mode = false;
|
2016-06-03 04:38:31 -05:00
|
|
|
bool init_mode = false;
|
2019-02-21 12:16:38 -06:00
|
|
|
bool params_mode = false;
|
2014-07-23 08:36:09 -05:00
|
|
|
SetundefWorker worker;
|
2014-01-17 16:14:36 -06:00
|
|
|
|
2016-11-08 11:53:36 -06:00
|
|
|
log_header(design, "Executing SETUNDEF pass (replace undef values with defined constants).\n");
|
|
|
|
|
2014-01-17 16:14:36 -06:00
|
|
|
size_t argidx;
|
|
|
|
for (argidx = 1; argidx < args.size(); argidx++)
|
|
|
|
{
|
|
|
|
if (args[argidx] == "-undriven") {
|
|
|
|
undriven_mode = true;
|
|
|
|
continue;
|
|
|
|
}
|
2018-05-13 15:53:35 -05:00
|
|
|
if (args[argidx] == "-expose") {
|
|
|
|
expose_mode = true;
|
|
|
|
continue;
|
|
|
|
}
|
2014-01-17 16:14:36 -06:00
|
|
|
if (args[argidx] == "-zero") {
|
2020-04-15 09:12:34 -05:00
|
|
|
got_value++;
|
2018-06-01 04:49:58 -05:00
|
|
|
worker.next_bit_mode = MODE_ZERO;
|
2018-05-13 09:36:12 -05:00
|
|
|
worker.next_bit_state = 0;
|
2014-01-17 16:14:36 -06:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (args[argidx] == "-one") {
|
2020-04-15 09:12:34 -05:00
|
|
|
got_value++;
|
2018-06-01 04:49:58 -05:00
|
|
|
worker.next_bit_mode = MODE_ONE;
|
2018-05-13 09:36:12 -05:00
|
|
|
worker.next_bit_state = 0;
|
2014-01-17 16:14:36 -06:00
|
|
|
continue;
|
|
|
|
}
|
2017-05-28 04:59:05 -05:00
|
|
|
if (args[argidx] == "-anyseq") {
|
2020-04-15 09:12:34 -05:00
|
|
|
got_value++;
|
2018-06-01 04:49:58 -05:00
|
|
|
worker.next_bit_mode = MODE_ANYSEQ;
|
|
|
|
worker.next_bit_state = 0;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (args[argidx] == "-anyconst") {
|
2020-04-15 09:12:34 -05:00
|
|
|
got_value++;
|
2018-06-01 04:49:58 -05:00
|
|
|
worker.next_bit_mode = MODE_ANYCONST;
|
2018-05-13 09:36:12 -05:00
|
|
|
worker.next_bit_state = 0;
|
2017-05-28 04:59:05 -05:00
|
|
|
continue;
|
|
|
|
}
|
2018-03-12 07:52:35 -05:00
|
|
|
if (args[argidx] == "-undef") {
|
2020-04-15 09:12:34 -05:00
|
|
|
got_value++;
|
2018-06-01 04:49:58 -05:00
|
|
|
worker.next_bit_mode = MODE_UNDEF;
|
2018-05-13 09:36:12 -05:00
|
|
|
worker.next_bit_state = 0;
|
2018-03-12 07:52:35 -05:00
|
|
|
continue;
|
|
|
|
}
|
2016-06-03 04:38:31 -05:00
|
|
|
if (args[argidx] == "-init") {
|
|
|
|
init_mode = true;
|
|
|
|
continue;
|
|
|
|
}
|
2019-02-21 12:16:38 -06:00
|
|
|
if (args[argidx] == "-params") {
|
|
|
|
params_mode = true;
|
|
|
|
continue;
|
|
|
|
}
|
2020-04-15 09:12:34 -05:00
|
|
|
if (args[argidx] == "-random" && argidx+1 < args.size()) {
|
|
|
|
got_value++;
|
2018-06-01 04:49:58 -05:00
|
|
|
worker.next_bit_mode = MODE_RANDOM;
|
2014-07-23 08:36:09 -05:00
|
|
|
worker.next_bit_state = atoi(args[++argidx].c_str()) + 1;
|
2014-01-17 16:14:36 -06:00
|
|
|
for (int i = 0; i < 10; i++)
|
2014-07-23 08:36:09 -05:00
|
|
|
worker.next_bit();
|
2014-01-17 16:14:36 -06:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
extra_args(args, argidx, design);
|
|
|
|
|
2018-09-10 20:44:36 -05:00
|
|
|
if (!got_value && expose_mode) {
|
|
|
|
log("Using default as -undef with -expose.\n");
|
2020-04-15 09:12:34 -05:00
|
|
|
got_value++;
|
2018-09-10 20:44:36 -05:00
|
|
|
worker.next_bit_mode = MODE_UNDEF;
|
|
|
|
worker.next_bit_state = 0;
|
|
|
|
}
|
|
|
|
|
2018-05-13 15:53:35 -05:00
|
|
|
if (expose_mode && !undriven_mode)
|
|
|
|
log_cmd_error("Option -expose must be used with option -undriven.\n");
|
2014-01-17 16:14:36 -06:00
|
|
|
if (!got_value)
|
2020-04-15 09:12:34 -05:00
|
|
|
log_cmd_error("One of the options -zero, -one, -anyseq, -anyconst, -random <seed>, or -expose must be specified.\n");
|
|
|
|
else if (got_value > 1)
|
|
|
|
log_cmd_error("Only one of the options -zero, -one, -anyseq, -anyconst, or -random <seed> can be specified.\n");
|
2018-06-01 04:57:28 -05:00
|
|
|
|
|
|
|
if (init_mode && (worker.next_bit_mode == MODE_ANYSEQ || worker.next_bit_mode == MODE_ANYCONST))
|
|
|
|
log_cmd_error("The options -init and -anyseq / -anyconst are exclusive.\n");
|
2014-01-17 16:14:36 -06:00
|
|
|
|
2016-06-03 04:38:31 -05:00
|
|
|
for (auto module : design->selected_modules())
|
2014-01-17 16:14:36 -06:00
|
|
|
{
|
2019-02-21 12:16:38 -06:00
|
|
|
if (params_mode)
|
|
|
|
{
|
2019-02-21 12:27:23 -06:00
|
|
|
for (auto *cell : module->selected_cells()) {
|
|
|
|
for (auto ¶meter : cell->parameters) {
|
2024-10-09 12:39:45 -05:00
|
|
|
for (auto bit : parameter.second) {
|
2019-02-21 12:16:38 -06:00
|
|
|
if (bit > RTLIL::State::S1)
|
|
|
|
bit = worker.next_bit();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-01-17 16:14:36 -06:00
|
|
|
if (undriven_mode)
|
|
|
|
{
|
|
|
|
if (!module->processes.empty())
|
|
|
|
log_error("The 'setundef' command can't operate in -undriven mode on modules with processes. Run 'proc' first.\n");
|
|
|
|
|
2018-08-17 22:38:07 -05:00
|
|
|
if (expose_mode)
|
|
|
|
{
|
|
|
|
SigMap sigmap(module);
|
|
|
|
dict<SigBit, bool> wire_drivers;
|
|
|
|
pool<SigBit> used_wires;
|
|
|
|
SigPool undriven_signals;
|
|
|
|
|
|
|
|
for (auto cell : module->cells())
|
|
|
|
for (auto &conn : cell->connections()) {
|
|
|
|
SigSpec sig = sigmap(conn.second);
|
|
|
|
if (cell->input(conn.first))
|
|
|
|
for (auto bit : sig)
|
|
|
|
if (bit.wire)
|
|
|
|
used_wires.insert(bit);
|
|
|
|
if (cell->output(conn.first))
|
|
|
|
for (int i = 0; i < GetSize(sig); i++)
|
|
|
|
if (sig[i].wire)
|
|
|
|
wire_drivers[sig[i]] = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (auto wire : module->wires()) {
|
|
|
|
if (wire->port_input) {
|
|
|
|
SigSpec sig = sigmap(wire);
|
|
|
|
for (int i = 0; i < GetSize(sig); i++)
|
|
|
|
wire_drivers[sig[i]] = true;
|
|
|
|
}
|
|
|
|
if (wire->port_output) {
|
|
|
|
SigSpec sig = sigmap(wire);
|
|
|
|
for (auto bit : sig)
|
|
|
|
if (bit.wire)
|
|
|
|
used_wires.insert(bit);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pool<RTLIL::Wire*> undriven_wires;
|
|
|
|
for (auto bit : used_wires)
|
|
|
|
if (!wire_drivers.count(bit))
|
|
|
|
undriven_wires.insert(bit.wire);
|
|
|
|
|
|
|
|
for (auto &it : undriven_wires)
|
|
|
|
undriven_signals.add(sigmap(it));
|
|
|
|
|
|
|
|
for (auto &it : undriven_wires)
|
|
|
|
if (it->port_input)
|
|
|
|
undriven_signals.del(sigmap(it));
|
|
|
|
|
|
|
|
CellTypes ct(design);
|
|
|
|
for (auto &it : module->cells_)
|
|
|
|
for (auto &conn : it.second->connections())
|
|
|
|
if (!ct.cell_known(it.second->type) || ct.cell_output(it.second->type, conn.first))
|
|
|
|
undriven_signals.del(sigmap(conn.second));
|
|
|
|
|
|
|
|
RTLIL::SigSpec sig = undriven_signals.export_all();
|
|
|
|
for (auto &c : sig.chunks()) {
|
|
|
|
RTLIL::Wire * wire;
|
|
|
|
if (c.wire->width == c.width) {
|
|
|
|
wire = c.wire;
|
|
|
|
wire->port_input = true;
|
|
|
|
} else {
|
|
|
|
string name = c.wire->name.str() + "$[" + std::to_string(c.width + c.offset) + ":" + std::to_string(c.offset) + "]";
|
|
|
|
wire = add_wire(module, name, c.width, true, false);
|
|
|
|
module->connect(RTLIL::SigSig(c, wire));
|
|
|
|
}
|
|
|
|
log("Exposing undriven wire %s as input.\n", wire->name.c_str());
|
|
|
|
}
|
|
|
|
module->fixup_ports();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
SigMap sigmap(module);
|
|
|
|
SigPool undriven_signals;
|
|
|
|
|
|
|
|
for (auto &it : module->wires_)
|
|
|
|
undriven_signals.add(sigmap(it.second));
|
|
|
|
|
|
|
|
for (auto &it : module->wires_)
|
|
|
|
if (it.second->port_input)
|
|
|
|
undriven_signals.del(sigmap(it.second));
|
|
|
|
|
|
|
|
CellTypes ct(design);
|
|
|
|
for (auto &it : module->cells_)
|
|
|
|
for (auto &conn : it.second->connections())
|
|
|
|
if (!ct.cell_known(it.second->type) || ct.cell_output(it.second->type, conn.first))
|
|
|
|
undriven_signals.del(sigmap(conn.second));
|
|
|
|
|
|
|
|
RTLIL::SigSpec sig = undriven_signals.export_all();
|
|
|
|
for (auto &c : sig.chunks()) {
|
|
|
|
RTLIL::SigSpec bits;
|
|
|
|
if (worker.next_bit_mode == MODE_ANYSEQ)
|
|
|
|
bits = module->Anyseq(NEW_ID, c.width);
|
|
|
|
else if (worker.next_bit_mode == MODE_ANYCONST)
|
|
|
|
bits = module->Anyconst(NEW_ID, c.width);
|
|
|
|
else
|
|
|
|
for (int i = 0; i < c.width; i++)
|
|
|
|
bits.append(worker.next_bit());
|
|
|
|
module->connect(RTLIL::SigSig(c, bits));
|
|
|
|
}
|
|
|
|
}
|
2014-01-17 16:14:36 -06:00
|
|
|
}
|
|
|
|
|
2016-06-03 04:38:31 -05:00
|
|
|
if (init_mode)
|
|
|
|
{
|
|
|
|
SigMap sigmap(module);
|
|
|
|
pool<SigBit> ffbits;
|
|
|
|
pool<Wire*> initwires;
|
|
|
|
|
|
|
|
for (auto cell : module->cells())
|
|
|
|
{
|
2020-04-08 10:36:12 -05:00
|
|
|
if (!RTLIL::builtin_ff_cell_types().count(cell->type))
|
2016-06-03 04:38:31 -05:00
|
|
|
continue;
|
|
|
|
|
2020-04-02 11:51:32 -05:00
|
|
|
for (auto bit : sigmap(cell->getPort(ID::Q)))
|
2016-06-03 04:38:31 -05:00
|
|
|
ffbits.insert(bit);
|
|
|
|
}
|
|
|
|
|
2019-06-05 03:26:48 -05:00
|
|
|
auto process_initwires = [&]()
|
2016-06-03 04:38:31 -05:00
|
|
|
{
|
2019-06-05 03:26:48 -05:00
|
|
|
dict<Wire*, int> wire_weights;
|
2016-06-03 04:38:31 -05:00
|
|
|
|
2019-06-05 03:26:48 -05:00
|
|
|
for (auto wire : initwires)
|
|
|
|
{
|
|
|
|
int weight = 0;
|
2016-06-03 04:38:31 -05:00
|
|
|
|
2019-06-05 03:26:48 -05:00
|
|
|
for (auto bit : sigmap(wire))
|
|
|
|
weight += ffbits.count(bit) ? +1 : -1;
|
|
|
|
|
|
|
|
wire_weights[wire] = weight;
|
|
|
|
}
|
|
|
|
|
|
|
|
initwires.sort([&](Wire *a, Wire *b) { return wire_weights.at(a) > wire_weights.at(b); });
|
|
|
|
|
|
|
|
for (auto wire : initwires)
|
|
|
|
{
|
2020-04-02 11:51:32 -05:00
|
|
|
Const &initval = wire->attributes[ID::init];
|
2024-10-09 12:39:45 -05:00
|
|
|
initval.bits().resize(GetSize(wire), State::Sx);
|
2019-06-05 03:26:48 -05:00
|
|
|
|
|
|
|
for (int i = 0; i < GetSize(wire); i++) {
|
|
|
|
SigBit bit = sigmap(SigBit(wire, i));
|
|
|
|
if (initval[i] == State::Sx && ffbits.count(bit)) {
|
2024-10-09 12:39:45 -05:00
|
|
|
initval.bits()[i] = worker.next_bit();
|
2019-06-05 03:26:48 -05:00
|
|
|
ffbits.erase(bit);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (initval.is_fully_undef())
|
2020-04-02 11:51:32 -05:00
|
|
|
wire->attributes.erase(ID::init);
|
2019-06-05 03:26:48 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
initwires.clear();
|
|
|
|
};
|
2016-06-03 04:38:31 -05:00
|
|
|
|
2019-06-05 02:53:06 -05:00
|
|
|
for (int wire_types = 0; wire_types < 2; wire_types++)
|
|
|
|
{
|
2019-06-05 03:26:48 -05:00
|
|
|
// prioritize wires that already have an init attribute
|
|
|
|
if (!ffbits.empty())
|
2019-06-05 02:53:06 -05:00
|
|
|
{
|
2019-06-05 03:26:48 -05:00
|
|
|
for (auto wire : module->wires())
|
|
|
|
{
|
|
|
|
if (wire->name[0] == (wire_types ? '\\' : '$'))
|
|
|
|
continue;
|
2019-06-05 02:53:06 -05:00
|
|
|
|
2020-04-02 11:51:32 -05:00
|
|
|
if (!wire->attributes.count(ID::init))
|
2019-06-05 03:26:48 -05:00
|
|
|
continue;
|
|
|
|
|
2020-04-02 11:51:32 -05:00
|
|
|
Const &initval = wire->attributes[ID::init];
|
2024-10-09 12:39:45 -05:00
|
|
|
initval.bits().resize(GetSize(wire), State::Sx);
|
2019-06-05 03:26:48 -05:00
|
|
|
|
|
|
|
if (initval.is_fully_undef()) {
|
2020-04-02 11:51:32 -05:00
|
|
|
wire->attributes.erase(ID::init);
|
2019-06-05 03:26:48 -05:00
|
|
|
continue;
|
2019-06-05 02:53:06 -05:00
|
|
|
}
|
|
|
|
|
2019-06-05 03:26:48 -05:00
|
|
|
for (int i = 0; i < GetSize(wire); i++)
|
|
|
|
if (initval[i] != State::Sx)
|
|
|
|
ffbits.erase(sigmap(SigBit(wire, i)));
|
|
|
|
|
|
|
|
initwires.insert(wire);
|
2019-06-05 02:53:06 -05:00
|
|
|
}
|
|
|
|
|
2019-06-05 03:26:48 -05:00
|
|
|
process_initwires();
|
2019-06-05 02:53:06 -05:00
|
|
|
}
|
2019-06-05 03:26:48 -05:00
|
|
|
|
|
|
|
// next consider wires that completely contain bits to be initialized
|
|
|
|
if (!ffbits.empty())
|
|
|
|
{
|
|
|
|
for (auto wire : module->wires())
|
|
|
|
{
|
|
|
|
if (wire->name[0] == (wire_types ? '\\' : '$'))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
for (auto bit : sigmap(wire))
|
|
|
|
if (!ffbits.count(bit))
|
|
|
|
goto next_wire;
|
|
|
|
|
|
|
|
initwires.insert(wire);
|
|
|
|
|
|
|
|
next_wire:
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
process_initwires();
|
2019-06-05 02:53:06 -05:00
|
|
|
}
|
2016-06-03 04:38:31 -05:00
|
|
|
|
2019-06-05 03:26:48 -05:00
|
|
|
// finally use whatever wire we can find.
|
|
|
|
if (!ffbits.empty())
|
|
|
|
{
|
|
|
|
for (auto wire : module->wires())
|
|
|
|
{
|
|
|
|
if (wire->name[0] == (wire_types ? '\\' : '$'))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
for (auto bit : sigmap(wire))
|
|
|
|
if (ffbits.count(bit))
|
|
|
|
initwires.insert(wire);
|
|
|
|
}
|
2016-06-03 04:38:31 -05:00
|
|
|
|
2019-06-05 03:26:48 -05:00
|
|
|
process_initwires();
|
|
|
|
}
|
2016-06-03 04:38:31 -05:00
|
|
|
}
|
2019-06-05 03:26:48 -05:00
|
|
|
|
|
|
|
log_assert(ffbits.empty());
|
2016-06-03 04:38:31 -05:00
|
|
|
}
|
|
|
|
|
2022-08-02 08:36:29 -05:00
|
|
|
if (worker.next_bit_mode == MODE_ANYSEQ || worker.next_bit_mode == MODE_ANYCONST)
|
|
|
|
{
|
|
|
|
// Do not add anyseq / anyconst to unused memory port clocks
|
|
|
|
std::vector<Mem> memories = Mem::get_selected_memories(module);
|
|
|
|
for (auto &mem : memories) {
|
|
|
|
bool changed = false;
|
|
|
|
for (auto &rd_port : mem.rd_ports) {
|
|
|
|
if (!rd_port.clk_enable && rd_port.clk.is_fully_undef()) {
|
|
|
|
changed = true;
|
|
|
|
rd_port.clk = State::S0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
for (auto &wr_port : mem.rd_ports) {
|
|
|
|
if (!wr_port.clk_enable && wr_port.clk.is_fully_undef()) {
|
|
|
|
changed = true;
|
|
|
|
wr_port.clk = State::S0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (changed)
|
|
|
|
mem.emit();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-12-21 07:24:10 -06:00
|
|
|
for (auto &it : module->cells_)
|
|
|
|
if (!it.second->get_bool_attribute(ID::xprop_decoder))
|
|
|
|
it.second->rewrite_sigspecs(worker);
|
|
|
|
for (auto &it : module->processes)
|
|
|
|
it.second->rewrite_sigspecs(worker);
|
|
|
|
for (auto &it : module->connections_) {
|
|
|
|
worker(it.first);
|
|
|
|
worker(it.second);
|
|
|
|
}
|
2017-05-28 04:59:05 -05:00
|
|
|
|
2018-06-01 04:49:58 -05:00
|
|
|
if (worker.next_bit_mode == MODE_ANYSEQ || worker.next_bit_mode == MODE_ANYCONST)
|
2017-05-28 04:59:05 -05:00
|
|
|
{
|
|
|
|
vector<SigSpec*> siglist;
|
|
|
|
siglist.swap(worker.siglist);
|
|
|
|
|
|
|
|
for (auto sigptr : siglist)
|
|
|
|
{
|
|
|
|
SigSpec &sig = *sigptr;
|
|
|
|
int cursor = 0;
|
|
|
|
|
|
|
|
while (cursor < GetSize(sig))
|
|
|
|
{
|
|
|
|
int width = 0;
|
|
|
|
while (cursor+width < GetSize(sig) && sig[cursor+width] == State::Sx)
|
|
|
|
width++;
|
|
|
|
|
|
|
|
if (width > 0) {
|
2018-06-01 04:49:58 -05:00
|
|
|
if (worker.next_bit_mode == MODE_ANYSEQ)
|
|
|
|
sig.replace(cursor, module->Anyseq(NEW_ID, width));
|
|
|
|
else
|
|
|
|
sig.replace(cursor, module->Anyconst(NEW_ID, width));
|
2017-05-28 04:59:05 -05:00
|
|
|
cursor += width;
|
|
|
|
} else {
|
|
|
|
cursor++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2014-01-17 16:14:36 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
} SetundefPass;
|
2015-07-02 04:14:30 -05:00
|
|
|
|
2014-09-27 09:17:53 -05:00
|
|
|
PRIVATE_NAMESPACE_END
|