[lc-devel] GCC __builting_expect
Status: Beta
Brought to you by:
nitin_sf
From: Rodrigo S. de C. <rc...@im...> - 2001-12-08 19:18:50
|
Hi, I was wondering what likely() and unlikely() macros defined in linux/include/linux/compiler.h for GCC > 2.96 did. Two explanations about that: From the compiler.h source code: /* Somewhere in the middle of the GCC 2.96 development cycle, we implemented a mechanism by which the user can annotate likely branch directions and expect the blocks to be reordered appropriately. Define __builtin_expect to nothing for earlier compilers. */ I found "Using and Porting the GNU Compiler Collection (GCC): Other Builtins" (http://www.dis.com/gnu/gcc/gcc_112.html) where I got the following: Built-in Function: long __builtin_expect (long exp, long c) You may use __builtin_expect to provide the compiler with branch prediction information. In general, you should prefer to use actual profile feedback for this (`-fprofile-arcs'), as programmers are notoriously bad at predicting how their programs actually perform. However, there are applications in which this data is hard to collect. The return value is the value of exp, which should be an integral expression. The value of c must be a compile-time constant. The semantics of the built-in are that it is expected that exp == c. For example: if (__builtin_expect (x, 0)) foo (); would indicate that we do not expect to call foo, since we expect x to be zero. Since you are limited to integral expressions for exp, you should use constructions such as if (__builtin_expect (ptr != NULL, 1)) error (); when testing pointer or floating-point values. Regards, -- Rodrigo S. de Castro <rc...@im...> |