Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
SystemVerilog Constrained
Random Gotchas
Author: Ahmed Yehia
Presenter: Gabriel Chidolue
significant
Random Solution
Constraints RNG
Failure
© Accellera Systems Initiative 6
Introduction to SystemVerilog
Constrained Random
SystemVerilog Randomization SystemVerilog Randomization
Methods Constraints
• randomize() • Expressions need to be held true by the Solver
– Built-in class method when solving a randomization problem
– Randomizes class fields with rand/randc qualifiers
according to predefined constraints • May include random variables, non-random state
– Accepts inline constraints using the “with” clause variables, operators, distributions, literals, and
– can be called to recursively randomize all random constants
variables of a class, or to randomize specific
variable(s) • Can be hard (default) or soft
• $urandom() • Can be switched on/off using constraint_mode()
– Called in a procedural context to generate a
pseudo-random number • special operators
• $urandom_range() – inside (set membership),
– Returns an unsigned random integer value within a – -> (implication),
specified range
– dist (distribution/weighting),
• std::randomize()
– foreach (iteration),
– Can be called outside the class scope to randomize
non-class members. – if..else (conditional),
– Can accept inline constraints using the “with” – and solve..before (probability and distribution)
clause.
– unique,…
8
Outline
• Introduction to Constrained Random
Verification
• Randomization Failures Gotchas
• Randomization Results Gotchas
• Runtime Performance Gotchas
if (! i1.randomize())
$error ("Randomization of object c1 failed!");
Always capture randomize() result to
avoid implicit void casting
!
assert(i1.randomize());
trans t1 = new;
• Always issue at least one full randomize() before
assert (t1.randomize);
selected variables randomize()
!
assert (t1.randomize (b));
• Normally, the initial SystemVerilog simulation seed, does not affect foreign language code !
• This can be resolved by passing the simulation initial seed to the foreign language code
endclass
not performance
• Surprises at class dummy_c;
randc bit [31:0] val;
runtime w.r.t. endclass
class trans;
Solver overhead rand bit [31:0] addrs [];
function void post_randomize();
dummy_c dc = new;
foreach (addrs[i]) begin
assert (dc.randomize);
addrs[i] = dc.val;
end
endfunction
endclass
dist
rand bit [4:0] rd;
operators rand bit [4:0] rd;
rand bit [1:0] rd_eq_15;
constraint mode_32bit{
can have mode == 32 -> rd < 16;}
constraint mode_32bit{
runtime mode == 32 -> rd < 15;
constraint rd_dist {
}
overhead. mode == 32 -> rd [3:0] dist
function void post_randomize();
{
Reduce [4'b0000:4'b1110]: 3,
if (mode == 32)
usage as if (rd_eq_15 == 2’b11)
4'b1111 : 1
rd = 5’b01111;
possible };
endfunction
}