Skip to content

BMC: implement weak/strong sequences #1070

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions regression/verilog/SVA/cover_sequence2.desc
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
KNOWNBUG
CORE
cover_sequence2.sv
--bound 2
^\[main\.p0\] cover \(main\.x == 2 ##1 main\.x == 3 ##1 main\.x == 100\): PROVED$
^\[main\.p1\] cover \(main\.x == 98 ##1 main\.x == 99 ##1 main\.x == 100\): REFUTED up to bound 2$
--bound 5
^\[main\.p0\] cover \(main\.x == 2 ##1 main\.x == 3 ##1 main\.x == 100\): REFUTED up to bound 5$
^\[main\.p1\] cover \(main\.x == 98 ##1 main\.x == 99 ##1 main\.x == 100\): REFUTED up to bound 5$
^\[main\.p2\] cover \(main\.x == 3 ##1 main\.x == 4 ##1 main\.x == 5\): PROVED$
^\[main\.p3\] cover \(main\.x == 4 ##1 main\.x == 5 ##1 main\.x == 6\): REFUTED up to bound 5$
^EXIT=10$
^SIGNAL=0$
--
^warning: ignoring
--
Cover property p0 cannot ever hold, but is shown proven when using a small bound.
12 changes: 9 additions & 3 deletions regression/verilog/SVA/cover_sequence2.sv
Original file line number Diff line number Diff line change
@@ -1,15 +1,21 @@
module main(input clk);

// count up
reg [7:0] x = 0;
int x = 0;

always @(posedge clk)
always_ff @(posedge clk)
x++;

// expected to fail
p0: cover property (x==2 ##1 x==3 ##1 x==100);

// expected to fail until bound reaches 100
// expected to fail until x reaches 100
p1: cover property (x==98 ##1 x==99 ##1 x==100);

// expected to pass once x reaches 5
p2: cover property (x==3 ##1 x==4 ##1 x==5);

// expected to pass once x reaches 6
p3: cover property (x==4 ##1 x==5 ##1 x==6);

endmodule
11 changes: 11 additions & 0 deletions regression/verilog/SVA/cover_sequence3.desc
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
CORE
cover_sequence3.sv
--bound 3
^\[main\.p0\] cover \(1 \[\*10\]\): REFUTED up to bound 3$
^\[main\.p1\] cover \(1 \[\*4:10\]\): PROVED$
^\[main\.p2\] cover \(1 \[\*5:10\]\): REFUTED up to bound 3$
^EXIT=10$
^SIGNAL=0$
--
^warning: ignoring
--
18 changes: 18 additions & 0 deletions regression/verilog/SVA/cover_sequence3.sv
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
module main(input clk);

// count up
int x = 0;

always_ff @(posedge clk)
x++;

// passes with bound >=9
p0: cover property (1[*10]);

// passes with bound >=3
p1: cover property (1[*4:10]);

// passes with bound >=4
p2: cover property (1[*5:10]);

endmodule
12 changes: 12 additions & 0 deletions regression/verilog/SVA/cover_sequence4.desc
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
KNOWNBUG
cover_sequence4.sv
--bound 3
^\[main\.p0\] cover \(1 \[=10\]\): REFUTED up to bound 3$
^\[main\.p1\] cover \(1 \[=4:10\]\): PROVED$
^\[main\.p2\] cover \(1 \[=5:10\]\): REFUTED up to bound 3$
^EXIT=10$
^SIGNAL=0$
--
^warning: ignoring
--
Implementation of [=x:y] is missing.
18 changes: 18 additions & 0 deletions regression/verilog/SVA/cover_sequence4.sv
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
module main(input clk);

// count up
int x = 0;

always_ff @(posedge clk)
x++;

// passes with bound >=9
p0: cover property (1[=10]);

// passes with bound >=3
p1: cover property (1[=4:10]);

// passes with bound >=4
p2: cover property (1[=5:10]);

endmodule
4 changes: 2 additions & 2 deletions regression/verilog/SVA/strong1.desc
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
CORE
strong1.sv
--bound 20
^\[main\.p0\] strong\(##\[0:9\] main\.x == 100\): REFUTED$
--bound 4
^\[main\.p0\] strong\(##\[0:9\] main\.x == 5\): REFUTED$
^EXIT=10$
^SIGNAL=0$
--
Expand Down
4 changes: 2 additions & 2 deletions regression/verilog/SVA/strong1.sv
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ module main;
always @(posedge clk)
x<=x+1;

// fails
initial p0: assert property (strong(##[0:9] x==100));
// fails if bound is too low
initial p0: assert property (strong(##[0:9] x==5));

endmodule
39 changes: 7 additions & 32 deletions src/trans-word-level/instantiate_word_level.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -123,40 +123,15 @@ wl_instantiatet::instantiate_rec(exprt expr, const mp_integer &t) const
expr.id() == ID_typecast && expr.type().id() == ID_bool &&
to_typecast_expr(expr).op().type().id() == ID_verilog_sva_sequence)
{
auto &sequence = to_typecast_expr(expr).op();

// sequence expressions -- these may have multiple potential
// match points, and evaluate to true if any of them matches
const auto matches = instantiate_sequence(sequence, t, no_timeframes);
exprt::operandst disjuncts;
disjuncts.reserve(matches.size());
mp_integer max = t;

for(auto &match : matches)
{
disjuncts.push_back(match.condition);
max = std::max(max, match.end_time);
}

return {max, disjunction(disjuncts)};
// should have been done by property_obligations_rec
PRECONDITION(false);
}
else if(expr.id() == ID_sva_sequence_property)
else if(
expr.id() == ID_sva_sequence_property || expr.id() == ID_sva_weak ||
expr.id() == ID_sva_strong)
{
// sequence expressions -- these may have multiple potential
// match points, and evaluate to true if any of them matches
auto &sequence = to_sva_sequence_property_expr(expr);
const auto matches = instantiate_sequence(sequence, t, no_timeframes);
exprt::operandst disjuncts;
disjuncts.reserve(matches.size());
mp_integer max = t;

for(auto &match : matches)
{
disjuncts.push_back(match.condition);
max = std::max(max, match.end_time);
}

return {max, disjunction(disjuncts)};
// should have been done by property_obligations_rec
PRECONDITION(false);
}
else if(expr.id() == ID_verilog_past)
{
Expand Down
41 changes: 33 additions & 8 deletions src/trans-word-level/property.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -530,8 +530,17 @@ static obligationst property_obligations_rec(
// The sequence must not match.
auto &sequence = to_sva_sequence_property_expr_base(op).sequence();

// clang-format off
auto semantics =
op.id() == ID_sva_strong ? sva_sequence_semanticst::STRONG
: op.id() == ID_sva_weak ? sva_sequence_semanticst::WEAK
: op.id() == ID_sva_implicit_strong ? sva_sequence_semanticst::STRONG
: op.id() == ID_sva_implicit_weak ? sva_sequence_semanticst::WEAK
: sva_sequence_semanticst::WEAK;
// clang-format on

const auto matches =
instantiate_sequence(sequence, current, no_timeframes);
instantiate_sequence(sequence, semantics, current, no_timeframes);

obligationst obligations;

Expand Down Expand Up @@ -577,10 +586,13 @@ static obligationst property_obligations_rec(
auto &implication = to_binary_expr(property_expr);

// The LHS is a sequence, the RHS is a property.
// The implication must hold for _all_ matches on the LHS,
// The implication must hold for _all_ (strong) matches on the LHS,
// i.e., each pair of LHS match and RHS obligation yields an obligation.
const auto lhs_match_points =
instantiate_sequence(implication.lhs(), current, no_timeframes);
const auto lhs_match_points = instantiate_sequence(
implication.lhs(),
sva_sequence_semanticst::STRONG,
current,
no_timeframes);

obligationst result;

Expand Down Expand Up @@ -620,9 +632,12 @@ static obligationst property_obligations_rec(
// the result is a property expression.
auto &followed_by = to_sva_followed_by_expr(property_expr);

// get match points for LHS sequence
auto matches =
instantiate_sequence(followed_by.antecedent(), current, no_timeframes);
// get (proper) match points for LHS sequence
auto matches = instantiate_sequence(
followed_by.antecedent(),
sva_sequence_semanticst::STRONG,
current,
no_timeframes);

exprt::operandst disjuncts;
mp_integer t = current;
Expand Down Expand Up @@ -663,9 +678,19 @@ static obligationst property_obligations_rec(
auto &sequence =
to_sva_sequence_property_expr_base(property_expr).sequence();

// clang-format off
auto semantics =
property_expr.id() == ID_sva_strong ? sva_sequence_semanticst::STRONG
: property_expr.id() == ID_sva_weak ? sva_sequence_semanticst::WEAK
: property_expr.id() == ID_sva_implicit_strong ? sva_sequence_semanticst::STRONG
: property_expr.id() == ID_sva_implicit_weak ? sva_sequence_semanticst::WEAK
: sva_sequence_semanticst::WEAK;
// clang-format on

// sequence expressions -- these may have multiple potential
// match points, and evaluate to true if any of them matches
const auto matches = instantiate_sequence(sequence, current, no_timeframes);
const auto matches =
instantiate_sequence(sequence, semantics, current, no_timeframes);
exprt::operandst disjuncts;
disjuncts.reserve(matches.size());
mp_integer max = current;
Expand Down
Loading
Loading