aboutsummaryrefslogtreecommitdiffstats
path: root/techlibs/ice40
diff options
context:
space:
mode:
authorEddie Hung <eddie@fpgeh.com>2019-08-28 17:29:25 -0700
committerEddie Hung <eddie@fpgeh.com>2019-08-28 17:29:25 -0700
commit070f3ac561e6f9aed46017c360a2e368779073d4 (patch)
tree63856af5a1b46fbe56ed296d528dc830e0cbed3a /techlibs/ice40
parent2421cb3fed1a990219227ed3cf0632eb221e9698 (diff)
parentd46d38e4d5e1502ea5cb6075161c87bd837af9eb (diff)
downloadyosys-070f3ac561e6f9aed46017c360a2e368779073d4.tar.gz
yosys-070f3ac561e6f9aed46017c360a2e368779073d4.tar.bz2
yosys-070f3ac561e6f9aed46017c360a2e368779073d4.zip
Merge remote-tracking branch 'origin/eddie/fix_carry_wrapper' into xaig_arrival
Diffstat (limited to 'techlibs/ice40')
-rw-r--r--techlibs/ice40/cells_sim.v2
-rw-r--r--techlibs/ice40/ice40_opt.cc47
2 files changed, 48 insertions, 1 deletions
diff --git a/techlibs/ice40/cells_sim.v b/techlibs/ice40/cells_sim.v
index 261d99c9b..34134d02a 100644
--- a/techlibs/ice40/cells_sim.v
+++ b/techlibs/ice40/cells_sim.v
@@ -153,7 +153,7 @@ module \$__ICE40_CARRY_WRAPPER (
input A, B,
(* abc_carry *)
input CI,
- input I0, I3,
+ input I0, I3
);
parameter LUT = 0;
SB_CARRY carry (
diff --git a/techlibs/ice40/ice40_opt.cc b/techlibs/ice40/ice40_opt.cc
index f528607d6..58f106f7c 100644
--- a/techlibs/ice40/ice40_opt.cc
+++ b/techlibs/ice40/ice40_opt.cc
@@ -83,6 +83,53 @@ static void run_ice40_opts(Module *module)
}
continue;
}
+
+ if (cell->type == "$__ICE40_CARRY_WRAPPER")
+ {
+ SigSpec non_const_inputs, replacement_output;
+ int count_zeros = 0, count_ones = 0;
+
+ SigBit inbit[3] = {
+ cell->getPort("\\A"),
+ cell->getPort("\\B"),
+ cell->getPort("\\CI")
+ };
+ for (int i = 0; i < 3; i++)
+ if (inbit[i].wire == nullptr) {
+ if (inbit[i] == State::S1)
+ count_ones++;
+ else
+ count_zeros++;
+ } else
+ non_const_inputs.append(inbit[i]);
+
+ if (count_zeros >= 2)
+ replacement_output = State::S0;
+ else if (count_ones >= 2)
+ replacement_output = State::S1;
+ else if (GetSize(non_const_inputs) == 1)
+ replacement_output = non_const_inputs;
+
+ if (GetSize(replacement_output)) {
+ optimized_co.insert(sigmap(cell->getPort("\\CO")[0]));
+ module->connect(cell->getPort("\\CO")[0], replacement_output);
+ module->design->scratchpad_set_bool("opt.did_something", true);
+ log("Optimized $__ICE40_CARRY_WRAPPER cell back to logic (without SB_CARRY) %s.%s: CO=%s\n",
+ log_id(module), log_id(cell), log_signal(replacement_output));
+ cell->type = "$lut";
+ cell->setPort("\\A", { cell->getPort("\\I0"), inbit[0], inbit[1], cell->getPort("\\I3") });
+ cell->setPort("\\Y", cell->getPort("\\O"));
+ cell->unsetPort("\\B");
+ cell->unsetPort("\\CI");
+ cell->unsetPort("\\I0");
+ cell->unsetPort("\\I3");
+ cell->unsetPort("\\CO");
+ cell->unsetPort("\\O");
+ cell->setParam("\\LUT", RTLIL::Const::from_string("0110100110010110"));
+ cell->setParam("\\WIDTH", 4);
+ }
+ continue;
+ }
}
for (auto cell : sb_lut_cells)