SV_Arrays_Structures
SV_Arrays_Structures
1
Packed and Unpacked Arrays
2
Unpacked Array to Packed Array
3
Multidimensional Arrays
4
Array Replication
5
Array with default values
6
Array with default values
7
Enumerated Example
1
-1
9
46327
46071**slid e
Enumerated Data type
9
Enumerated Data type
10
Enumerated Data type
11
Enumerated Data type
12
Enumerated Data type
13
Do while Construct
14
Definition of Structures (1)
1
-4
60935
Definition of Structures (2)
Advantages
— Enables a higher level of abstraction
— Easy to interface with other languages
— Can improve simulation performance
Structures Arrays
Can have members of different data Require all elements to be of the
types same type and size
Members are referenced by name Elements of an array are referenced
by index
1
-5
60935
Unpacked and Packed Structures
1
-6
60935
Packed Structures Example
1
-7
60935
60943**slid e
Definition of Unions (1)
A union is an aggregate data type like structure but uses the same memory for
all its members
1
-1
3
60935
Definition of Unions (2)
Unions Structures
Use the same memory for all members Use different memory for each member
More efficient than structures when its Can access more than one member at
members are not required to be the same time, unlike unions
accessed at the same time
1
-1
4
60935
63270**slid e
Dynamic Arrays
1
-3
7
46327
60757**slid e
Dynamic arrays
22
22
Dynamic arrays
logic 1FA1[2];
logic lDA1[];
initial
begin
$display("lDA1 size = %0d",lDA1.size);
lFA1[1]=1;
lFA1[0]=0;
lDA1=lFA1;
$display("lDA1[1] = %0d", lDA1[1]);
$display("lDA1[0] = %0d", lDA1[0]);
$display("lDA1 size = %0d",lDA1.size);
end
endprogram
23
Associative Arrays
24
24
Associative arrays
module m;
bit [2:0] AA1[*];
int int1;
logic [7:0] log1;
initial begin
int1 = 27;
log1 = 42;
AA1[456] = 3'b101;
AA1[int1] = 3'b000; // index is 27
AA1[log1] = 3'b111; // index is 42
end
endmodule
25
Associative Arrays
module asso_test;
bit [31:0]mem[*];
bit [31:0]i;
initial
begin
mem[7]=18;
mem[21]=20;
mem[83]=99;
mem[100]=989;
mem[157]=87;
mem[200]=111;
$display("%0d",mem.num);
$display("%0d",mem[12]);
$display("%0d",mem[200]);
mem.first(i);
$display("first index is %0d",i);
26
Associative Arrays
mem.next(i);
$display("next index of dirst index is %0d",i);
mem.last(i);
$display("Last index is %0d",i);
mem.prev(i);
$display("second last index is %0d",i);
mem.delete(i);
$display("deleted index is %0d",i);
$display("%0d",mem.num);
$display("%p",mem);
27
Associative Arrays
if(mem.exists(i))
$display("element found at %0d",i);
else
$display("element not found");
$display("%p",mem.max);
$display("%p",mem.min);
mem.delete();
$display("%p",mem);
end
endmodule
28
Queues (1)
1
-4
0
46327
46344**slid e
Queues (2)
All elements into a queue are indexed by an integral iterator The first
1
-4
1
46327
88975**slid e
Queues: Predefined Methods
Method Description
insert() Inserts the given item at the specified index position
delete() Deletes the item at the specified index
pop_front() Removes and returns the first element of the queue
pop_back() Removes and returns the last element of the queue
push_front() Inserts the given element at the front of the queue
push_back() Inserts the given element at the end of the queue
size() Returns the number of items in the queue. If the queue is empty, it returns 0
1
-4
3
46327
60759**slid e
Queues Example (1)
1
-4
4
46327
Queues Example (2)
The same results can be obtained via opposite push and pop methods
1
-4
5
46327
46346**slid e
Queue
34
Array Manipulations
module arrays_test;
int q[$]={0,7,9,5,11,11};
int d[]='{0,7,9,5,11,11};
int f[6]='{0,7,9,5,11,11};
initial
begin
$display("%d",q.and);
$display("%d",d.and);
$display("%d",f.and);
$display("%d",q.or);
$display("%d",d.or);
$display("%d",f.or);
$display("%d",q.xor);
$display("%d",d.xor);
$display("%d",f.xor);
35
Array Manipulations
$display("%d",q.sum);
$display("%d",d.sum);
$display("%d",f.sum);
$display("%d",q.product);
$display("%d",d.product);
$display("%d",f.product);
q.sort;
$display("%p",q);
f.sort;
$display("%p",f);
d.sort;
$display("%p",d);
q.rsort;
36
Array Manipulations
$display("%p",q);
f.rsort;
$display("%p",f);
d.rsort;
$display("%p",d);
q.shuffle;
$display("%p",q);
f.shuffle;
$display("%p",f);
d.shuffle;
$display("%p",d);
q.reverse;
$display("%p",q);
f.reverse;
$display("%p",f);
d.reverse;
37
Array Manipulations
$display("%p",d);
$display("%p",q.unique);
$display("%p",f.unique);
$display("%p",d.unique);
$display("%p",q.max);
$display("%p",f.max);
$display("%p",d.max);
$display("%p",q.min);
$display("%p",f.min);
$display("%p",d.min);
end
endmodule
38