[pypy-svn] r68265 - in pypy/branch/gc-compress/pypy: rpython/lltypesystem rpython/memory translator/c translator/c/src translator/c/test
arigo at codespeak.net
arigo at codespeak.net
Fri Oct 9 11:38:10 CEST 2009
Author: arigo
Date: Fri Oct 9 11:38:09 2009
New Revision: 68265
Modified:
pypy/branch/gc-compress/pypy/rpython/lltypesystem/llarena.py
pypy/branch/gc-compress/pypy/rpython/memory/lltypelayout.py
pypy/branch/gc-compress/pypy/translator/c/primitive.py
pypy/branch/gc-compress/pypy/translator/c/src/mem.h
pypy/branch/gc-compress/pypy/translator/c/test/test_lltyped.py
Log:
Enhance round_up_for_allocation() to take a second parameter,
which is a constant giving a minimum size.
Modified: pypy/branch/gc-compress/pypy/rpython/lltypesystem/llarena.py
==============================================================================
--- pypy/branch/gc-compress/pypy/rpython/lltypesystem/llarena.py (original)
+++ pypy/branch/gc-compress/pypy/rpython/lltypesystem/llarena.py Fri Oct 9 11:38:09 2009
@@ -240,12 +240,15 @@
"""A size that is rounded up in order to preserve alignment of objects
following it. For arenas containing heterogenous objects.
"""
- def __init__(self, basesize):
+ def __init__(self, basesize, minsize):
assert isinstance(basesize, llmemory.AddressOffset)
+ assert isinstance(minsize, llmemory.AddressOffset) or minsize == 0
self.basesize = basesize
+ self.minsize = minsize
def __repr__(self):
- return '< RoundedUpForAllocation %r >' % (self.basesize,)
+ return '< RoundedUpForAllocation %r %r >' % (self.basesize,
+ self.minsize)
def known_nonneg(self):
return self.basesize.known_nonneg()
@@ -299,10 +302,14 @@
% (addr.offset,))
addr.arena.allocate_object(addr.offset, size)
-def round_up_for_allocation(size):
+def round_up_for_allocation(size, minsize=0):
"""Round up the size in order to preserve alignment of objects
- following an object. For arenas containing heterogenous objects."""
- return RoundedUpForAllocation(size)
+ following an object. For arenas containing heterogenous objects.
+ If minsize is specified, it gives a minimum on the resulting size."""
+ return _round_up_for_allocation(size, minsize)
+
+def _round_up_for_allocation(size, minsize): # internal
+ return RoundedUpForAllocation(size, minsize)
def arena_new_view(ptr):
"""Return a fresh memory view on an arena
@@ -401,10 +408,11 @@
sandboxsafe=True)
llimpl_round_up_for_allocation = rffi.llexternal('ROUND_UP_FOR_ALLOCATION',
- [lltype.Signed], lltype.Signed,
+ [lltype.Signed, lltype.Signed],
+ lltype.Signed,
sandboxsafe=True,
_nowrapper=True)
-register_external(round_up_for_allocation, [int], int,
+register_external(_round_up_for_allocation, [int, int], int,
'll_arena.round_up_for_allocation',
llimpl=llimpl_round_up_for_allocation,
llfakeimpl=round_up_for_allocation,
Modified: pypy/branch/gc-compress/pypy/rpython/memory/lltypelayout.py
==============================================================================
--- pypy/branch/gc-compress/pypy/rpython/memory/lltypelayout.py (original)
+++ pypy/branch/gc-compress/pypy/rpython/memory/lltypelayout.py Fri Oct 9 11:38:09 2009
@@ -118,6 +118,10 @@
return 0
elif isinstance(offset, llarena.RoundedUpForAllocation):
basesize = convert_offset_to_int(offset.basesize)
+ if isinstance(offset.minsize, llmemory.AddressOffset):
+ minsize = convert_offset_to_int(offset.minsize)
+ if minsize > basesize:
+ basesize = minsize
mask = memory_alignment - 1
return (basesize + mask) & ~ mask
else:
Modified: pypy/branch/gc-compress/pypy/translator/c/primitive.py
==============================================================================
--- pypy/branch/gc-compress/pypy/translator/c/primitive.py (original)
+++ pypy/branch/gc-compress/pypy/translator/c/primitive.py Fri Oct 9 11:38:09 2009
@@ -50,8 +50,9 @@
elif type(value) == GCHeaderOffset:
return '0'
elif type(value) == RoundedUpForAllocation:
- return 'ROUND_UP_FOR_ALLOCATION(%s)' % (
- name_signed(value.basesize, db))
+ return 'ROUND_UP_FOR_ALLOCATION(%s, %s)' % (
+ name_signed(value.basesize, db),
+ name_signed(value.minsize, db))
elif isinstance(value, CDefinedIntSymbolic):
return str(value.expr)
elif isinstance(value, ComputedIntSymbolic):
Modified: pypy/branch/gc-compress/pypy/translator/c/src/mem.h
==============================================================================
--- pypy/branch/gc-compress/pypy/translator/c/src/mem.h (original)
+++ pypy/branch/gc-compress/pypy/translator/c/src/mem.h Fri Oct 9 11:38:09 2009
@@ -14,8 +14,9 @@
struct rpy_memory_alignment_test1 s;
};
#define MEMORY_ALIGNMENT offsetof(struct rpy_memory_alignment_test2, s)
-#define ROUND_UP_FOR_ALLOCATION(x) \
- (((x) + (MEMORY_ALIGNMENT-1)) & ~(MEMORY_ALIGNMENT-1))
+#define ROUND_UP_FOR_ALLOCATION(x, minsize) \
+ ((((x)>=(minsize)?(x):(minsize)) \
+ + (MEMORY_ALIGNMENT-1)) & ~(MEMORY_ALIGNMENT-1))
extern char __gcmapstart;
extern char __gcmapend;
Modified: pypy/branch/gc-compress/pypy/translator/c/test/test_lltyped.py
==============================================================================
--- pypy/branch/gc-compress/pypy/translator/c/test/test_lltyped.py (original)
+++ pypy/branch/gc-compress/pypy/translator/c/test/test_lltyped.py Fri Oct 9 11:38:09 2009
@@ -741,3 +741,34 @@
fn = self.getcompiled(f, [int])
res = fn(-1)
assert res == 5
+
+ def test_round_up_for_allocation(self):
+ from pypy.rpython.lltypesystem import llmemory, llarena
+ S = Struct('S', ('x', Char), ('y', Char))
+ M = Struct('M', ('x', Char), ('y', Signed))
+ #
+ def g():
+ ssize = llarena.round_up_for_allocation(llmemory.sizeof(S))
+ msize = llarena.round_up_for_allocation(llmemory.sizeof(M))
+ smsize = llarena.round_up_for_allocation(llmemory.sizeof(S),
+ llmemory.sizeof(M))
+ mssize = llarena.round_up_for_allocation(llmemory.sizeof(M),
+ llmemory.sizeof(S))
+ return ssize, msize, smsize, mssize
+ #
+ glob_sizes = g()
+ #
+ def check((ssize, msize, smsize, mssize)):
+ assert ssize == llmemory.sizeof(Signed)
+ assert msize == llmemory.sizeof(Signed) * 2
+ assert smsize == msize
+ assert mssize == msize
+ #
+ def f():
+ check(glob_sizes)
+ check(g())
+ return 42
+ #
+ fn = self.getcompiled(f, [])
+ res = fn()
+ assert res == 42
More information about the Pypy-commit
mailing list