Assembly output from JRuby 'fib'

Rémi Forax forax at univ-mlv.fr
Tue May 3 08:06:17 PDT 2011


On 05/03/2011 03:59 PM, Christian Thalinger wrote:
> On May 2, 2011, at 9:55 PM, Charles Oliver Nutter wrote:
>> On Thu, Apr 28, 2011 at 11:18 AM, Rémi Forax<forax at univ-mlv.fr>  wrote:
>>> Do you specialize the overflow check depending on the callsite ?
>>> for fib(n - 1), you just have to check if n is different from
>>> Integer.MIN_INT,
>>> for fib(n - 2), if n is<= to Integer.MIN_INT - 1
>>> and for + use the double xor tricks.
>> Here's a related question. Is there a way we can structure the double
>> xor trick to get Hotspot to intrinsify it as a jc instruction or
>> similar?
>>
>> As I posted earlier, we use the "double xor" trick, which I would
>> expect JVM could recognize as a carry check and do the right thing. Or
>> perhaps there's an intrinsic somewhere in JVM/JDK we could call?
> I look a little into this and as far as I know there is nothing you could call.  I also tried to hack something into the backend and I think that could work.  I'm just not sure how many users would trigger that pattern.
>
> -- Christian

The pattern occurs enough often to be recognized as a pattern.

Here is the version used by JSR 310 reference implementation:
http://threeten.svn.sourceforge.net/viewvc/threeten/trunk/threeten/src/main/java/javax/time/MathUtils.java?revision=1417&view=markup
(look for safeAdd)

It uses a && instead of a & in the middle,
I don't know which one is the better.

Rémi




More information about the mlvm-dev mailing list