[sv-bc] RE: Q: [N] array bounds legal for unpacked but not packed arrays?

From: Brad Pierce <Brad.Pierce@synopsys.com>
Date: Tue Sep 30 2014 - 13:44:23 PDT
[In reply to http://www.eda.org/sv-bc/hm/11620.html .]
The current [0:N-1] default for unpacked array dimensions is also significant (and annoying). With the hardware order [N-1:0] you can split/merge dimensions fluidly, as in

typedef struct {int x, y;} T;

module test#(N=2,M=3)
(   output T A_2D[(2**N)-1:0][(2**M)-1:0]
,   output T A_1D[(2**(N+M))-1:0]
);


logic [N-1:0] idx_N;
logic [M-1:0] idx_M;

always_comb begin
   for (int i = 0; i < 2**N; i++) begin
     for (int j = 0; j < 2**M; j++) begin
       idx_N = i;
       idx_M = j;
       A_2D[idx_N][idx_M] = '{i,j};
       A_1D[{idx_N,idx_M}] = '{i,j};
       assert final (A_2D[idx_N][idx_M] == A_1D[{idx_N,idx_M}]);
     end
   end
end

endmodule

But with the [0:N-1] default you need to flip the order of dimensions in the indexes, as in

typedef struct {int x, y;} T;

module test#(N=2,M=3)
(   output T A_2D[0:(2**N)-1][0:(2**M)-1]
,   output T A_1D[0:(2**(N+M))-1]
);

logic [N-1:0] idx_N;
logic [M-1:0] idx_M;

always_comb begin
   for (int i = 0; i < 2**N; i++) begin
     for (int j = 0; j < 2**M; j++) begin
       idx_N = i;
       idx_M = j;
       A_2D[idx_N][idx_M] = '{i,j};
       A_1D[{idx_M,idx_N}] = '{i,j};
      assert final (A_2D[idx_N][idx_M] == A_1D[{idx_M,idx_N}]);
     end
   end
end

endmodule

-- Brad

-- 
This message has been scanned for viruses and
dangerous content by MailScanner, and is
believed to be clean.
Received on Tue Sep 30 13:46:04 2014

This archive was generated by hypermail 2.1.8 : Tue Sep 30 2014 - 13:46:11 PDT