quick.gif

space2.gif

space2.gif

space2.gif

space2.gif

space2.gif

space2.gif

space2.gif

   

space.gif

   

space.gif

  ../images/main/bulllet_4dots_orange.gif Distributions Constraints

When weight based randomization is required in Systemverilog, we can use Distribution.

   

space.gif

Syntax

   

space.gif

constraint_block ::=
...
| expression dist { dist_list } ;
dist_list ::= dist_item { , dist_item }
dist_item ::= value_range [ dist_weight ]
dist_weight ::=
:= expression
| :/ expression
dist_item ::=
value_range := expression
| value_range :/ expression
expression_or_dist ::= expression [ dist { dist_list } ]
   

space.gif

Where

   

space.gif

  • expression : Can be any Systemverilog expression that refers to at least one variable declared as rand.
  • dist: The dist operator returns true if the expression is contained in the set; otherwise it returns false.
    • := weight : The := operator assigns weight to the item, min, or if there is a range (that is, min:max), to every value in the range (that is, all) elements in the range get the weight. weight may be any Systemverilog expression).
    • :/ weight : The :/ operator divides the value of weight and assigns equally among all elements in the range. If there are n values in the range, the weight of each value is range_weight/n. (weight may be any Systemverilog expression).
   

space.gif

   

space.gif

  ../images/main/bullet_star_pink.gif Example : Distributions
   

space.gif


  1 program distribution;
  2   class frame_t;
  3     rand bit [7:0] src_port;
  4     rand bit [7:0] des_port;
  5     rand bit [15:0] length;
  6     constraint len {
  7       length dist {
  8         [64  :  127 ] := 10,
  9         [128 :  511 ] := 10,
 10         [512 :  2048] := 10
 11       };
 12     }
 13     constraint src {
 14       src_port dist {
 15         0  := 1,
 16         1  := 1,
 17         2  := 5,
 18         4  := 1
 19       };
 20     }
 21     constraint des {
 22       des_port dist {
 23         [0   : 5   ] :/ 5,
 24         [6   : 100 ] := 1,
 25         [101 : 200 ] := 1,
 26         [201 : 255 ] := 1
 27       };
 28     }
 29 
 30     function void post_randomize();
 31       begin
 32         $display("src port : %0x",src_port);
 33         $display("des port : %0x",des_port);
 34         $display("length   : %0x",length);
 35       end
 36     endfunction
 37   endclass
 38 
 39   initial begin
 40     frame_t frame = new();
 41     integer i,j = 0;
 42     for (j=0;j < 4; j++) begin
 43       $display("-------------------------------");
 44       $display("Randomize Value");
 45       $display("-------------------------------");
 46       i = frame.randomize();
 47     end
 48     $display("-------------------------------");
 49   end
 50 
 51 endprogram
You could download file distribution.sv here
   

space.gif

  ../images/main/bullet_star_pink.gif Simulation Output : Distributions
   

space.gif

 -------------------------------
 Randomize Value
 -------------------------------
 src port : 0
 des port : 36
 length   : bd
 -------------------------------
 Randomize Value
 -------------------------------
 src port : 2
 des port : 5e
 length   : 43b
 -------------------------------
 Randomize Value
 -------------------------------
 src port : 2
 des port : 83
 length   : 4fe
 -------------------------------
 Randomize Value
 -------------------------------
 src port : 2
 des port : e4
 length   : 6d9
 -------------------------------
   

space.gif

   

space.gif

   

space.gif

   

space.gif

space2.gif

space2.gif

space2.gif

space2.gif

space2.gif

  

Copyright © 1998-2014

Deepak Kumar Tala - All rights reserved

Do you have any Comment? mail me at:deepak@asic-world.com