Title:
Clarification of the random stability in object instances
Description:
In section 12.13, it is claimed that each object (class instance) has
an independent RNG. This mechanism could cause a misuse of generating
random objects by user.
It is very commonly seen in may testbenches that a new class instance
is created and used per each test-sequence. In such case, multiple
class instances are created and sent to the testing subsystem. For
example, a class 'packet' can be created and sent to the testing
subsystem as:
// commonly used OOP coding style
packet pkt ;
int i ;
for( i = 0 ; i < 1000 ; i++ ) begin
pkt = new ;
packet_driver.send( pkt ) ;
..
end
This coding style can not be used with randomize() function due to the
random object stability. If the 'packet' class is declared as:
class packet ;
rand int id ;
randc bit [3:0] dest ;
..
endclass ;
And the code above is modified to call 'randomize()' as:
// code uses random class but not in a single random sequence
for( i = 0 ; i < 1000 ; i++ ) begin
pkt = new ;
success = pkt.randomize() ;
packet_driver.send( pkt ) ;
..
end
Because a new RNG is created on each packet instance, and the random
stability among instances, this code won't satisfy the non-repeating
nature of 'dest' variable, and the distribution of 'id' is
questionable. (In a cense that the distribution of 'id' purely relies
on the RNG initialization mechanism, and not utilize the
distribution-safeness of the RNG mechanism itself.)
In order to satisfy the randomness that a user may expect, the code
must be written as:
// the follow coding style is required to get a random sequence
packet pkt, ppp ;
int i, success ;
pkt = new ;
for( i = 0 ; i < 1000 ; i++ ) begin
success = pkt.randmize() ;
ppp = new pkt ; // create a copy for actual testing
packet_driver.send( ppp ) ;
..
end
To avoid the confusion and possible testing error by users, a detailed
explanation like above should be placed in the specifictation.
Also, it is desirable to have a mechanism to declare a random variable
without the instance level stability in the same class. This allows to
write the code in more intuitive way, and avoid many copy-object
operation which is possibly costly. This can be done with a new
property qualifier. For a possible implementation, the example here
uses 'cross' as an additional qualifier.
<BNF>
property_qualifier ::=
[ 'cross' ] 'rand'
|
[ 'cross' ] 'randc'
|
class_item_qualifier
Example:
class packet ;
cross rand int id ; // RNG is per class, not per object
cross randc bit [3:0] dest ; // per class cyclic
..
endclass ;
Note: non-terminal symbol in BNF is encapsulated in ' ' (single quote),
as bold characters can not be used in plain text.
Received on Sun Sep 5 14:25:49 2004
This archive was generated by hypermail 2.1.8 : Sun Sep 05 2004 - 14:26:57 PDT