1 /* 2 * Copyright (c) 2016, 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; 26 27 import static org.graalvm.compiler.hotspot.HotSpotBackend.Options.GraalArithmeticStubs; 28 import static org.graalvm.compiler.hotspot.amd64.AMD64HotSpotMathIntrinsicOp.IntrinsicOpcode.COS; 29 import static org.graalvm.compiler.hotspot.amd64.AMD64HotSpotMathIntrinsicOp.IntrinsicOpcode.LOG; 30 import static org.graalvm.compiler.hotspot.amd64.AMD64HotSpotMathIntrinsicOp.IntrinsicOpcode.LOG10; 31 import static org.graalvm.compiler.hotspot.amd64.AMD64HotSpotMathIntrinsicOp.IntrinsicOpcode.SIN; 32 import static org.graalvm.compiler.hotspot.amd64.AMD64HotSpotMathIntrinsicOp.IntrinsicOpcode.TAN; 33 34 import org.graalvm.compiler.core.amd64.AMD64ArithmeticLIRGenerator; 35 import org.graalvm.compiler.core.common.LIRKind; 36 import org.graalvm.compiler.hotspot.HotSpotBackend.Options; 37 import org.graalvm.compiler.lir.Variable; 38 import org.graalvm.compiler.lir.gen.LIRGenerator; 39 40 import jdk.vm.ci.meta.Value; 41 42 /** 43 * Lowering of selected {@link Math} routines that depends on the value of 44 * {@link Options#GraalArithmeticStubs}. 45 */ 46 public class AMD64HotSpotMaths implements AMD64ArithmeticLIRGenerator.Maths { 47 48 @Override 49 public Variable emitLog(LIRGenerator gen, Value input, boolean base10) { 50 if (GraalArithmeticStubs.getValue(gen.getResult().getLIR().getOptions())) { 51 return null; 52 } 53 Variable result = gen.newVariable(LIRKind.combine(input)); 54 gen.append(new AMD64HotSpotMathIntrinsicOp(base10 ? LOG10 : LOG, result, gen.asAllocatable(input))); 55 return result; 56 } 57 58 @Override 59 public Variable emitCos(LIRGenerator gen, Value input) { 60 if (GraalArithmeticStubs.getValue(gen.getResult().getLIR().getOptions())) { 61 return null; 62 } 63 Variable result = gen.newVariable(LIRKind.combine(input)); 64 gen.append(new AMD64HotSpotMathIntrinsicOp(COS, result, gen.asAllocatable(input))); 65 return result; 66 } 67 68 @Override 69 public Variable emitSin(LIRGenerator gen, Value input) { 70 if (GraalArithmeticStubs.getValue(gen.getResult().getLIR().getOptions())) { 71 return null; 72 } 73 Variable result = gen.newVariable(LIRKind.combine(input)); 74 gen.append(new AMD64HotSpotMathIntrinsicOp(SIN, result, gen.asAllocatable(input))); 75 return result; 76 } 77 78 @Override 79 public Variable emitTan(LIRGenerator gen, Value input) { 80 if (GraalArithmeticStubs.getValue(gen.getResult().getLIR().getOptions())) { 81 return null; 82 } 83 Variable result = gen.newVariable(LIRKind.combine(input)); 84 gen.append(new AMD64HotSpotMathIntrinsicOp(TAN, result, gen.asAllocatable(input))); 85 return result; 86 } 87 88 }