2014-04-30 17 views

Odpowiedz

15

domyślnie SystemVerilog przechodzi przez tablice wartości, kopiowanie całą tablicę.

Zaleca się przekazywanie tablic przez odniesienie, gdy tylko jest to możliwe ze względu na wydajność.

  • Jeśli chcesz, aby Twoja funkcja modyfikowała tablicę, użyj ref.
  • Jeśli chcesz, aby twoja funkcja odczytała tablicę, użyj const ref.

przykład:

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 

przykład w EDA zabaw: http://www.edaplayground.com/x/2m9

Powiązane problemy