mirror of https://github.com/YosysHQ/yosys.git
Merge pull request #1050 from YosysHQ/clifford/wandwor
Refactored wand/wor support
This commit is contained in:
commit
8e647901ef
|
@ -257,7 +257,7 @@ for them:
|
||||||
- Non-synthesizable language features as defined in
|
- Non-synthesizable language features as defined in
|
||||||
IEC 62142(E):2005 / IEEE Std. 1364.1(E):2002
|
IEC 62142(E):2005 / IEEE Std. 1364.1(E):2002
|
||||||
|
|
||||||
- The ``tri``, ``triand``, ``trior``, ``wand`` and ``wor`` net types
|
- The ``tri``, ``triand`` and ``trior`` net types
|
||||||
|
|
||||||
- The ``config`` and ``disable`` keywords and library map files
|
- The ``config`` and ``disable`` keywords and library map files
|
||||||
|
|
||||||
|
|
|
@ -194,6 +194,8 @@ AstNode::AstNode(AstNodeType type, AstNode *child1, AstNode *child2, AstNode *ch
|
||||||
is_logic = false;
|
is_logic = false;
|
||||||
is_signed = false;
|
is_signed = false;
|
||||||
is_string = false;
|
is_string = false;
|
||||||
|
is_wand = false;
|
||||||
|
is_wor = false;
|
||||||
is_unsized = false;
|
is_unsized = false;
|
||||||
was_checked = false;
|
was_checked = false;
|
||||||
range_valid = false;
|
range_valid = false;
|
||||||
|
|
|
@ -173,7 +173,7 @@ namespace AST
|
||||||
// node content - most of it is unused in most node types
|
// node content - most of it is unused in most node types
|
||||||
std::string str;
|
std::string str;
|
||||||
std::vector<RTLIL::State> bits;
|
std::vector<RTLIL::State> bits;
|
||||||
bool is_input, is_output, is_reg, is_logic, is_signed, is_string, range_valid, range_swapped, was_checked, is_unsized;
|
bool is_input, is_output, is_reg, is_logic, is_signed, is_string, is_wand, is_wor, range_valid, range_swapped, was_checked, is_unsized;
|
||||||
int port_id, range_left, range_right;
|
int port_id, range_left, range_right;
|
||||||
uint32_t integer;
|
uint32_t integer;
|
||||||
double realvalue;
|
double realvalue;
|
||||||
|
|
|
@ -920,6 +920,9 @@ RTLIL::SigSpec AstNode::genRTLIL(int width_hint, bool sign_hint)
|
||||||
log_file_error(filename, linenum, "Attribute `%s' with non-constant value!\n", attr.first.c_str());
|
log_file_error(filename, linenum, "Attribute `%s' with non-constant value!\n", attr.first.c_str());
|
||||||
wire->attributes[attr.first] = attr.second->asAttrConst();
|
wire->attributes[attr.first] = attr.second->asAttrConst();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (is_wand) wire->set_bool_attribute("\\wand");
|
||||||
|
if (is_wor) wire->set_bool_attribute("\\wor");
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
|
|
@ -218,6 +218,8 @@ YOSYS_NAMESPACE_END
|
||||||
"output" { return TOK_OUTPUT; }
|
"output" { return TOK_OUTPUT; }
|
||||||
"inout" { return TOK_INOUT; }
|
"inout" { return TOK_INOUT; }
|
||||||
"wire" { return TOK_WIRE; }
|
"wire" { return TOK_WIRE; }
|
||||||
|
"wor" { return TOK_WOR; }
|
||||||
|
"wand" { return TOK_WAND; }
|
||||||
"reg" { return TOK_REG; }
|
"reg" { return TOK_REG; }
|
||||||
"integer" { return TOK_INTEGER; }
|
"integer" { return TOK_INTEGER; }
|
||||||
"signed" { return TOK_SIGNED; }
|
"signed" { return TOK_SIGNED; }
|
||||||
|
|
|
@ -139,7 +139,7 @@ struct specify_rise_fall {
|
||||||
%token TOK_MODULE TOK_ENDMODULE TOK_PARAMETER TOK_LOCALPARAM TOK_DEFPARAM
|
%token TOK_MODULE TOK_ENDMODULE TOK_PARAMETER TOK_LOCALPARAM TOK_DEFPARAM
|
||||||
%token TOK_PACKAGE TOK_ENDPACKAGE TOK_PACKAGESEP
|
%token TOK_PACKAGE TOK_ENDPACKAGE TOK_PACKAGESEP
|
||||||
%token TOK_INTERFACE TOK_ENDINTERFACE TOK_MODPORT TOK_VAR
|
%token TOK_INTERFACE TOK_ENDINTERFACE TOK_MODPORT TOK_VAR
|
||||||
%token TOK_INPUT TOK_OUTPUT TOK_INOUT TOK_WIRE TOK_REG TOK_LOGIC
|
%token TOK_INPUT TOK_OUTPUT TOK_INOUT TOK_WIRE TOK_WAND TOK_WOR TOK_REG TOK_LOGIC
|
||||||
%token TOK_INTEGER TOK_SIGNED TOK_ASSIGN TOK_ALWAYS TOK_INITIAL
|
%token TOK_INTEGER TOK_SIGNED TOK_ASSIGN TOK_ALWAYS TOK_INITIAL
|
||||||
%token TOK_BEGIN TOK_END TOK_IF TOK_ELSE TOK_FOR TOK_WHILE TOK_REPEAT
|
%token TOK_BEGIN TOK_END TOK_IF TOK_ELSE TOK_FOR TOK_WHILE TOK_REPEAT
|
||||||
%token TOK_DPI_FUNCTION TOK_POSEDGE TOK_NEGEDGE TOK_OR TOK_AUTOMATIC
|
%token TOK_DPI_FUNCTION TOK_POSEDGE TOK_NEGEDGE TOK_OR TOK_AUTOMATIC
|
||||||
|
@ -485,6 +485,12 @@ wire_type_token_io:
|
||||||
wire_type_token:
|
wire_type_token:
|
||||||
TOK_WIRE {
|
TOK_WIRE {
|
||||||
} |
|
} |
|
||||||
|
TOK_WOR {
|
||||||
|
astbuf3->is_wor = true;
|
||||||
|
} |
|
||||||
|
TOK_WAND {
|
||||||
|
astbuf3->is_wand = true;
|
||||||
|
} |
|
||||||
TOK_REG {
|
TOK_REG {
|
||||||
astbuf3->is_reg = true;
|
astbuf3->is_reg = true;
|
||||||
} |
|
} |
|
||||||
|
|
|
@ -601,6 +601,7 @@ struct RTLIL::SigChunk
|
||||||
RTLIL::SigChunk &operator =(const RTLIL::SigChunk &other) = default;
|
RTLIL::SigChunk &operator =(const RTLIL::SigChunk &other) = default;
|
||||||
|
|
||||||
RTLIL::SigChunk extract(int offset, int length) const;
|
RTLIL::SigChunk extract(int offset, int length) const;
|
||||||
|
inline int size() const { return width; }
|
||||||
|
|
||||||
bool operator <(const RTLIL::SigChunk &other) const;
|
bool operator <(const RTLIL::SigChunk &other) const;
|
||||||
bool operator ==(const RTLIL::SigChunk &other) const;
|
bool operator ==(const RTLIL::SigChunk &other) const;
|
||||||
|
|
|
@ -562,7 +562,8 @@ struct HierarchyPass : public Pass {
|
||||||
log("In parametric designs, a module might exists in several variations with\n");
|
log("In parametric designs, a module might exists in several variations with\n");
|
||||||
log("different parameter values. This pass looks at all modules in the current\n");
|
log("different parameter values. This pass looks at all modules in the current\n");
|
||||||
log("design an re-runs the language frontends for the parametric modules as\n");
|
log("design an re-runs the language frontends for the parametric modules as\n");
|
||||||
log("needed.\n");
|
log("needed. It also resolves assignments to wired logic data types (wand/wor),\n");
|
||||||
|
log("resolves positional module parameters, unroll array instances, and more.\n");
|
||||||
log("\n");
|
log("\n");
|
||||||
log(" -check\n");
|
log(" -check\n");
|
||||||
log(" also check the design hierarchy. this generates an error when\n");
|
log(" also check the design hierarchy. this generates an error when\n");
|
||||||
|
@ -943,6 +944,121 @@ struct HierarchyPass : public Pass {
|
||||||
std::vector<Module*> design_modules = design->modules();
|
std::vector<Module*> design_modules = design->modules();
|
||||||
|
|
||||||
for (auto module : design_modules)
|
for (auto module : design_modules)
|
||||||
|
{
|
||||||
|
pool<Wire*> wand_wor_index;
|
||||||
|
dict<Wire*, SigSpec> wand_map, wor_map;
|
||||||
|
vector<SigSig> new_connections;
|
||||||
|
|
||||||
|
for (auto wire : module->wires())
|
||||||
|
{
|
||||||
|
if (wire->get_bool_attribute("\\wand")) {
|
||||||
|
wand_map[wire] = SigSpec();
|
||||||
|
wand_wor_index.insert(wire);
|
||||||
|
}
|
||||||
|
if (wire->get_bool_attribute("\\wor")) {
|
||||||
|
wor_map[wire] = SigSpec();
|
||||||
|
wand_wor_index.insert(wire);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for (auto &conn : module->connections())
|
||||||
|
{
|
||||||
|
SigSig new_conn;
|
||||||
|
int cursor = 0;
|
||||||
|
|
||||||
|
for (auto c : conn.first.chunks())
|
||||||
|
{
|
||||||
|
Wire *w = c.wire;
|
||||||
|
SigSpec rhs = conn.second.extract(cursor, GetSize(c));
|
||||||
|
|
||||||
|
if (wand_wor_index.count(w) == 0) {
|
||||||
|
new_conn.first.append(c);
|
||||||
|
new_conn.second.append(rhs);
|
||||||
|
} else {
|
||||||
|
if (wand_map.count(w)) {
|
||||||
|
SigSpec sig = SigSpec(State::S1, GetSize(w));
|
||||||
|
sig.replace(c.offset, rhs);
|
||||||
|
wand_map.at(w).append(sig);
|
||||||
|
} else {
|
||||||
|
SigSpec sig = SigSpec(State::S0, GetSize(w));
|
||||||
|
sig.replace(c.offset, rhs);
|
||||||
|
wor_map.at(w).append(sig);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
cursor += GetSize(c);
|
||||||
|
}
|
||||||
|
new_connections.push_back(new_conn);
|
||||||
|
}
|
||||||
|
module->new_connections(new_connections);
|
||||||
|
|
||||||
|
for (auto cell : module->cells())
|
||||||
|
{
|
||||||
|
if (!cell->known())
|
||||||
|
continue;
|
||||||
|
|
||||||
|
for (auto &conn : cell->connections())
|
||||||
|
{
|
||||||
|
if (!cell->output(conn.first))
|
||||||
|
continue;
|
||||||
|
|
||||||
|
SigSpec new_sig;
|
||||||
|
bool update_port = false;
|
||||||
|
|
||||||
|
for (auto c : conn.second.chunks())
|
||||||
|
{
|
||||||
|
Wire *w = c.wire;
|
||||||
|
|
||||||
|
if (wand_wor_index.count(w) == 0) {
|
||||||
|
new_sig.append(c);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
Wire *t = module->addWire(NEW_ID, GetSize(c));
|
||||||
|
new_sig.append(t);
|
||||||
|
update_port = true;
|
||||||
|
|
||||||
|
if (wand_map.count(w)) {
|
||||||
|
SigSpec sig = SigSpec(State::S1, GetSize(w));
|
||||||
|
sig.replace(c.offset, t);
|
||||||
|
wand_map.at(w).append(sig);
|
||||||
|
} else {
|
||||||
|
SigSpec sig = SigSpec(State::S0, GetSize(w));
|
||||||
|
sig.replace(c.offset, t);
|
||||||
|
wor_map.at(w).append(sig);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (update_port)
|
||||||
|
cell->setPort(conn.first, new_sig);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for (auto w : wand_wor_index)
|
||||||
|
{
|
||||||
|
bool wand = wand_map.count(w);
|
||||||
|
SigSpec sigs = wand ? wand_map.at(w) : wor_map.at(w);
|
||||||
|
|
||||||
|
if (GetSize(sigs) == 0)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
if (GetSize(w) == 1) {
|
||||||
|
if (wand)
|
||||||
|
module->addReduceAnd(NEW_ID, sigs, w);
|
||||||
|
else
|
||||||
|
module->addReduceOr(NEW_ID, sigs, w);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
SigSpec s = sigs.extract(0, GetSize(w));
|
||||||
|
for (int i = GetSize(w); i < GetSize(sigs); i += GetSize(w)) {
|
||||||
|
if (wand)
|
||||||
|
s = module->And(NEW_ID, s, sigs.extract(i, GetSize(w)));
|
||||||
|
else
|
||||||
|
s = module->Or(NEW_ID, s, sigs.extract(i, GetSize(w)));
|
||||||
|
}
|
||||||
|
module->connect(w, s);
|
||||||
|
}
|
||||||
|
|
||||||
for (auto cell : module->cells())
|
for (auto cell : module->cells())
|
||||||
{
|
{
|
||||||
Module *m = design->module(cell->type);
|
Module *m = design->module(cell->type);
|
||||||
|
@ -1001,6 +1117,7 @@ struct HierarchyPass : public Pass {
|
||||||
log_id(module), log_id(cell), log_id(conn.first), log_id(cell->type), log_signal(sig));
|
log_id(module), log_id(cell), log_id(conn.first), log_id(cell->type), log_signal(sig));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
for (auto module : blackbox_derivatives)
|
for (auto module : blackbox_derivatives)
|
||||||
design->remove(module);
|
design->remove(module);
|
||||||
|
|
|
@ -0,0 +1,36 @@
|
||||||
|
module wandwor_test0 (A, B, C, D, X, Y, Z);
|
||||||
|
input A, B, C, D;
|
||||||
|
output wor X;
|
||||||
|
output wand Y;
|
||||||
|
output Z;
|
||||||
|
|
||||||
|
assign X = A, X = B, Y = C, Y = D;
|
||||||
|
foo foo_0 (C, D, X);
|
||||||
|
foo foo_1 (A, B, Y);
|
||||||
|
foo foo_2 (X, Y, Z);
|
||||||
|
endmodule
|
||||||
|
|
||||||
|
module wandwor_test1 (A, B, C, D, X, Y, Z);
|
||||||
|
input [3:0] A, B, C, D;
|
||||||
|
output wor [3:0] X;
|
||||||
|
output wand [3:0] Y;
|
||||||
|
output Z;
|
||||||
|
|
||||||
|
bar bar_inst (
|
||||||
|
.I0({A, B}),
|
||||||
|
.I1({B, A}),
|
||||||
|
.O({X, Y})
|
||||||
|
);
|
||||||
|
|
||||||
|
assign X = C, X = D;
|
||||||
|
assign Y = C, Y = D;
|
||||||
|
assign Z = ^{X,Y};
|
||||||
|
endmodule
|
||||||
|
|
||||||
|
module foo(input I0, I1, output O);
|
||||||
|
assign O = I0 ^ I1;
|
||||||
|
endmodule
|
||||||
|
|
||||||
|
module bar(input [7:0] I0, I1, output [7:0] O);
|
||||||
|
assign O = I0 + I1;
|
||||||
|
endmodule
|
Loading…
Reference in New Issue