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 Iterative constraints

Iterative constraints allow arrayed variables to be constrained in a parameterized manner using loop variables and indexing expressions.

   

space.gif

The foreach construct specifies iteration over the elements of an array. Its argument is an identifier that designates any type of array (fixed-size, dynamic, associative, or queue) followed by a list of loop variables enclosed in square brackets. Each loop variable corresponds to one of the dimensions of the array.

   

space.gif

   

space.gif

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

space.gif


  1 program iterative_con;
  2   class frame_t;
  3     rand bit [15:0] data [];
  4   
  5     constraint frame_sizes {
  6       data.size inside {[1:10]};
  7       foreach (data[i])
  8         data[i] == i;
  9     }
 10     function void post_randomize();
 11       begin
 12         $display("length   : %0d", data.size());
 13         for (integer i = 0; i < data.size(); i++) begin
 14          $write ("%2x ",data[i]);
 15         end
 16         $write("\n");
 17       end
 18     endfunction
 19   endclass
 20 
 21   initial begin
 22      frame_t frame = new();
 23      integer i,j = 0;
 24      for (j=0;j < 4; j++) begin
 25        $write("-------------------------------\n");
 26        $write("Randomize Value\n");
 27        i = frame.randomize();
 28      end
 29      $write("-------------------------------\n");
 30   end
 31 
 32 endprogram
You could download file iterative_con.sv here
   

space.gif

  ../images/main/bullet_star_pink.gif Simulation : Iterative
   

space.gif

 -------------------------------
 Randomize Value
 length   : 4
 00 01 02 03 
 -------------------------------
 Randomize Value
 length   : 2
 00 01 
 -------------------------------
 Randomize Value
 length   : 8
 00 01 02 03 04 05 06 07 
 -------------------------------
 Randomize Value
 length   : 9
 00 01 02 03 04 05 06 07 08 
 -------------------------------
   

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