Question related to array slicing

Hi,

I am reading no of lines from file in system verilog. I am counting no of lines from file. That count I am passing to another function.
no_of_lines count I am using for array slicing But I am getting error.


          int m;
   	   while(!$feof(file)) begin
              for(j=0;j<5;j++) begin
              m = j;
              shifting_function(ref int m);
              end            
           end
          function shifting_function(ref bit [10:0] current_data,ref bit [10:0] prev_data, int m);
           data_out =  { prev_data[(2*m)-1 -: 2],current_data[4:(2*m)-1 -: 2]};
          endfunction


In reply to poonamnlwd:
how to use array slicing for current_data. shifting bits from previous data to current data and current data will shift next and so on
array slicing is not working for data_from_one_row_2d[129:((2j)-1 -: 2)]}
getting error Range must be bounded by constant expressions


           data_out  = {prev_data[(2j)-1 -: 2],data_from_one_row_2d[129:((2j)-1 -: 2)]};




In reply to poonamnlwd:

It would really help others help you better if you posted the full actual error message instead of just saying “getting error”

There is one obvious syntax error in your call to shifting_function() inside the for-loop. The function definition requires 3 arguments, and it look like you are only passing 1 argument, and that argument “ref int m” is not the correct syntax.

You have a while(!$feof(file)) loop, but no other file I/O statements, so once in the loop, you would never get out.

The slice current_data[4:(2*m)-1 -: 2] has two “:” operators in it. Can you explain what parts of current_data you are expecting to select?

In reply to dave_59:

I am reading 130 bit from file and sending it on 128 bit interface
130 bits, 130 bits, 130 bits
130 bits = 128 bits + 2 bits
from first 130 bits, 128 bits will go on 1st clock, 2 bit will be shifted to next 130 bits, 4 bits from 2nd 130 bits and shifting of bits is varying on each clock.
so I was getting error
“Range must be bounded by constant expressions”.
j is no of rows from file and on each row I have 130 bits
data_out = {prev_data[(2j)-1 -: 2],current_data[129:((2j)-1 -: 2)]};

data_out  = {prev_data[(2j)-1 -: 2],current_data[129:((2j)-1 -: 2)]};

But current_data[129:((2j)-1 -: 2)] part was not working. Its giving syntax error
I found 2 solutions for this

  1. Using array slicing - Getting issue for this current_data[129:((2j)-1 -: 2)]
  2. Using queue write 130 bits in queue and read 128 bit from queue
    Stream packed struct to bit queue | Verification Academy
    from above post,

bit [7:0] dataq[$];
 
// some loop
wait(queue.size >= 128)
dataq = {>>dataq, queue with [0+:128]}}; // pack 16 bytes
queue = queue[127:$]; // pop 16 bytes

How can I read 128 bits from queue? I am not able to understand reading part from queue in above post?
please suggest better solution for this.

In reply to poonamnlwd:


    bit [129:0] data_in;
    bit d_tmp [130];
    bit data_q [$];
    bit [127:0] data_out;

    data_in = {4{$urandom()}}; // input data, taken random value

    d_tmp = {<<{data_in}}; //pack to unpack 
    data_q = {data_q, d_tmp};  //adding new data in queue

    data_out = {<<{data_q[0:127]}}; //unpack to pack, sending 128bits data

    data_q = data_q[128:$]; //Reducing size of queue, removing 128 elements



https://www.linkedin.com/in/patel-rahulkumar/