128 multiplication uses two multiply instructions on x86_64

XMLWordPrintable

    • Type: Bug
    • Resolution: Unresolved
    • Priority: P3
    • None
    • Affects Version/s: 25.0.2
    • Component/s: hotspot

      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

            Assignee:
            Unassigned
            Reporter:
            Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated: