100%(1)1 out of 1 people found this document helpful
This preview shows page 79 - 81 out of 455 pages.
When reading and writing associative arrays, the simulator must search for the ele-ment in memory. The LRM does not specify how this is done, but popular ways arehash tables and trees. These require more computation than other arrays, and there-fore associative arrays are the slowest. 2.8.4 SortingSince SystemVerilog can sort any single-dimension array (fixed-size, dynamic, andassociative arrays plus queues), you should pick based on how often the values areadded to the array. If the values are received all at once, choose a fixed-size ordynamic array so that you only have to allocate the array once. If the data slowly drib-bles in, choose a queue, as adding new elements to the head or tail is very efficient.If you have unique and noncontiguous values, such as Õ{1, 10, 11, 50}, you canstore them in an associative array by using them as an index. Using the routinesfirst,next, and prev, you can search an associative array for a value and find suc-cessive values. Lists are doubly linked, and so you can find values both larger andsmaller than the current value. Both of these support removing a value. However, theassociative array is much faster in accessing any given element, given an index. For example, you can use an associative array of bits to hold expected 32-bit values.When the value is created, write to that location. When you need to see if a given
Chapter 2:Data Types48value has been written, use the existsfunction. When done with an element, usedeleteto remove it from the associative array.2.8.5 Choosing the Best Data StructureHere are some suggestions on choosing a data structure.zNetwork packets. Properties: fixed size, accessed sequentially. Use a fixed-size or dynamic array for fixed- or variable-size packets.zScoreboard of expected values. Properties: size not known until run-time,accessed by value, and a constantly changing size. In general, use a queue, asyou are continually adding and deleting elements during simulation. If youcan give every transaction a fixed id, such as 1, 2, 3, …, you could use this asan index into the queue. If your transaction is filled with random values, youcan just push them into a queue and search for unique values. If the score-board may have hundreds of elements, and you are often inserting and delet-ing them from the middle, an associative array may be faster.zSorted structures. Use a queue if the data comes out in a predictable order,or an associative array if the order is unspecified. If the scoreboard neverneeds to be searched, just store the expected values in a mailbox, as shownin Section 7.6.zModeling very large memories, greater than a million entries. If you do notneed every location, use an associative array as a sparse memory. If you doneed every location, try a different approach where you do not need so muchlive data. Still stuck? Be sure to use 2-state values packed into 32-bits.