[pypy-commit] pypy default: Kill align.h and its ROUND_UP_FOR_ALLOCATION. Do the computation directly instead. This shouldn't impact performance, but I'll run the benchmarks to verify.

Manuel Jacob noreply at buildbot.pypy.org
Sat Jan 25 20:03:52 CET 2014


Author: Manuel Jacob
Branch: 
Changeset: r68939:708f486843e2
Date: 2014-01-25 19:47 +0100
http://bitbucket.org/pypy/pypy/changeset/708f486843e2/

Log:	Kill align.h and its ROUND_UP_FOR_ALLOCATION. Do the computation
	directly instead. This shouldn't impact performance, but I'll run
	the benchmarks to verify.

diff --git a/rpython/rtyper/lltypesystem/llarena.py b/rpython/rtyper/lltypesystem/llarena.py
--- a/rpython/rtyper/lltypesystem/llarena.py
+++ b/rpython/rtyper/lltypesystem/llarena.py
@@ -405,8 +405,11 @@
 import os, sys
 from rpython.rtyper.lltypesystem import rffi, lltype
 from rpython.rtyper.extfunc import register_external
+from rpython.rtyper.tool.rffi_platform import memory_alignment
 from rpython.rlib.objectmodel import CDefinedIntSymbolic
 
+MEMORY_ALIGNMENT = memory_alignment()
+
 if sys.platform.startswith('linux'):
     # This only works with linux's madvise(), which is really not a memory
     # usage hint but a real command.  It guarantees that after MADV_DONTNEED
@@ -597,11 +600,8 @@
                   llfakeimpl=arena_shrink_obj,
                   sandboxsafe=True)
 
-llimpl_round_up_for_allocation = rffi.llexternal('ROUND_UP_FOR_ALLOCATION',
-                                                [lltype.Signed, lltype.Signed],
-                                                 lltype.Signed,
-                                                 sandboxsafe=True,
-                                                 _nowrapper=True)
+def llimpl_round_up_for_allocation(size, minsize):
+    return (max(size, minsize) + (MEMORY_ALIGNMENT-1)) & ~(MEMORY_ALIGNMENT-1)
 register_external(_round_up_for_allocation, [int, int], int,
                   'll_arena.round_up_for_allocation',
                   llimpl=llimpl_round_up_for_allocation,
diff --git a/rpython/translator/c/primitive.py b/rpython/translator/c/primitive.py
--- a/rpython/translator/c/primitive.py
+++ b/rpython/translator/c/primitive.py
@@ -11,10 +11,12 @@
     UnsignedLongLong, Float, SingleFloat, LongFloat, Char, UniChar, Bool, Void,
     FixedSizeArray, Ptr, cast_opaque_ptr, typeOf)
 from rpython.rtyper.lltypesystem.llarena import RoundedUpForAllocation
+from rpython.rtyper.tool.rffi_platform import memory_alignment
 from rpython.translator.c.support import cdecl, barebonearray
 
 
 SUPPORT_INT128 = hasattr(rffi, '__INT128_T')
+MEMORY_ALIGNMENT = memory_alignment()
 
 # ____________________________________________________________
 #
@@ -69,9 +71,12 @@
         elif type(value) == GCHeaderOffset:
             return '0'
         elif type(value) == RoundedUpForAllocation:
-            return 'ROUND_UP_FOR_ALLOCATION(%s, %s)' % (
-                name_signed(value.basesize, db),
-                name_signed(value.minsize, db))
+            return ('(((%(x)s>=%(minsize)s?%(x)s:%(minsize)s) + %(align_m1)s)'
+                    ' & ~%(align_m1)s)') % {
+                'x': name_signed(value.basesize, db),
+                'minsize': name_signed(value.minsize, db),
+                'align_m1': MEMORY_ALIGNMENT-1
+            }
         elif isinstance(value, CDefinedIntSymbolic):
             return str(value.expr)
         elif isinstance(value, ComputedIntSymbolic):
diff --git a/rpython/translator/c/src/align.h b/rpython/translator/c/src/align.h
deleted file mode 100644
--- a/rpython/translator/c/src/align.h
+++ /dev/null
@@ -1,21 +0,0 @@
-
-#ifndef _PYPY_ALIGN_H
-#define _PYPY_ALIGN_H
-
-/* alignment for arena-based garbage collectors: the following line
-   enforces an alignment that should be enough for any structure
-   containing pointers and 'double' fields. */
-struct rpy_memory_alignment_test1 {
-  double d;
-  void* p;
-};
-struct rpy_memory_alignment_test2 {
-  char c;
-  struct rpy_memory_alignment_test1 s;
-};
-#define MEMORY_ALIGNMENT	offsetof(struct rpy_memory_alignment_test2, s)
-#define ROUND_UP_FOR_ALLOCATION(x, minsize)  \
-  ((((x)>=(minsize)?(x):(minsize))           \
-               + (MEMORY_ALIGNMENT-1)) & ~(MEMORY_ALIGNMENT-1))
-
-#endif //_PYPY_ALIGN_H
diff --git a/rpython/translator/c/src/g_prerequisite.h b/rpython/translator/c/src/g_prerequisite.h
--- a/rpython/translator/c/src/g_prerequisite.h
+++ b/rpython/translator/c/src/g_prerequisite.h
@@ -23,6 +23,3 @@
 # define RPY_LENGTH0     1       /* array decl [0] are bad */
 # define RPY_DUMMY_VARLENGTH     /* nothing */
 #endif
-
-
-#include "src/align.h"


More information about the pypy-commit mailing list