当前位置:网站首页>SystemVerilog learning-08-random constraints and thread control
SystemVerilog learning-08-random constraints and thread control
2022-07-01 06:13:00 【Vuko-wxh】
Random constraint
brief introduction
As the design gets bigger and bigger , It is becoming more and more difficult to generate a complete incentive to test the function of the design .
The test method of directional excitation has long been unable to meet the requirements of checking functional integrity .SoC The complexity of interaction between modules is also increasing exponentially due to the improvement of integration , This makes verifier It is impossible to predict what will happen to users in the process of use .
Random - constraint , The combination of these two words constitutes the mainstream method of dynamic simulation verification . Random constraint test (CRT,Constrained-Random Test) That is, it can generate something you are interested in 、 Your test is unexpected , Through regression test 、 Replace random seeds to improve the coverage and collection efficiency of unit test cases .
Generate random numbers
Through system functions **std: :randomize()** Randomization can be done for some variables , Or it's called generating random numbers and assigning these variables .
We can also generate by some other system functions related to the generation of random numbers .
$urandom() : Can generate a 32 Unsigned random number of bits .
$urandom_range(maxval, minval=O): Can generate inter and maxval And minval Number between .
constraint
Rather than randomly generating some random numbers , In the face DUT In the process of random excitation , In order to comply with the agreement 、 Meet test requirements , We also need to add some constraints , Limit random numbers to be random when they meet the requirements of design requirements .
Member variables of a class can be declared as " Random " attribute , use rand perhaps randc To express .
Modifier rand and randc
about rand Modifier , Indicates that within the generatible range , The probability of each value is the same .
about randc Modifier , Its value will be random and traverse its range .
randc bit [1:0] y ;

A random variable
An integer in any class (bit/byte/int) Variables can be declared as rand/randc.
Fixed length array 、 The dynamic array 、 Associative arrays and queues can be declared rand/randc, You can restrict the length of dynamic arrays and queues .
rand bit [7:0] len;
rand integer data[];
constraint db{ data.size == len;}
Handle member pointing to the object , It can also be declared as rand, But it cannot be declared randc, When random, the handle points to the random variable in the object — And was randomly .
A non composite structure can be declared as rand, Non composite members can be declared as rand/randc.
Constraint block
Useful incentives are not just random values , There is also a correlation between variables . Random variables without constraints will contain many invalid and illegal values , This will make the generation of effective incentives inefficient . You need to define these relationships with constraint blocks that contain one or more constraint expressions .
Member collection
Constraint blocks support shaping through set Operator to set their value ranges .
rand integer x,y, z;
constraint c1 {x inside {3,5,[9:15],[24:32],[y:2*y],z};}
rand integer a, b, c ;
constraint c2 { a inside {b, c};}
integer fives[4]= '{ 5,10,15,20 };
rand integer v;
constraint c3 { v inside { fives };}
Weight distribution
In addition to member set settings , Constraint blocks can also be set with values and random weights .
about := The operator , It means that the weight of each value is the same .
x stay 100 ,101,102,200 and 300 The weight of is 1 - 1 - 1 - 2 - 5.
x dist {[100:102]:= 1,200 := 2,300 :=5}
about :/ The operator , It means that the weight will be equally distributed to each value .
x stay 100,101,102 ,200 and 300 The weight of is 1/3 -1/3 - 1/3 - 2 - 5.
x dist {[100:102]:/ 1,200 := 2,300 :=5}
Unique identification
unique Can be used to constrain a set of variables , So that it will not have the same value between random post variables .
a[2],a[3],b and excluded Different values will be included after randomization .
rand byte a [5];
rand byte b;
rand byte excluded;
constraint u { unique {b, a [2: 3], excluded} ; }
constraint exclusion { excluded == 5; }
Conditionality
have access to if-else perhaps -> Operator to represent a conditional constraint
mode == little -> len < 10;
mode == big -> len > 100 ;
bit [3:0]a, b;
constraint c {(a == 0) -> (b == 1); }
Iterative constraints
foreach It can be used to iterate the elements in the constraint array , These arrays can be fixed length arrays 、 The dynamic array 、 Associative arrays or queues .
class C;
rand byte A[];
constraint c1 { foreach (A[i]) A[i] inside
{2,4,8,16} ; }
constraint c2 { foreach (A[j]) A[j] > 2 * j; )
endclass
You can also use the reduction method of the array to make iterative constraints .
class c;
rand bit [7:0]A[];
constraint c1 { A.size() == 5; }
constraint c2 { A.sum()< 1000; }
endclass
Function call
Sometimes constraints cannot be expressed simply in some expressions , For example, to calculate the value of... In a merged array 1 :
function int count_ones ( bit [9:0] w ) ;
for ( count_ones = 0 ; w != 0; w = w >>1 )
count_ones += w & 1'b1;
endfunction
This function can be called in the constraint block to describe the constraint :
constraint c1 { length == count_ones ( v ) ; }
Soft constraint
In the absence of soft Constraints when describing , This is called a hard constraint , With soft It describes soft constraints . Soft constraints are used to specify the default values and weights of variables . If the user is using , Specify external constraints to make secondary constraints on the same variable , Or the user defines subclasses , When you also make a quadratic constraint on the same variable , Then hard constraints can " Cover ” Soft constraint , It should not lead to the failure of random number generation .
Random method
A random variable declared in a class , You need to call the method with the class handle randomize(), This is a SV Class :
virtual function int randomize () ;
If the randomization is successful, it will return 1, If it fails, it returns 0.
Embedded constraint
· When calling class methods randomize() Time can be accompanied by with To add additional constraints .
class simplesum ;
rand bit [7:0]x,y,Z;
constraint c { z== x+y; }
endclass
task InlineConstraintDemo ( SimpleSum p) ;
int success;
success = p.randomize
endtask
local Domain points to
Previously, when using inline constraint randomization , Variables with the same name are in different fields , There may be ambiguity in the direction . Can pass local: To specify the direction of random variables , namely local:: The variable pointed to will contain randomize() In the object of the method .
stochastic control
rand_mode It can be used to enable or disable random variables . When random numbers are forbidden , It will be a common variable declared as a random variable — sample , Will not participate in the randomization process .
You can see from the following two function declarations , You can call its... On a single random variable rand_mode, Or call... On the entire object rand_mode To control all the random variables .
task object [ .random_variable] :: rand _mode ( bit on_off ) ;
function int object.randon_variable ::rand_mode ( ) ;
Constraint control
Similar to stochastic control , Some constraint blocks or a set of constraint blocks of a class can be controlled individually or collectively .
task object [.constraint_identifier] : :constraint_mode(bit on_off );
function int object.constraint_identifier::constraint_mode() ;
Some constraint blocks can be enabled or disabled by constraint control functions .
Embedded variable control
Using the randomization function of the class randomize() when , If accompanied by parameters , Then only these variables will be randomized , The rest of the variables are declared as rand/randc, Will not participate in randomization .
Thread control
Parallel thread
.Verilog Medium and sequential threads begin…end The opposite is parallel threads fork…join.SV Two new methods for creating threads are introduced ,fork…join_none and fork…join_any.

fork…join All parallel threads need to end before execution can continue .
fork…join_any It will wait until any thread ends and continue to execute .
fork…join_none Will not wait for its child threads to continue execution .
It should be noted that ,fork…join_any and fork…join_none continue ) Hideous letter , Its — Some unfinished subroutines will still run after . If you want to wait for these subroutines to complete , Or stop these subroutines , have access to wait fork perhaps disable fork.
Timing control
SV The process block can be controlled by delay control or event waiting . Delay control is through # To complete .
#10 rega = regb;
event (event) Control is passed @ To complete .
@r rega = regb;
@(posedge clock) rega = regb;
wait Statements can also be combined with events or expressions to complete .
real AOR[];
initial wait(AOR.size( ) > o) ....;
reference
- Verification of West circuit department PPT
边栏推荐
- Diffusion (multi-source search)
- Preliminary level of C language -- selected good questions on niuke.com
- Primary application case of Excel DuPont analyzer
- Fixed height of the first column in El table dynamic header rendering
- ONEFLOW source code parsing: automatic inference of operator signature
- 1034 Head of a Gang
- Tidb single machine simulation deployment production environment cluster (closed pit practice, personal test is effective)
- highmap gejson数据格式转换脚本
- 【ManageEngine卓豪 】助力世界顶尖音乐学院--茱莉亚学院,提升终端安全
- OpenGL es: (5) basic concepts of OpenGL, the process of OpenGL es generating pictures on the screen, and OpenGL pipeline
猜你喜欢

QT write custom control - self drawn battery

C language beginner level - realize the minesweeping game

【ITSM】什么是ITSM,IT部门为什么需要ITSM

【自动化运维】自动化运维平台有什么用

让田头村变甜头村的特色农产品是仙景芋还是白菜

jdbc 数据库操作

记磁盘扇区损坏导致的Mysql故障排查

El tooltip in the table realizes line breaking display

excel初级应用案例——杜邦分析仪

Pla ne colle pas sur le lit: 6 solutions simples
随机推荐
2022 年面向初学者的 10 大免费 3D 建模软件
kubeadm搭建kubenetes 集群(个人学习版)
Preliminary level of C language -- selected good questions on niuke.com
Talking from mlperf: how to lead the next wave of AI accelerator
Flink实战--多流合并
excel動態圖錶
OpenGL es: (2) relationship between OpenGL es, EGL and glsl
SystemVerilog学习-08-随机约束和线程控制
3D printer threading: five simple solutions
Ant new village is one of the special agricultural products that make Tiantou village in Guankou Town, Xiamen become Tiantou village
three.js小结
FPGA - 7系列 FPGA内部结构之Clocking -01- 时钟架构概述
C language beginner level - realize the minesweeping game
srpingboot security demo
让厦门灌口镇田头村变“甜头”村的特色农产品之一是
Smartinstantiationawarebeanpostprocessor of the extension point series determines which construction method to execute - Chapter 432
浅谈SIEM
[file system] how to run squashfs on UBI
Top 10 Free 3D modeling software for beginners in 2022
机械臂速成小指南(六):步进电机驱动器