Here's a collapsed set of questions asked during the live web seminar along with Dave's answers. If you don't see your question here, or need further clarification, you can always ask on the Verification Academy Forums.
How do you randomize variable v to 2,4,6,8,10,12,.....N without using a constraint?
v = $urandom_range(N/2,1)*2;
How do you randomize negative and positive real numbers like from (-1, 1)?
The current LRM does not allow real random variables, but you can scale a number from (-1000,1000) and divide it by 1000 in post_randomize().
class A;
rand int int_val;
real real_val;
constraint range { int_val inside {[-1000:1000]}; }
function void post_randomize();
real_val = int_val/1000.0;
endfunction
endclass
When should we expect the next revision to the SystemVerilog standard, IEEE?
We are just about to start the next version/update that should be available around 2023. Refer to this Verification Horizons Blog post - Time for Another Revision of the SystemVerilog IEEE 1800 Standard.
What is the difference between rand and randc?
A class variable declared with the rand qualifier will have a set of possible values with a certain probability, as explained in this session. Each call to randomize() is independent operation with no history of previous randomization. Unless the probability of picking a value is an absolute 0, there is always some probability of picking the same value repeatedly before choosing a different value.
The randc qualifier gives you cyclic random values. You do not get a repeated value until all possible values have been used.
Is item a keyword in casting within constraint as shown in the example?
item is not a keyword; it is an implicit local variable for the reduction methods like sum(). It's similar to the foreach(array[i]) iterator except that item represents the element value, instead of the index value for i in the foreach.
What are bidirectional constraints?
I think this is misleading terminology in the LRM. Certain constraints appear to imply a procedural ordering in one direction but in fact they are just Boolean equations.
For example, the implication operator A -> B;, or the equivalent if(A) B; appears as if you need to determine A before deciding to determine B. The constraints solver simply implements this as (!A || B).
In which region of SV scheduling, constraints are solved?
There is no dedicated region for constraint solving. You call the randomize() method from a procedural thread, and the caller’s region determines the region of the callee.
Is there a way to get a number of possible solutions or probability of values before even executing the code?
This is an area of active research and development. For simple constraints like a range this is straightforward, but it explodes into a very hard problem quickly.
I want to generate stimulus in the power of 2. What is the approach to do this?
This is the same as a one-hot encoding, where only one bit is set in a variable.
constraint one_hot ($countones(my_var) == 1;}
What is the difference between $random & $urandom?
$random is legacy from Verilog and does not have a good distribution. It also does not have the built-in seed management or random stability offered by $urandom.
For the distribution example, is implicitly set that OP is solved before data? Or distribution is overridden if data is solved before OP?
Yes, a dist constraint implies some kind over ordering. The LRM is not explicit about where implicit ordering occurs, and how all conflicts in distributions get resolved.
How can we add constraints to array or queue and also add within range?
You can use the foreach iterative constraint and use implication to select a range.
constraint c {foreach (array[i])
i inside {[5:15] -> array[i] < max; }
Is it OK to have functional called in constraint?
You can call a user-defined function in a constraint, but there are special rules and limitations that you can read in section 18.5.12 Functions in constraints in the IEEE 1800-2017 LRM. The most import limitation is that the function’s inputs arguments get solved first, and the output of the function becomes a state variable. If there are constraints on the output that cannot be met, it will not go backwards to find input values that work, and the randomization will fail.
Can you give a brief idea on static constraint?
The static qualifier on a constraint affects access to the constraint_mode. There is only one constraint mode for a static constraint, whereas a non-static constraint has its own constraint_mode for each class instance.
Can we use more than 2 Relation operators in single Constraint
I used this same question as an example in this Verification Horizons Blog post - Asking better questions on the Verification Academy Forums with EDAPlayground.