OSDN Git Service

util.h: add unlikely() and likely() macros
authorPeter Jones <pjones@redhat.com>
Mon, 7 Jan 2019 15:30:23 +0000 (10:30 -0500)
committerPeter Jones <pjones@redhat.com>
Mon, 7 Jan 2019 15:30:23 +0000 (10:30 -0500)
Signed-off-by: Peter Jones <pjones@redhat.com>
src/util.h

index f63a890..ba8fee3 100644 (file)
 #define PACKED __attribute__((__packed__))
 #define VERSION(sym, ver) __asm__(".symver " # sym "," # ver)
 
+#define __branch_check__(x, expect, is_constant) \
+       __builtin_expect(!!(x), expect)
+#ifndef likely
+#define likely(x) (__branch_check__(x, 1, __builtin_constant_p(x)))
+#endif
+#ifndef unlikely
+#define unlikely(x) (__branch_check__(x, 0, __builtin_constant_p(x)))
+#endif
+
 /*
  * I'm not actually sure when these appear, but they're present in the
  * version in front of me.