@@ -1516,12 +1516,9 @@ void verilog_synthesist::synth_module_instance_builtin(
1516
1516
assert (trans.operands ().size ()==3 );
1517
1517
trans.invar ().add_to_operands (std::move (constraint));
1518
1518
}
1519
- else if (module ==ID_and ||
1520
- module ==ID_nand ||
1521
- module ==ID_or ||
1522
- module ==ID_nor ||
1523
- module ==ID_xor ||
1524
- module ==ID_xnor)
1519
+ else if (
1520
+ module == ID_and || module == ID_nand || module == ID_or ||
1521
+ module == ID_nor || module == ID_xor)
1525
1522
{
1526
1523
// 1800-2017 28.4 and, nand, nor, or, xor, and xnor gates
1527
1524
DATA_INVARIANT (
@@ -1549,6 +1546,41 @@ void verilog_synthesist::synth_module_instance_builtin(
1549
1546
equal_exprt constraint{output, op};
1550
1547
trans.invar ().add_to_operands (std::move (constraint));
1551
1548
}
1549
+ else if (module == ID_xnor)
1550
+ {
1551
+ // Our solver does not have ID_xnor, hence use the negation of ID_xor
1552
+ // ID_bitxor.
1553
+ // With one operand, or with more than three operands, the result is
1554
+ // ambiguous. The semantics of bitxnor do not match when using one
1555
+ // or more than two operands.
1556
+ DATA_INVARIANT (
1557
+ instance.connections ().size () >= 2 ,
1558
+ " binary primitive gates should have at least two connections" );
1559
+
1560
+ // One output, one or more inputs.
1561
+ auto &connections = instance.connections ();
1562
+ auto &output = connections[0 ];
1563
+
1564
+ exprt::operandst operands;
1565
+
1566
+ // iterate over the module inputs
1567
+ for (std::size_t i = 1 ; i < connections.size (); i++)
1568
+ {
1569
+ operands.push_back (connections[i]);
1570
+ }
1571
+
1572
+ exprt op;
1573
+
1574
+ if (instance.type ().id () == ID_bool)
1575
+ op = not_exprt{
1576
+ multi_ary_exprt{ID_xor, std::move (operands), instance.type ()}};
1577
+ else
1578
+ op = bitnot_exprt{
1579
+ multi_ary_exprt{ID_bitxor, std::move (operands), instance.type ()}};
1580
+
1581
+ equal_exprt constraint{output, std::move (op)};
1582
+ trans.invar ().add_to_operands (std::move (constraint));
1583
+ }
1552
1584
else if (module ==ID_buf)
1553
1585
{
1554
1586
assert (instance.connections ().size () >= 2 );
0 commit comments