// muladd_pipe.sv // Pipelined signed multiply-add: y = a * b + c. // // Datapath: three register stages (inputs, product, sum), latency 3 cycles. // Control: a valid bit travels with the data, so out_valid is high exactly // three cycles after in_valid. Only the valid bits are reset; the // data registers have no reset, which lets synthesis pack them into // a DSP slice. // Widths: a, b are W-bit signed; c is 2W-bit signed; y is 2W+1 bits, which // holds every possible result without overflow. `timescale 1ns / 1ps module muladd_pipe #( parameter int W = 16 ) ( input logic clk, input logic rst, // synchronous, active high input logic in_valid, input logic signed [W-1:0] a, input logic signed [W-1:0] b, input logic signed [2*W-1:0] c, output logic out_valid, output logic signed [2*W:0] y ); logic signed [W-1:0] a_r, b_r; logic signed [2*W-1:0] c_r, c_rr; logic signed [2*W-1:0] p_r; logic v1, v2; // Datapath (no reset) always_ff @(posedge clk) begin a_r <= a; // stage 1 b_r <= b; c_r <= c; p_r <= a_r * b_r; // stage 2 c_rr <= c_r; y <= (2*W+1)'(p_r) + (2*W+1)'(c_rr); // stage 3, sign-extended end // Control: valid pipeline (reset) always_ff @(posedge clk) begin if (rst) begin v1 <= 1'b0; v2 <= 1'b0; out_valid <= 1'b0; end else begin v1 <= in_valid; v2 <= v1; out_valid <= v2; end end endmodule