Skip to content

Commit 276aea1

Browse files
committed
Add packed array slicers
1 parent 64e0408 commit 276aea1

File tree

2 files changed

+138
-0
lines changed

2 files changed

+138
-0
lines changed

arbitrary_slicer_2d.sv

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
//------------------------------------------------------------------------------
2+
// arbitrary_slicer_2d.sv
3+
// Konstantin Pavlov, [email protected]
4+
//------------------------------------------------------------------------------
5+
6+
// INFO -------------------------------------------------------------------------
7+
// Arbitrary slicer for 2D packed SystemVerilog arrays
8+
// Slices along any array edge, all array sides simultaneously
9+
//
10+
// You can also generalize this aproach to support as many dimentions as needed
11+
//
12+
// This module does NOT consume any FPGA resources though it is absolutely
13+
// synthesizable
14+
//
15+
16+
17+
/* --- INSTANTIATION TEMPLATE BEGIN ---
18+
19+
arbitrary_slicer_2d #(
20+
.I2_HI( 3 ), .I2_LO( 0 ),
21+
.I1_HI( 7 ), .I1_LO( 0 ),
22+
23+
.O2_HI( 2 ), .O2_LO( 1 ),
24+
.O1_HI( 2 ), .O1_LO( 1 )
25+
) S1 (
26+
.in ( a[3:0][7:0] ),
27+
.out( b[2:1][2:1] )
28+
);
29+
30+
--- INSTANTIATION TEMPLATE END ---*/
31+
32+
33+
module arbitrary_slicer_3d #( parameter
34+
35+
// input array shape
36+
I2_HI = 3, // most significant size
37+
I2_LO = 0,
38+
39+
I1_HI = 7, // least significant size
40+
I1_LO = 0,
41+
42+
// sliced array shape
43+
O2_HI = 2, // most significant size
44+
O2_LO = 1,
45+
46+
O1_HI = 2, // least significant size
47+
O1_LO = 1
48+
)(
49+
input [I2_HI:I2_LO][I1_HI:I1_LO] in,
50+
output logic [O2_HI:O2_LO][O1_HI:O1_LO] out
51+
);
52+
53+
54+
integer i;
55+
always_comb begin
56+
57+
for ( i=O2_LO; i<=O2_HI; i++ ) begin
58+
out[i][O1_HI:O1_LO] = in[i][O1_HI:O1_LO];
59+
end
60+
61+
end
62+
63+
endmodule
64+

arbitrary_slicer_3d.sv

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
//------------------------------------------------------------------------------
2+
// arbitrary_slicer_3d.sv
3+
// Konstantin Pavlov, [email protected]
4+
//------------------------------------------------------------------------------
5+
6+
// INFO -------------------------------------------------------------------------
7+
// Arbitrary slicer for 3D packed SystemVerilog arrays
8+
// Slices along any array edge, all array sides simultaneously
9+
//
10+
// You can also generalize this aproach to support as many dimentions as needed
11+
//
12+
// This module does NOT consume any FPGA resources though it is absolutely
13+
// synthesizable
14+
//
15+
16+
17+
/* --- INSTANTIATION TEMPLATE BEGIN ---
18+
19+
arbitrary_slicer_3d #(
20+
.I3_HI( 3 ), .I3_LO( 0 ),
21+
.I2_HI( 3 ), .I2_LO( 0 ),
22+
.I1_HI( 7 ), .I1_LO( 0 ),
23+
24+
.O3_HI( 2 ), .O3_LO( 1 ),
25+
.O2_HI( 2 ), .O2_LO( 1 ),
26+
.O1_HI( 2 ), .O1_LO( 1 )
27+
) S1 (
28+
.in ( a[3:0][3:0][7:0] ),
29+
.out( b[2:1][2:1][2:1] )
30+
);
31+
32+
--- INSTANTIATION TEMPLATE END ---*/
33+
34+
35+
module arbitrary_slicer_3d #( parameter
36+
37+
// input array shape
38+
I3_HI = 3, // most significant size
39+
I3_LO = 0,
40+
41+
I2_HI = 3,
42+
I2_LO = 0,
43+
44+
I1_HI = 7, // least significant size
45+
I1_LO = 0,
46+
47+
// sliced array shape
48+
O3_HI = 2, // most significant size
49+
O3_LO = 1,
50+
51+
O2_HI = 2,
52+
O2_LO = 1,
53+
54+
O1_HI = 2, // least significant size
55+
O1_LO = 1
56+
)(
57+
input [I3_HI:I3_LO][I2_HI:I2_LO][I1_HI:I1_LO] in,
58+
output logic [O3_HI:O3_LO][O2_HI:O2_LO][O1_HI:O1_LO] out
59+
);
60+
61+
62+
integer i,j;
63+
always_comb begin
64+
65+
for ( i=O3_LO; i<=O3_HI; i++ ) begin
66+
for ( j=O2_LO; j<=O2_HI; j++ ) begin
67+
out[i][j][O1_HI:O1_LO] = in[i][j][O1_HI:O1_LO];
68+
end //j
69+
end //i
70+
71+
end
72+
73+
endmodule
74+

0 commit comments

Comments
 (0)