|
|
|
|
|
|
|
|
|
|
|
|
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. |
|
|
|
|
|
- Constraints
- Weighted Randomization
- Seed Management
|
|
|
|
|
|
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<8> can be generated using the following code:\ |
|
|
|
|
|
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
|
|
|
|
|
|
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 |
|
|
|
|
|
- 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.
|
|
|
|
|
|
Example : Simple Random
|
|
|
|
|
|
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
|
|
|
|
|
|
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
}
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Copyright © 1998-2014 |
Deepak Kumar Tala - All rights reserved |
Do you have any Comment? mail me at:deepak@asic-world.com
|
|