Could you please someone help me in coding a scoreboard storage structure using associative arrays. The output transaction are coming out of order. Is there also a better way to implement the data checks?
scoreboard data check use of associative arrays as storage structure
801 views Asked by Rahul AtThere are 4 answers
Thanks. That's what I was looking for. I tried to implement keyed list this way:
extend sys {
!a : list (key:it) of uint(bits:4);
run() is also {
var b : uint = 0;
for i from 0 to 10 {
a.add(b);
b = b+2;
};
if a.key_exists(4) {
print a;
print a.key(4);
print a.key_index(4);
print a.key_index(7);
};
};
};
The output I get is:
a = (11 items, dec): 4 2 0 14 12 10 8 6 4 2 0 .0
a.key(4) = 4
a.key_index(4) = 2
a.key_index(7) = -1
Clearly, the item at key 4 is 8 not 4. Do I understand wrong?
Rahul,
The results you get seem to be accurate. the list is a[0] = 0, a[1] = 2, a[2] = 4, ...
a.key(4) returns the item that its key is "4" (the item is "4", of course...)
a.key_index(4) returns the index of the item that its value is 4 - 2 (a[2] == 4)
a.key_index(7) returns the index of the item that its value is 7. since there is no item that its key is 7, the result is UNDEF
I recommend checking out the uvm_scoreboard. It's an open source in specman/uvm/uvm_lib. It also uses key list.
Please do not confuse between the key and the index. In a keyed list in e, each entry has both.
When you declare a keyed list with (key: it)
, it means that each entry's key is its own value. So, a.key(4) = 4
, and so on.
On the other hand, you are right that the entry at index 4 is 8. It means that a[4] = 8
or a.key_index(8) = 4
.
In other words, each entry in a keyed list still has an index just like in a regular (non-keyed) list. But the index and they key are completely unrelated. When you add a new entry to the list (using add()
), it gets added to the next index (just like with non-keyed lists), and it also get the relevant key.
e
doesn't have associative arrays in the traditional sense. What it does have, however, are keyed lists. Here's an example:First we need to define how an entry in the keyed list looks like. We model this as a struct that contains the key and the value pair. Also note, there's nothing stopping us from having multiple value fields indexed by the same key.
We define a keyed list of this type using the
key
field as the key. This means that the elements can be indexed by position (the order in which they are added to the list), but also by key.Have a look at the keyed-list chapter in the documentation for more info.