SV builds the key concept of Testbench: the CRT (constraint random test), the randomization of the test set.
Because the object class consists of data and operations, randomization of the data is typically placed within a class. (The configuration of the environment or environment can also be reflected in the randomization of configuration parameters)
A constraint consists of two parts: RAND/RANDC variable declaration, constraint constraint block. Where RANDC is periodically evaluated before repetition, the variable in the constraint constraint block has at least one RAND/RANDC
Variable, the constraint constraint block must be used within {} to represent multiple constraints. A constraint block is a declarative code that runs in parallel.
Constraint: Typically referenced in a initial module or program, in the form of an assert: Assert (P.randomize ()); After randomization fails, the return value of 0,assert will print log.
and exit. There are also two hidden function:pre_randomize (), Post_randomize (), which can be added to the initialization of non-randomize variables while leaving a hook.
Several constraint modes:
1) Constraint Longth {Low < Mid;
Mid < High;} Relational operators must be written separately.
2) constraint length {len = = Mid-Low;} You cannot have assignment statements within a constraint block, instead you should use relational operators
3) constraint C_dist {src_dist {0:= 40, [1:3]:=60;} : = After---equal weight
dst_dist {0:/ 40, [1:3]:/ 60};} :/Post Weight---scale
4) constraint C_rang {c inside {[Lo:hi]}; Inside:low-high
b inside {[10:$]}; $ can represent boundaries
! (c inside {[$:30]}); }//Plus () can be added! Represents a non-
5) Constraint C_io {(io_space_mode)--and Addr[31]==1 ' B1; ---> Indicates if
if (Op==read) len inside {[Byte:word]}; }//--->if--else
6) Constraint C_xy {(x==0), y==0; Solve. The probability that before may change the solution
Solve x before y;}
7) Assert (T.randmize () with {addr > 50; Inline constraints, the scope of addr is class at this level, the effect of randomize is equivalent
Addr < 150;} )
Switch control of the constraint:
Initial begin
p = new ();
P.c_short.constraint_mode (0); HANDLE + constraint block +mode, control this constraint block mode
ASSERT (P.randomize ());
Transmit (p);
P.contraint_mode (0); Handle +mode, control the entire handle of mode
P.c_short.constraint_mode (1);
ASSERT (P.randomize ());
Transmit (p);
End
Constraints on arrays:
1) constraint D_size {d.size inside {[1:10]};
D.sum = = 4 ' h4; The number of bits in the//sum is the same as the number of digits in the array, so you may not be able to reach the desired range.
In real-world applications, variables should be used to control constraints.
Randomization in SV