AMD64MathStub.java revision 12968:4d8a004e5c6d
1/* 2 * Copyright (c) 2016, 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 */ 23package org.graalvm.compiler.hotspot.amd64; 24 25import static org.graalvm.compiler.hotspot.amd64.AMD64HotSpotForeignCallsProvider.ARITHMETIC_COS_STUB; 26import static org.graalvm.compiler.hotspot.amd64.AMD64HotSpotForeignCallsProvider.ARITHMETIC_EXP_STUB; 27import static org.graalvm.compiler.hotspot.amd64.AMD64HotSpotForeignCallsProvider.ARITHMETIC_LOG10_STUB; 28import static org.graalvm.compiler.hotspot.amd64.AMD64HotSpotForeignCallsProvider.ARITHMETIC_LOG_STUB; 29import static org.graalvm.compiler.hotspot.amd64.AMD64HotSpotForeignCallsProvider.ARITHMETIC_POW_STUB; 30import static org.graalvm.compiler.hotspot.amd64.AMD64HotSpotForeignCallsProvider.ARITHMETIC_SIN_STUB; 31import static org.graalvm.compiler.hotspot.amd64.AMD64HotSpotForeignCallsProvider.ARITHMETIC_TAN_STUB; 32 33import org.graalvm.compiler.api.replacements.Snippet; 34import org.graalvm.compiler.core.common.spi.ForeignCallDescriptor; 35import org.graalvm.compiler.hotspot.HotSpotForeignCallLinkage; 36import org.graalvm.compiler.hotspot.meta.HotSpotProviders; 37import org.graalvm.compiler.hotspot.stubs.SnippetStub; 38import org.graalvm.compiler.options.OptionValues; 39import org.graalvm.compiler.replacements.nodes.BinaryMathIntrinsicNode; 40import org.graalvm.compiler.replacements.nodes.BinaryMathIntrinsicNode.BinaryOperation; 41import org.graalvm.compiler.replacements.nodes.UnaryMathIntrinsicNode; 42import org.graalvm.compiler.replacements.nodes.UnaryMathIntrinsicNode.UnaryOperation; 43 44/** 45 * Stub called to support {@link Math}. 46 */ 47public class AMD64MathStub extends SnippetStub { 48 49 public AMD64MathStub(ForeignCallDescriptor descriptor, OptionValues options, HotSpotProviders providers, HotSpotForeignCallLinkage linkage) { 50 super(snippetName(descriptor), options, providers, linkage); 51 } 52 53 private static String snippetName(ForeignCallDescriptor descriptor) { 54 if (descriptor == ARITHMETIC_LOG_STUB) { 55 return "log"; 56 } 57 if (descriptor == ARITHMETIC_LOG10_STUB) { 58 return "log10"; 59 } 60 if (descriptor == ARITHMETIC_SIN_STUB) { 61 return "sin"; 62 } 63 if (descriptor == ARITHMETIC_COS_STUB) { 64 return "cos"; 65 } 66 if (descriptor == ARITHMETIC_TAN_STUB) { 67 return "tan"; 68 } 69 if (descriptor == ARITHMETIC_EXP_STUB) { 70 return "exp"; 71 } 72 if (descriptor == ARITHMETIC_POW_STUB) { 73 return "pow"; 74 } 75 throw new InternalError("Unknown operation " + descriptor); 76 } 77 78 @Snippet 79 private static double log(double value) { 80 return UnaryMathIntrinsicNode.compute(value, UnaryOperation.LOG); 81 } 82 83 @Snippet 84 private static double log10(double value) { 85 return UnaryMathIntrinsicNode.compute(value, UnaryOperation.LOG10); 86 } 87 88 @Snippet 89 private static double sin(double value) { 90 return UnaryMathIntrinsicNode.compute(value, UnaryOperation.SIN); 91 } 92 93 @Snippet 94 private static double cos(double value) { 95 return UnaryMathIntrinsicNode.compute(value, UnaryOperation.COS); 96 } 97 98 @Snippet 99 private static double tan(double value) { 100 return UnaryMathIntrinsicNode.compute(value, UnaryOperation.TAN); 101 } 102 103 @Snippet 104 private static double exp(double value) { 105 return UnaryMathIntrinsicNode.compute(value, UnaryOperation.EXP); 106 } 107 108 @Snippet 109 private static double pow(double value1, double value2) { 110 return BinaryMathIntrinsicNode.compute(value1, value2, BinaryOperation.POW); 111 } 112} 113