Array equality, comparison and mismatch (original) (raw)
Andrew Haley aph at redhat.com
Tue Oct 13 10:03:36 UTC 2015
- Previous message: Array equality, comparison and mismatch
- Next message: Array equality, comparison and mismatch
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
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 = Double.compare(a[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]) !=
Double.doubleToLongBits(b[i])))
return Double.compare(a[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.
Andrew.
- Previous message: Array equality, comparison and mismatch
- Next message: Array equality, comparison and mismatch
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]