Verilog 加法器和减法器(6)
为了减小行波进位加法器中进位传播延迟的影响,可以尝试在每一级中快速计算进位,如果能在较短时间完成计算,则可以提高加法器性能。
我们可以进行如下的推导:
设 gi=xi&yi, pi = xi +y i
ci+1 = xi&y i+x i&ci+yi&ci=xi&yi + (xi+yi)&ci=g i+pi&c i = gi+pi&(gi-1+pi-1&ci-1)=g i+pi&g i-1+pi&pi-1&ci-1= ….=gi+pi &gi-1+pi &pi-1&gi-2+…+pi&pi-1…p2&p1 &g0+pi &pi-1..p1 &p0&c0; 实现这个逻辑电路的加法器是超前进位加法器。从公式中,可以看出门延时要比行波进位加法器小很多。但是电路复杂,逻辑门的扇入数量将限制超前进位加法器的速度。
由于扇入数量限制,通常我们仅实现4位超前进位加法器和8位超前进位加法器,然后在串联成16/32/64等高位加法器。
下面是4位和8位的超前进位加法器代码:
module adder4_fast(
cin,
x,
y,
s,
cout
); input cin;
input [3:0] x;
input [3:0] y;
output [3:0] s;
output cout; wire [4:0] g,p,c; assign c[0] = cin;
assign p = x | y;
assign g = x & y;
//assign c[1] = g[0] | (p[0] & c[0]);
//assign c[2] = g[1] | (p[1] & (g[0] | (p[0] & c[0])));
//assign c[3] = g[2] | (p[2] & (g[1] | (p[1] & (g[0] | (p[0] & c[0])))));
//assign c[4] = g[3] | (p[3] & (g[2] | (p[2] & (g[1] | (p[1] & (g[0] | (p[0] & c[0])))))));
assign c[1] = g[0] | (p[0] & c[0]);
assign c[2] = g[1] | (p[1]&g[0])|(p[1]&p[0]&c[0]);
assign c[3] = g[2] | (p[2]&g[1])|(p[2]&p[1]&g[0])|(p[2]&p[1]&p[0]&c[0]);
assign c[4] = g[3] | (p[3]&g[2])|(p[3]&p[2]&g[1])|(p[3]&p[2]&p[1]&g[0])|(p[3]&p[2]&p[1]&p[0]&c[0]);
assign s = x^y^c[3:0];
assign cout = c[4]; endmodule
module adder8_fast(
cin,
x,
y,
s,
cout
); input cin;
input [7:0] x;
input [7:0] y;
output [7:0] s;
output cout; wire [8:0] g,p,c; assign c[0] = cin;
assign p = x | y;
assign g = x & y;
//assign c[1] = g[0] | (p[0] & c[0]);
//assign c[2] = g[1] | (p[1] & (g[0] | (p[0] & c[0])));
//assign c[3] = g[2] | (p[2] & (g[1] | (p[1] & (g[0] | (p[0] & c[0])))));
//assign c[4] = g[3] | (p[3] & (g[2] | (p[2] & (g[1] | (p[1] & (g[0] | (p[0] & c[0])))))));
//assign c[5] = g[4] | (p[4] & (g[3] | (p[3] & (g[2] | (p[2] & (g[1] | (p[1] & (g[0] | (p[0] & c[0])))))))));
//assign c[6] = g[5] | (p[5] & (g[4] | (p[4] & (g[3] | (p[3] & (g[2] | (p[2] & (g[1] | (p[1] & (g[0] | (p[0] & c[0])))))))))));
//assign c[7] = g[6] | (p[6] & (g[5] | (p[5] & (g[4] | (p[4] & (g[3] | (p[3] & (g[2] | (p[2] & (g[1] | (p[1] & (g[0] | (p[0] & c[0])))))))))))));
//assign c[8] = g[7] | (p[7] & (g[6] | (p[6] & (g[5] | (p[5] & (g[4] | (p[4] & (g[3] | (p[3] & (g[2] | (p[2] & (g[1] | (p[1] & (g[0] | (p[0] & c[0])))))))))))))));
assign c[1] = g[0] | (p[0] & c[0]);
assign c[2] = g[1] | (p[1]&g[0])|(p[1]&p[0]&c[0]);
assign c[3] = g[2] | (p[2]&g[1])|(p[2]&p[1]&g[0])|(p[2]&p[1]&p[0]&c[0]);
assign c[4] = g[3] | (p[3]&g[2])|(p[3]&p[2]&g[1])|(p[3]&p[2]&p[1]&g[0])|(p[3]&p[2]&p[1]&p[0]&c[0]);
assign c[5] = g[4] | (p[4]&g[3])|(p[4]&p[3]&g[2])|(p[4]&p[3]&p[2]&g[1])|(p[4]&p[3]&p[2]&p[1]&g[0])|(p[4]&p[3]&p[2]&p[1]&p[0]&c[0]);
assign c[6] = g[5] | (p[5]&g[4])|(p[5]&p[4]&g[3])|(p[5]&p[4]&p[3]&g[2])|(p[5]&p[4]&p[3]&p[2]&g[1])|(p[5]&p[4]&p[3]&p[2]&p[1]&g[0])|(p[5]&p[4]&p[3]&p[2]&p[1]&p[0]&c[0]);
assign c[7] = g[6] | (p[6]&g[5])|(p[6]&p[5]&g[4])|(p[6]&p[5]&p[4]&g[3])|(p[6]&p[5]&p[4]&p[3]&g[2])|(p[6]&p[5]&p[4]&p[3]&p[2]&g[1])|(p[6]&p[5]&p[4]&p[3]&p[2]&p[1]&g[0])|(p[6]&p[5]&p[4]&p[3]&p[2]&p[1]&p[0]&c[0]);
assign c[8] = g[7] | (p[7]&g[6])|(p[7]&p[6]&g[5])|(p[7]&p[6]&p[5]&g[4])|(p[7]&p[6]&p[5]&p[4]&g[3])|(p[7]&p[6]&p[5]&p[4]&p[3]&g[2])|(p[7]&p[6]&p[5]&p[4]&p[3]&p[2]&g[1])|(p[7]&p[6]&p[5]&p[4]&p[3]&p[2]&p[1]&g[0])|(p[7]&p[6]&p[5]&p[4]&p[3]&p[2]&p[1]&p[0]&c[0]);
assign s = x^y^c[7:0];
assign cout = c[8]; endmodule
下面的代码把4个超前进位加法器串联起来,形成一个32位加法器。
module addern_fast(
cin,
x,
y,
s,
cout
); input cin;
input [31:0] x;
input [31:0] y;
output [31:0] s;
output cout;
wire [2:0] cout_tmp; adder8_fast adder8_fast_0(.cin(cin),.x(x[7:0]),.y(y[7:0]),.s(s[7:0]),.cout(cout_tmp[0]));
adder8_fast adder8_fast_1(.cin(cout_tmp[0]),.x(x[15:8]),.y(y[15:8]),.s(s[15:8]),.cout(cout_tmp[1]));
adder8_fast adder8_fast_2(.cin(cout_tmp[1]),.x(x[23:16]),.y(y[23:16]),.s(s[23:16]),.cout(cout_tmp[2]));
adder8_fast adder8_fast_3(.cin(cout_tmp[2]),.x(x[31:24]),.y(y[31:24]),.s(s[31:24]),.cout(cout)); endmodule
下面是4位超前进位加法器的逻辑图:

8位超前进位加法器的波形结果。

Verilog 加法器和减法器(6)的更多相关文章
- Verilog 加法器和减法器(8)-串行加法器
如果对速度要求不高,我们也可以使用串行加法器.下面通过状态机来实现串行加法器的功能. 设A=an-1an-2-a0, B=bn-1bn-2-b0,是要相加的两个无符号数,相加的和为:sum=sn-1s ...
- Verilog 加法器和减法器(4)
类似于行波进位加法器,用串联的方法也能够实现多位二进制数的减法操作. 比如下图是4位二进制减法逻辑电路图. 8位二进制减法的verilog代码如下: module subn(x, y, d,cin) ...
- Verilog 加法器和减法器(7)
在计算机中浮点数 表示通常采用IEEE754规定的格式,具体参考以下文章. https://www.cnblogs.com/mikewolf2002/p/10095995.html 下面我们在Veri ...
- Verilog 加法器和减法器(3)
手工加法运算时候,我们都是从最低位的数字开始,逐位相加,直到最高位.如果第i位产生进位,就把该位作为第i+1位输入.同样的,在逻辑电路中,我们可以把一位全加器串联起来,实现多位加法,比如下面的四位加法 ...
- Verilog 加法器和减法器(2)
类似半加器和全加器,也有半减器和全减器. 半减器只考虑当前两位二进制数相减,输出为差以及是否向高位借位,而全减器还要考虑当前位的低位是否曾有借位.它们的真值表如下: 对半减器,diff = x ^y, ...
- Verilog 加法器和减法器(1)
两个一位的二进制数x,y相加,假设和为s,进位为cout,其真值表为: 从真值表中,我们可以得到:s = x^y, cout = x&y,实现两个一位数相加的逻辑电路称为半加器. 实现该电路的 ...
- Verilog 加法器和减法器(5)
前面二进制加法运算,我们并没有提操作数是有符号数,还是无符号数.其实前面的二进制加法对于有符号数和无符号数都成立.比如前面的8位二进制加法运算,第一张图我们选radix是unsigned,表示无符号加 ...
- 基于Xilinx的Synthesize
所谓综合.就是讲HDL语言.原理图等设计输入翻译成由与.或.非们和RAM.触发器登记本逻辑单元的逻辑连接(即网表).并依据目标和要求(约束条件)优化生成的逻辑连接. ISE-XST XST是Xilin ...
- FPGA综合工具--Synplify Pro的常用选项及命令
最近要用到Synplify,但以前没使用过,无基础,找到一篇帖子,隧保存下来. 本文转自:http://blog.sina.com.cn/s/blog_65fe490d0100v8ax.html Sy ...
随机推荐
- NOIP练习赛题目4
肥得更高 难度级别:C: 运行时间限制:1000ms: 运行空间限制:51200KB: 代码长度限制:2000000B 试题描述 自2009年以来,A.B站的历史就已经步入了农业变革的黎明期.在两站的 ...
- 11、Redis的持久化(RDB、AOF)
写在前面的话:读书破万卷,编码如有神 --------------------------------------------------------------------------------- ...
- Codeforces Round #374 (Div. 2) B. Passwords 贪心
B. Passwords 题目连接: http://codeforces.com/contest/721/problem/B Description Vanya is managed to enter ...
- 【网站管理5】_讲解网站后台SEO优化和如何修改关键字以及关键词布局
讲解网站后台SEO优化和如何修改关键字以及关键词布局 制作:赖忠标 QQ:392277956 1.打开后台点击左侧边上的栏目,点击最后的系统-系统基本参数-站点设置 如下图 2.上图所改处 ...
- 二分法(折半查找法)小demo
使用此算法,必须有一个前提,那就是数组必须是有序的. package com.ly.tcwireless.international.test; import org.junit.Test; publ ...
- CentOS7忘记mysql的root密码_处理方法.
1.打开mysql的配置文件: vi /etc/my.cnf 2.在配置文件中添加:skip-grant-tables,然后保存退出, vi常用命令在最后. 如图 3.重启mysql servic ...
- 您该选择PRINCE2 还是 PMP认证
您该选择PRINCE2 还是 PMP认证? 很多人都问我,这是一个非常常见的问题,作为一个项目经理,他们是否应选择PRINCE2或PMP认证,因为这两个认证都是全世界非常流行的. PRINCE2 是一 ...
- C++ Primer笔记3_默认实參_类初探_名字查找与类的作用域
1.默认函数实參 在C++中,能够为參数指定默认值,C语言是不支持默认參数的,Java也不支持! 默认參数的语法与使用: (1)在函数声明或定义时,直接对參数赋值.这就是默认參数: (2)在函数调用时 ...
- Golang 处理 Json(一):编码
JSON 是一种数据格式描述语言.以 key 和 value 构成的哈系结构,类似 Javascript 中的对象,python 中的字典.通常 json 格式的 key 是字符串,其值可以是任意类型 ...
- .yaml 文件格式简介
命名 YAML 的意思其实是:"Yet Another Markup Language"(仍是一种置标语言)的缩写. 功能 YAML的语法和其他高阶语言类似,并且可以简单表达清单. ...