为什么除法比乘法更昂贵? [英] Why is division more expensive than multiplication?

查看:301
本文介绍了为什么除法比乘法更昂贵?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我并不是真的在尝试优化任何东西,但是我记得我一直都在听到程序员的声音,我认为这是事实.毕竟他们应该知道这些东西.

I am not really trying to optimize anything, but I remember hearing this from programmers all the time, that I took it as a truth. After all they are supposed to know this stuff.

但是我不知道为什么除法实际上比乘法慢?除法不只是光荣的减法,而乘法就是光荣的加法吗?因此,从数学上讲,我不明白为什么一种方式或另一种方式在计算上会产生很大的成本差异.

But I wonder why is division actually slower than multiplication? Isn't division just a glorified subtraction, and multiplication is a glorified addition? So mathematically I don't see why going one way or the other has computationally very different costs.

任何人都可以澄清其原因/原因,以便我知道,而不是我之前从其他程序员那里听到的询问:因为".

Can anyone please clarify the reason/cause of this so I know, instead of what I heard from other programmer's that I asked before which is: "because".

推荐答案

CPU的 ALU (算术逻辑单元)执行算法,尽管它们是在硬件中实现的.经典的乘法算法包括华莱士树此处.较新的处理器中提供了更复杂的技术.通常,处理器努力使位对操作并行化,以最小化所需的时钟周期.乘法算法可以非常有效地并行化(尽管需要更多的晶体管).

CPU's ALU (Arithmetic-Logic Unit) executes algorithms, though they are implemented in hardware. Classic multiplications algorithms includes Wallace tree and Dadda tree. More information is available here. More sophisticated techniques are available in newer processors. Generally, processors strive to parallelize bit-pairs operations in order the minimize the clock cycles required. Multiplication algorithms can be parallelized quite effectively (though more transistors are required).

除法算法不能如此高效地并行化.最有效的除法算法非常复杂( Pentium FDIV bug 展示了复杂程度).通常,它们每位需要更多的时钟周期.如果您需要更多技术细节,请

Division algorithms can't be parallelized as efficiently. The most efficient division algorithms are quite complex (The Pentium FDIV bug demonstrates the level of complexity). Generally, they requires more clock cycles per bit. If you're after more technical details, here is a nice explanation from Intel. Intel actually patented their division algorithm.

这篇关于为什么除法比乘法更昂贵?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆