没有合适的资源?快使用搜索试试~ 我知道了~
verilog_PLI_versus_SystemVerilog_DPI.pdf
需积分: 19 11 下载量 110 浏览量
2020-10-15
14:35:44
上传
评论 1
收藏 71KB PDF 举报
温馨提示


试读
18页
verilog_PLI_versus_SystemVerilog_DPI.pdf
资源推荐
资源详情
资源评论



















SNUG San Jose 2004 1 The PLI Is Dead (maybe)—Long Live The DPI
The Verilog PLI Is Dead (maybe)
Long Live The SystemVerilog DPI!
Stuart Sutherland
Sutherland HDL, Inc.
stuart@sutherland-hdl.com
ABSTRACT
In old England, when one monarch died a successor immediately took the throne. Hence the
chant, “The king is dead—long live the king!”. The Verilog Programming Language Interface
(PLI) appears to be undergoing a similar succession, with the advent of the new SystemVerilog
Direct Programming Interface (DPI). Is the old Verilog PLI dead, and the SystemVerilog DPI the
new king? This paper addresses the question of whether engineers should continue to use the
Verilog PLI, or switch to the new SystemVerilog DPI. The paper will show that the DPI can
simplify interfacing to the C language, and has capabilities that are not possible with the PLI.
However, the Verilog PLI also has unique capabilities that cannot be done using the DPI.
Table of Contents
1.0 Introduction ............................................................................................................................2
2.0 An overview of the DPI .........................................................................................................2
3.0 Verilog PLI capabilities .........................................................................................................3
3.1 How the PLI calls C functions ..................................................................................... 3
3.2 The evolution of the Verilog PLI ................................................................................. 4
3.3 Verilog PLI standards — Where they’ve been and where they’re heading ................ 6
4.0 A more detailed look at the SystemVerilog DPI ...................................................................7
4.1 The DPI import declaration ......................................................................................... 8
4.2 Function formal arguments .......................................................................................... 8
4.3 Function return values ................................................................................................. 9
4.4 Data type restrictions ................................................................................................... 9
4.5 Pure, context and generic C functions ....................................................................... 10
4.6 Referencing PLI libraries from DPI functions ........................................................... 11
5.0 Exporting Verilog tasks and functions .................................................................................11
6.0 Using the DPI to interface to C++, SystemC, and other languages .....................................12
7.0 Does the SystemVerilog DPI replace the Verilog PLI? ......................................................13
8.0 Conclusions ..........................................................................................................................16
8.1 When to use the DPI .................................................................................................. 16
8.2 When to use the PLI ................................................................................................... 16
8.3 Can the PLI 1.0 standard be deprecated? ................................................................... 17
8.4 The correct chant ....................................................................................................... 17
9.0 References ............................................................................................................................17
10.0 Glossary of acronyms ..........................................................................................................17
11.0 About the author ..................................................................................................................18

SNUG San Jose 2004 2 The PLI Is Dead (maybe)—Long Live The DPI
1.0 Introduction
The Verilog Programming Language Interface (PLI) provides a mechanism for Verilog code to
call functions written in the C programming language. The venerable Verilog PLI is one of the
reasons the Verilog language has been so successful for hardware design. Using the PLI, third
party companies and end-users can extend the capabilities of commercial Verilog simulators.
Virtually every serious design project using Verilog has utilized the Verilog PLI.
Over its nearly 20 year history, the Verilog PLI has seen two major generations, often referred to
as “PLI 1.0” and “PLI 2.0” (officially called the PLI-VPI). Accellera has recently introduced the
“SystemVerilog” extensions to the IEEE Verilog standard, which includes a new way for Verilog
code to call C and C++ functions. This new interface is called the “Direct Programming
Interface” or “DPI”. Some engineers feel that the advent of the SystemVerilog DPI marks the
demise of the old Verilog PLI. That is, that the DPI replaces the complex Verilog PLI with a
simple and straight forward C language interface. Does SystemVerilog make the Verilog PLI
obsolete? Can we all chant “The Verilog PLI is dead—long live the SystemVerilog DPI!” ?
Before the celebration begins, however, there are some important questions to answer. Is the
SystemVerilog DPI really better than the Verilog PLI, or are there good reasons to continue to use
the PLI? Are there applications that cannot be done using the SystemVerilog DPI, that will
necessitate keeping the Verilog PLI alive?
2.0 An overview of the DPI
The SystemVerilog Direct Programming Interface (DPI) allows Verilog code to call the names of
C functions as if the function were a native Verilog task or function (a task or function defined in
the Verilog language). This is done by importing the C function name into the Verilog language,
using a simple import statement. The import statement defines that the function uses the DPI
interface, and contains a prototype of the function name and arguments. For example:
import "DPI" function real sin(real in); // sine function in C math library
This import statement defines the function name sin for use in Verilog code. The data type of the
function return is a
real value (double precision) and the function has one input, which is also a
real data type. Once this C function name has been imported into Verilog, it can be called the
same way as a native Verilog language function. For example:
always @(posedge clock) begin
slope <= sin(angle); // call the "sin" function from C
end
The imported C function must be compiled and linked into the Verilog simulator. This process
will vary with different simulators. With the Synopsys VCS simulator, the process is very
straightforward; the C source file name, or a pre-compiled object file name, is listed along with
Verilog source code files as part of the
vcs compile command.
With the SystemVerilog DPI, the Verilog code is unaware that it is calling C code, and the C
function is unaware that it is being called from Verilog.

SNUG San Jose 2004 3 The PLI Is Dead (maybe)—Long Live The DPI
DPI compared to PLI. The ability to import a C function and then directly call the function
using the DPI is much simpler than the Verilog PLI. With the PLI, users must define a user-
defined system task or user-defined system function. The user-defined system task/function name
must begin with a dollar sign ( $ ). For example, the sine function above might be represented in
Verilog with $sine. This function is then associated with a user-supplied C function known as a
calltf routine. The calltf routine can then invoke the
sin function from the C math library. The
calltf routine, and any functions it calls, must then be compiled and linked into the Verilog
simulator. Once these steps have been performed, the
$sine system function can then be called
from within Verilog in the same way as a regular function. When simulation executes the call to
$sine, it will invoke the C calltf function that can then call the C sin function.
always @(posedge clock) begin
slope <= $sine(angle); // call the sine PLI application
end
At first glance, it might seem that within the Verilog code, there is very little difference between
using the PLI function and an imported DPI function. Indeed, within the Verilog code, there is no
significant difference; in both cases, the Verilog code is calling a task or function. Where the
difference becomes apparent—and it is a significant difference—is in what it takes to define the
PLI user-defined system task or system function. Using the DPI, the Verilog code can directly call
the sin function from the C math library, directly pass inputs to the function, and directly receive
a return value from the C function. Using the PLI, several steps are required to create a user-
defined system task that indirectly calls and passes values to the sin function. This indirect
process is described in more detail in the following section.
3.0 Verilog PLI capabilities
In order to fully discuss the strengths and weaknesses of the SystemVerilog DPI, it is necessary to
understand the capabilities of the Verilog PLI, and the C libraries that are part of the PLI standard.
The Verilog PLI is a simulation interface. It provides run-time access to the simulation data
structure, and allows user-supplied C functions a way to access information within the simulation
data structure. This user-supplied C function can both read and modify certain aspects of the data
structure. The Verilog PLI does not work with Verilog source code. It only works with a
simulation data structure. The PLI is not designed for use with tools other than simulation, such as
synthesis compilers.
3.1 How the PLI calls C functions
The Verilog PLI provides a set of C language functions that allow programmers to access the data
structure of a Verilog simulation. These C functions are bundled into three PLI libraries, referred
to as the TF library, the ACC library and the VPI library. The PLI access to the simulation data
structure is dynamic, in that it occurs while simulation is running. The access is also bidirectional.
Through the PLI, a programmer can both read information from the simulator’s data structure,
and modify information in the data structure.
The Verilog PLI allows programmers to extend the Verilog language though the creation of
system tasks and system functions. The names of these user-defined system tasks and functions

SNUG San Jose 2004 4 The PLI Is Dead (maybe)—Long Live The DPI
must begin with a dollar sign ( $ ). A task in Verilog is analogous to a subroutine. When a task is
called, the simulator’s instruction flow branches to a subroutine. Upon completion of the task, the
instruction flow returns back to the instruction following the task call. Verilog tasks do not return
values, but can have input, output and inout (bidirectional) formal arguments. A function in
Verilog is analogous to functions in most languages. When a function is called, it executes a set of
instructions, and then returns a value back to the statement that called the function. Verilog tasks
and functions can be defined as part of the Verilog language.
Using the Verilog PLI, a programmer must first define a system task function name, such as
$sine. The programmer then creates a C function referred to as a calltf routine, which will be
associated with the $sine task/function name. When simulation executes the statement with the
$sine system function call, the simulator calls the calltf routine associated with $sine. This calltf
routine is a layer between $sine and the sin function in the C math library. The arguments to
$sine are not passed directly to the calltf routine. Instead, the calltf routine must call special PLI
functions from a PLI library to read the input argument of $sine. The calltf routine can then call
the sin function, passing the input to the function. The calltf routine will receive the return value
from the sin function, and then call another special PLI function to write this return value back to
the $sine function. A final step when using the Verilog PLI is to bind the user-defined system
task/function name with the user-defined calltf routine. This step is different for each simulator,
and can range from editing a special table file to editing and compiling a complex C language file.
The PLI libraries allow a calltf routine to do more than just work with the arguments of a system
task or function. The libraries also allow a calltf application to search for objects in the simulation
data structure, modify delays and logic values in the data structure, and synchronize to simulation
activity and simulation time.
3.2 The evolution of the Verilog PLI
The Verilog PLI was originally developed in the mid to late 1980s as a proprietary interface to the
Gateway Design Automation Verilog-XL simulator product (now owned by Cadence Design
Systems). Gateway developed the PLI to satisfy two fundamental needs: First was to allow
Verilog-XL users a mechanism to use the C language for tasks such as file I/O. Second was to
provide a mechanism for ASIC foundries to analyze the usage of their standard cell libraries in
order to calculate accurate propagation delays within each cell instance. From these two
fundamental intents, the usage of the Verilog PLI has expanded in many ways. Common
applications of the Verilog PLI in today’s engineering environments include: commercial and
proprietary waveform viewers, commercial and proprietary design debug utilities, RAM/ROM
program loaders, scan chain vector loaders, custom file readers and writers, power analysis,
circuit tracing, C model interfaces, co-simulation environments, parallel process distribution, and
much, much more. The ways in which the PLI can be used to extend Verilog simulators is limited
only by the imagination of programmers.
The following paragraphs introduce the several generations of the Verilog PLI.
1985 — the TF interface. The first generation of the Verilog PLI is referred to as the Task/
Function interface, or TF interface. The TF interface comprises a set of C language functions
defined in a library file called verisuer.h. These C functions are typically referred to as the TF
routines. The primary purpose of the TF routines is to allow task/function arguments to be passed
剩余17页未读,继续阅读
资源评论


hwzjj
- 粉丝: 1
- 资源: 16
上传资源 快速赚钱
我的内容管理 展开
我的资源 快来上传第一个资源
我的收益
登录查看自己的收益我的积分 登录查看自己的积分
我的C币 登录后查看C币余额
我的收藏
我的下载
下载帮助


安全验证
文档复制为VIP权益,开通VIP直接复制
