[pypy-commit] pypy default: Hopefully fix the Win32 translation, which has just hit the limit of

arigo noreply at buildbot.pypy.org
Sun Jan 29 00:33:31 CET 2012


Author: Armin Rigo <arigo at tunes.org>
Branch: 
Changeset: r51940:c5e504c2c62b
Date: 2012-01-29 00:33 +0100
http://bitbucket.org/pypy/pypy/changeset/c5e504c2c62b/

Log:	Hopefully fix the Win32 translation, which has just hit the limit of
	generating more than 256 different instruction variants. Reduce
	this number by limiting instructions that have the "/..c.." variant
	to only the most common instructions.

diff --git a/pypy/jit/codewriter/assembler.py b/pypy/jit/codewriter/assembler.py
--- a/pypy/jit/codewriter/assembler.py
+++ b/pypy/jit/codewriter/assembler.py
@@ -131,13 +131,14 @@
         self.code.append("temporary placeholder")
         #
         argcodes = []
+        allow_short = (insn[0] in USE_C_FORM)
         for x in insn[1:]:
             if isinstance(x, Register):
                 self.emit_reg(x)
                 argcodes.append(x.kind[0])
             elif isinstance(x, Constant):
                 kind = getkind(x.concretetype)
-                is_short = self.emit_const(x, kind, allow_short=True)
+                is_short = self.emit_const(x, kind, allow_short=allow_short)
                 if is_short:
                     argcodes.append('c')
                 else:
@@ -257,3 +258,47 @@
         for func in callinfocollection.all_function_addresses_as_int():
             func = heaptracker.int2adr(func)
             self.see_raw_object(func.ptr)
+
+
+# A set of instructions that use the 'c' encoding for small constants.
+# Allowing it anywhere causes the number of instruction variants to
+# expode, growing past 256.  So we list here only the most common
+# instructions where the 'c' variant might be useful.
+USE_C_FORM = set([
+    'copystrcontent',
+    'copyunicodecontent',
+    'getarrayitem_gc_pure_i',
+    'getarrayitem_gc_pure_r',
+    'getarrayitem_gc_i',
+    'getarrayitem_gc_r',
+    'goto_if_not_int_eq',
+    'goto_if_not_int_ge',
+    'goto_if_not_int_gt',
+    'goto_if_not_int_le',
+    'goto_if_not_int_lt',
+    'goto_if_not_int_ne',
+    'int_add',
+    'int_and',
+    'int_copy',
+    'int_eq',
+    'int_ge',
+    'int_gt',
+    'int_le',
+    'int_lt',
+    'int_ne',
+    'int_return',
+    'int_sub',
+    'jit_merge_point',
+    'new_array',
+    'newstr',
+    'recursive_call_i',
+    'recursive_call_r',
+    'recursive_call_v',
+    'setarrayitem_gc_i',
+    'setarrayitem_gc_r',
+    'setfield_gc_i',
+    'strgetitem',
+    'strsetitem',
+
+    'foobar', 'baz',    # for tests
+])
diff --git a/pypy/jit/codewriter/test/test_assembler.py b/pypy/jit/codewriter/test/test_assembler.py
--- a/pypy/jit/codewriter/test/test_assembler.py
+++ b/pypy/jit/codewriter/test/test_assembler.py
@@ -157,15 +157,18 @@
         ('foobar', ListOfKind('int', [Constant(42, lltype.Signed)])),
         ('foobar', ListOfKind('int', [Constant(42, lltype.Signed)])),
         ('baz', Constant(42, lltype.Signed)),
+        ('bok', Constant(41, lltype.Signed)),
         ]
     assembler = Assembler()
     jitcode = assembler.assemble(ssarepr)
     assert jitcode.code == ("\x00\x01\xFF"
                             "\x00\x01\xFF"
-                            "\x01\x2A")
+                            "\x01\x2A"
+                            "\x02\xFE")
     assert assembler.insns == {'foobar/I': 0,
-                               'baz/c': 1}
-    assert jitcode.constants_i == [42]
+                               'baz/c': 1,    # in USE_C_FORM
+                               'bok/i': 2}    # not in USE_C_FORM
+    assert jitcode.constants_i == [42, 41]
 
 def test_assemble_descr():
     class FooDescr(AbstractDescr):


More information about the pypy-commit mailing list