quick.gif

space2.gif

space2.gif

space2.gif

space2.gif

space2.gif

space2.gif

space2.gif

   

space.gif

   

space.gif

  ../images/main/bullet_green_ball.gif Randomization

SCV provided very powerfull mechanism for doing randomization. Using the data introspection facility discussed previously, constrained randomization can be performed on arbitrary data types. We will be discussion following features of randomization offered by SystemC Verification Extension standard.

   

space.gif

  • Constraints
  • Weighted Randomization
  • Seed Management
   

space.gif

SCV provided scv_random class, as a replacement for rand() and srand() from the standard C library. The scv_random class uses an object-oriented paradigm to enable reproducibility in many use models. An instantiation of the scv_random class gives the user an independent stream of random unsigned integer values. It can take an explicit seed from the user, or extract a seed from the seed associated with the current process thread. By default, it uses the same algorithm as jrand48() from the standard C library, but it can be configured to use rand() or a user-specified algorithm.

   

space.gif

   

space.gif

  ../images/main/bulllet_4dots_orange.gif Basic Randomization

Data objects of arbitrary data types can be randomized through the use of scv_smart_ptr. For example, a random value for an sc_uint<8> can be generated using the following code:\

   

space.gif


  1 #include <scv.h>
  2 
  3 int sc_main (int argc, char* argv[]) {
  4   scv_smart_ptr< sc_uint<8> > data;
  5   cout <<"Value of data pre  randomize : " << endl;
  6   data->print();
  7   data->next(); // Randomize object data
  8   cout <<"Value of data post randomize : " << endl;
  9   data->print();
 10   return 0;
 11 }
You could download file scv_random_basic.cpp here
   

space.gif

By default, scv_smart_ptr instantiates an internal scv_random object to perform randomization. The same scv_random object can also be shared among smart pointers by calling the method set_random().

   

space.gif

Randomization can be disabled as in Vera language. SCV provides following methods

   

space.gif

  • Randomization can be turned on and off using the methods enable_randomization() and
  • disable_randomization(). The default is on.
  • The method reset_distribution() can be used to remove the existing distribution from a data object. If the mode before this call is DISTRIBUTION, it is changed to RANDOM.
   

space.gif

  ../images/main/bullet_star_pink.gif Example : Simple Random
   

space.gif


  1 #include <scv.h>
  2 
  3 #define RND_SEED 1
  4 
  5 class packet_t {
  6   public : 
  7     sc_uint<8>  addr;
  8     sc_uint<12> data;
  9     unsigned payload[2];
 10 };
 11 
 12 SCV_EXTENSIONS(packet_t) {
 13   public:
 14     scv_extensions< sc_uint<8> > addr;
 15     scv_extensions< sc_uint<12> > data;
 16     scv_extensions< unsigned [2] > payload;
 17     SCV_EXTENSIONS_CTOR(packet_t) {
 18       SCV_FIELD(addr);
 19       SCV_FIELD(data);
 20       SCV_FIELD(payload);
 21     }
 22 };
 23 
 24 int sc_main (int argc, char* argv[]) {
 25   scv_smart_ptr<packet_t> pkt_p("packet");
 26   scv_shared_ptr<scv_random> rand_p(new scv_random("gen", RND_SEED));
 27   pkt_p->set_random(rand_p);
 28   cout << "Packet Pre  Random: " << endl;
 29   pkt_p->print();
 30   // Disable randomization on addr field
 31   pkt_p->addr.disable_randomization();
 32   pkt_p->addr.write(100);
 33   //  Randomize whole packet
 34   pkt_p->next();
 35   cout << "Packet Post Random: " << endl;
 36   pkt_p->print();
 37   //  Randomize just one field
 38   pkt_p->payload.next();
 39   pkt_p->data.next();
 40   cout << "Packet Post Random: " << endl;
 41   pkt_p->print();
 42 
 43   return 0;
 44 }
You could download file scv_random.cpp here
   

space.gif

  ../images/main/bullet_star_pink.gif Simulation Output : Simple Random
   

space.gif

 Packet Pre  Random: 
 {
   addr:0
   data:0
   payload {
     [0]:0
     [1]:0
   }
 }
 Packet Post Random: 
 {
   addr:100
   data:1645
   payload {
     [0]:828284566
     [1]:2560170243
   }
 }
 Packet Post Random: 
 {
   addr:100
   data:2401
   payload {
     [0]:978506453
     [1]:78009065
   }
 }
   

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