Browse Source

(likely, unlikely): New macros.
(__malloc_likely, __malloc_unlikely): Macros removed.

Miles Bader 23 years ago
parent
commit
8879afda8b
1 changed files with 8 additions and 6 deletions
  1. 8 6
      libc/stdlib/malloc/malloc.h

+ 8 - 6
libc/stdlib/malloc/malloc.h

@@ -110,14 +110,16 @@ extern malloc_mutex_t __malloc_sbrk_lock;
 #endif /* __UCLIBC_HAS_THREADS__ */
 #endif /* __UCLIBC_HAS_THREADS__ */
 
 
 
 
-/* Use branch-prediction macros from libc if defined.  */
+/* branch-prediction macros; they may already be defined by libc.  */
-#ifdef likely
+#ifndef likely
-#define __malloc_likely(c)	likely(c)
+#if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 96)
-#define __malloc_unlikely(c)	unlikely(c)
+#define likely(cond)	__builtin_expect(!!(int)(cond), 1)
+#define unlikely(cond)	__builtin_expect((int)(cond), 0)
 #else
 #else
-#define __malloc_likely(c)	(c)
+#define likely(cond)	(cond)
-#define __malloc_unlikely(c)	(c)
+#define unlikely(cond)	(cond)
 #endif
 #endif
+#endif /* !likely */
 
 
 
 
 /* Define MALLOC_DEBUGGING to cause malloc to emit debugging info to stderr.  */
 /* Define MALLOC_DEBUGGING to cause malloc to emit debugging info to stderr.  */