1 /* 2 * Copyright (c) 2018, 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.amd64.test; 26 27 import static org.junit.Assume.assumeTrue; 28 29 import java.util.ArrayList; 30 import java.util.List; 31 32 import org.graalvm.compiler.api.test.Graal; 33 import org.graalvm.compiler.core.test.GraalCompilerTest; 34 import org.graalvm.compiler.runtime.RuntimeProvider; 35 import org.junit.Before; 36 import org.junit.Test; 37 import org.junit.runner.RunWith; 38 import org.junit.runners.Parameterized; 39 40 import jdk.vm.ci.amd64.AMD64; 41 import jdk.vm.ci.code.Architecture; 42 43 @RunWith(Parameterized.class) 44 public class UnaryMathStubTest extends GraalCompilerTest { 45 46 @Parameterized.Parameters(name = "{0}") 47 public static List<Object[]> data() { 48 ArrayList<Object[]> ret = new ArrayList<>(); 49 ret.add(new Object[]{"sin"}); 50 ret.add(new Object[]{"cos"}); 51 ret.add(new Object[]{"tan"}); 52 ret.add(new Object[]{"exp"}); 53 ret.add(new Object[]{"log"}); 54 ret.add(new Object[]{"log10"}); 55 return ret; 56 } 57 58 private static final double[] inputs = {0.0D, Math.PI / 2, Math.PI, -1.0D, Double.MAX_VALUE, Double.MIN_VALUE, Double.NaN, Double.POSITIVE_INFINITY, Double.NEGATIVE_INFINITY}; 59 private final String stub; 60 61 public UnaryMathStubTest(String stub) { 62 this.stub = stub; 63 } 64 65 @Before 66 public void checkAMD64() { 67 Architecture arch = Graal.getRequiredCapability(RuntimeProvider.class).getHostBackend().getTarget().arch; 68 assumeTrue("skipping AMD64 specific test", arch instanceof AMD64); 69 } 70 71 public static double sin(double value) { 72 return Math.sin(value); 73 } 74 75 public static double cos(double value) { 76 return Math.cos(value); 77 } 78 79 public static double tan(double value) { 80 return Math.tan(value); 81 } 82 83 public static double exp(double value) { 84 return Math.exp(value); 85 } 86 87 public static double log(double value) { 88 return Math.log(value); 89 } 90 91 public static double log10(double value) { 92 return Math.log10(value); 93 } 94 95 @Test 96 public void testStub() { 97 for (double input : inputs) { 98 test(stub, input); 99 } 100 } 101 }