Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8212043

AArch64: Add floating-point Math.min/max intrinsics


    • Subcomponent:
    • Resolved In Build:
    • CPU:
    • OS:


      We could add intrinsics of below 4 math methods to benefit their performance, at least for AArch64 platform.
      1) public static float min(float a, float b)
      2) public static float max(float a, float b)
      3) public static double min(double a, double b)
      4) public static double max(double a, double b)
      Java code of "Math.max(double a, double b)":
      1489 public static double max(double a, double b) {
      1490 if (a != a)
      1491 return a; // a is NaN
      1492 if ((a == 0.0d) &&
      1493 (b == 0.0d) &&
      1494 (Double.doubleToRawLongBits(a) == negativeZeroDoubleBits)) {
      1495 // Raw conversion ok since NaN can't map to -0.0.
      1496 return b;
      1497 }
      1498 return (a >= b) ? a : b;
      1499 }
      Below is the description of this method in Java API doc. The behaviors of the other 3 methods are similar.
      "Returns the greater of two double values. That is, the result is the argument closer to positive infinity. If the arguments have the same value, the result is that same value. If either value is NaN, then the result is NaN. Unlike the numerical comparison operators, this method considers negative zero to be strictly smaller than positive zero. If one argument is positive zero and the other negative zero, the result is positive zero."
      Math.max(2.0, -1.5) == 2.0
      Math.max(0.0, 0.0) == 0.0
      Math.max(0.0, -0.0) == 0.0 // min is -0.0
      Math.max(Double.POSITIVE_INFINITY, 2.0) == Double.POSITIVE_INFINITY
      Math.max(Double.NEGATIVE_INFINITY, 2.0) == 2.0
      Math.max(1.0, Double.NaN) == Double.NaN
      Math.max(Double.NaN, Double.NaN) == Double.NaN
      In AArch64 instruction set, the floating point instructions fmin and fmax have exactly the same behavior to the APIs above. So these intrinsics can be done in one single instruction on AArch64.


          Issue Links



              • Assignee:
                pli Pengfei Li
                zyao Zhongwei Yao
              • Votes:
                0 Vote for this issue
                8 Start watching this issue


                • Created: