forked from pConst/basic_verilog
-
Notifications
You must be signed in to change notification settings - Fork 0
/
reverse_dimensions.sv
executable file
·48 lines (36 loc) · 1.24 KB
/
reverse_dimensions.sv
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
//------------------------------------------------------------------------------
// reverse_dimensions.sv
// Konstantin Pavlov, [email protected]
//------------------------------------------------------------------------------
// INFO ------------------------------------------------------------------------
// "Physically" reverses dimension order in systemv_erilog 2D vector
// Thus in[7][1] signal becomes out[1][7], in[6][10] becomes out[10][6] and vise-versa
// Module is no doubt synthesizable, but its instance does NOT occupy any FPGA resources!
/* --- INSTANTIATION TEMPLATE BEGIN ---
reverse_dimensions #(
.D1_WIDTH( 8 ),
.D2_WIDTH( 3 )
) RD1 (
.in( smth[7:0][2:0] ),
.out( htms[2:0][7:0] ) // reversed bit order
);
--- INSTANTIATION TEMPLATE END ---*/
module reverse_dimensions #( parameter
D1_WIDTH = 8, // first dimention width
D2_WIDTH = 3 // second dimention width
)(
input [D1_WIDTH-1:0][D2_WIDTH-1:0] in,
output logic [D2_WIDTH-1:0][D1_WIDTH-1:0] out
);
genvar i;
genvar j;
generate
for (i = 0; i < D1_WIDTH ; i++) begin : gen_i
for (j = 0; j < D2_WIDTH ; j++) begin : gen_j
always_comb begin
out[j][i] = in[i][j];
end // always_comb
end // for
end // for
endgenerate
endmodule