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

From: Arturo Salz <Arturo.Salz@synopsys.com>
Date: Tue Sep 30 2014 - 14:06:25 PDT
Recall that the [0:N-1] ordering was also chosen because it matches the ordering of dynamic arrays and queues. Also compatibility with C/C++ is important when dealing with DPI.

                Arturo

From: owner-sv-bc@eda.org [mailto:owner-sv-bc@eda.org] On Behalf Of Rich, Dave
Sent: Tuesday, September 30, 2014 1:58 PM
To: Brad Pierce; sv-bc@eda.org
Subject: [sv-bc] RE: Q: [N] array bounds legal for unpacked but not packed arrays?

The current [0:N-1] ordering was chosen to match array index ordering in C/C++.

IMHO, [N] should never been allowed as a shortcut in a language that already supported ranges in either order because of the confusion it creates. Erik's workaround example is proof of that.

But it's too late to change the default range order now for an unpacked array now.

Dave


From: owner-sv-bc@eda.org<mailto:owner-sv-bc@eda.org> [mailto:owner-sv-bc@eda.org] On Behalf Of Brad Pierce
Sent: Tuesday, September 30, 2014 1:44 PM
To: sv-bc@eda.org<mailto:sv-bc@eda.org>
Subject: [sv-bc] RE: Q: [N] array bounds legal for unpacked but not packed arrays?

[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<http://www.mailscanner.info/>, and is
believed to be clean.

--
This message has been scanned for viruses and
dangerous content by MailScanner<http://www.mailscanner.info/>, and is
believed to be clean.

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

This archive was generated by hypermail 2.1.8 : Tue Sep 30 2014 - 14:07:06 PDT