-
Type:
Bug
-
Resolution: Unresolved
-
Priority:
P4
-
Affects Version/s: 21
-
Component/s: hotspot
-
x86_64
-
generic
The following test shows different results with the Interpreter and the C1/C2 compiler.
public class bug_fp32_fp16_conv {
public static int POS_NAN = 0x7fc00000;
public static int NEG_NAN = 0xffc00000;
public static short GOLDEN = Float.floatToFloat16(Float.intBitsToFloat(NEG_NAN) + Float.intBitsToFloat(POS_NAN));
public static short micro() {
return Float.floatToFloat16(Float.intBitsToFloat(NEG_NAN) + Float.intBitsToFloat(POS_NAN));
}
public static void main(String [] args) {
short [] res = new short[1024];
for (int i = 0; i < 10000; i++) {
for (int j = 0; j < 1024; j++) {
res[j] = micro();
}
}
for (int i = 0; i < 1024; i++) {
if (GOLDEN != res[i]) {
throw new AssertionError("FAIL " + " GOLDEN = " + GOLDEN + " != ACTUAL = " + res[i]);
}
}
System.out.println("PASS");
}
}
EMR>javac bug_fp32_fp16_conv.java
EMR>java -Xbatch -Xint -cp . bug_fp32_fp16_conv
PASS
EMR>
EMR>
EMR>java -Xbatch -XX:TieredStopAtLevel=3 -cp . bug_fp32_fp16_conv
Exception in thread "main" java.lang.AssertionError: FAIL GOLDEN = 32256 != ACTUAL = -512
at bug_fp32_fp16_conv.main(bug_fp32_fp16_conv.java:25)
The problem can also be reproduced with JDK-21.
public class bug_fp32_fp16_conv {
public static int POS_NAN = 0x7fc00000;
public static int NEG_NAN = 0xffc00000;
public static short GOLDEN = Float.floatToFloat16(Float.intBitsToFloat(NEG_NAN) + Float.intBitsToFloat(POS_NAN));
public static short micro() {
return Float.floatToFloat16(Float.intBitsToFloat(NEG_NAN) + Float.intBitsToFloat(POS_NAN));
}
public static void main(String [] args) {
short [] res = new short[1024];
for (int i = 0; i < 10000; i++) {
for (int j = 0; j < 1024; j++) {
res[j] = micro();
}
}
for (int i = 0; i < 1024; i++) {
if (GOLDEN != res[i]) {
throw new AssertionError("FAIL " + " GOLDEN = " + GOLDEN + " != ACTUAL = " + res[i]);
}
}
System.out.println("PASS");
}
}
EMR>javac bug_fp32_fp16_conv.java
EMR>java -Xbatch -Xint -cp . bug_fp32_fp16_conv
PASS
EMR>
EMR>
EMR>java -Xbatch -XX:TieredStopAtLevel=3 -cp . bug_fp32_fp16_conv
Exception in thread "main" java.lang.AssertionError: FAIL GOLDEN = 32256 != ACTUAL = -512
at bug_fp32_fp16_conv.main(bug_fp32_fp16_conv.java:25)
The problem can also be reproduced with JDK-21.