[pypy-svn] r78744 - in pypy/branch/jit-unroll-loops: . lib-python/modified-2.5.2/test lib_pypy/pypy_test pypy pypy/doc pypy/interpreter pypy/interpreter/pyparser pypy/interpreter/pyparser/test pypy/jit/backend/x86 pypy/jit/backend/x86/test pypy/jit/codewriter pypy/jit/metainterp/optimizeopt pypy/jit/tool pypy/module/array/benchmark pypy/module/array/test pypy/module/pypyjit/test pypy/rlib pypy/rlib/test pypy/tool pypy/translator/c pypy/translator/c/src

hakanardo at codespeak.net hakanardo at codespeak.net
Fri Nov 5 15:32:18 CET 2010


Author: hakanardo
Date: Fri Nov  5 15:32:14 2010
New Revision: 78744

Modified:
   pypy/branch/jit-unroll-loops/   (props changed)
   pypy/branch/jit-unroll-loops/lib-python/modified-2.5.2/test/mapping_tests.py
   pypy/branch/jit-unroll-loops/lib_pypy/pypy_test/test_ctypes_support.py
   pypy/branch/jit-unroll-loops/pypy/   (props changed)
   pypy/branch/jit-unroll-loops/pypy/doc/getting-started.txt
   pypy/branch/jit-unroll-loops/pypy/interpreter/baseobjspace.py
   pypy/branch/jit-unroll-loops/pypy/interpreter/executioncontext.py
   pypy/branch/jit-unroll-loops/pypy/interpreter/pyparser/genpytokenize.py
   pypy/branch/jit-unroll-loops/pypy/interpreter/pyparser/pytokenize.py
   pypy/branch/jit-unroll-loops/pypy/interpreter/pyparser/test/test_pyparse.py
   pypy/branch/jit-unroll-loops/pypy/jit/backend/x86/assembler.py
   pypy/branch/jit-unroll-loops/pypy/jit/backend/x86/test/test_runner.py
   pypy/branch/jit-unroll-loops/pypy/jit/codewriter/call.py
   pypy/branch/jit-unroll-loops/pypy/jit/codewriter/jtransform.py
   pypy/branch/jit-unroll-loops/pypy/jit/metainterp/optimizeopt/optimizer.py   (props changed)
   pypy/branch/jit-unroll-loops/pypy/jit/tool/pypytrace.vim
   pypy/branch/jit-unroll-loops/pypy/jit/tool/showstats.py
   pypy/branch/jit-unroll-loops/pypy/module/array/benchmark/Makefile   (props changed)
   pypy/branch/jit-unroll-loops/pypy/module/array/benchmark/intimg.c   (props changed)
   pypy/branch/jit-unroll-loops/pypy/module/array/benchmark/intimgtst.c   (props changed)
   pypy/branch/jit-unroll-loops/pypy/module/array/benchmark/intimgtst.py   (props changed)
   pypy/branch/jit-unroll-loops/pypy/module/array/benchmark/loop.c   (props changed)
   pypy/branch/jit-unroll-loops/pypy/module/array/benchmark/sum.c   (props changed)
   pypy/branch/jit-unroll-loops/pypy/module/array/benchmark/sumtst.c   (props changed)
   pypy/branch/jit-unroll-loops/pypy/module/array/benchmark/sumtst.py   (props changed)
   pypy/branch/jit-unroll-loops/pypy/module/array/test/test_array_old.py   (props changed)
   pypy/branch/jit-unroll-loops/pypy/module/pypyjit/test/test_pypy_c.py
   pypy/branch/jit-unroll-loops/pypy/rlib/rerased.py   (props changed)
   pypy/branch/jit-unroll-loops/pypy/rlib/test/test_rerased.py   (props changed)
   pypy/branch/jit-unroll-loops/pypy/tool/alarm.py
   pypy/branch/jit-unroll-loops/pypy/tool/readdictinfo.py
   pypy/branch/jit-unroll-loops/pypy/tool/rundictbenchmarks.py
   pypy/branch/jit-unroll-loops/pypy/tool/statistic_irc_log.py
   pypy/branch/jit-unroll-loops/pypy/tool/watchdog.py
   pypy/branch/jit-unroll-loops/pypy/tool/watchdog_nt.py
   pypy/branch/jit-unroll-loops/pypy/translator/c/genc.py
   pypy/branch/jit-unroll-loops/pypy/translator/c/src/g_include.h
   pypy/branch/jit-unroll-loops/pypy/translator/c/src/int.h
Log:
svn merge -r78530:HEAD svn+ssh://hakanardo@codespeak.net/svn/pypy/trunk

Modified: pypy/branch/jit-unroll-loops/lib-python/modified-2.5.2/test/mapping_tests.py
==============================================================================
--- pypy/branch/jit-unroll-loops/lib-python/modified-2.5.2/test/mapping_tests.py	(original)
+++ pypy/branch/jit-unroll-loops/lib-python/modified-2.5.2/test/mapping_tests.py	Fri Nov  5 15:32:14 2010
@@ -1,6 +1,7 @@
 # tests common to dict and UserDict
 import unittest
 import UserDict
+from test import test_support
 
 
 class BasicTestMappingProtocol(unittest.TestCase):
@@ -525,7 +526,8 @@
                     self.assertEqual(va, int(ka))
                     kb, vb = tb = b.popitem()
                     self.assertEqual(vb, int(kb))
-                    self.assert_(not(copymode < 0 and ta != tb))
+                    if test_support.check_impl_detail():
+                        self.assert_(not(copymode < 0 and ta != tb))
                 self.assert_(not a)
                 self.assert_(not b)
 

Modified: pypy/branch/jit-unroll-loops/lib_pypy/pypy_test/test_ctypes_support.py
==============================================================================
--- pypy/branch/jit-unroll-loops/lib_pypy/pypy_test/test_ctypes_support.py	(original)
+++ pypy/branch/jit-unroll-loops/lib_pypy/pypy_test/test_ctypes_support.py	Fri Nov  5 15:32:14 2010
@@ -22,12 +22,11 @@
     assert get_errno() == 0
 
 def test_argument_conversion_and_checks():
-    import ctypes
-    libc = ctypes.cdll.LoadLibrary("libc.so.6")
-    libc.strlen.argtypes = ctypes.c_char_p,
-    libc.strlen.restype = ctypes.c_size_t
-    assert libc.strlen("eggs") == 4
-    
+    strlen = standard_c_lib.strlen
+    strlen.argtypes = [c_char_p]
+    strlen.restype = c_size_t
+    assert strlen("eggs") == 4
+
     # Should raise ArgumentError, not segfault
-    py.test.raises(ctypes.ArgumentError, libc.strlen, False)
+    py.test.raises(ArgumentError, strlen, False)
 

Modified: pypy/branch/jit-unroll-loops/pypy/doc/getting-started.txt
==============================================================================
--- pypy/branch/jit-unroll-loops/pypy/doc/getting-started.txt	(original)
+++ pypy/branch/jit-unroll-loops/pypy/doc/getting-started.txt	Fri Nov  5 15:32:14 2010
@@ -18,6 +18,7 @@
 translation process - as opposed to encoding low level details into the
 language implementation itself. `more...`_
 
+
 .. _Python: http://docs.python.org/ref
 .. _`more...`: architecture.html
 

Modified: pypy/branch/jit-unroll-loops/pypy/interpreter/baseobjspace.py
==============================================================================
--- pypy/branch/jit-unroll-loops/pypy/interpreter/baseobjspace.py	(original)
+++ pypy/branch/jit-unroll-loops/pypy/interpreter/baseobjspace.py	Fri Nov  5 15:32:14 2010
@@ -299,6 +299,8 @@
                 self.timer.start("startup " + modname)
                 mod.init(self)
                 self.timer.stop("startup " + modname)
+        # Force the tick counter to have a valid value
+        self.actionflag.force_tick_counter()
 
     def finish(self):
         self.wait_for_thread_shutdown()

Modified: pypy/branch/jit-unroll-loops/pypy/interpreter/executioncontext.py
==============================================================================
--- pypy/branch/jit-unroll-loops/pypy/interpreter/executioncontext.py	(original)
+++ pypy/branch/jit-unroll-loops/pypy/interpreter/executioncontext.py	Fri Nov  5 15:32:14 2010
@@ -19,6 +19,9 @@
     # XXX   self.w_tracefunc, self.profilefunc
     # XXX   frame.is_being_profiled
 
+    # XXX [fijal] but they're not. is_being_profiled is guarded a bit all
+    #     over the place as well as w_tracefunc
+
     def __init__(self, space):
         self.space = space
         self.topframeref = jit.vref_None
@@ -317,7 +320,7 @@
                         " traceback and see where this one comes from :-)")
 
 
-class AbstractActionFlag:
+class AbstractActionFlag(object):
     """This holds the global 'action flag'.  It is a single bitfield
     integer, with bits corresponding to AsyncAction objects that need to
     be immediately triggered.  The correspondance from bits to

Modified: pypy/branch/jit-unroll-loops/pypy/interpreter/pyparser/genpytokenize.py
==============================================================================
--- pypy/branch/jit-unroll-loops/pypy/interpreter/pyparser/genpytokenize.py	(original)
+++ pypy/branch/jit-unroll-loops/pypy/interpreter/pyparser/genpytokenize.py	Fri Nov  5 15:32:14 2010
@@ -17,12 +17,17 @@
 def makePyPseudoDFA ():
     import string
     states = []
+    def makeEOL():
+        return group(states,
+                     newArcPair(states, "\n"),
+                     chain(states,
+                           newArcPair(states, "\r"),
+                           maybe(states, newArcPair(states, "\n"))))
     # ____________________________________________________________
     def makeLineCont ():
         return chain(states,
                      newArcPair(states, "\\"),
-                     maybe(states, newArcPair(states, "\r")),
-                     newArcPair(states, "\n"))
+                     makeEOL())
     # ____________________________________________________________
     # Ignore stuff
     def makeWhitespace ():
@@ -124,9 +129,7 @@
                      newArcPair(states, "~"))
     bracket = groupStr(states, "[](){}")
     special = group(states,
-                    chain(states,
-                          maybe(states, newArcPair(states, "\r")),
-                          newArcPair(states, "\n")),
+                    makeEOL(),
                     groupStr(states, "@:;.,`"))
     funny = group(states, operator, bracket, special)
     # ____________________________________________________________
@@ -140,13 +143,13 @@
                           makeStrPrefix(),
                           newArcPair(states, "'"),
                           any(states,
-                              notGroupStr(states, "\n'\\")),
+                              notGroupStr(states, "\r\n'\\")),
                           any(states,
                               chain(states,
                                     newArcPair(states, "\\"),
                                     newArcPair(states, DEFAULT),
                                     any(states,
-                                        notGroupStr(states, "\n'\\")))),
+                                        notGroupStr(states, "\r\n'\\")))),
                           group(states,
                                 newArcPair(states, "'"),
                                 makeLineCont())),
@@ -154,13 +157,13 @@
                           makeStrPrefix(),
                           newArcPair(states, '"'),
                           any(states,
-                              notGroupStr(states, '\n"\\')),
+                              notGroupStr(states, '\r\n"\\')),
                           any(states,
                               chain(states,
                                     newArcPair(states, "\\"),
                                     newArcPair(states, DEFAULT),
                                     any(states,
-                                        notGroupStr(states, '\n"\\')))),
+                                        notGroupStr(states, '\r\n"\\')))),
                           group(states,
                                 newArcPair(states, '"'),
                                 makeLineCont())))

Modified: pypy/branch/jit-unroll-loops/pypy/interpreter/pyparser/pytokenize.py
==============================================================================
--- pypy/branch/jit-unroll-loops/pypy/interpreter/pyparser/pytokenize.py	(original)
+++ pypy/branch/jit-unroll-loops/pypy/interpreter/pyparser/pytokenize.py	Fri Nov  5 15:32:14 2010
@@ -24,7 +24,7 @@
 # Automatically generated DFA's
 
 accepts = [True, True, True, True, True, True, True, True,
-           True, True, False, True, True, True, False, False,
+           True, True, False, True, True, True, True, False,
            False, False, True, True, True, False, True,
            False, True, False, True, False, False, True,
            False, False, False, False, True, False, False,
@@ -142,9 +142,11 @@
     # 14
     {'\n': 13},
     # 15
-    {automata.DEFAULT: 28, '\n': 25, "'": 26, '\\': 27},
+    {automata.DEFAULT: 28, '\n': 25,
+     '\r': 25, "'": 26, '\\': 27},
     # 16
-    {automata.DEFAULT: 31, '\n': 25, '"': 29, '\\': 30},
+    {automata.DEFAULT: 31, '\n': 25,
+     '\r': 25, '"': 29, '\\': 30},
     # 17
     {'\n': 13, '\r': 14},
     # 18
@@ -188,13 +190,15 @@
     # 27
     {automata.DEFAULT: 35, '\n': 13, '\r': 14},
     # 28
-    {automata.DEFAULT: 28, '\n': 25, "'": 13, '\\': 27},
+    {automata.DEFAULT: 28, '\n': 25,
+     '\r': 25, "'": 13, '\\': 27},
     # 29
     {'"': 13},
     # 30
     {automata.DEFAULT: 36, '\n': 13, '\r': 14},
     # 31
-    {automata.DEFAULT: 31, '\n': 25, '"': 13, '\\': 30},
+    {automata.DEFAULT: 31, '\n': 25,
+     '\r': 25, '"': 13, '\\': 30},
     # 32
     {'+': 37, '-': 37, '0': 38, '1': 38,
      '2': 38, '3': 38, '4': 38, '5': 38,
@@ -208,9 +212,11 @@
      '4': 34, '5': 34, '6': 34, '7': 34,
      '8': 34, '9': 34, 'J': 13, 'j': 13},
     # 35
-    {automata.DEFAULT: 35, '\n': 25, "'": 13, '\\': 27},
+    {automata.DEFAULT: 35, '\n': 25,
+     '\r': 25, "'": 13, '\\': 27},
     # 36
-    {automata.DEFAULT: 36, '\n': 25, '"': 13, '\\': 30},
+    {automata.DEFAULT: 36, '\n': 25,
+     '\r': 25, '"': 13, '\\': 30},
     # 37
     {'0': 38, '1': 38, '2': 38, '3': 38,
      '4': 38, '5': 38, '6': 38, '7': 38,
@@ -282,7 +288,6 @@
     ]
 doubleDFA = automata.DFA(states, accepts)
 
-
 #_______________________________________________________________________
 # End of automatically generated DFA's
 

Modified: pypy/branch/jit-unroll-loops/pypy/interpreter/pyparser/test/test_pyparse.py
==============================================================================
--- pypy/branch/jit-unroll-loops/pypy/interpreter/pyparser/test/test_pyparse.py	(original)
+++ pypy/branch/jit-unroll-loops/pypy/interpreter/pyparser/test/test_pyparse.py	Fri Nov  5 15:32:14 2010
@@ -92,6 +92,9 @@
         exc = py.test.raises(IndentationError, parse, input).value
         assert exc.msg == "unindent does not match any outer indentation level"
 
+    def test_mac_newline(self):
+        self.parse("this_is\ra_mac\rfile")
+
     def test_mode(self):
         assert self.parse("x = 43*54").type == syms.file_input
         tree = self.parse("43**54", "eval")

Modified: pypy/branch/jit-unroll-loops/pypy/jit/backend/x86/assembler.py
==============================================================================
--- pypy/branch/jit-unroll-loops/pypy/jit/backend/x86/assembler.py	(original)
+++ pypy/branch/jit-unroll-loops/pypy/jit/backend/x86/assembler.py	Fri Nov  5 15:32:14 2010
@@ -712,9 +712,11 @@
             dispatch_opnum = guard_opnum
         else:
             dispatch_opnum = op.getopnum()
-        res = genop_guard_list[dispatch_opnum](self, op, guard_op, guard_token,
-                                               arglocs, resloc)
-        faildescr._x86_adr_jump_offset = res
+        genop_guard_list[dispatch_opnum](self, op, guard_op, guard_token,
+                                         arglocs, resloc)
+        if not we_are_translated():
+            # must be added by the genop_guard_list[]()
+            assert hasattr(faildescr, '_x86_adr_jump_offset')
 
     def regalloc_perform_guard(self, guard_op, faillocs, arglocs, resloc,
                                current_depths):
@@ -771,15 +773,15 @@
             if isinstance(op.getarg(0), Const):
                 self.mc.CMP(arglocs[1], arglocs[0])
                 if guard_opnum == rop.GUARD_FALSE:
-                    return self.implement_guard(guard_token, rev_cond)
+                    self.implement_guard(guard_token, rev_cond)
                 else:
-                    return self.implement_guard(guard_token, false_rev_cond)
+                    self.implement_guard(guard_token, false_rev_cond)
             else:
                 self.mc.CMP(arglocs[0], arglocs[1])
                 if guard_opnum == rop.GUARD_FALSE:
-                    return self.implement_guard(guard_token, cond)
+                    self.implement_guard(guard_token, cond)
                 else:
-                    return self.implement_guard(guard_token, false_cond)
+                    self.implement_guard(guard_token, false_cond)
         return genop_cmp_guard
 
     def _cmpop_guard_float(cond, false_cond, need_jp):
@@ -793,13 +795,14 @@
             if guard_opnum == rop.GUARD_FALSE:
                 if need_jp:
                     self.mc.J_il8(rx86.Conditions['P'], 6)
-                return self.implement_guard(guard_token, cond)
+                self.implement_guard(guard_token, cond)
             else:
                 if need_jp:
                     self.mc.J_il8(rx86.Conditions['P'], 2)
                     self.mc.J_il8(rx86.Conditions[cond], 5)
-                    return self.implement_guard(guard_token)
-                return self.implement_guard(guard_token, false_cond)
+                    self.implement_guard(guard_token)
+                else:
+                    self.implement_guard(guard_token, false_cond)
         return genop_cmp_guard_float
 
     def _emit_call(self, x, arglocs, start=0, tmp=eax):
@@ -961,11 +964,11 @@
         self.mc.ensure_bytes_available(16 + guard_token.recovery_stub_size())
         if guard_opnum == rop.GUARD_TRUE:
             self.mc.J_il8(rx86.Conditions['P'], 6)
-            return self.implement_guard(guard_token, 'E')
+            self.implement_guard(guard_token, 'E')
         else:
             self.mc.J_il8(rx86.Conditions['P'], 2)
             self.mc.J_il8(rx86.Conditions['E'], 5)
-            return self.implement_guard(guard_token)
+            self.implement_guard(guard_token)
 
     def genop_float_neg(self, op, arglocs, resloc):
         # Following what gcc does: res = x ^ 0x8000000000000000
@@ -985,9 +988,9 @@
         guard_opnum = guard_op.getopnum()
         self.mc.CMP(arglocs[0], imm0)
         if guard_opnum == rop.GUARD_TRUE:
-            return self.implement_guard(guard_token, 'Z')
+            self.implement_guard(guard_token, 'Z')
         else:
-            return self.implement_guard(guard_token, 'NZ')
+            self.implement_guard(guard_token, 'NZ')
 
     def genop_int_is_true(self, op, arglocs, resloc):
         self.mc.CMP(arglocs[0], imm0)
@@ -999,9 +1002,9 @@
         guard_opnum = guard_op.getopnum()
         self.mc.CMP(arglocs[0], imm0)
         if guard_opnum == rop.GUARD_TRUE:
-            return self.implement_guard(guard_token, 'NZ')
+            self.implement_guard(guard_token, 'NZ')
         else:
-            return self.implement_guard(guard_token, 'Z')
+            self.implement_guard(guard_token, 'Z')
 
     def genop_int_is_zero(self, op, arglocs, resloc):
         self.mc.CMP(arglocs[0], imm0)
@@ -1198,13 +1201,13 @@
     def genop_guard_guard_true(self, ign_1, guard_op, guard_token, locs, ign_2):
         loc = locs[0]
         self.mc.TEST(loc, loc)
-        return self.implement_guard(guard_token, 'Z')
+        self.implement_guard(guard_token, 'Z')
     genop_guard_guard_nonnull = genop_guard_guard_true
 
     def genop_guard_guard_no_exception(self, ign_1, guard_op, guard_token,
                                        locs, ign_2):
         self.mc.CMP(heap(self.cpu.pos_exception()), imm0)
-        return self.implement_guard(guard_token, 'NZ')
+        self.implement_guard(guard_token, 'NZ')
 
     def genop_guard_guard_exception(self, ign_1, guard_op, guard_token,
                                     locs, resloc):
@@ -1212,19 +1215,18 @@
         loc1 = locs[1]
         self.mc.MOV(loc1, heap(self.cpu.pos_exception()))
         self.mc.CMP(loc1, loc)
-        addr = self.implement_guard(guard_token, 'NE')
+        self.implement_guard(guard_token, 'NE')
         if resloc is not None:
             self.mc.MOV(resloc, heap(self.cpu.pos_exc_value()))
         self.mc.MOV(heap(self.cpu.pos_exception()), imm0)
         self.mc.MOV(heap(self.cpu.pos_exc_value()), imm0)
-        return addr
 
     def _gen_guard_overflow(self, guard_op, guard_token):
         guard_opnum = guard_op.getopnum()
         if guard_opnum == rop.GUARD_NO_OVERFLOW:
-            return self.implement_guard(guard_token, 'O')
+            self.implement_guard(guard_token, 'O')
         elif guard_opnum == rop.GUARD_OVERFLOW:
-            return self.implement_guard(guard_token, 'NO')
+            self.implement_guard(guard_token, 'NO')
         else:
             not_implemented("int_xxx_ovf followed by %s" %
                             guard_op.getopname())
@@ -1244,7 +1246,7 @@
     def genop_guard_guard_false(self, ign_1, guard_op, guard_token, locs, ign_2):
         loc = locs[0]
         self.mc.TEST(loc, loc)
-        return self.implement_guard(guard_token, 'NZ')
+        self.implement_guard(guard_token, 'NZ')
     genop_guard_guard_isnull = genop_guard_guard_false
 
     def genop_guard_guard_value(self, ign_1, guard_op, guard_token, locs, ign_2):
@@ -1253,7 +1255,7 @@
             self.mc.UCOMISD(locs[0], locs[1])
         else:
             self.mc.CMP(locs[0], locs[1])
-        return self.implement_guard(guard_token, 'NE')
+        self.implement_guard(guard_token, 'NE')
 
     def _cmp_guard_class(self, locs):
         offset = self.cpu.vtable_offset
@@ -1285,7 +1287,7 @@
     def genop_guard_guard_class(self, ign_1, guard_op, guard_token, locs, ign_2):
         self.mc.ensure_bytes_available(256)
         self._cmp_guard_class(locs)
-        return self.implement_guard(guard_token, 'NE')
+        self.implement_guard(guard_token, 'NE')
 
     def genop_guard_guard_nonnull_class(self, ign_1, guard_op,
                                         guard_token, locs, ign_2):
@@ -1300,7 +1302,7 @@
         assert 0 < offset <= 127
         self.mc.overwrite(jb_location-1, [chr(offset)])
         #
-        return self.implement_guard(guard_token, 'NE')
+        self.implement_guard(guard_token, 'NE')
 
     def implement_guard_recovery(self, guard_opnum, faildescr, failargs,
                                                                fail_locs):
@@ -1627,13 +1629,15 @@
     def implement_guard(self, guard_token, condition=None):
         self.mc.reserve_bytes(guard_token.recovery_stub_size())
         self.pending_guard_tokens.append(guard_token)
-        # XXX: These jumps are patched later, the self.mc.tell() are just
-        # dummy values
+        # These jumps are patched later, the mc.tell() are just
+        # dummy values.  Also, use self.mc._mc to avoid triggering a
+        # "buffer full" exactly here.
+        mc = self.mc._mc
         if condition:
-            self.mc.J_il(rx86.Conditions[condition], self.mc.tell())
+            mc.J_il(rx86.Conditions[condition], mc.tell())
         else:
-            self.mc.JMP_l(self.mc.tell())
-        return self.mc.tell() - 4
+            mc.JMP_l(mc.tell())
+        guard_token.faildescr._x86_adr_jump_offset = mc.tell() - 4
 
     def genop_call(self, op, arglocs, resloc):
         sizeloc = arglocs[0]
@@ -1674,7 +1678,7 @@
         self.mc.MOV_bi(FORCE_INDEX_OFS, fail_index)
         self.genop_call(op, arglocs, result_loc)
         self.mc.CMP_bi(FORCE_INDEX_OFS, 0)
-        return self.implement_guard(guard_token, 'L')
+        self.implement_guard(guard_token, 'L')
 
     def genop_guard_call_assembler(self, op, guard_op, guard_token,
                                    arglocs, result_loc):
@@ -1761,7 +1765,7 @@
         assert 0 <= offset <= 127
         self.mc.overwrite(jmp_location - 1, [chr(offset)])
         self.mc.CMP_bi(FORCE_INDEX_OFS, 0)
-        return self.implement_guard(guard_token, 'L')
+        self.implement_guard(guard_token, 'L')
 
     def genop_discard_cond_call_gc_wb(self, op, arglocs):
         # use 'mc._mc' directly instead of 'mc', to avoid

Modified: pypy/branch/jit-unroll-loops/pypy/jit/backend/x86/test/test_runner.py
==============================================================================
--- pypy/branch/jit-unroll-loops/pypy/jit/backend/x86/test/test_runner.py	(original)
+++ pypy/branch/jit-unroll-loops/pypy/jit/backend/x86/test/test_runner.py	Fri Nov  5 15:32:14 2010
@@ -478,6 +478,10 @@
             # whether the test segfaults.
             assert self.cpu.get_latest_value_int(0) == finished.value
 
+    def test_overflow_guard_exception(self):
+        for i in range(50):
+            self.test_exceptions()
+
 
 class TestDebuggingAssembler(object):
     def setup_method(self, meth):

Modified: pypy/branch/jit-unroll-loops/pypy/jit/codewriter/call.py
==============================================================================
--- pypy/branch/jit-unroll-loops/pypy/jit/codewriter/call.py	(original)
+++ pypy/branch/jit-unroll-loops/pypy/jit/codewriter/call.py	Fri Nov  5 15:32:14 2010
@@ -237,6 +237,8 @@
                                     effectinfo)
 
     def _canraise(self, op):
+        if op.opname == 'pseudo_call_cannot_raise':
+            return False
         try:
             return self.raise_analyzer.can_raise(op)
         except lltype.DelayedPointer:

Modified: pypy/branch/jit-unroll-loops/pypy/jit/codewriter/jtransform.py
==============================================================================
--- pypy/branch/jit-unroll-loops/pypy/jit/codewriter/jtransform.py	(original)
+++ pypy/branch/jit-unroll-loops/pypy/jit/codewriter/jtransform.py	Fri Nov  5 15:32:14 2010
@@ -1098,7 +1098,7 @@
         c_func, TP = support.builtin_func_for_spec(self.cpu.rtyper,
                                                    oopspec_name, argtypes,
                                                    resulttype)
-        op = SpaceOperation('pseudo_call',
+        op = SpaceOperation('pseudo_call_cannot_raise',
                             [c_func] + [varoftype(T) for T in argtypes],
                             varoftype(resulttype))
         calldescr = self.callcontrol.getcalldescr(op, oopspecindex)

Modified: pypy/branch/jit-unroll-loops/pypy/jit/tool/pypytrace.vim
==============================================================================
--- pypy/branch/jit-unroll-loops/pypy/jit/tool/pypytrace.vim	(original)
+++ pypy/branch/jit-unroll-loops/pypy/jit/tool/pypytrace.vim	Fri Nov  5 15:32:14 2010
@@ -22,7 +22,7 @@
 hi def link pypyLoopStart   Structure
 "hi def link pypyLoopArgs    PreProc
 hi def link pypyFailArgs    String
-hi def link pypyOpName      Statement
+"hi def link pypyOpName      Statement
 hi def link pypyDebugMergePoint  Comment
 hi def link pypyConstPtr    Constant
 hi def link pypyNumber      Number

Modified: pypy/branch/jit-unroll-loops/pypy/jit/tool/showstats.py
==============================================================================
--- pypy/branch/jit-unroll-loops/pypy/jit/tool/showstats.py	(original)
+++ pypy/branch/jit-unroll-loops/pypy/jit/tool/showstats.py	Fri Nov  5 15:32:14 2010
@@ -10,7 +10,8 @@
 
 def main(argv):
     log = logparser.parse_log_file(argv[0])
-    parts = logparser.extract_category(log, "jit-log-noopt-")
+    log_count_lines = open(argv[0] + '.count').readlines()
+    parts = logparser.extract_category(log, "jit-log-opt-")
     for i, oplist in enumerate(parts):
         loop = parse(oplist, no_namespace=True, nonstrict=True)
         num_ops = 0
@@ -27,6 +28,7 @@
             print "Loop #%d, length: %d, opcodes: %d, guards: %d" % (i, num_ops, num_dmp, num_guards)
         else:
             print "Loop #%d, length: %d, opcodes: %d, guards: %d, %f" % (i, num_ops, num_dmp, num_guards, num_ops/num_dmp)
-
+        print loop.comment, "run", log_count_lines[i].split(":")[1].strip(), "times"
+        
 if __name__ == '__main__':
     main(sys.argv[1:])

Modified: pypy/branch/jit-unroll-loops/pypy/module/pypyjit/test/test_pypy_c.py
==============================================================================
--- pypy/branch/jit-unroll-loops/pypy/module/pypyjit/test/test_pypy_c.py	(original)
+++ pypy/branch/jit-unroll-loops/pypy/module/pypyjit/test/test_pypy_c.py	Fri Nov  5 15:32:14 2010
@@ -93,6 +93,9 @@
         # some support code...
         print >> f, py.code.Source("""
             import sys
+            # we don't want to see the small bridges created
+            # by the checkinterval reaching the limit
+            sys.setcheckinterval(10000000)
             try: # make the file runnable by CPython
                 import pypyjit
                 pypyjit.set_param(threshold=%d)

Modified: pypy/branch/jit-unroll-loops/pypy/tool/alarm.py
==============================================================================
--- pypy/branch/jit-unroll-loops/pypy/tool/alarm.py	(original)
+++ pypy/branch/jit-unroll-loops/pypy/tool/alarm.py	Fri Nov  5 15:32:14 2010
@@ -38,8 +38,9 @@
     sys.path.insert(0, os.path.dirname(sys.argv[0]))
     return sys.argv[0]
 
-finished = []
-try:
-    execfile(_main_with_alarm(finished))
-finally:
-    finished.append(True)
+if __name__ == '__main__':
+    finished = []
+    try:
+        execfile(_main_with_alarm(finished))
+    finally:
+        finished.append(True)

Modified: pypy/branch/jit-unroll-loops/pypy/tool/readdictinfo.py
==============================================================================
--- pypy/branch/jit-unroll-loops/pypy/tool/readdictinfo.py	(original)
+++ pypy/branch/jit-unroll-loops/pypy/tool/readdictinfo.py	Fri Nov  5 15:32:14 2010
@@ -7,37 +7,38 @@
 
 import sys
 
-infile = open(sys.argv[1])
+if __name__ == '__main__':
+    infile = open(sys.argv[1])
 
-curr = None
-slots = []
-for line in infile:
-    if line == '------------------\n':
-        if curr:
-            break
-        curr = 1
-    else:
-        attr, val = [s.strip() for s in line.split(':')]
-        slots.append(attr)
+    curr = None
+    slots = []
+    for line in infile:
+        if line == '------------------\n':
+            if curr:
+                break
+            curr = 1
+        else:
+            attr, val = [s.strip() for s in line.split(':')]
+            slots.append(attr)
 
-class DictInfo(object):
-    __slots__ = slots
+    class DictInfo(object):
+        __slots__ = slots
 
-infile = open(sys.argv[1])
+    infile = open(sys.argv[1])
 
-infos = []
+    infos = []
 
-for line in infile:
-    if line == '------------------\n':
-        curr = object.__new__(DictInfo)
-        infos.append(curr)
-    else:
-        attr, val = [s.strip() for s in line.split(':')]
-        if '.' in val:
-            val = float(val)
+    for line in infile:
+        if line == '------------------\n':
+            curr = object.__new__(DictInfo)
+            infos.append(curr)
         else:
-            val = int(val)
-        setattr(curr, attr, val)
+            attr, val = [s.strip() for s in line.split(':')]
+            if '.' in val:
+                val = float(val)
+            else:
+                val = int(val)
+            setattr(curr, attr, val)
 
 def histogram(infos, keyattr, *attrs):
     r = {}

Modified: pypy/branch/jit-unroll-loops/pypy/tool/rundictbenchmarks.py
==============================================================================
--- pypy/branch/jit-unroll-loops/pypy/tool/rundictbenchmarks.py	(original)
+++ pypy/branch/jit-unroll-loops/pypy/tool/rundictbenchmarks.py	Fri Nov  5 15:32:14 2010
@@ -7,20 +7,21 @@
 # need to hack a copy of rst2html for yourself (svn docutils
 # required).
 
-try:
-    os.unlink("dictinfo.txt")
-except os.error:
-    pass
+if __name__ == '__main__':
+    try:
+        os.unlink("dictinfo.txt")
+    except os.error:
+        pass
 
-progs = [('pystone', ['-c', 'from test import pystone; pystone.main()']),
-         ('richards', ['richards.py']),
-         ('docutils', ['rst2html.py', '../../doc/coding-guide.txt', 'foo.html']),
-         ('translate', ['translate.py', '--backendopt', '--no-compile', '--batch',
-                        'targetrpystonedalone.py'])
-         ]
+    progs = [('pystone', ['-c', 'from test import pystone; pystone.main()']),
+             ('richards', ['richards.py']),
+             ('docutils', ['rst2html.py', '../../doc/coding-guide.txt', 'foo.html']),
+             ('translate', ['translate.py', '--backendopt', '--no-compile', '--batch',
+                            'targetrpystonedalone.py'])
+             ]
 
-EXE = sys.argv[1]
+    EXE = sys.argv[1]
 
-for suffix, args in progs:
-    os.spawnv(os.P_WAIT, EXE, [EXE] + args)
-    os.rename('dictinfo.txt', 'dictinfo-%s.txt'%suffix)
+    for suffix, args in progs:
+        os.spawnv(os.P_WAIT, EXE, [EXE] + args)
+        os.rename('dictinfo.txt', 'dictinfo-%s.txt'%suffix)

Modified: pypy/branch/jit-unroll-loops/pypy/tool/statistic_irc_log.py
==============================================================================
--- pypy/branch/jit-unroll-loops/pypy/tool/statistic_irc_log.py	(original)
+++ pypy/branch/jit-unroll-loops/pypy/tool/statistic_irc_log.py	Fri Nov  5 15:32:14 2010
@@ -2,53 +2,54 @@
 from os import system, chdir
 from urllib import urlopen
 
-log_URL = 'http://tismerysoft.de/pypy/irc-logs/'
-archive_FILENAME = 'pypy.tar.gz'
-
-tempdir = py.test.ensuretemp("irc-log")
-
-# get compressed archive
-chdir( str(tempdir))
-system('wget -q %s%s' % (log_URL, archive_FILENAME))
-system('tar xzf %s'   % archive_FILENAME)
-chdir('pypy')
-
-# get more recent daily logs
-pypydir = tempdir.join('pypy')
-for line in urlopen(log_URL + 'pypy/').readlines():
-    i = line.find('%23pypy.log.')
-    if i == -1:
-        continue
-    filename = line[i:].split('"')[0]
-    system('wget -q %spypy/%s' % (log_URL, filename))
-
-# rename to YYYYMMDD
-for log_filename in pypydir.listdir('#pypy.log.*'):
-    rename_to = None
-    b = log_filename.basename
-    if '-' in b:
-        rename_to = log_filename.basename.replace('-', '')
-    elif len(b) == 19:
-        months= 'Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec'.split()
-        day   = b[10:12]
-        month = months.index(b[12:15]) + 1
-        year  = b[15:20]
-        rename_to = '#pypy.log.%04s%02d%02s' % (year, month, day)
-
-    if rename_to:
-        log_filename.rename(rename_to)
-        #print 'RENAMED', log_filename, 'TO', rename_to
-
-# print sorted list of filenames of daily logs
-print 'irc://irc.freenode.org/pypy'
-print 'date, messages, visitors'
-for log_filename in pypydir.listdir('#pypy.log.*'):
-    n_messages, visitors = 0, {}
-    f = str(log_filename)
-    for s in file(f):
-        if '<' in s and '>' in s:
-            n_messages += 1
-        elif ' joined #pypy' in s:
-            v = s.split()[1]
-            visitors[v] = True
-    print '%04s-%02s-%02s, %d, %d' % (f[-8:-4], f[-4:-2], f[-2:], n_messages, len(visitors.keys()))
+if __name__ == '__main__':
+    log_URL = 'http://tismerysoft.de/pypy/irc-logs/'
+    archive_FILENAME = 'pypy.tar.gz'
+
+    tempdir = py.test.ensuretemp("irc-log")
+
+    # get compressed archive
+    chdir( str(tempdir))
+    system('wget -q %s%s' % (log_URL, archive_FILENAME))
+    system('tar xzf %s'   % archive_FILENAME)
+    chdir('pypy')
+
+    # get more recent daily logs
+    pypydir = tempdir.join('pypy')
+    for line in urlopen(log_URL + 'pypy/').readlines():
+        i = line.find('%23pypy.log.')
+        if i == -1:
+            continue
+        filename = line[i:].split('"')[0]
+        system('wget -q %spypy/%s' % (log_URL, filename))
+
+    # rename to YYYYMMDD
+    for log_filename in pypydir.listdir('#pypy.log.*'):
+        rename_to = None
+        b = log_filename.basename
+        if '-' in b:
+            rename_to = log_filename.basename.replace('-', '')
+        elif len(b) == 19:
+            months= 'Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec'.split()
+            day   = b[10:12]
+            month = months.index(b[12:15]) + 1
+            year  = b[15:20]
+            rename_to = '#pypy.log.%04s%02d%02s' % (year, month, day)
+
+        if rename_to:
+            log_filename.rename(rename_to)
+            #print 'RENAMED', log_filename, 'TO', rename_to
+
+    # print sorted list of filenames of daily logs
+    print 'irc://irc.freenode.org/pypy'
+    print 'date, messages, visitors'
+    for log_filename in pypydir.listdir('#pypy.log.*'):
+        n_messages, visitors = 0, {}
+        f = str(log_filename)
+        for s in file(f):
+            if '<' in s and '>' in s:
+                n_messages += 1
+            elif ' joined #pypy' in s:
+                v = s.split()[1]
+                visitors[v] = True
+        print '%04s-%02s-%02s, %d, %d' % (f[-8:-4], f[-4:-2], f[-2:], n_messages, len(visitors.keys()))

Modified: pypy/branch/jit-unroll-loops/pypy/tool/watchdog.py
==============================================================================
--- pypy/branch/jit-unroll-loops/pypy/tool/watchdog.py	(original)
+++ pypy/branch/jit-unroll-loops/pypy/tool/watchdog.py	Fri Nov  5 15:32:14 2010
@@ -7,9 +7,6 @@
             return name
     return 'signal %d' % (n,)
 
-timeout = float(sys.argv[1])
-timedout = False
-
 def childkill():
     global timedout
     timedout = True
@@ -20,31 +17,35 @@
     except OSError:
         pass
 
-pid = os.fork()
-if pid == 0:
-    os.execvp(sys.argv[2], sys.argv[2:])
-else: # parent
-    t = threading.Timer(timeout, childkill)
-    t.start()
-    while True:
-        try:
-            pid, status = os.waitpid(pid, 0)
-        except KeyboardInterrupt:
-            continue
+if __name__ == '__main__':
+    timeout = float(sys.argv[1])
+    timedout = False
+
+    pid = os.fork()
+    if pid == 0:
+        os.execvp(sys.argv[2], sys.argv[2:])
+    else: # parent
+        t = threading.Timer(timeout, childkill)
+        t.start()
+        while True:
+            try:
+                pid, status = os.waitpid(pid, 0)
+            except KeyboardInterrupt:
+                continue
+            else:
+                t.cancel()
+                break
+        if os.WIFEXITED(status):
+            sys.exit(os.WEXITSTATUS(status))
         else:
-            t.cancel()
-            break
-    if os.WIFEXITED(status):
-        sys.exit(os.WEXITSTATUS(status))
-    else:
-        assert os.WIFSIGNALED(status)
-        sign = os.WTERMSIG(status)
-        if timedout and sign == signal.SIGTERM:
+            assert os.WIFSIGNALED(status)
+            sign = os.WTERMSIG(status)
+            if timedout and sign == signal.SIGTERM:
+                sys.exit(1)
+            signame = getsignalname(sign)
+            sys.stderr.write("="*26 + "timedout" + "="*26 + "\n")        
+            sys.stderr.write("="*25 + " %-08s " %  signame + "="*25 + "\n")
             sys.exit(1)
-        signame = getsignalname(sign)
-        sys.stderr.write("="*26 + "timedout" + "="*26 + "\n")        
-        sys.stderr.write("="*25 + " %-08s " %  signame + "="*25 + "\n")
-        sys.exit(1)
 
-    
-    
+
+

Modified: pypy/branch/jit-unroll-loops/pypy/tool/watchdog_nt.py
==============================================================================
--- pypy/branch/jit-unroll-loops/pypy/tool/watchdog_nt.py	(original)
+++ pypy/branch/jit-unroll-loops/pypy/tool/watchdog_nt.py	Fri Nov  5 15:32:14 2010
@@ -2,11 +2,6 @@
 import threading
 import ctypes
 
-PROCESS_TERMINATE = 0x1
-
-timeout = float(sys.argv[1])
-timedout = False
-
 def childkill(pid):
     global timedout
     timedout = True
@@ -14,19 +9,25 @@
     sys.stderr.write("="*26 + "timedout" + "="*26 + "\n")
     ctypes.windll.kernel32.TerminateProcess(pid, 1)
 
-pid = os.spawnv(os.P_NOWAIT, sys.argv[2], sys.argv[2:])
+if __name__ == '__main__':
+    PROCESS_TERMINATE = 0x1
+
+    timeout = float(sys.argv[1])
+    timedout = False
+
+    pid = os.spawnv(os.P_NOWAIT, sys.argv[2], sys.argv[2:])
+
+    t = threading.Timer(timeout, childkill, (pid,))
+    t.start()
+    while True:
+        try:
+            pid, status = os.waitpid(pid, 0)
+        except KeyboardInterrupt:
+            continue
+        else:
+            t.cancel()
+            break
+
+    #print 'status ', status >> 8
+    sys.exit(status >> 8)
 
-t = threading.Timer(timeout, childkill, (pid,))
-t.start()
-while True:
-    try:
-        pid, status = os.waitpid(pid, 0)
-    except KeyboardInterrupt:
-        continue
-    else:
-        t.cancel()
-        break
-
-#print 'status ', status >> 8
-sys.exit(status >> 8)
-    

Modified: pypy/branch/jit-unroll-loops/pypy/translator/c/genc.py
==============================================================================
--- pypy/branch/jit-unroll-loops/pypy/translator/c/genc.py	(original)
+++ pypy/branch/jit-unroll-loops/pypy/translator/c/genc.py	Fri Nov  5 15:32:14 2010
@@ -626,6 +626,7 @@
                         python + '$(PYPYDIR)/translator/c/gcc/trackgcroot.py -m$(PYPY_MAIN_FUNCTION) -t $< > $*.gcmap')
                 mk.rule('gcmaptable.s', '$(GCMAPFILES)',
                         python + '$(PYPYDIR)/translator/c/gcc/trackgcroot.py $(GCMAPFILES) > $@')
+                mk.rule('.PRECIOUS', '%.s', "# don't remove .s files if Ctrl-C'ed")
 
         else:
             mk.definition('DEBUGFLAGS', '-O1 -g')

Modified: pypy/branch/jit-unroll-loops/pypy/translator/c/src/g_include.h
==============================================================================
--- pypy/branch/jit-unroll-loops/pypy/translator/c/src/g_include.h	(original)
+++ pypy/branch/jit-unroll-loops/pypy/translator/c/src/g_include.h	Fri Nov  5 15:32:14 2010
@@ -39,9 +39,10 @@
 #include "src/instrument.h"
 
 /* optional assembler bits */
-#if defined(__GNUC__) && defined(__i386__)
-#  include "src/asm_gcc_x86.h"
-#endif
+// disabled: does not give any speed-up
+//#if defined(__GNUC__) && defined(__i386__)
+//#  include "src/asm_gcc_x86.h"
+//#endif
 
 #if defined(__GNUC__) && defined(__ppc__)
 #  include "src/asm_ppc.h"

Modified: pypy/branch/jit-unroll-loops/pypy/translator/c/src/int.h
==============================================================================
--- pypy/branch/jit-unroll-loops/pypy/translator/c/src/int.h	(original)
+++ pypy/branch/jit-unroll-loops/pypy/translator/c/src/int.h	Fri Nov  5 15:32:14 2010
@@ -2,40 +2,27 @@
 /************************************************************/
  /***  C header subsection: operations between ints        ***/
 
-#ifndef LLONG_MAX
-# if SIZEOF_LONG_LONG == 8
-#  define LLONG_MAX 0X7FFFFFFFFFFFFFFFLL
-# else
-#  error "fix LLONG_MAX"
-# endif
-#endif
-
-#ifndef LLONG_MIN
-# define LLONG_MIN (-LLONG_MAX-1)
-#endif
 
 /*** unary operations ***/
 
-#define OP_INT_IS_TRUE(x,r)   OP_INT_NE(x,0,r)
-
-#define OP_INT_INVERT(x,r)    r = ~((x))
-
-#define OP_INT_NEG(x,r)    r = -(x)
+#define OP_INT_IS_TRUE(x,r)   r = ((x) != 0)
+#define OP_INT_INVERT(x,r)    r = ~(x)
+#define OP_INT_NEG(x,r)       r = -(x)
 
 #define OP_INT_NEG_OVF(x,r) \
-    if ((x) == LONG_MIN) FAIL_OVF("integer negate"); \
+	if ((x) == LONG_MIN) FAIL_OVF("integer negate"); \
 	OP_INT_NEG(x,r)
 #define OP_LLONG_NEG_OVF(x,r) \
-    if ((x) == LLONG_MIN) FAIL_OVF("integer negate"); \
+	if ((x) == LLONG_MIN) FAIL_OVF("integer negate"); \
 	OP_LLONG_NEG(x,r)
 
 #define OP_INT_ABS(x,r)    r = (x) >= 0 ? x : -(x)
 
 #define OP_INT_ABS_OVF(x,r) \
-    if ((x) == LONG_MIN) FAIL_OVF("integer absolute"); \
+	if ((x) == LONG_MIN) FAIL_OVF("integer absolute"); \
 	OP_INT_ABS(x,r)
 #define OP_LLONG_ABS_OVF(x,r) \
-    if ((x) == LLONG_MIN) FAIL_OVF("integer absolute"); \
+	if ((x) == LLONG_MIN) FAIL_OVF("integer absolute"); \
 	OP_LLONG_ABS(x,r)
 
 /***  binary operations ***/
@@ -59,50 +46,46 @@
 
 #define OP_INT_ADD(x,y,r)     r = (x) + (y)
 
+/* cast to avoid undefined behaviour on overflow */
 #define OP_INT_ADD_OVF(x,y,r) \
-	OP_INT_ADD(x,y,r); \
-	if ((r^(x)) >= 0 || (r^(y)) >= 0); \
-	else FAIL_OVF("integer addition")
+        r = (long)((unsigned long)x + y); \
+        if ((r^x) < 0 && (r^y) < 0) FAIL_OVF("integer addition")
+
+#define OP_LLONG_ADD_OVF(x,y,r) \
+        r = (long long)((unsigned long long)x + y); \
+        if ((r^x) < 0 && (r^y) < 0) FAIL_OVF("integer addition")
 
 #define OP_INT_ADD_NONNEG_OVF(x,y,r)  /* y can be assumed >= 0 */ \
-    r = (long)((unsigned long)x + (unsigned long)y); \
-    if (r >= (x)); \
-    else FAIL_OVF("integer addition")
-/* Can a C compiler be too clever and think it can "prove" that
- * r >= x always holds above?  Yes.  Hence the casting. */
+        r = (long)((unsigned long)x + y); \
+        if ((r&~x) < 0) FAIL_OVF("integer addition")
 
 #define OP_INT_SUB(x,y,r)     r = (x) - (y)
 
 #define OP_INT_SUB_OVF(x,y,r) \
-	OP_INT_SUB(x,y,r); \
-	if ((r^(x)) >= 0 || (r^~(y)) >= 0); \
-	else FAIL_OVF("integer subtraction")
-
-#define OP_INT_MUL(x,y,r)     r = (x) * (y)
-
-#if defined(HAVE_LONG_LONG) && SIZE_OF_LONG_LONG < SIZE_OF_LONG
-#  define OP_INT_MUL_OVF_LL      1
-#lse
-#  define OP_INT_MUL_OVF_LL      0
-#endif
+        r = (long)((unsigned long)x - y); \
+        if ((r^x) < 0 && (r^~y) < 0) FAIL_OVF("integer subtraction")
 
-#if !OP_INT_MUL_OVF_LL
+#define OP_LLONG_SUB_OVF(x,y,r) \
+        r = (long long)((unsigned long long)x - y); \
+        if ((r^x) < 0 && (r^~y) < 0) FAIL_OVF("integer subtraction")
 
-#define OP_INT_MUL_OVF(x,y,r) \
-	if (op_int_mul_ovf(x,y,&r)); \
-	else FAIL_OVF("integer multiplication")
-
-#else
+#define OP_INT_MUL(x,y,r)     r = (x) * (y)
 
+#if SIZEOF_LONG * 2 <= SIZEOF_LONG_LONG
 #define OP_INT_MUL_OVF(x,y,r) \
 	{ \
-		PY_LONG_LONG lr = (PY_LONG_LONG)(x) * (PY_LONG_LONG)(y); \
-		r = (long)lr; \
-		if ((PY_LONG_LONG)r == lr); \
-		else FAIL_OVF("integer multiplication"); \
+		long long _lr = (long long)x * y; \
+		r = (long)_lr; \
+		if (_lr != (long long)r) FAIL_OVF("integer multiplication"); \
 	}
+#else
+#define OP_INT_MUL_OVF(x,y,r) \
+	r = op_llong_mul_ovf(x, y)   /* long == long long */
 #endif
 
+#define OP_LLONG_MUL_OVF(x,y,r) \
+	r = op_llong_mul_ovf(x, y)
+
 /* shifting */
 
 /* NB. shifting has same limitations as C: the shift count must be
@@ -121,6 +104,10 @@
 	OP_INT_LSHIFT(x,y,r); \
 	if ((x) != Py_ARITHMETIC_RIGHT_SHIFT(long, r, (y))) \
 		FAIL_OVF("x<<y losing bits or changing sign")
+#define OP_LLONG_LSHIFT_OVF(x,y,r) \
+	OP_LLONG_LSHIFT(x,y,r); \
+	if ((x) != Py_ARITHMETIC_RIGHT_SHIFT(PY_LONG_LONG, r, (y))) \
+		FAIL_OVF("x<<y losing bits or changing sign")
 
 /* floor division */
 
@@ -129,27 +116,48 @@
 #define OP_LLONG_FLOORDIV(x,y,r)  r = (x) / (y)
 #define OP_ULLONG_FLOORDIV(x,y,r) r = (x) / (y)
 
-#define OP_INT_FLOORDIV_OVF(x,y,r) \
-	if ((y) == -1 && (x) == LONG_MIN) \
-            { FAIL_OVF("integer division"); } \
-        else OP_INT_FLOORDIV(x,y,r)
-
-#define OP_INT_FLOORDIV_ZER(x,y,r) \
-	if ((y)) { OP_INT_FLOORDIV(x,y,r); } \
-	else FAIL_ZER("integer division")
-#define OP_UINT_FLOORDIV_ZER(x,y,r) \
-	if ((y)) { OP_UINT_FLOORDIV(x,y,r); } \
-	else FAIL_ZER("unsigned integer division")
-#define OP_LLONG_FLOORDIV_ZER(x,y,r) \
-	if ((y)) { OP_LLONG_FLOORDIV(x,y,r); } \
-	else FAIL_ZER("integer division")
-#define OP_ULLONG_FLOORDIV_ZER(x,y,r) \
-	if ((y)) { OP_ULLONG_FLOORDIV(x,y,r); } \
-	else FAIL_ZER("unsigned integer division")
-
-#define OP_INT_FLOORDIV_OVF_ZER(x,y,r) \
-	if ((y)) { OP_INT_FLOORDIV_OVF(x,y,r); } \
-	else FAIL_ZER("integer division")
+#define OP_INT_FLOORDIV_OVF(x,y,r)                      \
+	if ((y) == -1 && (x) == LONG_MIN)               \
+	    { FAIL_OVF("integer division"); r=0; }      \
+	else                                            \
+	    r = (x) / (y)
+#define OP_LLONG_FLOORDIV_OVF(x,y,r)                    \
+	if ((y) == -1 && (x) == LLONG_MIN)              \
+	    { FAIL_OVF("integer division"); r=0; }      \
+	else                                            \
+	    r = (x) / (y)
+
+#define OP_INT_FLOORDIV_ZER(x,y,r)                      \
+	if ((y) == 0)                                   \
+	    { FAIL_ZER("integer division"); r=0; }      \
+	else                                            \
+	    r = (x) / (y)
+#define OP_UINT_FLOORDIV_ZER(x,y,r)                             \
+	if ((y) == 0)                                           \
+	    { FAIL_ZER("unsigned integer division"); r=0; }     \
+	else                                                    \
+	    r = (x) / (y)
+#define OP_LLONG_FLOORDIV_ZER(x,y,r)                    \
+	if ((y) == 0)                                   \
+	    { FAIL_ZER("integer division"); r=0; }      \
+	else                                            \
+	    r = (x) / (y)
+#define OP_ULLONG_FLOORDIV_ZER(x,y,r)                           \
+	if ((y) == 0)                                           \
+	    { FAIL_ZER("unsigned integer division"); r=0; }     \
+	else                                                    \
+	    r = (x) / (y)
+
+#define OP_INT_FLOORDIV_OVF_ZER(x,y,r)                  \
+	if ((y) == 0)                                   \
+	    { FAIL_ZER("integer division"); r=0; }      \
+	else                                            \
+	    { OP_INT_FLOORDIV_OVF(x,y,r); }
+#define OP_LLONG_FLOORDIV_OVF_ZER(x,y,r)                \
+	if ((y) == 0)                                   \
+	    { FAIL_ZER("integer division"); r=0; }      \
+	else                                            \
+	    { OP_LLONG_FLOORDIV_OVF(x,y,r); }
 
 /* modulus */
 
@@ -158,27 +166,47 @@
 #define OP_LLONG_MOD(x,y,r)   r = (x) % (y)
 #define OP_ULLONG_MOD(x,y,r)  r = (x) % (y)
 
-#define OP_INT_MOD_OVF(x,y,r) \
-	if ((y) == -1 && (x) == LONG_MIN) \
-            { FAIL_OVF("integer modulo"); }\
-        else OP_INT_MOD(x,y,r)
-
-#define OP_INT_MOD_ZER(x,y,r) \
-	if ((y)) { OP_INT_MOD(x,y,r); } \
-	else FAIL_ZER("integer modulo")
-#define OP_UINT_MOD_ZER(x,y,r) \
-	if ((y)) { OP_UINT_MOD(x,y,r); } \
-	else FAIL_ZER("unsigned integer modulo")
-#define OP_LLONG_MOD_ZER(x,y,r) \
-	if ((y)) { OP_LLONG_MOD(x,y,r); } \
-	else FAIL_ZER("integer modulo")
-#define OP_ULLONG_MOD_ZER(x,y,r) \
-	if ((y)) { OP_ULLONG_MOD(x,y,r); } \
-	else FAIL_ZER("integer modulo")
-
-#define OP_INT_MOD_OVF_ZER(x,y,r) \
-	if ((y)) { OP_INT_MOD_OVF(x,y,r); } \
-	else FAIL_ZER("integer modulo")
+#define OP_INT_MOD_OVF(x,y,r)                           \
+	if ((y) == -1 && (x) == LONG_MIN)               \
+	    { FAIL_OVF("integer modulo"); r=0; }        \
+	else                                            \
+	    r = (x) % (y)
+#define OP_LLONG_MOD_OVF(x,y,r)                         \
+	if ((y) == -1 && (x) == LLONG_MIN)              \
+	    { FAIL_OVF("integer modulo"); r=0; }        \
+	else                                            \
+	    r = (x) % (y)
+#define OP_INT_MOD_ZER(x,y,r)                           \
+	if ((y) == 0)                                   \
+	    { FAIL_ZER("integer modulo"); r=0; }        \
+	else                                            \
+	    r = (x) % (y)
+#define OP_UINT_MOD_ZER(x,y,r)                                  \
+	if ((y) == 0)                                           \
+	    { FAIL_ZER("unsigned integer modulo"); r=0; }       \
+	else                                                    \
+	    r = (x) % (y)
+#define OP_LLONG_MOD_ZER(x,y,r)                         \
+	if ((y) == 0)                                   \
+	    { FAIL_ZER("integer modulo"); r=0; }        \
+	else                                            \
+	    r = (x) % (y)
+#define OP_ULLONG_MOD_ZER(x,y,r)                                \
+	if ((y) == 0)                                           \
+	    { FAIL_ZER("unsigned integer modulo"); r=0; }       \
+	else                                                    \
+	    r = (x) % (y)
+
+#define OP_INT_MOD_OVF_ZER(x,y,r)                       \
+	if ((y) == 0)                                   \
+	    { FAIL_ZER("integer modulo"); r=0; }        \
+	else                                            \
+	    { OP_INT_MOD_OVF(x,y,r); }
+#define OP_LLONG_MOD_OVF_ZER(x,y,r)                     \
+	if ((y) == 0)                                   \
+	    { FAIL_ZER("integer modulo"); r=0; }        \
+	else                                            \
+	    { OP_LLONG_MOD_OVF(x,y,r); }
 
 /* bit operations */
 
@@ -208,31 +236,30 @@
 
 /* _________________ certain implementations __________________ */
 
-#if !OP_INT_MUL_OVF_LL
 /* adjusted from intobject.c, Python 2.3.3 */
 
 /* prototypes */
 
-int op_int_mul_ovf(long a, long b, long *longprod);
+long long op_llong_mul_ovf(long long a, long long b);
 
 /* implementations */
 
 #ifndef PYPY_NOT_MAIN_FILE
 
-int
-op_int_mul_ovf(long a, long b, long *longprod)
+long long op_llong_mul_ovf(long long a, long long b)
 {
 	double doubled_longprod;	/* (double)longprod */
 	double doubleprod;		/* (double)a * (double)b */
+	long long longprod;
 
-	*longprod = a * b;
+	longprod = a * b;
 	doubleprod = (double)a * (double)b;
-	doubled_longprod = (double)*longprod;
+	doubled_longprod = (double)longprod;
 
 	/* Fast path for normal case:  small multiplicands, and no info
 	   is lost in either method. */
 	if (doubled_longprod == doubleprod)
-		return 1;
+		return longprod;
 
 	/* Somebody somewhere lost info.  Close enough, or way off?  Note
 	   that a != 0 and b != 0 (else doubled_longprod == doubleprod == 0).
@@ -247,15 +274,15 @@
 		/* absdiff/absprod <= 1/32 iff
 		   32 * absdiff <= absprod -- 5 good bits is "close enough" */
 		if (32.0 * absdiff <= absprod)
-			return 1;
-		return 0;
+			return longprod;
+
+		FAIL_OVF("integer multiplication");
+		return -1;
 	}
 }
 
 #endif /* PYPY_NOT_MAIN_FILE */
 
-#endif /* !OP_INT_MUL_OVF_LL */
-
 /* implementations */
 
 #define OP_UINT_IS_TRUE OP_INT_IS_TRUE



More information about the Pypy-commit mailing list