题解 | #流水线乘法器#
流水线乘法器
https://www.nowcoder.com/practice/be97f63817c543fe9260d46d971a7283
`timescale 1ns/1ns
module multi_pipe#(
parameter size = 4
)(
input clk ,
input rst_n ,
input [size-1:0] mul_a ,
input [size-1:0] mul_b ,
output reg [size*2-1:0] mul_out
);
reg [size*2-1:0] mul_out_r0, mul_out_r1, mul_out_r2,mul_out_r3;
always@(posedge clk, negedge rst_n) begin
if(rst_n==1'b0) begin
mul_out_r0 <= 'b0;
mul_out_r1 <= 'b0;
mul_out_r2 <= 'b0;
mul_out_r3 <= 'b0;
mul_out <= 'b0;
end
else begin
mul_out_r0 <= mul_a[0] ? mul_b : 'b0 ;
mul_out_r1 <= mul_a[1] ? ({3'b0,mul_b,1'b0}) : 'b0 ;
mul_out_r2 <= mul_a[2] ? ({2'b0,mul_b,2'b0}) : 'b0 ;
mul_out_r3 <= mul_a[3] ? ({1'b0,mul_b,3'b0}) : 'b0 ;
mul_out <= mul_out_r0 + mul_out_r1 + mul_out_r2 + mul_out_r3;
end
end
endmodule

