annotate graal/com.oracle.graal.replacements/src/com/oracle/graal/replacements/MathSubstitutionsX86.java @ 9737:34c892fdfb6d

moved responsibility for determining if a foreign call has a side effect to the runtime
author Doug Simon <doug.simon@oracle.com>
date Thu, 16 May 2013 16:32:46 +0200
parents 951d5ebf3c49
children 857632c8086a
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
1 /*
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
2 * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
4 *
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
5 * This code is free software; you can redistribute it and/or modify it
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
6 * under the terms of the GNU General Public License version 2 only, as
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
7 * published by the Free Software Foundation.
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
8 *
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
9 * This code is distributed in the hope that it will be useful, but WITHOUT
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
12 * version 2 for more details (a copy is included in the LICENSE file that
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
13 * accompanied this code).
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
14 *
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
15 * You should have received a copy of the GNU General Public License version
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
16 * 2 along with this work; if not, write to the Free Software Foundation,
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
18 *
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
20 * or visit www.oracle.com if you need additional information or have any
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
21 * questions.
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
22 */
8415
2361bf148c06 rename packages: *snippets* -> *replacements*
Doug Simon <doug.simon@oracle.com>
parents: 7556
diff changeset
23 package com.oracle.graal.replacements;
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
24
9736
951d5ebf3c49 refactored ForeignCallDescriptor into a top level class and moved it to the api.meta project
Doug Simon <doug.simon@oracle.com>
parents: 9735
diff changeset
25 import com.oracle.graal.api.meta.*;
8420
5d3fa6f949fb created com.oracle.graal.api.replacements project and moved ClassSubstitution and MethodSubstitution there
Doug Simon <doug.simon@oracle.com>
parents: 8419
diff changeset
26 import com.oracle.graal.api.replacements.*;
6521
2a0c9f20baa1 consolidated framework for runtime and stub calls and moved declaration of descriptors for such calls to the source file in which they are used
Doug Simon <doug.simon@oracle.com>
parents: 5579
diff changeset
27 import com.oracle.graal.graph.Node.ConstantNodeParameter;
2a0c9f20baa1 consolidated framework for runtime and stub calls and moved declaration of descriptors for such calls to the source file in which they are used
Doug Simon <doug.simon@oracle.com>
parents: 5579
diff changeset
28 import com.oracle.graal.graph.Node.NodeIntrinsic;
5060
4ed4295ce15f Update import statements.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 5059
diff changeset
29 import com.oracle.graal.nodes.extended.*;
8415
2361bf148c06 rename packages: *snippets* -> *replacements*
Doug Simon <doug.simon@oracle.com>
parents: 7556
diff changeset
30 import com.oracle.graal.replacements.nodes.*;
8481
92571f3eeeeb made VM independent method substitutions be interpretable
Doug Simon <doug.simon@oracle.com>
parents: 8451
diff changeset
31 import com.oracle.graal.replacements.nodes.MathIntrinsicNode.Operation;
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
32
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
33 /**
7356
fe9f252f0d05 renamings to clarify the difference between lowering/stub snippets and substitution snippets (the end goal is to remove the term 'snippet' from the latter altogether)
Doug Simon <doug.simon@oracle.com>
parents: 7355
diff changeset
34 * Substitutions for {@link java.lang.Math} methods.
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
35 */
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
36 @ClassSubstitution(java.lang.Math.class)
7356
fe9f252f0d05 renamings to clarify the difference between lowering/stub snippets and substitution snippets (the end goal is to remove the term 'snippet' from the latter altogether)
Doug Simon <doug.simon@oracle.com>
parents: 7355
diff changeset
37 public class MathSubstitutionsX86 {
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
38
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
39 private static final double PI_4 = 0.7853981633974483;
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
40
7355
8c163cfda1e5 only @MethodSubstitution annotated methods are now considered to be method substitutions which allows for helper methods to be in the same class
Doug Simon <doug.simon@oracle.com>
parents: 7300
diff changeset
41 @MethodSubstitution
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
42 public static double abs(double x) {
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
43 return MathIntrinsicNode.compute(x, Operation.ABS);
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
44 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
45
7355
8c163cfda1e5 only @MethodSubstitution annotated methods are now considered to be method substitutions which allows for helper methods to be in the same class
Doug Simon <doug.simon@oracle.com>
parents: 7300
diff changeset
46 @MethodSubstitution
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
47 public static double sqrt(double x) {
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
48 return MathIntrinsicNode.compute(x, Operation.SQRT);
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
49 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
50
7355
8c163cfda1e5 only @MethodSubstitution annotated methods are now considered to be method substitutions which allows for helper methods to be in the same class
Doug Simon <doug.simon@oracle.com>
parents: 7300
diff changeset
51 @MethodSubstitution
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
52 public static double log(double x) {
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
53 return MathIntrinsicNode.compute(x, Operation.LOG);
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
54 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
55
7355
8c163cfda1e5 only @MethodSubstitution annotated methods are now considered to be method substitutions which allows for helper methods to be in the same class
Doug Simon <doug.simon@oracle.com>
parents: 7300
diff changeset
56 @MethodSubstitution
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
57 public static double log10(double x) {
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
58 return MathIntrinsicNode.compute(x, Operation.LOG10);
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
59 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
60
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
61 // NOTE on snippets below:
7530
5e3d1a68664e applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents: 7356
diff changeset
62 // Math.sin(), .cos() and .tan() guarantee a value within 1 ULP of the
5e3d1a68664e applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents: 7356
diff changeset
63 // exact result, but x87 trigonometric FPU instructions are only that
5e3d1a68664e applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents: 7356
diff changeset
64 // accurate within [-pi/4, pi/4]. Examine the passed value and provide
5e3d1a68664e applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents: 7356
diff changeset
65 // a slow path for inputs outside of that interval.
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
66
7355
8c163cfda1e5 only @MethodSubstitution annotated methods are now considered to be method substitutions which allows for helper methods to be in the same class
Doug Simon <doug.simon@oracle.com>
parents: 7300
diff changeset
67 @MethodSubstitution
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
68 public static double sin(double x) {
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
69 if (abs(x) < PI_4) {
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
70 return MathIntrinsicNode.compute(x, Operation.SIN);
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
71 } else {
6521
2a0c9f20baa1 consolidated framework for runtime and stub calls and moved declaration of descriptors for such calls to the source file in which they are used
Doug Simon <doug.simon@oracle.com>
parents: 5579
diff changeset
72 return callDouble(ARITHMETIC_SIN, x);
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
73 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
74 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
75
7355
8c163cfda1e5 only @MethodSubstitution annotated methods are now considered to be method substitutions which allows for helper methods to be in the same class
Doug Simon <doug.simon@oracle.com>
parents: 7300
diff changeset
76 @MethodSubstitution
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
77 public static double cos(double x) {
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
78 if (abs(x) < PI_4) {
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
79 return MathIntrinsicNode.compute(x, Operation.COS);
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
80 } else {
6521
2a0c9f20baa1 consolidated framework for runtime and stub calls and moved declaration of descriptors for such calls to the source file in which they are used
Doug Simon <doug.simon@oracle.com>
parents: 5579
diff changeset
81 return callDouble(ARITHMETIC_COS, x);
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
82 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
83 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
84
7355
8c163cfda1e5 only @MethodSubstitution annotated methods are now considered to be method substitutions which allows for helper methods to be in the same class
Doug Simon <doug.simon@oracle.com>
parents: 7300
diff changeset
85 @MethodSubstitution
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
86 public static double tan(double x) {
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
87 if (abs(x) < PI_4) {
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
88 return MathIntrinsicNode.compute(x, Operation.TAN);
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
89 } else {
6521
2a0c9f20baa1 consolidated framework for runtime and stub calls and moved declaration of descriptors for such calls to the source file in which they are used
Doug Simon <doug.simon@oracle.com>
parents: 5579
diff changeset
90 return callDouble(ARITHMETIC_TAN, x);
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
91 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
92 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
93
9737
34c892fdfb6d moved responsibility for determining if a foreign call has a side effect to the runtime
Doug Simon <doug.simon@oracle.com>
parents: 9736
diff changeset
94 public static final ForeignCallDescriptor ARITHMETIC_SIN = new ForeignCallDescriptor("arithmeticSin", double.class, double.class);
34c892fdfb6d moved responsibility for determining if a foreign call has a side effect to the runtime
Doug Simon <doug.simon@oracle.com>
parents: 9736
diff changeset
95 public static final ForeignCallDescriptor ARITHMETIC_COS = new ForeignCallDescriptor("arithmeticCos", double.class, double.class);
34c892fdfb6d moved responsibility for determining if a foreign call has a side effect to the runtime
Doug Simon <doug.simon@oracle.com>
parents: 9736
diff changeset
96 public static final ForeignCallDescriptor ARITHMETIC_TAN = new ForeignCallDescriptor("arithmeticTan", double.class, double.class);
6521
2a0c9f20baa1 consolidated framework for runtime and stub calls and moved declaration of descriptors for such calls to the source file in which they are used
Doug Simon <doug.simon@oracle.com>
parents: 5579
diff changeset
97
2a0c9f20baa1 consolidated framework for runtime and stub calls and moved declaration of descriptors for such calls to the source file in which they are used
Doug Simon <doug.simon@oracle.com>
parents: 5579
diff changeset
98 @NodeIntrinsic(value = RuntimeCallNode.class, setStampFromReturnType = true)
9735
2e4f035186cf rename: Descriptor -> ForeignCallDescriptor
Doug Simon <doug.simon@oracle.com>
parents: 8481
diff changeset
99 public static double callDouble(@ConstantNodeParameter ForeignCallDescriptor descriptor, double value) {
8481
92571f3eeeeb made VM independent method substitutions be interpretable
Doug Simon <doug.simon@oracle.com>
parents: 8451
diff changeset
100 if (descriptor == ARITHMETIC_SIN) {
92571f3eeeeb made VM independent method substitutions be interpretable
Doug Simon <doug.simon@oracle.com>
parents: 8451
diff changeset
101 return Math.sin(value);
92571f3eeeeb made VM independent method substitutions be interpretable
Doug Simon <doug.simon@oracle.com>
parents: 8451
diff changeset
102 }
92571f3eeeeb made VM independent method substitutions be interpretable
Doug Simon <doug.simon@oracle.com>
parents: 8451
diff changeset
103 if (descriptor == ARITHMETIC_COS) {
92571f3eeeeb made VM independent method substitutions be interpretable
Doug Simon <doug.simon@oracle.com>
parents: 8451
diff changeset
104 return Math.cos(value);
92571f3eeeeb made VM independent method substitutions be interpretable
Doug Simon <doug.simon@oracle.com>
parents: 8451
diff changeset
105 }
92571f3eeeeb made VM independent method substitutions be interpretable
Doug Simon <doug.simon@oracle.com>
parents: 8451
diff changeset
106 assert descriptor == ARITHMETIC_TAN;
92571f3eeeeb made VM independent method substitutions be interpretable
Doug Simon <doug.simon@oracle.com>
parents: 8451
diff changeset
107 return Math.tan(value);
92571f3eeeeb made VM independent method substitutions be interpretable
Doug Simon <doug.simon@oracle.com>
parents: 8451
diff changeset
108 }
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
109 }