这个部分就开始考虑到加速的一些东西了
之前几个写的不论是1位加法器还是16位的加法器,实际上都是1位的,可以观察到,如果前面cout没有给出进位的数据,后面是没法开始运算的,所以前面的加法器就会很慢,延迟很高
但实际上,后面模块的运算可以优先进行,把进位是0和1的值都算出来,然后通过判断cout是0还是1,直接输出,这样就可以节约在知道cout的值之后,还需给运算的时间。
n this exercise, you are provided with the same module add16 as the previous exercise, which adds two 16-bit numbers with carry-in and produces a carry-out and 16-bit sum. You must instantiate three of these to build the carry-select adder, using your own 16-bit 2-to-1 multiplexer.
Connect the modules together as shown in the diagram below. The provided module add16 has the following declaration:
module add16 ( input[15:0] a, input[15:0] b, input cin, output[15:0] sum, output cout );
在这个练习中,你将使用与前一个练习相同的模块add16,它将两个带进位的16位数字相加,并生成一个带进位的16位和。用户必须实例化其中三个来构建进位选择加法器,使用用户自己的16位2对1多路复用器。
如下图所示,将模块连接在一起。提供的模块add16有如下声明:
模块add16(输入[15:0]a,输入[15:0]b,输入cin,输出[15:0]sum,输出cout);
主要是理解这个提前运算的概念,实际设计就按照图片给的连线就可以了。
module top_module(
input [31:0] a,
input [31:0] b,
output [31:0] sum
);
wire c_choose;
wire [15:0]sum_2;
wire [15:0]sum_3;
add16 add16_1(.a(a[15:0]),.b(b[15:0]),.cin(0),.cout(c_choose),.sum(sum[15:0]));
add16 add16_2(.a(a[31:16]),.b(b[31:16]),.cin(0),.cout(),.sum(sum_2));
add16 add16_3(.a(a[31:16]),.b(b[31:16]),.cin(1),.cout(),.sum(sum_3));
assign sum[31:16] = (c_choose) ? sum_3 : sum_2 ;
endmodule