I am looking to find a solution to split 9x9 array into 3x3 arrays.
This is what i am trying, please suggest a good solution.
In reply to n347:
You need to provide a lot more detail. Do you expect the two arrays to have the same total number of bits? Can you provide declarations for the source and target arrays along with sample data of how you want the data to be organized?
In reply to dave_59:
i am still trying to code this.
game = [
[1, 3, 2, 5, 7, 9, 4, 6, 8],
[4, 9, 8, 2, 6, 1, 3, 7, 5],
[7, 5, 6, 3, 8, 4, 2, 1, 9],
[6, 4, 3, 1, 5, 8, 7, 9, 2],
[5, 2, 1, 7, 9, 3, 8, 4, 6],
[9, 8, 7, 4, 2, 6, 5, 3, 1],
[2, 1, 4, 9, 3, 5, 6, 8, 7],
[3, 6, 5, 8, 1, 7, 9, 2, 4],
[8, 7, 9, 6, 4, 2, 1, 5, 3]
]
Split into chunks, it becomes
chunk_1 = [
[1, 3, 2],
[4, 9, 8],
[7, 5, 6]
]
chunk_2 = [
[5, 7, 9],
[2, 6, 1],
[3, 8, 4]
]
typedef bit array3x3[3][3];// there will b 9 3x3 arrays output
typedef bit array9x9[9][9];
function void split_fn (array9x9 in_array);
array3x3 out_array [9];// output array
for (int i=0; i<N;i++) begin
for(int j =0; j <N; j++) begin
end
end
endfunction
In reply to n347:
much better
module top;
typedef bit [3:0] array3x3[3][3];// there will be 9 3x3 arrays output
typedef bit [3:0] array9x9[9][9];
array9x9 in_game = '{
{1, 3, 2, 5, 7, 9, 4, 6, 8},
{4, 9, 8, 2, 6, 1, 3, 7, 5},
{7, 5, 6, 3, 8, 4, 2, 1, 9},
{6, 4, 3, 1, 5, 8, 7, 9, 2},
{5, 2, 1, 7, 9, 3, 8, 4, 6},
{9, 8, 7, 4, 2, 6, 5, 3, 1},
{2, 1, 4, 9, 3, 5, 6, 8, 7},
{3, 6, 5, 8, 1, 7, 9, 2, 4},
{8, 7, 9, 6, 4, 2, 1, 5, 3}
};
array3x3 out_game[9];
function automatic void split_fn(input array9x9 in, output array3x3 out[9]);
foreach(out[chunk]) begin
int x = chunk % 3;
int y = chunk / 3 % 3;
for(int i=0; i<3;i++)
out[chunk][i] = in[y*3+i][x*3+:3];
end
endfunction : split_fn
initial begin
split_fn(in_game, out_game);
foreach(out_game[i]) $display("%d\n%p", i, out_game[i]);
end
endmodule : top
In reply to dave_59:
Thanks a lot Dave! Appreciate your response.