Array equality, comparison and mismatch

Andrew Haley aph at
Tue Oct 13 10:03:36 UTC 2015

On 13/10/15 10:22, Paul Sandoz wrote:
> Analysis so far indicate big gains are to be had on larger arrays with better or no impact on small arrays if i do the following instead:
>   if (Double.doubleToRawLongBits(a[i]) !=
>       Double.doubleToRawLongBits(b[i])) {
>       int c =[i], b[i]);
>       if (c != 0) return c;
>   }

I was about to make a similar comment.  My experiment was with

        if (Double.doubleToRawLongBits(a[i]) != Double.doubleToRawLongBits(b[i])
                && (Double.doubleToLongBits(a[i]) !=
                return[i], b[i]);

which is about twice as fast as the original version, as is yours.
But yours is more elegant.  :-)

It's a shame that HotSpot doesn't see through the load of a
double and then the conversion through doubleToRawLongBits:
it could just load directly into the integer registers.


More information about the core-libs-dev mailing list