cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
j1s1e1
Observer
Observer
577 Views
Registered: ‎03-05-2010

Assignment to multidimensional localparam in function appears to be incorrect in simulator

Jump to solution

When assigning to a multidimensional localparm in a function as shown below:

`timescale 1ns / 1ps

module test_function_simple_tb();

parameter L=3, N = 15;
parameter int COEF[N] =  '{ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 };

localparam N_PART = (N + L - 1)/L;
int C1[L][N_PART];
localparam int C2[L][N_PART] = CalcCoefs();
localparam int C3[L][N_PART] = CalcCoefs2();

typedef int c_t[L][N_PART];

function c_t CalcCoefs();
  CalcCoefs = '{default : 0};
  for (int i = 0; i < N; i++)
    CalcCoefs[i%L][i/L] = COEF[i];
endfunction

function c_t CalcCoefs2();
  int C[N_PART];
  CalcCoefs2 = '{default : 0};
  for (int i = 0; i < L; i++)
    begin
      for (int j = 0; j < N_PART; j++)
        C[j] = COEF[i+L*j];
      CalcCoefs2[i] = C;
    end
endfunction

task WriteMatrix(string name, c_t M);
  $write("%s ", name);
    for (int i = 0; i < L; i++)
      for (int j = 0; j < N_PART; j++)
        $write("%3d ", M[i][j]);
  $write("\n");
endtask

initial
  begin
    C1 = CalcCoefs();
    WriteMatrix("C1", C1);
    WriteMatrix("C2", C2);
    WriteMatrix("C3", C3);
    $stop;
  end

endmodule

the resulting parameter array in Vivado Simulator (2018.3) is incorrect.  The above file shows that the function works by using it with a regular logic array. 

The results are as follows:

C1 1 4 7 10 13 2 5 8 11 14 3 6 9 12 15          This is the correct result using the function with logic
C2 3 6 9 12 15 3 6 9 12 15 3 6 9 12 15          Incorrect result as a localparam
C3 1 4 7 10 13 2 5 8 11 14 3 6 9 12 15          Workaround using more complicated function with localparam

The C2 result above shows all rows being assigned the final row value (Matrix is 3 rows by 5 columns)  In the workaround, I made the assignments to all values in each row and then assigned the rows in the localparam.

This appears to be a bug in the simulator.

Thanks,

James

 

Tags (1)
0 Kudos
1 Solution

Accepted Solutions
j1s1e1
Observer
Observer
456 Views
Registered: ‎03-05-2010

This issue is fixed in Vivado 2020.1

View solution in original post

0 Kudos
1 Reply
j1s1e1
Observer
Observer
457 Views
Registered: ‎03-05-2010

This issue is fixed in Vivado 2020.1

View solution in original post

0 Kudos