编译(Compilation)

1.3.1 编译型语言和解释型语言

verilog和systemverilog等都是编译型语言,需要使用专门的编译器,针对特定的平台,将源代码一次性的编译成可被该平台硬件执行的机器码,并包装成该平台能识别的可执行程序(simv)的格式。
相对于编译型语言存在的是解释型语言。源代码不是直接翻译成机器语言,而是先翻译成中间代码,再由解释器对中间代码进行解释运行。比如Python/JavaScript / Perl /Shell等都是解释型语言。
解释型语言:程序不需要编译,程序在运行时才翻译成机器语言,每执行一次都要翻译一次。因此效率比较低。但是优点是只要平台提供相应的解释器,就可以运行源代码,所以可以方便源程序移植。
至于性能的差别,可以参考C语言和一些脚本语言的区别。

什么是编译型语言和解释型语言

1.3.2 VCS和其他仿真器

VCS是编译型的仿真器,处理速度快,memory占用少,并且increment 增量编译的话,每次只需编译更新部分,比较快。
而Verilog XL等是解释器性的仿真器,比较占用memory,每次执行需要重新解释一遍source code。
由此可见,VCS其实就是一个编译器。那么编译器的常用流程是啥,无非就是编译和运行吗?那么针对VCS,就是Compilation和Simulation了。

1.3.3 VCS仿真流程

VCS主要支持两种flow的编译仿真流程。

  • 3-step flow for mixed-language users
    Analysis, Compilation, Simulation
  • 2-step flow for pure-Verilog users
    Compilation, Simulation
    就个人而言,用的最多的是2-step的流程,通常情况下,我们设计一个模块,designer只会选一种HDL语言。但是我们不能保证整个chip,就是有一种语言设计的啊,尤其是买的IP,很多欧美的工程师还是挺喜欢使用VHDL的。所以就有了3-step的流程。

1.3.4 VCS 3-step Flow

The three-step flow is also known as Unified Use Model (UUM flow). Simulating a design using three-step flow involves three basic steps:

  • “Analysis”
  • “Elaboration”
  • “Simulation”
    ###1. Analysis
    Analysis is the first step to simulate your design. In this phase, you analyze your VHDL, Verilog, SystemVerilog files using vhdlan or vlogan accordingly.
Analyzing VHDL files:

%> vhdlan [vhdlan_options] file1.vhd file2.vhd

Analyzing Verilog files:

%> vlogan [vlogan_options] file1.v file2.v

Analyzing SystemVerilog files:

%> vlogan -sverilog [vlogan_options] file1.sv file2.sv file3.v
在此阶段,VCS MX会检查设计的语法错误。VCS MX生成elaboration阶段所需的中间文件,并将这些文件保存在默认逻辑库指向的设计或工作库中。 在执行vhdlan或vlogan前,需确保synopsys_sim.setup文件中的库映射被定义了。
关于每条命令的具体使用方法,请查看UG,简单提示一下通用的options。

vhdlan
  • -help
    打印vhdlan的使用方法信息
  • -nc
    不打印the Synopsys copyright的信息.
  • -q
    压缩该条命令生成的所有信息
  • -version
    该条命令版本信息
  • -full64
    64-bit 模式
  • -output(-o) outfile
    重定向打印到屏幕的信息,到指定的文件,并且打印到屏幕
  • -f filename
    指定一个文件,文件内容是source files
  • -l filename
    指定log文件名
vlogan

上面vhdlan的options,也适用于vlogan

  • -sverilog
    使能对systemverilog 源码的分析
  • -timescale=time_unit/time_precision
    为缺少\\timescale 编译器指令的源文件,指定timescale。并且会覆盖纯在于源文件中的\\\\timescale
  • +define+macro
    定义文本宏\\`ifdef
  • Verilog_source_filename
    可以直接在vlogan后,跟verilog文件
    ###2. Elaboration
    Elaboration是3-step流程的第二步。Elaboration阶段是将设计组件绑定在一起的过程,类似于c语言的link。 Elaboration包括创建实例化,计算参数值,解析层次名称和连接网络等。 通常在编译和elab阶段时,它们不会被区分,被通称为编译。在此阶段,使用分析期间生成的中间文件,VCS MX构建实例层次结构并生成二进制可执行文件simv。 此二进制可执行文件稍后用于仿真。
    在此阶段,你可以选择在优化模式或调试模式下elaborate设计。 VCS MX的运行时性能取决于您选择的模式以及仿真期间所需的灵活性级别。 Synopsys建议使用完全调试或部分调试模式,直到达到设计正确性,然后切换到优化模式。
    所谓debug模式,就是开启debug功能,以便后续使用verdi或者其他工具,联调的时候,能够访问design的内部数据信息。而优化模式,是仅仅开启基本的输入输出,没有dump很多debug时,才需要的信息,仿真速度会大大提高。
    当处于开发周期的初始阶段,或者需要更多调试功能或工具来调试设计问题时,您可以在调试模式下编译设计,也称为交互模式。 在此模式下,性能不是VCS MX提供的最先考量。
    在优化模式(也称为批处理模式)中,VCS MX为设计提供了最佳的编译时间和运行时性能。 通常选择优化模式来运行回归,或者当你不需要大量调试功能时。
vcs

%> vcs [elab_options] [libname.]design_unit
design_unit 可以是verilog的top module name,或者VHDL的top entity name

  • -h or -help
    打印出所有的vcs命令支持的options
  • -file filename
    指定包含elaboration options的文件
  • -gui
    告诉仿真器,在simulation阶段,打开可视化debug工具DVE或者verdi来debug。
  • -q
    quiet mode, log文件中信息变少
  • -V
    Verbose mode
    -l filename
    指定log文件名
    ###3. Simulation
    使用上一步生成的二进制可执行文件simv跑仿真,可以使用交互式模式或者批处理模式。这取决于,你在elaboration时,是否加-gui选项。
交互式模式

在设计周期的初始阶段可以使用交互模式(也称为调试模式)详细验证设计代码。 在此阶段,需要使用GUI或命令行调试设计问题。 可以使用DVE或者Verdi进行调试,并通过命令行界面进行调试。
之所以会有交互式模式,是在testbench遇到问题时,或者想查看代码的执行顺序时,才会真正打开交互式模式,通过情况下,我们都是在批处理模式完成绝大部分testcase的调试。

批处理模式

在解决大部分设计问题后,你可以在批处理模式下elaborate设计,也称为优化模式。 在此阶段,你可以获得更好的性能,以最小的调试能力运行回归。也就是说回归测试时,你已经经历过若干迭代,已经写了很多case,发现了不少bug,设计趋近于收敛,所以,这个时候,你需要将随机的case进行若干轮回归测试。在批量跑case的时候,或许会发现遗漏的bug。

1.3.5 VCS 2-step Flow

2-step流程其实和3-step流程的后两部所使用的命令完全一样,但是步骤名称稍有修改,第一步是Compilation,第二步是Simulation,唯一的区别是,2-step流程适合于仿真纯verilog编写的dut。

  • Why is compilation a separate step?
    – Better simulation performance
    – Global optimizations
    – Static linking
    – Reuse previous elaboration results
    – Allows separate executables for multiple simulation modes
  • Methodology: Compile once, run multiple times

1.3.6 VCS 编译步骤如何工作的


Compilation creates the following files:

  • simv -Simulator executable
  • simv.daidir/ -Simulator database files
  • csrc/ -Files used for incremental recompilation

Common VCS Options

  • -o -Rename simulation executable
  • -ucli -Enable Tcl command-line interface
  • -debug_access+pp -Enable post-process waveforms
  • -debug_access -Enable debug capabilities
  • -debug_access+all -Enable source-line debugging
  • -debug_region=lib -Enable library cell debug capability
  • -l -Create runtime log file
  • -R -Run simulation immediately after compile
  • -gui -Start DVE after compilation finishes
  • <.c|.ofiles> -Add C or object files to compile
  • -assert enable_diag -Enable SVA report in simulation
  • -assert svaext -Enable the IEEE Std. 1800-2012 compliant SVA features.
    (Old debug options: -debug_pp -debug -debug_all)

File Parsing Options

  • +define+ -Defines a macro in the Verilog source
  • -file/-f file.list -Specify files as well as command options
  • -v <lib_file> -Specify a verilog library file
  • -y -Specify a directory of Verilog library files
  • +libext_ext+ -Specify library file extensions (use with -y)
  • +incdir+ -Specifies search directory for include files
  • +nospecify -Remove timing in specify blocks
  • +notimingchecks -Remove timingchecks
  • +v2k -Enable Verilog2001 constructs
  • -sverilog -Enable SystemVerilog constructs
  • -timescale=1ns/1ps -Specify default timescale
  • -kdb -lca -Generate Verdi KDB

1.3.7 Compiling C Code with VCS

  • PLI, DPI, Direct C:
    Specify C code or shared object directly on vcscommand line
    %> vcs <file.c> -cflags“<gccoptions>” <options>
    关于这点我要多写几句。针对复杂的仿真环境,假设使用DPI技术,将大量的C函数组成的库导入到验证环境中,作为参考模型使用,那么就需要编译大量的C语言文件。如果再用上面的将C文件和SV文件放在一起的编译方式,可能就容易混淆,且不容易编辑。其实VCS提供了在运行时动态加载DPI库的方法。在运行simv命令行之前执行以下步骤:
    1. 编译Verilog或SystemVerilog代码
      使用之前讲到的,不管是3-step还是2-step
    2. 编译C代码并创建共享对象,例如:
%> gcc -fPIC -Wall ${CFLAGS} -I${VCS_HOME}/include -I other_libraries -c test.c
%> gcc -fPIC -shared ${CFLAGS} -o test.so test.o
3. 使用以下运行时选项之一在simv运行时加载共享对象:

-sv_lib -sv_root -sv_liblist
-sv_lib 指定共享对象(.so文件的名字),不带后缀名
-sv_root 指定共享对象所在的位置
-sv_liblist 指定多个共享对象文件时,使用该运行时选项

%> simv -sv_lib test
%> simv -sv_liblist bootstrap_file
%> simv –sv_root path_relative_or_absolute_to_shared_object -sv_lib test

bootstrap_file文件内容如下:

#!SV_LIBRARIES
myclibs/lib1
myclibs/lib3
proj1/clibs/lib4
proj3/clibs/lib2

lib1,lib2,lib3和lib4是没有扩展名的情况下指定的共享对象文件名

  • PLI requires the use of table (*.tab) files to specify level of access needed for design objects
    %> vcs -P <file.tab> <file.so> <options>

1.3.8 Compiling for Debug

  • Goal: Perform interactive or post-simulation debug
    Want to keep design visibility
    Generate waveforms

  • Typical compile for post-simulation debug:
    Enables waveform generation (FSDB, VCD, etc)
    Minimum requirement for $dumpvars or $fsdbdumpvars
    %> vcs -debug_access+pp <options>

  • Typical compile for interactive debug:
    Enables full interactive Tcl and GUI debugging
    %> vcs -debug_access <options>

  • Enable full source-line debugging:
    Enables full debug and line-stepping (step, next, etc)
    Significant slowdown in simulation speed!
    %> vcs -debug_access+all <options>

1.3.9 Gate-level Simulation -Zero-delay

  • Why simulation in zero-delay mode?
    Speed! Speed! Speed!
    Significantly faster then SDF-annotated simulation
    Risk: Greater possibility of encountering race conditions

  • VCS Options:
    %> vcs +delay_mode_zero +nospecify <options>

  • Simulations failing?
    Most likely a race or zero-delay loop in the Verilog code

1.3.10 Gate-level Simulation -SDF

  • Applying SDF Annotation
    Recommendation: Use $sdf_annotate system task
    Part of Verilog standard
    Compatible with all simulators

  • s d f a n n o t a t e s y n t a x : ‘ sdf_annotate syntax: ` sdfannotatesyntax:sdf_annotate(“sdf_file”, <module_instance>,);where: <module_instance>is the scope where annotation starts <timing>is either: MINIMUM, TYPICAL, or MAXIMUM This is put inside an initial block in the Verilog netlist or TB top:initial $sdf_annotate(…);`

  • Applying SDF Annotation using the command line:
    %> vcs –sdf=[min|typ|max]:<instance_name>:<file.sdf>
    Simulator dependent

1.3.11 关于统一编译前端(Unified Compile front end)

统一编译前端
Unified Compile前端是VCS和Verdi编译器的集成,用于统一编译流程以进行仿真和调试。 Unified Compile前端使用VCS编译器脚本为Verdi编译知识库(KDB)。 因此,只需要为VCS和Verdi维护一个通用编译器脚本,以确保两个数据库之间的一致性。
Unified Compile前端提供的好处如下:

  • 单VCS和Verdi编译
  • 一致的HDL语言支持
  • 使用或处理VCS和Verdi选项的一致性

不管是2-step还是3-step流程均支持该编译模式。在2-step流程中,为vcs命令添加了“-kdb”选项,以便生成KDB。在3-step流程中,vlogan/vhdlan/vcs命令添加了“-kdb”选项。

Examples:
//使用VCS编译设计并生成VCS数据库和Verdi KDB

  • -kdb在VCS 2-step流程中
    %> vcs -kdb <compile_options> <源文件>

  • -kdb在VCS 3-step流程中

> vlogan -kdb <vlogan_options> <源文件>> vhdlan -kdb <vhdlan_options> <源文件>> vcs -kdb <top_name>

统一的编译前端,这种模式,使基于Verdi的debug,变得简单。后面我们会在调试技巧中,具体讲到如何联合Verdi,正确使用该功能。

  • 12
    点赞
  • 65
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值