0% found this document useful (0 votes)
127 views5 pages

Cheatsheets - AMIQ Consulting - SV

The document describes various data types and constraints that can be used in verification including: 1. Integer data types like bit, byte, shortint, int, longint, logic and reg for representing signed and unsigned values. 2. Enumerated types for declaring a set of named values using the enum keyword. 3. Structures for declaring user-defined packed or unpacked structures with named fields of different types that can be accessed by name or index. 4. Methods like first(), last(), and next() for operating on enumerated types. 5. Defaults for data types and enumerated values if not specified.

Uploaded by

nazim
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
127 views5 pages

Cheatsheets - AMIQ Consulting - SV

The document describes various data types and constraints that can be used in verification including: 1. Integer data types like bit, byte, shortint, int, longint, logic and reg for representing signed and unsigned values. 2. Enumerated types for declaring a set of named values using the enum keyword. 3. Structures for declaring user-defined packed or unpacked structures with named fields of different types that can be accessed by name or index. 4. Methods like first(), last(), and next() for operating on enumerated types. 5. Defaults for data types and enumerated values if not specified.

Uploaded by

nazim
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

Constraint Type Description Type Description

Functional Coverage real 64 bit, single-precision, floating-point number Unpacked Syntax:


(default)  
realtime 64 bit, single-precision, floating-point number
Assertions
struct

SVA Syntax  
   type1 field_name1;

Enum data types


   type2 field_name2;

Sequences
   ....

Properties Declares a user-defined enumerated type having a set of explicitly named values. Syntax:
} <struct_name>;

System functions enum data_type {item[0], item[1], ...} enum_type_name;

Access to a certain field: <struct_name>.<field_name>

Design and Verification Blocks  


Packed Syntax:
Defaults Description  

Data Types data_type If not specified data type defaults to int. struct packed

  {

 
   type1 field_name1;

Example:
Integer data types
   ....

bit[1:0], int, byte etc }<struct_name>;

Type Description
Members of a packed structure can be accessed either by their name, or by
bit 2-state data type, user-defined vector size representing unsigned data item[0] value If not specified the first item in an enumerated list will be represented as 0 indexing a vector. By default the first field will be the leftmost item in the vector:

byte 8 bit 2-state integer representing signed data or ASCII character item[n] value If not specified the n-th item in an enumerated list will be represented as item[n-1] Example:
+1
shortint 16 bit 2-state integer representing signed data struct packed

int 32 bit 2-state integer representing signed data      bit id;

   int addr;

longint 64 bit 2-state integer representing signed data Method Description    bit[7:0] data;

logic 4-state data type, user-defined vector size, unsigned data first() Returns the first value of an enumeration }my_struct;

reg 4-state data type, user-defined vector size, unsigned data last() Returns the last value of an enumeration In this case my_struct[0] is my_struct.data[0]

wire Used to connect different elements in a design. They can be read or assigned, but next(N) Return the N-th next value, wrapping to the beginning if needed. Default N = 1.
no values can be stored in them.
prev(N) Return the N-th previous value, wrapping to the end if needed. Default N = 1.
integer 32 bit 4-state integer representing signed data
num() Returns the number of values in the enum
time 64 bit 4-state integer representing signed data
 
 
  Dynamic array
Struct data types
Real data types  

Type Description A dynamic array is an unpacked array whose size can be set or changed at runtime. Syntax:
Type Description
type array_name[];

shortreal 32 bit, single-precision, floating-point number

array_name = new[expression1](expression2);

expression2 is an optional initialization of the array Method Description If the assignment is invalid, a task will generate a runtime error, while the function will return 0.

Method Description insert(i,d) Inserts item d at index i typedef enum(idle,busy,pause,done) state;

state current_state;

new[expression] Constructor that sets the size of the dynamic array and initializes its elements delete(i) Deletes item at index i, if index is omitted, deletes queue

  if(!$cast(current_state,6)

pop_front() Reads and removes the item from the front of the queue    $display(“Error in cast”);

Example:

pop_back() Reads and removes the item from the back of the queue  
int my_array[];

my_array = new[10]; //an array of 10 elements

push_front(d) Adds item d to front of the queue


Classes

push_back(d) Adds item d to back of the queue Class Declaration Syntax:


my_array = new[20]; //doubles the array size, discarding pr
evious values


  class my_class;

my_array = new[20](my_array); //doubles the array size, preserving pr    constructor

evious values
Casting    local/static/protected items

   Methods/method prototypes

endclass
 
size() Returns the current size or 0 if the array is not created or if it was deleted.

Example:
 
Static Cast Class Instance Syntax:

In a static cast, if the expression is assignment compatible with the casting type, then the cast shall return my_class obj; // declare an object of class my_class

int array_size;
the value of a variable of the casting type. Syntax:


Obj = new();  // initialize variable to a new allocated object of class my_class

array_size = my_array.size();

casting_type‘(expression)
 
Example 1:
delete() Empties the array, resulting in a zero-sized array Relevant keywords
 
shortint a;

Example: int b;
Keyword Description
b = int’(a);

my_array.delete();
static A static class field shares its value with all instances of the class

Example 2: A static method can only access static properties, but it can be called even when
no class instances exist by using class name and the scope resolution operator.

logic[7:0] register;

Example:
Queue data type register = signed’(4’b1100) // register = -4
 

Syntax: class my_class;

Example 3:
   static int number_of_instances = 0;

shortint a;

   function new();

<type> my_queue[$:max_size]; //where max_size is optional


int b;

      ++number_of_instances;

b = a; // implicit cast

   endfunction

Example:

     static function int get_count()

      return number_of_instances;

Dynamic Cast
int q_int[$];


   endfunction

my_class my_q[$:5]; // accepts maximum 6 elements

Used to assign values to variables that might not ordinarily be valid because of differing data types. Syntax: endclass

instances_count = my_class::get_count();

Method Description function int $cast(destination, source)

size() Returns current size of the queue task $cast(destination, source)

Keyword Description  
Keyword Description

this The this keyword gives unambiguous access to members of the current class Encapsulation extends It is used to create a new class that inherits the members of a base class.
instance  
  Keyword Description
class base_calculator;

Example: local Used to specify that class members are only visible within the class where they    int result;

were declared.    function void sum(int a, int b)

class  my_class;
        result = a + b;

   int x;

   endfunction


endclass

class my_class;

   function new(int x);

   //constructor;

      this.x = x; class smart_calculator extends base_calculator;

   local int private;

   endfunction
   function void mul(int a, int b)

   function void set_private(int x);


      result = a * b;

      private = x;

endclass
   endfunction

   endfunction

endclass
endclass

super The super keyword gives unambiguous access to members of the parent class of my_class  instance = new();

the calling object. initial begin

     instance.private = 1; // ERROR
 
   instance.set_private(1); // OK

Example:
   ...
Polymorphism
end
class parent;

Keyword Description
   //constructor

   string name = “parent”;

protected Used to specify that class members are only visible within the class where they virtual Virtual (class method) is used to define basic polymorphic constructs. A virtual
endclass

were declared and any subclasses. method is used to override a method in all of its base classes.
class child extends parent;
   
   //constructor

   string name = “child”;  //override


class my_class;

   function void get_parent_name();


   //constructor;
      return super.name;
   protected int private;

   endfunction
endclass

endclass


class my_extended_class extends my_class

child c = new();
   //constructor;

   function void set_private(int x);

initial begin
      private = x;

   $display(c.name);            // child


   endfunction

   $display(c.get_parent_name); // parent
endclass

   ...

end
my_extended_class  instance = new();

initial begin

   instance.private = 1;      // ERROR

virtual A virtual class is an abstract class which can only be inherited, but not instantiated.    instance.set_private(1);   // OK

   ...

const Class properties can be made read-only by using a const declaration. end
 

Example:
 
class my_class;

   const int id;


Inheritance
endclass
Keyword Description

 
Keyword Description class my_class;

   int x,y;

class base_class;
Interface class    function new();

   int A = 1;
      // simple constructor

   int B = 2;
The interface class is a class that can be viewed as having a common set of behaviours. An interface class
   endfunction

   function void printA();


shall contain only pure virtual methods, type declarations and parameter declaration, all other blocks and    function new(my_class obj);

      $display(“A from base: %d”, A)


declarations shall not be allowed.       this.x = obj.x;

   endfunction
      this.y = obj.y;

   virtual function void printB();


Syntax:    endfunction

      $display(“B from base: %d”, B)


endclass
   endfunction
interface class class_name [extends interface_class_type]

endclass
   // pure virtual methods
 

   // parameters

Operators
class extended_class extends base_class;
   // type declarations

   int A = 3;
endclass
   int B = 4;

   function void printA();


Symbol Description
A class may implement one or more interface classes.

      $display(“A from extended: %d”, A)

Example:
   endfunction
= Binary assignment operator
   virtual function void printB();

interface class set_data#(type SET_TYPE = logic)


+=  -= /=  *= Binary arithmetic assignment operator
      $display(“B from extended: %d”, B)

   endfunction
   pure virtual function void set(SET_TYPE a);

endclass
%= Binary arithmetic modulus assignment operator
endclass

interface class get_data#(type GET_TYPE = logic)


&=     |= ^= Binary bitwise assignment operator
base_class base = new();

extended_class child = new();


   pure virtual function void get();

endclass
>>=    <<= Binary logical shift assignment operator
initial begin

   base.printA;  // A from base 1

   base.printB;  // B from base 2


class my_queue#(type T =logic, DEPTH = 1);
>>>=      <<<= Binary arithmetic shift assignment operator
   T q[$:DEPTH - 1]

   base = child;

   base.printA;  // A from base 1


   virtual void function delete_queue();
+  - *   / ** Binary arithmetic operators
      q.delete();

   base.printB;  // B from extended 4

   child.printA;  // A from extended 3


   endfunction
% Binary arithmetic modulus operators
enclass

   child.printB;  // B from extended 4


&    | ^ Binary bitwise operators
end
class fifo (type T = logic, DEPTH = 1)

   extends my_queue#(T, DEPTH)


>>     << Binary shift operators
   implements set_data#(T), get_data#(T);

     virtual function void set(T a);


! Unary logical negation operator
      q.push_back(a);

Parameterized classes    endfunction

   virtual function void get();

~   & ~&
Unary logical reduction operator
  | ~|  
Class implementation can be customized by using class parameters. Example:       q.pop_front();
 
   endfunction
Example:
endclass ^  ~^
class vector#(int size  = 1)
&y will return the result of an AND operation between all the bits of y
   bit [size -1 : 0] a;

endclass
 

&&      || Binary logical operations
class stack#(type T  = int)
Copy-Constructor <  > <=  >= Binary relational operation
   local T items[];

   ...
The copy constructor is a constructor which creates an object by initializing it with an object of the same
endclass ==     != Binary logical equality operators
class, which has been created previously. Example:

     ===
Binary case equality operators.
Instantiation:
!==  

vector#(10) a = new();
Unlike logical equality operator, this operators can identify x and z.
stack#(real) b = new();
Symbol Description Verification Features Function Description

++       -- Unary increment/decrement operation   randomize(class Built-in method used to randomize all properties declared with rand and randc.
method) The properties that are not declared rand or randc can still be randomized if they
  Randomizations are passed as arguments.
 

Package Declaration Description


Cannot be overridden!

rand Used in class declaration to specify that a class property is a random variable with
package my_pacakge;
class my_class;

an uniform distribution
   //classes
   rand int random_value1, random_value2;

     int value;

   //variables

   //functions
enclass

rand int variable_name; my_class rand_obj;

   //structs

   //etc..

endpackage obj.randomize(); // will randomize rand_value1 and rand_value2

randc Used in class declaration to specify that a class property is a random variable with obj.randomize(value) // will randomize value as declared as a rand pr
an cyclic distribution operty
Wildcard import - Imports all symbols within the package
 

import my_package::*;
randc bit [1:0] x; pre_randomize() Built-in method that is called by the randomize() method before the objects are
randomized.
Explicit import - Imports only the mentioned symbol from the package
X can take on values in rage of 0 to 3. Randomize will compute an initial random  
permutation of the range values and return them in order on successive calls.
import my_package::my_symbol; class my_class

Initial permutation 0,2,1,3 rand bit[27:0] data;

  next permutation 2,3,0,1 bit[3:0] crc;

constraint data_constraint{ data <= 32000}

Processes The values will be generated in the following order  0,2,1,3,2,3,0,1. function void pre_randomization()

   //disable constraint before randomization

Parallel processes:    data_constraint.constraint_mode(0);

  endfunction

  endclass
Function Description
fork

   begin
std::randomize() It is a built-in function used to randomize local variables or class properties post_randomize() Built-in method that is called by the randomize() method after the objects are
      //Task 1
  randomized.
   end
 
   begin
rand int random_value;

      //Task 2
if(randomize(random_value))
class my_class;

   end
   $display(“Successful randomization”); rand bit[27:0] data;

   begin
bit[3:0] crc;

      //Task n
function void post_randomization()

The randomize function will return 1 if the randomization was successful or 0


   end
   crc = compute_crc(data);

otherwise.
join_keyword endfunction

endclass
join_keyword Description

join The fork completes when all tasks complete


 

Constraint
join_any The fork completes when the first task is completed

join_none The fork completes immediately


Used in class-based randomization, restricting values to specific ranges.

   

Syntax: Constraint item Description Keyword Description

constraint name_c {<constraint_item>;}


foreach Used to specify constraints over the elements of an array dist Used to define weighted distributions
class my_class;

   
   rand int random_value;

   constraint random_value_c{
Syntax:
class my_class;

      random_value >= 0;

rand int my_array[100];

      random_value <= 15;


variable_name dist {<range> <operator> <weight>};
constraint my_constraint

   }

endclass The operator is one of the following


   foreach(my_array[i])

   my_array[i] < 100;

:= attributes the range a specific weight


Constraint item Description }

:/ equally divides the specified weight to all members of the range


endclass
solve..before... Defines the order of generation for multiple values Example:
 
soft Designates a constraint that is to be satisfied unless contradicted by another class my_class;

Syntax: constraint with an higher priority.    rand int random_value;

     constraint random_value_c{

solve rand_variable1 before rand_variable2       random_value  dist {

class my_class;
      0:=20,

Example without solve...before...: rand int my_int;


      [1:10] :/ 80};

constraint my_constraint
   }

class  latch;
{
endclass
   rand bit set,reset;
   soft my_int < 100;

   constraint random_value_c{
}

      set == 1 -> reset == 0;


endclass
with Used to specify in-line constraints for randomization.
   }

 
endclass
my_class  rand_int = new();

// ”->” will be explained in the next section rand_int.randomize() with { my_int >1000; } Syntax:

randomize([properties]) [with {<constraints>};]

In this case we have three possible combinations (set,reset) = {(0,0);(0,1);(1,0)}


each having a 33% chance of occurring.


rand int random_value;

Keyword Description
Example with solve...before...: if(randomize(random_value) with {random_value < 50;})

   $display(“Successful randomization”);
inside Comparison operator which is true if an expression is contained within a specific
class  latch;

list
   rand bit set,reset;

 
   constraint random_value_c{

      set == 1 -> reset == 0;


Operators and Description
class my_class;

      solve set before reset;


methods
   rand int random_value;

   }

   constraint random_value_c{

endclass -> Implication operator used for conditional constraints. It is similar to the if construct.
      random_value  inside {[0:15]};

   }

 
In this case set is solved first, so (set,reset) = (1,0) has a 50% chance of occurring, endclass Syntax:
instead of 33%.

boolean_statement -> constraint_item

Similar to:

if(boolean_statement)

   constraint_item
Identifies a variable that will be tracked for coverage
Operators and Description Type Description
methods  
Set Syntax:
constraint_mode() Used to enable and disable class constraints. Syntax:  
task  
coverpoint variable  [iff (boolead_expresion)]
range_list1 => range_list2

Syntax: 1,2 => 3,4

{ /* bins */ }
// This is equivalent to : (1 => 3), (1 => 4), (2 => 3), (2 => 4)
//[enables|disable] all class constraints

If no bins are defined , the coverpoint creates an automatic bin for every value of the variable.
object.constraint_mode([1|0])

//[enables|disable] a certain constraint

Consecutive Syntax:
objects.constraint_name.constraint_mode([1|0]) covergroup my_cg with function sample(bit[31:0] addr)

coverpoint addr iff(rst_n);


repetitions [*n]  
{

   bins null_addr = {0};


transition_item[*repeat_range]

constraint_mode() Returns the current status of a constraint


   bins valid_addr = {[2:20]};
1[*3] is equivalent to 1 => 1 => 1
function  
}

Syntax: endgroup
Range of Syntax:
objects.constraint_name.constraint_mode()   repetitions [*n:m]  

  transition_item[* low_limit:high_limit]

  Cross Example:

Functional Coverage Correlates bins from two or more coverpoints so that an inter-variable value relationship can be explored.
1[*2:3] is equivalent to (1 => 1), (1 => 1 => 1)
 
 
Syntax: Goto repetition[- Syntax:
 
>n]  
Covergroups cross expression1 , expression2, … expression n [iff (boolean expression)];


transfer_item[->repeat_range]
Defines probes that sample relevant information from functional coverage and defines how coverage // or

results will be reported.

Examples:
cross expression1 , expression2, … expression n [iff (boolean expression)]

  { /* user defined cross coverage bins; */ }

1[->3] is equivalent to …=>1 … =>1 …=>1


covergroup name_cg <coverage event>


covergroup my_cg with function sample(bit signal1,bit signal2)

   coverpoint signal1;
Where … is any transition that does not contain the value 1
   //coverpoints

   //cross
   coverpoint signal2;

endgroup    cross signal1, signal2;


0 => 1[->3] => 0 // is equivalent to 0=>…=>1 … =>1 …=>1=>0
endgroup
Notice that the last transition happens immediately after the second 1 to 1
<coverage event> could be:
  transition.
@(block_event) example: @(posedge clk)
with function sample([port_list]) Transitions
Initialization code:  

name_cg = new();
Type Description
name_cg.set_inst_name(“my_name”);
Sequence A transition from valueA to valueB is defined as such:

  valueA => valueB 0 => 1

Coverpoints

Type Description Assertions Sequence Type Description

Nonconsecutive Syntax: Type Description Temporal delay


signal_1 ##[0:2] signal_2
repetition[=n]   ## with range
Immediate Syntax:
 

transfer_item[=repeat_range] assertions  
      delay = 0

Example: [label:]assert (boolean_expresion)

   // pass block

1[->3] is equivalent to …=>1 … =>1 …=>1... else

   //fail block

SIGNAL_ASSERTED_ERR: assert(signal) // pass block omitted

Where … is any transition that does not contain the value 1


           else $error(“Assertion failed”);       delay = 1

0 => 1[->3] => 0 is equivalent to 0=>…=>1 … =>1 …=>1...=>0

Notice that the transition following the nonconsecutive repetition may occur after Concurrent Are SVA directives used to verify that a property holds.

any number of transition as long as the value 1 doesn’t occur again. assertions Syntax:
   

      delay = 2

[label:] assert property (property_name);

 
property my_property;

Bins    @(posedge clk) (rst_n !== x && rst_n != Z)

endproperty

assert property (my_property);


Type of bins Description
Consecutive Where n,m re natural numbers, m>n>=1. The $ sign can be used to represent
bins Allows explicit named coverage bins to be defined and a range of values to be repetition [*m] or infinity

Cover Is SVA directive used to verify that a property occurs during simulation.
range [*n:m]  
tracked for each bins.
Syntax:  
 
 
signal_1[*1:2] ##1 signal_2
bins name = {range};
[label:] cover property (property_name);

property my_property;
 

   @(posedge clk) (rst_n !== x && rst_n != Z)


      The length of signal1 is 1 clock cycle

wildcard bins Allows x,z and ? as wildcard values in bins definition


endproperty

 
cover property (my_property);

wildcard bins name = {‘b11xx};

 
illegal_bins Identifies that a certain range of values are illegal.       The length of signal1 is 2 clock cycle

SVA Syntax
ignore_bins Identifies that a certain range of values are excluded from coverage.
 
default Default bins are used for all values not covered in other bin ranges.

Default bins are not tracked in cross-coverage. Sequences


 
Sequence Type Description
coverpoint addr iff(rst_n);

{
Temporal delay
signal_1 ##1 signal_2
   bins null_addr = {0};
## with integer
   bins valid_addr = {[10:20]};

   bins invalid_addr = default;

}
Sequence Type Description Operator Description  

 
Non-consecutive Example 1: Overlapping Syntax:
repetition [=n],   sequence  
Function Description
[=n:m] implication
signal_1[=2] operator |-> sequence_1 |-> sequence_2 $onehot(signal) Returns true if only one bit of the signal HIGH

This is a shortcut for the following sequence sequence_2 will start in the same clock cycle in which sequence_1 will end $onehot0(signal) Returns true if only one bit of the signal is LOW
Example:
!start[*0:$] ##1 start ##1 !start[*0:$] ##1 start ##1 !start[*0:$] $isunknown(signal) Returns true if at most one bit of the signal is X or Z

signal_1 ##1 signal_2 |-> signal_3 ##1 signal_4


Example 2: $rose(signal) Returns true if the signal has changed value to 1 in the current evaluation cycle

signal_1[=2] ##1 signal_2 $fell(signal) Returns true if the signal has changed value to 0 in the current evaluation cycle

$stable(signal) Returns true if the signal has the same value as it had in the previous evaluation
 

cycle

#past(signal, Returns the value of the signal at a previous evaluation cycle specified through
number_of_cc) the number_of_cc argument

Non-overlapping Syntax:
Goto non- Example 1: sequence    
consecutive   implication
repetition [->n], [- operator |=> sequence_1 |=> sequence_2 Design and Verification Blocks
>n:m] signal_1[->2]
 
sequence_2 will start one clock cycle after sequence_1 has ended

The difference between the two non-consecutive repetition is that the pattern

 
matching is finished after the last active pulse. This is a shortcut for the following
sequence:  

!start[*0:$] ##1 start ##1 !start[*0:$] ##1 start ##1 Block Description

Observe that signal_1 is matched before returning to the LOW state. Module Syntax:
 
Example 2:
Example:
module my_module (input input_signal1,

signal_1[=2] ##1 signal2


                  input input_signal2,

signal_1 ##1 signal_2 |=> signal_3 ##1 signal_4


                  output reg output_signal1);

 
   //module logic
Observation!

endmodule

Seq1 |=> Seq2 is the same as Seq1 |-> ##1 Seq2


 

reg input1, input2;

wire output;

  my_module module_name (.input_signal1(input1),

                       .input_signal2(input2)

  System functions                        .output_signal1(output))

Properties  

 
Operator Description
 

Block Description

Interface Syntax:
 

interface my_interface(port1, port2...)

   //<parameters>
   //<modports>

endinterface

An interface can have different views by defining modports.

interface my_interface(input clk,

                       input rst);

   logic input_signal1, input_signal2, output_signal1;

   modport  transmit (

      input input_signal1, input_signal2,

      output output_signal1);

   modport receive (

      output input_signal1, input_signal2,

      input output_signal1);

endinterface

Module declaration:

module my_module (my_interface.transmit my_name);

Virtual A virtual interface is a variable that represents an interface instance, providing a mechanism
Interface of separating abstract models from the actual RTL implementation.

Syntax:
 

virtual intarface_name virtual_interface_name;

interface my_interface(input logic clk, input logic rst_n)


   logic signal;

endinterface

   

class my_class;

virtual my_interface my_virtual_interface;

   //...

endclass

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy