diff --git a/kern/libkern/util.h b/kern/libkern/util.h new file mode 100644 index 0000000..ffb9cf2 --- /dev/null +++ b/kern/libkern/util.h @@ -0,0 +1,15 @@ +#ifndef UTIL_H +#define UTIL_H + +/* + * Give hints to the compiler for branch prediction optimization. + */ +#if defined(__clang__) || (defined(__GNUC__) && (__GNUC__ > 2)) +#define likely(c) (__builtin_expect(!!(c), 1)) +#define unlikely(c) (__builtin_expect(!!(c), 0)) +#else +#define likely(c) (c) +#define unlikely(c) (c) +#endif + +#endif // UTIL_H