System Verilog For Design
System Verilog For Design
3. Enumerated types.
4. Type casting.
1.3 Summary
SystemVerilog unifies several proven hardware design and verification languages, in the form of
extensions to the Verilog HDL. These extensions provide powerful new capabilities for modeling
hardware at the RTL, system and architectural levels, along with a rich set of features for
verifying model functionality.
1
2.1 Packages
1. SystemVerilog packages are defined between the keywords package and endpackage.
2. The synthesizable constructs that a packages can contain are: parameter, localparameter,
const typedef, automatic task and funtion, other import packages, Operator overload.
3. In Verilog, a parameter constant can be redefined for each instance of a module, whereas
a localparam cannot be directly redefined.
5. Modules and interfaces can reference the definitions and declarations in a package four
ways:
7. For similar reasons, synthesis does not support variables declarations in packages. In
simulation, a package variable will be shared by all modules that import the variable.
2. These external declarations are in a compilation-unit scope, and are visible to all modules
that are compiled at the same time.
3. A declaration in the compilation-unit scope is not the same as a global declaration. A true
global declaration, such as a global variable or function, would be shared by all modules
that make up a design, regardless of whether or not source files are compiled separately
or at the same time.
4. Coding guidelines:
(a) Do not make any declarations in the $unit space! All declarations should be made
in named packages.
(b) When necessary, packages can be imported into $unit. This is useful when a module
or interface contains multiple ports that are of user-defined types, and the type
definitions are in a package.
5. An alternative style is to import a package into the $unit compilation- unit scope, prior
to the module declaration. This makes the user-defined type definitions visible in the
SystemVerilog search order.
6. A package can also be imported into the $unit space using a wildcard import. Keep in
mind that a wildcard import does not actually import all package items. It simply adds
the package to the System- Verilog source path.
2
7. The same care must be observed when importing packages into the $unit space as with
making declarations and definitions in the $unit space. When using $unit, file order
dependencies can be an issue, and multiple $units can be an issue.
8. A solution to both of these problems with importing package items into the $unit compilation-
unit space is to place the import statements in every file, before the module or interface
definition.
9. A common C programming trick can be used to make it possible to import package items
into the $unit space with both single file compilation and multiple file compilation. The
trick is to use conditional compilation to include the import statements the first time the
statements are compiled into $unit, and not include the statements if they are encountered
again in the same compilation.
2.4 Summary
1. This chapter has introduced SystemVerilog packages and the $unit declaration space.
Packages provide a well-defined declaration space where user-defined types, tasks, func-
tions and constants can be defined. The definitions in a package can be imported into
any number of design blocks. Specific package items can be imported, or the package
definitions can be added to a design block’s search path using a wildcard import.
2. The $unit declaration space provides a quasi global declaration space. Any definitions
not contained within a design block, testbench block or package falls into the $unit
compilation-unit space. Care must be taken when using $unit to avoid file order depen-
dencies and differences between separate file compilation and multifile compilation. This
chapter provided coding guidelines for the proper usage of the $unit compilation-unit
space.
3. SystemVerilog also allows local variables to be defined in unnamed begin...end blocks.
This simplifies declaring local variables, and also hides the local variable from outside the
block. Local variables in unnamed blocks are protected from being read or modified from
code that is not part of the block.
3
4. SystemVerilog also enhances how simulation time units and precision are specified. These
enhancements eliminate the file order dependencies of Verilog’s ‘timescale directive.
The enhancement also makes it possible to code models that automatically scale to new vector
sizes without having to modify the logic of the model.
2. Data type indicates the value system of the net or variable, which is 0 or 1 for 2-state
data types, and 0, 1, Z or X for 4-state data types.
4. Semantically, a variable of the logic data type is identical to the Verilog reg type.
6. Synthesis guidelines
4
(a) The 4-state logic type and the 2-state bit, byte, shortint, int, and longint types are
synthesizable. Synthesis compilers treat 2- state and 4-state types the same way.
The use of 2-state types primarily affects simulation.
(b) 2-state types begin simulation with a default value of logic value of 0. Synthesis
ignores this default initial value.
2. SystemVerilog greatly simplifies determining the proper type to use in a model, by relaxing
the rules of where variables can be used.
4. Use variables for single-driver logic, and use nets for multidriver logic.
5. Only nets can have multiple sources, such as multiple continuous assignments and/or
connections to multiple output ports of module or primitive instances.
2. SystemVerilog adds a static keyword, and allows any variable to be explicitly declared as
either static or automatic.
5
3. a new system function, $cast, that performs dynamic, runtime checking on the value to
be cast.
4. The static, compile-time cast operator is synthesizable. The dynamic $cast system func-
tion might not be supported by synthesis compilers.
3.7 Constants
1. parameter is a constant for which the value can be redefined during elaboration using
defparam or in-line parameter redefinition.
2. specparam is a constant that can be redefined at elaboration time from SDF files.
3.8 Summary
1. This chapter introduced and discussed the powerful compilationunit declaration scope.
The proper use of compilation-unit scope declarations can make it easier to model func-
tionality in a more concise manner. A primary usage of compilation-unit scope declara-
tions is to define new types using typedef.
2. SystemVerilog enhances the ability to specify logic values, making it easier to assign values
that easily scale to any vector size. Enhancements to the ‘define text substitution provide
new capabilities to macros within Verilog models and testbenches.
3. SystemVerilog also adds a number of new 2-state variables to the Verilog language: bit,
byte, shortint, int, and longint. These variable types enable modeling designs at a higher
level of abstraction, using 2-state values. The semantic rules for 2-state values are well
defined, so that all software tools will interpret and execute Verilog models using 2-state
logic in the same way. A new const can be used in automatic tasks and functions
shortreal type and a logic type are also added. The initialization of variables is enhanced,
so as to reduce ambiguities that exist in the Verilog standard. This also helps ensure
that all types of software tools will interpret SystemVerilog models in the same way.
SystemVerilog also enhances the ability to declare variables that are static or automatic
(dynamic) in various levels of design hierarchy. These enhancements include the ability
to declare constants in begin...end blocks and in automatic tasks and functions.
4. The next chapter continues the topic on SystemVerilog types, covering user-defined types
and enumerated types.