Details

Enhancement

Resolution: Fixed

P4

11, 12, 13

b01

aarch64

linux
Backports
Issue  Fix Version  Assignee  Priority  Status  Resolution  Resolved In Build 

JDK8261903  11.0.11  Pengfei Li  P4  Resolved  Fixed  b04 
Description
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."
i.e.
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.
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."
i.e.
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.
Attachments
Issue Links
 backported by

JDK8261903 AArch64: Add floatingpoint Math.min/max intrinsics
 Resolved
 relates to

JDK8215687 [Graal] unit test CheckGraalIntrinsics failed after 8212043
 Resolved

JDK8226627 assert(t>singleton()) failed: must be a constant
 Resolved

JDK8214922 AArch64: Add vectorization support for fmin/fmax
 Resolved

JDK8217561 x86: Add floatingpoint Math.min/max intrinsics
 Resolved

JDK8226627 assert(t>singleton()) failed: must be a constant
 Resolved

JDK8218550 Add test omitted from JDK8212043
 Resolved
(2 relates to)