lkml.org 
[lkml]   [2006]   [Apr]   [26]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
From
SubjectRe: [PATCH] likely cleanup: remove unlikely for kfree(NULL)
Date
Here's code that I've found works as well as can be expected under  
both GCC 3 and GCC 4. If xp is a known-NULL constant the whole
function will be optimized out completely. If xp is known-not-NULL,
then it will optimize to a kfree function without the null check.
Otherwise it optimizes to call the out-of-line version.

Cheers,
Kyle Moffett

static inline void kfree(void *ptr)
{
if (__builtin_constant_p((ptr == NULL))) {
if (ptr)
kfree_nonnull(ptr);
} else {
kfree_unknown(ptr);
}
}

void kfree_nonnull(void *ptr)
{
/* kfree code here, no null check */
}

void kfree_unknown(void *ptr)
{
if (ptr)
kfree_nonnull(ptr);
}

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/

\
 
 \ /
  Last update: 2006-04-26 21:11    [W:0.060 / U:0.204 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site