当前位置:网站首页>[quick start of Digital IC Verification] 17. Basic grammar of SystemVerilog learning 4 (randomization)
[quick start of Digital IC Verification] 17. Basic grammar of SystemVerilog learning 4 (randomization)
2022-07-07 08:01:00 【luoganttcc】
Reading guide : The author has the honor to be a pioneer in the field of electronic information in China “ University of electronic technology ” During postgraduate study , Touch the cutting edge Numbers IC Verification knowledge , I heard something like Huawei Hisilicon 、 Tsinghua purple light 、 MediaTek technology And other top IC related enterprises in the industry , Pairs of numbers IC Verify some knowledge accumulation and learning experience . Want to get started for help IC Verified friends , After one or two thoughts , This column is specially opened , In order to spend the shortest time , Take the least detours , Most learned IC Verify technical knowledge .
List of articles
- One 、 Description of content
- Two 、 Randomized validation strategy
- 2.1、 Why use a randomized validation strategy ( important )
- 2.2、 What are the random contents ( abstract , understand )
- 2.3、SystemVerilog The randomization of
- 2.3.1、rand A random variable
- 2.3.2、randc A random variable
- 2.3.3、 Classes with random variables
- 2.3.4、randomize() function ( Start random variables )
- 2.3.5、 Constraint interpreter
- 2.3.6、constraint Constraint statement block
- 2.3.7、 Randomized constraints : Simple expressions
- 2.3.8、 Randomized constraints : Set the range operator
- 2.3.9、 Randomized constraints : Weight distribution
- 2.3.10、 Randomized constraints : Bidirectional constraint
- 2.3.11、 Randomized constraints : Conditionality
- 2.3.12、 The result possibility of randomized constraints : Unconstrained situation
- 2.3.13、 The result possibility of randomized constraints : There are constraints
- 2.3.14、 Randomized constraints :functions
- 2.3.15、 Randomized constraints : Restraint protection
- 2.3.16、 Enable or disable random variables (`randomize` Large switch of )
- 2.3.17、 Activate or deactivate constraints (`constraint` Large switch of )
- 2.3.18、 Test questions
One 、 Description of content
- Why use a randomized validation strategy
- 1、 There is a lot of room for verification ( Time for space , Time is sacrificed ; Different time covers different space )
- 2、 Boundary conditions are unexpected , Randomization motivates rich , Ensure the completeness of verification
- SystemVerilog Randomization in
- Range 、 The weight
- In the class (
class) Declare random variables in - Set constraints for random variables (
Constraints) - The weight distribution of random variables (
weighted distribution) - Turn off or on randomization and constraints (
rand_mode() and constraint_mode())
Two 、 Randomized validation strategy
2.1、 Why use a randomized validation strategy ( important )
- After the design complexity increases , Direct tests ( Directional test )(directed testcase), There is no way to verify all vectors by exhaustive method
- Directional test cases are used to check the determined design properties , Only used to check for predictable errors
- The directional test method and test time are linear Relationship
- Directional test cases Invisible errors cannot be checked
programme : Randomized test cases with constraints , Excitation randomization of input
The randomized verification strategy can detect unexpected errors and hidden errors in the design
2.2、 What are the random contents ( abstract , understand )
notes : Random content needs to be based on reality DUT Requirements to determine !
RTL Design configuration information
- Different design configurations ( randomization )
- For example, verify a router , Different numbers of input and output ports can be configured
Verify the configuration of the environment
- Configure the whole environment randomly
- Input data quantity
- Enter the data type
- Configure the whole environment randomly
Main input data
- The input data is processed randomization
- In the input data of Within the effective range Randomize
Encapsulated input data
- If the data is encapsulated layer by layer , Different layers of packaging Can be randomized , such as TCP/IP( Network message )
Agreement exceptions , Fault tolerant processing and protocol violations (DFX)
- Verify how the system handles errors
- Expected error type , And introduce the error into the system , Ensure that the system design can correctly handle these errors
- Insert these errors randomly
Time delay ( Clock cycle )
- Randomly insert the time delay according to the Protocol (latency)
- Check the sensitivity of the design to clock cycles
- There is no need to verify the establishment and holding time
2.3、SystemVerilog The randomization of
- randomization Allow users to automatically generate random input incentives , Used to verify functions
- SystemVerilog Allow users Use specific constraints , Keep the number of randomly entered data pages in a valid range
- must stay OOP Specify random constraints in ( In a Class in , Grammatical rules )
2.3.1、rand A random variable
- The value of the random variable is within the specified range Uniform distribution
- If Do not add constraints , The value of a random variable can be Specify any value within the valid range

2.3.2、randc A random variable
- Periodic random variables use keywords
randcMake a statement- Its value depends on the declared valid range Periodically
- The data type can only be
bitperhapsenum - randc The random variable repeats all values in the range , In the process of sequential circulation , The same value will not appear repeatedly ( After a circular introduction , The new cycle starts automatically )


2.3.3、 Classes with random variables
- Bus Class contains two random variables :addr and data
constraintbe known as range1 It specifies addr The numerical range of- Ensure that the constraints do not conflict

2.3.4、randomize() function ( Start random variables )
- call
randomize()Functions can be all random variables in the object assignment- Start random generation :
Handle to class .randomize();, Each call produces a random result
- Start random generation :
- The value of random variable should Compliance constraint
- randomize When the function succeeds, it returns 1, Return... On failure 0
- If the random variable No constraints added , Then its random value can be any value within the effective range

- produce 50 individual addr and data
b.randomize()The call time is rightbThe value of the memory space variable referred to by this handle is randomized
2.3.5、 Constraint interpreter
Analyze the relationship of constraints
The same seed (seed) Generate the same random number ( Pseudorandom )
- Use different seeds , You can generate a different set of random numbers
Different EDA The constraint parser of tool manufacturers is customized
2.3.6、constraint Constraint statement block
- For random variables Value Limit
- You can also be right about The relationship between different variables Constraint
- The constraint statement block is Class members , Be similar to
task,functionAnd variables - Constraint statement block Statement
Identifier of constraint statement: Indicates the name of the constraint statement blockConstraint statement block: Is a list of expression statements , Limit the value range of variables or the relationship between variables

- Above addr It's not a random variable , So the constraint will fail
Q: For large space validation , Even if random verification is adopted , There must be places that cannot be covered , For areas not covered , How to ensure its correctness
- A: Random coverage + Directed use cases . Look at the function coverage to judge whether the random points have been reached , If the function coverage does not reach , Adjust the random range or constraint, If not , Then add directed use cases ! Functional coverage is achieved through feature To decompose .( Random + Functional coverage )
- Functional coverage CDV(coverage driven verification)
2.3.7、 Randomized constraints : Simple expressions
- Constraint variables must have a fixed order (fixed order)
- Only One Relational operator :
<, <=, ==, >=, > - Multiple variables use multiple expressions
- Only One Relational operator :

2.3.8、 Randomized constraints : Set the range operator
- If there are no other constraints ,
insideThe probability that any value within the range of values represented by the operator will be selected is the same - inside The negation operator of the operator is
!, Indicates that the value range is no longer inside Within the range indicated by the operator

! insideMeans not ininsideWithin the scope of
2.3.9、 Randomized constraints : Weight distribution
- Numerical distribution operator :
dist- Add weight to some values ( Purpose )
- attribute 1: Test cases need relevant values
- attribute 2: Specify a certain numerical distribution for the test results
- Two operators :
:=and:/:=: The operator means that the specified value has the same distribution weight:/: The operator means that the specified value divides the weight equally , If the weight is w, The value has n individual , Then the weight of each value isw/n
- The value can be a number , It can also be a numerical range :
[lo:hi] - The weight is not a percentage , It doesn't have to be 100
randcKeyword declared random variables You can't Set weight
- Add weight to some values ( Purpose )


2.3.10、 Randomized constraints : Bidirectional constraint
- Constraint statements are not procedural statements (
procedural) But declarative statements (declarative)- All constraint statements take effect at the same time

2.3.11、 Randomized constraints : Conditionality
- Constraint statements provide two syntaxes for declaring conditional relationships :
->if ... else ...

2.3.12、 The result possibility of randomized constraints : Unconstrained situation
- Possible distribution of values

- Equal probability distribution of each combination
2.3.13、 The result possibility of randomized constraints : There are constraints
Conditional operators :->
->Operators will affect the distribution of values->Operators are bidirectional operators

- y The value of depends on x, When x = 0 when ,y = 0;
- therefore , When x = 0 when ,y It is impossible to take other values , namely x = 0 also y != 0 The odds are 0
-> It is the understanding of bidirectional constraints :
- The newly added constraints will affect the distribution

- When x=0 when ,y=0, But when y=0 when , dissatisfaction
y>0Conditions , therefore x Not for 0,x Only for 1!
Conditional operators :solve … before …
solve ... before ...grammar The valid range of the value will not be changed , But it will change the probability of occurrence of the value

solve y before xDon't write this sentence , Except that it won't appear 3 In this case , rest 5 The probability of this situation is 1/5;- Yes
solve y before xThis sentence , Will give priority to y The combination group that appears , here y Yes 4 Species value , So it can be divided into 4 Group , Two in each group . And the probability of each group is 1/4, If a group of two situations will occur , Then the probability of each case is 1/8, If there is only one case in a group , Then the probability of this case is 1/4!
Iterative constraints :foreach
- about Array Variable , have access to Loop variable Constraint


- Remember the core : From left to right
2.3.14、 Randomized constraints :functions
Functions in constraint statements
- Some attributes cannot be constrained by simple expressions
- For example, use a loop to calculate the sum of values in an array
- If you don't use loops , Then you must expand the loop
- SystemVerilog Expressions in constraint statements can call functions
- Function It cannot contain
outputperhapsrefParameters - function Must be
automatic - Constraint statements in functions You cannot modify other constraint statements
- Must be in Call the function before the constraint is valid Count , And function The return value must be treated as a state variable
- Random variables as parameters of a function must create an implicit variable order or priority
- As in the following code
y, You must create a constraint !
- As in the following code
- Function It cannot contain

2.3.15、 Randomized constraints : Restraint protection
Constraint protection is expressed as prediction , Its function is to create protection constraints
- Restraint protection It is not a logical relationship that the constraint interpreter must satisfy
- Restraint protection can Prevent the constraint interpreter from generating error data
Constraint protection is implemented before constraint resolution , It mainly includes :
- constant
- State variables
- Object handle comparison

2.3.16、 Enable or disable random variables (randomize Large switch of )
- Use
rand_mode()Function can turn off random variables- You can control random variables to start (active) Or shut down (inactive)
- When the random variable is inactive , Indicates that the variable is not declared rand or randc
rand_mode()The function is SV Built in functions , Can't be covered
- You can control random variables to start (active) Or shut down (inactive)

2.3.17、 Activate or deactivate constraints (constraint Large switch of )
- Activate or deactivate constraints
- Inactive constraints cannot be invoked
randomize()Function implementation randomization - All constraint initial states are active
constraint_mode()The function is SV Built in functions , Can't be covered
- Inactive constraints cannot be invoked

- Use format :
Handle . Constraint name .constraint_mode()
2.3.18、 Test questions

- The pointer may be
null, Need to add a judgment protection

边栏推荐
- 【数字IC验证快速入门】15、SystemVerilog学习之基本语法2(操作符、类型转换、循环、Task/Function...内含实践练习)
- [webrtc] m98 Screen and Window Collection
- Live broadcast platform source code, foldable menu bar
- misc ez_ usb
- Few-Shot Learning && Meta Learning:小样本学习原理和Siamese网络结构(一)
- 2022 welder (elementary) judgment questions and online simulation examination
- Installing postgresql11 database under centos7
- [P2P] local packet capturing
- Ansible
- Leetcode 43 String multiplication (2022.02.12)
猜你喜欢
![[SUCTF 2019]Game](/img/9c/362117a4bf3a1435ececa288112dfc.png)
[SUCTF 2019]Game

【经验分享】如何为visio扩展云服务图标

这5个摸鱼神器太火了!程序员:知道了快删!

微信小程序基本组件使用介绍

The configuration that needs to be modified when switching between high and low versions of MySQL 5-8 (take aicode as an example here)

【webrtc】m98 screen和window采集

2022-07-06: will the following go language codes be panic? A: Meeting; B: No. package main import “C“ func main() { var ch chan struct

Common validation comments

Resource create package method

2022 tea master (intermediate) examination questions and mock examination
随机推荐
[Stanford Jiwang cs144 project] lab4: tcpconnection
LeetCode 40:组合总和 II
[matlab] when matrix multiplication in Simulink user-defined function does not work properly, matrix multiplication module in module library can be used instead
解决问题:Unable to connect to Redis
You Li takes you to talk about C language 6 (common keywords)
Operation suggestions for today's spot Silver
[performance pressure test] how to do a good job of performance pressure test?
Common method signatures and meanings of Iterable, collection and list
大视频文件的缓冲播放原理以及实现
Visualization Document Feb 12 16:42
[advanced digital IC Verification] command query method and common command interpretation of VCs tool
SQL优化的魅力!从 30248s 到 0.001s
通信设备商,到底有哪些岗位?
2022焊工(初级)判断题及在线模拟考试
Info | webrtc M97 update
Chip information website Yite Chuangxin
Jenkins remote build project timeout problem
Thinkcmf6.0 installation tutorial
Idea add class annotation template and method template
A bit of knowledge - about Apple Certified MFI