From: Albert Cahalan <albert@users.sf.net>
To: linux-kernel mailing list <linux-kernel@vger.kernel.org>, chip@pobox.com
Subject: Re: [PATCH] 2.4.22pre10: {,un}likely_p() macros for pointers
Date: 05 Aug 2003 08:44:39 -0400 [thread overview]
Message-ID: <1060087479.796.50.camel@cube> (raw)
Chip Salzenberg writes:
> GCC is warning about a pointer-to-int conversion when
> the likely() and unlikely() macros are used with pointer
> values. So, for architectures where pointers are larger
> than 'int', I suggest this patch.
...
> -#define likely(x) __builtin_expect((x),1)
> -#define unlikely(x) __builtin_expect((x),0)
> +#define likely(x) __builtin_expect((x), 1)
> +#define likely_p(x) __builtin_expect((x) != 0, 1)
> +#define unlikely(x) __builtin_expect((x) ,0)
> +#define unlikely_p(x) __builtin_expect((x) != 0 ,0)
That's ugly, plus the "_p" suffix is kind of a
standard for "predicate". (__builtin_constant_p, etc.)
I'm using these in the procps project:
// tell gcc what to expect: if(unlikely(err)) die(err);
#define likely(x) __builtin_expect(!!(x),1)
#define unlikely(x) __builtin_expect(!!(x),0)
#define expected(x,y) __builtin_expect((x),(y))
That makes a slight change to the meaning, since the
original value is no longer available. I've not
found that to be any trouble at all; if it is then
you could work around it using a statement-expression
with a variable, cast, and/or __typeof__.
Something like this:
#define likely(x) ({ \
__typeof__ (x) _tmp; \
__builtin_expect(!!_tmp,1); \
_tmp; \
})
next reply other threads:[~2003-08-05 12:54 UTC|newest]
Thread overview: 31+ messages / expand[flat|nested] mbox.gz Atom feed top
2003-08-05 12:44 Albert Cahalan [this message]
2003-08-09 0:21 ` [PATCH] 2.4.22pre10: {,un}likely_p() macros for pointers Jamie Lokier
2003-08-09 8:13 ` Willy Tarreau
2003-08-09 8:51 ` David S. Miller
2003-08-09 9:36 ` Jamie Lokier
2003-08-09 10:10 ` Herbert Xu
2003-08-09 10:42 ` Alan Cox
2003-08-09 16:23 ` Jamie Lokier
2003-08-09 17:30 ` NULL. Again. (was Re: [PATCH] 2.4.22pre10: {,un}likely_p()) Chip Salzenberg
2003-08-09 17:43 ` Sean Neakums
2003-08-11 1:04 ` Jamie Lokier
2003-08-11 23:06 ` Timothy Miller
2003-08-09 19:44 ` Jamie Lokier
-- strict thread matches above, loose matches on Subject: below --
2003-08-10 4:03 [PATCH] 2.4.22pre10: {,un}likely_p() macros for pointers Albert Cahalan
2003-08-10 7:29 ` Willy Tarreau
2003-08-10 8:02 ` Willy Tarreau
2003-08-11 1:23 ` Chip Salzenberg
2003-08-11 2:09 ` Jamie Lokier
2003-08-11 2:39 ` Chip Salzenberg
2003-08-11 4:02 ` Albert Cahalan
2003-08-11 4:30 ` Jamie Lokier
2003-08-11 5:30 ` Willy Tarreau
2003-08-11 5:42 ` Jamie Lokier
2003-08-11 13:09 ` Albert Cahalan
2003-08-11 18:55 ` Andrew Morton
2003-08-11 23:13 ` Albert Cahalan
2003-08-13 19:42 ` Jamie Lokier
2003-08-11 4:55 ` Jamie Lokier
2003-08-11 5:26 ` Willy Tarreau
2003-08-11 5:38 ` Jamie Lokier
2003-08-04 17:06 Chip Salzenberg
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1060087479.796.50.camel@cube \
--to=albert@users.sf.net \
--cc=chip@pobox.com \
--cc=linux-kernel@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.