[pypy-svn] r74767 - pypy/branch/blackhole-improvement/pypy/jit/codewriter/test
arigo at codespeak.net
arigo at codespeak.net
Wed May 26 11:49:50 CEST 2010
Author: arigo
Date: Wed May 26 11:49:48 2010
New Revision: 74767
Modified:
pypy/branch/blackhole-improvement/pypy/jit/codewriter/test/test_flatten.py
pypy/branch/blackhole-improvement/pypy/jit/codewriter/test/test_jtransform.py
Log:
Implement int_abs using local control flow.
Modified: pypy/branch/blackhole-improvement/pypy/jit/codewriter/test/test_flatten.py
==============================================================================
--- pypy/branch/blackhole-improvement/pypy/jit/codewriter/test/test_flatten.py (original)
+++ pypy/branch/blackhole-improvement/pypy/jit/codewriter/test/test_flatten.py Wed May 26 11:49:48 2010
@@ -682,3 +682,14 @@
int_add %i1, %i2 -> %i3
int_return %i3
""", transform=True)
+
+ def test_int_abs(self):
+ def f(n):
+ return abs(n)
+ self.encoding_test(f, [5], """
+ int_copy %i0 -> %i1
+ goto_if_not_int_lt %i0, $0, L1
+ int_neg %i0 -> %i1
+ L1:
+ int_return %i1
+ """, transform=True)
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 11:49:48 2010
@@ -6,6 +6,7 @@
from pypy.rpython.lltypesystem import lltype, llmemory, rclass, rstr
from pypy.translator.unsimplify import varoftype
from pypy.jit.codewriter import heaptracker
+from pypy.jit.codewriter.flatten import Label, TLabel
class FakeRTyper:
class type_system: name = 'lltypesystem'
@@ -641,3 +642,22 @@
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)
+ oplist = Transformer().rewrite_operation(op)
+ assert len(oplist) == 4
+ assert oplist[0].opname == 'int_copy'
+ assert oplist[0].args == [v1]
+ assert oplist[0].result == v2
+ #
+ assert oplist[1].opname == 'goto_if_not_int_lt'
+ assert oplist[1].args == [v1, Constant(0, lltype.Signed), TLabel(v2)]
+ #
+ assert oplist[2].opname == 'int_neg'
+ assert oplist[2].args == [v1]
+ assert oplist[2].result == v2
+ #
+ assert oplist[3] == Label(v2)
More information about the Pypy-commit
mailing list