aboutsummaryrefslogtreecommitdiffstats
path: root/tests/various/dynamic_part_select/forloop_select.v
blob: 926fb3133e70f2ac0b8d7405a14965343b38d284 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
`default_nettype none
module forloop_select #(parameter WIDTH=16, SELW=4, CTRLW=$clog2(WIDTH), DINW=2**SELW)
   (input wire             clk,
    input wire [CTRLW-1:0] ctrl,
    input wire [DINW-1:0]  din,
    input wire             en,
    output reg [WIDTH-1:0] dout);

   reg [SELW:0]            sel;
   localparam SLICE = WIDTH/(SELW**2);

   always @(posedge clk)
     begin
        if (en) begin
           for (sel = 0; sel <= 4'hf; sel=sel+1'b1)
             dout[(ctrl*sel)+:SLICE] <= din;
        end
     end
endmodule