def test_object_alignment(self): # all objects returned by the GC should be properly aligned. from pypy.rpython.lltypesystem import rffi from pypy.rpython.tool import rffi_platform mylist = ['a', 'bc', '84139871', 'ajkdh', '876'] def f(): result = 0 buffer = "" for j in range(100): for s in mylist: buffer += s addr = rffi.cast(lltype.Signed, buffer) result |= addr return result fn = self.getcompiled(f) res = fn() expected_alignment = rffi_platform.memory_alignment() assert (res & (expected_alignment-1)) == 0
def repr_offset(self, value): if isinstance(value, llarena.RoundedUpForAllocation): # XXX not supported when used in a CompositeOffset from pypy.rpython.tool import rffi_platform align = rffi_platform.memory_alignment() r_basesize = self.repr_offset(value.basesize) # Note that the following expression is known to crash 'llc'; # you may need to upgrade llvm. return "and(i32 add(i32 %s, i32 %d), i32 %d)" % ( r_basesize, align-1, ~(align-1)) from_, indices, to = self.get_offset(value, []) if from_ is lltype.Void or not indices: return "0" assert to is not lltype.Void r = self.database.repr_type indices_as_str = ", ".join("%s %s" % (w, i) for w, i in indices) return "ptrtoint(%s* getelementptr(%s* null, %s) to i32)" % (r(to), r(from_), indices_as_str)
def test_object_alignment(self): res = self.run('object_alignment') from pypy.rpython.tool import rffi_platform expected_alignment = rffi_platform.memory_alignment() assert (res & (expected_alignment-1)) == 0
def test_memory_alignment(): a = rffi_platform.memory_alignment() print a assert a % struct.calcsize("P") == 0