2002 HDLCon Paper SystemVerilog
2002 HDLCon Paper SystemVerilog
Accelleras SystemVerilog
Stuart Sutherland
Sutherland HDL, Inc., Portland, Oregon
[email protected]
Background: Verilog HDL data types can be declared as VAR_TYPE j = 0; /* j is of type shortint
unless redefined */
arrays. The reg and net types can also have a vector width
...
declared. A dimension declared before the object name is endmodule
the vector width dimension. The dimensions declared
after the object name are the array dimensions. module bar;
logic [3:0] i,o;
reg [7:0] r1 [1:256]; //256 8-bit variables
foo #(.VAR_TYPE(int)) u1 (i, o);
SystemVerilog uses different terminology. The term //redefines VAR_TYPE to a type of int
packed array is used to refer to the dimensions declared endmodule
before the object name, instead of vector width. The term
unpacked array is used to refer to the dimensions 14. Module port connections
declared after the object name. Packed arrays can only be Background: Verilog restricts the data types that may be
made of the types: bit, logic, reg, wire, and the other connected to module ports to net types, and the variable
net types. Multiple dimensions can be declared for packed types reg, integer and time.
arrays as well for unpacked arrays.
SystemVerilog removes all restrictions on connections to
bit [7:0] a; //a 1-d packed array
bit b [7:0]; //a 1-d unpacked array
module ports. Any data type can be passed through ports,
bit [0:11] [7:0] c; //a 2-d packed array including reals, arrays and structures.
bit [3:0] [7:0] d [1:10]; /* a 10 element
unpacked array of a packed array, consisting 15. Literal values
of 4 8-bit bytes */
Background: Verilog has several limitations when
Unpacked dimensions are referenced before packed
specifying or assigning literal values.
dimensions. This allows referencing an entire packed array
as a single element. In the last example above, d[1] refers SystemVerilog adds the following enhancements to how
to a single element in the unpacked array. That element is literal values can be specified.
an array of four bytes. All bits of a literal value can be filled with the same value
using 0, 1, z or x. This allows a vector of any size SystemVerilog adds the ability to explicitly specify when
to filled, without having to explicitly specify the vector each branch of decision statements is unique or requires
size of the literal value. priority evaluation. The keywords unique and priority
bit [63:0] data; can be specified before the if or case keyword. These
data = 1; //set all bits of data to 1 keywords can be used to instruct simulators, synthesis
A string literal can be assigned to an array of characters. compilers, and other tools the specific type of hardware
A null termination is added as in C. If the size differs, it is intended. Tools can use this information to check that the
left justified, as in C. if or case statement properly models the desired logic.
char foo [0:12] = hello world\n;
For example, if a decision statement is qualified as unique,
simulators can issue a warning message if an unexpected
Several special string characters have been added:
case value is found.
\v for vertical tab
bit[2:0] a;
\f for form feed
\a for bell unique if ((a==0) || (a==1)) y = in1;
\x02 for a hex number representing an ASCII character else if (a == 2) y = in2;
else if (a == 4) y = in3;
Arrays can be assigned literal values, using a syntax //values 3,5,6,7 will cause a warning
similar to C initializers, except that the replicate operator
is also allowed. The number of nested of braces must priority if (a[2:1]==0) y = in1 //a is 0 or 1
exactly match the number of dimensions (unlike C). else if (a[2] == 0) y = in2; //a is 2 or 3
else y = in3; //a is any other value
int n[1:2][1:3] = { {0,1,2}, {3{4}} };
unique case(a)
16. Type casting 0, 1: y = in1;
2: y = in2;
Background: The Verilog language does not have the 4: y = in3;
ability to cast values to a different data type. endcase //values 3,5,6,7 will cause a warning
SystemVerilog adds the ability to change the type of a
priority casez(a)
value to a using a cast operation, represented by <type>. 2'b00?: y = in1; // a is 0 or 1
The cast can be to any type, including user-defined types. 2'b0??: y = in2; //a is 2 or 3;
int(2.0 * 3.0) //cast result to int default: y = in3; //a is any other value
mytype(foo) //cast foo to the type of mytype endcase