使用FPGA实现32位无符号整数的加法
一、软件自动编译实现
1、verilog代码
`timescale 1ns / 1ps
module add32(
input [31:0] A,
input [31:0] B,
output [31:0] out
);
assign out = A + B;
endmodule
2、testbench
`timescale 1ns / 1ps
module add32_tb(
);
reg [31:0] A;
reg [31:0] B;
wire [31:0] out;
add32 add32_1(
.A(A),
.B(B),
.out(out)
);
initial begin
A = 1000;
B = 0;
#10
$display("A = %d, B = %d, out = %d",A,B,out);
A = 32'hFFFFFFFF;
B = 1;
#10
$display("A = %d, B = %d, out = %d",A,B,out);
end
endmodule
3、RTL
一个加法器
4、综合
看不清可以查看附件资源,可以看到的编译器自动优化使用了LUT资源以及Carry4(这个就是前面设计实现的4位加法器的超前进位加法器),其本质是由8个4位的全加器组合而成。
5、实现
使用了8片slice,32个LUT,8个CARRY4
由上图可知:K7的CLB由两个sliceL组成,每个slice由四个LUT6_2,三个MUX2_1,一个CARRY4,8个DFF组成。
二、指定DSP实现
1、verilog代码
`timescale 1ns / 1ps
(* USE_DSP="yes"*)module add32(
input [31:0] A,
input [31:0] B,
output [31:0] out
);
assign out = A + B;
endmodule
就是指定使用DSP实现:(* USE_DSP="yes"*),testbench、RTL与上面是一样的
2、综合
3、实现
由一个DSP48E1实现