0

Given a matrix

logic [0:3] [0:3] matrix =
    {4'b 1111,
     4'b 1111,
     4'b 1111,
     4'b 1111
    }

During run time, I get input (x,y) as index. I would like to reach indexes (x,y+1), (x,y), (x,y-1) and change them.

for example, if I get (x,y)=(1,2), then I would get

    {4'b 1111,
     4'b 1011,
     4'b 1011,
     4'b 1011
    }

I tried doing it in an always_ff block:

always_ff@(posedge clk or negedge resetN)
begin
     matrix[y-1:y+1][x] <= 0;
end

but it says range must be final index.

Thanks.

Zahi
  • 1
  • 1

1 Answers1

0

The range you are asking for is called a slice or part-select in SystemVerilog. There are two problems with what you are trying to do.

  1. You can only slice the last the last dimension of a select. In other words, select must represent a contiguous set of bits. You are trying to do the reverse.
  2. Selects must have constant widths. Assuming you fixed the first issue, you would have to do something like [y-1 +:3]. See What is `+:` and `-:`?

But it might be better just using a for loop.

always_ff@(posedge clk)
     for(yy=y-1;yy<y+2;y++) matrix[yy][x] <= 0;
dave_59
  • 30,490
  • 3
  • 22
  • 48