Based on some microbenchmark results, C2 on sparc doesn't appear to use the hardware instruction for square root since the square root intensive program below runs nearly 20x faster with the client compiler. On the x86, both C1 and C2 appear to use that processor's sqrt instruction.
import java.util.*;
public class SqrtMicrobench {
public static void main(String[] argv) {
long start1, end1;
double data = 1.0;
double sum = 0.0;
double increment =0.0;
// Find an ulp of 1.0
increment = (1.0 + 1.1102230246251568e-16d) - 1.0;
assert increment > 1.0;
// want to run loop for millions of iterations; 2^53
// floating-point numbers between 1.0 and 2.0, multiply
// increment by 2^47 to get bigger granularity.
increment *= (1<<47);
start1 = System.currentTimeMillis();
for(int i =0; i < 100000000; i++) {
sum += Math.sqrt(data);
data += increment;
}
System.out.println("Sum = " + sum);
end1 = System.currentTimeMillis();
System.out.println("Sqrt took " + (end1-start1) + " millseconds.");
}
}
import java.util.*;
public class SqrtMicrobench {
public static void main(String[] argv) {
long start1, end1;
double data = 1.0;
double sum = 0.0;
double increment =0.0;
// Find an ulp of 1.0
increment = (1.0 + 1.1102230246251568e-16d) - 1.0;
assert increment > 1.0;
// want to run loop for millions of iterations; 2^53
// floating-point numbers between 1.0 and 2.0, multiply
// increment by 2^47 to get bigger granularity.
increment *= (1<<47);
start1 = System.currentTimeMillis();
for(int i =0; i < 100000000; i++) {
sum += Math.sqrt(data);
data += increment;
}
System.out.println("Sum = " + sum);
end1 = System.currentTimeMillis();
System.out.println("Sqrt took " + (end1-start1) + " millseconds.");
}
}
- relates to
-
JDK-6179452 REGRESSION: performance regression in monte carlo simulation code using 5.0
-
- Resolved
-
-
JDK-4301297 Math.exp & Math.log are 8 times faster than Math.sqrt
-
- Closed
-