Skip to content

Commit

Permalink
Merge pull request #13 from YosysHQ/master
Browse files Browse the repository at this point in the history
merge "YosysHQ/yosys" into master+wip
  • Loading branch information
mithro committed Mar 1, 2019
2 parents 7a22a5a + 60e3c38 commit 98104b3
Show file tree
Hide file tree
Showing 28 changed files with 594 additions and 77 deletions.
28 changes: 20 additions & 8 deletions backends/firrtl/firrtl.cc
Expand Up @@ -169,7 +169,6 @@ struct FirrtlWorker
return *str == '\\' ? str + 1 : str;
}


std::string cellname(RTLIL::Cell *cell)
{
return fid(cell->name).c_str();
Expand Down Expand Up @@ -219,29 +218,42 @@ struct FirrtlWorker
if (it->second.size() > 0) {
const SigSpec &secondSig = it->second;
const std::string firstName = cell_name + "." + make_id(it->first);
const std::string secondName = make_expr(secondSig);
const std::string secondExpr = make_expr(secondSig);
// Find the direction for this port.
FDirection dir = getPortFDirection(it->first, instModule);
std::string source, sink;
std::string sourceExpr, sinkExpr;
const SigSpec *sinkSig = nullptr;
switch (dir) {
case FD_INOUT:
log_warning("Instance port connection %s.%s is INOUT; treating as OUT\n", cell_type.c_str(), log_signal(it->second));
case FD_OUT:
source = firstName;
sink = secondName;
sourceExpr = firstName;
sinkExpr = secondExpr;
sinkSig = &secondSig;
break;
case FD_NODIRECTION:
log_warning("Instance port connection %s.%s is NODIRECTION; treating as IN\n", cell_type.c_str(), log_signal(it->second));
/* FALL_THROUGH */
case FD_IN:
source = secondName;
sink = firstName;
sourceExpr = secondExpr;
sinkExpr = firstName;
break;
default:
log_error("Instance port %s.%s unrecognized connection direction 0x%x !\n", cell_type.c_str(), log_signal(it->second), dir);
break;
}
wire_exprs.push_back(stringf("\n%s%s <= %s", indent.c_str(), sink.c_str(), source.c_str()));
// Check for subfield assignment.
std::string bitsString = "bits(";
if (sinkExpr.substr(0, bitsString.length()) == bitsString ) {
if (sinkSig == nullptr)
log_error("Unknown subfield %s.%s\n", cell_type.c_str(), sinkExpr.c_str());
// Don't generate the assignment here.
// Add the source and sink to the "reverse_wire_map" and we'll output the assignment
// as part of the coalesced subfield assignments for this wire.
register_reverse_wire_map(sourceExpr, *sinkSig);
} else {
wire_exprs.push_back(stringf("\n%s%s <= %s", indent.c_str(), sinkExpr.c_str(), sourceExpr.c_str()));
}
}
}
wire_exprs.push_back(stringf("\n"));
Expand Down
6 changes: 3 additions & 3 deletions backends/protobuf/protobuf.cc
Expand Up @@ -48,7 +48,7 @@ struct ProtobufDesignSerializer

ProtobufDesignSerializer(bool use_selection, bool aig_mode) :
aig_mode_(aig_mode), use_selection_(use_selection) { }

string get_name(IdString name)
{
return RTLIL::unescape_id(name);
Expand All @@ -60,7 +60,7 @@ struct ProtobufDesignSerializer
{
for (auto &param : parameters) {
std::string key = get_name(param.first);


yosys::pb::Parameter pb_param;

Expand Down Expand Up @@ -207,7 +207,7 @@ struct ProtobufDesignSerializer
(*models)[aig.name] = pb_model;
}
}

void serialize_design(yosys::pb::Design *pb, Design *design)
{
GOOGLE_PROTOBUF_VERIFY_VERSION;
Expand Down
15 changes: 11 additions & 4 deletions backends/smt2/smt2.cc
Expand Up @@ -1103,20 +1103,27 @@ struct Smt2Worker
break;

Const initword = init_data.extract(i*width, width, State::Sx);
Const initmask = initword;
bool gen_init_constr = false;

for (auto bit : initword.bits)
if (bit == State::S0 || bit == State::S1)
for (int k = 0; k < GetSize(initword); k++) {
if (initword[k] == State::S0 || initword[k] == State::S1) {
gen_init_constr = true;
initmask[k] = State::S1;
} else {
initmask[k] = State::S0;
initword[k] = State::S0;
}
}

if (gen_init_constr)
{
if (statebv)
/* FIXME */;
else
init_list.push_back(stringf("(= (select (|%s#%d#0| state) #b%s) #b%s) ; %s[%d]",
init_list.push_back(stringf("(= (bvand (select (|%s#%d#0| state) #b%s) #b%s) #b%s) ; %s[%d]",
get_id(module), arrayid, Const(i, abits).as_string().c_str(),
initword.as_string().c_str(), get_id(cell), i));
initmask.as_string().c_str(), initword.as_string().c_str(), get_id(cell), i));
}
}
}
Expand Down
13 changes: 11 additions & 2 deletions backends/verilog/verilog_backend.cc
Expand Up @@ -33,7 +33,7 @@
USING_YOSYS_NAMESPACE
PRIVATE_NAMESPACE_BEGIN

bool verbose, norename, noattr, attr2comment, noexpr, nodec, nohex, nostr, defparam, decimal;
bool verbose, norename, noattr, attr2comment, noexpr, nodec, nohex, nostr, defparam, decimal, siminit;
int auto_name_counter, auto_name_offset, auto_name_digits;
std::map<RTLIL::IdString, int> auto_name_map;
std::set<RTLIL::IdString> reg_wires, reg_ct;
Expand Down Expand Up @@ -1310,7 +1310,7 @@ void dump_cell(std::ostream &f, std::string indent, RTLIL::Cell *cell)
}
}

if (reg_ct.count(cell->type) && cell->hasPort("\\Q")) {
if (siminit && reg_ct.count(cell->type) && cell->hasPort("\\Q")) {
std::stringstream ss;
dump_reg_init(ss, cell->getPort("\\Q"));
if (!ss.str().empty()) {
Expand Down Expand Up @@ -1607,6 +1607,10 @@ struct VerilogBackend : public Backend {
log(" without this option all internal cells are converted to Verilog\n");
log(" expressions.\n");
log("\n");
log(" -siminit\n");
log(" add initial statements with hierarchical refs to initialize FFs when\n");
log(" in -noexpr mode.\n");
log("\n");
log(" -nodec\n");
log(" 32-bit constant values are by default dumped as decimal numbers,\n");
log(" not bit pattern. This option deactivates this feature and instead\n");
Expand Down Expand Up @@ -1663,6 +1667,7 @@ struct VerilogBackend : public Backend {
nostr = false;
defparam = false;
decimal = false;
siminit = false;
auto_prefix = "";

bool blackboxes = false;
Expand Down Expand Up @@ -1739,6 +1744,10 @@ struct VerilogBackend : public Backend {
decimal = true;
continue;
}
if (arg == "-siminit") {
siminit = true;
continue;
}
if (arg == "-blackboxes") {
blackboxes = true;
continue;
Expand Down
2 changes: 1 addition & 1 deletion frontends/verific/verific.cc
Expand Up @@ -2316,7 +2316,7 @@ struct ReadPass : public Pass {
}
void execute(std::vector<std::string> args, RTLIL::Design *design) YS_OVERRIDE
{
if (args.size() < 2)
if (args.size() < 2 || args[1][0] != '-')
log_cmd_error("Missing mode parameter.\n");

if (args.size() < 3)
Expand Down
12 changes: 6 additions & 6 deletions misc/yosys.proto
@@ -1,12 +1,12 @@
//
// yosys -- Yosys Open SYnthesis Suite
//
//
// Copyright (C) 2018 Serge Bazanski <q3k@symbioticeda.com>
//
//
// 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
Expand Down Expand Up @@ -73,7 +73,7 @@ message Module {
BitVector bits = 2;
}
map<string, Port> port = 2;

// Named cells in this module.
message Cell {
// Set to true when the name of this cell is automatically created and
Expand Down Expand Up @@ -129,7 +129,7 @@ message Model {
TYPE_FALSE = 6;
};
Type type = 1;

message Port {
// Name of port.
string portname = 1;
Expand All @@ -148,7 +148,7 @@ message Model {
// Set for AND, NAND.
Gate gate = 3;
}

// Set when the node drives given output port(s).
message OutPort {
// Name of port.
Expand Down
29 changes: 24 additions & 5 deletions passes/opt/wreduce.cc
Expand Up @@ -53,6 +53,7 @@ struct WreduceWorker
std::set<Cell*, IdString::compare_ptr_by_name<Cell>> work_queue_cells;
std::set<SigBit> work_queue_bits;
pool<SigBit> keep_bits;
dict<SigBit, State> init_bits;

WreduceWorker(WreduceConfig *config, Module *module) :
config(config), module(module), mi(module) { }
Expand Down Expand Up @@ -141,6 +142,7 @@ struct WreduceWorker

SigSpec sig_d = mi.sigmap(cell->getPort("\\D"));
SigSpec sig_q = mi.sigmap(cell->getPort("\\Q"));
Const initval;

int width_before = GetSize(sig_q);

Expand All @@ -150,24 +152,32 @@ struct WreduceWorker
bool zero_ext = sig_d[GetSize(sig_d)-1] == State::S0;
bool sign_ext = !zero_ext;

for (int i = 0; i < GetSize(sig_q); i++) {
SigBit bit = sig_q[i];
if (init_bits.count(bit))
initval.bits.push_back(init_bits.at(bit));
else
initval.bits.push_back(State::Sx);
}

for (int i = GetSize(sig_q)-1; i >= 0; i--)
{
if (zero_ext && sig_d[i] == State::S0) {
if (zero_ext && sig_d[i] == State::S0 && (initval[i] == State::S0 || initval[i] == State::Sx)) {
module->connect(sig_q[i], State::S0);
sig_d.remove(i);
sig_q.remove(i);
continue;
}

if (sign_ext && i > 0 && sig_d[i] == sig_d[i-1]) {
if (sign_ext && i > 0 && sig_d[i] == sig_d[i-1] && initval[i] == initval[i-1]) {
module->connect(sig_q[i], sig_q[i-1]);
sig_d.remove(i);
sig_q.remove(i);
continue;
}

auto info = mi.query(sig_q[i]);
if (!info->is_output && GetSize(info->ports) <= 1 && !keep_bits.count(mi.sigmap(sig_q[i]))) {
if (!info->is_output && GetSize(info->ports) == 1 && !keep_bits.count(mi.sigmap(sig_q[i]))) {
sig_d.remove(i);
sig_q.remove(i);
zero_ext = false;
Expand All @@ -183,10 +193,11 @@ struct WreduceWorker

if (GetSize(sig_q) == 0) {
log("Removed cell %s.%s (%s).\n", log_id(module), log_id(cell), log_id(cell->type));
module->remove(cell);
return;
}

log("Removed top %d bits (of %d) from mux cell %s.%s (%s).\n", width_before - GetSize(sig_q), width_before,
log("Removed top %d bits (of %d) from FF cell %s.%s (%s).\n", width_before - GetSize(sig_q), width_before,
log_id(module), log_id(cell), log_id(cell->type));

for (auto bit : sig_d)
Expand Down Expand Up @@ -376,10 +387,18 @@ struct WreduceWorker

void run()
{
for (auto w : module->wires())
for (auto w : module->wires()) {
if (w->get_bool_attribute("\\keep"))
for (auto bit : mi.sigmap(w))
keep_bits.insert(bit);
if (w->attributes.count("\\init")) {
Const initval = w->attributes.at("\\init");
SigSpec initsig = mi.sigmap(w);
int width = std::min(GetSize(initval), GetSize(initsig));
for (int i = 0; i < width; i++)
init_bits[initsig[i]] = initval[i];
}
}

for (auto c : module->selected_cells())
work_queue_cells.insert(c);
Expand Down
4 changes: 2 additions & 2 deletions passes/pmgen/Makefile.inc
Expand Up @@ -4,5 +4,5 @@ passes/pmgen/ice40_dsp.o: passes/pmgen/ice40_dsp_pm.h
EXTRA_OBJS += passes/pmgen/ice40_dsp_pm.h
.SECONDARY: passes/pmgen/ice40_dsp_pm.h

passes/pmgen/ice40_dsp_pm.h: passes/pmgen/ice40_dsp.pmg passes/pmgen/pmgen.py
$(P) cd passes/pmgen && python3 pmgen.py ice40_dsp
passes/pmgen/ice40_dsp_pm.h: passes/pmgen/pmgen.py passes/pmgen/ice40_dsp.pmg
$(P) mkdir -p passes/pmgen && python3 $^
19 changes: 11 additions & 8 deletions passes/pmgen/pmgen.py
Expand Up @@ -6,7 +6,10 @@

pp = pprint.PrettyPrinter(indent=4)

prefix = sys.argv[1]
pmgfile = sys.argv[1]
assert pmgfile.endswith(".pmg")
prefix = pmgfile[0:-4]
pmname = prefix.split('/')[-1]

state_types = dict()
udata_types = dict()
Expand Down Expand Up @@ -73,7 +76,7 @@ def rewrite_cpp(s):

return "".join(t)

with open("%s.pmg" % prefix, "r") as f:
with open(pmgfile, "r") as f:
while True:
line = f.readline()
if line == "": break
Expand All @@ -82,7 +85,7 @@ def rewrite_cpp(s):
cmd = line.split()
if len(cmd) == 0 or cmd[0].startswith("//"): continue
cmd = cmd[0]

if cmd == "state":
m = re.match(r"^state\s+<(.*?)>\s+(([A-Za-z_][A-Za-z_0-9]*\s+)*[A-Za-z_][A-Za-z_0-9]*)\s*$", line)
assert m
Expand Down Expand Up @@ -187,10 +190,10 @@ def rewrite_cpp(s):
print("YOSYS_NAMESPACE_BEGIN", file=f)
print("", file=f)

print("struct {}_pm {{".format(prefix), file=f)
print("struct {}_pm {{".format(pmname), file=f)
print(" Module *module;", file=f)
print(" SigMap sigmap;", file=f)
print(" std::function<void()> on_accept;".format(prefix), file=f)
print(" std::function<void()> on_accept;".format(pmname), file=f)
print("", file=f)

for index in range(len(blocks)):
Expand Down Expand Up @@ -288,7 +291,7 @@ def rewrite_cpp(s):
print(" }", file=f)
print("", file=f)

print(" {}_pm(Module *module, const vector<Cell*> &cells) :".format(prefix), file=f)
print(" {}_pm(Module *module, const vector<Cell*> &cells) :".format(pmname), file=f)
print(" module(module), sigmap(module) {", file=f)
for s, t in sorted(udata_types.items()):
if t.endswith("*"):
Expand Down Expand Up @@ -318,7 +321,7 @@ def rewrite_cpp(s):
print(" }", file=f)
print("", file=f)

print(" ~{}_pm() {{".format(prefix), file=f)
print(" ~{}_pm() {{".format(pmname), file=f)
print(" for (auto cell : autoremove_cells)", file=f)
print(" module->remove(cell);", file=f)
print(" }", file=f)
Expand All @@ -337,7 +340,7 @@ def rewrite_cpp(s):
print(" }", file=f)
print("", file=f)

print(" void run(std::function<void({}_pm&)> on_accept_f) {{".format(prefix), file=f)
print(" void run(std::function<void({}_pm&)> on_accept_f) {{".format(pmname), file=f)
print(" run([&](){on_accept_f(*this);});", file=f)
print(" }", file=f)
print("", file=f)
Expand Down
1 change: 1 addition & 0 deletions passes/sat/Makefile.inc
Expand Up @@ -8,4 +8,5 @@ OBJS += passes/sat/expose.o
OBJS += passes/sat/assertpmux.o
OBJS += passes/sat/clk2fflogic.o
OBJS += passes/sat/async2sync.o
OBJS += passes/sat/supercover.o

0 comments on commit 98104b3

Please sign in to comment.