默认情况下,SystemVerilog是按值还是引用传递数组?
例如:
int array[5] = '{0,1,2,3,4};
some_function(array); // <-- value or reference?
答案 0 :(得分:16)
默认情况下,SystemVerilog按值传递数组,复制整个数组。
出于性能原因,建议尽可能通过引用传递数组。
ref
。const ref
。示例:
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
EDA游乐场示例:http://www.edaplayground.com/x/2m9