diff --git a/share/man/man9/style.9 b/share/man/man9/style.9 --- a/share/man/man9/style.9 +++ b/share/man/man9/style.9 @@ -902,6 +902,19 @@ .Fn _Static_assert instead of the older .Fn CTASSERT . +.Pp +.Fn __predict_true +and +.Fn __predict_false +should only be used in performance critical code. +Consistently use +.Fn __predict_false +for error conditions that are not typical, and document the exceptions. +Use +.Fn __predict_true +for operations expected to almost always succeed. +Do not add these annotations without empirical evidence of the likelihood of the +branch. .Sh FILES .Bl -tag -width indent .It Pa /usr/src/tools/build/checkstyle9.pl diff --git a/sys/sys/cdefs.h b/sys/sys/cdefs.h --- a/sys/sys/cdefs.h +++ b/sys/sys/cdefs.h @@ -321,6 +321,13 @@ #define __restrict restrict #endif +/* + * All modern compilers have explicit branch prediction so that the CPU back-end + * can hint to the processor and also so that code blocks can be reordered such + * that the predicted path sees a more linear flow, thus improving cache + * behavior, etc. Use sparingly, except in performance critical code where + * they make things faster. + */ #define __predict_true(exp) __builtin_expect((exp), 1) #define __predict_false(exp) __builtin_expect((exp), 0)