[sv-ec] randc vs object stability and randstate

From: Daniel Mlynek <danielm@aldec.com.pl>
Date: Wed Dec 19 2012 - 00:26:49 PST
Object stability described in chapter 18.14.3 defines that 2 calls to 
randomize on different object should be independent.
This perfectly works for rand variables as those need only RNG state to 
compute value.
Randc variables need also its cyclic state. Bcos of that it is not 
simple to have randc variables work as decribed in "object stability" 
chapter.
I see have both technical(vendor implementation) and interpretation 
(LRM) issues with randc and object stability.

See below example:

    class CC;
       randc reg[7:0]rc; //if here we use rand instead randc then object
    stability works ok
    endclass
    class C;
       rand CC cc;
       function new;
         cc=new;
       endfunction
    endclass
    module top;
       C c = new;
       initial begin
         $display("%s\n%s", c.get_randstate,c.cc.get_randstate);
         //according to object stability calls to c and c.cc randomize
    should be independent so commenting below randomize
         // should not change results of 2nd randomize
         c.cc.randomize;
         $display(c.cc.rc);
         $display("%s\n%s", c.get_randstate,c.cc.get_randstate);
         c.randomize;
         $display("this value should not change if 1st randomize is
    commented out\n\t>>> %d <<<< ",c.cc.rc);
         $display("%s\n%s", c.get_randstate,c.cc.get_randstate);
       end
    endmodule

The issue here is caused by that cyclic state is recorded together with 
randc variable in CC class object. It cannot be saved in parent C class 
object as cc can point to different class object bcos of inheritance or 
can point to null
I think that LRM should explicitly state that randc can break object 
stability.

2nd issue is that LRM doesn't explicitly say that  cyclic variable state 
can be read/modify by get/set_randstate  but I assume that it should. It 
works ok until we have case with has-a relation like in above code.
Doing c.get_randstate , some randomize calls on c and then 
c.set_randstate on C class object will not cause that c.cc.rc will be 
randomizing same values as for saved state. Cyclic variable state must 
be stored in CC object randstate as I stated before and this is why 
doing get/set_randstate on C will not affect randc in CC.
Calling c.randomize will cause c.cc randstate will change if there is 
randc inside c.cc (if we change randc to rand then only c randstate will 
be changed after randomization

Sumarizing - LRM do not describe how to deal with object stability and 
randstate when we are using class with randc members as member of other 
class. IMHO it need to be cleared in LRM


DANiel

-- 
This message has been scanned for viruses and
dangerous content by MailScanner, and is
believed to be clean.
Received on Wed Dec 19 00:27:22 2012

This archive was generated by hypermail 2.1.8 : Wed Dec 19 2012 - 00:27:37 PST