当前位置:网站首页>[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 .

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
  • 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

 Insert picture description here

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 perhaps enum
    • 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 )

 Insert picture description here

 Insert picture description here

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

 Insert picture description here

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
  • 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

 Insert picture description here

  • produce 50 individual addr and data
  • b.randomize() The call time is right b 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 block
      • Constraint statement block : Is a list of expression statements , Limit the value range of variables or the relationship between variables

 Insert picture description here

  • 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

 Insert picture description here

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

 Insert picture description here

  • ! inside Means not in inside 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 is w/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

 Insert picture description here

 Insert picture description here

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

 Insert picture description here

2.3.11、 Randomized constraints : Conditionality

  • Constraint statements provide two syntaxes for declaring conditional relationships :
    • ->
    • if ... else ...

 Insert picture description here

2.3.12、 The result possibility of randomized constraints : Unconstrained situation

  • Possible distribution of values

 Insert picture description here

  • 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

 Insert picture description here

  • 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

 Insert picture description here

  • 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

 Insert picture description here

 Insert picture description here

  • 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 perhaps ref 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 !

 Insert picture description here

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

 Insert picture description here

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

 Insert picture description here

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

 Insert picture description here

  • Use format : Handle . Constraint name .constraint_mode()

2.3.18、 Test questions

 Insert picture description here

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

原网站

版权声明
本文为[luoganttcc]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/188/202207070443428188.html