>>加速分裂 [英] >> to accelerate division

查看:88
本文介绍了>>加速分裂的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们通常使用<< n作为一种更便宜的乘法选项,当它的

因子为

2 ^ n对,


即使是非2 ^ n说


ix24 ==> ix(16 + 8)==> (i<< 4)+(i<<<<<<<<<<<<<<<<<<<<<<<<<<">>
类似地怀疑是否有更便宜的选择i / 24 ==> i /(16 + 8)==> ????????

或i / 72 .....


还有其他更快的算术选择,如>>和<<

for

div n乘法

fORDGE

we usually use <<n as a cheaper option to multiplication when its
factor of
2^n right,

even for non 2^n say

ix24 ==> ix(16+8) ==> (i<<4)+(i<<3)

similarly divison 2^n is >>n

doubt is there a cheaper option to i/24 ==> i/(16+8) ==> ????????
or i/72.....

also are there other faster arithmetic alternatives like the >> and <<
for
div n multiplication
fORDGE

推荐答案

好吧,你可以稍微减少它,但是分歧想要坚持

...


i /(24 )== i /(6 * 4)== i / 6/4 == i /(3 * 2)/ 4 == i / 3/2/2/2

==( i / 3)>> 1>> 1>> 1


i / 24 ==(i>> 3)/ 3

如果你能想出一种表达方式i / 3比特移位,

然后你有所改善。

但是我怀疑是否有办法,没有完全分裂。


-Jh

Well, you could reduce it somewhat, but the divide wants to stick
around...

i/(24) == i/(6*4) == i/6/4 == i/(3*2)/4 == i/3/2/2/2
== (i / 3) >> 1 >> 1 >> 1

i / 24 == (i >> 3) / 3

If you can figure out a way of expressing i / 3 as bit shifts,
then you have an improvement.
But I am doubting there is a way, without doing the full divide.

-Jh


< posted&邮寄>


请记住,您的编译器可能会将所有这些语句

转换为相同的代码:


i>> 1;

i / = 2;

i = i / 2;


.... so你不会指望任何性能差异。同样地,

跟随应该生成完全相同的代码:


i<< 1;

i * = 2;

i = i * 2;


此外,根据硬件,''i * 24''可能比''(i<< 4)+

(i<<< 3)''...假设您的机器没有将代码优化到

同样的事情......

fo****@gmail.com 写道:
<posted & mailed>

Keep in mind that your compiler will probably turn all of these statements
into the same code:

i>>1;
i/=2;
i=i/2;

.... so you wouldn''t expect any performance difference. Likewise, the
following should all generate exactly the same code:

i<<1;
i*=2;
i=i*2;

Also, depending on the hardware, ''i * 24'' may be faster than ''(i<<4) +
(i<<3)'' ... assuming that your machine didn''t optimize the code into the
same thing...

fo****@gmail.com wrote:
我们通常使用<< n作为一种更便宜的乘法选择,当它的因素为2 ^ n时,即使对于非2 ^ n说
/>
ix24 ==> ix(16 + 8)==> (i<<<<<<<<<<<<<<<<<<<<<<<<<<<">} / 24 ==> i /(16 + 8)==> ????????
或i / 72 .....

还有其他更快的算术选择,如>>和<<

div n乘法

fORDGE
we usually use <<n as a cheaper option to multiplication when its
factor of
2^n right,

even for non 2^n say

ix24 ==> ix(16+8) ==> (i<<4)+(i<<3)

similarly divison 2^n is >>n

doubt is there a cheaper option to i/24 ==> i/(16+8) ==> ????????
or i/72.....

also are there other faster arithmetic alternatives like the >> and <<
for
div n multiplication
fORDGE




-

从电子邮件地址中删除''.nospam''以通过电子邮件回复



--
Remove ''.nospam'' from e-mail address to reply by e-mail


" Mysidia" <我的***** @ gmail.com>写道:
"Mysidia" <my*****@gmail.com> writes:
如果你能想出一种表达i / 3作为位移的方法,那么你就有了改进。
但我怀疑是否存在一种方式,没有完全分裂。
If you can figure out a way of expressing i / 3 as bit shifts,
then you have an improvement.
But I am doubting there is a way, without doing the full divide.




你可以实现i / 3作为乘法,然后是一点

shift。在某些情况下,这可能是一种改进。但是,如果它是
是一个改进,你的编译器可能已经为你做了。


见Warren,Jr。的第10章,_Hacker'' s Delight_,Addison-Wesley

2003,ISBN 0-201-91465-4,详情。

-

Ben Pfaff

电子邮件: bl*@cs.stanford.edu

web: http://benpfaff.org


这篇关于&GT;&GT;加速分裂的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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