java函数中的模运算符如何? [英] How does the modulus operator in java function?

查看:128
本文介绍了java函数中的模运算符如何?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我将开始对一段巨大的代码进行优化,并且我需要确切知道使用模运算符时执行哪些操作。我一直在寻找相当长的一段时间,但我无法找到任何关于它背后的机器代码。任何想法?

解决方案

整数上的模数运算符是内置于大多数平台上的。执行时间与除法时间相当的指令,产生模数。

编译器可以对二次幂的除数进行优化:代替执行模数例如 x%512 ,编译器可以使用可能更快的 x& 0x01FF


I'm about to start optimizations on an enormous piece of code and I need to know exactly which operations are performed when the modulus operator is used. I have been searching for quite a while, but I can't find anything about the machine code behind it. Any ideas?

解决方案

The modulus operator on integers is built in on most platforms. An instruction with the timing comparable to that of division is performed, producing the modulus.

The compiler can perform an optimization for divisors that are powers of two: instead of performing modulos of, say, x % 512, the compiler can use a potentially faster x & 0x01FF.

这篇关于java函数中的模运算符如何?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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