Likely/unlikely

This commit is contained in:
Imbus 2025-09-04 05:00:09 +02:00
parent 4ee23cd145
commit 129b29eaf3

15
kern/libkern/util.h Normal file
View file

@ -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