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