Skip to content

SVA [*...] for sequence operands #1092

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

Merged
merged 1 commit into from
May 8, 2025
Merged
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
10 changes: 10 additions & 0 deletions regression/verilog/SVA/sequence_repetition7.desc
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
CORE
sequence_repetition7.sv
--bound 20
^\[.*\] \(main\.a ##1 main\.b\) \[\*5\]: PROVED up to bound 20$
^\[.*\] \(\!main\.b ##1 \!main\.a\) \[\*5\]: PROVED up to bound 20$
^EXIT=0$
^SIGNAL=0$
--
^warning: ignoring
--
16 changes: 16 additions & 0 deletions regression/verilog/SVA/sequence_repetition7.sv
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
module main(input clk);

bit a = 1, b = 0;

always_ff @(posedge clk) begin
a = !a;
b = !b;
end

// a b a b ...
initial assert property ((a ##1 b)[*5]);

// !b !a !b !a ...
initial assert property ((!b ##1 !a)[*5]);

endmodule
42 changes: 14 additions & 28 deletions src/trans-word-level/sequence.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ Author: Daniel Kroening, [email protected]
#include "sequence.h"

#include <util/arith_tools.h>
#include <util/mathematical_types.h>

#include <ebmc/ebmc_error.h>
#include <temporal-logic/temporal_logic.h>
Expand Down Expand Up @@ -367,36 +368,21 @@ sequence_matchest instantiate_sequence(
else if(expr.id() == ID_sva_sequence_repetition_star) // [*...]
{
auto &repetition = to_sva_sequence_repetition_star_expr(expr);
if(repetition.is_unbounded() && repetition.repetitions_given())
if(repetition.is_empty_match())
{
// [*x:$]
auto from = numeric_cast_v<mp_integer>(repetition.from());
auto &op = repetition.op();

// Is op a sequence or a state predicate?
if(is_SVA_sequence_operator(op))
PRECONDITION(false); // no support

sequence_matchest result;

// we incrementally add conjuncts to the condition
exprt::operandst conjuncts;

for(mp_integer u = t; u < no_timeframes; ++u)
{
// does op hold in timeframe u?
auto cond_u = instantiate(op, u, no_timeframes);
conjuncts.push_back(cond_u);

if(conjuncts.size() >= from)
result.push_back({u, conjunction(conjuncts)});
}

// Empty match allowed?
if(from == 0)
result.push_back({t, true_exprt{}});
// [*0] denotes the empty match
return {{t, true_exprt{}}};
}
else if(repetition.is_unbounded() && repetition.repetitions_given())
{
// [*from:$] -> op[*from:to]
// with to = no_timeframes - t
auto to = from_integer(no_timeframes - t, integer_typet{});
auto new_repetition = sva_sequence_repetition_star_exprt{
repetition.op(), repetition.from(), to};

return result;
return instantiate_sequence(
new_repetition.lower(), semantics, t, no_timeframes);
}
else
{
Expand Down
9 changes: 7 additions & 2 deletions src/verilog/sva_expr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,11 +75,16 @@ exprt sva_sequence_repetition_star_exprt::lower() const
return sva_sequence_repetition_star_exprt{
op(), from_integer(0, integer_typet{}), infinity_exprt{integer_typet{}}};
}
else if(is_empty_match())
{
// [*0] is a special case, denoting the empty match
PRECONDITION(false);
}
else if(!is_range())
{
// expand x[*n] into x ##1 x ##1 ...
auto n = numeric_cast_v<mp_integer>(repetitions());
DATA_INVARIANT(n >= 1, "number of repetitions must be at least one");
PRECONDITION(n >= 1);

exprt result = op();

Expand All @@ -103,7 +108,7 @@ exprt sva_sequence_repetition_star_exprt::lower() const
auto from_int = numeric_cast_v<mp_integer>(from());
auto to_int = numeric_cast_v<mp_integer>(to());

DATA_INVARIANT(from_int >= 1, "number of repetitions must be at least one");
DATA_INVARIANT(from_int >= 0, "number of repetitions must not be negative");
DATA_INVARIANT(
to_int >= from_int, "number of repetitions must be interval");

Expand Down
6 changes: 6 additions & 0 deletions src/verilog/sva_expr.h
Original file line number Diff line number Diff line change
Expand Up @@ -1401,6 +1401,12 @@ class sva_sequence_repetition_exprt : public ternary_exprt
return op1().is_not_nil();
}

/// op[*0] is a special case, denoting the empty match
bool is_empty_match() const
{
return !is_range() && repetitions_given() && op1().is_zero();
}

// The number of repetitions must be a constant after elaboration.
const constant_exprt &repetitions() const
{
Expand Down
Loading