n + 1或n + 0的快速加法 [英] Fast addition for n+1 or n+0
问题描述
考虑以下声明:
n + i,其中i = 1或0.
有更快的方法来计算n + i而不是直接计算总和?
-
Alex Vinokur
电子邮件:alex DOT vinokur AT gmail DOT com
http://mathforum.org/library/view/10978.html > http://sourceforge.net/users/alexvn
* Alex Vinokur:请考虑以下声明:
n + i,其中i = 1或0.
有没有更快的计算n + i的方法比直接计算总和?
这取决于类型涉及。
对于内置数字类型,直接计算可能是最快的。
测量你是否有疑问(并且它真的很重要。
-
答:因为它弄乱了人们通常阅读文字的顺序。
Q :为什么这么糟糕?
A:热门帖子。
问:usenet和电子邮件中最烦人的是什么?
" Alex Vinokur" <人**** @ big-foot.com>写道:考虑以下语句:
n + i,其中i = 1或0.
有没有更快的方法来计算n + i而不是直接计算这个总和?
计算n + 0的最佳方法是n。
计算n +的最佳方法1是n + 1;如果CPU比一般的添加指令提供更快的价格,那么编译器会为你生成
。
-
Keith Thompson(The_Other_Keith) ks***@mib.org < http:// www。 ghoti.net/~kst>
圣地亚哥超级计算机中心< *> < http://users.sdsc.edu/~kst>
我们必须做点什么。这是事情。因此,我们必须这样做。
Alex Vinokur写道:
请考虑以下声明:
n + i ,其中i = 1或0.
是否有更快的计算n + i的方法比直接计算总和?
假设整数,硬件添加仅使用完整的
加法器或更快的算法(如进位超前)实现。
n + 0没有进位是快速的;许多编制者将不断折叠到n
n + 1可能m进行m位算术
全加器:
http://isweb.redwoods.cc.ca.us/ INSTR ... logic / full.htm
继续前进:
http://www.seas.upenn.edu/~ee201/lab...kAheadF01.html
gtoomey
www.gregorytoomey.com
Consider the following statement:
n+i, where i = 1 or 0.
Is there more fast method for computing n+i than direct computing that sum?
--
Alex Vinokur
email: alex DOT vinokur AT gmail DOT com
http://mathforum.org/library/view/10978.html
http://sourceforge.net/users/alexvn
* Alex Vinokur:Consider the following statement:
n+i, where i = 1 or 0.
Is there more fast method for computing n+i than direct computing that sum?
That depends on the types involved.
For built-in numeric types, direct computation is probably fastest.
Measure if you''re in doubt (and it really matters).
--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?
"Alex Vinokur" <al****@big-foot.com> writes:Consider the following statement:
n+i, where i = 1 or 0.
Is there more fast method for computing n+i than direct computing that sum?
The best way to compute n+0 is n.
The best way to compute n+1 is n+1; if the CPU provides something
faster than a general add instruction, the compiler will generate it
for you.
--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
Alex Vinokur wrote:
Consider the following statement:
n+i, where i = 1 or 0.
Is there more fast method for computing n+i than direct computing that
sum?
Assuming integers, hardware addition is implemented simply using full
adders, or faster algorithms like carry lookahead.
n+0 has no carries is is fast; many compliers will constant fold to n
n+1 has potentially m carries in m-bit arithmetic
Full adder:
http://isweb.redwoods.cc.ca.us/INSTR...logic/full.htm
Carry look ahead:
http://www.seas.upenn.edu/~ee201/lab...kAheadF01.html
gtoomey
www.gregorytoomey.com
这篇关于n + 1或n + 0的快速加法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!