2004-SNUG-Presentation Verilog PLI Versus SystemVerilog DPI
2004-SNUG-Presentation Verilog PLI Versus SystemVerilog DPI
2004-SNUG-Presentation Verilog PLI Versus SystemVerilog DPI
The Verilog PLI Is Dead (maybe)... Long Live The SystemVerilog DPI!
Stuart Sutherland
Sutherland HDL, Inc. Portland, Oregon [email protected]
Objectives
! Introduce the SystemVerilog DPI ! Verilog PLI strengths and weaknesses ! Show how the SystemVerilog DPI works ! Compare and contrast PLI and DPI ! Decide if the PLI is finally dead
The Verilog PLI is Dead (maybe) ... Long Live the SystemVerilog DPI! by Stuart Sutherland, Sutherland HDL, Inc.
A Verilog function
import "DPI" function real sin(real in); //sin function in C math lib
always @(a, b, opcode) case (opcode) //call function SINE: result = sin(a); ...
The Verilog PLI is Dead (maybe) ... Long Live the SystemVerilog DPI! by Stuart Sutherland, Sutherland HDL, Inc.
Whats Next
The PLI is a protecting layer between user programs and simulation data structure
Verilog Simulation
PLI
C Program
Indirect access through PLI libraries C program cannot directly read or modify the simulation data Protects the simulator from bad C programs Protects C programs from bad Verilog code
The Verilog PLI is Dead (maybe) ... Long Live the SystemVerilog DPI! by Stuart Sutherland, Sutherland HDL, Inc.
PLI Libraries
TF library (introduced in 1985)
Provides access to system task/function arguments Provides synchronization to simulation time and events
NOTE! The IEEE is considering deprecating (removing) the TF and ACC libraries from the 1364 standard
Only the VPI library supports the new Verilog-2001 features Only the VPI library will support SystemVerilog enhancements
The Verilog PLI is Dead (maybe) ... Long Live the SystemVerilog DPI! by Stuart Sutherland, Sutherland HDL, Inc.
Can find any modeling object anywhere in the data structure Can synchronize to simulation time
After blocking assignments, after nonblocking assignments, after all events, at future simulation times, etc.
10
The Verilog PLI is Dead (maybe) ... Long Live the SystemVerilog DPI! by Stuart Sutherland, Sutherland HDL, Inc.
11
Whats Next
" Introduce the SystemVerilog DPI " Verilog PLI strengths and weaknesses
! Show how the SystemVerilog DPI works ! Compare and contrast PLI and DPI ! Decide if the PLI is finally dead
12
import "DPI" function real sin(real in); //sin function in C math lib
always @(a, b, opcode) case (opcode) //call function SINE: result = sin(a); ...
Can directly call C functions from Verilog Do not need to define complex PLI system tasks/functions Can directly pass values to and from C functions Do not need the complex PLI libraries to read/write values
The Verilog PLI is Dead (maybe) ... Long Live the SystemVerilog DPI! by Stuart Sutherland, Sutherland HDL, Inc.
13
14
import "DPI" function real sin(real in); //sin function in C math lib
The Verilog PLI is Dead (maybe) ... Long Live the SystemVerilog DPI! by Stuart Sutherland, Sutherland HDL, Inc.
15
16
real shortreal chandle string enum (using default int type) bit (2-state type, any vector size)
logic (4-state type, any vector size) packed array unpacked array
The Verilog PLI is Dead (maybe) ... Long Live the SystemVerilog DPI! by Stuart Sutherland, Sutherland HDL, Inc.
17
Arrays (unpacked)
Can be passed to equivalent C arrays Must use compatible types within the structure or union The array indexing might change (C must always starts with 0)
18
Compatibility Warning!
Warning! Warning! It is the users responsibility to correctly declare compatible data types in an import statement
Improper declarations can lead to unpredictable run-time behavior The DPI does not check for type compatibility The DPI does not provide a way to check and adjust for the data types on the Verilog side (the PLI can do this)
The Verilog PLI is Dead (maybe) ... Long Live the SystemVerilog DPI! by Stuart Sutherland, Sutherland HDL, Inc.
19
Imported functions cannot return 1-bit values, vectors, structures, unions, or enumerated types
Warning!
It is the users responsibility to correctly declare an import statement that matches the C function return value Incorrect import declarations can lead to unexpected behavior
20
Must have a return value; cannot have output or inout arguments Cannot call any other functions or use static or global variables Can be highly optimized for simulation performance Advantage! A context function is aware of the Verilog scope in which it is imported
import DPI context task print(input int file_id, input bit [127:0] data);
Can be a void function, and can have output and inout arguments Can call functions from C libraries (for file I/O, etc.) Can call many of the functions in the PLI libraries (more on this later) A generic function is one that is not declared as pure or context Can be a void function, and can have output and inout arguments Can call other C functions Cannot call most functions in the PLI libraries
The Verilog PLI is Dead (maybe) ... Long Live the SystemVerilog DPI! by Stuart Sutherland, Sutherland HDL, Inc.
21
Declaration Warning!
You must do this right! It is the users responsibility to correctly declare pure and context functions
The DPI does not check for proper declarations Improper declarations can lead to unpredictable simulation behavior Improper declarations can lead to software crashes
22
export DPI sync_reset; ... Export declarations do not have argument prototypes endmodule
The Verilog PLI is Dead (maybe) ... Long Live the SystemVerilog DPI! by Stuart Sutherland, Sutherland HDL, Inc.
23
Direct calls to C make it transparent that the Verilog model is calling SystemC code
Verilog code can directly call an imported C function that connects to the SystemC model Values can be directly passed to and from the SystemC model
24
Whats Next
" Introduce the SystemVerilog DPI " Verilog PLI strengths and weaknesses " Show how the SystemVerilog DPI works
! Compare and contrast PLI and DPI ! Decide if the PLI is finally dead
The Verilog PLI is Dead (maybe) ... Long Live the SystemVerilog DPI! by Stuart Sutherland, Sutherland HDL, Inc.
25
TF Interface
ACC Interface
VPI Interface
Indirectly call C functions from Verilog code by associating the C function with a user-defined system task or system function name
(no equivalent) Synch to simulators event scheduler
26
Danger!
The Verilog PLI is Dead (maybe) ... Long Live the SystemVerilog DPI! by Stuart Sutherland, Sutherland HDL, Inc.
27
28
NOTE: The DPI context is not the same as the PLI context
DPI context is the scope in which the import declaration occurs Matches the behavior of native Verilog task and functions PLI context is the scope in which a system task is called Context functions cannot fully utilize the PLI libraries Cannot use PLI checktf and misctf routines Cannot access all objects in the simulation data structure
The Verilog PLI is Dead (maybe) ... Long Live the SystemVerilog DPI! by Stuart Sutherland, Sutherland HDL, Inc.
29
Whats Next
" Introduce the SystemVerilog DPI " Verilog PLI strengths and weaknesses " Show how the SystemVerilog DPI works " Compare and contrast PLI and DPI
! Decide if the PLI is finally dead
30
Conclusion
The Verilog PLI and the SystemVerilog DPI are both needed Use the DPI to
Directly call C functions that do not need to access the simulation data structure Directly call PLI applications that only need limited access to the simulation data structure Interface to C and SystemC models
The Verilog PLI is Dead (maybe) ... Long Live the SystemVerilog DPI! by Stuart Sutherland, Sutherland HDL, Inc.
31
The PLI TF/ACC libraries are dead... long live the PLI VPI and the SystemVerilog DPI, together!
The DPI greatly simplifies many applications The VPI replaces the old TF and ACC libraries
32
Questions?
The Verilog PLI is Dead (maybe) ... Long Live the SystemVerilog DPI! by Stuart Sutherland, Sutherland HDL, Inc.
33
Develops and presents expert-level Verilog, PLI and SystemVerilog training courses
34
IEEE 1364-1995
Standardized PLI 1.0 as TF and ACC libraries Rewrite of PLI 2.0 to be backward compatible, called VPI library
The Verilog PLI is Dead (maybe) ... Long Live the SystemVerilog DPI! by Stuart Sutherland, Sutherland HDL, Inc.
35
from C / C++
dynamic arrays associative arrays references globals enum typedef structures unions casting const break continue return dowhile ++ -- += -= *= /= >>= <<= >>>= <<<= &= |= ^= %=
3.1a
classes inheritance strings int shortint longint byte shortreal void alias
3.0
Verilog-2001
ANSI C style ports generate localparam constant functions standard file I/O $value$plusargs `ifndef `elsif `line @* (* attributes *) configurations memory part selects variable part select multi dimensional arrays signed types automatic ** (power operator)
Verilog-1995
modules parameters function/tasks always @ assign $finish $fopen $fclose $display $write $monitor `define `ifdef `else `include `timescale initial disable events wait # @ forkjoin wire reg integer real time packed arrays 2D memory beginend while for forever ifelse repeat + = * / % >> <<
36