[pypy-commit] pypy default: (arigo, agaynor, fijal) a bit more precise unrolling condition

fijal noreply at buildbot.pypy.org
Mon Mar 12 21:58:25 CET 2012


Author: Maciej Fijalkowski <fijall at gmail.com>
Branch: 
Changeset: r53344:a19a489bca12
Date: 2012-03-12 13:58 -0700
http://bitbucket.org/pypy/pypy/changeset/a19a489bca12/

Log:	(arigo, agaynor, fijal) a bit more precise unrolling condition

diff --git a/pypy/objspace/std/tupleobject.py b/pypy/objspace/std/tupleobject.py
--- a/pypy/objspace/std/tupleobject.py
+++ b/pypy/objspace/std/tupleobject.py
@@ -9,6 +9,9 @@
 from pypy.rlib.debug import make_sure_not_resized
 from pypy.rlib import jit
 
+# Tuples of known length up to UNROLL_TUPLE_LIMIT have unrolled certain methods
+UNROLL_TUPLE_LIMIT = 10
+
 class W_AbstractTupleObject(W_Object):
     __slots__ = ()
 
@@ -114,24 +117,28 @@
 def mul__ANY_Tuple(space, w_times, w_tuple):
     return mul_tuple_times(space, w_tuple, w_times)
 
- at jit.look_inside_iff(lambda space, w_tuple1, w_tuple2:
-                     jit.is_constant(len(w_tuple1.wrappeditems)) and
-                     jit.is_constant(len(w_tuple2.wrappeditems)))
+def tuple_unroll_condition(space, w_tuple1, w_tuple2):
+    lgt1 = len(w_tuple1.wrappeditems)
+    lgt2 = len(w_tuple2.wrappeditems)
+    return ((jit.is_constant(lgt1) and lgt1 <= UNROLL_TUPLE_LIMIT) or
+            (jit.is_constant(lgt2) and lgt2 <= UNROLL_TUPLE_LIMIT))
+
+ at jit.look_inside_iff(tuple_unroll_condition)
 def eq__Tuple_Tuple(space, w_tuple1, w_tuple2):
     items1 = w_tuple1.wrappeditems
     items2 = w_tuple2.wrappeditems
-    if len(items1) != len(items2):
+    lgt1 = len(items1)
+    lgt2 = len(items2)
+    if lgt1 != lgt2:
         return space.w_False
-    for i in range(len(items1)):
+    for i in range(lgt1):
         item1 = items1[i]
         item2 = items2[i]
         if not space.eq_w(item1, item2):
             return space.w_False
     return space.w_True
 
- at jit.look_inside_iff(lambda space, w_tuple1, w_tuple2:
-                     jit.is_constant(len(w_tuple1.wrappeditems)) and
-                     jit.is_constant(len(w_tuple2.wrappeditems)))
+ at jit.look_inside_iff(tuple_unroll_condition)
 def lt__Tuple_Tuple(space, w_tuple1, w_tuple2):
     items1 = w_tuple1.wrappeditems
     items2 = w_tuple2.wrappeditems
@@ -143,9 +150,7 @@
     # No more items to compare -- compare sizes
     return space.newbool(len(items1) < len(items2))
 
- at jit.look_inside_iff(lambda space, w_tuple1, w_tuple2:
-                     jit.is_constant(len(w_tuple1.wrappeditems)) and
-                     jit.is_constant(len(w_tuple2.wrappeditems)))
+ at jit.look_inside_iff(tuple_unroll_condition)
 def gt__Tuple_Tuple(space, w_tuple1, w_tuple2):
     items1 = w_tuple1.wrappeditems
     items2 = w_tuple2.wrappeditems
@@ -171,7 +176,8 @@
     return space.wrap(hash_tuple(space, w_tuple.wrappeditems))
 
 @jit.look_inside_iff(lambda space, wrappeditems:
-                     jit.is_constant(len(wrappeditems)))
+                     jit.is_constant(len(wrappeditems)) and
+                     len(wrappeditems) < UNROLL_TUPLE_LIMIT)
 def hash_tuple(space, wrappeditems):
     # this is the CPython 2.4 algorithm (changed from 2.3)
     mult = 1000003


More information about the pypy-commit mailing list