730 likes | 1.6k Views
Speaker: Hsiu-Yi Lin Date: 5/4 2010. The data types in Systemverilog. Outline. Built-In Data Types The Logic type 2-State Data Types Arrays Declaring fixed-size arrays Unpacked array Packed array Dynamic array Queues Associative array Choosing a Storage Type. Built-In Data Types.
E N D
Speaker: Hsiu-Yi Lin Date: 5/4 2010 The data types in Systemverilog
Outline • Built-In Data Types • The Logic type • 2-State Data Types • Arrays • Declaring fixed-size arrays • Unpacked array • Packed array • Dynamic array • Queues • Associative array • Choosing a Storage Type
Built-In Data Types • The Logic type • 2-State Data Types
The Logic type • Verilog always leaves new users confusing because they can’t know the difference of “reg” and “wire”. • SystemVerilog improves the classic reg data type so that it can be driven by continuous assignments, gates, and modules. • A logic signal can be used anywhere a net is uesd.
2-State Data Types • SystemVerilog introduces several 2-state types to improve simulator performance and reduce memory usage. • Original version in Verilog is 4-state types (0,1,Z,X) . • The common 2-state types in SystemVerilog are bit, int and byte…etc.
Arrays • Declaring fixed-size arrays • Unpacked array • Packed array • Dynamic arrays
Declaring fixed-size arrays • Verilog requires that the low and high array limits must be given in the declaration. • SystemVeriolog lets you use the shortcut of just giving the array size, which is similar to C’s style.
Unpacked array • If the array bounds are declared after the variable name, it is called an unpacked array
Packed Array • If the array upper and lower bounds are declared between the variable type and the variable name, the array is called packed. • A SystemVerilog packed array is treated as both an array and a single value.
Dynamic Arrays • If we do not know the size of the array until run-time, we can use dynamic arrays. • SystemVerilog provides a dynamic array that can be allocated and resized during simulation and so our simulation consumes a minimal amount of memory.
Queues • SystemVerilog introduces a new data type, the queue, which combines the best of an linked list and array. • Like an array, we can directly access any element with an index, without linked list’s overhead of stepping through the preceding elements. • The elements of a queue are numbered from 0 to $.
Associative Arrays • If we want to create a big array and processor may only touch a few memory locations, we can use associative arrays. • SystemVerilog offers associative arrays that store entries in a sparse matrix, and allocates memory for an element when we write to it.
Choosing a Storage Type • Flexibility • Memory Usage • Speed • Sorting
Flexibility • Choose a fixed-size array if the array size is known at compile time. • Choose a dynamic array if the array size is known at run-time. • Choose associative arrays for nonstandard indices such as widely separated values because of random values or addresses. • Queues are a good way to store values when the number of elements grows and shrinks a lot during simulation.
Memory Usage • Use 2-state elements to reduce the simulation memory usage. • For arrays with a thousand to a million active elements, fixed-size and dynamic arrays are the most memory efficient. • Modeling memories larger than a few megabytes should be done with an associative array.
Speed • Choose our array type based on how many times it is accessed per clock cycle. • Fixed-size and dynamic arrays are stored in contiguous memory, and so any element can be found in the same amount of time. • Queues own a similar performance to fixed-size and dynamic arrays when reading and writing data, but it will be slow when inserting new elements into a large queue. • Associative arrays are slowest because they require more computation when search for the element in memory.
Choosing the best data structure • Nework packets • Fixed-size, acceseed sequentially. • Use a fixed-size or dynamic array. • Scoreboard of expected values • Size is not known until run-time. • Use a queue. • Use associative arrays when we often insert and delete the elements in large space.
Choosing the best data structure (cont.) • Modeling very large memories • If we don’t need every location, use an associative array. • If we need use every location, try a different approach where we do not need so much live data. • Be sure to use 2-state values.