题解 | #流水线乘法器

流水线乘法器

http://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 [7:0] mul_a_save0,mul_a_save1,mul_a_save2,mul_a_save3;
    reg [7:0] mul_acc;     //累加
    always@(posedge clk or negedge rst_n)
        begin
            if(!rst_n)
                mul_a_save0 <= 0;
            else
                mul_a_save0 <= mul_b[0] ? mul_a : 0;
        end
    always@(posedge clk or negedge rst_n)
        begin
            if(!rst_n)
                mul_a_save1 <= 0;
            else
                mul_a_save1 <= mul_b[1] ? mul_a<<1 : 0;
        end
    always@(posedge clk or negedge rst_n)
        begin
            if(!rst_n)
                mul_a_save2 <= 0;
            else
                mul_a_save2 <= mul_b[2] ? mul_a<<2 : 0;
        end
    always@(posedge clk or negedge rst_n)
        begin
            if(!rst_n)
                mul_a_save3 <= 0;
            else
                mul_a_save3 <= mul_b[3] ? mul_a<<3 : 0;
        end
    always@(posedge clk or negedge rst_n)
        begin
            if(!rst_n)
                mul_out <= 0;
            else
                mul_out <= mul_a_save0+mul_a_save1+mul_a_save2+mul_a_save3;
        end
    
            

    
endmodule
全部评论

相关推荐

03-05 14:55
已编辑
门头沟学院 Java
Jhin4ever:别去,杂活太多,今天让你部署一下模型,明天让你写一下LLM工作流,后天要你研究一下Agent,想微调模型都难
点赞 评论 收藏
分享
评论
1
收藏
分享

创作者周榜

更多
牛客网
牛客企业服务