Skip to content

Commit

Permalink
Merge pull request #884 from diffblue/not1
Browse files Browse the repository at this point in the history
Veriog: synthesis of primitive not gates
  • Loading branch information
tautschnig authored Dec 16, 2024
2 parents 2d98387 + 3a5eb17 commit 5baabf1
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 8 deletions.
7 changes: 7 additions & 0 deletions regression/verilog/primitive_gates/not1.desc
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
CORE
not1.sv
--bound 0
^EXIT=0$
^SIGNAL=0$
--
^warning: ignoring
11 changes: 11 additions & 0 deletions regression/verilog/primitive_gates/not1.sv
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
module main(input not_in);

wire not_out1, not_out2;

not not_gate(not_out1, not_out2, not_in);

// should pass
not_out1_ok: assert final (not_out1 == !not_in);
not_out2_ok: assert final (not_out2 == !not_in);

endmodule
20 changes: 12 additions & 8 deletions src/verilog/verilog_synthesis.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1586,17 +1586,21 @@ void verilog_synthesist::synth_module_instance_builtin(
{
assert(instance.connections().size() >= 2);

for(unsigned i = 0; i < instance.connections().size() - 1; i++)
{
exprt op(ID_not, instance.type());
op.add_to_operands(instance.connections()[i]);
// May have multiple outputs. The input is the last connection.
auto &input = instance.connections().back();
exprt rhs;

if(instance.type().id()!=ID_bool)
op.id("bit"+op.id_string());
if(input.type().id() == ID_bool)
rhs = not_exprt{input};
else
rhs = bitnot_exprt{input};

equal_exprt constraint{op, instance.connections().back()};
rhs.add_source_location() = module_item.source_location();

assert(trans.operands().size()==3);
for(std::size_t i = 0; i < instance.connections().size() - 1; i++)
{
auto &lhs = instance.connections()[i];
auto constraint = equal_exprt{lhs, rhs};
trans.invar().add_to_operands(std::move(constraint));
}
}
Expand Down

0 comments on commit 5baabf1

Please sign in to comment.