当前位置:网站首页>[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
randc
Make a statement- Its value depends on the declared valid range Periodically
- The data type can only be
bit
perhapsenum
- 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
constraint
be 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 rightb
The 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
,function
And 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 ,
inside
The 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
! inside
Means not ininside
Within 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
randc
Keyword 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>0
Conditions , 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 x
Don'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 x
This 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
output
perhapsref
Parameters - 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
边栏推荐
- 【经验分享】如何为visio扩展云服务图标
- You Li takes you to talk about C language 6 (common keywords)
- Regular e-commerce problems part1
- numpy中dot函数使用与解析
- [webrtc] M98 screen and window acquisition
- The configuration that needs to be modified when switching between high and low versions of MySQL 5-8 (take aicode as an example here)
- Redis technology leak detection and filling (II) - expired deletion strategy
- 2022 welder (elementary) judgment questions and online simulation examination
- Who has docker to install MySQL locally?
- Linux server development, MySQL cache strategy
猜你喜欢
[webrtc] m98 Screen and Window Collection
Leetcode 90: subset II
有 Docker 谁还在自己本地安装 Mysql ?
Detailed explanation of Kalman filter for motion state estimation
[mathematical notes] radian
解决问题:Unable to connect to Redis
2022 tea master (intermediate) examination questions and mock examination
Linux server development, detailed explanation of redis related commands and their principles
Operation suggestions for today's spot Silver
[UTCTF2020]file header
随机推荐
C language queue
[GUET-CTF2019]虚假的压缩包
Problem solving: unable to connect to redis
C语言队列
Rust versus go (which is my preferred language?)
misc ez_usb
buuctf misc USB
pytest+allure+jenkins安装问题:pytest: error: unrecognized arguments: --alluredir
【webrtc】m98 screen和window采集
Pytorch parameter initialization
A bit of knowledge - about Apple Certified MFI
Implementation of replacement function of shell script
Leetcode 43 String multiplication (2022.02.12)
[advanced digital IC Verification] command query method and common command interpretation of VCs tool
[webrtc] M98 screen and window acquisition
SQL优化的魅力!从 30248s 到 0.001s
Mysql高低版本切换需要修改的配置5-8(此处以aicode为例)
Linux server development, MySQL process control statement
pytest+allure+jenkins環境--填坑完畢
Cnopendata geographical distribution data of religious places in China