Documente Academic
Documente Profesional
Documente Cultură
Index
System Verilog Data Types
Array Operations
Packed Arrays
Engineering Design Institute
1
1/25/16
SystemVerilog Features
Two state data types Better Performance and reduced memory usage
Unions and packed structures Allows multiple views of the same data
A very powerful language to develop testbenches that can functionally verify complex RTL
Engineering Design Institute Designs 4
2
1/25/16
reg
reg [dimension1:dimension2]variable_name;
Represents data storage element, cannot have multiple drivers, can be synthesized as FF, latches or combinational circuit
reg
reg [dimension1:dimension2]variable_name;
Represents data storage element, cannot have multiple drivers, can be synthesized as FF, latches or combinational circuit
3
1/25/16
0 1 2 3 4 5 6 7
reg
Engineering Design Institute 7
4
1/25/16
wire
wire [dimension1:dimension2]variable_name;
Used to connect different parts of the design and can have multiple drivers
Engineering Design Institute 9
0
1
2
3
4
5
6
7
wire
Engineering Design Institute 10
5
1/25/16
Verilog Code
logic
logic[dimension1:dimension2]variable_name;
SV improves the classic reg data type so that it can be driven by continuous assignments, gates and modules in addition to being a
variable. Cannot be driven by multiple drivers
6
1/25/16
logic
logic [dimension1:dimension2]variable_name;
SV improves the classic reg data type so that it can be driven by continuous assignments, gates and modules in addition to being a
variable. Cannot be driven by multiple drivers and is a 4-state variable (can have the values 0,1,x or z)
0 1 2 3 4 5 6 7
logic
Engineering Design Institute 14
7
1/25/16
SystemVerilog Code
7 6 5 4 3 2 1 0 0 1 2 3 4 5 6 7
8
1/25/16
7 6 5 4 3 2 1 0 0 1 2 3 4 5 6 7
a[0]<=1; a[0]<=1;
a[1]<=1; a[1]<=1;
a[2]<=0; a[2]<=0;
a[3]<=1; a[3]<=1;
a[4]<=0; a[4]<=0;
Initialize the vector a[5]<=0; Initialize the vector a[5]<=0;
a[6]<=1; a[6]<=1;
a[7]<=1; a[7]<=1;
a[8]<=0 a[8]<=0;
7 6 5 4 3 2 1 0 0 1 2 3 4 5 6 7
a[0]<=1; a[0]<=1;
a[1]<=1; a[1]<=1;
a[2]<=0; a[2]<=0;
a[3]<=1; a[3]<=1;
a[4]<=0; a[4]<=0;
initialized a[5]<=0; Initialized a[5]<=0;
a[6]<=1; a[6]<=1;
a[7]<=1; a[7]<=1;
a[8]<=0 a[8]<=0;
7 6 5 4 3 2 1 0 0 1 2 3 4 5 6 7
1 1 0 0 1 0 1 1 1 1 1 1 0 0 0 1
9
1/25/16
byte a
bit[7:0] a
8 bits
User defined
signed
unsigned
byte
bit
value of a value of a
0 to 255 byte a -127 to +127
bit[7:0] a
8 bits
User defined
signed
unsigned
byte
bit
value of a
-(2^32-1) to +(2^32-1) value of a value of a
-(2^16-1) to +(2^16-1) -(2^64-1) to +(2^64-1)
10
1/25/16
$isunknown(variable);
A 2 state datatype can only have the value 0 or 1
11
1/25/16
Arrays
1
type array_name [dimensions]
2
3
Can be of any type A unique name given Defines the size of
logic, bit, int etc. to the array the array 4
4 bits
array1
module init_array()
logic clk=0; 0 8
logic reset=0;
Logic [3:0] array1[0:7]; 1 7
int i;
always #5 clk=~clk; 2 6
initial
begin 3 5
for(i=0;i<8;i=i+1)
begin 4 4
array1[i]<=8-i;
end 5 3
end
endmodule 2
6
7 1
12
1/25/16
$size(array_name);
module init_array() 0 8
logic clk=0;
logic reset=0; 1 7
Logic [3:0] array1[0:7];
int i; 2 6
always #5 clk=~clk;
initial 3 5
begin
for(i=0;i<$size(array1);i=i+1) 4 4
begin
array1[i]<=8-i; 5 3
end
end 2
6
endmodule
7 1
13
1/25/16
Multidimensional Arrays
1
type array_name [dimensions][dimensions]; 2
Can be of any type A unique name given Define the size of the
4
logic, bit, int etc. to the array array
5
0 1 2 3 4 5 6 7
Engineering Design Institute 25
Initializing Arrays
foreach (array[dim1,dim2]);
4 bits array2d
module init_array() 0
logic clk=0;
logic reset=0; 1
logic [3:0] array2d[0:7][0:7];
always #5 clk=~clk; 2
initial
begin 3
foreach(array2d[[i,j])
begin 4
array2d[i,j]<=i+j;
end 5
end
endmodule
6
0 1 2 3 4 5 6 7
Engineering Design Institute 26
14
1/25/16
Initializing Arrays
foreach (array[dim1,dim2]);
4 bits array2d
module init_array() 0 1 2 3 4 5 6 7
0
logic clk=0;
logic reset=0; 1 1 2 3 4 5 6 7 8
logic [3:0] array2d[0:7][0:7];
always #5 clk=~clk; 2 2 3 4 5 6 7 8 9
initial
begin 3 3 4 5 6 7 8 9 10
foreach(array2d[[i,j])
begin 4 4 5 6 7 8 9 10 11
array2d[i,j]<=i+j;
end 5 5 6 7 8 9 10 11 12
end
endmodule 6 7 8 9 10 11 12 13
6
7 7 8 9 10 11 12 13 14
0 1 2 3 4 5 6 7
Engineering Design Institute 27
Array Operations
15
1/25/16
initial begin
bit [31:0] src[5] = {0,1,2,3,4},
dst[5] = {5,4,3,2,1}; 5 0 0
5
0
if(src==dst)
$display(src==dst); 1 1 1
4
else
2 2 2
3
$display(src!=dst);
dst=src; 3 2
3
src[0]=5; 3
if(src[1:4]==dst[1:4]) 4 1
4
4
$display(src==dst);
else
32 bits 32 bits
$display(src!=dst);
end
src dst
initial
begin
bit [31:0] src[5] = {5{5}},
$displayb(src[0],src[2][2:1],src[4][5]);
end
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 1
1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 1
2 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 1
3 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 1
4 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 1
16
1/25/16
initial
begin
bit [31:0] src[5] = {5{5}},
$displayb(src[0],src[2][2:1],src[4][5]);
end
$display(src[2][2:1])
$display(src[0])
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 1
1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 1
2 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 1
3 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 1
4 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 1
$display(src[4][5])
Engineering Design Institute 29
Packed Arrays
17
1/25/16
Packed Arrays
Treated as a both an array and a single value
Easy to slice
Packed bit and word dimensions should be specified Array types dimensions Name of the array
3 2 1 0
7 6 5 4 3 2 1 0 7 6 5 4 3 2 1 0 7 6 5 4 3 2 1 0 7 6 5 4 3 2 1 0
The assignment can be a constant value, a concatenation of constant values or a replication of constant values
3 2 1 0
7 6 5 4 3 2 1 0 7 6 5 4 3 2 1 0 7 6 5 4 3 2 1 0 7 6 5 4 3 2 1 0
a=32h0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
3 2 1 0
7 6 5 4 3 2 1 0 7 6 5 4 3 2 1 0 7 6 5 4 3 2 1 0 7 6 5 4 3 2 1 0
b={16hz,16h0} z z z z z z z z z z z z z z z z 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
3 2 1 0
7 6 5 4 3 2 1 0 7 6 5 4 3 2 1 0 7 6 5 4 3 2 1 0 7 6 5 4 3 2 1 0
c={16{2b01}} 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1
18
1/25/16
bit [3:0][7:0]packed_array;
packed_array=32habcd_efab;
$displayb(packed_array);
3 2 1 0
7 6 5 4 3 2 1 0 7 6 5 4 3 2 1 0 7 6 5 4 3 2 1 0 7 6 5 4 3 2 1 0
packed_array 1 0 1 0 1 0 1 1 1 1 0 0 1 1 0 1 1 1 1 0 1 1 1 1 1 0 1 0 1 0 1 1
bit [3:0][7:0]packed_array;
packed_array=32habcd_efab;
$displayb(packed_array[3]);
3 2 1 0
7 6 5 4 3 2 1 0 7 6 5 4 3 2 1 0 7 6 5 4 3 2 1 0 7 6 5 4 3 2 1 0
packed_array[3] 1 0 1 0 1 0 1 1 1 1 0 0 1 1 0 1 1 1 1 0 1 1 1 1 1 0 1 0 1 0 1 1
19
1/25/16
bit [3:0][7:0]packed_array;
packed_array=32habcd_efab;
$displayb(packed_array[2][5]);
3 2 1 0
7 6 5 4 3 2 1 0 7 6 5 4 3 2 1 0 7 6 5 4 3 2 1 0 7 6 5 4 3 2 1 0
packed_array[2][5] 1 0 1 0 1 0 1 1 1 1 0 0 1 1 0 1 1 1 1 0 1 1 1 1 1 0 1 0 1 0 1 1
39
Engineering Design Institute
3 2 1 0
7 6 5 4 3 2 1 0 7 6 5 4 3 2 1 0 7 6 5 4 3 2 1 0 7 6 5 4 3 2 1 0
20
1/25/16
0 1
3 2 1 0 3 2 1 0
2 1 0 2 1 0 2 1 0 2 1 0 2 1 0 2 1 0 2 1 0 2 1 0
0
1 1
logic [3:0][2:0]mixed_array[0:1][0:2]
Thank You
21