1

I would like my array of data from SystemVerilog have the entire copy of data from the array on the C/C++ side:

C/C++ code:

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 code:

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

My issue is that I don't know the exact size of the source array each time. Also, even if it was a fixed size every time, I would imagine having a long list of index arguments would be excessive for a large array. The other SV-DPI handler functions either don't seem to apply to my case or I must be misunderstanding how they are to be used.

Cit5
  • 400
  • 5
  • 19
  • how about passing array size along as a separate parameter? – Serge Jun 20 '21 at 14:39
  • @Serge actually I have done that already. My issue isn't with the SV side knowing the size, but it is with the actual assignment if the elements of the array. The functions I've used seem to only assign the first element of the source array – Cit5 Jun 20 '21 at 17:26
  • for that you need to provide a small reproducer example and show your bad/good results. – Serge Jun 21 '21 at 00:19

1 Answers1

1

You construct is called 'open array'. Standard defines a fiew functions which could be used to determine array parameters.

/*
* 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);

As an alternative method you can pass array size as a separate parameter to your function.

Serge
  • 11,616
  • 3
  • 18
  • 28