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.lir.aarch64; 26 27 import static jdk.vm.ci.aarch64.AArch64.v0; 28 import static jdk.vm.ci.aarch64.AArch64.v1; 29 30 import org.graalvm.compiler.core.common.LIRKind; 31 import org.graalvm.compiler.debug.GraalError; 32 import org.graalvm.compiler.lir.LIRInstructionClass; 33 import org.graalvm.compiler.lir.Variable; 34 import org.graalvm.compiler.lir.gen.LIRGenerator; 35 36 import jdk.vm.ci.aarch64.AArch64; 37 import jdk.vm.ci.aarch64.AArch64Kind; 38 import jdk.vm.ci.code.Register; 39 import jdk.vm.ci.code.RegisterValue; 40 import jdk.vm.ci.meta.Value; 41 42 public abstract class AArch64MathIntrinsicBinaryOp extends AArch64LIRInstruction { 43 44 @Def protected Value output; 45 @Use protected Value input0; 46 @Use protected Value input1; 47 @Temp protected Value[] temps; 48 49 public AArch64MathIntrinsicBinaryOp(LIRInstructionClass<? extends AArch64LIRInstruction> type, Register... registers) { 50 super(type); 51 input0 = v0.asValue(LIRKind.value(AArch64Kind.V64_WORD)); 52 input1 = v0.asValue(LIRKind.value(AArch64Kind.V64_WORD)); 53 output = v0.asValue(LIRKind.value(AArch64Kind.V64_WORD)); 54 55 temps = registersToValues(registers); 56 } 57 58 protected static Value[] registersToValues(Register[] registers) { 59 Value[] temps = new Value[registers.length]; 60 for (int i = 0; i < registers.length; i++) { 61 Register register = registers[i]; 62 if (AArch64.CPU.equals(register.getRegisterCategory())) { 63 temps[i] = register.asValue(LIRKind.value(AArch64Kind.V64_WORD)); 64 } else if (AArch64.SIMD.equals(register.getRegisterCategory())) { 65 temps[i] = register.asValue(LIRKind.value(AArch64Kind.V64_WORD)); 66 } else { 67 throw GraalError.shouldNotReachHere("Unsupported register type in math stubs."); 68 } 69 } 70 return temps; 71 } 72 73 public final Variable emitLIRWrapper(LIRGenerator gen, Value x, Value y) { 74 LIRKind kind = LIRKind.combine(x, y); 75 RegisterValue v0value = v0.asValue(kind); 76 gen.emitMove(v0value, x); 77 RegisterValue v1value = v1.asValue(kind); 78 gen.emitMove(v1value, y); 79 gen.append(this); 80 Variable result = gen.newVariable(kind); 81 gen.emitMove(result, v0value); 82 return result; 83 } 84 }