assertion 作用
(1) 检测一个条件有没有发生;(2)检测一系列动作有没有发生。可以直接介入硬件内部信号,bind到硬件。
1. 当拍assert,“ |-> ”。
上升沿
always @(posedge clock)
a_example1: assert(A && !B);
或者
property example1;
@(posedge clock) A |-> !B;
endproperty
a_example1: assert property(example1);
或者
a_example1: assert property(@(posedge clock) A |-> !B);
下降沿
always @(negedge clock)
a_example2: assert(A && !B);
或者
property example2;
@(negedge clock) A |-> !B;
endproperty
a_example2: assert property(example2);
或者
a_example2: assert property(@(negedge clock) A |-> !B);
变化沿
a_example2: assert property(@(A or B) C || D);
2. 下一拍assert,“ |=> ”。
always @(posedge clock)
a_example1: assert(A |=> B);
或者
property example1;
@(posedge clock) A |=> B;
endproperty
assert property(example1);
或者
a_example1: assert property(@(posedge clock) A |=> !B);
3. 推后几拍,##clcyes。
a_example1: assert property(@(posedge clock) A ##1 B ##2 C);//this will check the condition every cycle, the expression must be true every cycle.
a_example2: assert property(@(posedge clock) A |-> B ##2 C);//this will check the condition every cycle, the expression must be true only when A is true at posedge clock.
a_example3: assert property(@(posedge clock) A |=> ##[1:3] !B);//this will check the condition every cycle, the expression must be true only when A is true at posedge clock.
4. 连续重复次数,BOOL[*serval],[*min:max],min可以为0,max可以为无限大。
property EXAMPLE1
@(posedge clock) A[*5] |=> A;
endproperty
a_example1: assert property(EXAMPLE1);
property EXAMPLE2
@(posedge clock) A ##1 !A |-> !A[*2:5] ##1 A;
endproperty
a_example2: assert property(EXAMPLE2);
5. 不连续重复次数,BOOL[->serval];[->min:max],min可以为0,max可以为无限大。BOOL表达式在第serval次为TRUE,且在下一个sequence判断时,也是TRUE。
property EXAMPLE1
@(posedge clock) A |=> B[->2] ##1 C;
endproperty
a_example1: assert property(EXAMPLE1);
property EXAMPLE2
@(posedge clock) A |-> B[->2:5] ##1 C[->1:3];
endproperty
a_example2: assert property(EXAMPLE2);
6. 不连续重复次数,BOOL[=serval];[->min:max],min可以为0,max可以为无限大。BOOL表达式在第serval次为TRUE,且在下一个sequence判断时,可以不是TRUE。
property EXAMPLE1
@(posedge clock) A |=> B[=2] ##1 C;
endproperty
a_example1: assert property(EXAMPLE1);
property EXAMPLE2
@(posedge clock) A |-> B[=2:5] ##1 C[->1:3];
endproperty
a_example2: assert property(EXAMPLE2);
7. or
a_example1: assert(@(posedge clock) A |-> B or C);//hwen A is true, either of B or C is true, the result is true
8. not
sequence BC;
B ##1 C;
endsequence;
property EXAMPLE1;
(posedge clock) A |-> not(BC);
endproperty
a_example1: assert property(EXAMPLE1);
9. $rose(BOOL),在当前的clock上升沿之前,判断是否检测到BOOL的上升沿,如果有,接着判断B。
property EXAMPLE1;
@(posedge clock) $rose(A) |-> B;
endproperty
a_example1: assert property(EXAMPLE1);
10. $fell(BOOL),在当前的clock上升沿之前,判断是否检测到BOOL的下降沿,如果有,接着判断B。
property EXAMPLE1;
@(posedge clock) $fell(A) |=> !B;
endproperty
a_example1: assert property(EXAMPLE1);
11. $stable(BOOL),BOOL与上一clcok的值比较,判断是否保持原值。
property EXAMPLE1;
@(posedge clock) !A |=> $stable(B);
endproperty
a_example1: assert property(EXAMPLE1);
12. $past(BOOL,serval),与BOOL的前serval clock的值比较,判断是否一致。
property EXAMPLE1;
@(posedge clock) !A |=> (B == $past(C,2));
endproperty
a_example1: assert property(EXAMPLE1);
13. $disable,disable iff(!A)是使能条件,第一条件是clock上升沿,第二条件是iff(!A),这个语句才有效,即如果A为0,才接着判断后面的sequence。
property EXAMPLE1;
@(posedge clock) disable iff(!A) B |=> C ##1 D ##2 E;
endproperty
a_example1: assert property(EXAMPLE1);
14. $onehot(BOOL),判断BOOL中的1的个数,非0时,assert成功。
property EXAMPLE1;
@(posedge clock) $onehot(A);
endproperty
a_example1: assert property(EXAMPLE1);
15. $onehot0,判断BOOL中的1的个数,不多于1个时,assert成功。
property EXAMPLE1;
@(posedge clock) $onehot(A);
endproperty
a_example1: assert property(EXAMPLE1);
16. countones,判断BOOL中的1的个数,等于相应的值时,assert成功。
property EXAMPLE1;
@(posedge clock) $countones(A)==2;
endproperty
a_example1: assert property(EXAMPLE1);
17. isunknown,判断是否有Z 、X态。
property EXAMPLE1;
@(posedge clock) $isunknown(A);
endproperty
a_example1: assert property(EXAMPLE1);
18. and,如下,B和C必须在同一时间为TRUE,不必同一时间为FALSE。
property EXAMPLE1;
(posedge clock) A |-> B and C;
endproperty
a_example1: assert property(EXAMPLE1);
19. intersect,如下,B和C必须在同一时间为TRUE,同一时间为FALSE。
property EXAMPLE1;
(posedge clock) A |-> B intersect C;
endproperty
a_example1: assert property(EXAMPLE1);
20. first_match()
property EXAMPLE1;
(posedge clock) first_match(A ##[1:2] |-> B intersect C);
endproperty
a_example1: assert property(EXAMPLE1);
21. within
sequence C;
C ##1 !C;
endsequence
property EXAMPLE1;
(posedge clock) $rose(A) |=> C[*5] within !A[->1];
endproperty
a_example1: assert property(EXAMPLE1);
22. throughout
sequence C;
C ##1 !C;
endsequence
property EXAMPLE1;
(posedge clock) $rose(A) |=> (B throughout C[*5]) ##1 !A;
endproperty
a_example1: assert property(EXAMPLE1);
23. if else
property EXAMPLE1;
(posedge clock) A ##1 (B || C)[->1] |->
if(B)
(##1 D)
else
(##1 E);
endproperty
a_example1: assert property(EXAMPLE1);
24. .ended()
sequence ab;
@(posedge clock) $fell(a) ##1 $rose(b);
endsequence
property EXAMPLE1;
(posedge clock) $rose(C) |-> AB(A,B).ended();
endproperty
a_example1: assert property(EXAMPLE1);
25. .matched()
sequence ab;
@(posedge clock) $fell(a) ##1 $rose(b);
endsequence
property EXAMPLE1;
(posedge clock) $rose(C) |-> AB(A,B) |=> ((posedge clock1) AB(A,B).matched())[->1];
endproperty
a_example1: assert property(EXAMPLE1);
26. expect
sequence ABC1;
A ##2 B ##2 C;
endsequence
property ABC2;
@(posedge clock) A |=> ABC1;
endproperty
expect(@(posedge clock) (ABC1)); // PASS
expect(ABC2); ; // PASS
@(posedge clock) expect(ABC1) ; // FAIL