[pypy-commit] lang-smalltalk 64bit-c2: graft changes from 64bit branch onto master

timfel noreply at buildbot.pypy.org
Fri Feb 7 13:12:41 CET 2014


Author: Tim Felgentreff <timfelgentreff at gmail.com>
Branch: 64bit-c2
Changeset: r599:8343cdb32ec6
Date: 2014-02-07 13:12 +0100
http://bitbucket.org/pypy/lang-smalltalk/changeset/8343cdb32ec6/

Log:	graft changes from 64bit branch onto master

diff --git a/spyvm/constants.py b/spyvm/constants.py
--- a/spyvm/constants.py
+++ b/spyvm/constants.py
@@ -144,7 +144,7 @@
     "timerSemaphore" : SO_TIMER_SEMAPHORE,
 }
 
-LONG_BIT = 32
+from rpython.rlib.rarithmetic import LONG_BIT
 TAGGED_MAXINT = 2 ** (LONG_BIT - 2) - 1
 TAGGED_MININT = -2 ** (LONG_BIT - 2)
 
diff --git a/spyvm/display.py b/spyvm/display.py
--- a/spyvm/display.py
+++ b/spyvm/display.py
@@ -1,4 +1,3 @@
-from rpython.rlib.rarithmetic import r_uint
 from rpython.rtyper.lltypesystem import lltype, rffi
 from rpython.rlib.runicode import unicode_encode_utf_8
 from rpython.rlib import jit
diff --git a/spyvm/model.py b/spyvm/model.py
--- a/spyvm/model.py
+++ b/spyvm/model.py
@@ -15,15 +15,23 @@
 that create W_PointersObjects of correct size with attached shadows.
 """
 import sys, weakref
-from spyvm import constants, error
+from spyvm import constants, error, system
 
 from rpython.rlib import rrandom, objectmodel, jit, signature
-from rpython.rlib.rarithmetic import intmask, r_uint, r_int
+from rpython.rlib.rarithmetic import intmask, r_uint32, r_uint, r_int
 from rpython.tool.pairtype import extendabletype
 from rpython.rlib.objectmodel import instantiate, compute_hash
 from rpython.rtyper.lltypesystem import lltype, rffi
 from rsdl import RSDL, RSDL_helper
 
+
+if system.IS_64BIT:
+    from rpython.rlib.rarithmetic import widen
+else:
+    def widen(x):
+        return x
+
+
 class W_Object(object):
     """Root of Squeak model, abstract."""
     _attrs_ = []    # no RPython-level instance variables allowed in W_Object
@@ -168,7 +176,7 @@
         return isinstance(self.value, int) and self.value < 0x8000
 
     def lshift(self, space, shift):
-        from rpython.rlib.rarithmetic import ovfcheck, intmask, r_uint
+        from rpython.rlib.rarithmetic import ovfcheck, intmask
         # shift > 0, therefore the highest bit of upperbound is not set,
         # i.e. upperbound is positive
         upperbound = intmask(r_uint(-1) >> shift)
@@ -294,7 +302,6 @@
         return space.wrap_int((self.value >> shift) & mask)
 
     def unwrap_uint(self, space):
-        from rpython.rlib.rarithmetic import r_uint
         return r_uint(self.value)
 
     def clone(self, space):
@@ -396,11 +403,11 @@
         from rpython.rlib.rstruct.ieee import float_pack
         r = float_pack(self.value, 8) # C double
         if n0 == 0:
-            return space.wrap_uint(r_uint(intmask(r >> 32)))
+            return space.wrap_uint(r_uint32(intmask(r >> 32)))
         else:
             # bounds-check for primitive access is done in the primitive
             assert n0 == 1
-            return space.wrap_uint(r_uint(intmask(r)))
+            return space.wrap_uint(r_uint32(intmask(r)))
 
     def store(self, space, n0, w_obj):
         from rpython.rlib.rstruct.ieee import float_unpack, float_pack
@@ -757,14 +764,19 @@
         byte0 = ord(self.getchar(byte_index0))
         byte1 = ord(self.getchar(byte_index0 + 1)) << 8
         if byte1 & 0x8000 != 0:
-            byte1 = intmask(r_uint(0xffff0000) | r_uint(byte1))
+            byte1 = intmask(widen(r_uint32(0xffff0000)) | widen(r_uint32(byte1)))
         return space.wrap_int(byte1 | byte0)
 
     def short_atput0(self, space, index0, w_value):
         from rpython.rlib.rarithmetic import int_between
         i_value = space.unwrap_int(w_value)
-        if not int_between(-0x8000, i_value, 0x8000):
-            raise error.PrimitiveFailedError
+        if constants.LONG_BIT == 64:
+            if (not int_between(0, i_value, 0x8000) and
+                not int_between(0, i_value ^ (0xffffffff), 0x8000)):
+                raise error.PrimitiveFailedError
+        else:
+            if not int_between(-0x8000, i_value, 0x8000):
+                raise error.PrimitiveFailedError
         byte_index0 = index0 * 2
         byte0 = i_value & 0xff
         byte1 = (i_value & 0xff00) >> 8
@@ -897,20 +909,25 @@
         else:
             short = (word >> 16) & 0xffff
         if short & 0x8000 != 0:
-            short = r_uint(0xffff0000) | r_uint(short)
+            short = widen(r_uint32(0xffff0000)) | short
         return space.wrap_int(intmask(short))
 
     def short_atput0(self, space, index0, w_value):
         from rpython.rlib.rarithmetic import int_between
         i_value = space.unwrap_int(w_value)
-        if not int_between(-0x8000, i_value, 0x8000):
-            raise error.PrimitiveFailedError
+        if constants.LONG_BIT == 64:
+            if (not int_between(0, i_value, 0x8000) and
+                not int_between(0, i_value ^ (0xffffffff), 0x8000)):
+                raise error.PrimitiveFailedError
+        else:
+            if not int_between(-0x8000, i_value, 0x8000):
+                raise error.PrimitiveFailedError
         word_index0 = index0 / 2
-        word = intmask(self.getword(word_index0))
+        word = intmask(r_uint32(self.getword(word_index0)))
         if index0 % 2 == 0:
-            word = intmask(r_uint(word) & r_uint(0xffff0000)) | (i_value & 0xffff)
+            word = intmask(widen(r_uint32(word)) & widen(r_uint32(0xffff0000))) | (i_value & 0xffff)
         else:
-            word = (i_value << 16) | (word & 0xffff)
+            word = intmask(r_uint32((i_value << 16) | (word & 0xffff)))
         value = r_uint(word)
         self.setword(word_index0, value)
 
@@ -977,7 +994,7 @@
 
 class W_DisplayBitmap(W_AbstractObjectWithClassReference):
     _attrs_ = ['pixelbuffer', '_realsize', '_real_depth_buffer', 'display', '_depth']
-    _immutable_fields_ = ['_realsize', 'display', '_depth']
+    _immutable_fields_ = ['_realsize', 'display', '_depth', '_real_depth_buffer']
 
     @staticmethod
     def create(space, w_class, size, depth, display):
@@ -992,7 +1009,7 @@
 
     def __init__(self, space, w_class, size, depth, display):
         W_AbstractObjectWithClassReference.__init__(self, space, w_class)
-        self._real_depth_buffer = lltype.malloc(rffi.CArray(rffi.UINT), size, flavor='raw')
+        self._real_depth_buffer = [r_uint(0)] * size
         self._realsize = size
         self.display = display
         self._depth = depth
@@ -1003,7 +1020,7 @@
 
     def atput0(self, space, index0, w_value):
         word = space.unwrap_uint(w_value)
-        self.setword(index0, word)
+        self.setword(index0, r_uint(word))
 
     def flush_to_screen(self):
         self.display.flip()
@@ -1028,7 +1045,7 @@
 
     def setword(self, n, word):
         self._real_depth_buffer[n] = word
-        self.display.get_pixelbuffer()[n] = word
+        self.display.get_pixelbuffer()[n] = r_uint32(word)
 
     def is_array_object(self):
         return True
@@ -1062,13 +1079,13 @@
             ((msb & mask) << 11)
         )
 
-        self.display.get_pixelbuffer()[n] = r_uint(lsb | (msb << 16))
+        self.display.get_pixelbuffer()[n] = r_uint32(lsb | (msb << 16))
 
 
 class W_8BitDisplayBitmap(W_DisplayBitmap):
     def setword(self, n, word):
         self._real_depth_buffer[n] = word
-        self.display.get_pixelbuffer()[n] = r_uint(
+        self.display.get_pixelbuffer()[n] = r_uint32(
             (word >> 24) |
             ((word >> 8) & 0x0000ff00) |
             ((word << 8) & 0x00ff0000) |
@@ -1081,7 +1098,7 @@
     @jit.unroll_safe
     def setword(self, n, word):
         self._real_depth_buffer[n] = word
-        word = r_uint(word)
+        nWord = r_uint(word)
         pos = self.compute_pos(n)
         assert self._depth <= 4
         rshift = 32 - self._depth
@@ -1090,10 +1107,10 @@
                 return
             mapword = r_uint(0)
             for i in xrange(4):
-                pixel = r_uint(word) >> rshift
+                pixel = r_uint(nWord) >> rshift
                 mapword |= (r_uint(pixel) << (i * 8))
-                word <<= self._depth
-            self.display.get_pixelbuffer()[pos] = mapword
+                nWord <<= self._depth
+            self.display.get_pixelbuffer()[pos] = r_uint32(mapword)
             pos += 1
 
     def compute_pos(self, n):
diff --git a/spyvm/objspace.py b/spyvm/objspace.py
--- a/spyvm/objspace.py
+++ b/spyvm/objspace.py
@@ -1,6 +1,6 @@
 import os
 
-from spyvm import constants, model, shadow, wrapper
+from spyvm import constants, model, shadow, wrapper, system
 from spyvm.error import UnwrappingError, WrappingError, PrimitiveFailedError
 from rpython.rlib import jit, rpath
 from rpython.rlib.objectmodel import instantiate, specialize
@@ -15,7 +15,7 @@
         self.make_bootstrap_objects()
 
     def find_executable(self, executable):
-        if os.sep in executable or (os.name == "nt" and ":" in executable):
+        if os.sep in executable or (system.IS_WINDOWS and ":" in executable):
             return executable
         path = os.environ.get("PATH")
         if path:
@@ -198,9 +198,8 @@
     # methods for wrapping and unwrapping stuff
 
     def wrap_int(self, val):
-        from spyvm import constants
-        assert isinstance(val, int)
-        # we don't do tagging
+        if not isinstance(val, int):
+            raise WrappingError
         return model.W_SmallInteger(val)
 
     def wrap_uint(self, val):
diff --git a/spyvm/plugins/bitblt.py b/spyvm/plugins/bitblt.py
--- a/spyvm/plugins/bitblt.py
+++ b/spyvm/plugins/bitblt.py
@@ -17,7 +17,7 @@
         raise PrimitiveFailedError("BitBlt primitive not called in BitBlt object!")
 
     # only allow combinationRules 0-41
-    combinationRule = interp.space.unwrap_positive_32bit_int(w_rcvr.fetch(interp.space, 3))
+    combinationRule = interp.space.unwrap_int(w_rcvr.fetch(interp.space, 3))
     if combinationRule > 41:
         raise PrimitiveFailedError("Missing combinationRule %d" % combinationRule)
 
diff --git a/spyvm/primitives.py b/spyvm/primitives.py
--- a/spyvm/primitives.py
+++ b/spyvm/primitives.py
@@ -5,7 +5,7 @@
 from spyvm import model, shadow
 from spyvm import constants, display
 from spyvm.error import PrimitiveFailedError, \
-    PrimitiveNotYetWrittenError
+    PrimitiveNotYetWrittenError, WrappingError
 from spyvm import wrapper
 
 from rpython.rlib import rarithmetic, rfloat, unroll, jit
@@ -296,9 +296,13 @@
 @expose_primitive(FLOAT_TRUNCATED, unwrap_spec=[float])
 def func(interp, s_frame, f):
     try:
-        return interp.space.wrap_int(rarithmetic.ovfcheck_float_to_int(f))
+        integer = rarithmetic.ovfcheck_float_to_int(f)
     except OverflowError:
         raise PrimitiveFailedError
+    try:
+        return interp.space.wrap_int(integer) # in 64bit VMs, this may fail
+    except WrappingError:
+        raise PrimitiveFailedError
 
 @expose_primitive(FLOAT_TIMES_TWO_POWER, unwrap_spec=[float, int])
 def func(interp, s_frame, rcvr, arg):
@@ -647,17 +651,22 @@
 def func(interp, s_frame, argcount, s_method):
     from spyvm.interpreter import Return
     w_rcvr = s_frame.peek(0)
-    try:
-        s_frame._sendSelfSelector(interp.image.w_simulateCopyBits, 0, interp)
-    except Return:
-        w_dest_form = w_rcvr.fetch(interp.space, 0)
-        w_display = interp.space.objtable['w_display']
-        if w_dest_form.is_same_object(w_display):
-            w_bitmap = w_display.fetch(interp.space, 0)
-            assert isinstance(w_bitmap, model.W_DisplayBitmap)
-            w_bitmap.flush_to_screen()
-        return w_rcvr
-    except shadow.MethodNotFound:
+    w_display = interp.space.objtable['w_display']
+    if interp.space.unwrap_int(w_display.fetch(interp.space, 3)) == 1:
+        try:
+            s_frame._sendSelfSelector(interp.image.w_simulateCopyBits, 0, interp)
+        except Return:
+            w_dest_form = w_rcvr.fetch(interp.space, 0)
+            if w_dest_form.is_same_object(w_display):
+                w_bitmap = w_display.fetch(interp.space, 0)
+                assert isinstance(w_bitmap, model.W_DisplayBitmap)
+                w_bitmap.flush_to_screen()
+            return w_rcvr
+        except shadow.MethodNotFound:
+            from spyvm.plugins.bitblt import BitBltPlugin
+            BitBltPlugin.call("primitiveCopyBits", interp, s_frame, argcount, s_method)
+            return w_rcvr
+    else:
         from spyvm.plugins.bitblt import BitBltPlugin
         BitBltPlugin.call("primitiveCopyBits", interp, s_frame, argcount, s_method)
         return w_rcvr
@@ -872,6 +881,15 @@
 
     w_rcvr.s_class = w_arg.s_class
 
+
+if constants.LONG_BIT == 32:
+    def callIProxy(signature, interp, s_frame, argcount, s_method):
+        from spyvm.interpreter_proxy import IProxy
+        return IProxy.call(signature, interp, s_frame, argcount, s_method)
+else:
+    def callIProxy(signature, interp, s_frame, argcount, s_method):
+        raise PrimitiveFailedError
+
 @expose_primitive(EXTERNAL_CALL, clean_stack=False, no_result=True, compiled_method=True)
 def func(interp, s_frame, argcount, s_method):
     space = interp.space
@@ -898,8 +916,7 @@
         from spyvm.plugins.vmdebugging import DebuggingPlugin
         return DebuggingPlugin.call(signature[1], interp, s_frame, argcount, s_method)
     else:
-        from spyvm.interpreter_proxy import IProxy
-        return IProxy.call(signature, interp, s_frame, argcount, s_method)
+        return callIProxy(signature, interp, s_frame, argcount, s_method)
     raise PrimitiveFailedError
 
 @expose_primitive(COMPILED_METHOD_FLUSH_CACHE, unwrap_spec=[object])
@@ -1074,7 +1091,7 @@
     sec_since_epoch = rarithmetic.r_uint(time.time())
     # XXX: overflow check necessary?
     sec_since_1901 = sec_since_epoch + secs_between_1901_and_1970
-    return interp.space.wrap_uint(sec_since_1901)
+    return interp.space.wrap_uint(rarithmetic.r_uint(sec_since_1901))
 
 
 #____________________________________________________________________________
@@ -1118,7 +1135,7 @@
             w_arg.setchar(i, chr(new_value))
     elif isinstance(w_arg, model.W_WordsObject) or isinstance(w_arg, model.W_DisplayBitmap):
         for i in xrange(w_arg.size()):
-            w_arg.setword(i, new_value)
+            w_arg.setword(i, rarithmetic.r_uint(new_value))
     else:
         raise PrimitiveFailedError
     return w_arg
diff --git a/spyvm/squeakimage.py b/spyvm/squeakimage.py
--- a/spyvm/squeakimage.py
+++ b/spyvm/squeakimage.py
@@ -383,12 +383,11 @@
         self.startup_time = time.time()
 
     def run_spy_hacks(self, space):
-        pass
-        # w_display = space.objtable["w_display"]
-        # if w_display is not None and w_display is not space.w_nil:
-        #     if space.unwrap_int(w_display.fetch(space, 3)) < 8:
-        #         # non-native indexed color depth not well supported
-        #         w_display.store(space, 3, space.wrap_int(8))
+        if constants.LONG_BIT == 64:
+            w_display = space.objtable["w_display"]
+            if w_display is not None and w_display is not space.w_nil:
+                if space.unwrap_int(w_display.fetch(space, 3)) < 32:
+                    w_display.store(space, 3, space.wrap_int(32))
 
     def find_symbol(self, space, reader, symbol):
         w_dnu = self.special(constants.SO_DOES_NOT_UNDERSTAND)
diff --git a/targetimageloadingsmalltalk.py b/targetimageloadingsmalltalk.py
--- a/targetimageloadingsmalltalk.py
+++ b/targetimageloadingsmalltalk.py
@@ -6,9 +6,8 @@
 from rpython.rlib import jit, rpath
 
 from spyvm import model, interpreter, squeakimage, objspace, wrapper,\
-    error, shadow
+    error, shadow, system
 from spyvm.tool.analyseimage import create_image
-from spyvm.interpreter_proxy import VirtualMachine
 
 
 def _run_benchmark(interp, number, benchmark, arg):
@@ -222,6 +221,9 @@
     # driver.config.translation.gc = "stmgc"
     # driver.config.translation.gcrootfinder = "stm"
     from rpython.rlib import rgc
+    driver.exe_name = "rsqueakvm"
+    if system.IS_64BIT:
+        driver.exe_name += "-64"
     if hasattr(rgc, "stm_is_enabled"):
         driver.config.translation.stm = True
         driver.config.translation.thread = True


More information about the pypy-commit mailing list