Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: azonenberg/yosys
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 203b521a781c
Choose a base ref
...
head repository: azonenberg/yosys
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 6fed2dc996a5
Choose a head ref
  • 10 commits
  • 11 files changed
  • 3 contributors

Commits on Feb 12, 2017

  1. Copy the full SHA
    8283037 View commit details
  2. Copy the full SHA
    76c4ee0 View commit details

Commits on Feb 13, 2017

  1. Copy the full SHA
    db7314b View commit details
  2. Copy the full SHA
    69468d5 View commit details
  3. More progress on Firrtl backend.

    Chisel -> Firrtl -> Verilog -> Firrtl -> Verilog is successful for a
    simple rocket-chip design.
    azidar committed Feb 13, 2017
    Copy the full SHA
    794cec0 View commit details

Commits on Feb 14, 2017

  1. Merge pull request YosysHQ#313 from azidar/bugfix-assign-wmask

    More progress on Firrtl backend.
    cliffordwolf authored Feb 14, 2017
    Copy the full SHA
    f3a25d9 View commit details
  2. Copy the full SHA
    2a311c2 View commit details
  3. Copy the full SHA
    4e80ce9 View commit details
  4. Copy the full SHA
    4fb8007 View commit details
  5. Copy the full SHA
    6fed2dc View commit details
7 changes: 5 additions & 2 deletions backends/edif/edif.cc
Original file line number Diff line number Diff line change
@@ -323,7 +323,10 @@ struct EdifBackend : public Backend {
for (auto &p : cell->connections()) {
RTLIL::SigSpec sig = sigmap(p.second);
for (int i = 0; i < GetSize(sig); i++)
if (sig.size() == 1)
if (sig[i].wire == NULL && sig[i] != RTLIL::State::S0 && sig[i] != RTLIL::State::S1)
log_warning("Bit %d of cell port %s.%s.%s driven by %s will be left unconnected in EDIF output.\n",
i, log_id(module), log_id(cell), log_id(p.first), log_signal(sig[i]));
else if (sig.size() == 1)
net_join_db[sig[i]].insert(stringf("(portRef %s (instanceRef %s))", EDIF_REF(p.first), EDIF_REF(cell->name)));
else
net_join_db[sig[i]].insert(stringf("(portRef (member %s %d) (instanceRef %s))", EDIF_REF(p.first), i, EDIF_REF(cell->name)));
@@ -332,7 +335,7 @@ struct EdifBackend : public Backend {
for (auto &it : net_join_db) {
RTLIL::SigBit sig = it.first;
if (sig.wire == NULL && sig != RTLIL::State::S0 && sig != RTLIL::State::S1)
continue;
log_abort();
std::string netname = log_signal(sig);
for (size_t i = 0; i < netname.size(); i++)
if (netname[i] == ' ' || netname[i] == '\\')
122 changes: 117 additions & 5 deletions backends/firrtl/firrtl.cc
Original file line number Diff line number Diff line change
@@ -157,7 +157,53 @@ struct FirrtlWorker

for (auto cell : module->cells())
{
if (cell->type.in("$add", "$sub", "$xor"))
if (cell->type.in("$not", "$logic_not", "$neg", "$reduce_and", "$reduce_or", "$reduce_xor", "$reduce_bool", "$reduce_xnor"))
{
string y_id = make_id(cell->name);
bool is_signed = cell->parameters.at("\\A_SIGNED").as_bool();
int y_width = cell->parameters.at("\\Y_WIDTH").as_int();
string a_expr = make_expr(cell->getPort("\\A"));
wire_decls.push_back(stringf(" wire %s: UInt<%d>\n", y_id.c_str(), y_width));

if (cell->parameters.at("\\A_SIGNED").as_bool()) {
a_expr = "asSInt(" + a_expr + ")";
}

a_expr = stringf("pad(%s, %d)", a_expr.c_str(), y_width);

string primop;
bool always_uint = false;
if (cell->type == "$not") primop = "not";
if (cell->type == "$neg") primop = "neg";
if (cell->type == "$logic_not") {
primop = "eq";
a_expr = stringf("%s, UInt(0)", a_expr.c_str());
}
if (cell->type == "$reduce_and") primop = "andr";
if (cell->type == "$reduce_or") primop = "orr";
if (cell->type == "$reduce_xor") primop = "xorr";
if (cell->type == "$reduce_xnor") {
primop = "not";
a_expr = stringf("xorr(%s)", a_expr.c_str());
}
if (cell->type == "$reduce_bool") {
primop = "neq";
a_expr = stringf("%s, UInt(0)", a_expr.c_str());
}

string expr = stringf("%s(%s)", primop.c_str(), a_expr.c_str());

if ((is_signed && !always_uint))
expr = stringf("asUInt(%s)", expr.c_str());

cell_exprs.push_back(stringf(" %s <= %s\n", y_id.c_str(), expr.c_str()));
register_reverse_wire_map(y_id, cell->getPort("\\Y"));

continue;
}
if (cell->type.in("$add", "$sub", "$mul", "$div", "$mod", "$xor", "$and", "$or", "$eq", "$eqx",
"$gt", "$ge", "$lt", "$le", "$ne", "$nex", "$shr", "$sshr", "$sshl", "$shl",
"$logic_and", "$logic_or"))
{
string y_id = make_id(cell->name);
bool is_signed = cell->parameters.at("\\A_SIGNED").as_bool();
@@ -166,22 +212,88 @@ struct FirrtlWorker
string b_expr = make_expr(cell->getPort("\\B"));
wire_decls.push_back(stringf(" wire %s: UInt<%d>\n", y_id.c_str(), y_width));

if (is_signed) {
if (cell->parameters.at("\\A_SIGNED").as_bool()) {
a_expr = "asSInt(" + a_expr + ")";
}
if (cell->parameters.at("\\A_SIGNED").as_bool() & (cell->type != "$shr")) {
b_expr = "asSInt(" + b_expr + ")";
}

a_expr = stringf("pad(%s, %d)", a_expr.c_str(), y_width);
b_expr = stringf("pad(%s, %d)", b_expr.c_str(), y_width);

if ((cell->type != "$shl") && (cell->type != "$sshl")) {
b_expr = stringf("pad(%s, %d)", b_expr.c_str(), y_width);
}

if (cell->parameters.at("\\A_SIGNED").as_bool() & (cell->type == "$shr")) {
a_expr = "asUInt(" + a_expr + ")";
}

string primop;
bool always_uint = false;
if (cell->type == "$add") primop = "add";
if (cell->type == "$sub") primop = "sub";
if (cell->type == "$xor") primop = "xor";
if (cell->type == "$mul") primop = "mul";
if (cell->type == "$div") primop = "div";
if (cell->type == "$mod") primop = "rem";
if (cell->type == "$and") {
primop = "and";
always_uint = true;
}
if (cell->type == "$or" ) {
primop = "or";
always_uint = true;
}
if (cell->type == "$xor") {
primop = "xor";
always_uint = true;
}
if ((cell->type == "$eq") | (cell->type == "$eqx")) {
primop = "eq";
always_uint = true;
}
if ((cell->type == "$ne") | (cell->type == "$nex")) {
primop = "neq";
always_uint = true;
}
if (cell->type == "$gt") {
primop = "gt";
always_uint = true;
}
if (cell->type == "$ge") {
primop = "geq";
always_uint = true;
}
if (cell->type == "$lt") {
primop = "lt";
always_uint = true;
}
if (cell->type == "$le") {
primop = "leq";
always_uint = true;
}
if ((cell->type == "$shl") | (cell->type == "$sshl")) primop = "dshl";
if ((cell->type == "$shr") | (cell->type == "$sshr")) primop = "dshr";
if ((cell->type == "$logic_and")) {
primop = "and";
a_expr = "neq(" + a_expr + ", UInt(0))";
b_expr = "neq(" + b_expr + ", UInt(0))";
always_uint = true;
}
if ((cell->type == "$logic_or")) {
primop = "or";
a_expr = "neq(" + a_expr + ", UInt(0))";
b_expr = "neq(" + b_expr + ", UInt(0))";
always_uint = true;
}

if (!cell->parameters.at("\\B_SIGNED").as_bool()) {
b_expr = "asUInt(" + b_expr + ")";
}

string expr = stringf("%s(%s, %s)", primop.c_str(), a_expr.c_str(), b_expr.c_str());

if ((is_signed && !cell->type.in("$xor")) || cell->type.in("$sub"))
if ((is_signed && !always_uint) || cell->type.in("$sub"))
expr = stringf("asUInt(%s)", expr.c_str());

cell_exprs.push_back(stringf(" %s <= %s\n", y_id.c_str(), expr.c_str()));
19 changes: 11 additions & 8 deletions backends/firrtl/test.sh
Original file line number Diff line number Diff line change
@@ -1,22 +1,25 @@
#!/bin/bash
set -ex

../../yosys -p 'prep -nordff; write_firrtl test.fir' test.v
cd ../../
make
cd backends/firrtl

firrtl -i test.fir -o test_out.v
../../yosys -q -p 'prep -nordff; write_firrtl test.fir' $1

../../yosys -p '
read_verilog test.v
rename test gold
firrtl -i test.fir -o test_out.v -ll Info

../../yosys -p "
read_verilog $1
rename Top gold
read_verilog test_out.v
rename test gate
rename Top gate
prep
memory_map
miter -equiv -flatten gold gate miter
hierarchy -top miter
sat -verify -prove trigger 0 -set-init-zero -seq 10 miter
'

"
67 changes: 53 additions & 14 deletions backends/firrtl/test.v
Original file line number Diff line number Diff line change
@@ -1,24 +1,63 @@
module test(
input clk, wen,
input [4:0] waddr, raddr,
input [31:0] wdata,
output reg [31:0] rdata,
signed input [7:0] a, b, x,
output [15:0] s, d, y, z, u, q
input [7:0] uns,
input signed [7:0] a, b,
input signed [23:0] c,
input signed [2:0] sel,
output [15:0] s, d, y, z, u, q, p, mul, div, mod, mux, And, Or, Xor, eq, neq, gt, lt, geq, leq, eqx, shr, sshr, shl, sshl, Land, Lor, Lnot, Not, Neg, pos, Andr, Orr, Xorr, Xnorr, Reduce_bool,
output [7:0] PMux
);
reg [31:0] memory [0:31];

always @(posedge clk) begin
rdata <= memory[raddr];
if (wen) memory[waddr] <= wdata;
end

//initial begin
//$display("shr = %b", shr);
//end
assign s = a+{b[6:2], 2'b1};
assign d = a-b;
assign y = x;
assign z[7:0] = s+d;
assign z[15:8] = s-d;
assign p = a & b | x;
assign mul = a * b;
assign div = a / b;
assign mod = a % b;
assign mux = x[0] ? a : b;
assign And = a & b;
assign Or = a | b;
assign Xor = a ^ b;
assign Not = ~a;
assign Neg = -a;
assign eq = a == b;
assign neq = a != b;
assign gt = a > b;
assign lt = a < b;
assign geq = a >= b;
assign leq = a <= b;
assign eqx = a === b;
assign shr = a >> b; //0111111111000000
assign sshr = a >>> b;
assign shl = a << b;
assign sshl = a <<< b;
assign Land = a && b;
assign Lor = a || b;
assign Lnot = !a;
assign pos = $signed(uns);
assign Andr = &a;
assign Orr = |a;
assign Xorr = ^a;
assign Xnorr = ~^a;
always @*
if(!a) begin
Reduce_bool = a;
end else begin
Reduce_bool = b;
end
//always @(sel or c or a)
// begin
// case (sel)
// 3'b000: PMux = a;
// 3'b001: PMux = c[7:0];
// 3'b010: PMux = c[15:8];
// 3'b100: PMux = c[23:16];
// endcase
// end

always @(posedge clk)
q <= s ^ d ^ x;
endmodule
11 changes: 9 additions & 2 deletions frontends/ast/simplify.cc
Original file line number Diff line number Diff line change
@@ -2183,9 +2183,16 @@ skip_dynamic_range_lvalue_expansion:;
if (wire->children.empty()) {
for (auto c : child->children)
wire->children.push_back(c->clone());
} else {
if (!child->children.empty())
} else if (!child->children.empty()) {
while (child->simplify(true, false, false, stage, -1, false, false)) { }
if (GetSize(child->children) == GetSize(wire->children)) {
for (int i = 0; i < GetSize(child->children); i++)
if (*child->children.at(i) != *wire->children.at(i))
goto tcall_incompatible_wires;
} else {
tcall_incompatible_wires:
log_error("Incompatible re-declaration of wire %s at %s:%d.\n", child->str.c_str(), filename.c_str(), linenum);
}
}
}
else
14 changes: 12 additions & 2 deletions kernel/driver.cc
Original file line number Diff line number Diff line change
@@ -219,7 +219,11 @@ int main(int argc, char **argv)
printf(" Use 'ALL' as <header_id> to dump at every header.\n");
printf("\n");
printf(" -W regex\n");
printf(" print a warning for all log messages matching the regex \n");
printf(" print a warning for all log messages matching the regex.\n");
printf("\n");
printf(" -w regex\n");
printf(" if a warning message matches the regex, it is printes as regular\n");
printf(" message instead.\n");
printf("\n");
printf(" -V\n");
printf(" print version information and exit\n");
@@ -241,7 +245,7 @@ int main(int argc, char **argv)
}

int opt;
while ((opt = getopt(argc, argv, "MXAQTVSm:f:Hh:b:o:p:l:L:qv:tds:c:W:D:")) != -1)
while ((opt = getopt(argc, argv, "MXAQTVSm:f:Hh:b:o:p:l:L:qv:tds:c:W:w:D:")) != -1)
{
switch (opt)
{
@@ -329,6 +333,12 @@ int main(int argc, char **argv)
std::regex_constants::optimize |
std::regex_constants::egrep));
break;
case 'w':
log_nowarn_regexes.push_back(std::regex(optarg,
std::regex_constants::nosubs |
std::regex_constants::optimize |
std::regex_constants::egrep));
break;
case 'D':
{
auto args = split_tokens(optarg, ":");
29 changes: 21 additions & 8 deletions kernel/log.cc
Original file line number Diff line number Diff line change
@@ -41,7 +41,7 @@ YOSYS_NAMESPACE_BEGIN
std::vector<FILE*> log_files;
std::vector<std::ostream*> log_streams;
std::map<std::string, std::set<std::string>> log_hdump;
std::vector<std::regex> log_warn_regexes;
std::vector<std::regex> log_warn_regexes, log_nowarn_regexes;
bool log_hdump_all = false;
FILE *log_errfile = NULL;
SHA1 *log_hasher = NULL;
@@ -202,15 +202,28 @@ void logv_header(RTLIL::Design *design, const char *format, va_list ap)

void logv_warning(const char *format, va_list ap)
{
if (log_errfile != NULL && !log_quiet_warnings)
log_files.push_back(log_errfile);
std::string message = vstringf(format, ap);
bool suppressed = false;

log("Warning: ");
logv(format, ap);
log_flush();
for (auto &re : log_nowarn_regexes)
if (std::regex_search(message, re))
suppressed = true;

if (log_errfile != NULL && !log_quiet_warnings)
log_files.pop_back();
if (suppressed)
{
log("Suppressed warning: %s", message.c_str());
}
else
{
if (log_errfile != NULL && !log_quiet_warnings)
log_files.push_back(log_errfile);

log("Warning: %s", message.c_str());
log_flush();

if (log_errfile != NULL && !log_quiet_warnings)
log_files.pop_back();
}
}

void logv_error(const char *format, va_list ap)
2 changes: 1 addition & 1 deletion kernel/log.h
Original file line number Diff line number Diff line change
@@ -49,7 +49,7 @@ struct log_cmd_error_exception { };
extern std::vector<FILE*> log_files;
extern std::vector<std::ostream*> log_streams;
extern std::map<std::string, std::set<std::string>> log_hdump;
extern std::vector<std::regex> log_warn_regexes;
extern std::vector<std::regex> log_warn_regexes, log_nowarn_regexes;
extern bool log_hdump_all;
extern FILE *log_errfile;
extern SHA1 *log_hasher;
Loading