Author: Armin Rigo <ar...@tunes.org> Branch: inline-dict-ops Changeset: r48306:c9296c708287 Date: 2011-10-21 14:08 +0200 http://bitbucket.org/pypy/pypy/changeset/c9296c708287/
Log: Sign in getinteriorfield_gc, test and fix (at least for llsupport). diff --git a/pypy/jit/backend/llsupport/llmodel.py b/pypy/jit/backend/llsupport/llmodel.py --- a/pypy/jit/backend/llsupport/llmodel.py +++ b/pypy/jit/backend/llsupport/llmodel.py @@ -361,15 +361,20 @@ ofs, size, _ = self.unpack_arraydescr_size(arraydescr) ofs += descr.fielddescr.offset fieldsize = descr.fielddescr.get_field_size(self.translate_support_code) + sign = descr.fielddescr.is_field_signed() fullofs = itemindex * size + ofs # --- start of GC unsafe code (no GC operation!) --- items = rffi.ptradd(rffi.cast(rffi.CCHARP, gcref), fullofs) for STYPE, UTYPE, itemsize in unroll_basic_sizes: if fieldsize == itemsize: - # XXX signedness - item = rffi.cast(rffi.CArrayPtr(STYPE), items) - val = item[0] - val = rffi.cast(lltype.Signed, val) + if sign: + item = rffi.cast(rffi.CArrayPtr(STYPE), items) + val = item[0] + val = rffi.cast(lltype.Signed, val) + else: + item = rffi.cast(rffi.CArrayPtr(UTYPE), items) + val = item[0] + val = rffi.cast(lltype.Signed, val) # --- end of GC unsafe code --- return val else: diff --git a/pypy/jit/backend/test/runner_test.py b/pypy/jit/backend/test/runner_test.py --- a/pypy/jit/backend/test/runner_test.py +++ b/pypy/jit/backend/test/runner_test.py @@ -882,13 +882,20 @@ def test_array_of_structs(self): TP = lltype.GcStruct('x') - ITEM = lltype.Struct('x', ('v', lltype.Signed), + ITEM = lltype.Struct('x', + ('vs', lltype.Signed), + ('vu', lltype.Unsigned), + ('vsc', rffi.SIGNEDCHAR), + ('vuc', rffi.UCHAR), + ('vss', rffi.SHORT), + ('vus', rffi.USHORT), + ('vsi', rffi.INT), + ('vui', rffi.UINT), ('k', lltype.Float), ('p', lltype.Ptr(TP))) a_box, A = self.alloc_array_of(ITEM, 15) s_box, S = self.alloc_instance(TP) kdescr = self.cpu.interiorfielddescrof(A, 'k') - vdescr = self.cpu.interiorfielddescrof(A, 'v') pdescr = self.cpu.interiorfielddescrof(A, 'p') self.execute_operation(rop.SETINTERIORFIELD_GC, [a_box, BoxInt(3), boxfloat(1.5)], @@ -899,15 +906,36 @@ r = self.execute_operation(rop.GETINTERIORFIELD_GC, [a_box, BoxInt(3)], 'float', descr=kdescr) assert r.getfloat() == 2.5 - self.execute_operation(rop.SETINTERIORFIELD_GC, [a_box, BoxInt(3), - BoxInt(15)], - 'void', descr=vdescr) - i = self.cpu.bh_getinteriorfield_gc_i(a_box.getref_base(), 3, vdescr) - assert i == 15 - self.cpu.bh_setinteriorfield_gc_i(a_box.getref_base(), 3, vdescr, 25) - r = self.execute_operation(rop.GETINTERIORFIELD_GC, [a_box, BoxInt(3)], - 'int', descr=vdescr) - assert r.getint() == 25 + # + NUMBER_FIELDS = [('vs', lltype.Signed), + ('vu', lltype.Unsigned), + ('vsc', rffi.SIGNEDCHAR), + ('vuc', rffi.UCHAR), + ('vss', rffi.SHORT), + ('vus', rffi.USHORT), + ('vsi', rffi.INT), + ('vui', rffi.UINT)] + for name, TYPE in NUMBER_FIELDS[::-1]: + vdescr = self.cpu.interiorfielddescrof(A, name) + self.execute_operation(rop.SETINTERIORFIELD_GC, [a_box, BoxInt(3), + BoxInt(-15)], + 'void', descr=vdescr) + for name, TYPE in NUMBER_FIELDS: + vdescr = self.cpu.interiorfielddescrof(A, name) + i = self.cpu.bh_getinteriorfield_gc_i(a_box.getref_base(), 3, + vdescr) + assert i == rffi.cast(lltype.Signed, rffi.cast(TYPE, -15)) + for name, TYPE in NUMBER_FIELDS[::-1]: + vdescr = self.cpu.interiorfielddescrof(A, name) + self.cpu.bh_setinteriorfield_gc_i(a_box.getref_base(), 3, + vdescr, -25) + for name, TYPE in NUMBER_FIELDS: + vdescr = self.cpu.interiorfielddescrof(A, name) + r = self.execute_operation(rop.GETINTERIORFIELD_GC, + [a_box, BoxInt(3)], + 'int', descr=vdescr) + assert r.getint() == rffi.cast(lltype.Signed, rffi.cast(TYPE, -25)) + # self.execute_operation(rop.SETINTERIORFIELD_GC, [a_box, BoxInt(4), s_box], 'void', descr=pdescr) _______________________________________________ pypy-commit mailing list pypy-commit@python.org http://mail.python.org/mailman/listinfo/pypy-commit