// sum8_chain.sv // Sum of eight unsigned numbers with registered inputs and a registered output. // The adders form one chain of seven between the two registers, so the // register-to-register path is long. Latency: 2 clock cycles. `timescale 1ns/1ps module sum8_chain #( parameter int W = 16 ) ( input logic clk, input logic rst, input logic in_valid, input logic [7:0][W-1:0] x, output logic out_valid, output logic [W+2:0] y ); logic [7:0][W-1:0] x_r; logic v_r; logic [W+2:0] acc; // Combinational chain: ((((x0 + x1) + x2) + x3) ... + x7) always_comb begin acc = '0; for (int i = 0; i < 8; i++) begin acc = acc + (W+3)'(x_r[i]); end end always_ff @(posedge clk) begin x_r <= x; y <= acc; end always_ff @(posedge clk) begin if (rst) begin v_r <= 1'b0; out_valid <= 1'b0; end else begin v_r <= in_valid; out_valid <= v_r; end end endmodule