处理器中的减法指令
为什么处理器应该实现减法指令?为什么编译器不能将减法更改为 2 补码加法?
Why should a processor implement a subtract instruction ? Why cant the compilers change subtraction to 2-s complement additions?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
因为如果每个减法都必须是两条指令(取反和加法),那么您将浪费大量内存流量(因为代码会变得更大)、缓存空间(因为代码会更大)和指令解码时间(因为会有更多的指令需要解码),从而在 CPU 简单性方面获得微小的提升。完全不值得。
Because if every subtraction had to be two instructions (negate and add) then you'd waste a lot of memory traffic (because code would become larger), cache space (because code would be larger), and instruction decode time (because there would be more instructions to decode), for a tiny gain in CPU simplicity. Totally not worth it.
加法和减法的使用已经足够多,因此构建它是有意义的。这是需要更少 CPU 周期的更多本机指令与更快的 CPU 周期(更多周期/秒)之间的权衡。
Addition and subtraction are used enough that it makes sense to build it in. It is a trade off between having more native instructions which require less CPU cycles to faster CPU cycles (more cycles / second).