Commits

Brian Kearns committed 1f7ca87

use jit.loop_unrolling_heuristic where possible

  • Participants
  • Parent commits 38a8292

Comments (0)

Files changed (7)

File pypy/module/__builtin__/functional.py

 
 @specialize.arg(2)
 def min_max(space, args, implementation_of):
-    if not jit.we_are_jitted() or (jit.isconstant(len(args.arguments_w)) and
-            len(args.arguments_w) == 2):
+    if not jit.we_are_jitted() or jit.loop_unrolling_heuristic(
+            args.arguments_w, len(args.arguments_w)):
         return min_max_unroll(space, args, implementation_of)
     else:
         return min_max_normal(space, args, implementation_of)

File pypy/objspace/std/dictmultiobject.py

 from rpython.rlib.debug import mark_dict_non_null
 from rpython.tool.sourcetools import func_with_new_name
 
-from rpython.rlib import rerased
-from rpython.rlib import jit
+from rpython.rlib import rerased, jit
 
 def _is_str(space, w_key):
     return space.is_w(space.type(w_key), space.w_str)
             space.is_w(w_lookup_type, space.w_float)
             )
 
-
-DICT_CUTOFF = 5
-
 @specialize.call_location()
 def w_dict_unrolling_heuristic(w_dct):
     """ In which cases iterating over dict items can be unrolled.
     an actual dict
     """
     return jit.isvirtual(w_dct) or (jit.isconstant(w_dct) and
-                                    w_dct.length() <= DICT_CUTOFF)
+                                    w_dct.length() <= jit.UNROLL_CUTOFF)
+
 
 class W_DictMultiObject(W_Object):
     from pypy.objspace.std.dicttype import dict_typedef as typedef
             update1_keys(space, w_dict, w_data)
 
 
-@jit.look_inside_iff(lambda space, w_dict, w_data: w_dict_unrolling_heuristic(w_data))
+@jit.look_inside_iff(lambda space, w_dict, w_data:
+                     w_dict_unrolling_heuristic(w_data))
 def update1_dict_dict(space, w_dict, w_data):
     iterator = w_data.iteritems()
     while 1:

File pypy/objspace/std/intobject.py

 
 
 # helper for pow()
-@jit.look_inside_iff(lambda space, iv, iw, iz: jit.isconstant(iw) and jit.isconstant(iz))
+@jit.look_inside_iff(lambda space, iv, iw, iz:
+                     jit.isconstant(iw) and jit.isconstant(iz))
 def _impl_int_int_pow(space, iv, iw, iz):
     if iw < 0:
         if iz != 0:

File pypy/objspace/std/kwargsdict.py

     def getitem_str(self, w_dict, key):
         return self._getitem_str_indirection(w_dict, key)
 
-    @jit.look_inside_iff(lambda self, w_dict, key: jit.isconstant(self.length(w_dict)) and jit.isconstant(key))
+    @jit.look_inside_iff(lambda self, w_dict, key:
+            jit.isconstant(self.length(w_dict)) and jit.isconstant(key))
     def _getitem_str_indirection(self, w_dict, key):
         keys, values_w = self.unerase(w_dict.dstorage)
         result = []

File pypy/objspace/std/listobject.py

 from pypy.objspace.std.stdtypedef import StdTypeDef, SMM
 from sys import maxint
 
-UNROLL_CUTOFF = 5
 
 class W_AbstractListObject(W_Object):
     __slots__ = ()
     return W_ListObject.from_storage_and_strategy(space, storage, strategy)
 
 @jit.look_inside_iff(lambda space, list_w, sizehint:
-                         jit.isconstant(len(list_w)) and len(list_w) < UNROLL_CUTOFF)
+                     jit.loop_unrolling_heuristic(list_w, len(list_w)))
 def get_strategy_from_list_objects(space, list_w, sizehint):
     if not list_w:
         if sizehint != -1:
         raise NotImplementedError("abstract base class")
 
     @jit.look_inside_iff(lambda space, w_list, list_w:
-        jit.isconstant(len(list_w)) and len(list_w) < UNROLL_CUTOFF)
+                         jit.loop_unrolling_heuristic(list_w, len(list_w)))
     def init_from_list_w(self, w_list, list_w):
         l = [self.unwrap(w_item) for w_item in list_w]
         w_list.lstorage = self.erase(l)
         return self.wrap(r)
 
     @jit.look_inside_iff(lambda self, w_list:
-           jit.isconstant(w_list.length()) and w_list.length() < UNROLL_CUTOFF)
+                         jit.loop_unrolling_heuristic(w_list, w_list.length()))
     def getitems_copy(self, w_list):
         return [self.wrap(item) for item in self.unerase(w_list.lstorage)]
 
         return [self.wrap(item) for item in self.unerase(w_list.lstorage)]
 
     @jit.look_inside_iff(lambda self, w_list:
-           jit.isconstant(w_list.length()) and w_list.length() < UNROLL_CUTOFF)
+                         jit.loop_unrolling_heuristic(w_list, w_list.length()))
     def getitems_fixedsize(self, w_list):
         return self.getitems_unroll(w_list)
 

File pypy/objspace/std/tupleobject.py

 from rpython.rlib import jit
 from rpython.tool.sourcetools import func_with_new_name
 
-# Tuples of known length up to UNROLL_TUPLE_LIMIT have unrolled certain methods
-UNROLL_TUPLE_LIMIT = 10
 
 class W_AbstractTupleObject(W_Object):
     __slots__ = ()
     start, stop = normalize_simple_slice(space, length, w_start, w_stop)
     return space.newtuple(w_tuple.wrappeditems[start:stop])
 
-THRESHOLD = 7
-
-def unroll_tuple_contains(space, w_tuple, w_obj):
-    if (jit.isconstant(w_tuple) or jit.isvirtual(w_tuple) and
-        len(w_tuple.wrappeditems) < THRESHOLD):
-        return True
-    return False
-
-@jit.look_inside_iff(unroll_tuple_contains)
+@jit.look_inside_iff(lambda space, w_tuple, w_obj:
+        jit.loop_unrolling_heuristic(w_tuple, len(w_tuple.wrappeditems)))
 def contains__Tuple_ANY(space, w_tuple, w_obj):
     for w_item in w_tuple.wrappeditems:
         if space.eq_w(w_item, w_obj):
     return mul_tuple_times(space, w_tuple, w_times)
 
 def tuple_unroll_condition(space, w_tuple1, w_tuple2):
-    lgt1 = len(w_tuple1.wrappeditems)
-    lgt2 = len(w_tuple2.wrappeditems)
-    return ((jit.isconstant(lgt1) and lgt1 <= UNROLL_TUPLE_LIMIT) or
-            (jit.isconstant(lgt2) and lgt2 <= UNROLL_TUPLE_LIMIT))
+    return jit.loop_unrolling_heuristic(w_tuple1, len(w_tuple1.wrappeditems)) or \
+           jit.loop_unrolling_heuristic(w_tuple2, len(w_tuple2.wrappeditems))
 
 @jit.look_inside_iff(tuple_unroll_condition)
 def eq__Tuple_Tuple(space, w_tuple1, w_tuple2):
 def _make_tuple_comparison(name):
     import operator
     op = getattr(operator, name)
-    #
+
     @jit.look_inside_iff(tuple_unroll_condition)
     def compare_tuples(space, w_tuple1, w_tuple2):
         items1 = w_tuple1.wrappeditems
     return space.wrap(hash_tuple(space, w_tuple.wrappeditems))
 
 @jit.look_inside_iff(lambda space, wrappeditems:
-                     jit.isconstant(len(wrappeditems)) and
-                     len(wrappeditems) < UNROLL_TUPLE_LIMIT)
+        jit.loop_unrolling_heuristic(wrappeditems, len(wrappeditems)))
 def hash_tuple(space, wrappeditems):
     # this is the CPython 2.4 algorithm (changed from 2.3)
     mult = 1000003

File rpython/rlib/jit.py

     return NonConstant(False)
 isvirtual._annspecialcase_ = "specialize:call_location"
 
-LIST_CUTOFF = 2
+UNROLL_CUTOFF = 5
 
 @specialize.call_location()
 def loop_unrolling_heuristic(lst, size):
     """ In which cases iterating over items of lst can be unrolled
     """
-    return isvirtual(lst) or (isconstant(size) and size <= LIST_CUTOFF)
+    return isvirtual(lst) or (isconstant(size) and size <= UNROLL_CUTOFF)
 
 class Entry(ExtRegistryEntry):
     _about_ = hint