Posts

Usage of Soft Constraints in SystemVerilog

 SystemVerilog supports the usage of Soft Constraints to specify a default value e.g      class  base;            rand    bit [3:0]   r;              constraint cb  {  soft r inside  { [0:3] };}          endclass If there is a conflict between multiple soft constraints, who wins ?  e.g     class   base;                   rand bit [3:0]  r;                       constraint   low { soft r == 0; }                       constraint  high  { soft  r > 10; }            endclass ** Here later constraints are higher priority than the earlier, so  r> 10 wins e.g   class  stuff;            rand  base    b_h ;            constraint  higher  { soft  b_h.r == 9; } endclass ** Here, b_h.r == 9  wins over the rest of the above e.g   class  base_extend  extends  base;           constraint hi { soft r == 2; } endclass ** Here, the extend class has higher priority on the variable r

How Disable Constraints in SystemVerilog

 In SystemVerilog Constraints can be enabled/disabled to allow the tests without the constraint using the keyword  "constraint_mode"   e.g           class Transcation;                   rand    logic [15:0] addr;                  constraint align { addr[1:0] == 2'b0;}            endclass module test;        Transcation   t_h  ;    // create a handle        initial  begin           t_h   =  new();   // generate a handle by allocating memory           t_h.align. constraint_mode(0) ;    // disable the constraint by making it "0"           t_h.align. constraint_mode(1) ;    // enable the constraint by making it "1"       end endmodule           

How to define a Cyclic Randomization in SystemVerilog

  How can we generate a non-repeating a random set of values ? SystemVerilog introduces keyword by name "randc" The "randc" modifier creates a cyclic random variable in a class e.g       typedef   enum bit [3:0] { SPADE, CLUB, ....., QUEEN, HEART} cards_t;       class gambler;                       randc  cards_t                    cards ;  // cyclic randomization of cards                       rand     bit [2:0]                   dice   ;  // uniform randomzation of dice                       constraint dice_vals { dice  inside {[1:6]};}        endclass

How to define an implication Constraints in SystemVerilog

 Implication Constraints in SystemVerilog Creates dependency between two expressions. This introduces a concept that if  a is "TRUE" then  b will be "TRUE" e.g typedef   enum   [LONG, SHORT]  packet_size; class  packet;         rand  packet_size       packet_size_t;         rand bit [7:0] addr;         constraint packet_c { (packet_size_t  == LONG  -> (addr == 200);}  endclass    

How do we define Weighted Distribution Constraint in SystemVerilog

 In SystemVerilog how do we define constraint to have values a higher probability than others? For this we use an Weighted Distribution concept using "dist"   syntax For e.g    class Transcation;                  rand bit [1:0]     src_addr, dst_addr;                  constraint  c_distribution  {                              src_addr    dist   { 5 := 2, [7:9] := 3};                              dst_addr  dist     { 5: /2 ,  [7:9] : /3};                    }     endclass The above two expression  '5:=2'  and '5:/2' are equivalent [7:9] := 3 says to make the weight for each value in the range equal to 3 [7:9] :/3  says to divide the weight across each value in the range

How to define Constraint Set Memership in SystemVerilog

  SystemVerilog defines a way to pick inputs randomly from a list of values The   "inside"  operator can hold a list of values, ranges and even arrays For e.g         class choices;                 rand   bit [3:0]   m,p,q,r;                 constraint c_p   { p inside    { 1, [3:6]};          end class

What is Class based Randomization and how do we define ?

In SystemVerilog, we need to specify the keyword "rand" or "randc" to generate class variables randomly. Below, we can see an small example defined class  game;           rand      bit [2:0]  dice;   // using randomization we can have 8-possible values                       bit [9:0]  money;  // This variable is not random            // Apply in-line constraints to generate dice values within a particular range           constraint   dice_values { dice  inside {[1:5]}; }    endclass //*** To generate the above class variables use randomize() method .  module top;          game      game_h;     // class game handle defined          initial begin                   game_h     = new();  // generate the class game by allocating memory                   repeat(50)                           if (! game_h.randomize() )                              $fatal (1, "Game::randomize() failed");                              $display("Rolled a %0d", game_h.dice);