Skip to content

Commit

Permalink
Merge pull request #927 from diffblue/bitwise_not1
Browse files Browse the repository at this point in the history
aval/bval for bitwise not
  • Loading branch information
tautschnig authored Jan 15, 2025
2 parents cbad677 + e467b98 commit f274e11
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 0 deletions.
7 changes: 7 additions & 0 deletions regression/verilog/expressions/bitwise_not1.desc
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
CORE
bitwise_not1.sv
--bound 0
^EXIT=0$
^SIGNAL=0$
--
^warning: ignoring
12 changes: 12 additions & 0 deletions regression/verilog/expressions/bitwise_not1.sv
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
module main;

assert final (~0 === 'hffff_ffff);
assert final (~1 === 'hffff_fffe);
assert final (~(-('sd1)) === 0);
assert final (~3'b101 === 3'b010);
assert final (~3'bxxx === 3'bxxx);
assert final (~3'bzzz === 3'bxxx);
assert final (~3'b10x === 3'b01x);
assert final (~3'b10z === 3'b01x);

endmodule
19 changes: 19 additions & 0 deletions src/verilog/aval_bval_encoding.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,7 @@ combine_aval_bval(const exprt &aval, const exprt &bval, const typet &dest)
{
PRECONDITION(aval.type().id() == ID_bv);
PRECONDITION(bval.type().id() == ID_bv);
PRECONDITION(dest.id() == ID_bv);
return concatenation_exprt{{bval, aval}, dest};
}

Expand Down Expand Up @@ -336,6 +337,24 @@ exprt aval_bval(const not_exprt &expr)
return if_exprt{has_xz, x, aval_bval_conversion(not_expr, x.type())};
}

exprt aval_bval(const bitnot_exprt &expr)
{
auto &type = expr.type();
PRECONDITION(is_four_valued(type));
PRECONDITION(is_aval_bval(expr.op()));

// x/z is done bit-wise.
// ~z is x.
auto op_aval = aval(expr.op());
auto op_bval = bval(expr.op());

exprt aval = bitor_exprt{
bitand_exprt{bitnot_exprt{op_bval}, op_bval}, // x/z case
bitand_exprt{bitnot_exprt{op_aval}, bitnot_exprt{op_bval}}}; // 0/1 case

return combine_aval_bval(aval, op_bval, lower_to_aval_bval(expr.type()));
}

exprt aval_bval(const power_exprt &expr)
{
PRECONDITION(is_four_valued(expr.type()));
Expand Down
3 changes: 3 additions & 0 deletions src/verilog/aval_bval_encoding.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ Author: Daniel Kroening, [email protected]
#ifndef CPROVER_VERILOG_AVAL_BVAL_H
#define CPROVER_VERILOG_AVAL_BVAL_H

#include <util/bitvector_expr.h>
#include <util/bitvector_types.h>
#include <util/mathematical_expr.h>

Expand Down Expand Up @@ -46,6 +47,8 @@ exprt aval_bval(const verilog_logical_inequality_exprt &);

/// lowering for !
exprt aval_bval(const not_exprt &);
/// lowering for ~
exprt aval_bval(const bitnot_exprt &);
/// lowering for ==?
exprt aval_bval(const verilog_wildcard_equality_exprt &);
/// lowering for !=?
Expand Down
10 changes: 10 additions & 0 deletions src/verilog/verilog_lowering.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -503,6 +503,16 @@ exprt verilog_lowering(exprt expr)
else
return expr; // leave as is
}
else if(expr.id() == ID_bitnot)
{
auto &bitnot_expr = to_bitnot_expr(expr);

// encode into aval/bval
if(is_four_valued(expr.type()))
return aval_bval(bitnot_expr);
else
return expr; // leave as is
}
else if(expr.id() == ID_verilog_iff)
{
auto &iff = to_verilog_iff_expr(expr);
Expand Down

0 comments on commit f274e11

Please sign in to comment.