[pypy-commit] pypy default: (fijal, arigo) heuristic for unrolling loops, unroll a bit more
fijal
noreply at buildbot.pypy.org
Sat Apr 14 18:38:19 CEST 2012
Author: Maciej Fijalkowski <fijall at gmail.com>
Branch:
Changeset: r54366:c85c18524c4f
Date: 2012-04-14 18:37 +0200
http://bitbucket.org/pypy/pypy/changeset/c85c18524c4f/
Log: (fijal, arigo) heuristic for unrolling loops, unroll a bit more
diff --git a/pypy/objspace/std/stringobject.py b/pypy/objspace/std/stringobject.py
--- a/pypy/objspace/std/stringobject.py
+++ b/pypy/objspace/std/stringobject.py
@@ -14,6 +14,7 @@
from pypy.objspace.std.tupleobject import W_TupleObject
from pypy.rlib.rstring import StringBuilder, split
from pypy.interpreter.buffer import StringBuffer
+from pypy.rlib import jit
from pypy.objspace.std.stringtype import sliced, wrapstr, wrapchar, \
stringendswith, stringstartswith, joined2
@@ -398,6 +399,8 @@
return _str_join_many_items(space, w_self, list_w, size)
+ at jit.look_inside_iff(lambda space, w_self, list_w, size:
+ jit.loop_unrolling_heuristic(list_w, size))
def _str_join_many_items(space, w_self, list_w, size):
self = w_self._value
reslen = len(self) * (size - 1)
diff --git a/pypy/objspace/std/unicodeobject.py b/pypy/objspace/std/unicodeobject.py
--- a/pypy/objspace/std/unicodeobject.py
+++ b/pypy/objspace/std/unicodeobject.py
@@ -16,6 +16,7 @@
from pypy.rlib.runicode import unicode_encode_unicode_escape
from pypy.module.unicodedata import unicodedb
from pypy.tool.sourcetools import func_with_new_name
+from pypy.rlib import jit
from pypy.objspace.std.formatting import mod_format
from pypy.objspace.std.stringtype import stringstartswith, stringendswith
@@ -214,6 +215,8 @@
return _unicode_join_many_items(space, w_self, list_w, size)
+ at jit.look_inside_iff(lambda space, w_self, list_w, size:
+ jit.loop_unrolling_heuristic(list_w, size))
def _unicode_join_many_items(space, w_self, list_w, size):
self = w_self._value
prealloc_size = len(self) * (size - 1)
diff --git a/pypy/rlib/jit.py b/pypy/rlib/jit.py
--- a/pypy/rlib/jit.py
+++ b/pypy/rlib/jit.py
@@ -204,6 +204,14 @@
return NonConstant(False)
isvirtual._annspecialcase_ = "specialize:call_location"
+LIST_CUTOFF = 2
+
+ at specialize.argtype(0)
+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)
+
class Entry(ExtRegistryEntry):
_about_ = hint
diff --git a/pypy/rpython/lltypesystem/rstr.py b/pypy/rpython/lltypesystem/rstr.py
--- a/pypy/rpython/lltypesystem/rstr.py
+++ b/pypy/rpython/lltypesystem/rstr.py
@@ -709,7 +709,8 @@
return count
@enforceargs(int, None)
- @jit.look_inside_iff(lambda length, items: jit.isconstant(length) and length <= 2)
+ @jit.look_inside_iff(lambda length, items: jit.loop_unrolling_heuristic(
+ items, length))
def ll_join_strs(length, items):
# Special case for length 1 items, helps both the JIT and other code
if length == 1:
More information about the pypy-commit
mailing list