|
From: Bart V. A. <bar...@gm...> - 2008-03-15 16:46:03
|
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 Bart. |