Assertions LECTURE5 V1 1
Assertions LECTURE5 V1 1
Jean-Michel Chabloz
Assertions basic Idea
• We assert that a certain “thing” should be
true.
– If it is true, fine
– If it is false, then we get an error/warning/etc.
initial begin
…
assert(a==10) else $info(“a is not 10”);
…
end
• Example:
checkOnReq: assert property (@(negedge clk) req |-> ##2 !req ##1
valid==1) else $error(“error found”);
• Any alternatives?
Implication in Single-Cycle
assertions
• If a is one then b must be one
– assert property (@(negedge clk) a |-> b)
• a: 2 4 2 2 4
• c: 0 1 2 3 4
• In cycle 0: matches at 1
• In cycle 1: fails at 1
– at 1 we know the assertion will never match
• In cycle 2: fails at 3
– at 2 we think the assertion may match
– at 3 we realize we were wrong
• In cycle 3: matches at 4
Multicycle assertions
• We normally want to write assertions that are
triggered by something
• g: 0 0 0 0 0 0 0 1 1 1
• r: 0 0 0 0 1 1 1 1 1 1
• c: 0 1 2 3 4 5 6 7 8 9
• g: 0 0 0 0 0 0 0 1 1 1
• r: 0 0 0 0 1 1 1 1 1 1
• c: 0 1 2 3 4 5 6 7 8 9
• c: 0 1 2 3 4 5 6 7 8 9
• a: 0 1 0 1 0 1 0 0 0 1
• g: 0 0 0 0 1 0 0 0 1 0
• alternative syntax:
• c: 0 1 2 3 4 5 6 7 8 9
• b: 0 1 0 0 0 0 1 0 0 0
• a: 0 0 0 1 0 1 0 1 1 0
• c: 0 1 2 3 4 5 6 7 8 9
• b: 0 1 0 0 0 0 0 0 0 0
• a: 0 0 0 1 0 1 0 1 1 0
• b ##1 !a [*0:$] ##1 a |-> cond1 is different – The evaluation attempt started at 1 will
fail if condition 1 is false at 3 (first occurrence of a==1 after b). It will not fail if cond1 is
false at 5, 7, 8.
• sequence s1;
• ##1 b [*0:$] ##1 b;
• endsequence
• sequence s2;
• $fell(b) ##1 !b ##1 b;
• endsequence
• Good for code reuse and for keeping a good coding style
Internal variables
• The other big advantage of sequences is that they can have local
variables
• sequence s1;
• int cnt;
• (a==1, b=cnt) ##1 !a [*0:$] ##1 (a && b==cnt+1);
• endsequence
• sequence s1;
• int cnt;
• (1, cnt=b) ##1 !a *[0:$] ##1 (a & b==cnt+1);
• endsequence
• since in the sequence we want to record the value cnt every time a is one, we don’t
have a condition. But we cannot write
• cnt=b ##1 !a *[0:...
• We always need a condition, in case there is no condition then use the trivial
condition “1”
• Can even have function calls and $display – useful for debugging – example ##1
(a==1, $display(cnt))
throughout
• Often the assertions take the form:
• after r is one, then r will go to zero and
remain at zero for at least one cycle
cycles, then it will raise. Check that cond1
is true for all the cycles in which r is zero