quick.gif

space2.gif

space2.gif

space2.gif

space2.gif

space2.gif

space2.gif

space2.gif

   

space.gif

   

space.gif

  ../images/main/bullet_green_ball.gif Constraint Blocks

In last few pages we saw how to contraint a random variable to legal range that we want to generate. In next few pages we will see.

   

space.gif

  • inclusive and exclusive (set membership)
  • distribution
  • conditional constraint
  • foreach
   

space.gif

And also some advanced constraint topics.

   

space.gif

   

space.gif

  ../images/main/bulllet_4dots_orange.gif Set Membership

Sometimes we want to randomize a variable within a set of values (inclusive) or sometimes we want to exclude some values from random values generated (exclusive).

   

space.gif

  • [] is used for specifying range.
  • The negated form of the inside operator denotes that expression lies outside the set: !(expression inside { set }).
  • Absent any other constraints, all values (either single values or value ranges) have an equal probability of being chosen by the inside operator.
   

space.gif

  ../images/main/bullet_star_pink.gif Example : Set Membership
   

space.gif


  1 program set_membership;
  2   class frame_t;
  3     rand bit [7:0] src_port;
  4     rand bit [7:0] des_port;
  5     constraint c {
  6        // inclusive
  7        src_port inside { [8'h0:8'hA],8'h14,8'h18 };
  8        // exclusive
  9         ! (des_port inside { [8'h4:8'hFF] });
 10     }
 11     function void post_randomize();
 12       begin
 13         $display("src port : %0x",src_port);
 14         $display("des port : %0x",des_port);
 15       end
 16     endfunction
 17   endclass
 18 
 19   initial begin
 20     frame_t frame = new();
 21     integer i,j = 0;
 22     for (j=0;j < 4; j++) begin
 23       $display("-------------------------------");
 24       $display("Randomize Value");
 25       $display("-------------------------------");
 26       i = frame.randomize();
 27     end   
 28     $display("-------------------------------");
 29   end
 30 endprogram
You could download file set_membership.sv here
   

space.gif

  ../images/main/bullet_star_pink.gif Simulation Output : Set Membership
   

space.gif

 -------------------------------
 Randomize Value
 -------------------------------
 src port : 3
 des port : 2
 -------------------------------
 Randomize Value
 -------------------------------
 src port : 0
 des port : 2
 -------------------------------
 Randomize Value
 -------------------------------
 src port : 18
 des port : 3
 -------------------------------
 Randomize Value
 -------------------------------
 src port : 2
 des port : 0
 -------------------------------
   

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