summaryrefslogtreecommitdiffstats
path: root/sys
diff options
context:
space:
mode:
authordas <das@FreeBSD.org>2009-01-31 18:27:02 +0000
committerdas <das@FreeBSD.org>2009-01-31 18:27:02 +0000
commit61dc3e056cc2ad51f33f296f1cfda0ece440b85e (patch)
tree86563ca98ba62d850839a916a23d185416bda1b7 /sys
parentfb1404080f89a63cdf36da668e5ff4fc65cfa4d9 (diff)
downloadFreeBSD-src-61dc3e056cc2ad51f33f296f1cfda0ece440b85e.zip
FreeBSD-src-61dc3e056cc2ad51f33f296f1cfda0ece440b85e.tar.gz
Add a function attribute called `__malloc_like', which informs gcc
that the annotated function returns a pointer that doesn't alias any extant pointer. This results in a 50%+ speedup in microbenchmarks such as the following: char *cp = malloc(1), *buf = malloc(BUF); for (i = 0; i < BUF; i++) buf[i] = *cp; In real programs, your mileage will vary. Note that gcc already performs this optimization automatically for any function called `malloc', `calloc', `strdup', or `strndup' unless -fno-builtins is used.
Diffstat (limited to 'sys')
-rw-r--r--sys/sys/cdefs.h2
-rw-r--r--sys/sys/malloc.h4
2 files changed, 4 insertions, 2 deletions
diff --git a/sys/sys/cdefs.h b/sys/sys/cdefs.h
index e796908..a850950 100644
--- a/sys/sys/cdefs.h
+++ b/sys/sys/cdefs.h
@@ -221,8 +221,10 @@
#endif
#if __GNUC_PREREQ__(2, 96)
+#define __malloc_like __attribute__((__malloc__))
#define __pure __attribute__((__pure__))
#else
+#define __malloc_like
#define __pure
#endif
diff --git a/sys/sys/malloc.h b/sys/sys/malloc.h
index 33b287f..24a044c 100644
--- a/sys/sys/malloc.h
+++ b/sys/sys/malloc.h
@@ -190,9 +190,9 @@ typedef void malloc_type_list_func_t(struct malloc_type *, void *);
void contigfree(void *addr, unsigned long size, struct malloc_type *type);
void *contigmalloc(unsigned long size, struct malloc_type *type, int flags,
vm_paddr_t low, vm_paddr_t high, unsigned long alignment,
- unsigned long boundary);
+ unsigned long boundary) __malloc_like;
void free(void *addr, struct malloc_type *type);
-void *malloc(unsigned long size, struct malloc_type *type, int flags);
+void *malloc(unsigned long size, struct malloc_type *type, int flags) __malloc_like;
void malloc_init(void *);
int malloc_last_fail(void);
void malloc_type_allocated(struct malloc_type *type, unsigned long size);
OpenPOWER on IntegriCloud