[pypy-svn] r54036 - in pypy/dist/pypy: config objspace objspace/std objspace/std/test

fijal at codespeak.net fijal at codespeak.net
Wed Apr 23 11:54:42 CEST 2008


Author: fijal
Date: Wed Apr 23 11:54:41 2008
New Revision: 54036

Modified:
   pypy/dist/pypy/config/pypyoption.py
   pypy/dist/pypy/objspace/descroperation.py
   pypy/dist/pypy/objspace/std/objspace.py
   pypy/dist/pypy/objspace/std/test/test_intobject.py
Log:
* Create an option for optimized comparison op
* Use this option instead of hacks in descroperation
* test_loop is faster, but will measure it exactly how much.


Modified: pypy/dist/pypy/config/pypyoption.py
==============================================================================
--- pypy/dist/pypy/config/pypyoption.py	(original)
+++ pypy/dist/pypy/config/pypyoption.py	Wed Apr 23 11:54:41 2008
@@ -272,6 +272,9 @@
         BoolOption("optimized_int_add",
                    "special case the addition of two integers in BINARY_ADD",
                    default=False),
+        BoolOption("optimized_comparison_op",
+                   "special case the comparison of integers",
+                   default=False),
         BoolOption("optimized_list_getitem",
                    "special case the 'list[integer]' expressions",
                    default=False),

Modified: pypy/dist/pypy/objspace/descroperation.py
==============================================================================
--- pypy/dist/pypy/objspace/descroperation.py	(original)
+++ pypy/dist/pypy/objspace/descroperation.py	Wed Apr 23 11:54:41 2008
@@ -475,14 +475,8 @@
 def _make_comparison_impl(symbol, specialnames):
     left, right = specialnames
     op = getattr(operator, left)
+    
     def comparison_impl(space, w_obj1, w_obj2):
-        from pypy.objspace.std.intobject import W_IntObject
-        if type(w_obj1) is W_IntObject and type(w_obj2) is W_IntObject:
-            return space.newbool(op(w_obj1.intval, w_obj2.intval))
-        return _comparison_impl(space, w_obj1, w_obj2)
-    comparison_impl._always_inline_ = True
-
-    def _comparison_impl(space, w_obj1, w_obj2):
         w_typ1 = space.type(w_obj1)
         w_typ2 = space.type(w_obj2)
         w_left_src, w_left_impl = space.lookup_in_type_where(w_typ1, left)
@@ -508,11 +502,9 @@
         w_res = _cmp(space, w_first, w_second)
         res = space.int_w(w_res)
         return space.wrap(op(res, 0))
-    _comparison_impl._dont_inline_ = True
 
     return func_with_new_name(comparison_impl, 'comparison_%s_impl'%left.strip('_'))
 
-
 def _make_inplace_impl(symbol, specialnames):
     specialname, = specialnames
     assert specialname.startswith('__i') and specialname.endswith('__')

Modified: pypy/dist/pypy/objspace/std/objspace.py
==============================================================================
--- pypy/dist/pypy/objspace/std/objspace.py	(original)
+++ pypy/dist/pypy/objspace/std/objspace.py	Wed Apr 23 11:54:41 2008
@@ -4,6 +4,7 @@
 from pypy.interpreter.typedef import get_unique_interplevel_subclass
 from pypy.interpreter.argument import Arguments
 from pypy.interpreter import pyframe
+from pypy.interpreter.pyopcode import unrolling_compare_dispatch_table
 from pypy.rlib.objectmodel import instantiate
 from pypy.interpreter.gateway import PyPyCacheDir
 from pypy.tool.cache import Cache 
@@ -17,6 +18,7 @@
      r_longlong, r_ulonglong
 from pypy.rlib.objectmodel import we_are_translated
 from pypy.rlib.jit import hint, we_are_jitted
+from pypy.rlib.unroll import unrolling_iterable
 import sys
 import os
 import __builtin__
@@ -40,6 +42,19 @@
     assert issubclass(implcls, W_Object)
     _registered_implementations[implcls] = True
 
+
+compare_table = [
+    "lt",   # "<"
+    "le",   # "<="
+    "eq",   # "=="
+    "ne",   # "!="
+    "gt",   # ">"
+    "ge",   # ">="
+    ]
+
+unrolling_compare_ops = unrolling_iterable(
+    enumerate(compare_table))
+
 ##################################################################
 
 class StdObjSpace(ObjSpace, DescrOperation):
@@ -149,6 +164,29 @@
                 # def CALL_METHOD(...):
                 from pypy.objspace.std.callmethod import CALL_METHOD
 
+            if self.config.objspace.std.optimized_comparison_op:
+                def COMPARE_OP(f, testnum, *ignored):
+                    import operator
+                    w_2 = f.popvalue()
+                    w_1 = f.popvalue()
+                    w_result = None
+                    if (type(w_2) is W_IntObject and type(w_1) is W_IntObject
+                        and testnum < len(compare_table)):
+                        for i, attr in unrolling_compare_ops:
+                            if i == testnum:
+                                op = getattr(operator, attr)
+                                w_result = f.space.newbool(op(w_1.intval,
+                                                              w_2.intval))
+                                break
+                    else:
+                        for i, attr in unrolling_compare_dispatch_table:
+                            if i == testnum:
+                                w_result = getattr(f, attr)(w_1, w_2)
+                                break
+                        else:
+                            raise BytecodeCorruption, "bad COMPARE_OP oparg"
+                    f.pushvalue(w_result)
+
             if self.config.objspace.std.logspaceoptypes:
                 _space_op_types = []
                 for name, func in pyframe.PyFrame.__dict__.iteritems():
@@ -182,7 +220,7 @@
                                 w_result = operation(w_1)
                                 f.pushvalue(w_result)
                             return func_with_new_name(opimpl, "opcode_impl_for_%s" % operationname)
-                        locals()[name] = make_opimpl(operationname)
+                        locals()[name] = make_opimpl(operationname)                    
 
         self.FrameClass = StdObjSpaceFrame
 

Modified: pypy/dist/pypy/objspace/std/test/test_intobject.py
==============================================================================
--- pypy/dist/pypy/objspace/std/test/test_intobject.py	(original)
+++ pypy/dist/pypy/objspace/std/test/test_intobject.py	Wed Apr 23 11:54:41 2008
@@ -418,3 +418,9 @@
     def setup_class(cls):
         from pypy.conftest import gettestobjspace
         cls.space = gettestobjspace(**{"objspace.std.optimized_int_add": True})
+
+class AppTestIntOptimizedComp(AppTestInt):
+    def setup_class(cls):
+        from pypy.conftest import gettestobjspace
+        cls.space = gettestobjspace(**{"objspace.std.optimized_comparison_op": True})
+        



More information about the Pypy-commit mailing list