Tuesday, June 8, 2010

Queue usage in System verilog

I am using a queue and loading/fetching data from it as if it is an array.The following examples shows how i actually did that

Ex:
Code snippet -1:
============
if i code as shown below

int arr_a[$];
arr_a[0] = 1;
arr_a[1] = 11;
//arr_a[2] = 2;
arr_a[3] = 22;

when i tried to print the array elements i am getting the following output
Results:
arr[0] = 1
arr[1] = 11
arr[2] = 0
arr[3] = 0

i reran the same code commenting index 0 element

int arr_a[$];
//arr_a[0] = 1;
arr_a[1] = 11;
arr_a[2] = 2;
arr_a[3] = 22;

Results:
arr[0] = 0
arr[1] = 0
arr[2] = 0
arr[3] = 0

so if any index is missing in assigning the variables all the indices above it fetches 0 when you pop.

explanation for the above behavior i got through a mail from a friend:

I ran a few tests and also looked at the 2009 standard. I believe that this is covered in the standard and is executing exactly as the standard specifies. To some degree, a gotcha is something that is allowed but not expected. In this case, this could be a gotcha, but it is not wrong.

As for "improper usage of SV construct", I suggest that the construct is working as defined. Please check out the paragraphs on reading and writing with invalid indexes at the end of section 7.10.1 in the 2009 standard. The results you got fall directly in line with the "invalid" read index. The simulator I ran my tests on gave me a warning (as the standard requires) when I tried to "skip" an index like you showed in code snippet #1.

I hope this helps.

No comments:

Post a Comment