Skip to content

Commit 329bbf6

Browse files
committed
Avoid calls to 'truffle_ptr_comper' for EQ/NE.
1 parent 6697a90 commit 329bbf6

File tree

1 file changed

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

1 file changed

+22
-8
lines changed

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

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1438,8 +1438,22 @@ private static boolean executeCFunction(int op, Object a, Object b, InteropLibra
14381438
}
14391439
}
14401440

1441+
@Specialization(guards = "isEq(opName)", limit = "2")
1442+
static boolean doEq(@SuppressWarnings("unused") String opName, PythonAbstractNativeObject a, PythonAbstractNativeObject b,
1443+
@CachedLibrary("a.getPtr()") InteropLibrary aLib,
1444+
@CachedLibrary(limit = "3") InteropLibrary bLib) {
1445+
return aLib.isIdentical(a.getPtr(), b.getPtr(), bLib);
1446+
}
1447+
1448+
@Specialization(guards = "isNe(opName)", limit = "2")
1449+
static boolean doNe(@SuppressWarnings("unused") String opName, PythonAbstractNativeObject a, PythonAbstractNativeObject b,
1450+
@CachedLibrary("a.getPtr()") InteropLibrary aLib,
1451+
@CachedLibrary(limit = "3") InteropLibrary bLib) {
1452+
return !aLib.isIdentical(a.getPtr(), b.getPtr(), bLib);
1453+
}
1454+
14411455
@Specialization(guards = "cachedOpName.equals(opName)", limit = "1")
1442-
public boolean execute(@SuppressWarnings("unused") String opName, PythonNativeObject a, PythonNativeObject b,
1456+
static boolean execute(@SuppressWarnings("unused") String opName, PythonNativeObject a, PythonNativeObject b,
14431457
@Shared("cachedOpName") @Cached("opName") @SuppressWarnings("unused") String cachedOpName,
14441458
@Shared("op") @Cached(value = "findOp(opName)", allowUncached = true) int op,
14451459
@CachedLibrary(limit = "1") InteropLibrary interopLibrary,
@@ -1448,7 +1462,7 @@ public boolean execute(@SuppressWarnings("unused") String opName, PythonNativeOb
14481462
}
14491463

14501464
@Specialization(guards = "cachedOpName.equals(opName)", limit = "1")
1451-
public boolean execute(@SuppressWarnings("unused") String opName, PythonNativeObject a, long b,
1465+
static boolean execute(@SuppressWarnings("unused") String opName, PythonNativeObject a, long b,
14521466
@Shared("cachedOpName") @Cached("opName") @SuppressWarnings("unused") String cachedOpName,
14531467
@Shared("op") @Cached(value = "findOp(opName)", allowUncached = true) int op,
14541468
@CachedLibrary(limit = "1") InteropLibrary interopLibrary,
@@ -1457,15 +1471,15 @@ public boolean execute(@SuppressWarnings("unused") String opName, PythonNativeOb
14571471
}
14581472

14591473
@Specialization(guards = "cachedOpName.equals(opName)", limit = "1")
1460-
public boolean execute(@SuppressWarnings("unused") String opName, PythonNativeVoidPtr a, long b,
1474+
static boolean execute(@SuppressWarnings("unused") String opName, PythonNativeVoidPtr a, long b,
14611475
@Shared("cachedOpName") @Cached("opName") @SuppressWarnings("unused") String cachedOpName,
14621476
@Shared("op") @Cached(value = "findOp(opName)", allowUncached = true) int op,
14631477
@CachedLibrary(limit = "1") InteropLibrary interopLibrary,
14641478
@Shared("importCAPISymbolNode") @Cached ImportCAPISymbolNode importCAPISymbolNode) {
14651479
return executeCFunction(op, a.getPointerObject(), b, interopLibrary, importCAPISymbolNode);
14661480
}
14671481

1468-
public static int findOp(String specialMethodName) {
1482+
static int findOp(String specialMethodName) {
14691483
for (int i = 0; i < SpecialMethodNames.COMPARE_OP_COUNT; i++) {
14701484
if (SpecialMethodNames.getCompareName(i).equals(specialMethodName)) {
14711485
return i;
@@ -1474,12 +1488,12 @@ public static int findOp(String specialMethodName) {
14741488
throw new RuntimeException("The special method used for Python C API pointer comparison must be a constant literal (i.e., interned) string");
14751489
}
14761490

1477-
public static PointerCompareNode create() {
1478-
return PointerCompareNodeGen.create();
1491+
static boolean isEq(String opName) {
1492+
return SpecialMethodNames.__EQ__.equals(opName);
14791493
}
14801494

1481-
public static PointerCompareNode getUncached() {
1482-
return PointerCompareNodeGen.getUncached();
1495+
static boolean isNe(String opName) {
1496+
return SpecialMethodNames.__NE__.equals(opName);
14831497
}
14841498
}
14851499

0 commit comments

Comments
 (0)