1 /*
   2  * Copyright (c) 2019, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  */
  23 
  24 
  25 package org.graalvm.compiler.hotspot.jdk9.test;
  26 
  27 import static org.junit.Assume.assumeTrue;
  28 
  29 import java.util.ArrayList;
  30 import java.util.Collection;
  31 import java.util.List;
  32 
  33 import org.graalvm.compiler.core.test.GraalCompilerTest;
  34 import org.graalvm.compiler.test.AddExports;
  35 import org.junit.Before;
  36 import org.junit.Test;
  37 import org.junit.runner.RunWith;
  38 import org.junit.runners.Parameterized;
  39 import org.junit.runners.Parameterized.Parameter;
  40 import org.junit.runners.Parameterized.Parameters;
  41 
  42 import jdk.vm.ci.amd64.AMD64;
  43 
  44 @AddExports({"java.base/java.lang"})
  45 @RunWith(Parameterized.class)
  46 public final class MathDoubleFMATest extends GraalCompilerTest {
  47 
  48     @Before
  49     public void checkAMD64() {
  50         assumeTrue("skipping AMD64 specific test", getTarget().arch instanceof AMD64);
  51     }
  52 
  53     @Parameters(name = "{0}, {1}, {2}")
  54     public static Collection<Object[]> data() {
  55         double[] inputs = {0.0d, 1.0d, 4.0d, -0.0d, -1.0d, -4.0d, Double.MIN_VALUE, Double.MAX_VALUE, Double.NEGATIVE_INFINITY, Double.POSITIVE_INFINITY,
  56                         Double.NaN, Double.longBitsToDouble(0xfff0000000000001L)};
  57 
  58         List<Object[]> tests = new ArrayList<>();
  59         for (double a : inputs) {
  60             for (double b : inputs) {
  61                 for (double c : inputs) {
  62                     tests.add(new Object[]{a, b, c});
  63                 }
  64             }
  65         }
  66         return tests;
  67     }
  68 
  69     @Parameter(value = 0) public double input0;
  70     @Parameter(value = 1) public double input1;
  71     @Parameter(value = 2) public double input2;
  72 
  73     public static double fma(double a, double b, double c) {
  74         return Math.fma(a, b, c);
  75     }
  76 
  77     @Test
  78     public void testFMA() {
  79         test("fma", input0, input1, input2);
  80     }
  81 
  82 }