JDK-8352585 : Add special case handling for Float16.max/min x86 backend
  • Type: Bug
  • Component: hotspot
  • Sub-Component: compiler
  • Affected Version: 25
  • Priority: P3
  • Status: Open
  • Resolution: Unresolved
  • CPU: x86_64
  • Submitted: 2025-03-21
  • Updated: 2025-03-21
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 25
25Unresolved
Related Reports
Relates :  
Description
As per  AVX512-FP16 ISA specification for VMAXPH and VMINPH,  NaN and -/+0.0 need the following special handling.

"If the values being compared are both 0.0s (of either sign), the value in the second operand (source
operand) is returned. If a value in the second operand is an SNaN, then SNaN is forwarded unchanged to
the destination (that is, a QNaN version of the SNaN is not returned).
If only one value is a NaN (SNaN or QNaN) for this instruction, the second operand (source operand), either
a NaN or a valid floating-point value, is written to the result. Suppose instead of this behavior, it is required that
the NaN source operand (from either the first or second operand) be returned. In that case, the action of VMINSH can
be emulated using a sequence of instructions, such as a comparison followed by AND, ANDN, and OR."

A similar sequence was added for float/double min/max operation by the following patch on the Panama-vector branch.

commit 0357665ebe2058b174438033acdaf25a16fd50b0
Author: Jatin Bhateja <jatin.bhateja@intel.com>
Date:   Wed Mar 6 13:45:32 2019 -0800

    Float/Double min/max implementation for x86

The upcoming AVX10.2 ISA extension will lift this limitation and align Min/Max with IEEE-754 specifications.


Comments
A pull request was submitted for review. Branch: master URL: https://git.openjdk.org/jdk/pull/24169 Date: 2025-03-21 20:20:24 +0000
21-03-2025

[~chagedorn] yes, I am in the process of validating the fix and will release the patch shortly. import jdk.incubator.vector.*; public class fp16_min_bench { public static final int iter = 10000; public static Float16 PZERO = Float16.valueOf(0.0f); public static Float16 NZERO = Float16.valueOf(-0.0f); public static float res = 0.0f; public static float min_kernel(Float16 a, Float16 b) { return Float16.min(a, b).floatValue(); } public static void main(String [] args) { for (int i = 0; i < iter; i++) { res = min_kernel(NZERO, PZERO); } System.out.println("[res] Float16.min(-0.0f, 0.0) = " + res); for (int i = 0; i < iter; i++) { res = min_kernel(Float16.NaN, Float16.valueOf((float)i)); } System.out.println("[res] Float16.min(NaN, 4.0) = " + res); for (int i = 0; i < iter; i++) { res = min_kernel(Float16.valueOf(5.0f), Float16.valueOf((float)i)); } System.out.println("[res] Float16.min(5.0, 4.0) = " + res); } } Results with latest jdk-25 builds WARNING: Using incubator modules: jdk.incubator.vector [res] Float16.min(-0.0f, 0.0) = 0.0 [res] Float16.min(NaN, 4.0) = 10000.0 [res] Float16.min(5.0, 4.0) = 5.0
21-03-2025

ILW = Wrong execution on AVX-512 with FLoat16.max/min, low, use -XX:UseAVX=2 = HLM = P3
21-03-2025

Thanks Jatin for the details!
21-03-2025

Is it currently producing wrong values due to the missing handling?
21-03-2025