|
47 | 47 | import java.math.BigInteger;
|
48 | 48 | import java.math.MathContext;
|
49 | 49 |
|
50 |
| -import com.oracle.graal.python.builtins.objects.ints.PInt; |
| 50 | +import com.oracle.graal.python.builtins.modules.MathGuards; |
51 | 51 | import com.oracle.graal.python.nodes.ErrorMessages;
|
52 | 52 | import com.oracle.graal.python.nodes.PRaiseNode;
|
53 | 53 | import com.oracle.graal.python.runtime.object.PythonObjectFactory;
|
54 | 54 | import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary;
|
55 | 55 | import com.oracle.truffle.api.dsl.Cached;
|
56 |
| -import com.oracle.truffle.api.dsl.Fallback; |
57 | 56 | import com.oracle.truffle.api.dsl.GenerateCached;
|
58 | 57 | import com.oracle.truffle.api.dsl.GenerateInline;
|
59 | 58 | import com.oracle.truffle.api.dsl.GenerateUncached;
|
| 59 | +import com.oracle.truffle.api.dsl.ImportStatic; |
60 | 60 | import com.oracle.truffle.api.dsl.Specialization;
|
61 | 61 | import com.oracle.truffle.api.nodes.Node;
|
62 |
| -import com.oracle.truffle.api.profiles.InlinedConditionProfile; |
63 | 62 |
|
64 | 63 | @GenerateUncached
|
65 | 64 | @GenerateInline
|
66 | 65 | @GenerateCached(false)
|
| 66 | +@ImportStatic(MathGuards.class) |
67 | 67 | public abstract class PyLongFromDoubleNode extends Node {
|
68 | 68 | public abstract Object execute(Node inliningTarget, double value);
|
69 | 69 |
|
70 | 70 | public static Object executeUncached(double value) {
|
71 | 71 | return PyLongFromDoubleNodeGen.getUncached().execute(null, value);
|
72 | 72 | }
|
73 | 73 |
|
74 |
| - @Specialization(guards = "isFinite(value)") |
75 |
| - static Object doFinite(Node inliningTarget, double value, |
76 |
| - @Cached InlinedConditionProfile fitsInLong, |
77 |
| - @Cached InlinedConditionProfile fitsInInt, |
| 74 | + @Specialization(guards = "fitInt(value)") |
| 75 | + static int doInt(double value) { |
| 76 | + return (int) value; |
| 77 | + } |
| 78 | + |
| 79 | + @Specialization(guards = "fitLong(value)") |
| 80 | + static long doLong(double value) { |
| 81 | + return (long) value; |
| 82 | + } |
| 83 | + |
| 84 | + @Specialization(guards = {"!fitLong(value)", "isFinite(value)"}) |
| 85 | + static Object doFinite(double value, |
78 | 86 | @Cached PythonObjectFactory factory) {
|
79 |
| - BigInteger bigInteger = toBigInteger(value); |
80 |
| - if (fitsInLong.profile(inliningTarget, PInt.bigIntegerFitsInLong(bigInteger))) { |
81 |
| - long longValue = PInt.longValue(bigInteger); |
82 |
| - if (fitsInInt.profile(inliningTarget, PInt.isIntRange(longValue))) { |
83 |
| - return (int) longValue; |
84 |
| - } |
85 |
| - return longValue; |
86 |
| - } |
87 |
| - return factory.createInt(bigInteger); |
| 87 | + return factory.createInt(toBigInteger(value)); |
88 | 88 | }
|
89 | 89 |
|
90 |
| - @Fallback |
| 90 | + @Specialization(guards = "!isFinite(value)") |
91 | 91 | static Object doInfinite(double value,
|
92 | 92 | @Cached PRaiseNode raiseNode) {
|
93 | 93 | if (Double.isNaN(value)) {
|
|
0 commit comments