Verilator介绍

Verilator是一种开源的Verilog/SystemVerilog仿真器,可用于编译代码以及代码在线检查,Verilator能够读取Verilog或者SystemVerilog文件,并进行lint checks(基于lint工具的语法检测),并最终将其转换成C++的源文件.cpp和.h。

Verilator不直接将Verilog HDL转换为C++或者SystemC,反之Verilator将代码编译成更快的优化过的并且支持多线程的模型,该模型被依次包装在(wrapped)在C++/SystemC模型中。这样就生成一个编译的Verilog模型,其功能和Verilog是一致的,但效率由于基于C++即使是单线程模型也可以10倍快于SystemC,100倍快于基于解释Verilog的仿真器,并且通过多线程可以进一步加速。

Verilator的优点:将Verilog/SystemVerilog转换成C++/SystemC,仿真速度快很多,如果有这方面的需求,那Verilator是不错的选择。

本节将先介绍下Verilator的安装以及基本的使用方法,所有操作均在Ubuntu16系统上实现。

Verilator安装

安装必要的软件包:

sudo apt-get install git perl python3 make autoconf g++ flex bison ccache
sudo apt-get install libgoogle-perftools-dev numactl perl-doc
sudo apt-get install libfl-dev
sudo apt-get install zlibc zlib1g zlib1g-dev

git上拷贝源代码:

git clone https://github.com/verilator/verilator

编译前的准备工作:

unset VERILATOR_ROOT  # For bash
cd verilator
git pull         # Make sure git repository is up-to-date
git tag          # See what versions exist

这里选择编译版本v4.210(最新版本会报错)

git checkout v4.210 

配置编译安装:

autoconf         # Create ./configure script
./configure      # Configure and create Makefile
make -j `nproc`  # Build Verilator itself (if error, try just 'make')
sudo make install

如果成功的话输入:

verilator --version

可以看到verilator的版本信息:

一个简单例子

下面我们看下官方示例,最简单的hello world代码,文件位置在verilator/examples/make_hello_c/下,主要两个文件:

top.v

// DESCRIPTION: Verilator: Verilog example module
//
// This file ONLY is placed under the Creative Commons Public Domain, for
// any use, without warranty, 2017 by Wilson Snyder.
// SPDX-License-Identifier: CC0-1.0// See also the EXAMPLE section in the verilator manpage/document.
module top;initial begin$display("Hello World!");$finish;end
endmodule

sim_main.cpp

// DESCRIPTION: Verilator: Verilog example module
//
// This file ONLY is placed under the Creative Commons Public Domain, for
// any use, without warranty, 2017 by Wilson Snyder.
// SPDX-License-Identifier: CC0-1.0
//======================================================================// Include common routines
#include <verilated.h>// Include model header, generated from Verilating "top.v"
#include "Vtop.h"int main(int argc, char** argv, char** env) {// See a similar example walkthrough in the verilator manpage.// This is intended to be a minimal example.  Before copying this to start a// real project, it is better to start with a more complete example,// e.g. examples/c_tracing.// Prevent unused variable warningsif (false && argc && argv && env) {}// Construct the Verilated model, from Vtop.h generated from Verilating "top.v"Vtop* top = new Vtop;// Simulate until $finishwhile (!Verilated::gotFinish()) {// Evaluate modeltop->eval();}// Final model cleanuptop->final();// Destroy modeldelete top;// Return good completion statusreturn 0;
}

MakeFile文件:

######################################################################
#
# DESCRIPTION: Verilator Example: Small Makefile
#
# This calls the object directory makefile.  That allows the objects to
# be placed in the "current directory" which simplifies the Makefile.
#
# This file ONLY is placed under the Creative Commons Public Domain, for
# any use, without warranty, 2020 by Wilson Snyder.
# SPDX-License-Identifier: CC0-1.0
#
######################################################################
# Check for sanity to avoid later confusionifneq ($(words $(CURDIR)),1)$(error Unsupported: GNU Make cannot build in directories containing spaces, build elsewhere: '$(CURDIR)')
endif####################################################################### This is intended to be a minimal example.  Before copying this to start a
# real project, it is better to start with a more complete example,
# e.g. examples/make_tracing_c.# If $VERILATOR_ROOT isn't in the environment, we assume it is part of a
# package install, and verilator is in your path. Otherwise find the
# binary relative to $VERILATOR_ROOT (such as when inside the git sources).
ifeq ($(VERILATOR_ROOT),)
VERILATOR = verilator
else
export VERILATOR_ROOT
VERILATOR = $(VERILATOR_ROOT)/bin/verilator
endifdefault:@echo "-- Verilator hello-world simple example"@echo "-- VERILATE & BUILD --------"$(VERILATOR) -cc --exe --build -j top.v sim_main.cpp@echo "-- RUN ---------------------"obj_dir/Vtop@echo "-- DONE --------------------"@echo "Note: Once this example is understood, see examples/make_tracing_c."@echo "Note: Also see the EXAMPLE section in the verilator manpage/document."######################################################################maintainer-copy::
clean mostlyclean distclean maintainer-clean::-rm -rf obj_dir *.log *.dmp *.vpd core

MakeFile中核心的编译语句其实就是执行:

verilator -Wall --cc --exe --build top.v sim_main.cpp

直接执行编译:

make

执行生成的C++可执行文件,结果如下:

可以看到C++实现了和verilog相同的功能。

配合gtkwave实现波形仿真

安装gtkwave

gtkwave同样是开源的工具其git地址为:

https://github.com/gtkwave/gtkwave.git

这里我们直接安装:

sudo apt-get install gtkwave

简单示例

以一个简单的逻辑组合为例:

top.v

module top(input a,input b,input c,input d,output f
);assign f = ~((a&b) | (~(c&d)));
endmodule

top_main.cpp

#include <stdio.h>
#include <stdlib.h>
#include <assert.h>#include "Vtop.h"  // create `top.v`,so use `Vtop.h`
#include "verilated.h"#include "verilated_vcd_c.h" //可选,如果要导出vcd则需要加上int main(int argc, char** argv, char** env) {VerilatedContext* contextp = new VerilatedContext;contextp->commandArgs(argc, argv);Vtop* top = new Vtop{contextp};VerilatedVcdC* tfp = new VerilatedVcdC; //初始化VCD对象指针contextp->traceEverOn(true); //打开追踪功能top->trace(tfp, 0); //tfp->open("wave.vcd"); //设置输出的文件wave.vcdwhile (!contextp->gotFinish()) {int a = rand() & 1;int b = rand() & 1;int c = rand() & 1;int d = rand() & 1;top->a = a;top->b = b;top->c = c;top->d = d;top->eval();printf("a = %d, b = %d, c = %d, d = %d, f = %d\n", a, b, c, d, top->f);tfp->dump(contextp->time()); //dump wavecontextp->timeInc(1); //推动仿真时间assert(top->f == ~((a&b) | (~(c&d))));}delete top;tfp->close();delete contextp;return 0;
}

执行编译:

verilator -Wall top.v top_main.cpp --cc --trace --exe --build
#增加了--trace 是为了显示波形的
./obj_dir/Vtop   //必须执行这个,才会出现.vcd文件,需要强制退出
gtkwave wave.vcd //如果报错缺少canberra-gtk-module,apt安装即可

结果如下图:

这一节先说到这里。

EDA开源仿真工具verilator入门1:安装和测试相关推荐

  1. EDA开源仿真工具verilator入门9:资料总结和最新版本安装

    前面的文章已经对verilator相关功能和流程进行了较详细的介绍,由于最近版本更新较多,并且很多粉丝希望有一个更完整的总结,特别是针对最新版本,本节将基于verilator最新版本,对资料和相关内容 ...

  2. EDA开源仿真工具verilator入门8:verilator 5.0 最新版本仿真玄铁性能对比

    verilator最新已经升级到到了5.005,新版本的verilator在功能上更加完善,加入对Semantic Scheduling算法标准的支持,但因此效率肯定会有所损失,本节将接上一节测试最新 ...

  3. EDA开源仿真工具verilator入门5:调试

    在源代码中调用UINFO表示一定debug等级下的打印,消息等级3以及低等级只需要标记 "--debug" 就可以,更高等级需要 "--debugi<level&g ...

  4. EDA开源仿真工具Verilator:简介及Hello World

    最近在学习Verilator背后的原理,本文对于Verilator的基本功能做了简要的叙述,并简要讲解了hello world的运行过程.也算是学习之中的一点笔记了! 更详细的内容,一定还是要看Ver ...

  5. TensorFlow 2快速入门之安装与测试

    文章目录 本地安装环境及要求 安装步骤 安装常见问题及解决 ModuleNotFoundError: No module named 'pip' Read timed out 解决方法 本地安装环境及 ...

  6. Ubuntu:Ubuntu下安装Anaconda和Tensorflow的简介、入门、安装流程之详细攻略

    Ubuntu:Ubuntu下安装Anaconda和Tensorflow的简介.入门.安装流程之详细攻略 目录 安装流程 1.安装nvidia显卡驱动 2.安装cuda8 3.安装Cudnn 4.Ana ...

  7. 【完结】给新手的12大深度学习开源框架快速入门项目

    文/编辑 | 言有三 这是一篇总结文,给大家来捋清楚12大深度学习开源框架的快速入门,这是有三AI的GitHub项目,欢迎大家star/fork. https://github.com/longpen ...

  8. 【github干货】主流深度学习开源框架从入门到熟练

    文章首发于微信公众号<有三AI> [github干货]主流深度学习开源框架从入门到熟练 今天送上有三AI学院第一个github项目 01项目背景 目前深度学习框架呈百家争鸣之态势,光是为人 ...

  9. 人工智能 - paddlepaddle飞桨 - 入门之安装教程

    人工智能 - paddlepaddle飞桨 - 入门之安装教程 快速安装 PaddlePaddle支持使用pip快速安装, 执行下面的命令完成CPU版本的快速安装: pip install -U pa ...

最新文章

  1. 图文并茂!60页PPT《快速入门python数据分析路线》(附链接)
  2. 文件的读取流和书写流
  3. C++的速度比Java快2.1%:来自计算100万以内质数的实验数据对比
  4. Java 随心笔记10
  5. Android后台杀死系列之二:ActivityManagerService与App现场恢复机制
  6. AngularJS HTML DOM
  7. 交换机千兆和百兆对网速影响_家里明明装了百兆宽带!为啥网速还这么慢?原因竟然在这!...
  8. 工作69:发布商品页面
  9. php获取表单元素的值,PHP如何获取表单提交的数据
  10. 移动机器人建图与导航代码实现——1.Hector SLAM
  11. js 正则表达式匹配定义及使用
  12. 西安西北大学计算机研究生学费,关于西北大学研究生学费及住宿的解答
  13. PMP/高项 项目立项管理
  14. 生产订单管理系统软件哪家好?
  15. 玉柴spn码故障对照表_玉柴电控柴油机故障代码及读码方法
  16. Idea插件开发-开发自己的第一款idea插件
  17. 个人网盘源码 本地网盘网站源码
  18. 使用jstack查看线程
  19. 上海市政府颁布《上海市居住证申办实施细则》
  20. 机器人操作系统ROS学习实战篇之------让小乌龟画矩形

热门文章

  1. 【51nod 3241】【堆】小明和他的同学们
  2. Qt Designer工具的使用
  3. 怎样判断一个网站是不是模板建站
  4. 计算机教学常规检查小结,小学教学常规检查自查报告范文
  5. 多款iPhone国内被禁售的背后,你真以为高通在助攻华为?
  6. 签到功能完成03《ivx低代码签到系统制作》
  7. 首位女性图灵奖获得者离世,曾开发上古语言COBOL编译器
  8. Android号码匹配位数修改 来电显示不匹配
  9. 基于jeesite+android开发 电子商务系统免费教程
  10. f:selectitem的Long 型等数值的转换问题