Author: Tim Felgentreff <timfelgentr...@gmail.com> Branch: stm-c4 Changeset: r768:01f187f7c32b Date: 2014-04-02 12:51 +0200 http://bitbucket.org/pypy/lang-smalltalk/changeset/01f187f7c32b/
Log: merge 64bit-c2 branch 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,17 +15,25 @@ that create W_PointersObjects of correct size with attached shadows. """ import sys, weakref -from spyvm import constants, error, version +from spyvm import constants, error, system, version from spyvm.version import elidable_for_version 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.rlib.debug import make_sure_not_resized from rpython.tool.pairtype import extendabletype from rpython.rlib.objectmodel import instantiate, compute_hash, import_from_mixin 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 @@ -170,7 +178,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) @@ -296,7 +304,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): @@ -398,11 +405,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 @@ -484,7 +491,7 @@ class W_AbstractPointersObject(W_AbstractObjectWithClassReference): """Common object.""" _attrs_ = ['shadow'] - + def changed(self): # This is invoked when an instance-variable is changed. # Kept here in case it might be usefull in the future. @@ -543,7 +550,7 @@ def _get_shadow(self): return self.shadow - + @objectmodel.specialize.arg(2) def attach_shadow_of_class(self, space, TheClass): shadow = TheClass(space, self) @@ -644,11 +651,11 @@ self.fieldtypes = fieldtypes_of_length(self.s_class, size) for i in range(size): # do it by hand for the JIT's sake vars[i] = w_nil - + def set_vars(self, new_vars): self._vars = new_vars make_sure_not_resized(self._vars) - + def fillin(self, space, g_self): W_AbstractPointersObject.fillin(self, space, g_self) from spyvm.fieldtypes import fieldtypes_of @@ -773,14 +780,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 @@ -913,20 +925,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) @@ -993,10 +1010,10 @@ 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'] pixelbuffer = None - + @staticmethod def create(space, w_class, size, depth, display): if depth < 8: @@ -1010,7 +1027,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 @@ -1021,7 +1038,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() @@ -1046,7 +1063,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 @@ -1080,13 +1097,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) | @@ -1099,7 +1116,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 @@ -1108,10 +1125,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, version +from spyvm import constants, model, shadow, wrapper, system, version 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): @@ -648,17 +652,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 @@ -873,6 +882,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 @@ -899,8 +917,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]) @@ -1075,7 +1092,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)) #____________________________________________________________________________ @@ -1119,7 +1136,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,7 +6,7 @@ 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 def _run_benchmark(interp, number, benchmark, arg, use_stm): @@ -223,7 +223,9 @@ def target(driver, *args): from rpython.rlib import rgc - driver.exe_name = 'rsqueak' + 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 _______________________________________________ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit