A DESCRIPTION OF THE PROBLEM :
A pattern like:
var low = a *b;
var high = Math.multiplyHigh(a, b);
generates two x86_64 multiplications even the hardware can do it in one instruction.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
java -XX:+UnlockDiagnosticVMOptions -XX:CompileCommand=print,MultiplyTest::doMath MultiplyTest.java
---------- BEGIN SOURCE ----------
public class MultiplyTest {
public static void main(String[] args) {
long b = 987654321L;
var acc = 0L;
for (int i = 0; i < 200_000; i++) {
acc += doMath(i, b);
}
System.exit((int) acc);
}
private static long doMath(long a, long b) {
long low = a * b;
long high = Math.multiplyHigh(a, b);
return low + high;
}
}
---------- END SOURCE ----------
FREQUENCY :
ALWAYS
A pattern like:
var low = a *b;
var high = Math.multiplyHigh(a, b);
generates two x86_64 multiplications even the hardware can do it in one instruction.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
java -XX:+UnlockDiagnosticVMOptions -XX:CompileCommand=print,MultiplyTest::doMath MultiplyTest.java
---------- BEGIN SOURCE ----------
public class MultiplyTest {
public static void main(String[] args) {
long b = 987654321L;
var acc = 0L;
for (int i = 0; i < 200_000; i++) {
acc += doMath(i, b);
}
System.exit((int) acc);
}
private static long doMath(long a, long b) {
long low = a * b;
long high = Math.multiplyHigh(a, b);
return low + high;
}
}
---------- END SOURCE ----------
FREQUENCY :
ALWAYS