[pypy-svn] r76936 - in pypy/trunk/pypy: objspace/flow rlib

arigo at codespeak.net arigo at codespeak.net
Wed Sep 8 11:34:37 CEST 2010


Author: arigo
Date: Wed Sep  8 11:34:35 2010
New Revision: 76936

Modified:
   pypy/trunk/pypy/objspace/flow/specialcase.py
   pypy/trunk/pypy/rlib/rzipfile.py
Log:
Allow constant-folding to occur early for r_uint(long-value).
It must be done before annotation, because now annotation
explodes when seeing the long value.


Modified: pypy/trunk/pypy/objspace/flow/specialcase.py
==============================================================================
--- pypy/trunk/pypy/objspace/flow/specialcase.py	(original)
+++ pypy/trunk/pypy/objspace/flow/specialcase.py	Wed Sep  8 11:34:35 2010
@@ -3,6 +3,7 @@
 from pypy.interpreter.gateway import ApplevelClass
 from pypy.interpreter.error import OperationError
 from pypy.tool.cache import Cache
+from pypy.rlib.rarithmetic import r_uint
 import py
 
 def sc_import(space, fn, args):
@@ -120,6 +121,14 @@
         pass
     return space.do_operation('simple_call', Constant(func), *args_w)
 
+def sc_r_uint(space, r_uint, args):
+    args_w, kwds_w = args.unpack()
+    assert not kwds_w
+    [w_value] = args_w
+    if isinstance(w_value, Constant):
+        return Constant(r_uint(w_value.value))
+    return space.do_operation('simple_call', space.wrap(r_uint), w_value)
+
 def setup(space):
     # fn = pyframe.normalize_exception.get_function(space)
     # this is now routed through the objspace, directly.
@@ -131,3 +140,7 @@
     # if possible
     for fn in OperationName:
         space.specialcases[fn] = sc_operator
+    # special case to constant-fold r_uint(32-bit-constant)
+    # (normally, the 32-bit constant is a long, and is not allowed to
+    # show up in the flow graphs at all)
+    space.specialcases[r_uint] = sc_r_uint

Modified: pypy/trunk/pypy/rlib/rzipfile.py
==============================================================================
--- pypy/trunk/pypy/rlib/rzipfile.py	(original)
+++ pypy/trunk/pypy/rlib/rzipfile.py	Wed Sep  8 11:34:35 2010
@@ -16,16 +16,15 @@
 crc_32_tab = import_from_lib_pypy('binascii').crc_32_tab
 
 rcrc_32_tab = [r_uint(i) for i in crc_32_tab]
-mask32 = r_uint(0xffffffffL)
 
 def crc32(s, crc=0):
     result = 0
-    crc = ~r_uint(crc) & mask32
+    crc = ~r_uint(crc) & r_uint(0xffffffffL)
     for c in s:
-        crc = rcrc_32_tab[(crc ^ r_uint(ord(c))) & 0xff] ^ (crc >> 8)
+        crc = rcrc_32_tab[(crc ^ r_uint(ord(c))) & 0xffL] ^ (crc >> 8)
         #/* Note:  (crc >> 8) MUST zero fill on left
 
-        result = crc ^ mask32
+        result = crc ^ r_uint(0xffffffffL)
     
     return result
 
@@ -195,7 +194,7 @@
             (x.create_version, x.create_system, x.extract_version, x.reserved,
                 x.flag_bits, x.compress_type, t, d,
                 crc, x.compress_size, x.file_size) = centdir[1:12]
-            x.CRC = r_uint(crc) & mask32
+            x.CRC = r_uint(crc) & r_uint(0xffffffff)
             x.dostime = t
             x.dosdate = d
             x.volume, x.internal_attr, x.external_attr = centdir[15:18]



More information about the Pypy-commit mailing list