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

Incorrect computation in Float16 reduction loop

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Unresolved
    • Icon: P3 P3
    • 26
    • 25
    • hotspot
    • x86_64
    • generic

      Following test throws AssertionError with JDK-25 while it was passing with JDK-24.

      public class reduction_loop {

          public static short [] arr = { 15318, 15320, -1024, 15324, 15325, 15327, 15328, 15329 };

          public static int ITER = 10000;

          public static long GOLDEN = ADDReduceLong();

          static long ADDReduceLong() {
              short res = 0;
              for (int i = 0; i < 8; i++) {
                  res = Float.floatToFloat16(Float.float16ToFloat(res) + Float.float16ToFloat(arr[i]));
              }
              return (long)res;
          }

          public static void main(String [] args) {
              long res = 0;
              for (int i = 0; i < ITER; i++) {
                  res += ADDReduceLong();
              }

              if ((GOLDEN * ITER) != res) {
                  throw new AssertionError("Incorrect result, " + GOLDEN + " != " + res);
              }
              System.out.println("PASS");
          }
      }


      EMR>which java
      /usr/lib/jvm/java-24-openjdk-amd64//bin/java
      EMR>java -Xbatch -XX:-TieredCompilation --add-modules=jdk.incubator.vector -cp . reduction_loop
      WARNING: Using incubator modules: jdk.incubator.vector
      PASS
      EMR>
      EMR>export JAVA_HOME=/home/jatin_bhateja/softwares/jdk-25/
      EMR>export PATH=$JAVA_HOME/bin:$PATH
      EMR>which java
      /home/jatin_bhateja/softwares/jdk-25//bin/java
      EMR>
      EMR>
      EMR>java -Xbatch -XX:-TieredCompilation --add-modules=jdk.incubator.vector -cp . reduction_loop
      WARNING: Using incubator modules: jdk.incubator.vector
      Exception in thread "main" java.lang.AssertionError: Incorrect result, -1024 != 544587776
              at reduction_loop.main(reduction_loop.java:25)

            jbhateja Jatin Bhateja
            jbhateja Jatin Bhateja
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated: