题解 | #流水线乘法器#

流水线乘法器

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		
);
localparam N=size*2;
wire [N-1:0] part_pro[size-1:0];
genvar i;
generate
	for(i=0;i<size;i=i+1) 
		// assign part_pro[i] = (mul_b & {size{mul_a[i]}})<<i;
		assign part_pro[i] = (mul_b[i])? mul_a<<i : 'd0;
endgenerate

reg [N-1:0] sum_part[size-1:0];
integer j;
always@(posedge clk or negedge rst_n) begin
	if(~rst_n) for(j=0;j<2;j=j+1)
		sum_part[j] <= 0;	
	else for(j=0;j<2;j=j+1)
		sum_part[j] <= part_pro[2*j] + part_pro[2*j+1];
end
always@(posedge clk or negedge rst_n) begin
	if(~rst_n) mul_out <= 0;
	else mul_out <= sum_part[0] + sum_part[1];

end
endmodule

全部评论

相关推荐

11-25 09:41
已编辑
Java
程序员花海_:实习和校招简历正确格式应该是教育背景+实习+项目经历+个人评价 其中项目经历注意要体现业务 实习经历里面的业务更是要自圆其说 简历模板尽可能保持干净整洁 不要太花哨的
投了多少份简历才上岸
点赞 评论 收藏
分享
想进开水团喝开水:哦 给我一个 就算你真拿到牛友也会为你开心的
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务