Mercurial > hg > truffle
annotate graal/com.oracle.graal.replacements.amd64/src/com/oracle/graal/replacements/amd64/AMD64ConvertSnippets.java @ 16520:9a07bf8467a6
[SPARC] Implement floatingpoint branch instructions, removing math substitutions for SPARC; fixing problems with constants in debug info (Big/Little Endian problems)
author | Stefan Anzinger <stefan.anzinger@gmail.com> |
---|---|
date | Sun, 13 Jul 2014 17:46:57 -0700 |
parents | 0993768dfc8e |
children | 06c15e88d383 |
rev | line source |
---|---|
8179
80a825206cbc
replaced AMD64Arithmetic.ConvertSlowPath with a snippet (GRAAL-140)
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
1 /* |
80a825206cbc
replaced AMD64Arithmetic.ConvertSlowPath with a snippet (GRAAL-140)
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
2 * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved. |
80a825206cbc
replaced AMD64Arithmetic.ConvertSlowPath with a snippet (GRAAL-140)
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
80a825206cbc
replaced AMD64Arithmetic.ConvertSlowPath with a snippet (GRAAL-140)
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
4 * |
80a825206cbc
replaced AMD64Arithmetic.ConvertSlowPath with a snippet (GRAAL-140)
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
5 * This code is free software; you can redistribute it and/or modify it |
80a825206cbc
replaced AMD64Arithmetic.ConvertSlowPath with a snippet (GRAAL-140)
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
6 * under the terms of the GNU General Public License version 2 only, as |
80a825206cbc
replaced AMD64Arithmetic.ConvertSlowPath with a snippet (GRAAL-140)
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
7 * published by the Free Software Foundation. |
80a825206cbc
replaced AMD64Arithmetic.ConvertSlowPath with a snippet (GRAAL-140)
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
8 * |
80a825206cbc
replaced AMD64Arithmetic.ConvertSlowPath with a snippet (GRAAL-140)
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
9 * This code is distributed in the hope that it will be useful, but WITHOUT |
80a825206cbc
replaced AMD64Arithmetic.ConvertSlowPath with a snippet (GRAAL-140)
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
80a825206cbc
replaced AMD64Arithmetic.ConvertSlowPath with a snippet (GRAAL-140)
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
80a825206cbc
replaced AMD64Arithmetic.ConvertSlowPath with a snippet (GRAAL-140)
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
12 * version 2 for more details (a copy is included in the LICENSE file that |
80a825206cbc
replaced AMD64Arithmetic.ConvertSlowPath with a snippet (GRAAL-140)
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
13 * accompanied this code). |
80a825206cbc
replaced AMD64Arithmetic.ConvertSlowPath with a snippet (GRAAL-140)
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
14 * |
80a825206cbc
replaced AMD64Arithmetic.ConvertSlowPath with a snippet (GRAAL-140)
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
15 * You should have received a copy of the GNU General Public License version |
80a825206cbc
replaced AMD64Arithmetic.ConvertSlowPath with a snippet (GRAAL-140)
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
16 * 2 along with this work; if not, write to the Free Software Foundation, |
80a825206cbc
replaced AMD64Arithmetic.ConvertSlowPath with a snippet (GRAAL-140)
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
80a825206cbc
replaced AMD64Arithmetic.ConvertSlowPath with a snippet (GRAAL-140)
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
18 * |
80a825206cbc
replaced AMD64Arithmetic.ConvertSlowPath with a snippet (GRAAL-140)
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
80a825206cbc
replaced AMD64Arithmetic.ConvertSlowPath with a snippet (GRAAL-140)
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
20 * or visit www.oracle.com if you need additional information or have any |
80a825206cbc
replaced AMD64Arithmetic.ConvertSlowPath with a snippet (GRAAL-140)
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
21 * questions. |
80a825206cbc
replaced AMD64Arithmetic.ConvertSlowPath with a snippet (GRAAL-140)
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
22 */ |
8415
2361bf148c06
rename packages: *snippets* -> *replacements*
Doug Simon <doug.simon@oracle.com>
parents:
8413
diff
changeset
|
23 package com.oracle.graal.replacements.amd64; |
8179
80a825206cbc
replaced AMD64Arithmetic.ConvertSlowPath with a snippet (GRAAL-140)
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
24 |
10787
388fbd0dd4a4
moved BranchNodeProbabilities to graal.nodes project
Doug Simon <doug.simon@oracle.com>
parents:
9602
diff
changeset
|
25 import static com.oracle.graal.nodes.extended.BranchProbabilityNode.*; |
8415
2361bf148c06
rename packages: *snippets* -> *replacements*
Doug Simon <doug.simon@oracle.com>
parents:
8413
diff
changeset
|
26 import static com.oracle.graal.replacements.SnippetTemplate.*; |
8179
80a825206cbc
replaced AMD64Arithmetic.ConvertSlowPath with a snippet (GRAAL-140)
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
27 |
80a825206cbc
replaced AMD64Arithmetic.ConvertSlowPath with a snippet (GRAAL-140)
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
28 import com.oracle.graal.api.code.*; |
15018
db4254246f9a
Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents:
14000
diff
changeset
|
29 import com.oracle.graal.api.replacements.*; |
8179
80a825206cbc
replaced AMD64Arithmetic.ConvertSlowPath with a snippet (GRAAL-140)
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
30 import com.oracle.graal.debug.*; |
80a825206cbc
replaced AMD64Arithmetic.ConvertSlowPath with a snippet (GRAAL-140)
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
31 import com.oracle.graal.nodes.*; |
80a825206cbc
replaced AMD64Arithmetic.ConvertSlowPath with a snippet (GRAAL-140)
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
32 import com.oracle.graal.nodes.calc.*; |
80a825206cbc
replaced AMD64Arithmetic.ConvertSlowPath with a snippet (GRAAL-140)
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
33 import com.oracle.graal.nodes.spi.*; |
12054
bba234a1670e
grouped provider values/parameters into a Providers object (GRAAL-511)
Doug Simon <doug.simon@oracle.com>
parents:
12052
diff
changeset
|
34 import com.oracle.graal.phases.util.*; |
8415
2361bf148c06
rename packages: *snippets* -> *replacements*
Doug Simon <doug.simon@oracle.com>
parents:
8413
diff
changeset
|
35 import com.oracle.graal.replacements.*; |
9015
92d2bedb5dfc
Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents:
8637
diff
changeset
|
36 import com.oracle.graal.replacements.SnippetTemplate.AbstractTemplates; |
92d2bedb5dfc
Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents:
8637
diff
changeset
|
37 import com.oracle.graal.replacements.SnippetTemplate.Arguments; |
92d2bedb5dfc
Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents:
8637
diff
changeset
|
38 import com.oracle.graal.replacements.SnippetTemplate.SnippetInfo; |
8179
80a825206cbc
replaced AMD64Arithmetic.ConvertSlowPath with a snippet (GRAAL-140)
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
39 |
80a825206cbc
replaced AMD64Arithmetic.ConvertSlowPath with a snippet (GRAAL-140)
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
40 /** |
80a825206cbc
replaced AMD64Arithmetic.ConvertSlowPath with a snippet (GRAAL-140)
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
41 * Snippets used for conversion operations on AMD64 where the AMD64 instruction used does not match |
80a825206cbc
replaced AMD64Arithmetic.ConvertSlowPath with a snippet (GRAAL-140)
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
42 * the semantics of the JVM specification. |
80a825206cbc
replaced AMD64Arithmetic.ConvertSlowPath with a snippet (GRAAL-140)
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
43 */ |
8413
d9347ee39fbe
rename: SnippetsInterface -> Snippets
Doug Simon <doug.simon@oracle.com>
parents:
8306
diff
changeset
|
44 public class AMD64ConvertSnippets implements Snippets { |
8179
80a825206cbc
replaced AMD64Arithmetic.ConvertSlowPath with a snippet (GRAAL-140)
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
45 |
80a825206cbc
replaced AMD64Arithmetic.ConvertSlowPath with a snippet (GRAAL-140)
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
46 /** |
80a825206cbc
replaced AMD64Arithmetic.ConvertSlowPath with a snippet (GRAAL-140)
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
47 * Converts a float to an int. |
80a825206cbc
replaced AMD64Arithmetic.ConvertSlowPath with a snippet (GRAAL-140)
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
48 * <p> |
80a825206cbc
replaced AMD64Arithmetic.ConvertSlowPath with a snippet (GRAAL-140)
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
49 * This snippet accounts for the semantics of the x64 CVTTSS2SI instruction used to do the |
80a825206cbc
replaced AMD64Arithmetic.ConvertSlowPath with a snippet (GRAAL-140)
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
50 * conversion. If the float value is a NaN, infinity or if the result of the conversion is |
80a825206cbc
replaced AMD64Arithmetic.ConvertSlowPath with a snippet (GRAAL-140)
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
51 * larger than {@link Integer#MAX_VALUE} then CVTTSS2SI returns {@link Integer#MIN_VALUE} and |
80a825206cbc
replaced AMD64Arithmetic.ConvertSlowPath with a snippet (GRAAL-140)
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
52 * extra tests are required on the float value to return the correct int value. |
15018
db4254246f9a
Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents:
14000
diff
changeset
|
53 * |
8179
80a825206cbc
replaced AMD64Arithmetic.ConvertSlowPath with a snippet (GRAAL-140)
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
54 * @param input the float being converted |
80a825206cbc
replaced AMD64Arithmetic.ConvertSlowPath with a snippet (GRAAL-140)
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
55 * @param result the result produced by the CVTTSS2SI instruction |
80a825206cbc
replaced AMD64Arithmetic.ConvertSlowPath with a snippet (GRAAL-140)
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
56 */ |
80a825206cbc
replaced AMD64Arithmetic.ConvertSlowPath with a snippet (GRAAL-140)
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
57 @Snippet |
9015
92d2bedb5dfc
Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents:
8637
diff
changeset
|
58 public static int f2i(float input, int result) { |
9316
5e1465ec46d6
Change the way branch probabilities are injected. Update all snippets.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
9015
diff
changeset
|
59 if (probability(SLOW_PATH_PROBABILITY, result == Integer.MIN_VALUE)) { |
8179
80a825206cbc
replaced AMD64Arithmetic.ConvertSlowPath with a snippet (GRAAL-140)
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
60 if (Float.isNaN(input)) { |
80a825206cbc
replaced AMD64Arithmetic.ConvertSlowPath with a snippet (GRAAL-140)
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
61 // input is NaN -> return 0 |
80a825206cbc
replaced AMD64Arithmetic.ConvertSlowPath with a snippet (GRAAL-140)
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
62 return 0; |
80a825206cbc
replaced AMD64Arithmetic.ConvertSlowPath with a snippet (GRAAL-140)
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
63 } else if (input > 0.0f) { |
80a825206cbc
replaced AMD64Arithmetic.ConvertSlowPath with a snippet (GRAAL-140)
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
64 // input is > 0 -> return max int |
80a825206cbc
replaced AMD64Arithmetic.ConvertSlowPath with a snippet (GRAAL-140)
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
65 return Integer.MAX_VALUE; |
80a825206cbc
replaced AMD64Arithmetic.ConvertSlowPath with a snippet (GRAAL-140)
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
66 } |
80a825206cbc
replaced AMD64Arithmetic.ConvertSlowPath with a snippet (GRAAL-140)
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
67 } |
80a825206cbc
replaced AMD64Arithmetic.ConvertSlowPath with a snippet (GRAAL-140)
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
68 return result; |
80a825206cbc
replaced AMD64Arithmetic.ConvertSlowPath with a snippet (GRAAL-140)
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
69 } |
80a825206cbc
replaced AMD64Arithmetic.ConvertSlowPath with a snippet (GRAAL-140)
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
70 |
80a825206cbc
replaced AMD64Arithmetic.ConvertSlowPath with a snippet (GRAAL-140)
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
71 /** |
80a825206cbc
replaced AMD64Arithmetic.ConvertSlowPath with a snippet (GRAAL-140)
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
72 * Converts a float to a long. |
80a825206cbc
replaced AMD64Arithmetic.ConvertSlowPath with a snippet (GRAAL-140)
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
73 * <p> |
80a825206cbc
replaced AMD64Arithmetic.ConvertSlowPath with a snippet (GRAAL-140)
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
74 * This snippet accounts for the semantics of the x64 CVTTSS2SI instruction used to do the |
80a825206cbc
replaced AMD64Arithmetic.ConvertSlowPath with a snippet (GRAAL-140)
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
75 * conversion. If the float value is a NaN or infinity then CVTTSS2SI returns |
80a825206cbc
replaced AMD64Arithmetic.ConvertSlowPath with a snippet (GRAAL-140)
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
76 * {@link Long#MIN_VALUE} and extra tests are required on the float value to return the correct |
80a825206cbc
replaced AMD64Arithmetic.ConvertSlowPath with a snippet (GRAAL-140)
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
77 * long value. |
15018
db4254246f9a
Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents:
14000
diff
changeset
|
78 * |
8179
80a825206cbc
replaced AMD64Arithmetic.ConvertSlowPath with a snippet (GRAAL-140)
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
79 * @param input the float being converted |
80a825206cbc
replaced AMD64Arithmetic.ConvertSlowPath with a snippet (GRAAL-140)
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
80 * @param result the result produced by the CVTTSS2SI instruction |
80a825206cbc
replaced AMD64Arithmetic.ConvertSlowPath with a snippet (GRAAL-140)
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
81 */ |
80a825206cbc
replaced AMD64Arithmetic.ConvertSlowPath with a snippet (GRAAL-140)
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
82 @Snippet |
9015
92d2bedb5dfc
Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents:
8637
diff
changeset
|
83 public static long f2l(float input, long result) { |
9316
5e1465ec46d6
Change the way branch probabilities are injected. Update all snippets.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
9015
diff
changeset
|
84 if (probability(SLOW_PATH_PROBABILITY, result == Long.MIN_VALUE)) { |
8179
80a825206cbc
replaced AMD64Arithmetic.ConvertSlowPath with a snippet (GRAAL-140)
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
85 if (Float.isNaN(input)) { |
80a825206cbc
replaced AMD64Arithmetic.ConvertSlowPath with a snippet (GRAAL-140)
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
86 // input is NaN -> return 0 |
80a825206cbc
replaced AMD64Arithmetic.ConvertSlowPath with a snippet (GRAAL-140)
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
87 return 0; |
80a825206cbc
replaced AMD64Arithmetic.ConvertSlowPath with a snippet (GRAAL-140)
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
88 } else if (input > 0.0f) { |
80a825206cbc
replaced AMD64Arithmetic.ConvertSlowPath with a snippet (GRAAL-140)
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
89 // input is > 0 -> return max int |
80a825206cbc
replaced AMD64Arithmetic.ConvertSlowPath with a snippet (GRAAL-140)
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
90 return Long.MAX_VALUE; |
80a825206cbc
replaced AMD64Arithmetic.ConvertSlowPath with a snippet (GRAAL-140)
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
91 } |
80a825206cbc
replaced AMD64Arithmetic.ConvertSlowPath with a snippet (GRAAL-140)
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
92 } |
80a825206cbc
replaced AMD64Arithmetic.ConvertSlowPath with a snippet (GRAAL-140)
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
93 return result; |
80a825206cbc
replaced AMD64Arithmetic.ConvertSlowPath with a snippet (GRAAL-140)
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
94 } |
80a825206cbc
replaced AMD64Arithmetic.ConvertSlowPath with a snippet (GRAAL-140)
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
95 |
80a825206cbc
replaced AMD64Arithmetic.ConvertSlowPath with a snippet (GRAAL-140)
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
96 /** |
80a825206cbc
replaced AMD64Arithmetic.ConvertSlowPath with a snippet (GRAAL-140)
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
97 * Converts a double to an int. |
80a825206cbc
replaced AMD64Arithmetic.ConvertSlowPath with a snippet (GRAAL-140)
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
98 * <p> |
80a825206cbc
replaced AMD64Arithmetic.ConvertSlowPath with a snippet (GRAAL-140)
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
99 * This snippet accounts for the semantics of the x64 CVTTSD2SI instruction used to do the |
80a825206cbc
replaced AMD64Arithmetic.ConvertSlowPath with a snippet (GRAAL-140)
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
100 * conversion. If the double value is a NaN, infinity or if the result of the conversion is |
80a825206cbc
replaced AMD64Arithmetic.ConvertSlowPath with a snippet (GRAAL-140)
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
101 * larger than {@link Integer#MAX_VALUE} then CVTTSD2SI returns {@link Integer#MIN_VALUE} and |
80a825206cbc
replaced AMD64Arithmetic.ConvertSlowPath with a snippet (GRAAL-140)
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
102 * extra tests are required on the double value to return the correct int value. |
15018
db4254246f9a
Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents:
14000
diff
changeset
|
103 * |
8179
80a825206cbc
replaced AMD64Arithmetic.ConvertSlowPath with a snippet (GRAAL-140)
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
104 * @param input the double being converted |
80a825206cbc
replaced AMD64Arithmetic.ConvertSlowPath with a snippet (GRAAL-140)
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
105 * @param result the result produced by the CVTTSS2SI instruction |
80a825206cbc
replaced AMD64Arithmetic.ConvertSlowPath with a snippet (GRAAL-140)
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
106 */ |
80a825206cbc
replaced AMD64Arithmetic.ConvertSlowPath with a snippet (GRAAL-140)
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
107 @Snippet |
9015
92d2bedb5dfc
Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents:
8637
diff
changeset
|
108 public static int d2i(double input, int result) { |
9316
5e1465ec46d6
Change the way branch probabilities are injected. Update all snippets.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
9015
diff
changeset
|
109 if (probability(SLOW_PATH_PROBABILITY, result == Integer.MIN_VALUE)) { |
8179
80a825206cbc
replaced AMD64Arithmetic.ConvertSlowPath with a snippet (GRAAL-140)
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
110 if (Double.isNaN(input)) { |
80a825206cbc
replaced AMD64Arithmetic.ConvertSlowPath with a snippet (GRAAL-140)
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
111 // input is NaN -> return 0 |
80a825206cbc
replaced AMD64Arithmetic.ConvertSlowPath with a snippet (GRAAL-140)
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
112 return 0; |
80a825206cbc
replaced AMD64Arithmetic.ConvertSlowPath with a snippet (GRAAL-140)
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
113 } else if (input > 0.0d) { |
80a825206cbc
replaced AMD64Arithmetic.ConvertSlowPath with a snippet (GRAAL-140)
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
114 // input is positive -> return maxInt |
80a825206cbc
replaced AMD64Arithmetic.ConvertSlowPath with a snippet (GRAAL-140)
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
115 return Integer.MAX_VALUE; |
80a825206cbc
replaced AMD64Arithmetic.ConvertSlowPath with a snippet (GRAAL-140)
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
116 } |
80a825206cbc
replaced AMD64Arithmetic.ConvertSlowPath with a snippet (GRAAL-140)
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
117 } |
80a825206cbc
replaced AMD64Arithmetic.ConvertSlowPath with a snippet (GRAAL-140)
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
118 return result; |
80a825206cbc
replaced AMD64Arithmetic.ConvertSlowPath with a snippet (GRAAL-140)
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
119 } |
80a825206cbc
replaced AMD64Arithmetic.ConvertSlowPath with a snippet (GRAAL-140)
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
120 |
80a825206cbc
replaced AMD64Arithmetic.ConvertSlowPath with a snippet (GRAAL-140)
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
121 /** |
80a825206cbc
replaced AMD64Arithmetic.ConvertSlowPath with a snippet (GRAAL-140)
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
122 * Converts a double to a long. |
80a825206cbc
replaced AMD64Arithmetic.ConvertSlowPath with a snippet (GRAAL-140)
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
123 * <p> |
80a825206cbc
replaced AMD64Arithmetic.ConvertSlowPath with a snippet (GRAAL-140)
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
124 * This snippet accounts for the semantics of the x64 CVTTSD2SI instruction used to do the |
80a825206cbc
replaced AMD64Arithmetic.ConvertSlowPath with a snippet (GRAAL-140)
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
125 * conversion. If the double value is a NaN, infinity or if the result of the conversion is |
80a825206cbc
replaced AMD64Arithmetic.ConvertSlowPath with a snippet (GRAAL-140)
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
126 * larger than {@link Long#MAX_VALUE} then CVTTSD2SI returns {@link Long#MIN_VALUE} and extra |
80a825206cbc
replaced AMD64Arithmetic.ConvertSlowPath with a snippet (GRAAL-140)
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
127 * tests are required on the double value to return the correct long value. |
15018
db4254246f9a
Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents:
14000
diff
changeset
|
128 * |
8179
80a825206cbc
replaced AMD64Arithmetic.ConvertSlowPath with a snippet (GRAAL-140)
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
129 * @param input the double being converted |
80a825206cbc
replaced AMD64Arithmetic.ConvertSlowPath with a snippet (GRAAL-140)
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
130 * @param result the result produced by the CVTTSS2SI instruction |
80a825206cbc
replaced AMD64Arithmetic.ConvertSlowPath with a snippet (GRAAL-140)
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
131 */ |
80a825206cbc
replaced AMD64Arithmetic.ConvertSlowPath with a snippet (GRAAL-140)
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
132 @Snippet |
9015
92d2bedb5dfc
Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents:
8637
diff
changeset
|
133 public static long d2l(double input, long result) { |
9316
5e1465ec46d6
Change the way branch probabilities are injected. Update all snippets.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
9015
diff
changeset
|
134 if (probability(SLOW_PATH_PROBABILITY, result == Long.MIN_VALUE)) { |
8179
80a825206cbc
replaced AMD64Arithmetic.ConvertSlowPath with a snippet (GRAAL-140)
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
135 if (Double.isNaN(input)) { |
80a825206cbc
replaced AMD64Arithmetic.ConvertSlowPath with a snippet (GRAAL-140)
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
136 // input is NaN -> return 0 |
80a825206cbc
replaced AMD64Arithmetic.ConvertSlowPath with a snippet (GRAAL-140)
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
137 return 0; |
80a825206cbc
replaced AMD64Arithmetic.ConvertSlowPath with a snippet (GRAAL-140)
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
138 } else if (input > 0.0d) { |
80a825206cbc
replaced AMD64Arithmetic.ConvertSlowPath with a snippet (GRAAL-140)
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
139 // input is positive -> return maxInt |
80a825206cbc
replaced AMD64Arithmetic.ConvertSlowPath with a snippet (GRAAL-140)
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
140 return Long.MAX_VALUE; |
80a825206cbc
replaced AMD64Arithmetic.ConvertSlowPath with a snippet (GRAAL-140)
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
141 } |
80a825206cbc
replaced AMD64Arithmetic.ConvertSlowPath with a snippet (GRAAL-140)
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
142 } |
80a825206cbc
replaced AMD64Arithmetic.ConvertSlowPath with a snippet (GRAAL-140)
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
143 return result; |
80a825206cbc
replaced AMD64Arithmetic.ConvertSlowPath with a snippet (GRAAL-140)
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
144 } |
80a825206cbc
replaced AMD64Arithmetic.ConvertSlowPath with a snippet (GRAAL-140)
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
145 |
9015
92d2bedb5dfc
Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents:
8637
diff
changeset
|
146 public static class Templates extends AbstractTemplates { |
8179
80a825206cbc
replaced AMD64Arithmetic.ConvertSlowPath with a snippet (GRAAL-140)
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
147 |
12656
9334392ed279
Refactor ConvertNode.
Roland Schatz <roland.schatz@oracle.com>
parents:
12625
diff
changeset
|
148 private final SnippetInfo f2i; |
9334392ed279
Refactor ConvertNode.
Roland Schatz <roland.schatz@oracle.com>
parents:
12625
diff
changeset
|
149 private final SnippetInfo f2l; |
9334392ed279
Refactor ConvertNode.
Roland Schatz <roland.schatz@oracle.com>
parents:
12625
diff
changeset
|
150 private final SnippetInfo d2i; |
9334392ed279
Refactor ConvertNode.
Roland Schatz <roland.schatz@oracle.com>
parents:
12625
diff
changeset
|
151 private final SnippetInfo d2l; |
8179
80a825206cbc
replaced AMD64Arithmetic.ConvertSlowPath with a snippet (GRAAL-140)
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
152 |
15018
db4254246f9a
Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents:
14000
diff
changeset
|
153 public Templates(Providers providers, SnippetReflectionProvider snippetReflection, TargetDescription target) { |
db4254246f9a
Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents:
14000
diff
changeset
|
154 super(providers, snippetReflection, target); |
9015
92d2bedb5dfc
Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents:
8637
diff
changeset
|
155 |
12656
9334392ed279
Refactor ConvertNode.
Roland Schatz <roland.schatz@oracle.com>
parents:
12625
diff
changeset
|
156 f2i = snippet(AMD64ConvertSnippets.class, "f2i"); |
9334392ed279
Refactor ConvertNode.
Roland Schatz <roland.schatz@oracle.com>
parents:
12625
diff
changeset
|
157 f2l = snippet(AMD64ConvertSnippets.class, "f2l"); |
9334392ed279
Refactor ConvertNode.
Roland Schatz <roland.schatz@oracle.com>
parents:
12625
diff
changeset
|
158 d2i = snippet(AMD64ConvertSnippets.class, "d2i"); |
9334392ed279
Refactor ConvertNode.
Roland Schatz <roland.schatz@oracle.com>
parents:
12625
diff
changeset
|
159 d2l = snippet(AMD64ConvertSnippets.class, "d2l"); |
8179
80a825206cbc
replaced AMD64Arithmetic.ConvertSlowPath with a snippet (GRAAL-140)
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
160 } |
80a825206cbc
replaced AMD64Arithmetic.ConvertSlowPath with a snippet (GRAAL-140)
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
161 |
14000
958c99d0790c
Split convert node into separate nodes for different conversions.
Roland Schatz <roland.schatz@oracle.com>
parents:
13505
diff
changeset
|
162 public void lower(FloatConvertNode convert, LoweringTool tool) { |
958c99d0790c
Split convert node into separate nodes for different conversions.
Roland Schatz <roland.schatz@oracle.com>
parents:
13505
diff
changeset
|
163 SnippetInfo key; |
958c99d0790c
Split convert node into separate nodes for different conversions.
Roland Schatz <roland.schatz@oracle.com>
parents:
13505
diff
changeset
|
164 switch (convert.getOp()) { |
958c99d0790c
Split convert node into separate nodes for different conversions.
Roland Schatz <roland.schatz@oracle.com>
parents:
13505
diff
changeset
|
165 case F2I: |
958c99d0790c
Split convert node into separate nodes for different conversions.
Roland Schatz <roland.schatz@oracle.com>
parents:
13505
diff
changeset
|
166 key = f2i; |
958c99d0790c
Split convert node into separate nodes for different conversions.
Roland Schatz <roland.schatz@oracle.com>
parents:
13505
diff
changeset
|
167 break; |
958c99d0790c
Split convert node into separate nodes for different conversions.
Roland Schatz <roland.schatz@oracle.com>
parents:
13505
diff
changeset
|
168 case F2L: |
958c99d0790c
Split convert node into separate nodes for different conversions.
Roland Schatz <roland.schatz@oracle.com>
parents:
13505
diff
changeset
|
169 key = f2l; |
12656
9334392ed279
Refactor ConvertNode.
Roland Schatz <roland.schatz@oracle.com>
parents:
12625
diff
changeset
|
170 break; |
14000
958c99d0790c
Split convert node into separate nodes for different conversions.
Roland Schatz <roland.schatz@oracle.com>
parents:
13505
diff
changeset
|
171 case D2I: |
958c99d0790c
Split convert node into separate nodes for different conversions.
Roland Schatz <roland.schatz@oracle.com>
parents:
13505
diff
changeset
|
172 key = d2i; |
12656
9334392ed279
Refactor ConvertNode.
Roland Schatz <roland.schatz@oracle.com>
parents:
12625
diff
changeset
|
173 break; |
14000
958c99d0790c
Split convert node into separate nodes for different conversions.
Roland Schatz <roland.schatz@oracle.com>
parents:
13505
diff
changeset
|
174 case D2L: |
958c99d0790c
Split convert node into separate nodes for different conversions.
Roland Schatz <roland.schatz@oracle.com>
parents:
13505
diff
changeset
|
175 key = d2l; |
958c99d0790c
Split convert node into separate nodes for different conversions.
Roland Schatz <roland.schatz@oracle.com>
parents:
13505
diff
changeset
|
176 break; |
958c99d0790c
Split convert node into separate nodes for different conversions.
Roland Schatz <roland.schatz@oracle.com>
parents:
13505
diff
changeset
|
177 default: |
958c99d0790c
Split convert node into separate nodes for different conversions.
Roland Schatz <roland.schatz@oracle.com>
parents:
13505
diff
changeset
|
178 return; |
8179
80a825206cbc
replaced AMD64Arithmetic.ConvertSlowPath with a snippet (GRAAL-140)
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
179 } |
80a825206cbc
replaced AMD64Arithmetic.ConvertSlowPath with a snippet (GRAAL-140)
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
180 |
9602
19c5a07c7843
Introduce a graph() method that returns a StructuredGraph, to make many explicit casts unnecessary
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9489
diff
changeset
|
181 StructuredGraph graph = convert.graph(); |
8179
80a825206cbc
replaced AMD64Arithmetic.ConvertSlowPath with a snippet (GRAAL-140)
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
182 |
13505
75a67ebd50e8
Introduce a LoweringStage so that lowerings can be conditional on one of the three times that lowering is performed by default
Christian Wimmer <christian.wimmer@oracle.com>
parents:
12656
diff
changeset
|
183 Arguments args = new Arguments(key, graph.getGuardsStage(), tool.getLoweringStage()); |
16156
0993768dfc8e
new UnaryNode base class
Lukas Stadler <lukas.stadler@oracle.com>
parents:
15018
diff
changeset
|
184 args.add("input", convert.getValue()); |
0993768dfc8e
new UnaryNode base class
Lukas Stadler <lukas.stadler@oracle.com>
parents:
15018
diff
changeset
|
185 args.add("result", graph.unique(new AMD64FloatConvertNode(convert.stamp(), convert.getOp(), convert.getValue()))); |
9015
92d2bedb5dfc
Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents:
8637
diff
changeset
|
186 |
92d2bedb5dfc
Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents:
8637
diff
changeset
|
187 SnippetTemplate template = template(args); |
14000
958c99d0790c
Split convert node into separate nodes for different conversions.
Roland Schatz <roland.schatz@oracle.com>
parents:
13505
diff
changeset
|
188 Debug.log("Lowering %s in %s: node=%s, template=%s, arguments=%s", convert.getOp(), graph, convert, template, args); |
12625
1f7bca29d15c
Simplify AMD64ConvertSnippets instantiation code.
Roland Schatz <roland.schatz@oracle.com>
parents:
12054
diff
changeset
|
189 template.instantiate(providers.getMetaAccess(), convert, DEFAULT_REPLACER, tool, args); |
11798
2fbb9fd55dde
made lowering recursive instead of iterative
Doug Simon <doug.simon@oracle.com>
parents:
11732
diff
changeset
|
190 graph.removeFloating(convert); |
8179
80a825206cbc
replaced AMD64Arithmetic.ConvertSlowPath with a snippet (GRAAL-140)
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
191 } |
80a825206cbc
replaced AMD64Arithmetic.ConvertSlowPath with a snippet (GRAAL-140)
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
192 } |
80a825206cbc
replaced AMD64Arithmetic.ConvertSlowPath with a snippet (GRAAL-140)
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
193 } |