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 inclusive and exclusive Constraints

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

Syntax

   

space.gif

expression set_operator {value_range_list};
   

space.gif

Where

   

space.gif

  • expression : Can be any Vera expression that refers to at least one variable declared as rand.
  • set_operator : Can be in or !in. The in operator returns true if the expression is contained in the set; otherwise it returns false. The !in operator returns the negated value of the in operator. For example, x !in { } is the same as ! (x in { }) In the absence of any other constraints, all values (either single values or values within ranges), have an equal probability of being chosen by the in or !in operators.
  • value_range_list : Is a comma-separated list of integers, enumerated types, bit expressions, and ranges. Ranges are defined by specifying a low and high bound, separated by a colon (low_bound : high_bound). Ranges include all of the integer elements between the bounds. The bound to the left of the colon must be less than or equal to the bound to the right, otherwise the range is NULL and contains no values. The bound on the right (high_bound), can be set to $, which represents the largest possible value the expression can take.
   

space.gif

   

space.gif

  ../images/main/bullet_star_pink.gif Example : Inclusive Exclusive
   

space.gif


  1 class frame_t {
  2   rand bit [7:0] src_port;
  3   rand bit [7:0] des_port;
  4   constraint c {
  5      // inclusive
  6      src_port in {
  7        8'h0:8'hA,8'h14,8'h18
  8      };
  9      // exclusive
 10      des_port  ! in {
 11        8'h4:$
 12      };
 13   }
 14 }
 15 
 16 program inclusive_exclusive {
 17    frame_t frame = new();
 18    integer i,j = 0;
 19    for (j=0;j < 4; j++) {
 20      printf("-------------------------------\n");
 21      printf("Randomize Value\n");
 22      i = frame.randomize();
 23      frame.object_print();
 24    }
 25    printf("-------------------------------\n");
 26 }
You could download file inclusive_exclusive.vr here
   

space.gif

  ../images/main/bullet_star_pink.gif Simulation Output : Inclusive Exclusive
   

space.gif

 -------------------------------
 Randomize Value
     src_port            : hex: 03
     des_port            : hex: 02
 -------------------------------
 Randomize Value
     src_port            : hex: 00
     des_port            : hex: 02
 -------------------------------
 Randomize Value
     src_port            : hex: 18
     des_port            : hex: 03
 -------------------------------
 Randomize Value
     src_port            : hex: 02
     des_port            : hex: 00
 -------------------------------
   

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