Pipeline matmul multiplier: 2-stage to fix WNS

Split compute into stage1 (compute → partial) and
stage2 (partial → c_data). Halves CARRY4 chain depth
from 16 to ~8 levels. Compute cycles: 16 → 32.
This commit is contained in:
2026-06-24 21:40:34 +08:00
parent db2ad12dbb
commit 5972facc0a

View File

@@ -71,6 +71,8 @@ reg busy;
reg done; reg done;
reg error; reg error;
reg [3:0] calc_index; reg [3:0] calc_index;
reg [65:0] partial; // pipeline register for 2-stage multiplier
reg pipe_valid; // partial has valid data
wire write_fire; wire write_fire;
wire start_fire; wire start_fire;
@@ -288,17 +290,28 @@ always @(posedge clk) begin
done <= 1'b0; done <= 1'b0;
error <= 1'b0; error <= 1'b0;
calc_index <= 4'd0; calc_index <= 4'd0;
pipe_valid <= 1'b0;
end else if (busy) begin end else if (busy) begin
c_data[calc_index] <= calc_c_element(calc_index); if (!pipe_valid) begin
// Stage 1: compute element, store in partial
partial <= calc_c_element(calc_index);
pipe_valid <= 1'b1;
end else begin
// Stage 2: store partial into c_data, advance
c_data[calc_index] <= partial;
pipe_valid <= 1'b0;
if (calc_index == 4'd15) begin if (calc_index == 4'd15) begin
busy <= 1'b0; busy <= 1'b0;
done <= 1'b1; done <= 1'b1;
calc_index <= 4'd0; calc_index <= 4'd0;
partial <= 66'b0;
pipe_valid <= 1'b0;
end else begin end else begin
calc_index <= calc_index + 4'd1; calc_index <= calc_index + 4'd1;
end end
end end
end end
end
end end
endmodule endmodule