Author: Richard Plangger <planri...@gmail.com> Branch: s390x-backend Changeset: r81617:782f331d2e8b Date: 2016-01-08 09:09 +0100 http://bitbucket.org/pypy/pypy/changeset/782f331d2e8b/
Log: merged memop simplify (malloc_nursery_varsize updates) diff --git a/lib_pypy/cPickle.py b/lib_pypy/cPickle.py --- a/lib_pypy/cPickle.py +++ b/lib_pypy/cPickle.py @@ -167,7 +167,11 @@ try: key = ord(self.read(1)) while key != STOP: - self.dispatch[key](self) + try: + meth = self.dispatch[key] + except KeyError: + raise UnpicklingError("invalid load key, %r." % chr(key)) + meth(self) key = ord(self.read(1)) except TypeError: if self.read(1) == '': diff --git a/pypy/module/test_lib_pypy/test_cPickle.py b/pypy/module/test_lib_pypy/test_cPickle.py --- a/pypy/module/test_lib_pypy/test_cPickle.py +++ b/pypy/module/test_lib_pypy/test_cPickle.py @@ -5,3 +5,7 @@ def test_stack_underflow(): py.test.raises(cPickle.UnpicklingError, cPickle.loads, "a string") + +def test_bad_key(): + e = py.test.raises(cPickle.UnpicklingError, cPickle.loads, "v") + assert str(e.value) == "invalid load key, 'v'." diff --git a/rpython/jit/backend/llgraph/runner.py b/rpython/jit/backend/llgraph/runner.py --- a/rpython/jit/backend/llgraph/runner.py +++ b/rpython/jit/backend/llgraph/runner.py @@ -722,7 +722,8 @@ def bh_gc_load_indexed_f(self, struct, index, scale, base_ofs, bytes): if bytes != 8: raise Exception("gc_load_indexed_f is only for 'double'!") - return llop.gc_load_indexed(rffi.DOUBLE, struct, index, scale, base_ofs) + return llop.gc_load_indexed(longlong.FLOATSTORAGE, + struct, index, scale, base_ofs) def bh_increment_debug_counter(self, addr): p = rffi.cast(rffi.CArrayPtr(lltype.Signed), addr) diff --git a/rpython/jit/backend/llsupport/rewrite.py b/rpython/jit/backend/llsupport/rewrite.py --- a/rpython/jit/backend/llsupport/rewrite.py +++ b/rpython/jit/backend/llsupport/rewrite.py @@ -203,39 +203,48 @@ def transform_to_gc_load(self, op): NOT_SIGNED = 0 CINT_ZERO = ConstInt(0) - if op.is_getarrayitem() or \ - op.getopnum() in (rop.GETARRAYITEM_RAW_I, - rop.GETARRAYITEM_RAW_F): + opnum = op.getopnum() + if opnum == rop.CALL_MALLOC_NURSERY_VARSIZE: + v_length = op.getarg(2) + scale = op.getarg(1).getint() + if scale not in self.cpu.load_supported_factors: + scale, offset, v_length = \ + self._emit_mul_if_factor_offset_not_supported(v_length, scale, 0) + op.setarg(1, ConstInt(scale)) + op.setarg(2, v_length) + elif op.is_getarrayitem() or \ + opnum in (rop.GETARRAYITEM_RAW_I, + rop.GETARRAYITEM_RAW_F): self.handle_getarrayitem(op) - elif op.getopnum() in (rop.SETARRAYITEM_GC, rop.SETARRAYITEM_RAW): + elif opnum in (rop.SETARRAYITEM_GC, rop.SETARRAYITEM_RAW): self.handle_setarrayitem(op) - elif op.getopnum() == rop.RAW_STORE: + elif opnum == rop.RAW_STORE: itemsize, ofs, _ = unpack_arraydescr(op.getdescr()) ptr_box = op.getarg(0) index_box = op.getarg(1) value_box = op.getarg(2) self.emit_gc_store_or_indexed(op, ptr_box, index_box, value_box, itemsize, 1, ofs) - elif op.getopnum() in (rop.RAW_LOAD_I, rop.RAW_LOAD_F): + elif opnum in (rop.RAW_LOAD_I, rop.RAW_LOAD_F): itemsize, ofs, sign = unpack_arraydescr(op.getdescr()) ptr_box = op.getarg(0) index_box = op.getarg(1) self.emit_gc_load_or_indexed(op, ptr_box, index_box, itemsize, 1, ofs, sign) - elif op.getopnum() in (rop.GETINTERIORFIELD_GC_I, rop.GETINTERIORFIELD_GC_R, - rop.GETINTERIORFIELD_GC_F): + elif opnum in (rop.GETINTERIORFIELD_GC_I, rop.GETINTERIORFIELD_GC_R, + rop.GETINTERIORFIELD_GC_F): ofs, itemsize, fieldsize, sign = unpack_interiorfielddescr(op.getdescr()) ptr_box = op.getarg(0) index_box = op.getarg(1) self.emit_gc_load_or_indexed(op, ptr_box, index_box, fieldsize, itemsize, ofs, sign) - elif op.getopnum() in (rop.SETINTERIORFIELD_RAW, rop.SETINTERIORFIELD_GC): + elif opnum in (rop.SETINTERIORFIELD_RAW, rop.SETINTERIORFIELD_GC): ofs, itemsize, fieldsize, sign = unpack_interiorfielddescr(op.getdescr()) ptr_box = op.getarg(0) index_box = op.getarg(1) value_box = op.getarg(2) self.emit_gc_store_or_indexed(op, ptr_box, index_box, value_box, fieldsize, itemsize, ofs) - elif op.getopnum() in (rop.GETFIELD_GC_I, rop.GETFIELD_GC_F, rop.GETFIELD_GC_R, - rop.GETFIELD_GC_PURE_I, rop.GETFIELD_GC_PURE_F, rop.GETFIELD_GC_PURE_R, - rop.GETFIELD_RAW_I, rop.GETFIELD_RAW_F, rop.GETFIELD_RAW_R): + elif opnum in (rop.GETFIELD_GC_I, rop.GETFIELD_GC_F, rop.GETFIELD_GC_R, + rop.GETFIELD_GC_PURE_I, rop.GETFIELD_GC_PURE_F, rop.GETFIELD_GC_PURE_R, + rop.GETFIELD_RAW_I, rop.GETFIELD_RAW_F, rop.GETFIELD_RAW_R): ofs, itemsize, sign = unpack_fielddescr(op.getdescr()) ptr_box = op.getarg(0) if op.getopnum() in (rop.GETFIELD_GC_F, rop.GETFIELD_GC_I, rop.GETFIELD_GC_R): @@ -250,45 +259,45 @@ self.emit_op(op) return True self.emit_gc_load_or_indexed(op, ptr_box, ConstInt(0), itemsize, 1, ofs, sign) - elif op.getopnum() in (rop.SETFIELD_GC, rop.SETFIELD_RAW): + elif opnum in (rop.SETFIELD_GC, rop.SETFIELD_RAW): ofs, itemsize, sign = unpack_fielddescr(op.getdescr()) ptr_box = op.getarg(0) value_box = op.getarg(1) self.emit_gc_store_or_indexed(op, ptr_box, ConstInt(0), value_box, itemsize, 1, ofs) - elif op.getopnum() == rop.ARRAYLEN_GC: + elif opnum == rop.ARRAYLEN_GC: descr = op.getdescr() assert isinstance(descr, ArrayDescr) ofs = descr.lendescr.offset self.emit_gc_load_or_indexed(op, op.getarg(0), ConstInt(0), WORD, 1, ofs, NOT_SIGNED) - elif op.getopnum() == rop.STRLEN: + elif opnum == rop.STRLEN: basesize, itemsize, ofs_length = get_array_token(rstr.STR, self.cpu.translate_support_code) self.emit_gc_load_or_indexed(op, op.getarg(0), ConstInt(0), WORD, 1, ofs_length, NOT_SIGNED) - elif op.getopnum() == rop.UNICODELEN: + elif opnum == rop.UNICODELEN: basesize, itemsize, ofs_length = get_array_token(rstr.UNICODE, self.cpu.translate_support_code) self.emit_gc_load_or_indexed(op, op.getarg(0), ConstInt(0), WORD, 1, ofs_length, NOT_SIGNED) - elif op.getopnum() == rop.STRGETITEM: + elif opnum == rop.STRGETITEM: basesize, itemsize, ofs_length = get_array_token(rstr.STR, self.cpu.translate_support_code) assert itemsize == 1 self.emit_gc_load_or_indexed(op, op.getarg(0), op.getarg(1), itemsize, itemsize, basesize, NOT_SIGNED) - elif op.getopnum() == rop.UNICODEGETITEM: + elif opnum == rop.UNICODEGETITEM: basesize, itemsize, ofs_length = get_array_token(rstr.UNICODE, self.cpu.translate_support_code) self.emit_gc_load_or_indexed(op, op.getarg(0), op.getarg(1), itemsize, itemsize, basesize, NOT_SIGNED) - elif op.getopnum() == rop.STRSETITEM: + elif opnum == rop.STRSETITEM: basesize, itemsize, ofs_length = get_array_token(rstr.STR, self.cpu.translate_support_code) assert itemsize == 1 self.emit_gc_store_or_indexed(op, op.getarg(0), op.getarg(1), op.getarg(2), itemsize, itemsize, basesize) - elif op.getopnum() == rop.UNICODESETITEM: + elif opnum == rop.UNICODESETITEM: basesize, itemsize, ofs_length = get_array_token(rstr.UNICODE, self.cpu.translate_support_code) self.emit_gc_store_or_indexed(op, op.getarg(0), op.getarg(1), op.getarg(2), @@ -527,6 +536,7 @@ # replaced with another constant greater than 0.) #o = ResOperation(rop.ZERO_ARRAY, [v_arr, self.c_zero, v_length], # descr=arraydescr) + assert isinstance(arraydescr, ArrayDescr) scale = arraydescr.itemsize v_length_scaled = v_length if not isinstance(v_length, ConstInt): @@ -655,6 +665,7 @@ for op in self.last_zero_arrays: assert op.getopnum() == rop.ZERO_ARRAY descr = op.getdescr() + assert isinstance(descr, ArrayDescr) scale = descr.itemsize box = op.getarg(0) try: @@ -785,8 +796,12 @@ arraydescr.lendescr.offset != gc_descr.standard_array_length_ofs)): return False self.emitting_an_operation_that_can_collect() + scale = itemsize + if scale not in self.cpu.load_supported_factors: + scale, offset, v_length = \ + self._emit_mul_if_factor_offset_not_supported(v_length, scale, 0) op = ResOperation(rop.CALL_MALLOC_NURSERY_VARSIZE, - [ConstInt(kind), ConstInt(itemsize), v_length], + [ConstInt(kind), ConstInt(scale), v_length], descr=arraydescr) self.replace_op_with(v_result, op) self.emit_op(op) diff --git a/rpython/jit/backend/llsupport/test/test_gc_integration.py b/rpython/jit/backend/llsupport/test/test_gc_integration.py --- a/rpython/jit/backend/llsupport/test/test_gc_integration.py +++ b/rpython/jit/backend/llsupport/test/test_gc_integration.py @@ -315,7 +315,7 @@ 'strdescr': arraydescr}) # check the returned pointers gc_ll_descr = self.cpu.gc_ll_descr - assert gc_ll_descr.calls == [(8, 15, 10), (5, 15, 3), ('str', 3)] + assert gc_ll_descr.calls == [(8, 15, 10), (1, 15, 15), ('str', 15)] # one fit, one was too large, one was not fitting def test_malloc_slowpath(self): diff --git a/rpython/jit/backend/x86/assembler.py b/rpython/jit/backend/x86/assembler.py --- a/rpython/jit/backend/x86/assembler.py +++ b/rpython/jit/backend/x86/assembler.py @@ -1502,32 +1502,6 @@ genop_gc_load_indexed_r = _genop_gc_load_indexed genop_gc_load_indexed_f = _genop_gc_load_indexed - def _imul_const_scaled(self, mc, targetreg, sourcereg, itemsize): - """Produce one operation to do roughly - targetreg = sourcereg * itemsize - except that the targetreg may still need shifting by 0,1,2,3. - """ - if (itemsize & 7) == 0: - shift = 3 - elif (itemsize & 3) == 0: - shift = 2 - elif (itemsize & 1) == 0: - shift = 1 - else: - shift = 0 - itemsize >>= shift - # - if valid_addressing_size(itemsize - 1): - mc.LEA_ra(targetreg, (sourcereg, sourcereg, - get_scale(itemsize - 1), 0)) - elif valid_addressing_size(itemsize): - mc.LEA_ra(targetreg, (rx86.NO_BASE_REGISTER, sourcereg, - get_scale(itemsize), 0)) - else: - mc.IMUL_rri(targetreg, sourcereg, itemsize) - # - return shift - def genop_discard_increment_debug_counter(self, op, arglocs): # The argument should be an immediate address. This should # generate code equivalent to a GETFIELD_RAW, an ADD(1), and a @@ -2354,12 +2328,8 @@ jmp_adr0 = self.mc.get_relative_pos() self.mc.MOV(eax, heap(nursery_free_adr)) - if valid_addressing_size(itemsize): - shift = get_scale(itemsize) - else: - shift = self._imul_const_scaled(self.mc, edi.value, - varsizeloc.value, itemsize) - varsizeloc = edi + assert valid_addressing_size(itemsize) + shift = get_scale(itemsize) # now varsizeloc is a register != eax. The size of # the variable part of the array is (varsizeloc << shift) diff --git a/rpython/jit/backend/x86/regalloc.py b/rpython/jit/backend/x86/regalloc.py --- a/rpython/jit/backend/x86/regalloc.py +++ b/rpython/jit/backend/x86/regalloc.py @@ -1009,7 +1009,7 @@ self.rm.possibly_free_var(length_box) # itemsize = op.getarg(1).getint() - maxlength = (gc_ll_descr.max_size_of_young_obj - WORD * 2) / itemsize + maxlength = (gc_ll_descr.max_size_of_young_obj - WORD * 2) self.assembler.malloc_cond_varsize( op.getarg(0).getint(), gc_ll_descr.get_nursery_free_addr(), diff --git a/rpython/jit/metainterp/executor.py b/rpython/jit/metainterp/executor.py --- a/rpython/jit/metainterp/executor.py +++ b/rpython/jit/metainterp/executor.py @@ -399,9 +399,7 @@ rop.GC_LOAD_I, rop.GC_LOAD_R, rop.GC_LOAD_F, - rop.GC_LOAD_INDEXED_I, rop.GC_LOAD_INDEXED_R, - rop.GC_LOAD_INDEXED_F, rop.GC_STORE, rop.GC_STORE_INDEXED, ): # list of opcodes never executed by pyjitpl _______________________________________________ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit