Home / Learn Verilog / DPI: Call C from SystemVerilog
DPI: Call C from SystemVerilog
Mix languages.
In shortMix languages.
What's actually going on
What it is
The Direct Programming Interface lets SV call C functions and vice versa.
Why it matters
Reference models in C, file formats, math libraries.
Mechanically speaking
import "DPI-C" function ...
Shows up in
- Everyday RTL design
- FPGA and ASIC projects
- Testbenches and debugging
Try it
A reference model you could also write in CVerilog: edit and run
With DPI the function body would live in a C file.
// SystemVerilog\nimport "DPI-C" function int c_gcd(int a, int b);\n// C\nint c_gcd(int a, int b) { while (b) { int t = b; b = a % b; a = t; } return a; }Careful:This simulator runs the core of SystemVerilog (logic, always_ff, always_comb, enum, typedef, int, loops with int, break/continue, inside, immediate assert). Features shown only in the grey code box need a full simulator (Icarus -g2012, Verilator, Questa, VCS, Xcelium).
Check yourself
1. DPI connects SV with...
C/C++ code.