如何更换/(除法)运算符 [英] How to replace /(division) operator

查看:82
本文介绍了如何更换/(除法)运算符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为了提高性能,如何用按位

运算符更改/运算符?

例如:25 / 5,225 / 25或25/3或任何分裂,但我没有打扰
剩余的

To increase the performance, how to change the / operator with bitwise
operators?
for ex: 25/5, 225/25 or 25/3 or any division, but I am not bothered
of any remainder.

推荐答案

spl写道:
spl wrote:

为了提高性能,如何用按位

运算符更改/运算符?

for ex:25 / 5,225 / 25或25/3或任何分裂,但我没有打扰
剩余的

To increase the performance, how to change the / operator with bitwise
operators?
for ex: 25/5, 225/25 or 25/3 or any division, but I am not bothered
of any remainder.



如果你没说出你使用的是哪个CPU,那就没有意义。分区不再贵了,

和按位实现分区的额外代码

运算符可能会慢得多。


lcc-win编译器将使用3-4个带有移位和加法的指令替换某些类型的除法(除以
整数常量)。这个

只有在编译时知道除数才有可能。


-

jacob navia

jacob at jacob point remcomp point fr

logiciels / informatique
http://www.cs.virginia.edu/~lcc-win32


spl写道:
spl wrote:

为了提高性能,如何使用按位

运算符更改/运算符?

for ex:25/5, 225/25或25/3或任何分组,但我没有打扰
剩余的

To increase the performance, how to change the / operator with bitwise
operators?
for ex: 25/5, 225/25 or 25/3 or any division, but I am not bothered
of any remainder.



性能有多糟糕马上?你有证据表明整数分裂是坏的原因吗?


如果你有这样的证据,很可能是

编译器用于缓慢分割的机器已经使用了很多

的技巧来用更快的替代品替换慢速分区。

如果分母是编译 - 时间常数,编译器

对于这样的机器很可能会使用各种闪避来避免缓慢的分歧。 (如果分子和分母

都是编译时常量,那么在运行时它将是任何分区,这是非常不可思议的。)


几乎是唯一一个你能够做到的情况比编译器更好的
分区是x / y和

ya运行时变量,你知道编译器没有的关于x和y的

范围的事情。在这种情况下

编译器可能会生成一个完全通用的分区,你可以用更少的通用代替
更快。你需要在

利息的机器上研究这个,因为在一台计算机和下一台计算机之间的权衡会有所不同。 />

最后,就像其他任何事情一样:最快的

师是你根本没有表演的。如果您的计划

陷入了多个部门的困境,请考虑重新安排计算的方式来重新安排计算,因此需要更少的部门

第一个
-

Eric Sosman
es ***** @ ieee-dot-org.inva lid

How bad is "the performance" right now? Do you have
evidence that integer divisions are the reason it''s bad?

If you do have such evidence, it''s probable that the
compiler for a slow-dividing machine already employs lots
of tricks to replace slow divisions with faster alternatives.
If the denominator is a compile-time constant, the compiler
for such a machine will quite likely use all kinds of dodges
to avoid a slow divide. (If both the numerator and denominator
are compile-time constants, it''s quite UNlikely that there
will be any divisions at run-time.)

Pretty much the only case where you''ll be able to do
better than the compiler is where the division is x/y with
y a run-time variable and where you know things about the
ranges of x and y that the compiler doesn''t. In this case
the compiler may generate a fully-general division that
you might be able to replace with something less general but
faster. You''ll need to study this on the machine(s) of
interest, because the trade-offs will be different from one
computer to the next.

Finally, as with pretty much anything else: The fastest
division is the one you don''t perform at all. If your program
is bogged down in a multitude of divisions, consider ways to
rearrange the calculation so fewer divisions are needed in
the first place.

--
Eric Sosman
es*****@ieee-dot-org.invalid


我只使用普通的Microsoft Visual C ++编译器。由于在访问/运算符中有更多的b / b
频率,我觉得用按位

运算符更改它,因为它总是比/运算符更快。所以,如果你知道

按位操作,请建议我!!
I use normal Microsoft visual C++ compiler only. Due to lots of more
frequency in accessing / operator, I feel to change it with bitwise
operator, as it is always faster then / operator. So, If you know
bitwise manipulation, please suggest me!!


这篇关于如何更换/(除法)运算符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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