Thursday, January 08, 2009     Register | Login | Search | Contact Us
     

Many of you already received communications about the move of the Cadence user community into cadence.com. And many of you have already joined, with over 4000 registrations in the first two weeks.

The new Cadence Community enhances the ability of Cadence users to connect and collaborate. In addition to moving the community into cadence.com -- enabling single sign-on for community, Sourcelink and Cadence events -- the new site is organized around nine technology segments, giving you easy access to product information, training, forums and blogs. Some of the new features include:
  • Ability to respond to posts via e-mail
  • Technology-specific blogs
  • Latest Web 2.0 social networking capabilities
  • Public profile options
  • Private messaging
  • Friends lists
Visit the new Cadence Community today at www.cadence.com/community and join the discussions!

Registration note: Due to the scope of the enhancements and the new SSO registration system, we were not able to migrate existing cdnusers.org member accounts. So new registrations are required, but this enables a broader set of functionality we think you'll enjoy.

Forum note: Under the guidance of forum moderators, we have taken the 20+ cdnusers.org forums and consolidated them into 11 forums on the new site. Posts have been brought over so you can leverage that posting history. CDNusers forums will be set to read only starting 7/30, and cdnusers.org will be redirected to the new community on 8/4.

Best regards,
Mike and Tom

Michael A. Catrambone - Steering Committee Chairman
Distinguished Engineer
PCB/Mechanical
UTStarcom, Inc.

Tom Diederich
Cadence Community Manager
Home
Forums
Subject: Constraining Dynamic array size
Posting to forums is available to community members only.
Login or Register
Rate this topic:
   
Author Messages
sundar_80
Posts: 20
Online: User is Offline
8/07/2007 11:37 PM  
Hello All, I have a query in constraining the size of dynamic array. One way of constraining i have given bellow.

 class dynamic_array;
   rand int array_size;
   rand logicΕ:0] data[]
   constraint arry_constrian{
     data.size() == array_size;
   }
 endclass
In the above code there is a great possibilities that dynamic array might get generate first then array_size, in that case data size will be random. We can use solve before construct, but I am not sure how to use solve before construct for dynamic array. It would be good if i get some comments on the above. Sundar
stephenh
Posts: 77
Online: User is Offline
8/08/2007 3:02 AM  
Hi Sundar.

I think the generator is a bit more intelligent than you give it credit for ;-)
It should be able to understand that the array_size and data.size() are linked, and thus generate them together.

By way of demonstrating this point, I expanded on your example, using an in-line constraint on data.size(). If you run this, you should see that array_size is never greater then 4.

module test;
 class dynamic_array;
   rand int array_size;
   rand byte data [] ;
   constraint array_constriant {
     array_size inside { [ 1:10 ] } ;
     data.size() == array_size;
   }
   function void post_randomize();
     $display("Array_size=%0d", array_size);
   endfunction

 endclass

  dynamic_array c = new();

initial begin
  for (int a=0; a<100; a++)
    void'( c.randomize() with { data.size() < 5; } );
end
endmodule


Steve H.
iman2418
Posts: 3
Online: User is Offline
8/22/2007 12:47 PM  
In SystemVerilog, a dynamic array marked with "rand" and its size are considered as two different random variables. In addition, an implicit ordering exists between generation of the size of a dynamic array and generation of that dynamic array, where the size variable is always generated first. In your examples, random variables "array_size" and "data.size()" are solved first and assigned random variables. Then random array "data" is resized to the value assigned to "data.size()" and then its members are randomized. This approach effectively means that size of array "data" in your example will always be the same as the random value generated for "array_size". Note that this implicit ordering is very important to keep in mind since it can lead to generation problems (i.e. not finding a solution where one exists) if a constraint is given between "array_size" and one of the elements of array "data" (e.g. dataΑ]). See section 12.3 in LRM.
iman2418
Posts: 3
Online: User is Offline
8/22/2007 12:57 PM  
I should also clarify that if the size of a dynamic array is not constrained, then the size of that array remains the same across generation. In this case, only members of the array are randomized. So size of an array is considered as a random variable if and only if a constraint is specified for it. Also, if there is a constraint specified for size of an array, I THINK that the array is resized only if the randomly generated size is bigger than the previous size. For example, if a dynamic array size is 100, and I constrain the size to 50, then the actual array size doesn't change, but randomization only randomizes the first 50 elements. But if I constrain the size to be 200, then the array is resized and the first 200 elements are randomized. Sasan
Posting to forums is available to community members only.
Login or Register

Forums > Functional Verification > SystemVerilog > Constraining Dynamic array size


ActiveForums 3.6
     
Copyright 2006 Cadence Design Systems, Inc.