gpt4 book ai didi

c - 在 DPI-C 中,内部变量使用什么数据类型?

转载 作者:太空宇宙 更新时间:2023-11-04 08:01:45 26 4
gpt4 key购买 nike

在 EDA Playground 的 VCS 中使用 DPI-C,我没有得到以下代码的正确输出。我期望 6 作为答案,但无论 a 和 b 值如何,我每次都会得到 248。我已经尝试在 helloFromC.c 中使用 svLogic、int 和 unsigned char 作为 a_int 的数据类型。

module automatic test;

import "DPI-C" function void helloFromC(logic [2:0] a, logic [2:0] b);

initial run();

task run();
logic [2:0] a;
logic [2:0] b;
logic [2:0] c;
a = 3'b100;
b = 3'b010;
c = a+b;
$display("Output from SV is %0d", c);
helloFromC(a,b);

endtask

endmodule

这是我的C程序

#include <stdio.h>
#include <svdpi.h>


extern "C" int helloFromC(svLogic a, svLogic b) {
svLogic a_int = a+b;
printf("Output from C is %d", a_int);
return 0;
}

我得到的输出为

Output from SV is 6
Output from C is 248

最佳答案

svLogic 应该映射到单个位 logic。你有一个 vector (又名压缩数组),因此你应该使用 svLogicVecVal。它仍然是一个 4 态值,因此在 C 端执行的 SystemVerilog 值的算法操作可能无法按您预期的方式工作。在 SystemVerilog 端使用 bit [2:0] 并在 C 端使用 svBitVecVal 将如您期望的那样工作。或者简化事情并在两边使用 int

有关 DPI 的更多信息,请参阅 IEEE1800-2012第 35 节、附件 H 和附件 I。

关于c - 在 DPI-C 中,内部变量使用什么数据类型?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46113119/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com