43972
|
1 |
/*
|
52910
|
2 |
* Copyright (c) 2011, 2018, Oracle and/or its affiliates. All rights reserved.
|
43972
|
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 |
*/
|
50858
|
23 |
|
|
24 |
|
43972
|
25 |
package org.graalvm.compiler.hotspot.amd64;
|
|
26 |
|
|
27 |
import static jdk.vm.ci.code.ValueUtil.asRegister;
|
|
28 |
|
|
29 |
import org.graalvm.compiler.asm.amd64.AMD64MacroAssembler;
|
|
30 |
import org.graalvm.compiler.debug.GraalError;
|
|
31 |
import org.graalvm.compiler.lir.LIRInstructionClass;
|
|
32 |
import org.graalvm.compiler.lir.Opcode;
|
|
33 |
import org.graalvm.compiler.lir.amd64.AMD64LIRInstruction;
|
|
34 |
import org.graalvm.compiler.lir.asm.CompilationResultBuilder;
|
|
35 |
|
|
36 |
import jdk.vm.ci.amd64.AMD64Kind;
|
|
37 |
import jdk.vm.ci.meta.Value;
|
|
38 |
|
|
39 |
/**
|
|
40 |
* This provides the default implementation expected by some HotSpot based lowerings of Math
|
|
41 |
* intrinsics. Depending on the release different patterns might be used.
|
|
42 |
*/
|
|
43 |
public final class AMD64HotSpotMathIntrinsicOp extends AMD64LIRInstruction {
|
|
44 |
public static final LIRInstructionClass<AMD64HotSpotMathIntrinsicOp> TYPE = LIRInstructionClass.create(AMD64HotSpotMathIntrinsicOp.class);
|
|
45 |
|
|
46 |
public enum IntrinsicOpcode {
|
|
47 |
SIN,
|
|
48 |
COS,
|
|
49 |
TAN,
|
|
50 |
LOG,
|
|
51 |
LOG10
|
|
52 |
}
|
|
53 |
|
|
54 |
@Opcode private final IntrinsicOpcode opcode;
|
|
55 |
@Def protected Value result;
|
|
56 |
@Use protected Value input;
|
|
57 |
|
|
58 |
public AMD64HotSpotMathIntrinsicOp(IntrinsicOpcode opcode, Value result, Value input) {
|
|
59 |
super(TYPE);
|
|
60 |
this.opcode = opcode;
|
|
61 |
this.result = result;
|
|
62 |
this.input = input;
|
|
63 |
}
|
|
64 |
|
|
65 |
@Override
|
|
66 |
public void emitCode(CompilationResultBuilder crb, AMD64MacroAssembler masm) {
|
|
67 |
switch (opcode) {
|
|
68 |
case LOG:
|
|
69 |
masm.flog(asRegister(result, AMD64Kind.DOUBLE), asRegister(input, AMD64Kind.DOUBLE), false);
|
|
70 |
break;
|
|
71 |
case LOG10:
|
|
72 |
masm.flog(asRegister(result, AMD64Kind.DOUBLE), asRegister(input, AMD64Kind.DOUBLE), true);
|
|
73 |
break;
|
|
74 |
case SIN:
|
|
75 |
masm.fsin(asRegister(result, AMD64Kind.DOUBLE), asRegister(input, AMD64Kind.DOUBLE));
|
|
76 |
break;
|
|
77 |
case COS:
|
|
78 |
masm.fcos(asRegister(result, AMD64Kind.DOUBLE), asRegister(input, AMD64Kind.DOUBLE));
|
|
79 |
break;
|
|
80 |
case TAN:
|
|
81 |
masm.ftan(asRegister(result, AMD64Kind.DOUBLE), asRegister(input, AMD64Kind.DOUBLE));
|
|
82 |
break;
|
|
83 |
default:
|
|
84 |
throw GraalError.shouldNotReachHere();
|
|
85 |
}
|
|
86 |
}
|
|
87 |
}
|