是否可以将 System Verilog 函数编译为 C 或 C++?

发布于 2024-11-06 05:36:24 字数 289 浏览 6 评论 0 原文

我正在开发一个用 C++ 编写的高级模拟器,用于一些用 System Verilog 编写的硬件。

System Verilog 代码包括许多仅包含逻辑的函数(即不耗时,没有触发器)。我想在我的 C++ 模拟器中重用此代码。

有没有办法通过以下方式在 C++(或 C,很容易链接到 C++)中重用这些函数:

  • 在编译之前将 System Verilog 转换为 C/C++?
  • 将系统 Verilog 编译为可由 C/C++ 调用的函数?
  • 还有其他办法吗?

I work on a high-level simulator written in C++ for some hardware that is written in System Verilog.

The System Verilog code includes a number of functions that contain only logic (that is, nothing time-consuming, no flip-flops). I want to reuse this code in my C++ simulator.

Is there any way to reuse these functions in C++ (or C, which is easily linked into C++) by way of:

  • Converting System Verilog to C/C++ before compilation?
  • Compiling the System Verilog to functions callable by C/C++?
  • Any other way?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

小红帽 2024-11-13 05:36:24

通常,这种集成是在另一个方向完成的,这意味着从 Verilog 调用 C/C++ 例程。当然,这仅对验证组件有意义,显然无法合成。最有可能实现您想要的环境是 SystemC/Verilog 协同仿真,但这意味着同时使用 Verilog 模拟器(您明确不想要)和使用 SystemC 的 C 模型。

寻求高性能的模拟器通常会生成 C 或本机代码。我不知道有什么方法可以从 VCS(我最熟悉的模拟器)中生成的代码中提取特定功能,但使用其中一个开源模拟器可能可以做到这一点。任何商业(即许可的)模拟器都不可能支持生成无需许可证即可运行的代码。我不确定您想要使用独立于模拟器的 Verilog 功能的愿望是否是由许可、运行时开销、工具安装负担或其他因素驱动的。

我假设您不维护 SystemVerilog 例程,因此可能无法更改它们的实现方式。然而,如果可能的话,当 C 和 Verilog 中都需要功能时,一种常见策略是编写可以将单个定义转换为 C 和 Verilog 实现的代码生成器。

另一种更深奥的可能性是 SystemC 综合。它相对较新,我没有这方面的经验,但如果您可以使用这些工具并且它们适用于您的功能,那么您将可以重用 C 实现来进行 C 模型、硬件仿真和综合。

Typically this kind of integration is done in the other direction, meaning calling C/C++ routines from Verilog. Of course, that only makes sense for verification components, obviously that can't be synthesized. The most likely environment to do what you want is a SystemC/Verilog cosimulation, but that implies both the use of a Verilog simulator (which you explicitly don't want), and a C model using SystemC.

Simulators seeking high performance often generate C or native code. I'm not aware of any way to extract specific functions from the generated code in VCS (the simulator I'm most familiar with), but it might be possible to do so with one of the open source simulators. Any commercial (i.e., licensed) simulator is unlikely to support generating code that you can run without a license. I'm not sure if your desire to use the Verilog functions independent of the simulator is driven by licensing, runtime overhead, tool installation burden, or something else entirely.

I'm assuming you don't maintain the SystemVerilog routines, so it may not be possible to change the way they're implemented. However, if it is possible, one common strategy when functionality is needed both in C and in Verilog is to write code generators that can transform a single definition into C and Verilog implementations.

Another more esoteric possibility is SystemC synthesis. It is relatively new and I don't have experience with it, but if you have access to the tools and they work for your functions, it would allow you to reuse a C implementation for C models, hardware simulation, and synthesis.

芯好空 2024-11-13 05:36:24

快速搜索带来了 Verilog2C++验证器。我没有使用过这些程序;你需要亲自尝试一下。

A quick search brought Verilog2C++ and Verilator. I haven't used these programs; you need to try them yourself.

不羁少年 2024-11-13 05:36:24

如果您有底层 SV/Verilog 模拟器(例如免费的 Icarus/CVC),那么您可以使用 DPI。其他人可以尝试 Verilator - 我猜它更多的是 Verilog/V2K 而不是 SV,也许你可以将你的 SV 代码映射到 Verilog?

If you have an underlying SV/Verilog simulator (such as free ones à la Icarus/CVC) then you could use DPI. Else one could try Verilator - I guess it is more of Verilog/V2K than SV, maybe you can map your SV code to Verilog?

情绪 2024-11-13 05:36:24

Verilator 是实现您目的的绝佳工具。基本上,Verilator 可以将您的设计编译为 C++ 类,它代表您的顶级模块。然后,您可以通过在自定义 C++ 代码中驱动和刺激 C++ 类来模拟设计。

Verilator还支持DPI接口,这意味着您可以将Verilog函数/任务导出为C++函数,并导入C++函数以在Verilog代码中使用。

Verilator is a great tool for your purpose. Basically Verilator can compile your design to a C++ class which is a representation of the your top-level module. Then you can simulate the design by driving and stimulating the C++ class in your custom C++ code.

Verilator also support DPI interfaces, which means you can export Verilog function/task to C++ functions and import C++ function to be used in Verilog code.

2024-11-13 05:36:24

关于 verilator 和 DPI,您可能想看看我是如何评估它的:

“...为了练习 cpp (c++) 验证平台,使用系统 verilog DPI,使用 verilog DUT,我决定下载 verilator 并做一些自学练习。

首先,我在 debian 机器上安装了该软件:
apt-get 安装 verilator...”
http://bknpk.ddns.net/my_web/SystemC_MyFirst/verilator_my_first.html

Regarding verilator and DPI you may want to take a look at how I evaluated it:

"... In order to practice cpp (c++) verification benches, with system verilog DPI, using a verilog DUT, I decided to download verilator and do some self study exercises.

First I installed the software. This is fairly simple on a debian machine:
apt-get install verilator..."
http://bknpk.ddns.net/my_web/SystemC_MyFirst/verilator_my_first.html

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文