1991-2018 Mentor Graphics Corporation
All rights reserved.
This document contains information that is trade secret and proprietary to Mentor Graphics Corporation or its licensors and
is subject to license terms. No part of this document may be photocopied, reproduced, translated, distributed, disclosed or
provided to third parties without the prior written consent of Mentor Graphics.
ModelSim®/Questa® Core Advanced Topics
Student Workbook
This document is for information and instruction purposes. Mentor Graphics reserves the right to make
changes in specifications and other information contained in this publication without prior notice, and the reader
should, in all cases, consult Mentor Graphics to determine whether any changes have been made.
The terms and conditions governing the sale and licensing of Mentor Graphics products are set forth in written
agreements between Mentor Graphics and its customers. No representation or other affirmation of fact
contained in this publication shall be deemed to be a warranty or give rise to any liability of Mentor Graphics
whatsoever.
MENTOR GRAPHICS MAKES NO WARRANTY OF ANY KIND WITH REGARD TO THIS MATERIAL
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
FOR A PARTICULAR PURPOSE.
MENTOR GRAPHICS SHALL NOT BE LIABLE FOR ANY INCIDENTAL, INDIRECT, SPECIAL, OR
CONSEQUENTIAL DAMAGES WHATSOEVER (INCLUDING BUT NOT LIMITED TO LOST PROFITS)
ARISING OUT OF OR RELATED TO THIS PUBLICATION OR THE INFORMATION CONTAINED IN IT, EVEN
IF MENTOR GRAPHICS HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
U.S. GOVERNMENT LICENSE RIGHTS: The software and documentation were developed entirely at private
expense and are commercial computer software and commercial computer software documentation within the
meaning of the applicable acquisition regulations. Accordingly, pursuant to FAR 48 CFR 12.212 and DFARS
48 CFR 227.7202, use, duplication and disclosure by or for the U.S. Government or a U.S. Government
subcontractor is subject solely to the terms and conditions set forth in the license agreement provided with the
software, except for provisions which are contrary to applicable mandatory federal laws.
TRADEMARKS: The trademarks, logos and service marks ("Marks") used herein are the property of Mentor
Graphics Corporation or other parties. No one is permitted to use these Marks without the prior written consent
of Mentor Graphics or the owner of the Mark, as applicable. The use herein of a third- party Mark is not an
attempt to indicate Mentor Graphics as a source of a product, but is intended to indicate a product from, or
associated with, a particular third party. A current list of Mentor Graphics’ trademarks may be viewed at:
www.mentor.com/trademarks.
The registered trademark Linux® is used pursuant to a sublicense from LMI, the exclusive licensee of Linus
Torvalds, owner of the mark on a world-wide basis.
End-User License Agreement: You can print a copy of the End-User License Agreement from:
www.mentor.com/eula.
Mentor Graphics Corporation
8005 S.W. Boeckman Road, Wilsonville, Oregon 97070-7777
Telephone: 503.685.7000
Toll-Free Telephone: 800.592.2210
Website: www.mentor.com
SupportNet: supportnet.mentor.com/
Send Feedback on Documentation: supportnet.mentor.com/doc_feedback_form
Part Number: 073672
Table of Contents
ModelSim/Questa Core Advanced Topics
I
Module 1: Introduction: Functional Verification Overview ............................. 13
Objectives ........................................................................................................................................... 14
Module Overview ............................................................................................................................... 15
2-Day Course Agenda ........................................................................................................................ 16
Digital Simulation Design Flow ......................................................................................................... 17
Functional Verification ...................................................................................................................... 18
Digital Functional Verification .......................................................................................................... 19
Functional Verification Techniques ................................................................................................... 20
Hardware Assisted Functional Verification ....................................................................................... 21
Digital Simulation Using ModelSim / Questa Core ........................................................................... 22
Summary ............................................................................................................................................ 24
Module 2: Tcl/Tk Overview.................................................................................. 25
Objectives ........................................................................................................................................... 26
Module Overview ............................................................................................................................... 27
Why Tcl/Tk? ...................................................................................................................................... 28
Some Examples of Using Tcl/Tk in Debugging ................................................................................ 29
Tcl Overview ...................................................................................................................................... 30
Tk Overview ....................................................................................................................................... 31
Tcl Commands ................................................................................................................................... 32
Basic Tcl Syntax ................................................................................................................................. 33
Tcl Variables ...................................................................................................................................... 34
Command Substitution ....................................................................................................................... 35
Quotes ................................................................................................................................................. 36
Curly Braces ....................................................................................................................................... 37
Table of Contents
ModelSim/Questa Core Advanced Topics
II
Control Structures .............................................................................................................................. 38
Simulation Commands ....................................................................................................................... 39
Using Commands to Add Signals to the Wave Window ................................................................... 40
Using Commands to Organize Signals in the Wave Window ........................................................... 41
Grouping Signals in the Wave Window ............................................................................................. 42
Tcl Script Example ............................................................................................................................. 43
Creating a Simulation Script .............................................................................................................. 44
Simulation Script Example ................................................................................................................. 45
Tk Widget Overview .......................................................................................................................... 46
Tk Commands .................................................................................................................................... 47
Simple Tk Example ............................................................................................................................ 48
Adding a Customized Button to the Main Window ........................................................................... 49
Additional Tcl/Tk Resources ............................................................................................................. 51
Summary ............................................................................................................................................ 52
Lab 1: Tcl/Tk Application .................................................................................................................. 53
Module 3: Code Coverage .................................................................................... 55
Objectives ........................................................................................................................................... 56
Code Coverage ................................................................................................................................... 57
Purpose of Code Coverage ................................................................................................................. 58
Code Coverage in ModelSim / Questa Core ...................................................................................... 59
Types of Code Coverage .................................................................................................................... 60
Unified Coverage Database (UCDB) ................................................................................................. 62
Coverage Modes ................................................................................................................................. 63
Statement Coverage ............................................................................................................................ 64
Table of Contents
ModelSim/Questa Core Advanced Topics
III
Branch Coverage ................................................................................................................................ 65
Expression Coverage .......................................................................................................................... 67
Condition Coverage ............................................................................................................................ 68
Focused Expression Coverage............................................................................................................ 70
Toggle Coverage ................................................................................................................................ 72
Extended Toggle Coverage ................................................................................................................ 73
Finite State Machine (FSM) Coverage ............................................................................................... 74
Invoking Code Coverage: Two-Step Flow ......................................................................................... 75
Invoking Code Coverage: Alternative Two-Step Flows .................................................................... 76
Invoking Code Coverage: Three-Step Flows ..................................................................................... 77
Union of Coverage Types .................................................................................................................. 79
Enabling Code Coverage in the GUI, 2-Step Flow ............................................................................ 80
Enabling Code Coverage in the GUI, 3-Step Flow ............................................................................ 81
Code Coverage Windows ................................................................................................................... 82
Code Coverage in the Structure Window ........................................................................................... 83
Code Coverage Analysis Window ..................................................................................................... 84
Viewing Toggle Coverage.................................................................................................................. 88
Toggle Coverage Data ........................................................................................................................ 89
Instance Coverage Window ............................................................................................................... 91
Code Coverage in the Source Window .............................................................................................. 92
Excluding Lines and Files From Coverage Statistics ......................................................................... 95
Saving and Recalling Exclusions ....................................................................................................... 96
Creating Coverage Reports ................................................................................................................ 97
Saving Coverage Data ........................................................................................................................ 98
Reloading Coverage Data in the GUI .............................................................................................. 100
Table of Contents
ModelSim/Questa Core Advanced Topics
IV
Merging Coverage Data in the GUI ................................................................................................. 102
Invoking Coverage View Mode in the GUI ..................................................................................... 103
Coverage View Mode with UCDB Loaded ..................................................................................... 104
Generating HTML Reports .............................................................................................................. 105
Managing Coverage Data ................................................................................................................. 107
Managing Coverage Data Off-Line .................................................................................................. 109
Understanding Optimization Effects ................................................................................................ 111
Customizing the Optimization Level for Coverage ......................................................................... 112
Coverage Optimization Levels ......................................................................................................... 113
Summary .......................................................................................................................................... 114
Lab 2: Code Coverage ...................................................................................................................... 115
Module 4: vopt for Performance ........................................................................ 117
Objectives ......................................................................................................................................... 118
Module Overview ............................................................................................................................. 119
Optimization (vopt) .......................................................................................................................... 120
vopt — The Big Picture ................................................................................................................... 121
Default Performance Mode .............................................................................................................. 122
Preserving Visibility and Enabling Access ...................................................................................... 123
Design Optimization and Visibility .................................................................................................. 125
Adjusting Design Visibility Through the GUI ................................................................................. 126
Design Visibility versus Performance .............................................................................................. 129
3-Step vopt Flow .............................................................................................................................. 130
2-Step vopt Flow .............................................................................................................................. 131
1-Step vopt Flow .............................................................................................................................. 132
Table of Contents
ModelSim/Questa Core Advanced Topics
V
vopt: Use for Different Flows .......................................................................................................... 134
Lab 3: vopt for Performance ............................................................................................................ 135
Module 5: Optimization Flows and Methods ................................................... 137
Objectives ......................................................................................................................................... 138
Module Overview ............................................................................................................................. 139
ModelSim / Questa Core Structure and Flow .................................................................................. 140
Optimization Flow ............................................................................................................................ 141
RTL/Behavioral Designs .................................................................................................................. 142
vopt Commands for RTL Simulation ............................................................................................... 143
Verilog Delay Modes ....................................................................................................................... 144
Verilog Delay Mode for Gate-Level Simulation .............................................................................. 145
Verilog Gate-Level Without SDF .................................................................................................... 148
Verilog Gate-Level With SDF ......................................................................................................... 149
vopt Switches for Gate-Level Simulation ........................................................................................ 150
Increasing Verilog Gate-Level Optimizations ................................................................................. 152
Analyzing Cell Optimization Results ............................................................................................... 154
Compiled SDF .................................................................................................................................. 156
Verilog Coding Style for Maximum Performance ........................................................................... 157
Direct Programming Interface .......................................................................................................... 159
vcom Performance Commands ........................................................................................................ 160
VHDL Coding for Performance ....................................................................................................... 161
Measuring Time and Memory Usage ............................................................................................... 164
Alternate Elaboration Flow .............................................................................................................. 165
When to Use an Elaboration File ..................................................................................................... 167
Table of Contents
ModelSim/Questa Core Advanced Topics
VI
Tips for Performance ........................................................................................................................ 168
General Performance Issues ............................................................................................................. 170
Summary .......................................................................................................................................... 171
Module 6: Statistical and Memory Profiler ...................................................... 173
Objectives ......................................................................................................................................... 174
Module Overview ............................................................................................................................. 175
Challenges ........................................................................................................................................ 176
Statistical and Memory Profilers ...................................................................................................... 177
Statistical Sampling Profiler ............................................................................................................. 178
Invoking the Profiler ........................................................................................................................ 179
Profile Commands ............................................................................................................................ 181
Enable Profiling ................................................................................................................................ 182
Graphical Views ............................................................................................................................... 183
Understanding In and Under ............................................................................................................ 184
Graphical Views ............................................................................................................................... 186
Profile Details Window .................................................................................................................... 188
Integration With the Source Window ............................................................................................... 189
Saving a Profile Report File ............................................................................................................. 190
Memory Allocation Profiler ............................................................................................................. 191
Capacity Analysis ............................................................................................................................. 192
Displaying Capacity Objects in the Wave Window ......................................................................... 194
Summary .......................................................................................................................................... 195
Lab 4: Analyzing Performance ........................................................................................................ 196
Module 7: Virtual Objects and Signal Spy ....................................................... 197
Table of Contents
ModelSim/Questa Core Advanced Topics
VII
Objectives ......................................................................................................................................... 198
Module Overview ............................................................................................................................. 199
Virtual Objects ................................................................................................................................. 200
Virtual Signals .................................................................................................................................. 201
Create Meaningful Definitions With Virtual Signals ....................................................................... 203
Combining Signals ........................................................................................................................... 204
Extract/Pad or Split Bus ................................................................................................................... 205
Virtual Regions ................................................................................................................................ 206
Virtual Functions .............................................................................................................................. 207
Virtual Signal Builder ...................................................................................................................... 210
Virtual Types .................................................................................................................................... 211
Other Virtual Commands ................................................................................................................. 212
User-Defined Radices ...................................................................................................................... 214
Managing Radices ............................................................................................................................ 216
Global Signal Radix ......................................................................................................................... 217
Virtual Signal Builder ...................................................................................................................... 218
Signal Spy ........................................................................................................................................ 219
init_signal_spy Procedure ................................................................................................................ 221
enable_signal_spy Procedure ........................................................................................................... 222
disable_signal_spy Procedure .......................................................................................................... 223
init_signal_spy VHDL Utility .......................................................................................................... 224
Probing Verilog Signals From the VHDL Testbench ...................................................................... 226
$init_signal_spy Verilog Task ......................................................................................................... 227
VHDL Extended and Verilog Escaped Identifiers ........................................................................... 232
Summary .......................................................................................................................................... 234
Table of Contents
ModelSim/Questa Core Advanced Topics
VIII
Lab 5: Signal Spy ............................................................................................................................. 235
Module 8: Waveform Compare ......................................................................... 237
Objectives ......................................................................................................................................... 238
Module Overview ............................................................................................................................. 239
Saving Waveform Datasets .............................................................................................................. 240
Opening Datasets .............................................................................................................................. 241
Managing Datasets ........................................................................................................................... 242
Dataset and Compare Windows ....................................................................................................... 243
Compare Datasets Using Waveform Compare ................................................................................ 244
Comparison Wizard .......................................................................................................................... 246
Waveform Compare Menus ............................................................................................................. 248
Compare by Signal Dialog Box ....................................................................................................... 249
Compare by Region Dialog Box ...................................................................................................... 250
Add Clocks Dialog Box ................................................................................................................... 251
Differences ....................................................................................................................................... 252
Clocked versus Continuous Differences .......................................................................................... 253
Compare Objects in the List Window .............................................................................................. 254
Write Report ..................................................................................................................................... 255
Save Differences .............................................................................................................................. 256
Save Rules ........................................................................................................................................ 257
Comparing Hierarchical and Flattened Designs ............................................................................... 258
Using Tcl Commands to Define a Comparison ............................................................................... 259
Tcl Compare Command ................................................................................................................... 260
Tcl Compare Example ...................................................................................................................... 261
Table of Contents
ModelSim/Questa Core Advanced Topics
IX
Tcl Compare Example Using "when" .............................................................................................. 263
Summary .......................................................................................................................................... 265
Lab 6: Waveform Compare .............................................................................................................. 266
Module 9: HDL Support and Gate-Level Simulation ...................................... 267
Objectives ......................................................................................................................................... 268
Module Overview ............................................................................................................................. 269
VHDL Support ................................................................................................................................. 270
VHDL-2008 Functionality ............................................................................................................... 271
VHDL VITAL SDF ......................................................................................................................... 272
SDF Annotation ................................................................................................................................ 274
Verilog Support ................................................................................................................................ 275
SystemVerilog .................................................................................................................................. 276
Why SystemVerilog? ....................................................................................................................... 277
SystemVerilog Support .................................................................................................................... 278
SystemVerilog Compilation Units ................................................................................................... 279
SystemVerilog Functionality ............................................................................................................ 280
Summary .......................................................................................................................................... 281
Lab 7: Gate-Level Simulation .......................................................................................................... 282
Module 10: FSM Viewer ..................................................................................... 283
Objectives ......................................................................................................................................... 284
Module Overview ............................................................................................................................. 285
FSM Recognition ............................................................................................................................. 286
FSM Viewer Modes ......................................................................................................................... 287
FSM Recognition in the Transcript Window ................................................................................... 288
Table of Contents
ModelSim/Questa Core Advanced Topics
X
Viewing FSM Information in the GUI ............................................................................................. 289
FSM List Window Menu .................................................................................................................. 290
FSM Viewer and Wave Windows .................................................................................................... 291
FSM Properties ................................................................................................................................. 293
Integration With the Source Window ............................................................................................... 294
FSM Viewer Display Controls ......................................................................................................... 295
FSM Viewer – Transitions to Reset ................................................................................................. 298
Export the FSM Viewer Window as an Image ................................................................................ 300
Summary .......................................................................................................................................... 301
Lab 8: FSM Viewer .......................................................................................................................... 302
Module 11: Event Tracing .................................................................................. 303
Objectives ......................................................................................................................................... 304
Module Overview ............................................................................................................................. 305
Causality Traceback ......................................................................................................................... 306
Recommended Usage Flow .............................................................................................................. 307
Alternative Usage Flow .................................................................................................................... 308
Post-Simulation Causality Traceback .............................................................................................. 309
Terminology ..................................................................................................................................... 310
Causality Traceback from the GUI .................................................................................................. 311
Tracing First Sequential From the Wave Window ........................................................................... 312
Show Drivers Control Bar ................................................................................................................ 315
Tracing From the Source Window ................................................................................................... 316
Tracing From the Objects Window .................................................................................................. 318
Tracing From the Schematic Window ............................................................................................. 319
Table of Contents
ModelSim/Questa Core Advanced Topics
XI
Tracing Immediate Driver From the Wave Window ....................................................................... 321
Tracing to the Root Cause ................................................................................................................ 323
Tracing to the Root Cause of an Unknown ...................................................................................... 324
Finding All Possible Drivers ............................................................................................................ 325
Tracing from a Specific Time .......................................................................................................... 326
Viewing Causality Path Details ........................................................................................................ 327
Causality Traceback Preferences ..................................................................................................... 328
Summary .......................................................................................................................................... 329
Lab 9 : Causality Traceback ............................................................................................................. 330
Module 12: Selected Advanced Debugging Topics .......................................... 331
Objectives ......................................................................................................................................... 332
Module Overview ............................................................................................................................. 333
Debugging Issues ............................................................................................................................. 334
Checkpoint and Restore ................................................................................................................... 335
Contention and Float Checking ........................................................................................................ 336
Toggle and Stability Checking ......................................................................................................... 337
Contention, Float, and Stability Checking Script ............................................................................. 338
Example: Contention Checking ....................................................................................................... 339
Example: Float Checking ................................................................................................................. 340
Example: Stability Checking ............................................................................................................ 341
Iteration Violations ........................................................................................................................... 342
IP Integrity for compile .................................................................................................................... 344
-nodebug Command ......................................................................................................................... 345
Preoptimizing Regions of the Design ............................................................................................... 347
Table of Contents
ModelSim/Questa Core Advanced Topics
XII
Source Window: Finding Declaration .............................................................................................. 348
Source Window: Finding Where used ............................................................................................. 349
Source Window: Tracing Readers .................................................................................................... 350
Source Window: Tracing Drivers .................................................................................................... 351
Dataflow Window: Point-to-Point Tracing ...................................................................................... 353
List Window: Signal Search ............................................................................................................. 354
Wave Window: Signal Search .......................................................................................................... 355
Wave Window: Signal Grouping ..................................................................................................... 356
Saving Waveforms Between Two Cursors ...................................................................................... 357
Wave Window: Expanded Time ...................................................................................................... 358
Wave Window: Expanded Time at Active Cursor ........................................................................... 359
Wave Window: Expanded All Time ................................................................................................ 360
Wave Window: Expanded Time Deltas in the List Window ........................................................... 361
Wave Window: Events Mode .......................................................................................................... 362
Wave Window: Deltas Mode versus Events Mode .......................................................................... 363
Post-Simulation Results Analysis .................................................................................................... 364
Post-Simulation Coverage Analysis ................................................................................................. 365
Related Functional Verification Training Courses ........................................................................... 366
Summary .......................................................................................................................................... 367
Lab 10: Debugging a Design ............................................................................................................ 368