Skip to content

Commit c135dfa

Browse files
committed
Add specialization for non-small int/long in ToSulongNode.
1 parent 8bae74e commit c135dfa

File tree

1 file changed

+55
-34
lines changed
  • graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/cext

1 file changed

+55
-34
lines changed

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/cext/CExtNodes.java

Lines changed: 55 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,6 @@
5959
import com.oracle.graal.python.builtins.modules.PythonCextBuiltins;
6060
import com.oracle.graal.python.builtins.objects.PNone;
6161
import com.oracle.graal.python.builtins.objects.PythonAbstractObject;
62-
import com.oracle.graal.python.builtins.objects.cext.DynamicObjectNativeWrapper.PrimitiveNativeWrapper;
63-
import com.oracle.graal.python.builtins.objects.cext.DynamicObjectNativeWrapper.PythonObjectNativeWrapper;
6462
import com.oracle.graal.python.builtins.objects.cext.CExtNodesFactory.AllToJavaNodeGen;
6563
import com.oracle.graal.python.builtins.objects.cext.CExtNodesFactory.AllToSulongNodeGen;
6664
import com.oracle.graal.python.builtins.objects.cext.CExtNodesFactory.AsPythonObjectNodeGen;
@@ -77,6 +75,8 @@
7775
import com.oracle.graal.python.builtins.objects.cext.CExtNodesFactory.TernaryFirstThirdToSulongNodeGen;
7876
import com.oracle.graal.python.builtins.objects.cext.CExtNodesFactory.TransformExceptionToNativeNodeGen;
7977
import com.oracle.graal.python.builtins.objects.cext.CExtNodesFactory.WrapVoidPtrNodeGen;
78+
import com.oracle.graal.python.builtins.objects.cext.DynamicObjectNativeWrapper.PrimitiveNativeWrapper;
79+
import com.oracle.graal.python.builtins.objects.cext.DynamicObjectNativeWrapper.PythonObjectNativeWrapper;
8080
import com.oracle.graal.python.builtins.objects.cext.capi.CApiContext;
8181
import com.oracle.graal.python.builtins.objects.cext.capi.NativeReferenceCache.ResolveNativeReferenceNode;
8282
import com.oracle.graal.python.builtins.objects.cext.capi.PyTruffleObjectFree.FreeNode;
@@ -351,17 +351,13 @@ static PrimitiveNativeWrapper doIntegerSmall(@SuppressWarnings("unused") CExtCon
351351
return PrimitiveNativeWrapper.createInt(i);
352352
}
353353

354-
/**
355-
* Generic integer conversion.<br/>
356-
* In the interpreter: we just lookup the cached primitive native wrapper and use this
357-
* instance. In compiled code, we do the same but create a fresh copy such that the compiler
358-
* always sees a fresh instance. This avoids a phi and certainly a real allocation. Note: it
359-
* is important to copy the existing cached wrapper because otherwise pointer equality is
360-
* not ensured (see also:
361-
* {@link AsPythonObjectBaseNode#mayUsePrimitive(IsPointerNode, PrimitiveNativeWrapper)}).
362-
*/
363-
@Specialization(replaces = "doIntegerSmall")
364-
static PrimitiveNativeWrapper doInteger(@SuppressWarnings("unused") CExtContext cextContext, int i,
354+
@Specialization(guards = "!isSmallInteger(i)", replaces = "doIntegerSmall")
355+
static PrimitiveNativeWrapper doInteger(@SuppressWarnings("unused") CExtContext cextContext, int i) {
356+
return PrimitiveNativeWrapper.createInt(i);
357+
}
358+
359+
@Specialization(replaces = {"doIntegerSmall", "doInteger"})
360+
static PrimitiveNativeWrapper doIntegerGeneric(@SuppressWarnings("unused") CExtContext cextContext, int i,
365361
@Shared("contextRef") @CachedContext(PythonLanguage.class) ContextReference<PythonContext> contextRef) {
366362
if (CApiGuards.isSmallInteger(i)) {
367363
return doIntegerSmall(cextContext, i, contextRef);
@@ -379,8 +375,13 @@ static PrimitiveNativeWrapper doLongSmall(@SuppressWarnings("unused") CExtContex
379375
return PrimitiveNativeWrapper.createLong(l);
380376
}
381377

382-
@Specialization(replaces = "doLongSmall")
383-
static PrimitiveNativeWrapper doLong(@SuppressWarnings("unused") CExtContext cextContext, long l,
378+
@Specialization(guards = "!isSmallLong(l)", replaces = "doLongSmall")
379+
static PrimitiveNativeWrapper doLong(@SuppressWarnings("unused") CExtContext cextContext, long l) {
380+
return PrimitiveNativeWrapper.createLong(l);
381+
}
382+
383+
@Specialization(replaces = {"doLongSmall", "doLong"})
384+
static PrimitiveNativeWrapper doLongGeneric(@SuppressWarnings("unused") CExtContext cextContext, long l,
384385
@Shared("contextRef") @CachedContext(PythonLanguage.class) ContextReference<PythonContext> contextRef) {
385386
if (CApiGuards.isSmallLong(l)) {
386387
return doLongSmall(cextContext, l, contextRef);
@@ -596,6 +597,20 @@ static PrimitiveNativeWrapper doIntegerSmall(@SuppressWarnings("unused") CExtCon
596597
return PrimitiveNativeWrapper.createInt(i);
597598
}
598599

600+
@Specialization(guards = "!isSmallInteger(i)", replaces = "doIntegerSmall")
601+
static PrimitiveNativeWrapper doInteger(@SuppressWarnings("unused") CExtContext cextContext, int i) {
602+
return PrimitiveNativeWrapper.createInt(i);
603+
}
604+
605+
@Specialization(replaces = {"doIntegerSmall", "doInteger"})
606+
static PrimitiveNativeWrapper doIntegerGeneric(CExtContext cextContext, int i,
607+
@Shared("contextRef") @CachedContext(PythonLanguage.class) ContextReference<PythonContext> contextRef) {
608+
if (CApiGuards.isSmallInteger(i)) {
609+
return doIntegerSmall(cextContext, i, contextRef);
610+
}
611+
return PrimitiveNativeWrapper.createInt(i);
612+
}
613+
599614
@Specialization(guards = "isSmallLong(l)")
600615
static PrimitiveNativeWrapper doLongSmall(@SuppressWarnings("unused") CExtContext cextContext, long l,
601616
@Shared("contextRef") @CachedContext(PythonLanguage.class) ContextReference<PythonContext> contextRef) {
@@ -608,17 +623,13 @@ static PrimitiveNativeWrapper doLongSmall(@SuppressWarnings("unused") CExtContex
608623
return PrimitiveNativeWrapper.createLong(l);
609624
}
610625

611-
@Specialization(replaces = "doIntegerSmall")
612-
static PrimitiveNativeWrapper doInteger(CExtContext cextContext, int i,
613-
@Shared("contextRef") @CachedContext(PythonLanguage.class) ContextReference<PythonContext> contextRef) {
614-
if (CApiGuards.isSmallInteger(i)) {
615-
return doIntegerSmall(cextContext, i, contextRef);
616-
}
617-
return PrimitiveNativeWrapper.createInt(i);
626+
@Specialization(guards = "!isSmallLong(l)", replaces = "doLongSmall")
627+
static PrimitiveNativeWrapper doLong(@SuppressWarnings("unused") CExtContext cextContext, long l) {
628+
return PrimitiveNativeWrapper.createLong(l);
618629
}
619630

620-
@Specialization(replaces = "doLongSmall")
621-
static PrimitiveNativeWrapper doLong(CExtContext cextContext, long l,
631+
@Specialization(replaces = {"doLongSmall", "doLong"})
632+
static PrimitiveNativeWrapper doLongGeneric(CExtContext cextContext, long l,
622633
@Shared("contextRef") @CachedContext(PythonLanguage.class) ContextReference<PythonContext> contextRef) {
623634
if (CApiGuards.isSmallLong(l)) {
624635
return doLongSmall(cextContext, l, contextRef);
@@ -788,34 +799,44 @@ static Object doString(CExtContext cextContext, String str,
788799
}
789800

790801
@Specialization
791-
static Object doBoolean(@SuppressWarnings("unused") CExtContext cextContext, boolean b,
802+
static Object doBoolean(CExtContext cextContext, boolean b,
792803
@Shared("contextRef") @CachedContext(PythonLanguage.class) ContextReference<PythonContext> contextRef,
793804
@Cached("createBinaryProfile()") ConditionProfile profile) {
794805
return ToNewRefNode.doBoolean(cextContext, b, contextRef, profile);
795806
}
796807

797808
@Specialization(guards = "isSmallInteger(i)")
798-
static PrimitiveNativeWrapper doIntegerSmall(@SuppressWarnings("unused") CExtContext cextContext, int i,
809+
static PrimitiveNativeWrapper doIntegerSmall(CExtContext cextContext, int i,
799810
@Shared("contextRef") @CachedContext(PythonLanguage.class) ContextReference<PythonContext> contextRef) {
800811
return ToNewRefNode.doIntegerSmall(cextContext, i, contextRef);
801812
}
802813

814+
@Specialization(guards = "!isSmallInteger(i)", replaces = "doIntegerSmall")
815+
static PrimitiveNativeWrapper doInteger(CExtContext cextContext, int i) {
816+
return ToNewRefNode.doInteger(cextContext, i);
817+
}
818+
819+
@Specialization(replaces = {"doIntegerSmall", "doInteger"})
820+
static PrimitiveNativeWrapper doIntegerGeneric(CExtContext cextContext, int i,
821+
@Shared("contextRef") @CachedContext(PythonLanguage.class) ContextReference<PythonContext> contextRef) {
822+
return ToNewRefNode.doIntegerGeneric(cextContext, i, contextRef);
823+
}
824+
803825
@Specialization(guards = "isSmallLong(l)")
804-
static PrimitiveNativeWrapper doLongSmall(@SuppressWarnings("unused") CExtContext cextContext, long l,
826+
static PrimitiveNativeWrapper doLongSmall(CExtContext cextContext, long l,
805827
@Shared("contextRef") @CachedContext(PythonLanguage.class) ContextReference<PythonContext> contextRef) {
806828
return ToNewRefNode.doLongSmall(cextContext, l, contextRef);
807829
}
808830

809-
@Specialization(replaces = "doIntegerSmall")
810-
static PrimitiveNativeWrapper doInteger(CExtContext cextContext, int i,
811-
@Shared("contextRef") @CachedContext(PythonLanguage.class) ContextReference<PythonContext> contextRef) {
812-
return ToNewRefNode.doInteger(cextContext, i, contextRef);
831+
@Specialization(guards = "!isSmallLong(l)", replaces = "doLongSmall")
832+
static PrimitiveNativeWrapper doLong(@SuppressWarnings("unused") CExtContext cextContext, long l) {
833+
return ToNewRefNode.doLong(cextContext, l);
813834
}
814835

815-
@Specialization(replaces = "doLongSmall")
816-
static PrimitiveNativeWrapper doLong(CExtContext cextContext, long l,
836+
@Specialization(replaces = {"doLongSmall", "doLong"})
837+
static PrimitiveNativeWrapper doLongGeneric(CExtContext cextContext, long l,
817838
@Shared("contextRef") @CachedContext(PythonLanguage.class) ContextReference<PythonContext> contextRef) {
818-
return ToNewRefNode.doLong(cextContext, l, contextRef);
839+
return ToNewRefNode.doLongGeneric(cextContext, l, contextRef);
819840
}
820841

821842
@Specialization(guards = "!isNaN(d)")

0 commit comments

Comments
 (0)