Skip to content

Commit 1289b5a

Browse files
committedSep 11, 2017
recover_adder_core: Fix bug with carry into XOR3 not into port C
1 parent 29edbc9 commit 1289b5a

File tree

1 file changed

+44
-6
lines changed

1 file changed

+44
-6
lines changed
 

‎passes/techmap/recover_adder_core.cpp

+44-6
Original file line numberDiff line numberDiff line change
@@ -312,10 +312,29 @@ struct RecoverAdderCorePass : public Pass {
312312
SigSpec b;
313313
SigSpec y;
314314

315-
for (auto x : cur_adder)
315+
for (size_t i = 0; i < cur_adder.size(); i++)
316316
{
317-
a.append_bit(x->getPort("\\A")[0]);
318-
b.append_bit(x->getPort("\\B")[0]);
317+
auto x = cur_adder[i];
318+
auto this_a = x->getPort("\\A")[0];
319+
auto this_b = x->getPort("\\B")[0];
320+
if (x->type == "\\__XOR3_")
321+
{
322+
auto this_c = x->getPort("\\C")[0];
323+
SigBit last_cout;
324+
if (!is_sub)
325+
last_cout = cur_adder[i - 1]->getPort("\\Cout")[0];
326+
else
327+
last_cout = cur_adder[i - 1]->getPort("\\Bout")[0];
328+
329+
if (sigmap(this_a) == sigmap(last_cout))
330+
this_a = this_c;
331+
else if (sigmap(this_b) == sigmap(last_cout))
332+
this_b = this_c;
333+
else
334+
log_assert(sigmap(this_c) == sigmap(last_cout));
335+
}
336+
a.append_bit(this_a);
337+
b.append_bit(this_b);
319338
y.append_bit(x->getPort("\\Y")[0]);
320339
}
321340

@@ -364,10 +383,29 @@ struct RecoverAdderCorePass : public Pass {
364383
SigSpec y;
365384
SigSpec cout;
366385

367-
for (auto x : cur_adder)
386+
for (size_t i = 0; i < cur_adder.size(); i++)
368387
{
369-
a.append_bit(x->getPort("\\A")[0]);
370-
b.append_bit(x->getPort("\\B")[0]);
388+
auto x = cur_adder[i];
389+
auto this_a = x->getPort("\\A")[0];
390+
auto this_b = x->getPort("\\B")[0];
391+
if (x->type == "\\__XOR3_")
392+
{
393+
auto this_c = x->getPort("\\C")[0];
394+
SigBit last_cout;
395+
if (!is_sub)
396+
last_cout = cur_adder[i - 1]->getPort("\\Cout")[0];
397+
else
398+
last_cout = cur_adder[i - 1]->getPort("\\Bout")[0];
399+
400+
if (sigmap(this_a) == sigmap(last_cout))
401+
this_a = this_c;
402+
else if (sigmap(this_b) == sigmap(last_cout))
403+
this_b = this_c;
404+
else
405+
log_assert(sigmap(this_c) == sigmap(last_cout));
406+
}
407+
a.append_bit(this_a);
408+
b.append_bit(this_b);
371409
y.append_bit(x->getPort("\\Y")[0]);
372410
auto portname = is_sub ? "\\Bout" : "\\Cout";
373411
if (x->hasPort(portname))

0 commit comments

Comments
 (0)
Please sign in to comment.