【问题标题】:How can I copy data from C/C++ array to the entire SV array using SV-DPI?如何使用 SV-DPI 将数据从 C/C++ 数组复制到整个 SV 数组?
【发布时间】:2021-06-20 04:35:01
【问题描述】:

我希望 SystemVerilog 中的数据数组具有 C/C++ 端数组中数据的完整副本:

C/C++ 代码:

void myCfunc(svOpenArrayHandle results) {
    int randomsize;
    ...
    uint32_t myArray[randomsize];
    ...
    svPutBitArrElemVecVal(results, myArray, 1); // copies only the first element
    //svPutBitArrElemVecVal(results, myArray, 1, 2, 3); // still only copies the first element for some reason
    // svCopyArr(results, myArray); // this isn't a DPI function, but I would like do to something like this.
    // Copy the whole array, not just the an element
}

SV 代码:

module tb_top;
    int results[100];
    import "DPI-C" function myCfunc(output int results[]);
    ...
    initial begin
        myCfunc(results);
    end
endmodule : tb_top

我的问题是我每次都不知道源数组的确切大小。此外,即使每次都是固定大小,我会想象对于大型数组来说,拥有一长串索引参数将是多余的。其他 SV-DPI 处理程序函数似乎不适用于我的案例,或者我一定误解了它们的使用方式。

【问题讨论】:

  • 如何将数组大小作为单独的参数传递?
  • @Serge 实际上我已经这样做了。我的问题不在于 SV 方知道大小,而在于数组元素的实际分配。我使用的函数似乎只分配源数组的第一个元素
  • 为此,您需要提供一个小型复制器示例并展示您的坏/好结果。

标签: c++ arrays system-verilog system-verilog-dpi


【解决方案1】:

您的构造称为“开放数组”。标准定义了一些可用于确定数组参数的函数。

/*
* Open array querying functions
* These functions are modeled upon the SystemVerilog array
* querying functions and use the same semantics.
*
* If the dimension is 0, then the query refers to the
* packed part of an array (which is one-dimensional).
* Dimensions > 0 refer to the unpacked part of an array.
*/
/* h= handle to open array, d=dimension */
XXTERN int svLeft(const svOpenArrayHandle h, int d);
XXTERN int svRight(const svOpenArrayHandle h, int d);
XXTERN int svLow(const svOpenArrayHandle h, int d);
XXTERN int svHigh(const svOpenArrayHandle h, int d);
XXTERN int svIncrement(const svOpenArrayHandle h, int d);
XXTERN int svSize(const svOpenArrayHandle h, int d);
XXTERN int svDimensions(const svOpenArrayHandle h);

作为一种替代方法,您可以将数组大小作为单独的参数传递给您的函数。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-11-14
    • 1970-01-01
    • 2012-10-27
    • 1970-01-01
    • 2014-05-19
    相关资源
    最近更新 更多