ModelSim is produced by Model Technology™, a Mentor Graphics Corporation
company. Copying, duplication, or other reproduction is prohibited without the
written consent of Model Technology.
The information in this manual is subject to change without notice and does not
represent a commitment on the part of Model Technology. The program described
in this manual is furnished under a license agreement and may not be used or
copied except in accordance with the terms of the agreement. The online
documentation provided with this product may be printed by the end-user. The
number of copies that may be printed is limited to the number of licenses
purchased.
ModelSim is a registered trademark and Signal Spy, TraceX, ChaseX and Model
Technology are trademarks of Mentor Graphics Corporation. PostScript is a
registered trademark of Adobe Systems Incorporated. UNIX is a registered
trademark of AT&T in the USA and other countries. FLEXlm is a trademark of
Globetrotter Software, Inc. IBM, AT, and PC are registered trademarks, AIX and
RISC System/6000 are trademarks of International Business Machines
Corporation. Windows, Microsoft, and MS-DOS are registered trademarks of
Microsoft Corporation. OSF/Motif is a trademark of the Open Software Foundation,
Inc. in the USA and other countries. SPARC is a registered trademark and
SPARCstation is a trademark of SPARC International, Inc. Sun Microsystems is a
registered trademark, and Sun
, SunOS and OpenWindows are trademarks of Sun
Microsystems, Inc. All other trademarks and registered trademarks are the
properties of their respective holders.
company. All rights reserved. Confidential. Online documentation may be printed
by licensed customers of Model Technology and Mentor Graphics for internal
business purposes on ly.
ModelSim support
Support for ModelSim is available from your FPGA vendor. See the About
ModelSim dialog box (accessed via the Help menu) for contact information.
What is an "HDL item" . . . . . . . . . . . . . UM-16
This documentation was written for ModelSim version 5.7c for Microsoft Windows 98/
Me/NT/2000/XP. If the ModelSim software you are using is a later release, check the
README file that accompanied the software. Any supplemental information will be there.
UM-13
ModelSim User’s Manual
UM-141 - Introduction
Standards supported
Assumptions
ModelSim VHDL supports both the IEEE 1076-1987 and 1076-1993 VHDL, the
1164-1993 Standard Multivalue Logic System for VHDL Interoperability, and the
1076.2-1996 Standard VHDL Mathematical Packages standards. A ny design developed
with ModelSim will be compatible with any other VHDL system that is compliant with
either IEEE Standard 1076-1987 or 1076-1993.
ModelSim Verilog is based on IEEE Std 1364-1995 and a partial implementation of
1364-2001 Standard Hardware Description Language Based on the Ve rilog Hardware Description Language (see /<install_dir>/modeltech/docs/technotes/vlog_2001.note for
implementation details). The Open Verilog International Veri l og LRM version 2.0 is also
applicable to a large extent. Both PLI (Programming Language Interface) and VCD (V alue
Change Dump) are supported for ModelSim PE and SE users.
In addition, all products support SDF 1.0 through 3.0, VITAL 2.2b, VITAL’95 – IEEE
1076.4-1995, and VITAL 2000 – IEEE 1076.4-2000.
We assume that you are familiar with the use of your operating system. If you are not
familiar with Microsoft Windows, we recommend that you work through the tutorials
provided with MS Windows before using ModelSim.
We also assume that you have a working knowledge of VHDL and Verilog. Although
ModelSim is an excellent tool to use while learning HDL concepts and practices, this
document is not written to support that goal.
Finally, we make the assumption that you have worked the appropriate lesson s in the
ModelSim Tutorial and are therefore familiar with the basic functionality of ModelSim.
The ModelSim Tutorial is available from the ModelSim Help menu.
Sections in this document
In addition to this introduction, you will find the following major sections in this document:
2 - Projects (UM-17)
This chapter discusses ModelSim "projects", a container for design files and their
associated simulation properties.
3 - Design libraries
To simulate an HDL design using ModelSim, you need to know how to create,
compile, maintain, and delete design libraries as described in this chapter.
4 - VHDL simulation
This chapter is an overview of compilation and simulation for VHDL within the
Model
Sim environment.
(UM-37)
(UM-49)
ModelSim User’s Manual
5 - Verilog simulation
This chapter is an overview of compilation and simulation for Verilog within the
Model
Sim environment.
(UM-67)
Sections in this documentUM-15
6 - WLF files (datasets) and virtuals
(UM-117)
This chapter describes datas ets and virtuals - both methods for viewing and organizing
simulation data in Model
7 - Graphic interface
(UM-129)
Sim.
This chapter describes the graphic interface available while operating ModelSim.
Model
Sim’s graphic interface is designed to provide consistency throughout all
operating system environments.
8 - Signal Spy
(UM-269)
This chapter describes Signal Spy, a set of VHDL procedures and Verilog system tasks
that let you monitor, drive, force, or release an item from anywhere in the hierarchy of
a VHDL or mixed design.
9 - Standard Delay Format (SDF) Timing Annotation
(UM-289)
This chapter discusses ModelSim’s implementation of SDF (Standard Delay Format)
timing annotation. Included are sections on VITAL SDF and Verilog SDF, plus
troubleshooting.
10 - Value Change Dump (VCD) Files
(UM-303)
This chapter explains Model Technology’s Verilog VCD implementation for
Model
Sim. The VCD usage is extended to include VHDL designs.
11 - Tcl and macros (DO files)
(UM-315)
This chapter provides an overview of Tcl (tool command language) as used with
Model
Sim.
A - ModelSim variables
(UM-335)
This appendix describes environment, system, and preference variables used in
Model
Sim.
B - ModelSim shortcuts
(UM-355)
This appendix describes ModelSim keyboard and mouse shortcuts.
C - ModelSim messages
(UM-361)
This appendix describes ModelSim error and warning messages.
D - System initialization
(UM-371)
This appendix describes what happens during ModelSim startup.
E - Tips and techniques
(UM-377)
This appendix contains a collection of ModelSim usage examples taken from our
manuals and tech support solutions.
ModelSim User’s Manual
UM-161 - Introduction
What is an "HDL item"
Text conventions
Because ModelSim works with both VHDL and Verilog, “HDL” refers to either VHDL or
Verilog when a specific language reference is not needed. Depending on the context, “HDL
item” can refer to any of the following:
Accessing projects from the command line . . . . . . . . UM-35
This chapter discusses ModelSim projects. Projects simplify the process of compiling and
simulating a design and are a great tool for getting started with ModelSim.
ModelSim User’s Manual
UM-182 - Projects
Introduction
What are projects?
Projects are collection entities for HDL designs under specification or test. At a minimum,
projects have a root directory, a work library, and " metadata" which are stored in a .mpf file
located in a project’s root directory. The metadata include compiler switch settings, compile
order, and file mappings. Projects may also include:
• HDL source files or references to source files
• other files such as READMEs or other project documentation
• local libraries
• references to global libraries
• Simulation Configurations (see "Creating a Simulation Config uration"
• Folders (see "Organizing projects with folders" (UM-32))
Important: Project metadata are updated and stored only for actions taken within the
project itself. For example, if you have a file in a project, and you compile that file from
the command line rather than using the project menu commands, the project will not
update to reflect any new compile settings.
What are the benefits of pr ojects?
Projects offer benefits to both new and advanced users. Projects
• simplify interaction with ModelSim; you don’t need to understand the intricacies of
compiler switches and library mappings
• eliminate the need to remember a conceptual model of the design; the compile order is
maintained for you in the project
• remove the necessity to r e-establish compiler switches and settings at each session; these
are stored in the project metadata as are mappings to HDL source files
• allow users to share libraries without copying files to a local directory; you can establish
references to source files that are stored remotely or locally
• allow you to change individual parameters across multiple files; in previous versions you
could only set parameters one file at a time
(UM-30)
ModelSim User’s Manual
• enable "what-if" analysis; you can copy a project, manipulate the settings, and rerun it to
observe the new results
• reload .ini variable settings every time the project is opened; in previous versions you had
to quit ModelSim and restart the program to read in a new .ini file
How do projects differ from pre-5.5 versions?
Projects have improved a great deal from version s prior to 5.5. Some of the key diff erences
include:
• A new interface eliminates the need to write custom scripts.
• You don’t have to copy files into a specific directory; you can establish references to files
in any location.
• You don’t have to specify compiler switches; the automatic defaults will work for many
designs. However, if you do want to customi ze the settings, you do it through a dialog
box rather than by writing a script.
• All metadata (compiler settings, compile order, file mappings, etc.) are stored in the
project .mpf file.
Note: Due to the significant changes, pro jects created in versions prior to 5.5 cannot be
converted automatically. If you created a project in an earlier version, you will need to
recreate it in versions later than 5.5. With the new interface even the most complex
project should take less than 15 minutes to recreate. Follow the instructions in the
ensuing pages to recreate your project.
Introduction UM-19
Project conversion between versions
Projects are generally not backwards compatible for either number or letter releases. Wh en
you open a project created in an earlier version (e.g, yo u’re using 5.6 and you open a project
created in 5.5), you’ll see a message warning that the project will be converted to the newer
version. You have the option of continuing with the conversion or cancelling the operation.
As stated in the warning message, a backup of the original project is created before the
conversion occurs. The backup file is named <proj ect name>.mpf.bak an d is created in the
same directory in which the original project is located.
ModelSim User’s Manual
UM-202 - Projects
Getting started with projects
This section describes the four basic steps to working with a project.
Step 1 — Creating a new project (UM-20)
This creates a .mpf file and a working library.
Step 2 — Adding items to the project (UM-21)
Projects can reference or include HDL source files, folders for organization, simulations,
and any other files you want to associate with the project. You can copy files into the
project directory or simply create mappings to files in other locations.
Step 3 — Compiling the files (UM-24)
This checks syntax and semantics and creates the pseudo machine code ModelSim us es
for simulation.
Step 4 — Simulating a design (UM-25)
This specifies the design unit you want to simulate and op ens a st ructure tab in the Main
window workspace.
Step 1 — Creating a new project
Select File > New > Project (Main window) to create a new project. This opens the Create
Project dialog.
The dialog includes these options:
• Project Name
The name of the new project.
• Project Location
The directory in which the .mpf file will be created.
• Default L ibrary Name
The name of the working library. See "Design library types"
work libraries. You can generally leave the Default Library Name set to "work." The
(UM-39) for more details on
ModelSim User’s Manual
workspace
Getting started with projectsUM-21
name you specify will be used to create a working library subdirectory within the Project
Location.
After selecting OK, you will see a blank Project tab in the workspace area of the Main
window and the Add Items to the Project dialog.
The name of the current project is shown at the bottom left corner of the Main window.
Step 2 — Adding items to the project
The Add Items to the Project dialog includes these options:
• Create New File
Create a new VHDL, Verilog, Tcl, or text file using the Source window. See below for
details.
• Add Existing File
Add an existing file. See below for details.
• Create Simulation
Create a Simulation Configuration that specifies source files and simulator options. See
"Creating a Simulation Configuration"
• Create New Folder
Create an organization folder. See "Organizing projects with folders"
(UM-30) for details.
(UM-32) for details.
ModelSim User’s Manual
UM-222 - Projects
Create New File
The Create New File command lets you create a new VHDL, Verilog, Tcl, or text file using
the Source window. You can also access this command by s electing File > Add to Project > New File (Main window) or right-clicking
The Create Project File dialog includes these options:
• File Nam e
The name of the new file.
• Add file as type
The type of the new file. Select VHDL, Verilog, TCL, or text.
• Folder
The organization folder in which you want the new file placed. You must first create
folders in order to access them here. See "Organizing projects with folders"
(UM-32) for
details.
When you select OK, the Source window opens with an empty file, and the file is listed in
the Project tab of the Main window workspace.
ModelSim User’s Manual
Getting started with projectsUM-23
Add Existing File
You can also access this command by selecting File > Add to Project > Existing File
(Main window) or by right-clicking
The Add file to Project dialog includes these options:
• File Nam e
The name of the file to add. You can add multiple files at one time.
• Add file as type
The type of the file. "Default" assigns type based on the file extension (e.g., .v is type
Verilog).
• Folder
The organization folder in which you want the file placed. You must first create folders
in order to access them here. See "Organizing projects with folders"
(UM-32) for details.
• Reference from current location/Copy to project directory
Choose whether to reference the file from its current location or to copy it into the project
directory.
When you select OK, the file(s) is listed in the Project tab of the Main window workspace.
ModelSim User’s Manual
UM-242 - Projects
Step 3 — Compiling the files
The question marks next to the files in the Project tab denote either the files haven’t been
compiled into the project or the source has changed since the last compile. To compile the
files, select Compile > Compile All (Main window) or right click in the Project tab and
select Compile > Compile All.
Once compilation is finished, click the Library tab, expand library work by clicking the "+",
and you’ll see the two compiled design units.
ModelSim User’s Manual
Step 4 — Simulating a design
To simulate one of the designs, either double-click the name or right-click the name and
select Simulate. A new tab appears showing the structure of the active simulation.
Getting started with projectsUM-25
At this point you are ready to run the simulation and analyze your results. You often do this
by adding signals to the Wave window and running the simulation for a given period of
time. See the ModelSim Tutorial for examples.
Other basic project operations
Open an existing project
If you previously exited ModelSim with a project open, ModelSim automatically will open
that same project upon startup. You can open a different project by selecting File > Open > Project (Main window).
Close a project
Select File > Close > Project (Main window). This closes the Project tab but leaves the
Library tab open in the workspace. Note that you cannot close a project while a simulation
is in progress.
Delete a project
Select File > Delete > Project (Main window). You cannot delete a project while it is open.
ModelSim User’s Manual
UM-262 - Projects
The Project tab
The Project tab contains information about the items in your project. By default the tab is
divided into five columns.
Sorting the list
Name – The name of a file or object.
Status – Identifies whether a source file has been successfully compiled. Applies only to
VHDL or Verilog files. A question mark means the file hasn’t been compiled or the source
file has changed since the last successful com pile; an X means the compile failed; a check
mark means the compile succeeded.
Type – The file type as determined by registered file types on Windows or the type y ou
specify when you add the file to the project.
Order – The order in which the file will be compiled when you execute a Compile All
command.
Modified – The date and time of the last modification to the file.
You can hide or show columns by right-clicking on a column title and selecting or
deselecting entries.
You can sort the list by any of the five columns. Click on a column heading to sort by that
column; click the heading again to invert the sort order. An arrow in the column heading
indicates which field the list is sorted by and whether the sort order is descending (down
arrow) or ascending (up arrow).
ModelSim User’s Manual
Project tab context menu
Like the other workspace tabs, the Project tab has a context menu that you access by
clicking your right mouse button anywhere in the tab.
The context menu has the following options:
• Edit
Open the selected file in the ModelSim editor.
• Compile > Compile Selected
Compile the selected file(s). Note that if you select a folder and select Compile Selected,
it will compile all files in the folder and any sub-folders.
• Compile > Compile All
Compile all source files included in the project.
• Compile > Compile Out-of-Date
Compile source files that have been modified since the last compile.
• Compile > Compile Order
Set compile order for all files in the project. See "Changing compile order"
more details.
• Compile > Compile Report
Show the compilation history of the selected file.
The Project tabUM-27
(UM-28) for
• Compile > Compile Summary
Show the compilation history of the entire project.
• Compile > Compile Properties
View/change project compiler settings for the selected source file(s).
• Simulate
Load the design unit(s) and associated simulation options from the selected Simulation
Configuration. See "Creating a Simulation Configuration"
(UM-30) for more details.
• Add to Project > New File
Add a new file to the project.
• Add to Project > Existing File
Add an extant file to the project.
• Add to Project > Simulation Configuration
Create a new Simulation Configuration. See "Creating a Simulation Configuration"
for more details.
30)
• Add to Project > Folder
Add an organization folder to the project. See "Organizing projects with folders"
(UM-32)
for more details.
• Remove from Project
Remove the selected item from the project.
• Close Project
Close the active project.
(UM-
• Properties
View/change project compiler settings for the selected source file(s).
ModelSim User’s Manual
UM-282 - Projects
Changing compile order
When you compile all files in a project, ModelSim by default compiles the files in the order
in which they were added to the project. You have two alternatives for changing the default
compile order: 1) select and compile each file individually; 2) specify a custom compile
order.
To specify a custom compile order, follow these steps:
1 Select Compile > Compile Order (Main window) or select it from the context menu in
the Project tab.
2 Drag the files into the correct order or use the up and down ar row buttons. Note that yo u
can select multiple files and drag them simultaneously.
Auto-generating compile order
The Auto Generate button in the Compile Order dialog (see above) "determines" the
correct compile order by making multiple passes over the files. It starts compiling from the
top; if a file fails to compile due to dependencies, it moves that file to the bottom and then
recompiles it after compiling the rest of the files. It continues in this manner until all files
compile successfully or until a file(s) can’t be compiled for reasons other than depen dency.
ModelSim User’s Manual
Grouping files
Changing compile order UM-29
You can group two or more files in the Compile Order dialog so they are sent to the
compiler at the same time. For example, you might have one file with a bunch of Verilog
define statements and a second file that is a Verilog module. You would want to compile
these two files together.
To group files, follow these steps:
1 Select the files you want to group.
2 Click the Group button.
To ungroup files, select the group and click the Ungroup button.
ModelSim User’s Manual
UM-302 - Projects
Creating a Simulation Configuration
A Simulation Configuration associates a design unit(s) and its simulation options. For
example, say you routinely load a particular design and you have to specify the simulator
resolution, generics, and SDF timing files. Or dinarily you wou l d have to specify t hose
options each time you load the design. With a Simulation Configuration, you would specify
the design and those options and then save the configuration with a name (e.g., top_config).
The name is then listed in the Project tab and you can double-click it to load the design
along with its options.
To create a Simulation Configuration, follow these steps:
1 Select File > Add to Project > Simulation Configuration ( Main window) o r select it
from the context menu in the Project tab.
ModelSim User’s Manual
2 Specify a name in the Simulation Configuration Name field.
3 Specify the folder in which you want to place the configuration (see Organi zing projects
with folders
4 Select one or more design unit(s) and click Add.
(UM-32)).
Creating a Simulation Configu rat io nUM-31
Use the other tabs in the dialog to specify any required simulation options. All of the
5
options in t his dialog are described under "Simulating with the graphic interface"
.
245)
Click OK and the simulation configuration is added to the Project tab.
(UM-
Double-click the object to load it.
ModelSim User’s Manual
UM-322 - Projects
Organizing projects with folders
Adding a folder
The more files you add to a project, the harder it can be to locate the item you need. You
can add "folders" to the project to organize your files. These folders are akin to directo ries
in that you can have multiple levels of folders and sub-folders. However, no actual
directories are created via the file system–the folders are present only within the project
file.
To add a folder to your project, select File > Add to Project > Folder.
Specify the Folder Name, the location for the folder, and click OK. The folder will be
displayed in the Project tab.
ModelSim User’s Manual
Organizing projects with foldersUM-33
You use the folders when you add new objects to the project. For example, when you add
a file, you can select which folder to place it in.
If you want to move a file into a folder later on, you can do so using the Properties dialog
for the file (right-click on the file and select Properties from the context menu).
ModelSim User’s Manual
UM-342 - Projects
Setting compiler options
The VHDL and Verilog compilers (vcom and vlog, respectively) have numerous options
that affect how a design is compiled and subsequently simulated. You can customize the
settings on individual files or a group of files.
Important: Any changes you make to the compile properties outside of the project,
whether from the command line, the GUI, or the modelsim.ini file, will not affect the
properties of files already in the project.
To customize specific files, select the file(s) in the Project tab, right click on the file names,
and select Properties. The resulting dialog varies depending on the number and type of
files you have selected. If you select a single VHDL or Verilog file, you’ll see the General
tab and the VHDL or Verilog tab, respectively. On the General tab, you’ll see file properties
such as Type, Location, and Size. If you select multiple files, the file properties on the
General tab are not listed. Finally, if you select both a VHDL file and a Verilog file, you’ll
see all three tabs but no file information on the General tab.
ModelSim User’s Manual
The General tab includes these options:
• Do Not Compile
Determines whether the file is excluded from the compile.
• Compile to library
Specifies to which library you want to compile the file; defaults to the working library.
• Place in Folder
Specifies the folder in which to place the selected file(s). See "Organizing projects with
folders"
• File Properties
A variety of information about the selected file (e.g, type, size, path). Displays only if a
single file is selected in the Project tab.
The definitions of the options on the VHDL and Verilog tabs can be found in the section
"Setting default compile options"
(UM-32) for details on folders.
(UM-240).
Accessing projects from the command lineUM-35
When setting options on a group of files, keep in mind the following:
• If two or more files have different settings for the same option, the checkbox in the dialog
will be "grayed out." If you change the option, you cannot change it back to a "multi- state
setting" without cancelling out of the dialog. Once you click OK, ModelSim will set the
option the same for all selected files.
• If you select a combination of VHDL and Verilog files, the options you set on the VHDL
and Verilog tabs apply only to those file types.
Accessing projects from the command line
Generally, projects are used from within the ModelSim GUI. However, standalone tools
will use the project file if they are invoked in the project's root directory. If you want to
invoke outside the project directory, set the MODELSIM environment variable with the
path to the project file (<Project_Root_Dir>/<Project_Name>.mpf).
You can also use the project command
common operations on new projects. The command is to be used outside of a simulation
session.
VHDL contains libraries, which are objects that contain compiled design units; libraries
are given names so they may be referenced. Verilog designs simulated with in ModelSim
are compiled into libraries as well.
ModelSim User’s Manual
UM-383 - Design libraries
Design library contents
Design unit information
A design library is a directory or archive that serves as a repository for compiled design
units. The design units contained in a design library consist of VHDL entities, packages,
architectures, and configurations; and Verilog modules and UDPs (user-defined
primitives). The design units are classified as follows:
• Primary design units
Consist of entities, package declarations, configuration declarations, modules, and
UDPs. Primary design units within a given library must have unique names.
• Secondary design units
Consist of architecture bodies and package bodies. Secondary design units are associated
with a primary design unit. Architectures by the same name can exist if they are
associated with different entities.
The information stored for each design unit in a design library is:
• retargetable, executable code
Archives
• debugging information
• dependency information
By default design libraries are stored in a director y stru cture with a sub-dir ectory fo r each
design unit in the library. Alternatively, you can configure a design library to use archives.
In this case each design unit is stored in its own archive file. To create an archive, use the
-archive argument to the vlib command
Generally you would do this only in the rare case that you hit the reference count limit on
I-nodes due to the ".." entries in the lower-level directories. An example of an error message
that is produced when this limit is hit is:
mkdir: cannot create directory ‘65534’: Too many links
Archives may also have limited value to customers seeking disk space savings.
Note that GMAKE won’t work with these archives on the IBM platform.
(CR-180).
ModelSim User’s Manual
Design library types
There are two kinds of design libraries: working libr aries and resource lib raries. A working
library is the library into which a design unit is placed after compilation. A resource library
contains design units that can be referenced within the design unit being compiled. Only
one library can be the working library; in contrast, any number of libraries (including the
working li brary itself) ca n be resource libraries during a compilation.
The library named work has special attributes within ModelSim; it is predefined in the
compiler and need not be declared explicitly (i.e. library work). It is also the library name
used by the compiler as the default destination of compiled design units. In other words the
work library is the working library. In all other aspects it is the same as any other library.
Design library typesUM-39
ModelSim User’s Manual
UM-403 - Design libraries
Working with design libraries
Creating a library
The implementation of a design library is not defined within standard VHDL or Verilog.
Within ModelSim design libraries are implemented as directories and can have any legal
name allowed by the operating system, with one exception; extended identifiers are not
supported for library names.
When you create a project (see "Getting started with projects" (UM-20)), ModelSim
automatically creates a working design library. If you don’t create a project, you need to
create a working design library bef ore yo u run the compiler. This can be done from either
the command line or from the ModelSim graphic interface.
From the ModelSim prompt or a DOS prompt, use this vlib command
vlib <directory_pathname>
To create a new library with the ModelSim graphic interface, select File > New > Library
(Main window).
The Create a New Library dialog box includes these options:
(CR-180):
ModelSim User’s Manual
• Create a new library and a logical mapping to it
Type the new library name into the Library Name field. This creates a library subdirectory in your current working directory, initially mapped to itself. Once created, the
mapped library is easily remapped to a different library.
• Create a map to an existing library
Type the new library name into the Library Name field, then type into the Library Maps to field or Browse to select a library name for the mapping.
• Library Name
Type the logical name of the new library into this field.
• Library Physical Name
Type the physical name of the new library into this field. ModelSim will create a
directory with this name.
• Library Maps to
Type or Browse for a mapping for the specified library. This field is visible and can be
changed only when the Create a map to an ex isting library opti on is selected.
When you cli ck OK, ModelSim creates the specified library directory and writes a
specially-formatted file named _info into that directory. The _info file must remain in the
directory to distinguish it as a ModelSim library.
The new map entry is written to the modelsim.ini file in the [Library] section. See
"[Library] library path variable s"
Note: Remember that a design library is a special kind of directory; the only way to
create a library is to use the ModelSim GUI or the vlib command
libraries using DOS or Windows commands.
Managing library contents
Working with design librariesUM-41
(UM-341) for more information.
(CR-180). Do not create
Library contents can be viewed, deleted, recompiled, edited and so on using either the
graphic interface or command line.
The Library tab in the Main window workspace provides access to design units
(configurations, modules, packages, entities, and architectures) in a library. The listing is
organized hierarchically, and the unit types are identified both by icon (entity (E), module
(M), and so forth) and the Type column.
ModelSim User’s Manual
UM-423 - Design libraries
The Library tab has a context menu that you access by clicking your right mo use button in
the Library tab.
The context menu includes the following commands:
• Simulate
Loads the selected design unit and opens structure and Files tabs in the workspace.
Related command line command is vsim
(CR-189).
• Edit
Opens the selected design unit in the Source window, or if a library is selected, opens the
Edit Library Mapping dialog (see "Library mappings with the GUI"
(UM-43)).
• Refresh
Rebuilds the library image of the selected library without using source code. Related
command line command is vcom
(CR-145) or with the -refresh argument.
• Recompile
Recompiles the selected design unit. Related command line command is vcom
(CR-145)
or .
• Update
Updates the display of available libraries and design units.
• Delete
Deletes the selected design unit. Related command line command is vdel
(CR-151).
Deleting a package, configuration, or entity will remove the design unit from the library.
If you delete an entity that has one or more architectures, the entity and all its associated
architectures will be deleted.
You can also delete an architecture without deleting its associated entity. Expand the
entity, right-click the desired architecture name, and select Delete. You are prompted for
confirmation before any design unit is actually deleted.
• New
Create a new library.
ModelSim User’s Manual
• Properties
Displays various properties (e.g., Name, Type, Source, etc.) of the selected design unit
or library.
Assigning a logical name to a design library
VHDL uses logical library names that can be mapped to ModelSim library directories. By
default, ModelSim can find libraries in your current directory (assuming they have the right
name), but for it to find libraries located elsewhere, you need to map a logical library name
to the pathname of the library.
You can use the GUI, a command, or a pro j ect to assign a log ical name to a d esign library.
Library mappings with the GUI
To associate a logical name with a library, select the library in the workspace, right-click
and select Edit from the context menu. This brings up a dialog box that allows you to edit
the mapping.
Working with design librariesUM-43
The dialog box includes these options:
• Library Mapping N ame
The logical name of the library.
• Library Pathname
The pathname to the library.
Library mapping from the command line
You can issue a command to set the mapping between a logical library name and a
directory; its form is:
vmap <logical_name> <directory_pathname>
You may invoke this command from either a DOS prompt or from the command line within
ModelSim.
When you use vmap
(CR-188) this way you are modifying the modelsim.ini file. You can
also modify modelsim.ini manually by adding a mapping li n e. To do this, use a text editor
and add a line under the [Library] section heading using the syntax:
<logical_name> = <directory_pathname>
ModelSim User’s Manual
UM-443 - Design libraries
More than one logical name can b e mapped to a single directo ry. For examp le, suppose th e
modelsim.ini file in the current working directory contains following lines:
[Library]
work = /usr/rick/design
my_asic = /usr/rick/design
This would allow you to use either the logical name work or my_asic in a library or use
clause to refer to the same design library.
Moving a library
The vmap command
(CR-188) can also be used to display the mapping of a logical library
name to a directory. To do this, enter the shortened form of the command:
vmap <logical_name>
Library search rules
The system searches for the mapping of a logical name in the following order:
• First the system looks for a modelsim.ini file.
• If the system doesn’t find a modelsim.ini file, or if the specified logical name does not
exist in the modelsim.ini file, the system searches the current working directory for a
subdirectory that matches the logical name.
An error is generated by the compiler if you specify a logical name that does not resolve to
an existing directory.
Individual design units in a design library cannot be moved. An entire design library can
be moved, however, by using standard operating system commands for moving a directory
or an archive.
ModelSim User’s Manual
Specifying the resource libraries
Verilog resource libraries
ModelSim supports and encourages separate compilation of distinct portions of a Verilog
design. The vlog
specified library. The library thus contains pre-comp iled modules and UDPs that are
referenced by the simulator as it loads the design. See "Library usage"
Important: Resource libraries are specified differently for Verilog and VHDL. For
Verilog you use either the -L or -Lf argument to vlog
VHDL resource libraries
Within a VHDL source file, you use the VHDL library clause to specify logical names of
one or more resource libraries to be r eferenc ed in the subsequent design unit. Th e scope of
a library clause includes the text region that starts immediately after the library clause an d
extends to the end of the declarative region of the a ssociated design unit. It does not extend
to the next design unit in the file.
(CR-181) compiler is used to compile one or more source files into a
Specifying the resource librariesUM-45
(UM-72).
(CR-181).
Note that the library clause is not used to specify the working library into which the design
unit is placed after compilation; the vcom command
to the current working library. By default, this is the library named work. To change the
current working library, you can use vcom-work and specify the name of the desired target
library.
Default binding rules
A common question related to resource libraries is how ModelSim handles default binding
for components. ModelSim addresses default binding at compile time. When look ing f or
an entity to bind with, ModelSim searches the currently visible libraries for an entity with
the same name as the component. ModelSim does this because IEEE 1076-1987 contained
a flaw that made it almost impossible for an entity to be directly visible if it had the same
name as the component. In short, if a componen t was declared in an arch itecture, any likenamed entity above that declaration would be hidden because component/entity names
cannot be overloaded. As a result we implemented the following rules for determining
default binding:
• If a directly visible entity has the same name as the component, use it.
• If the component is declared in a package, search the library that contained the package
for an entity with the same name.
• Search the work library.
• Search all other libraries that are currently visible by means of the library clause.
(CR-145) adds compiled design units
ModelSim User’s Manual
UM-463 - Design libraries
Predefined libraries
In IEEE 1076-1993, the flaw was partially fixed in that the name look-up for the default
entity ignores component declarations. However, you could still encounter problems.
Consider the case where you declare a component C in a package P, library L contains an
entity C, and you have the following lines of code:
library L;
use L.P.all; -- Makes component C visible
use L.all;-- Because L.C exists and entity and component cannot be
overloaded, neither L.C nor L.P.C are directly visible.
In this case you couldn’t have the statement:
U1: C PORT MAP ( p1 => ...);
Instead, you need to have:
U1: P.C PORT MAP ( p1 => ...);
Because the default binding rules in IEEE 1076 contain these flaws, different simulators
implement default binding in different ways.
Certain resource libraries are predefined in standard VHDL. The library named std
contains the packages standard and textio, which should not be modi fied. The contents of
these packages and other aspects o f the p redefined langua ge environmen t are documented
in the IEEE Standard VHDL Language Reference Manua l, Std 1076- 1987 and ANSI /IEEE Std 1076-1993. See also, "Using the TextIO package"
(UM-55).
A VHDL use clause can be specified to select particular declarations in a library or package
that are to be visible within a design unit during compilation. A use clause references the
compiled version of the package—not the source.
By default, every VHDL design unit is assumed to contain the following declarations:
LIBRARY std, work;
USE std.standard.all
To specify that all declarations in a library or pack age can be r eferenced, a dd the suffix .all
to the library/package name. For example, the use clause above specifies that all
declarations in the package standard in the design library named std are to be visible to the
VHDL design file in which the use clause is placed. Other libraries or packages are not
visible unless they are explicitly specified using a library or use clause.
Another predefined library is work, the library where a design unit is stored after it is
compiled as described earlier. There is no limit to the number of libraries that can be
referenced, but only one library is modified during compilation.
Alternate IEEE libraries supplied
The installation directory may contain two or more versions of the IEEE library:
• ieeepure
Contains only IEEE approved std_logic_1164 packages (accelerated for ModelSim).
ModelSim User’s Manual
• ieee
Contains precompiled Synopsys and IEEE arithmetic packages which have been
accelerated by Model Technology including math_complex, math_real, numeric_bit,
numeric_std, std_logic_1164, std_logic_misc, std_logic_textio, std_logic_ ari th,
std_logic_signed, std_logic_unsigned, vital_primiti ves , and vital_timing.
You can select which library to use by changing the mapping in the modelsim.ini file. The
modelsim.ini file in the installation directory defaults to the ieee library.
Regenerating your design libraries
Dependin g on your current ModelSim version, you may need to regenerate your design
libraries before running a simulation. Check the installation README file to see if your
libraries require an update. You can regenerate your design libraries using the Refresh
command from the Library tab context menu (see "Managing library conten ts"
by using the -refresh argument to vcom
From the command line, you would use vcom with the -refresh option to update VHDL
design units in a lib rary , and vlog with the -refresh option to update Verilog design units.
By default, the work library is updated; use -work <library> to update a different library.
For example, if you have a library named mylib that contains both VHDL and Verilog
design units:
An important feature of -refresh is that it rebuilds the library image without using source
code. This means that models delivered as compiled libraries without source code can be
rebuilt for a specific release of ModelSim (4.6 and later only). In general, this works for
moving forwards or backward s on a release. Movin g backwards on a release may not work
if the models used compiler switches or directives (Verilog only) that do not exist in the
older release.
Note: You don't need to regenerate the std, ieee, vital22b, and verilog libraries. Also, you
cannot use the -refresh option to update libraries that were built before the 4.6 release.
ModelSim User’s Manual
UM-483 - Design libraries
Importing FPGA libraries
ModelSim includes an import wizard for referencing and using vendor FPGA libraries. The
wizard scans for and enforces dependencies in the libraries and determines the correct
mappings and target directories.
Important: The FPGA libraries you import must be pre-compiled. Most FPGA vendors
supply pre-compiled libraries configured for use with ModelSim.
To import an FPGA library, select File > Import > Library (Main window).
ModelSim User’s Manual
Follow the instructions in the wizard to complete the import.
This chapter provides an overview of compilation and simulation for VHDL; using the
TextIO package with ModelSim; ModelSim’s implementation of the VITAL (VHDL
Initiative Towards ASIC Libraries) specification for ASIC modeling; and docu mentation
on ModelSim’s special built-in utilities package.
The TextIO package is defined within the VHDL L an gua ge Ref erence Manuals, IEEE St d
1076-1987 and IEEE Std 1076-1993; it allows human-readable text input from a declared
source within a VHDL file during simulation.
ModelSim User’s Manual
UM-504 - VHDL simulation
Compiling VHDL designs
Creating a design library
Before you can compile your design, you must create a library in which to store the
compilation results. Use vlib
vlib work
(CR-180) to create a new library. For example:
This creates a library named work. By default, compilation results are stored in the work
library.
Note: The work library is actually a subdirectory named work. This subdirectory
contains a special file named _info. Do not create libraries using MS Windows or DOS
commands – always use the v lib command
(CR-180).
See "Design libraries"
Invoking the VHDL compiler
ModelSim compiles one or more VHDL design units with a single invocation of vcom (CR-
, the VHDL compiler. The design units are compiled in the order that they appear on
145)
the command line. For VHDL, the order of compilation is important – you must compile
any entities or configurations before an architecture that references them.
You can simulate a design containing units written with both the 1076 -1987 and 1076
-1993 versions of VHDL. To do so you will need to compile units from each VHDL version
separately. The vcom
by default; use the -93 option with vcom
1076 -1993. You can also change the default by modifying the modelsim.ini file (see
"Preference variables located in INI files"
Dependency checking
Dependent design units must be reanalyzed when the design units they depend on are
changed in the library. vcom
have changed. For example, if you keep an entity and its architectures in the same source
file and you modify only an architecture and recompile the source file, the entity
compilation results will remain unchanged and you will not have to recompile design units
that depend on the entity.
(UM-37) for additional information on working with libraries.
(CR-145) command compiles units written with version 1076 -1987
(CR-145) to compile units written with version
(UM-341) for more information).
(CR-145) determines whether or not the compilation results
Range and index checking
ModelSim User’s Manual
A range check verifies that a scalar value defined with a range subtype is always assigned
a value within its range. An index check verifies that whenever an array subscript
expression is evaluated, the subscript will be within the array's range.
Range and index checks are perfor med by default when you compi le your desi gn. You can
disable range checks (potentially offering a performance advantage) and index checks
using arguments to the vcom
(CR-145) command. Or, you can use the NoRangeCheck and
NoIndexCheck variables in the modelsim.ini file to specify whether or not they are
performed. See "Preference variables located in INI files"
(UM-341).
Compiling VHDL designsUM-51
Range checks in ModelSim are slightly more restrictive than those specified by the VHDL
LRM. ModelSim requires any assignment to a signal to also be in range whereas the LRM
requires only that range checks be d one whenever a sig nal is updated. Most assignments to
signals update the signal anyway, and the more restrictive requirement allows ModelSim
to generate better error messages.
ModelSim User’s Manual
UM-524 - VHDL simulation
Simulating VHDL designs
After compiling the design units, you can simulate your designs with vsim (CR-189). This
section discusses simulation from the Windows/DOScommand line. You can also use a
project to simulate (see "Getting started with projects"
(see "Simulating with the graphic interface"
For VHDL invoke vsim
(CR-189) with the name of the configuration, or entity/ architecture
(UM-245)).
(UM-20)) or the Simulate dialog box
pair. Note that if you specify a configuration you may not specify an architecture.
This example invokes vsim
vsim my_asic structure
vsim (CR-189) is capable of annotating a design using VITAL compliant models with timing
data from an SDF file. You can specify the min:typ:max delay by invoking vsim with the
-sdfmin, -sdftyp and -sdfmax options. Using the SDF file f1.sdf in the current work
directory, the following invocation of vsim annotates maximum timing values for the
design unit my_asic:
vsim -sdfmax /my_asic=f1.sdf my_asic
By default, the timing checks within VITAL models are enabled. They can be disabled with
the +notimingchecks option. For example:
vsim +notimingchecks topmod
Simulator resolution limit
The simulator internally represents time as a 64-bit integer in units equivalent to the
smallest unit of simulation time, also known as the simulator resolution limit. The default
resolution limit is set to the value specified by the Resolution
modelsim.ini file. You can view the current resolution by invoking the report command
(CR-109) with the simulator state option .
Overriding the resolution
You can override ModelSim’s default resolution by specifying the -t option on the
command line or by selecting a different Simula tor Resolution in the Simulate dialog box.
Available resolutions are: 1x, 10x or 100x of fs, ps, ns, us, ms, or sec.
(CR-189) on the entity my_asic and the architecture structure:
(UM-347) variable in the
ModelSim User’s Manual
For example this command chooses 10 ps resolution:
vsim -t 10ps topmod
Clearly you need to be careful when doing this type of operation. If the resolution set by -t
is larger than a delay value in your design, the delay values in that design unit are rounded
to the next multiple of the resolution. In the example above, a delay of 4 ps would be
rounded to 0 ps.
Choosing the resolution
You should choose the coarsest resolution limit possible that does not result in undesired
rounding of your delays. The time precision should not be unnecessarily small because it
will limit the maximum simulation time limit, and it will degrade performance in some
cases.
Delta delays
Simulating VHDL designs UM-53
Event-based simulators such as ModelSim may process many events at a given s imulation
time. Multiple signals may need updating, statements that are sensitive to these signa ls
must be executed, and any new events that result from these statements must then be
queued and executed as well. The steps taken to evaluate the design without advancing
simulation time are referred to as "delta times" or just "deltas."
The diagram below represents the process for VHDL designs. This process continues until
the end of simulation time.
Execute
concurrent
statements at
Advance
delta time
current time
Advance
simulation
time
Any transactions
No
to process?
Any events to
Yes
No
process?
Yes
Execute concurrent
statements that are
sensitive to events
This mechanism in event-based simulators may cause unexpected results. Consider the
following code snippet:
.
.
.
clk2 <= clk;
process (rst, clk)
begin
if(rst = ’0’)then
s0 <= ’0’;
elsif(clk’event and clk=’1’) then
s0 <= inp;
end if;
end process;
process (rst, clk2)
begin
if(rst = ’0’)then
ModelSim User’s Manual
UM-544 - VHDL simulation
s1 <= ’0’;
elsif(clk2’event and clk2=’1’) then
s1 <= s0;
end if;
end process;
.
.
.
In this example you have two synchronous processes, one t r ig gered with clk an d the o ther
with clk2. To your surprise, the signals change in the clk2 process on the same edge as they
are set in the clk process. As a result, the value of inp appears at s1 rather than s0. What is
going on?
Here is what’s happing. During simulation an event on clk occurs (from the testbench).
From this event ModelSim performs the "clk2 <= clk" assignment and the process which
is sensitive to clk. Before advancing the simulation time, ModelSim finds that the process
sensitive to clk2 can also be run. Since there are no delays present, the effect is that the
value of inp appears at s1 in the same simulation cycle.
In order to get the expected results, you must do one of the following:
1 insert delay at every output
2 make certain to use the same clock
3 insert a delta delay
To insert a delta delay, you would modify the code like this:
process (rst, clk)
begin
if(rst = ’0’)then
s0 <= ’0’;
elsif(clk’event and clk=’1’) then
s0 <= inp;
s0_delayed <= s0;
end if;
end process;
process (rst, clk2)
begin
if(rst = ’0’)then
s1 <= ’0’;
elsif(clk2’event and clk2=’1’) then
s1 <= s0_delayed;
end if;
end process;
The best way to debug delta delay problems is observe your signals in the List window.
There you can see how values change at each delta time.
ModelSim User’s Manual
Using the TextIO package
To access the routines in TextIO, include the following statement in your VHDL source
code:
USE std.textio.all;
A simple example using the package TextIO is:
USE std.textio.all;
ENTITY simple_textio IS
END;
ARCHITECTURE simple_behavior OF simple_textio IS
BEGIN
PROCESS
VARIABLE i: INTEGER:= 42;
VARIABLE LLL: LINE;
BEGIN
WRITE (LLL, i);
WRITELINE (OUTPUT, LLL);
WAIT;
END PROCESS;
END simple_behavior;
Using the TextIO package UM-55
Syntax for file declaration
The VHDL’87 syntax for a file declaration is:
file identifier : subtype_indication is [ mode ] file_logical_name ;
where "file_logical_name" must be a string expression.
This chapter describes how to compile and simulate Verilog designs with ModelSim
Verilog. ModelSim Verilog implements the Verilog language as defined by the IEEE Std
1364, and it is recommended that you obtain this specification as a reference manual.
In addition to the functionality described in the IEEE Std 1364, ModelSim Verilog includes
the following features:
• Standard Delay Format (SDF) annotator compatible wi th many ASIC and FPGA vendor' s
• Value Change Dump (VCD) file extensions for ASIC vendor test tools
• Dynamic loading of PLI/VPI applications
• Compilation into retargetable, executable code
• Incremental design compilation
• Extensive support for mixing VHDL and Verilog in the same design (including SDF
• Graphic Interface that is common with ModelSim VHDL
• Extensions to provide compatibility with Verilog-XL
The following IEEE Std 1364 f unctionality is partially implemen ted in ModelSim Verilog:
Verilog libraries
annotation)
• Verilog Procedural Interface (VPI) (see /<install_dir>/modeltech/docs/technotes/Verilog_VPI.note for details)
• Verilog 2001 (see /<install_dir>/modeltech/docs/technotes/vlog_2000.note for details)
Many of the examples in this chapter are shown from the command line. For compiling and
simulating within a project or ModelSim’s GUI see:
• Getting started with projects
(UM-20)
• Compiling with the graphic interface (UM-238)
• Simulating with the graphic interface (UM-245)
ModelSim User’s Manual
Compilation
Compilation UM-69
Before you can simulate a Ve rilog design, you must first create a library and compile the
Verilog source code into that library. This section provides detailed information on
compiling Verilog designs. For information on creating a design library, see Chapter 3 -
Design libraries.
The ModelSim Verilog compiler, vlog, compiles Verilog source code into retargetable,
executable code, meaning that the library format is compatible across all supported
platforms a nd that you can simulate your design on any platform without having to
recompile your design specifically for that platform. As you compile your design, the
resulting object code for modules and UDPs is generated into a library. By default, the
compiler places results into the work library. You can s pecify an alternate library with the
-work argument. The following is a simple example of how to create a work library,
compile a design, and simulate it:
Contents of top.v:
module top;
initial $display("Hello world");
endmodule
Create the work library:
% vlib work
Compile the design:
% vlog top.v
-- Compiling module top
Top level modules:
top
View the contents of the work library (optional):
% vdir
MODULE top
Simulate the design:
% vsim -c top
# Loading work.top
VSIM 1> run -all
# Hello world
VSIM 2> quit
In this example, the simulator was run without the graphic interface by specifying the -c
argument. After the design was loaded, the simulator command run -all was entered,
meaning to simulate until there are no more simulator events. Finally, the quit command
was entered to exit the simulator. By default, a log of the simulation is written to the
transcript file in the current directory.
ModelSim User’s Manual
UM-705 - Verilog simulation
Incremental compilation
By default, ModelSim Verilog supports incremental compilatio n of designs, thus saving
compilation time when you modify your design. Unlike other Verilog simulators, there is
no requirement that you compile the entire design in one invocation of the compiler .
You are not required to compile your design in any particular order because all module an d
UDP instantiations and external hierarchical references are resolved when the design is
loaded by the simulator. Incremental compilation is made possible by deferring these
bindings, and as a result some errors cannot be detected during compilation. Commonly,
these errors include: modules that were referenced but not compiled, incorrect port
connections, and incorrect hierarchical references.
The following example shows how a hierarchical design can be compiled in top-down
order:
Contents of top.v:
module top;
or2 or2_i (n1, a, b);
and2 and2_i (n2, n1, c);
endmodule
Contents of and2.v:
module and2(y, a, b);
output y;
input a, b;
and(y, a, b);
endmodule
Contents of or2.v:
module or2(y, a, b);
output y;
input a, b;
or(y, a, b);
endmodule
Compile the design in top down order (assumes work library already exists):
% vlog top.v
-- Compiling module top
Top level modules:
top
% vlog and2.v
-- Compiling module and2
Top level modules:
and2
% vlog or2.v
-- Compiling module or2
ModelSim User’s Manual
Top level modules:
or2
Note that the compiler lists each module as a top level module, although, ultimately, only
top is a top-level module. If a module is not referenced by another module compiled in the
same invocation of the compiler, then it is listed as a top level module. This is just an
CompilationUM-71
informative message and can be ignored during incremental compilation. The message is
more useful when you compile an entire desi gn in one invocation of the compiler and need
to know the top-level module names for the simulator. For example,
% vlog top.v and2.v or2.v
-- Compiling module top
-- Compiling module and2
-- Compiling module or2
Top level modules:
top
The most efficient method of incremental compilation is to manually compile only the
modules that have changed. This is not always convenient, especially if your source files
have compiler directive interdependencies (such as macros). In this case, you may prefer to
always compile your entire design in one invocation of the compiler. If you specify the
-incr argument, the compiler will automatically determine which modules have changed
and generate code only for those modules. This is not as efficient as manual incremental
compilation because the compiler must scan all of the source code to determine which
modules must be compiled.
The following is an example of how to compile a design with automatic incremental
compilation:
% vlog -incr top.v and2.v or2.v
-- Compiling module top
-- Compiling module and2
-- Compiling module or2
Top level modules:
top
Now, suppose that you modify the functionality of the or2 module:
% vlog -incr top.v and2.v or2.v
-- Skipping module top
-- Skipping module and2
-- Compiling module or2
Top level modules:
top
The compiler informs you that it skipped the modules top and and2, and compiled or2.
Automatic incremental compilation is intelligent about when to compile a module. For
example, changing a comment in your source code does not result in a recompile; however,
changing the compiler command line arguments results in a recompile of all modules.
Note: Changes to your source code that do not change functionality but that do affect
source code line numbers (such as adding a comment line) will cause all affected
modules to be recompiled. This happens becaus e debug information must be kept curren t
so that ModelSim can trace back to the correct areas of the source code.
ModelSim User’s Manual
UM-725 - Verilog simulation
Library usage
All modules and UDPs in a Verilog design must be compiled into one or more libraries.
One library is usually sufficient for a simple design, but you may want to organize your
modules into variou s libraries for a co mplex design. If your des ign uses different mod ule s
having the same name, then you are required to put those modules in different libraries
because design unit names must be unique within a library.
The following is an example of how you may organize your ASIC cells into one library and
the rest of your design into another:
Note that the first compilation uses the -work asiclib argument to instruct the compiler to
place the results in the asiclib library rather than the default work library.
Since instantiation bindings are not determined at compile time, you must instruct the
simulator to search your libraries when loading the design. The top-level modules are
loaded from the library named work unless you prefix the modules with the <library>.
option. All other Verilog instantiations are resolved in the following order:
• Search libraries specified with -Lf arguments in the order they appear on the command
line.
• Search the library specified in the "Verilog-XL `uselib compiler directive"
(UM-74).
• Search libraries specified with -L arguments in the order they appear on the command
line.
• Search the work library.
• Search the library explicitly named in the special escaped identifier instance name.
The work library is not necessarily a library named work—rather, the work library refers
to the library containing the module that instantiates the module or UDP that is currently
being searched for. This definition is useful if you have hierarchical modules organized into
separate libraries and if sub-module names overlap among the libraries. In this situation you
want the modules to search for their sub-modules in the work library first. This is
accomplished by specifying -L work first in the list of search libraries.
For example, assume you have a top-level module top that instantiates module modA from
library libA and module modB from library libB. Furthermore, modA and modB both
instantiate modules named cellA, but the definition of cellA compiled into libA is different
from that compiled into libB. In this case, it is insufficient to just specify -L libA - L libB
as the search libraries because instantiations o f cellA from modB resolve to the libA version
of cellA. The appropriate search library arguments are -L work -L libA -L libB.
ModelSim User’s Manual
Verilog-XL compatible compiler arguments
The compiler arguments listed below are equivalent to Verilog-XL arguments and may
ease the porting of a design to ModelSim. See the vlog command
of each argument.
The compiler arguments listed below support source libraries in the same manner as
Verilog-XL. See the vlog command
Note that these source libraries are very different from the libraries that the ModelSim
compiler uses to store compilation results. You may find it convenient to use these
arguments if you are porting a design to ModelSim or if you are familiar with these
arguments and prefer to use them.
(CR-181) for a description of each argument.
CompilationUM-73
(CR-181) for a description
Source libraries are searched after the source files on the command line are compiled. If
there are any unresolved references to modules or UDPs, then the compiler searches the
source libraries to satisfy them. The modules compiled from source libraries m a y in tu rn
have additional unresolved references that cause the source libraries to be searched again.
This process is repeated until all references are resolved or until no new unresolved
references are found. Source libraries are searched in the order they appear on the co mmand
line.
The ‘uselib compiler directive is an alternative source library management scheme to the
-v, -y, and +libext compiler arguments. It has the advantage that a design may reference
different modules having the same name. You compile designs that contain ‘uselib
directive statements using the -compile_uselibs argument (described below) to vlog
181)
The syntax for the ‘uselib directive is:
where <library_reference> is:
The library references are equivalent to command line argu ments as follow s:
is equivalent to the following command li ne arguments:
-y /h/vendorA +libext+.v
Since the ‘uselib directives are embedded in the Verilog source code, there is more
flexibility in defining the source libraries for the instantiations in the design. The
appearance of a ‘uselib directive in the source code explicitly defines how instantiations
that follow it are resolved, completely overriding any previous ‘uselib directives.
-compile_uselibs argument
Use the -compile_uselibs argument to vlog (CR-181)to reference ‘uselib directives. The
argument finds the source files referenced in the directive, compiles them into
automatically created object libraries, and updates the modelsim.ini file with the logical
mappings to the libraries.
When using -compile_uselibs, ModelSim determines into what directory to compile the
object libraries by choosing, in order, from the following three values:
• The directory name specified by the -compile_uselibs argument. For example,
-compile_uselibs=./mydir
• The directory specified by the MTI_USELIB_DIR environment variable (see
"Environment variables"
(UM-337))
• A directory named mti_uselibs that is created in the current working directory
Note: In ModelSim versions prior to 5.5, the library files referenced by the ‘uselib
directive were not automatically compiled by ModelSim Verilog. To maintain
backwards compatibility, this is still the default behavior when -compile_uselibs is not
used. See www.model.com/products/documentation/pre55_uselib.pdf
for a description
of the pre-5.5 implementa tion.
ModelSim User’s Manual
CompilationUM-75
The following code fragment and compiler invocation sho w how two differ ent modules
that have the same name can be instantiated within the same design:
This allows the NAND2 module to have different definitions in the vendorA and vendorB
libraries.
‘uselib is persistent
As mentioned above, the appearance of a ‘uselib directive in the source code explicitly
defines how instantiations that follow it are resolved. This may result in unex pected
consequences. For example, consider the following compile command:
vlog -compile_uselibs dut.v srtr.v
Assume that dut.v contains a ‘uselib directive. Since srtr.v is compiled after dut.v, the
‘uselib directive is still in effect. When srtr is loaded it is using the ‘uselib directive from
dut.v to decide where to locate modules. If this is not what you intend, then you need to put
an empty ‘uselib at the end of dut.v to "close" the previous ‘uselib statement.
ModelSim User’s Manual
UM-765 - Verilog simulation
Simulation
The ModelSim simulator can load and simulate both Verilog and VHDL designs, providing
a uniform graphic interface and simulation cont rol commands for debugg ing and analyzing
your designs. The graphic interface and simulator commands are described elsewhere in
this manual, while this section focuses specifically on Verilog simul a tion.
Invoking the simulator
A Verilog design is ready for simulation after it has been compiled into one or more
libraries. The simulator may then be invoked with the names of the top-level modules
(many designs contain only one top level module). For example, if your top level modules
are "testbench" and "globals", then invoke the simulator as follows:
After the simulator loads the top-level modules, it iteratively loads the instantiated modules
and UDPs in the design hierarchy, linking the design together by connecting the ports and
resolving hierarchical references. By default all modules and UDPs are loaded from the
library named work. Modules and UDPs from other libraries can be specified using the -L
or -Lf arguments to vsim (see "Library usage"
On successful loading of the design, the simulation time is set to zero, and you must enter
a run command to begin simulation. Commonly, you enter run -all to run until there are
no more simulation events or until $finish is executed in the Verilog code. You can also
run for specific time periods (e.g.,
simulator.
vsim testbench globals
(UM-72) for details).
run 100 ns). Enter the quit command to exit the
ModelSim User’s Manual
Simulator resolution limit
The simulator internally represents time as a 64-bit integer in units equivalent to the
smallest unit of simulation time, also known as the simulator resolutio n limit. The
resolution limit defaults to the smallest time precisi on found among all of the ‘timescale
compiler directives in the design. Here is an example of a ‘timescale directive:
‘timescale 1 ns / 100 ps
The first number is the time units and the second number is the time pr ecision. The directive
above causes time values to be read as ns and to be rounded to the nearest 100 ps.
Modules without timescale directives
You may encounter unexpected behavior i f your design contains some modules with
timescale directives and others without. The time units for modules without a timescale
directive default to the simulator resolution. For example, say you have the two modules
shown in the table below:
Module 1Module 2
SimulationUM-77
`timescale 1 ns / 10 ps
module mod1 (set);
module mod2 (set);
output set;
reg set;
output set;
parameter d = 1.55;
reg set;
parameter d = 1.55;
initial
begin
initial
begin
set = 1'bz;
#d set = 1'b0;
set = 1'bz;
#d set = 1'b0;
#d set = 1'b1;
end
#d set = 1'b1;
end
endmodule
endmodule
If you invoke vsim as
vsim mod2 mod1 then Module 1 sets the simulator resolution to 10 ps.
Module 2 has no timescale directive, so the time units default to the simulator resolution,
in this case 10 ps. If you watched /mod1/set and /mod2/set in the Wave window, you’d see
that in Module 1 it transitions every 1.55 ns as expected (because of the 1 ns time unit in
the timescale directive). However, in Module 2, set transitions every 20 ps. That’s because
the delay of 1.55 in Module 2 is read as 15.5 ps and is rounded up to 20 ps.
In such cases ModelSim will issue the following warning message during elaboration:
** Warning: (vsim-3010) [TSCALE] - Module ’mod1’ has a ‘timescale directive
in effect, but previous modules do not.
ModelSim User’s Manual
UM-785 - Verilog simulation
If you invoke vsim as vsim mod1 mod2, the simulation results would be the same but
ModelSim would produce a different warning message:
These warnings should ALWAYS be investigated.
If the design contains no ‘timescale directives, then the resolution limit and time units
default to the value specified by the Resolution
(The variable is set to 1 ps by default.)
Multiple timescale directives
As alluded to above, your design can have multiple timescale directives. The timescale
directive takes effect where it appears in a source file and applies to all source files which
follow in the same vlog
different timescales. The simulator determines the smallest timescale of all the modules in
a design and uses that as the simulator resolution.
Overriding the resolution
You can override the simulator resolution (or ModelSim’s default resolution) by specifying
the -t argument on the command line or by selecting a different Simulator Resolution in the
Simulate dialog box. Available resol utions are: 1 x, 10x or 100x of fs, p s, ns, us, ms , or sec.
** Warning: (vsim-3009) [TSCALE] - Module ’mod2’ does not have a ‘timescale
directive in effect, but previous modules do.
(UM-347) variable in the modelsim.ini file.
(CR-181) command. Separately compiled modules can also have
For example this command chooses 10 ps resolution:
vsim -t 10ps top
Clearly you need to be careful when doing this type of operation. If the resolution set by -t
is larger than the timescale of some module, the time valu es in that mod ule ar e ro und ed to
the next multiple of the resolution. In the example above, a delay of 4 ps would be rounded
to 0 ps.
Choosing the resolution
You should choose the coarsest resolution limit possible that does not result in undesired
rounding of your delays. The time precision should not be unnecessarily small because it
will limit the maximum simulation time limit, and it will degrade performance in some
cases.
ModelSim User’s Manual
Event ordering in Verilog designs
Event-based simulators such as ModelSim may process multiple events at a given
simulation time. The Verilog language is defined such that you cannot explicitly control the
order in which simultaneous events are processed. Unfortunately, some designs rely on a
particular event order, and these designs may behave differently than you expect.
Event queues
Section 5 of the IEEE Std 1364-1995 LRM defines several event queues that determine the
order in which events are evaluated. At the current simulation time, the simulator has the
following pending events:
• active events
• inactive events
• non-blocking assignment u pdate events
• monitor events
• future events
- inactive events
SimulationUM-79
- non-blocking assignment update events
The LRM dictates that events are processed as follows – 1) all active events are processed;
2) the inactive events are moved to the active event queue and then processed; 3) the
non-blocking events are moved to the active event queue and then processed ; 4) the monitor
events are moved to the a ctive queue and then proces sed; 5) simulation advances to the next
time where there is an inactive event or a non-blocking assignment update event.
Within the active event queue, the events can be processed in any order, and new active
events can be added to the queue in any order. In other words, you cannot control event
order within the active queue. The example below illustrates potential ramifications of this
situation.
Say you have these four statements:
1 always @(q) p = q;
2 always @(q) p2 = not q;
3 always @(p or p2) clk = p and p2;
4 always @(posedge clk)
and current values as follows: q = 0, p = 0, p2=1
ModelSim User’s Manual
UM-805 - Verilog simulation
The tables below show two of the many valid evaluations of these statements. Evaluation
events are denoted #, where # is the statement to be evaluated. Update events are denoted
<name>(old->new) where <name> indicates the reg being upd ated and new is the updated
value.
Again, both evaluations ar e valid. However, in Evaluation 1, clk has a glitch on it; in
Evaluation 2, clk doesn’t. This indicates that the design has a zero-delay race condition on
clk.
ModelSim User’s Manual
SimulationUM-81
’Controlling’ event queues with blocking/non-blocking assignments
The only control you have over event order is to assign an event to a particular queue. You
do this via blocking or non-blocking assignments.
Blocking assignments
Blocking assignments place an event in the active, inactive, or futur e queues depending o n
what type of delay they have:
• a blocking assignment without a delay goes in the active queue
• a blocking assignment with an explicit delay of 0 goes in the inactiv e queu e
• a blocking assignment with a non-zero delay goes in the future queue
Non-blocking assignments
A non-blocking assignment goes into either the non-blocking assignment update event
queue or the future non-blocking assignment update event queue. (Non-blocking
assignments with no delays and those with explicit zero delays are treated the same.)
Non-blocking assignments should be used only for outputs of flip-flops. This insures that
all outputs of flip-flops do not change until after all flip-flops have been evaluated.
Attempting to use non-blocking assignments in combinational logic paths to remove race
conditions may only cause more problems. (In the preceding example, changing all
statements to non-blocking assignments would not remove the race condition.) This
includes using non-blocki ng assignments in the generati on of gated clocks.
The following is an example of how to properly use non-blocking assignments.
gen1: always @(master)
clk1 = master;
gen2: always @(clk1)
clk2 = clk1;
f1 : always @(posedge clk1)
begin
q1 <= d1;
end
f2: always @(posedge clk2)
begin
q2 <= q1;
end
If written this way, a value on d1 always takes two clock cycles to get from d1 to q2.
If you change clk1 = master and clk2 = clk1 to non-blocking assignment s or q 2 <= q1 and
q1 <= d1 to blocking assignments, then d1 may get to q2 is less than two clock cycles.
Debugging event order issues
Since many models have been developed on Verilog-XL, ModelSim tries to duplicate
Verilog-XL event ordering to ease the porting of those models to ModelSim. However,
ModelSim does not match Verilog-XL event ordering in all cases, and if a model ported to
ModelSim does not behave as expected, then you sho uld suspect that there ar e event ord er
dependencies.
ModelSim User’s Manual
UM-825 - Verilog simulation
ModelSim helps you track down event order dependencies with the following compiler
arguments: -compat, -hazards, and -keep_delta.
See the vlog command
(CR-181) for descriptions of -compat and -keep_delta.
Hazard detection
The -hazard argument to vsim (CR-189) detects event order hazards involving simultaneous
reading and writing of the same register in concurrently executing processes. vsim detects
the following kinds of hazards:
• WRITE/WRITE:
Two processes writing to the same variable at the same time.
• READ/WRITE:
One process reading a variable at the same time it is being written to by another process.
ModelSim calls this a READ/WRITE hazard if it executed the read first.
• WRITE/READ:
Same as a READ/WRITE hazard except that ModelSim executed the write first.
vsim issues an error message when it detects a hazard. The message pinpoints the v ariable
and the two processes involved. You can h ave th e simulator break on the s tatement wh ere
the hazard is detected by setting the break on assertion level to error.
To enable hazard detection you must invoke vlog
(CR-181) with the -hazards argument
when you compile your source code and you must also invoke vsim with the -hazards
argument when you simula t e.
Important: Enabling -hazards implicitly enables the -compat argument. As a result,
using this argument may affect your simulation results.
Limitations of hazard detection
• Reads and writes involving bit and part selects of vectors are not considered for hazard
detection. The overhead of tracking the overlap between the bit and part selects is too
high.
• A WRITE/WRITE hazard is flagged even if the same value is written by both processes.
• A WRITE/READ or READ/WRITE hazard is flagged even if the write does not modify
the variable's value.
• Glitches on nets caused by non-guaranteed event ordering are not detected.
ModelSim User’s Manual
Negative timing check limits
Verilog supports negative limit values in the $setuphold and $recrem system tasks. These
tasks have optional del ayed versio ns of input s ignals to i nsure proper eval uation of models
with negative timing check limits. Delay values for these delayed nets are determined by
the simulator so that valid data is available for evaluation before a clocking signal.
ModelSim calculates the delay for signal d_dly as 4 time units instead of 3. It does this to
prevent d_dly and clk_dly from occurring simultaneously when a violation isn’t reported.
Note: ModelSim accepts negative limit checks by default, unlike current versions of
Verilog-XL. To match Verilog-XL default behavior (i.e., zeroing all negative timing
check limits), use the +no_neg_tcheck argument to vsim
SimulationUM-83
5
3
0
(CR-189).
Negative timing constraint algorithm
The algorithm ModelSim uses to calculate delays for delayed nets isn’t described in IEEE
Std 1364. Rather, ModelSim matches Verilog-XL beha vior. The algorithm att empts to find
a set of delays so the data net is valid when the clock net transitions and the timing checks
are satisfied. The algorithm is iterative because a set of delays can be selected that satisfies
all timing checks for a pair of inputs but then causes mis-ordering of another pair (where
both pairs of inputs share a common input). When a set of delays that satisfies all timing
checks is found, the delays are said to converge.
When none of the delay sets cause converg ence, the algorithm pes simistically changes the
timing check limits to force convergence. Basically the algorithm zeroes the smallest
negative $setup/$recovery limit. If a negative $setup/$recovery doesn't exist, then the
algorithm zeros the smallest negative $hold/$removal limit. After zeroing a negative limit,
the delay calculation procedure is repeated. If the delays don’t converge , the algorithm
zeros another negative limit, repeating the process until convergence is found.
ModelSim User’s Manual
UM-845 - Verilog simulation
A simple example will help clarify the algorithm. Assume you have the following timing
checks:
The violation regions for t and d in this example are:
Note that the delays between clk/clk_dly, t/t_dly, and d/d_dly are not edge sensitive, and
they must be the same for both rising and falling transitions of clk, t, and d. A d => d_dly
delay of 5 will satisfy the negedge case (transitions of d from 5 to 0 before clk won’t be
latched), but valid transitions of posedge d, in the region of 5 to 3 before clk, won’t latch
correctly. Therefore, to find convergence, the algorithm starts zeroing negative $hold
limits (-12, then -11, and then -5). The check limits on t are zeroed first because of their
magnitude.
ModelSim will display messages when limits are zeroed if you use the +ntc_warn
argument. Even if you don ’t se t +ntc_warn, ModelSim displays a summar y of an y zeroed
limits.
Extending check limits without zeroing
If zeroing limits is too pessimistic for your design, you can use the vsim (CR-189) arguments
-extend_tcheck_data_limit and -extend_tcheck_ref_limit instead. These arguments
cause a one-time extension of qualifying data or reference limits in an attempt to provide a
solution prior to any limit zeroing. A limit qualifies if it bounds a violation region which
does not overlap a related violation region.
ModelSim User’s Manual
An example will help illustrate. Assume you have the following timing checks:
The delay net delay analysis in this case does not provide a solution. The required negative
hold delay of 68 between d and dd could cause a non-violating posedge d transition to be
delayed on dd so that it could arrive after dclk for functional evaluation. By default the -68
hold limit is set pessimistically to 0 to insure the correct functional evaluation.
Alternatively, you could use -extend_tcheck_data_limit to overlap the regions. In this
example we must specify the percentage by which to "decrease" the negative hold limit in
order to overlap the positive setup limit. In other words, you must extend the 216, -68
region to 216, -44. You would calculate the percentage as follows:
1 Calculate the size of the negative edge violation region:
216 - 68 = 148
2 Calculate the gap between the negative hold limit and the positi ve setup limit and add
one timing unit to allow for overlap:
68 - 45 = 23 + 1 = 24
3 Divide the gap size by the violation region size:
24 / 148 = .16
Hence, you would set -extend_tcheck_data_limit to 16.
Note: ModelSim will extend the limit only as far as is needed to derive a solution. So if
you used 100 in the previous example, it would still only extend the limit 16 percent.
Indeed, in some cases it may be easiest to select a large percentage number and not worry
about an exact calculation.
ModelSim User’s Manual
UM-865 - Verilog simulation
Verilog-XL compatible simulator arguments
The simulator arguments listed below are equivalent to Verilog-XL arguments and may
ease the porting of a design to ModelSim. See the vsim
argument.
Model Technology passed the ASIC Council’s Verilog test suite and achieved the "Library
Tested and Approved" designation from Si2 Labs. This test suite is designed to ensure
Verilog timing accuracy and functionality and is the first significant hurdle to complete on
the way to achieving full ASIC vendor su pport. As a consequ ence, many ASIC and FPGA
vendors’ Verilog cell libraries are compatible with ModelSim Verilog.
The cell models generally contain Verilog "specify blocks" that describe the path delays
and timing constraints for the cells. See section 13 in the IEEE Std 1364-1995 for details
on specify blocks, and section 14.5 for details on timing constraints. ModelSim Verilog
fully implements specify blocks and timing constraints as defined in IEEE Std 1364 along
with some Verilog-XL compatible extensions.
SDF timing annotation
ModelSim Verilog supports timing annotation from Standard Del ay Format (SDF) files.
See Chapter 9 - Standard Delay Format (SDF) Timing Annotatio n for details.
Delay modes
Cell libraries UM-87
Verilog models may contain both distributed delays an d path delays. The delays on
primitives, UDPs , and conti nuous assi gnments ar e the distributed delays , whereas the portto-port delays specified in specify blocks are the path delays. These delays interact to
determine the actual delay observed. Most Verilog cells use path delays exclusively, with
the distributed delays set to zero. For example,
module and2(y, a, b);
input a, b;
output y;
and(y, a, b);
specify
(a => y) = 5;
(b => y) = 5;
endspecify
endmodule
In the above two-input "and" gate cell, the distributed delay for the "and" primitive is zero,
and the actual delays observed on the module ports are taken from the path delays. This is
typical for most cells, but a complex cell may require non-zero distributed delays to work
properly. Even so, these delays are usually small enough that the path delays take priority
over the distributed delays. The rule is that if a module contains both path delays and
distributed delays, then the la rger of the two delay s for each path shall be used (as defined
by the IEEE Std 1364). This is the default behavior, but you can specify alternate delay
modes with compiler directives and arguments. These arguments and directives are
compatible with Verilog-XL. Compiler delay mode arguments take preceden ce over delay
mode directives in the source code.
ModelSim User’s Manual
UM-885 - Verilog simulation
Distributed delay mode
In distributed delay mode the specify path delays are ignored in favor of the distributed
delays. Select this del ay mode with th e +delay_mode_distributed compiler argument or
the ‘delay_mode_distributed compiler directive.
Path delay mode
In path delay mode the distributed delays are set to zero in any module that co ntains a path
delay. Select this delay mode with the +delay_mode_path compiler argument or the
‘delay_mode_path compiler directive.
Unit delay mode
In unit delay mode the distributed delays are set to one (the unit is the time_unit specified
in the ‘timescale directive), and the s pecify path delays and timing con straints are ignored.
Select this delay mode with the +delay_mode_unit compiler argument or the
‘delay_mode_unit compiler directive.
Zero delay mode
In zero delay mode the distributed delays are set to zero, and the specify path delays and
timing constraints are ignored. Select this delay mode with the +delay_mode_zero
compiler argument or the ‘delay_mode_zero compiler directive.
ModelSim User’s Manual
System tasks
The IEEE Std 1364 defines many system tasks as part of the Verilog language, and
ModelSim Verilog supports all of these along with several non-s tandard Verilog-XL
system tasks. The system tasks listed in this chapter are built into the simulator, although
some designs depend on user-defined system tasks implemented with the Programming
Language Interface (PLI) or Verilog Procedural Interface (VPI). If the simulator issues
warnings regarding undefined system tasks, then it is likely that thes e system tasks are
defined by a PLI/VPI application that must be loaded by the simulator.
IEEE Std 1364 system tasks
The following system tasks are described in detail in the IEEE Std 1364.
Note: $readmemb and $readmemh match th e beha vi or o f Verilog -XL rath er than IEEE
Std 1364. Specifically, they load data into memory starting with the lowest address. For
example, whether you make the declaration
memory[127:0] or memory[0:127],
ModelSim will load data starting at address 0 and work upwards to address 127.
ModelSim User’s Manual
UM-925 - Verilog simulation
Verilog-XL compatible system tasks
The following system tasks are provided for compatibility with Verilog-XL. Although they
are not part of the IEEE standard, they are described in an annex of the IEEE Std 1364.
The following system tasks are also provided for compatibility with Verilog-XL; they are
not described in the IEEE Std 1364.
This system task sets a Verilog register or net to the specified value. variable is the
register or net to be changed; value is the new value for the register or net. The value
remains until there is a subsequent driver transaction or another $deposit task for the
same register or net. This system task operates identically to the ModelSim
force -deposit command.
This system task instructs ModelSim to disable warnings about timing check violations
or triregs that acquire a value of ‘X’ due to charge decay. <keyword> may be decay or
timing. If you don’t specify a module_instance, ModelSim disables warnings for the
entire simulation.
This system task enables warnings about timing check violations or triregs that acquire a
value of ‘X’ due to charge decay. <keyword> may be decay or timing. If you don’t
specify a module_instance, ModelSim enables warnings for the entire simulation.
The following system tasks are extended to provide additional functionality for negative
timing constraints and an alternate method of conditioning, as in Verilog-XL.
The $recovery system task normally takes a recovery_limit as the third argument and an
optional notifier as the fourth argument. By specifying a limi t for both the third and
fourth arguments, the $recovery timing check is transformed into a combination removal
and recovery timing check similar to the $recrem timing check. The only difference is
that the removal_limit and recovery_limit are swapped.
The tstamp_cond argument conditions the data_event for the setup check and the
clk_event for the hold check. This alternate method of conditioning precludes specifying
conditions in the clk_event and data_event arguments.
The tcheck_cond argument conditions the data_event for the hold check and the
clk_event for the setup check. This alternate method of conditioning preclu des specifying
conditions in the clk_event and data_event arguments.
The delayed_clk argument is a net that i s continuously assigned the value of the net
specified in the clk_event. The delay is non-zero if the setup_limit is negative, zero
otherwise.
ModelSim User’s Manual
System tasksUM-93
The delayed_data argument is a net tha t is continuously assigned the value of the net
specified in the data_event. The delay is non-zero if the hold_limit is negative, zero
otherwise.
The delayed_clk and delayed_data arguments are provided to ease the modeling of
devices that may have negative timing constraints. The model’s logic should reference
the delayed_clk and delayed_data nets in place of the normal clk and data nets. This
ensures that the correct data is latched in the presence of negative constraints. The
simulator automatically calculates the delays for delayed_clk and delayed_data such that
the correct data is latched as long as a timing constraint has not been violated. See
"Negative timing check limits"
(UM-83) for more details.
The following system tasks are Verilog-XL system tasks that are not implemented in
ModelSim Verilog, but have equivalent simulator commands.
$input("filename")
This system task reads commands from the specified filename. The equivalent simulator
command is do <filename>.
$list[(hierarchical_name)]
This system task lists the source code for the specified scope. The equivalent
functionality is provided by selecting a module in the graphic interface Structure
window. The corresponding source code is displayed in the Source window.
$reset
This system task resets the simulation back to its time 0 state. The equivalent simulator
command is restart.
$restart("filename")
This system task sets the simulation to the state specified by filename, saved in a previous
call to $save. The equivalent simulator command is restore <filename>.
$save("filename")
This system task saves the current simulation state to the file specified by filename. The
equivalent simulator command is checkpoint <filename>.
$scope(hierarchical_name)
This system task sets the interactive scope to the scope specified by hierarchical_name.
The equivalent simulator command is environment <pathname>.
$showscopes
This system task displays a list of scopes defined in the current interactive scope. The
equivalent simulator command is show.
$showvars
This system task displays a list of registers and nets defined in the current in teract ive
scope. The equivalent simulator command is show.
ModelSim User’s Manual
UM-945 - Verilog simulation
ModelSim Verilog system tasks
The following system tasks are specific to ModelSim. They are not included in the IEEE
Std 1364 nor are they likely supported in other simulators. Their use may limit the
portability of your code.
$init_signal_driver
$init_signal_spy
$signal_force
The $init_signal_driver() system task drives the value of a VHDL signal or Verilog net
onto an existing VHDL signal or Verilog net. This allows you to drive signals or nets at
any level of the design hierarchy from within a Verilog module (e.g., a testbench). See
$init_signal_driver
(UM-280) in Chapter 8 - Signal Spy for complete details and syntax on
this system task.
The $init_signal_spy() system task mirrors the value of a VHDL signal or Verilog
register/net onto an existing Verilog register or VHDL signal. This system task allows
you to reference signal s, regist ers, or nets at any level of hierarchy from within a Verilog
module (e.g., a testbench). See $init_signal_spy
(UM-283) in Chapter 8 - Signal Spy for
complete details and syntax on this system task.
The $signal_force() system task forces the value specified onto an existing VHDL signal
or Verilog register or net. This allows you to force signals, registers, or n ets at any level
of the design hierarchy from within a Verilog module (e.g., a t estbench). A $signal_force
works the same as the force command
repeating force. See $signal_force
(CR-82) with the exception that you cannot issue a
(UM-285) in Chapter 8 - Signal Spy for complete details
and syntax on this system task.
$signal_release
The $signal_release() system task releases a value that had previously been forced onto
an existing VHDL signal or Verilog register or net. A $signal_release works the same as
the noforce command
(CR-92). See $signal_release (UM-287) in Chapter 8 - Signal Spy for
complete details and syntax on this system task.
$sdf_done
This task is a "cleanup" function that removes internal buffers, called MIPDs, that have
a delay value of zero. These MIPDs are inserted in response to the -v2k_int_delay
argument to the vsim comman d
(CR-189). In general the simulator will automatically
remove all zero delay MIPDs. However, if you have $sdf_annot ate() calls in your design
that are not getting executed, the zero-delay MIPDs are not removed. Adding the
$sdf_done task after your last $sdf_annotate() will remove any zero-delay MIPDs that
have been created.
ModelSim User’s Manual
Compiler directives
ModelSim Verilog supports all of the compiler directives defined in the IEEE Std 1364,
some Verilog-XL compiler directives, and some that are proprietary.
Many of the compiler directives (such as ‘timescale) take effect at the point they are
defined in the source code and stay in effect until the directive is redefined or until it is reset
to its default by a ‘resetall directive. The effect of compiler directives spans source files,
so the order of source files on the compilation command line could be significant. For
example, if you have a file that defines some common macros for the entire design, then
you might need to place it first in the list of files to be compiled.
The ‘resetall directive affects only the following directives by resetting them back to their
default settings (this information is not provided in the IEEE Std 1364):
The following compiler directives are provided for compatibility with Verilog-XL.
‘default_decay_time <time>
`delay_mode_distributed
`delay_mode_path
`delay_mode_unit
`delay_mode_zero
This directive specifies the default decay time to be used in trireg net declarations that do
not explicitly declare a decay time. The decay time can be expressed as a real or integer
number, or as "infinite" to specify that the charge never decays.
This directive disables path delays in favor of distributed delays. See "Delay modes" (UM-
for details.
87)
This directive sets distributed delays to zero in favor of path delays. See "Delay modes"
(UM-87) for details.
This directive sets path delays to zero and non-zero distributed delays to one time unit.
See Delay modes
(UM-87) for details.
This directive sets path delays and distributed delays to zero. See "Delay modes" (UM-87)
for details.
`uselib
This directive is an alternative to the -v, -y, and +libext source library compiler
arguments. See "Verilog-XL ‘uselib compiler directive"
(UM-74) for details.
The following Verilog-XL compiler directives are silently ignored by ModelSim Verilog.
Many of these directives are irrelevant to ModelSim Verilog, but may appear in code being
ported from Verilog-XL.
The following Verilog-XL compiler directives produce warning messages in ModelSim
Verilog. These are not implemented in ModelSim Verilog, and any code containing these
directives may behave differently in ModelSim Verilog than in Verilog-XL.
`default_trireg_strength
`signed
`unsigned
ModelSim User’s Manual
Verilog PLI/VPI
The Verilog PLI (Programming Language Interface) and VPI (Verilog Procedural
Interface) both provide a mechanism for defining system tasks and functions that
communicate with the simulator through a C procedural interface. There are many third
party applications available that interface to Verilog simulators through the PLI (see "Third
party PLI applications"
applications.
ModelSim Verilog implements the PLI as defined in the IEEE Std 1364, with the excep tion
of the acc_handle_datapath() routine. We did not implement the acc_handle_datapath()
routine because the information it returns is more appropriate for a static timing analysis
tool. The VPI is partially implemented as defined in the IEEE Std 1364-2001. The list of
currently supported functionality can be found in the following file:
The IEEE Std 1364 is the reference that defines the usage of the PLI/VPI routines. This
manual only describes details of using the PLI/VPI with ModelSim Verilog.
Registering PLI applications
Verilog PLI/VPIUM-97
(UM-108)). In addition, you may write your own PLI/VPI
Each PLI application must register its system tasks and functions with the simulato r,
providing the name of each system task and func tion and the associated callb ack routines .
Since many PLI applications already interface to Verilog-XL, ModelSim Verilog PLI
applications make use of the same mechanism to register information about each system
task and function in an array of s_tfcell structures. This structure is declared in the
veriuser.h include file as follows:
typedef int (*p_tffn)();
typedef struct t_tfcell {
short type;/* USERTASK, USERFUNCTION, or USERREALFUNCTION */
short data;/* passed as data argument of callback function */
p_tffn checktf; /* argument checking callback function */
p_tffn sizetf; /* function return size callback function */
p_tffn calltf; /* task or function call callback function */
p_tffn misctf; /* miscellaneous reason callback function */
char *tfname;/* name of system task or function */
/* The following fields are ignored by ModelSim Verilog */
int forwref;
char *tfveritool;
char *tferrmessage;
int hash;
struct t_tfcell *left_p;
struct t_tfcell *right_p;
char *namecell_p;
int warning_printed;
} s_tfcell, *p_tfcell;
The various callback functions (checktf, sizetf, calltf, and misctf) are described in detail in
the IEEE Std 1364. The simulator calls these functions for various reasons. All callback
functions are optional, but most applications contain at least the calltf function, which is
called when the system task or function is executed in the Verilog code. The first argument
to the callback functions is the value supplied in the data field (many PLI applications don’t
ModelSim User’s Manual
UM-985 - Verilog simulation
use this field). The type field defines the entry as either a system task (USERTASK) or a
system function that returns either a register (USERFUNCTION) or a real
(USERREALFUNCTION). The tfname field is the system task or function name (it must
begin with $). The remaining fields are not used by ModelSim Verilog.
On loading of a PLI application, the simulator first looks for an init_usertfs function, and
then a veriusertfs array. If init_usertfs is found, the simulato r calls that function so that it
can call mti_RegisterUserTF() for each system task or function defined. The
mti_RegisterUserTF() function is declared in veriuser.h as follows:
The storage for each usertf entry passed to the simulator must persist throughout the
simulation because the simulator de-references the usertf pointer to call the callback
functions. We recommend that you define your entries in an array, with the last entry set to
0. If the array is named veriusertfs (as is the case for linking to Verilog-XL), then you don’t
have to provide an init_usertfs function, and the simulator will automatically register the
entries directly from the array (the last entry must be 0). For example,
void mti_RegisterUserTF(p_tfcell usertf);
s_tfcell veriusertfs[] = {
{usertask, 0, 0, 0, abc_calltf, 0, "$abc"},
{usertask, 0, 0, 0, xyz_calltf, 0, "$xyz"},
{0} /* last entry must be 0 */
};
Alternatively, you can add an init_usertfs function to explicitly register each entry from the
array:
void init_usertfs()
{
p_tfcell usertf = veriusertfs;
while (usertf->type)
}
mti_RegisterUserTF(usertf++);
It is an error if a PLI shared library does not contain a veriusertfs array or an init_usertfs
function.
Since PLI applications are dynamically loaded by the simulator, you must specify which
applications to load (each application must be a dynamically loadable library, see
"Compiling and linking PLI/VPI C applications"
(UM-101)). The PLI applications are
specified as follows (note that on a Windows platform the file extension would be .dll):
• As a list in the Veriuser entry in the modelsim.ini file:
• As a -pli argument to the simulator (multiple arguments are allowed):
-pli pliapp1.so -pli pliapp2.so -pli pliappn.so
ModelSim User’s Manual
The various methods of specifying PLI applications can be used simultaneously. The
libraries are loaded in the order listed above. Environment variable references can be used
in the paths to the libraries in all cases.
Registering VPI applications
Each VPI application must register its system tasks and functions and its callbacks with the
simulator. To accomplish this, one or more user-created reg istration routines must be called
at simulation startup. Each registration routine should make one or more calls to
vpi_register_systf() to register user-defined system tasks and functions and
vpi_register_cb() to register callbacks. The registration routines must be placed in a table
named vlog_startup_routines so that the simulator can find them. The table must be
terminated with a 0 entry.
Loading VPI applications into the simulator is the same as described in "Registering PLI
applications"
PLI and VPI applications can co-exist in the same application object file. In such cases, the
applications are loaded at startup as follows:
• If an init_usertfs() function exists, then it is executed and only those sy stem tasks and
• If an init_usertfs() function does not exist but a veriusertfs table does exist, then only
• If an init_usertfs() function does not exist and a veriusertfs table does not exist, but a
As a result, when PLI and VPI applications exist in the same application object file, they
must be registered in the same manner. VPI registrati on fu ncti ons that woul d norm ally be
listed in a vlog_startup_routines table can be called from an init_usertfs() function instead.
(UM-97).
functions registered by calls to mti_RegisterUserTF() will be defin e d.
those system tasks and functions listed in the veriusertfs table will be defined.
vlog_startup_routines table does exist, then only those system tasks and functions and
callbacks registered by functions in the vlog_startup_routin es table will be defined.
ModelSim User’s Manual
Loading...
+ hidden pages
You need points to download manuals.
1 point = 1 manual.
You can buy points or you can get point for every manual you upload.