< prev index next >

test/hotspot/jtreg/compiler/intrinsics/math/TestFpMinMaxIntrinsics.java

Print this page


   1 /*
   2  * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved.
   3  * Copyright (c) 2018, Arm Limited. All rights reserved.
   4  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   5  *
   6  * This code is free software; you can redistribute it and/or modify it
   7  * under the terms of the GNU General Public License version 2 only, as
   8  * published by the Free Software Foundation.
   9  *
  10  * This code is distributed in the hope that it will be useful, but WITHOUT
  11  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  12  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  13  * version 2 for more details (a copy is included in the LICENSE file that
  14  * accompanied this code).
  15  *
  16  * You should have received a copy of the GNU General Public License version
  17  * 2 along with this work; if not, write to the Free Software Foundation,
  18  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  19  *
  20  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  21  * or visit www.oracle.com if you need additional information or have any
  22  * questions.
  23  */
  24 
  25 /*
  26  * @test
  27  * @bug 8212043
  28  * @summary Test compiler intrinsics of floating-point Math.min/max
  29  *
  30  * @run main/othervm -Xint compiler.intrinsics.math.TestFpMinMaxIntrinsics
  31  * @run main/othervm -XX:+UnlockDiagnosticVMOptions
  32  *                   -Xcomp -XX:TieredStopAtLevel=1
  33  *                   -XX:CompileOnly=java/lang/Math
  34  *                   compiler.intrinsics.math.TestFpMinMaxIntrinsics
  35  * @run main/othervm -XX:+UnlockDiagnosticVMOptions
  36  *                   -Xcomp -XX:-TieredCompilation
  37  *                   -XX:CompileOnly=java/lang/Math
  38  *                   compiler.intrinsics.math.TestFpMinMaxIntrinsics




  39  */
  40 
  41 package compiler.intrinsics.math;
  42 
  43 import java.util.Arrays;
  44 
  45 public class TestFpMinMaxIntrinsics {
  46 
  47     private static final float fPos     =  15280.0f;
  48     private static final float fNeg     = -55555.5f;
  49     private static final float fPosZero =      0.0f;
  50     private static final float fNegZero =     -0.0f;
  51     private static final float fPosInf  = Float.POSITIVE_INFINITY;
  52     private static final float fNegInf  = Float.NEGATIVE_INFINITY;
  53     private static final float fNaN     = Float.NaN;
  54 
  55     private static final double dPos     =  482390926662501720.0;
  56     private static final double dNeg     = -333333333333333333.3;
  57     private static final double dPosZero =                   0.0;
  58     private static final double dNegZero =                  -0.0;
  59     private static final double dPosInf  = Double.POSITIVE_INFINITY;
  60     private static final double dNegInf  = Double.NEGATIVE_INFINITY;
  61     private static final double dNaN     = Double.NaN;
  62 
  63     private static final float[][] f_cases = {
  64         //     a         b         min       max
  65         {     fPos,     fPos,     fPos,     fPos },
  66         {     fPos,     fNeg,     fNeg,     fPos },

  67         { fPosZero, fNegZero, fNegZero, fPosZero },

  68         { fNegZero, fNegZero, fNegZero, fNegZero },

  69         {     fPos,  fPosInf,     fPos,  fPosInf },
  70         {     fNeg,  fNegInf,  fNegInf,     fNeg },

  71         {     fPos,     fNaN,     fNaN,     fNaN },






  72         {  fNegInf,     fNaN,     fNaN,     fNaN },

  73     };
  74 
  75     private static final double[][] d_cases = {
  76         //     a         b         min       max
  77         {     dPos,     dPos,     dPos,     dPos },
  78         {     dPos,     dNeg,     dNeg,     dPos },

  79         { dPosZero, dNegZero, dNegZero, dPosZero },

  80         { dNegZero, dNegZero, dNegZero, dNegZero },

  81         {     dPos,  dPosInf,     dPos,  dPosInf },
  82         {     dNeg,  dNegInf,  dNegInf,     dNeg },

  83         {     dPos,     dNaN,     dNaN,     dNaN },






  84         {  dNegInf,     dNaN,     dNaN,     dNaN },

  85     };
  86 
  87     private static void fTest(float[] row) {
  88         float min = Math.min(row[0], row[1]);
  89         float max = Math.max(row[0], row[1]);
  90         if (Float.isNaN(min) && Float.isNaN(max)
  91                 && Float.isNaN(row[2]) && Float.isNaN(row[3])) {
  92             // Return if all of them are NaN
  93             return;
  94         }
  95         if (min != row[2] || max != row[3]) {
  96             throw new AssertionError("Unexpected result of float min/max: " +
  97                     "a = " + row[0] + ", b = " + row[1] + ", " +
  98                     "result = (" + min + ", " + max + "), " +
  99                     "expected = (" + row[2] + ", " + row[3] + ")");
 100         }
 101     }
 102 
 103     private static void dTest(double[] row) {
 104         double min = Math.min(row[0], row[1]);
 105         double max = Math.max(row[0], row[1]);
 106         if (Double.isNaN(min) && Double.isNaN(max)
 107                 && Double.isNaN(row[2]) && Double.isNaN(row[3])) {
 108             // Return if all of them are NaN
 109             return;
 110         }
 111         if (min != row[2] || max != row[3]) {
 112             throw new AssertionError("Unexpected result of double min/max" +
 113                     "a = " + row[0] + ", b = " + row[1] + ", " +
 114                     "result = (" + min + ", " + max + "), " +
 115                     "expected = (" + row[2] + ", " + row[3] + ")");
 116         }
 117     }
 118 
 119     public static void main(String[] args) {

 120         Arrays.stream(f_cases).forEach(TestFpMinMaxIntrinsics::fTest);
 121         Arrays.stream(d_cases).forEach(TestFpMinMaxIntrinsics::dTest);
 122         System.out.println("PASS");
 123     }
 124 }
 125 
   1 /*
   2  * Copyright (c) 2018, 2019, Oracle and/or its affiliates. All rights reserved.
   3  * Copyright (c) 2018, 2019, Arm Limited. All rights reserved.
   4  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   5  *
   6  * This code is free software; you can redistribute it and/or modify it
   7  * under the terms of the GNU General Public License version 2 only, as
   8  * published by the Free Software Foundation.
   9  *
  10  * This code is distributed in the hope that it will be useful, but WITHOUT
  11  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  12  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  13  * version 2 for more details (a copy is included in the LICENSE file that
  14  * accompanied this code).
  15  *
  16  * You should have received a copy of the GNU General Public License version
  17  * 2 along with this work; if not, write to the Free Software Foundation,
  18  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  19  *
  20  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  21  * or visit www.oracle.com if you need additional information or have any
  22  * questions.
  23  */
  24 
  25 /*
  26  * @test
  27  * @bug 8212043
  28  * @summary Test compiler intrinsics of floating-point Math.min/max
  29  *
  30  * @run main/othervm -Xint compiler.intrinsics.math.TestFpMinMaxIntrinsics
  31  * @run main/othervm -XX:+UnlockDiagnosticVMOptions
  32  *                   -Xcomp -XX:TieredStopAtLevel=1
  33  *                   -XX:CompileOnly=java/lang/Math
  34  *                   compiler.intrinsics.math.TestFpMinMaxIntrinsics
  35  * @run main/othervm -XX:+UnlockDiagnosticVMOptions
  36  *                   -Xcomp -XX:-TieredCompilation
  37  *                   -XX:CompileOnly=java/lang/Math
  38  *                   compiler.intrinsics.math.TestFpMinMaxIntrinsics
  39  * @run main/othervm -XX:+IgnoreUnrecognizedVMOptions -XX:+UnlockDiagnosticVMOptions
  40  *                   -XX:-TieredCompilation -XX:CompileThresholdScaling=0.1
  41  *                   -XX:CompileCommand=print,compiler/intrinsics/math/TestFpMinMaxIntrinsics.*Test*
  42  *                   compiler.intrinsics.math.TestFpMinMaxIntrinsics
  43  */
  44 
  45 package compiler.intrinsics.math;
  46 
  47 import java.util.Arrays;
  48 
  49 public class TestFpMinMaxIntrinsics {
  50 
  51     private static final float fPos     =  15280.0f;
  52     private static final float fNeg     = -55555.5f;
  53     private static final float fPosZero =      0.0f;
  54     private static final float fNegZero =     -0.0f;
  55     private static final float fPosInf  = Float.POSITIVE_INFINITY;
  56     private static final float fNegInf  = Float.NEGATIVE_INFINITY;
  57     private static final float fNaN     = Float.NaN;
  58 
  59     private static final double dPos     =  482390926662501720.0;
  60     private static final double dNeg     = -333333333333333333.3;
  61     private static final double dPosZero =                   0.0;
  62     private static final double dNegZero =                  -0.0;
  63     private static final double dPosInf  = Double.POSITIVE_INFINITY;
  64     private static final double dNegInf  = Double.NEGATIVE_INFINITY;
  65     private static final double dNaN     = Double.NaN;
  66 
  67     private static final float[][] f_cases = {
  68         //     a         b         min       max
  69         {     fPos,     fPos,     fPos,     fPos },
  70         {     fPos,     fNeg,     fNeg,     fPos },
  71 
  72         { fPosZero, fNegZero, fNegZero, fPosZero },
  73         { fNegZero, fPosZero, fNegZero, fPosZero },
  74         { fNegZero, fNegZero, fNegZero, fNegZero },
  75 
  76         {     fPos,  fPosInf,     fPos,  fPosInf },
  77         {     fNeg,  fNegInf,  fNegInf,     fNeg },
  78 
  79         {     fPos,     fNaN,     fNaN,     fNaN },
  80         {     fNaN,     fPos,     fNaN,     fNaN },
  81         {     fNeg,     fNaN,     fNaN,     fNaN },
  82         {     fNaN,     fNeg,     fNaN,     fNaN },
  83 
  84         {  fPosInf,     fNaN,     fNaN,     fNaN },
  85         {     fNaN,  fPosInf,     fNaN,     fNaN },
  86         {  fNegInf,     fNaN,     fNaN,     fNaN },
  87         {     fNaN,  fNegInf,     fNaN,     fNaN }
  88     };
  89 
  90     private static final double[][] d_cases = {
  91         //     a         b         min       max
  92         {     dPos,     dPos,     dPos,     dPos },
  93         {     dPos,     dNeg,     dNeg,     dPos },
  94 
  95         { dPosZero, dNegZero, dNegZero, dPosZero },
  96         { dNegZero, dPosZero, dNegZero, dPosZero },
  97         { dNegZero, dNegZero, dNegZero, dNegZero },
  98 
  99         {     dPos,  dPosInf,     dPos,  dPosInf },
 100         {     dNeg,  dNegInf,  dNegInf,     dNeg },
 101 
 102         {     dPos,     dNaN,     dNaN,     dNaN },
 103         {     dNaN,     dPos,     dNaN,     dNaN },
 104         {     dNeg,     dNaN,     dNaN,     dNaN },
 105         {     dNaN,     dNeg,     dNaN,     dNaN },
 106 
 107         {  dPosInf,     dNaN,     dNaN,     dNaN },
 108         {     dNaN,  dPosInf,     dNaN,     dNaN },
 109         {  dNegInf,     dNaN,     dNaN,     dNaN },
 110         {     dNaN,  dNegInf,     dNaN,     dNaN }
 111     };
 112 
 113     private static void fTest(float[] row) {
 114         float min = Math.min(row[0], row[1]);
 115         float max = Math.max(row[0], row[1]);
 116         if (Float.isNaN(min) && Float.isNaN(max)
 117                 && Float.isNaN(row[2]) && Float.isNaN(row[3])) {
 118             // Return if all of them are NaN
 119             return;
 120         }
 121         if (min != row[2] || max != row[3]) {
 122             throw new AssertionError("Unexpected result of float min/max: " +
 123                     "a = " + row[0] + ", b = " + row[1] + ", " +
 124                     "result = (" + min + ", " + max + "), " +
 125                     "expected = (" + row[2] + ", " + row[3] + ")");
 126         }
 127     }
 128 
 129     private static void dTest(double[] row) {
 130         double min = Math.min(row[0], row[1]);
 131         double max = Math.max(row[0], row[1]);
 132         if (Double.isNaN(min) && Double.isNaN(max)
 133                 && Double.isNaN(row[2]) && Double.isNaN(row[3])) {
 134             // Return if all of them are NaN
 135             return;
 136         }
 137         if (min != row[2] || max != row[3]) {
 138             throw new AssertionError("Unexpected result of double min/max: " +
 139                     "a = " + row[0] + ", b = " + row[1] + ", " +
 140                     "result = (" + min + ", " + max + "), " +
 141                     "expected = (" + row[2] + ", " + row[3] + ")");
 142         }
 143     }
 144 
 145     public static void main(String[] args) {
 146         for (int i = 0 ; i < 10_000 ; i++) {
 147             Arrays.stream(f_cases).forEach(TestFpMinMaxIntrinsics::fTest);
 148             Arrays.stream(d_cases).forEach(TestFpMinMaxIntrinsics::dTest);
 149         }
 150     }
 151 }
 152 
< prev index next >