By default, SystemVerilog passes arrays by value, copying the entire array.
It is recommended that you use arrays by reference, if possible for performance reasons.
- If you want your function to modify the array, use
ref . - If you want your function to read an array, use
const ref .
Example:
function void pass_by_value(int array[5], int queue[$], int assoc[int]); // Default. // A copy of the arrays is made in this function endfunction function void pass_by_ref(ref int array[5], ref int queue[$], ref int assoc[int]); // Original arrays are being referenced endfunction function void pass_by_const_ref(const ref int array[5], const ref int queue[$], const ref int assoc[int]); // Original arrays are being referenced // And they can be read but cannot be modified in this function endfunction
Example on EDA Playground: http://www.edaplayground.com/x/2m9
source share