[lkml]   [2003]   [Aug]   [11]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
Messages in this thread
SubjectRe: [PATCH] 2.4.22pre10: {,un}likely_p() macros for pointers
On Mon, Aug 11, 2003 at 05:55:31AM +0100, Jamie Lokier wrote:
> Willy Tarreau wrote:
> > > I looked at the assembly (ppc, gcc 3.2.3) and didn't
> > > see any overhead.
> >
> > same here on x86, gcc-2.95.3 and gcc-3.3.1. The compiler is smart enough not
> > to add several intermediate tests for !!(x).
> What I recall is no additional tests, but the different forms affected
> the compilers choice of instructions on x86, making one form better
> than another. Unfortunately I don't recall what that was, or what
> test it showed up in :(

It may well be when you use it in boolean constructs. The following functions
return exactly the same result with different code :

int test1(int u, int v, int x, int y) {
return (u > v) || (x > y);

int test2(int u, int v, int x, int y) {
return !!(u > v) | !!(x > y);

test1() uses 2 jumps on x86 while test2 uses only test-and-set and should be
faster. This also allows to easily write the boolean XOR BTW :

int test3(int u, int v, int x, int y) {
return !!(u > v) ^ !!(x > y);


To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to
More majordomo info at
Please read the FAQ at

 \ /
  Last update: 2005-03-22 13:47    [W:0.151 / U:3.380 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site