Skip to content

Commit 675dd53

Browse files
committed
Small fixes and improvements in $allconst/$allseq handling
Signed-off-by: Clifford Wolf <[email protected]>
1 parent fba499b commit 675dd53

File tree

2 files changed

+23
-16
lines changed

2 files changed

+23
-16
lines changed

README.md

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -396,10 +396,11 @@ Non-standard or SystemVerilog features for formal verification
396396
but also works outside of checkers. (Yosys also supports ``rand``
397397
variables outside checkers.)
398398

399-
- The system functions ``$allconst`` and ``$allseq`` are used to construct formal
400-
exist-forall problems. Assertions are only violated if the trace vialoates
401-
the assertion for all ``$allconst/$allseq`` values and assumptions only hold
402-
if the trace satisfies the assumtion for all ``$allconst/$allseq`` values.
399+
- The system functions ``$allconst`` and ``$allseq`` can be used to construct
400+
formal exist-forall problems. Assumptions only hold if the trace satisfies
401+
the assumtion for all ``$allconst/$allseq`` values. For assertions and cover
402+
statements it is sufficient if just one ``$allconst/$allseq`` value triggers
403+
the property (similar to ``$anyconst/$anyseq``).
403404

404405
- The SystemVerilog tasks ``$past``, ``$stable``, ``$rose`` and ``$fell`` are
405406
supported in any clocked block.

backends/smt2/smtbmc.py

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1019,6 +1019,12 @@ def smt_state(step):
10191019
smt.write("(declare-fun s%d () |%s_s|)" % (step, topmod))
10201020
states.append("s%d" % step)
10211021

1022+
def smt_assert(expr):
1023+
if expr == "true":
1024+
return
1025+
1026+
smt.write("(assert %s)" % expr)
1027+
10221028
def smt_assert_antecedent(expr):
10231029
if expr == "true":
10241030
return
@@ -1158,12 +1164,12 @@ def smt_check_sat():
11581164
smt_assert_consequent(get_constr_expr(constr_assumes, step))
11591165

11601166
if step == num_steps:
1161-
smt_assert_consequent("(not (and (|%s_a| s%d) %s))" % (topmod, step, get_constr_expr(constr_asserts, step)))
1167+
smt_assert("(not (and (|%s_a| s%d) %s))" % (topmod, step, get_constr_expr(constr_asserts, step)))
11621168

11631169
else:
11641170
smt_assert_antecedent("(|%s_t| s%d s%d)" % (topmod, step, step+1))
1165-
smt_assert_consequent("(|%s_a| s%d)" % (topmod, step))
1166-
smt_assert_consequent(get_constr_expr(constr_asserts, step))
1171+
smt_assert("(|%s_a| s%d)" % (topmod, step))
1172+
smt_assert(get_constr_expr(constr_asserts, step))
11671173

11681174
if step > num_steps-skip_steps:
11691175
print_msg("Skipping induction in step %d.." % (step))
@@ -1234,7 +1240,7 @@ def smt_check_sat():
12341240
while "1" in cover_mask:
12351241
print_msg("Checking cover reachability in step %d.." % (step))
12361242
smt_push()
1237-
smt_assert_antecedent("(distinct (covers_%d s%d) #b%s)" % (coveridx, step, "0" * len(cover_desc)))
1243+
smt_assert("(distinct (covers_%d s%d) #b%s)" % (coveridx, step, "0" * len(cover_desc)))
12381244

12391245
if smt_check_sat() == "unsat":
12401246
smt_pop()
@@ -1317,8 +1323,8 @@ def smt_check_sat():
13171323
if step < skip_steps:
13181324
if assume_skipped is not None and step >= assume_skipped:
13191325
print_msg("Skipping step %d (and assuming pass).." % (step))
1320-
smt_assert_consequent("(|%s_a| s%d)" % (topmod, step))
1321-
smt_assert_consequent(get_constr_expr(constr_asserts, step))
1326+
smt_assert("(|%s_a| s%d)" % (topmod, step))
1327+
smt_assert(get_constr_expr(constr_asserts, step))
13221328
else:
13231329
print_msg("Skipping step %d.." % (step))
13241330
step += 1
@@ -1354,7 +1360,7 @@ def smt_check_sat():
13541360
print_msg("Checking assertions in steps %d to %d.." % (step, last_check_step))
13551361
smt_push()
13561362

1357-
smt_assert_consequent("(not (and %s))" % " ".join(["(|%s_a| s%d)" % (topmod, i) for i in range(step, last_check_step+1)] +
1363+
smt_assert("(not (and %s))" % " ".join(["(|%s_a| s%d)" % (topmod, i) for i in range(step, last_check_step+1)] +
13581364
[get_constr_expr(constr_asserts, i) for i in range(step, last_check_step+1)]))
13591365

13601366
if smt_check_sat() == "sat":
@@ -1380,8 +1386,8 @@ def smt_check_sat():
13801386

13811387
if (constr_final_start is not None) or (last_check_step+1 != num_steps):
13821388
for i in range(step, last_check_step+1):
1383-
smt_assert_consequent("(|%s_a| s%d)" % (topmod, i))
1384-
smt_assert_consequent(get_constr_expr(constr_asserts, i))
1389+
smt_assert("(|%s_a| s%d)" % (topmod, i))
1390+
smt_assert(get_constr_expr(constr_asserts, i))
13851391

13861392
if constr_final_start is not None:
13871393
for i in range(step, last_check_step+1):
@@ -1392,7 +1398,7 @@ def smt_check_sat():
13921398
smt_push()
13931399

13941400
smt_assert_consequent(get_constr_expr(constr_assumes, i, final=True))
1395-
smt_assert_consequent("(not %s)" % get_constr_expr(constr_asserts, i, final=True))
1401+
smt_assert("(not %s)" % get_constr_expr(constr_asserts, i, final=True))
13961402

13971403
if smt_check_sat() == "sat":
13981404
print("%s BMC failed!" % smt.timestamp())
@@ -1408,8 +1414,8 @@ def smt_check_sat():
14081414

14091415
else: # gentrace
14101416
for i in range(step, last_check_step+1):
1411-
smt_assert_consequent("(|%s_a| s%d)" % (topmod, i))
1412-
smt_assert_consequent(get_constr_expr(constr_asserts, i))
1417+
smt_assert("(|%s_a| s%d)" % (topmod, i))
1418+
smt_assert(get_constr_expr(constr_asserts, i))
14131419

14141420
print_msg("Solving for step %d.." % (last_check_step))
14151421
if smt_check_sat() != "sat":

0 commit comments

Comments
 (0)