Author: fijal
Branch: 
Changeset: r82456:3c94bed8d07e
Date: 2016-02-23 18:20 +0100
http://bitbucket.org/pypy/pypy/changeset/3c94bed8d07e/

Log:    look inside tuple hash, improves mdp

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
@@ -30,6 +30,11 @@
 contains_jmp = jit.JitDriver(greens = ['tp'], reds = 'auto',
                              name = 'tuple.contains')
 
+hash_driver = jit.JitDriver(
+    name='tuple.hash',
+    greens=['w_type'],
+    reds='auto')
+
 class W_AbstractTupleObject(W_Root):
     __slots__ = ()
 
@@ -262,8 +267,14 @@
     def length(self):
         return len(self.wrappeditems)
 
-    @jit.look_inside_iff(lambda self, _1: _unroll_condition(self))
     def descr_hash(self, space):
+        if _unroll_condition(self):
+            return self._descr_hash_unroll(space)
+        else:
+            return self._descr_hash_jitdriver(space)
+
+    @jit.unroll_safe
+    def _descr_hash_unroll(self, space):
         mult = 1000003
         x = 0x345678
         z = len(self.wrappeditems)
@@ -275,6 +286,20 @@
         x += 97531
         return space.wrap(intmask(x))
 
+    def _descr_hash_jitdriver(self, space):
+        mult = 1000003
+        x = 0x345678
+        z = len(self.wrappeditems)
+        w_type = space.type(self.wrappeditems[0])
+        for w_item in self.wrappeditems:
+            hash_driver.jit_merge_point(w_type=w_type)
+            y = space.hash_w(w_item)
+            x = (x ^ y) * mult
+            z -= 1
+            mult += 82520 + z + z
+        x += 97531
+        return space.wrap(intmask(x))
+
     def descr_eq(self, space, w_other):
         if not isinstance(w_other, W_AbstractTupleObject):
             return space.w_NotImplemented
diff --git a/rpython/rlib/jit.py b/rpython/rlib/jit.py
--- a/rpython/rlib/jit.py
+++ b/rpython/rlib/jit.py
@@ -284,7 +284,7 @@
 def loop_unrolling_heuristic(lst, size, cutoff=2):
     """ In which cases iterating over items of lst can be unrolled
     """
-    return isvirtual(lst) or (isconstant(size) and size <= cutoff)
+    return size == 0 or isvirtual(lst) or (isconstant(size) and size <= cutoff)
 
 class Entry(ExtRegistryEntry):
     _about_ = hint
_______________________________________________
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to