|
From: Nicholas N. <nj...@cs...> - 2008-03-21 09:08:13
|
Bart Van Assche wrote: > Hello, > > Code executed in Valgrind tools that analyzes runtime behavior of > clients often can be made faster by specifying branch prediction > information. E.g. gcc offers the built-in function __builtin_expect() > to allow branch prediction information to be specified in source code. > Unfortunately there is not yet a standard way in Valgrind to specify > branch prediction hints. The patch below is modeled after the include > file linux/compiler.h in the Linux kernel source tree, and should > replace the EXPECTED_TAKEN / EXPECTED_NOT_TAKEN / LIKELY / UNLIKELY > macro's found in various source files. Comments are welcome. > > Index: include/pub_tool_compiler.h > =================================================================== > --- include/pub_tool_compiler.h (revision 0) > +++ include/pub_tool_compiler.h (revision 0) > @@ -0,0 +1,9 @@ > +/* Compiler-dependent functionality. */ > + > +#include "config.h" > + > +#if HAVE_BUILTIN_EXPECT > +#define LIKELY(x) __builtin_expect(!!(x), 1) > +#define UNLIKELY(x) __builtin_expect((x), 0) > +#else > +#define LIKELY(x) (x) > +#define UNLIKELY(x) (x) > +#endif The idea seems ok to me. I'd probably put it in pub_tool_basics.h, though. It would be good if the various other macros were changed to use this one, too. Nick |