This is the mail archive of the libc-alpha@sourceware.org mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

inline _int_free into free


Hi,

The purpose of this patch is to inline the call to _int_free in public_fREe, but
not (necessarily) the other calls to _int_free.

this patch improves performance for the sip parser benchmark with 2 to 3.5% for
n32 and o32 on for the xlp processor, while increasing code size of malloc.o
with 1512 bytes.

I tested the patch on MIPS qemu (mips-linux-gnu) with host i686-pc-linux-gnu.
On that target, code size of malloc.o increased with 1976 bytes.

Thanks,
- Tom

2012-01-29  Tom de Vries  <tom@codesourcery.com>

	* malloc/malloc.c (DECLARE_INLINE_VERSION, COMMA, INLINE_VERSION): New
	macro.
	(_int_free): Declare using DECLARE_INLINE_VERSION. Define using
	INLINE_VERSION.
	(public_fREe): Call _inline__int_free rather than _int_free.

diff --git a/malloc/malloc.c b/malloc/malloc.c
index 300e879..4d6d77a 100644
--- a/malloc/malloc.c
+++ b/malloc/malloc.c
@@ -1138,8 +1138,37 @@ typedef struct malloc_chunk* mchunkptr;
 
 /* Internal routines.  */
 
+#define DECLARE_INLINE_VERSION(return, name, params) \
+  return name (params);   \
+  return _inline_ ## name (params);   \
+
+#ifdef COMMA
+#error COMMA already defined
+#else
+#define COMMA ,
+#endif
+
+#ifdef __OPTIMIZE_SIZE__
+#define INLINE_VERSION(return, name, params, args) \
+  return name (params);   \
+  return _inline_ ## name (params)   \
+  {   \
+  name (args);   \
+  }   \
+  return name (params)
+#else
+#define INLINE_VERSION(return, name, params, args) \
+  return _inline_ ##  name (params);   \
+  return name (params)   \
+  {   \
+  _inline_## name (args);   \
+  }   \
+  __attribute__((always_inline)) return _inline_ ##  name (params)
+#endif
+
 static void*  _int_malloc(mstate, size_t);
-static void     _int_free(mstate, mchunkptr, int);
+DECLARE_INLINE_VERSION (static void, _int_free,
+			mstate COMMA mchunkptr COMMA int);
 static void*  _int_realloc(mstate, mchunkptr, INTERNAL_SIZE_T,
 			     INTERNAL_SIZE_T);
 static void*  _int_memalign(mstate, size_t, size_t);
@@ -2980,7 +3009,7 @@ public_fREe(void* mem)
   }
 
   ar_ptr = arena_for_chunk(p);
-  _int_free(ar_ptr, p, 0);
+  _inline__int_free(ar_ptr, p, 0);
 }
 libc_hidden_def (public_fREe)
 
@@ -3903,8 +3932,9 @@ _int_malloc(mstate av, size_t bytes)
   ------------------------------ free ------------------------------
 */
 
-static void
-_int_free(mstate av, mchunkptr p, int have_lock)
+INLINE_VERSION (static void, _int_free,
+		mstate av COMMA mchunkptr p COMMA int have_lock,
+		av COMMA p COMMA have_lock)
 {
   INTERNAL_SIZE_T size;        /* its size */
   mfastbinptr*    fb;          /* associated fastbin */

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]