Project

General

Profile

[logo] 
 
Home
News
Activity
About/Contact
Major Tools
  Dinotrace
  Verilator
  Verilog-mode
  Verilog-Perl
Other Tools
  BugVise
  CovVise
  Force-Gate-Sim
  Gspice
  IPC::Locker
  Rsvn
  SVN::S4
  Voneline
  WFH
General Info
  Papers

Error on indexing the multiple dimensional array (MDA)

Added by Yu Sheng Lin 5 months ago

I am using v4.012 and find a problem on slicing MDA non-power-of-2 array with variables. In the following example, if I compile with +define+OK then everything is fine. However, if not using +define+OK, then since in a <= A[i], A is of size 7, so it gives an error. The error happens when the array size is non-power-of-2 and the index is larger than the array size.

module M(input clk, input [2:0] i);
int A [7][1], B [8][1];
int a    [1], b    [1];

always_ff @(posedge clk) begin
`ifdef OK
    a <= A[0];
    b <= B[i];
`else
    a <= A[i];
    b <= B[0];
`endif
end
endmodule
Also, the error message is confusing.
CONST '32'h0' is not an unpacked array, but is in an unpacked array context

Is there any plan to fix this bug? Or can you provide instructions about fixing this?


Replies (4)

RE: Error on indexing the multiple dimensional array (MDA) - Added by Wilson Snyder 5 months ago

As you noted this is an error, but the message is confusing because the out-of-bounds gets converted to a constant before it does the slicing. I'll see how to fix this.

RE: Error on indexing the multiple dimensional array (MDA) - Added by Yu Sheng Lin 4 months ago

Also, sometimes the error message is

%Error: AND is not an unpacked array, but is in an unpacked array context

. Inspecting the tree through --debug, it seems that the RHS is converted into an AND operation between 23_inline and 25_const. Here I use "input [3:0] i", "input logic A [7][3]", and "output logic a [3]", assigning "a <= A[i]".

    1:2:2:1: CONDBOUND 0x55acc70f2bd0 <e381> {e7} @dt=0x55acc70e9270@(w1)u[0:2]
    1:2:2:1:1: GTE 0x55acc70f2c90 <e377> {e7} @dt=0x55acc70f0d70@(G/nw1)
    1:2:2:1:1:1: CONST 0x55acc70f2d50 <e366> {e7} @dt=0x55acc70ec190@(G/w3)  3'h6
    1:2:2:1:1:2: SEL 0x55acc70f2eb0 <e367> {e7} @dt=0x55acc70ec190@(G/w3)
    1:2:2:1:1:2:1: VARREF 0x55acc70f2f80 <e286> {e7} @dt=0x55acc70e66c0@(G/w4)  i [RV] <- VAR 0x55acc70e4550 <e304> {e2} @dt=0x55acc70e66c0@(G/w4)  i [PI] INPUT [P] PORT
    1:2:2:1:1:2:2: CONST 0x55acc70f30a0 <e287> {e7} @dt=0x55acc70e75c0@(G/w32)  32'h0
    1:2:2:1:1:2:3: CONST 0x55acc70f3200 <e288> {e7} @dt=0x55acc70e75c0@(G/w32)  32'h3
    1:2:2:1:2: ARRAYSEL 0x55acc70f3360 <e378> {e7} @dt=0x55acc70e9270@(w1)u[0:2]
    1:2:2:1:2:1: VARREF 0x55acc70f3420 <e268> {e7} @dt=0x55acc70e9340@(w1)u[0:6]  A [RV] <- VAR 0x55acc70e48e0 <e310> {e3} @dt=0x55acc70e9340@(w1)u[0:6]  A [PI] INPUT [P] PORT
    1:2:2:1:2:2: SEL 0x55acc70f3540 <e294> {e7} @dt=0x55acc70ec190@(G/w3)
    1:2:2:1:2:2:1: VARREF 0x55acc70f3610 <e286> {e7} @dt=0x55acc70e66c0@(G/w4)  i [RV] <- VAR 0x55acc70e4550 <e304> {e2} @dt=0x55acc70e66c0@(G/w4)  i [PI] INPUT [P] PORT
    1:2:2:1:2:2:2: CONST 0x55acc70f3730 <e287> {e7} @dt=0x55acc70e75c0@(G/w32)  32'h0
    1:2:2:1:2:2:3: CONST 0x55acc70f3890 <e288> {e7} @dt=0x55acc70e75c0@(G/w32)  32'h3
    1:2:2:1:3: CONST 0x55acc70f3a10 <e385> {e7} @dt=0x55acc70eb890@(G/w1)  1'h0
    1:2:2:1: AND 0x55acc70f5700 <e485#> {e7} @dt=0x55acc70f0d70@(G/nw1)
    1:2:2:1:1: GTE 0x55acc70f2c90 <e481#> {e7} @dt=0x55acc70f0d70@(G/nw1)
    1:2:2:1:1:1: CONST 0x55acc70f2d50 <e366> {e7} @dt=0x55acc70ec190@(G/w3)  3'h6
    1:2:2:1:1:2: SEL 0x55acc70f2eb0 <e367> {e7} @dt=0x55acc70ec190@(G/w3)
    1:2:2:1:1:2:1: VARREF 0x55acc70f2f80 <e286> {e7} @dt=0x55acc70e66c0@(G/w4)  i [RV] <- VAR 0x55acc70e4550 <e304> {e2} @dt=0x55acc70e66c0@(G/w4)  i [PI] INPUT [P] PORT
    1:2:2:1:1:2:2: CONST 0x55acc70f30a0 <e287> {e7} @dt=0x55acc70e75c0@(G/w32)  32'h0
    1:2:2:1:1:2:3: CONST 0x55acc70f3200 <e288> {e7} @dt=0x55acc70e75c0@(G/w32)  32'h3

RE: Error on indexing the multiple dimensional array (MDA) - Added by Yu Sheng Lin 4 months ago

Disabling this branch in V3Unknown.cpp temporarily resolves the problem. While the comments say that it slows down something, since this generates workable codes, it can be considered to be a good workaround.

virtual void visit(AstArraySel* nodep) {
   ...
   else if (!lvalue && !VN_IS(nodep->backp(), ArraySel)) {  // Too complicated and slow if mid-multidimension
       ...
   }
}

RE: Error on indexing the multiple dimensional array (MDA) - Added by Wilson Snyder about 2 months ago

Sorry, this got misplaced for a while as wasn't in the issues list.

Your proposed fix is in the right spot, but ended up being slightly different.

Fixed in git towards 4.018.

    (1-4/4)