[pypy-svn] r35782 - in pypy/dist/pypy/translator: c/test cli cli/test oosupport

antocuni at codespeak.net antocuni at codespeak.net
Fri Dec 15 11:50:51 CET 2006


Author: antocuni
Date: Fri Dec 15 11:50:50 2006
New Revision: 35782

Modified:
   pypy/dist/pypy/translator/c/test/test_backendoptimized.py
   pypy/dist/pypy/translator/cli/function.py
   pypy/dist/pypy/translator/cli/ilgenerator.py
   pypy/dist/pypy/translator/cli/test/test_backendopt.py
   pypy/dist/pypy/translator/oosupport/function.py
   pypy/dist/pypy/translator/oosupport/metavm.py
Log:
Make render_numeric_switch_naive backend-indipendent and move it to
oosupport.

Added support for *LongLong switches in gencli.



Modified: pypy/dist/pypy/translator/c/test/test_backendoptimized.py
==============================================================================
--- pypy/dist/pypy/translator/c/test/test_backendoptimized.py	(original)
+++ pypy/dist/pypy/translator/c/test/test_backendoptimized.py	Fri Dec 15 11:50:50 2006
@@ -144,7 +144,7 @@
             return 0
         codegenerator = self.CodeGenerator()
         fn = codegenerator.getcompiled(f, [r_ulonglong])
-        for x in (0,1,2,3,9,27,48, -9):
+        for x in (0,1,2,3,9,27,48, r_ulonglong(-9)):
             assert fn(x) == f(x)
 
     def test_chr_switch(self):

Modified: pypy/dist/pypy/translator/cli/function.py
==============================================================================
--- pypy/dist/pypy/translator/cli/function.py	(original)
+++ pypy/dist/pypy/translator/cli/function.py	Fri Dec 15 11:50:50 2006
@@ -206,6 +206,12 @@
         self.ilasm.opcode('ret')
 
     def render_numeric_switch(self, block):
+        if block.exitswitch.concretetype in (ootype.SignedLongLong, ootype.UnsignedLongLong):
+            # TODO: it could be faster to check is the values fit in
+            # 32bit, and perform a cast in that case
+            self.render_numeric_switch_naive(block)
+            return
+
         cases = {}
         naive = False
         for link in block.exits:
@@ -248,17 +254,6 @@
         self._setup_link(link)
         self.generator.branch_unconditionally(target_label)
 
-    def render_numeric_switch_naive(self, block):
-        for link in block.exits:
-            target_label = self._get_block_name(link.target)
-            self._setup_link(link)
-            if link.exitcase == 'default':
-                self.ilasm.opcode('br', target_label)
-            else:
-                push_constant(self.db, block.exitswitch.concretetype, link.exitcase, self)
-                self.generator.load(block.exitswitch)
-                self.ilasm.opcode('beq', target_label)
-
     # Those parts of the generator interface that are function
     # specific
 

Modified: pypy/dist/pypy/translator/cli/ilgenerator.py
==============================================================================
--- pypy/dist/pypy/translator/cli/ilgenerator.py	(original)
+++ pypy/dist/pypy/translator/cli/ilgenerator.py	Fri Dec 15 11:50:50 2006
@@ -350,6 +350,9 @@
     def branch_conditionally(self, cond, target_label):
         self.ilasm.branch_if(cond, target_label)
 
+    def branch_if_equal(self, target_label):
+        self.ilasm.opcode('beq', target_label)
+
     def push_primitive_constant(self, TYPE, value):
         ilasm = self.ilasm
         if TYPE is ootype.Void:

Modified: pypy/dist/pypy/translator/cli/test/test_backendopt.py
==============================================================================
--- pypy/dist/pypy/translator/cli/test/test_backendopt.py	(original)
+++ pypy/dist/pypy/translator/cli/test/test_backendopt.py	Fri Dec 15 11:50:50 2006
@@ -15,11 +15,6 @@
         return compile_function(fn, annotation, backend_opt=self.backend_opt)
 
 class TestOptimizedSwitchTestCase(CTestCompat, c_TestTypedOptimizedSwitchTestCase):
-    def test_longlong_switch(self):
-        py.test.skip('Not yet supported')
-
-    def test_ulonglong_switch(self):
-        py.test.skip('Not yet supported')
 
     def test_switch_naive(self):
         def fn(x):

Modified: pypy/dist/pypy/translator/oosupport/function.py
==============================================================================
--- pypy/dist/pypy/translator/oosupport/function.py	(original)
+++ pypy/dist/pypy/translator/oosupport/function.py	Fri Dec 15 11:50:50 2006
@@ -1,3 +1,8 @@
+import py
+from pypy.tool.ansi_print import ansi_log
+log = py.log.Producer("oosupport") 
+py.log.setconsumer("oosupport", ansi_log) 
+
 from pypy.objspace.flow import model as flowmodel
 from pypy.rpython.ootypesystem import ootype
 from pypy.translator.oosupport.metavm import InstructionList
@@ -177,7 +182,9 @@
             self.generator.branch_unconditionally(target_label)
         elif block.exitswitch.concretetype is ootype.Bool:
             self.render_bool_switch(block)
-        elif block.exitswitch.concretetype in (ootype.Signed, ootype.Unsigned, ootype.Char, ootype.UniChar):
+        elif block.exitswitch.concretetype in (ootype.Signed, ootype.SignedLongLong,
+                                               ootype.Unsigned, ootype.UnsignedLongLong,
+                                               ootype.Char, ootype.UniChar):
             self.render_numeric_switch(block)
         else:
             assert False, 'Unknonw exitswitch type: %s' % block.exitswitch.concretetype
@@ -195,7 +202,19 @@
                 self.generator.branch_conditionally(link.exitcase, target_label)
 
     def render_numeric_switch(self, block):
-        raise NotImplementedError # it's too dependent on the backend to be implemented here
+        log.WARNING("The default version of render_numeric_switch is *slow*: please override it in the backend")
+        self.render_numeric_switch_naive(block)
+
+    def render_numeric_switch_naive(self, block):
+        for link in block.exits:
+            target_label = self._get_block_name(link.target)
+            self._setup_link(link)
+            if link.exitcase == 'default':
+                self.generator.branch_unconditionally(target_label)
+            else:
+                self.generator.push_primitive_constant(block.exitswitch.concretetype, link.exitcase)
+                self.generator.load(block.exitswitch)
+                self.generator.branch_if_equal(target_label)
 
     def _setup_link(self, link):
         self.generator.add_comment("Setup link")

Modified: pypy/dist/pypy/translator/oosupport/metavm.py
==============================================================================
--- pypy/dist/pypy/translator/oosupport/metavm.py	(original)
+++ pypy/dist/pypy/translator/oosupport/metavm.py	Fri Dec 15 11:50:50 2006
@@ -138,6 +138,15 @@
         Stack: cond, ... -> ... """
         raise NotImplementedError
 
+    def branch_if_equal(self, target_label):
+        """
+        Pops two values from the stack and branches to target_label if
+        they are equal.
+
+        Stack: obj1, obj2, ... -> ...
+        """
+        raise NotImplementedError
+
     def call_graph(self, graph):
         """ Invokes the function corresponding to the given graph.  The
         arguments to the graph have already been pushed in order



More information about the Pypy-commit mailing list