0
\$\begingroup\$

Hi when I use the systemverilog, there are some confused point.

first one is distinguish about DPI and DPI-C.

as following example used DPI not DPI-C . but As I know DPI-C is used to in C.

CODE:SV_file.sv 
program main; 
logic a; 
import "DPI" function void show(logic a); 
initial begin 
a = 1'b0; 
show(a); 
a = 1'b1; 
show(a); 
a = 1'bX; 
show(a); 
a = 1'bZ; 
show(a); 
end 
endprogram 

CODE: C_file.v 
#include <stdio.h> 
#include <svdpi.h> 

void show(svLogic a){ 
if(a == 0) 
printf(" a is 0 \n"); 
else if(a == 1) 
printf(" a is 1 \n"); 
else if(a == 2) 
printf(" a is x \n"); 
else if(a == 3) 
printf(" a is z \n"); 

} 
RESULTS 

a is 0 
a is 1 
a is z 
a is x 

Would you let me know how to use the DPI and DPI-C?

\$\endgroup\$
2
\$\begingroup\$

The difference has to do with which version of the standard your C code is based on: "DPI" is from the older Accellera standard, and "DPI-C" is the current IEEE standard.

Then key difference between two versions is how packed arrays of bit or logic are represented when they are passed through as arguments. The older "DPI" version did not standardize the representation of packed arrays - you had to know your tool's specific representation, or use macros provided by the tool vendor to access individual bits. The current version standardizes the way you access bits of packed array, and that makes your C code binary compatible with any tool, meaning you don't have to recompile your DPI code for each tool vendor you work with. Annex H.13 of the IEEE 1800-2012 SystemVerilog LRM has more info on the differences.

My recommendation for "DPI-C" users is that unless you need access to 4-state values, keep your arguments C-compatible. That means using only ints, bytes(char) or unpacked array/structs of ints/bytes across the language boundary.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.