I am trying to implement an array Right Shifter.
It accepts an array of integers, then right shifts everything to the right-side of specified index position, and inserts a specified integer value at index position.
For e.g.
If arr = {1, 2, 3, 4, 5, 6, 7, .... 16}; idx = 4; insert_value = 0; then new_arr = {1, 2, 3, 0, 4, 5, 6, ... 15}
Below is my code:
// Right shifts the arrays from given index, and inserts given value.
`timescale 1ns / 1ps
module indexed_rsh(
input wire [511:0] arr,
input wire [3:0] idx,
input wire [31:0] insert_value,
output wire [511:0] new_arr
);
logic [0:15][31:0] arr_sig, new_arr_sig;
assign arr_sig = arr;
assign new_arr = new_arr_sig;
genvar i;
generate
for (i=0; i < 16; i = i + 1)
begin
always_comb
if(idx == i)
new_arr_sig [0:15][31:0] = {arr_sig[0:i-1][31:0], insert_value, arr_sig[i:14][31:0]};
end
endgenerate
endmodule
On EDAplayground, I get a syntax error on line 21, and "error: invalid module item" on line 23.
In Vivado, I got an error saying "range is not allowed in prefix" on line 23. If range is not allowed in prefix, what is a good way to index 2D arrays?
Here is one way to insert a 32-bit value into a 512-bit value at a given 32-bit index offset, while shifting the other bits right:
If you want to use the internal 2D packed arrays: