When reading and writing associative arrays the simulator must search for the

When reading and writing associative arrays the

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 are hash tables and trees. These require more computation than other arrays, and there- fore associative arrays are the slowest. 2.8.4 Sorting Since SystemVerilog can sort any single-dimension array (fixed-size, dynamic, and associative arrays plus queues), you should pick based on how often the values are added to the array. If the values are received all at once, choose a fixed-size or dynamic 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 can store them in an associative array by using them as an index. Using the routines first , 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 and smaller than the current value. Both of these support removing a value. However, the associative 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
Image of page 79
Chapter 2:Data Types 48 value has been written, use the exists function. When done with an element, use delete to remove it from the associative array. 2.8.5 Choosing the Best Data Structure Here are some suggestions on choosing a data structure. z Network packets . Properties: fixed size, accessed sequentially. Use a fixed- size or dynamic array for fixed- or variable-size packets. z Scoreboard of expected values . Properties: size not known until run-time, accessed by value, and a constantly changing size. In general, use a queue, as you are continually adding and deleting elements during simulation. If you can give every transaction a fixed id, such as 1, 2, 3, …, you could use this as an index into the queue. If your transaction is filled with random values, you can 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. z Sorted 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 never needs to be searched, just store the expected values in a mailbox, as shown in Section 7.6. z Modeling very large memories, greater than a million entries . If you do not need every location, use an associative array as a sparse memory. If you do need every location, try a different approach where you do not need so much live data. Still stuck? Be sure to use 2-state values packed into 32-bits.
Image of page 80
Image of page 81

You've reached the end of your free preview.

Want to read all 455 pages?

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture