Messages in this thread | | | Subject | Re: [PATCH] 2.4.22pre10: {,un}likely_p() macros for pointers | From | Albert Cahalan <> | Date | 05 Aug 2003 08:44:39 -0400 |
| |
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; \ })
- 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/
| |