Skip to content

Commit a80b390

Browse files
committed
Add fast-paths to PyLongFromDoubleNode
1 parent f563b33 commit a80b390

File tree

1 file changed

+17
-17
lines changed

1 file changed

+17
-17
lines changed

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyLongFromDoubleNode.java

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -47,47 +47,47 @@
4747
import java.math.BigInteger;
4848
import java.math.MathContext;
4949

50-
import com.oracle.graal.python.builtins.objects.ints.PInt;
50+
import com.oracle.graal.python.builtins.modules.MathGuards;
5151
import com.oracle.graal.python.nodes.ErrorMessages;
5252
import com.oracle.graal.python.nodes.PRaiseNode;
5353
import com.oracle.graal.python.runtime.object.PythonObjectFactory;
5454
import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary;
5555
import com.oracle.truffle.api.dsl.Cached;
56-
import com.oracle.truffle.api.dsl.Fallback;
5756
import com.oracle.truffle.api.dsl.GenerateCached;
5857
import com.oracle.truffle.api.dsl.GenerateInline;
5958
import com.oracle.truffle.api.dsl.GenerateUncached;
59+
import com.oracle.truffle.api.dsl.ImportStatic;
6060
import com.oracle.truffle.api.dsl.Specialization;
6161
import com.oracle.truffle.api.nodes.Node;
62-
import com.oracle.truffle.api.profiles.InlinedConditionProfile;
6362

6463
@GenerateUncached
6564
@GenerateInline
6665
@GenerateCached(false)
66+
@ImportStatic(MathGuards.class)
6767
public abstract class PyLongFromDoubleNode extends Node {
6868
public abstract Object execute(Node inliningTarget, double value);
6969

7070
public static Object executeUncached(double value) {
7171
return PyLongFromDoubleNodeGen.getUncached().execute(null, value);
7272
}
7373

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,
7886
@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));
8888
}
8989

90-
@Fallback
90+
@Specialization(guards = "!isFinite(value)")
9191
static Object doInfinite(double value,
9292
@Cached PRaiseNode raiseNode) {
9393
if (Double.isNaN(value)) {

0 commit comments

Comments
 (0)