Skip to content

Commit 014b8c5

Browse files
committed
Done slicer functions as a parametrized SV class
1 parent 276aea1 commit 014b8c5

File tree

3 files changed

+100
-20
lines changed

3 files changed

+100
-20
lines changed

arbitrary_slicer_2d.sv renamed to slicer_2d.sv

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
//------------------------------------------------------------------------------
2-
// arbitrary_slicer_2d.sv
2+
// slicer_2d.sv
33
// Konstantin Pavlov, pavlovconst@gmail.com
44
//------------------------------------------------------------------------------
55

@@ -16,12 +16,12 @@
1616

1717
/* --- INSTANTIATION TEMPLATE BEGIN ---
1818
19-
arbitrary_slicer_2d #(
20-
.I2_HI( 3 ), .I2_LO( 0 ),
21-
.I1_HI( 7 ), .I1_LO( 0 ),
19+
slicer_2d #(
20+
.I2_HI( 3 ), .I2_LO( 0 ),
21+
.I1_HI( 7 ), .I1_LO( 0 ),
2222
23-
.O2_HI( 2 ), .O2_LO( 1 ),
24-
.O1_HI( 2 ), .O1_LO( 1 )
23+
.O2_HI( 2 ), .O2_LO( 1 ),
24+
.O1_HI( 2 ), .O1_LO( 1 )
2525
) S1 (
2626
.in ( a[3:0][7:0] ),
2727
.out( b[2:1][2:1] )
@@ -30,7 +30,7 @@ arbitrary_slicer_2d #(
3030
--- INSTANTIATION TEMPLATE END ---*/
3131

3232

33-
module arbitrary_slicer_3d #( parameter
33+
module slicer_2d #( parameter
3434

3535
// input array shape
3636
I2_HI = 3, // most significant size
@@ -54,9 +54,9 @@ module arbitrary_slicer_3d #( parameter
5454
integer i;
5555
always_comb begin
5656

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
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
6060

6161
end
6262

arbitrary_slicer_3d.sv renamed to slicer_3d.sv

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
//------------------------------------------------------------------------------
2-
// arbitrary_slicer_3d.sv
2+
// slicer_3d.sv
33
// Konstantin Pavlov, pavlovconst@gmail.com
44
//------------------------------------------------------------------------------
55

@@ -16,14 +16,14 @@
1616

1717
/* --- INSTANTIATION TEMPLATE BEGIN ---
1818
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 ),
19+
slicer_3d #(
20+
.I3_HI( 3 ), .I3_LO( 0 ),
21+
.I2_HI( 3 ), .I2_LO( 0 ),
22+
.I1_HI( 7 ), .I1_LO( 0 ),
2323
24-
.O3_HI( 2 ), .O3_LO( 1 ),
25-
.O2_HI( 2 ), .O2_LO( 1 ),
26-
.O1_HI( 2 ), .O1_LO( 1 )
24+
.O3_HI( 2 ), .O3_LO( 1 ),
25+
.O2_HI( 2 ), .O2_LO( 1 ),
26+
.O1_HI( 2 ), .O1_LO( 1 )
2727
) S1 (
2828
.in ( a[3:0][3:0][7:0] ),
2929
.out( b[2:1][2:1][2:1] )
@@ -32,7 +32,7 @@ arbitrary_slicer_3d #(
3232
--- INSTANTIATION TEMPLATE END ---*/
3333

3434

35-
module arbitrary_slicer_3d #( parameter
35+
module slicer_3d #( parameter
3636

3737
// input array shape
3838
I3_HI = 3, // most significant size
@@ -45,7 +45,7 @@ module arbitrary_slicer_3d #( parameter
4545
I1_LO = 0,
4646

4747
// sliced array shape
48-
O3_HI = 2, // most significant size
48+
O3_HI = 2, // most significant size
4949
O3_LO = 1,
5050

5151
O2_HI = 2,

slicer_functions.vh

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
//------------------------------------------------------------------------------
2+
// slicer_functions.vh
3+
// published as part of https://github.com/pConst/basic_verilog
4+
// Konstantin Pavlov, pavlovconst@gmail.com
5+
//------------------------------------------------------------------------------
6+
7+
// INFO ------------------------------------------------------------------------
8+
// Arbitrary slice functions for 2D and 3D packed SystemVerilog arrays
9+
// Slices along any array edge, all array sides simultaneously
10+
//
11+
// You can also generalize this aproach to support as many dimentions as needed
12+
//
13+
// This module does NOT consume any FPGA resources though it is absolutely
14+
// synthesizable
15+
//
16+
// Parametrized classes are supported by Vivado, NOT supported by Quartus.
17+
// Please use slicer_2d.sv and slicer_3d.sv conventional modules instead.
18+
//
19+
// Call syntax:
20+
// ============
21+
// assign a[2:1][2:1] = slicer_functions#(
22+
// .I2_HI( 3 ), .I2_LO( 0 ), .I1_HI( 7 ), .I1_LO( 0 ),
23+
// .O2_HI( 2 ), .O2_LO( 1 ), .O1_HI( 2 ), .O1_LO( 1 ) )::slice2d( b[3:0][7:0] );
24+
//
25+
// assign c[2:1][2:1][2:1] = slicer_functions#(
26+
// .I3_HI( 3 ), .I3_LO( 0 ), .I2_HI( 3 ), .I2_LO( 0 ),
27+
// .I1_HI( 7 ), .I1_LO( 0 ), .O3_HI( 2 ), .O3_LO( 1 ),
28+
// .O2_HI( 2 ), .O2_LO( 1 ), .O1_HI( 2 ), .O1_LO( 1 ) )::slice3d( d[3:0][3:0][7:0] );
29+
//
30+
31+
32+
virtual class slicer_functions #( parameter
33+
34+
// input array shape
35+
I3_HI = 3, // most significant size
36+
I3_LO = 0,
37+
38+
I2_HI = 3,
39+
I2_LO = 0,
40+
41+
I1_HI = 7, // least significant size
42+
I1_LO = 0,
43+
44+
// sliced array shape
45+
O3_HI = 2, // most significant size
46+
O3_LO = 1,
47+
48+
O2_HI = 2,
49+
O2_LO = 1,
50+
51+
O1_HI = 2, // least significant size
52+
O1_LO = 1
53+
);
54+
55+
56+
static function [O2_HI:O2_LO][O1_HI:O1_LO] slice2d(
57+
input [I2_HI:I2_LO][I1_HI:I1_LO] in
58+
);
59+
60+
integer i;
61+
for ( i=O2_LO; i<=O2_HI; i++ ) begin
62+
slice2d[i][O1_HI:O1_LO] = in[i][O1_HI:O1_LO];
63+
end //i
64+
endfunction
65+
66+
67+
static function [O3_HI:O3_LO][O2_HI:O2_LO][O1_HI:O1_LO] slice3d(
68+
input [I3_HI:I3_LO][I2_HI:I2_LO][I1_HI:I1_LO] in
69+
);
70+
71+
integer i,j;
72+
for ( i=O3_LO; i<=O3_HI; i++ ) begin
73+
for ( j=O2_LO; j<=O2_HI; j++ ) begin
74+
slice3d[i][j][O1_HI:O1_LO] = in[i][j][O1_HI:O1_LO];
75+
end //j
76+
end //i
77+
endfunction
78+
79+
endclass
80+

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy