[pypy-svn] r74781 - in pypy/branch/blackhole-improvement/pypy/jit/codewriter: . test

arigo at codespeak.net arigo at codespeak.net
Wed May 26 16:44:53 CEST 2010


Author: arigo
Date: Wed May 26 16:44:51 2010
New Revision: 74781

Modified:
   pypy/branch/blackhole-improvement/pypy/jit/codewriter/call.py
   pypy/branch/blackhole-improvement/pypy/jit/codewriter/support.py
   pypy/branch/blackhole-improvement/pypy/jit/codewriter/test/test_codewriter.py
   pypy/branch/blackhole-improvement/pypy/jit/codewriter/test/test_jtransform.py
Log:
Found out how to write it so that int_abs and int_lshift_ovf
are seen by the JIT.  We don't care too much that they are
not inlined by the codewriter.


Modified: pypy/branch/blackhole-improvement/pypy/jit/codewriter/call.py
==============================================================================
--- pypy/branch/blackhole-improvement/pypy/jit/codewriter/call.py	(original)
+++ pypy/branch/blackhole-improvement/pypy/jit/codewriter/call.py	Wed May 26 16:44:51 2010
@@ -41,6 +41,11 @@
 
         assert self.portal_graph is not None
         todo = [self.portal_graph]
+        for oopspec_name, ll_args, ll_res in support.inline_calls_to:
+            c_func, _ = support.builtin_func_for_spec(self.rtyper,
+                                                      oopspec_name,
+                                                      ll_args, ll_res)
+            todo.append(c_func.value._obj.graph)
         candidate_graphs = set(todo)
 
         def callers():

Modified: pypy/branch/blackhole-improvement/pypy/jit/codewriter/support.py
==============================================================================
--- pypy/branch/blackhole-improvement/pypy/jit/codewriter/support.py	(original)
+++ pypy/branch/blackhole-improvement/pypy/jit/codewriter/support.py	Wed May 26 16:44:51 2010
@@ -185,10 +185,22 @@
     return llop.int_mod_zer(lltype.Signed, x, y)
 
 def _ll_2_int_lshift_ovf(x, y):
-    return llop.int_lshift_ovf(lltype.Signed, x, y)
+    result = x << y
+    if (result >> y) != x:
+        raise OverflowError
+    return result
 
 def _ll_1_int_abs(x):
-    return abs(x)
+    if x < 0:
+        return -x
+    else:
+        return x
+
+# in the following calls to builtins, the JIT is allowed to look inside:
+inline_calls_to = [
+    ('int_lshift_ovf', [lltype.Signed, lltype.Signed], lltype.Signed),
+    ('int_abs',        [lltype.Signed],                lltype.Signed),
+    ]
 
 
 class LLtypeHelpers:

Modified: pypy/branch/blackhole-improvement/pypy/jit/codewriter/test/test_codewriter.py
==============================================================================
--- pypy/branch/blackhole-improvement/pypy/jit/codewriter/test/test_codewriter.py	(original)
+++ pypy/branch/blackhole-improvement/pypy/jit/codewriter/test/test_codewriter.py	Wed May 26 16:44:51 2010
@@ -127,3 +127,15 @@
         else:
             assert 0, "missing instantiate_*_%s in:\n%r" % (expected,
                                                             names)
+
+def test_int_abs():
+    def f(n):
+        return abs(n)
+    rtyper = support.annotate(f, [35])
+    maingraph = rtyper.annotator.translator.graphs[0]
+    cw = CodeWriter(FakeCPU(rtyper), maingraph)
+    cw.find_all_graphs(FakePolicy())
+    cw.make_jitcodes(verbose=True)
+    #
+    s = cw.mainjitcode.dump()
+    assert "inline_call_ir_i <JitCode '_ll_1_int_abs__Signed'>" in s

Modified: pypy/branch/blackhole-improvement/pypy/jit/codewriter/test/test_jtransform.py
==============================================================================
--- pypy/branch/blackhole-improvement/pypy/jit/codewriter/test/test_jtransform.py	(original)
+++ pypy/branch/blackhole-improvement/pypy/jit/codewriter/test/test_jtransform.py	Wed May 26 16:44:51 2010
@@ -641,3 +641,13 @@
     assert block.operations[1].args == [v1]
     assert block.operations[1].result is None
     assert block.exits[0].args == [v1]
+
+def test_int_abs():
+    v1 = varoftype(lltype.Signed)
+    v2 = varoftype(lltype.Signed)
+    op = SpaceOperation('int_abs', [v1], v2)
+    tr = Transformer(FakeCPU(), FakeRegularCallControl())
+    tr.graph = "somemaingraph"
+    oplist = tr.rewrite_operation(op)
+    assert oplist[0].opname == 'inline_call_ir_i'
+    assert oplist[0].args[0] == 'somejitcode'



More information about the Pypy-commit mailing list