1
0
mirror of https://sourceware.org/git/glibc.git synced 2025-08-07 06:43:00 +03:00

malloc: replace instances of __builtin_expect with __glibc_unlikely

Replaced all instances of __builtin_expect to __glibc_unlikely
within malloc.c and malloc-debug.c.  This improves the portability
of glibc by avoiding calls to GNU C built-in functions.  Since all
the expected results from calls to __builtin_expect were 0,
__glibc_likely was never used as a replacement.  Multiple
calls to __builtin_expect within a single if statement have
been replaced with one call to __glibc_unlikely, which wraps
every condition.

Reviewed-by: Adhemerval Zanella  <adhemerval.zanella@linaro.org>
Reviewed-by: Wilco Dijkstra  <Wilco.Dijkstra@arm.com>
This commit is contained in:
William Hunt
2025-06-26 15:07:14 +00:00
committed by Wilco Dijkstra
parent d1ad959b00
commit 9a5a7613ac
2 changed files with 25 additions and 26 deletions

View File

@@ -169,7 +169,7 @@ static void *
__debug_malloc (size_t bytes)
{
void *(*hook) (size_t, const void *) = atomic_forced_read (__malloc_hook);
if (__builtin_expect (hook != NULL, 0))
if (__glibc_unlikely (hook != NULL))
return (*hook)(bytes, RETURN_ADDRESS (0));
void *victim = NULL;
@@ -193,7 +193,7 @@ static void
__debug_free (void *mem)
{
void (*hook) (void *, const void *) = atomic_forced_read (__free_hook);
if (__builtin_expect (hook != NULL, 0))
if (__glibc_unlikely (hook != NULL))
{
(*hook)(mem, RETURN_ADDRESS (0));
return;
@@ -218,7 +218,7 @@ __debug_realloc (void *oldmem, size_t bytes)
{
void *(*hook) (void *, size_t, const void *) =
atomic_forced_read (__realloc_hook);
if (__builtin_expect (hook != NULL, 0))
if (__glibc_unlikely (hook != NULL))
return (*hook)(oldmem, bytes, RETURN_ADDRESS (0));
size_t orig_bytes = bytes, oldsize = 0;
@@ -272,7 +272,7 @@ _debug_mid_memalign (size_t alignment, size_t bytes, const void *address)
{
void *(*hook) (size_t, size_t, const void *) =
atomic_forced_read (__memalign_hook);
if (__builtin_expect (hook != NULL, 0))
if (__glibc_unlikely (hook != NULL))
return (*hook)(alignment, bytes, address);
void *victim = NULL;
@@ -371,7 +371,7 @@ __debug_calloc (size_t nmemb, size_t size)
}
void *(*hook) (size_t, const void *) = atomic_forced_read (__malloc_hook);
if (__builtin_expect (hook != NULL, 0))
if (__glibc_unlikely (hook != NULL))
{
void *mem = (*hook)(bytes, RETURN_ADDRESS (0));