Verification Using SystemC Part VI

In

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.

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.

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 can be generated using the following code:\

  1 #include

  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 }
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().
Randomization can be disabled as in Vera language. SCV provides following methods

Example : Simple Random

  1 #include

  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 pkt_p("packet");

 26   scv_shared_ptr 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 }
Simulation Output : Simple Random

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

   }

 }

 Bạn Có Đam Mê Với Vi Mạch hay Nhúng      -     Bạn Muốn Trau Dồi Thêm Kĩ Năng

Mong Muốn Có Thêm Cơ Hội Trong Công Việc

Và Trở Thành Một Người Có Giá Trị Hơn

Bạn Chưa Biết Phương Thức Nào Nhanh Chóng Để Đạt Được Chúng

Hãy Để Chúng Tôi Hỗ Trợ Cho Bạn. SEMICON  

Lần cập nhật cuối ( Thứ ba, 29 Tháng 3 2022 00:43 )