1

I have a 360x640 matrix i.e. 230,400 pixel values. Using $readmemh, I want to read only a specific part of matrix and store it in matrix Y_luma (read only the 8x8 matrix values inside the square box i.e. from 154 to 148 and store it in first row of matrix Y_luma, from 152 to 153 store in 2nd row of matrix Y_luma and so on until 155 to 152 in 8th row of Y_luma).

enter image description here

The code I tried is:

module matrix_copy;

    reg [7:0] Y_luma [0:7][0:7];
    
    $readmemh("Luma_space.txt", Y_luma,

Not able to proceed afterwards. How to specify the start address i.e. [8][8] and stop address i.e. [8][15] in first row of matrix Y_luma and also, how to store the next array from [9][8] to [9][15] in 2nd row of matrix Y_luma and so on?

Help is appreciated!

toolic
  • 57,801
  • 17
  • 75
  • 117
Sunil.B
  • 27
  • 5

1 Answers1

1

One approach is to declare another memory variable which exactly matches the size of the input file and read the entire file into that memory (addresses 0 to 230,399). Then you can use for loops to selectively load your Y_luma variable.

reg [7:0] mem [360*640];
initial $readmemh("Luma_space.txt", mem);

This avoids any error or warning messages about incorrect memory size.

Also refer to IEEE Std 1800-2017, section 21.4.3 File format considerations for multidimensional unpacked arrays. However, it might require that your input file be in a very specific format, perhaps with address entries (@0).

$readmemh does have optional start_addr and finish_addr arguments, but it might be tricky getting them to work with your configuration.

Here is one example of the optional arguments.

toolic
  • 57,801
  • 17
  • 75
  • 117
  • The post does not say if this is simulation only or RTL for synthesis. If this is for synthesis a large ROM will be created using LUTS for the big table. The parts have a lot of LUTS so the utilization should not be an issue, however if the part is running fast this may produce timing closure issues because a big ROM will have many levels of logic. – Mikef May 12 '23 at 15:11
  • @Mikef yes in the end i have to synthesize the code in cadence. But initially i am experimenting it on xilinx, but having issue in xilinx. module matrix_read; reg [7:0] Y_luma [0:230399]; initial $readmemh("dummy.txt", Y_luma); reg [7:0] store [0:50]; generate for(genvar k=0; k<50; k=k+1) assign store [k]= Y_luma [k]; endgenerate initial begin #10; $display("%d",Y_luma); $display("%d",store); end endmodule Even this simple code is unable to run, shows exceeds maximum traceable size and ISim shows fatal error – Sunil.B May 12 '23 at 20:09