Page Menu
Home
FreeBSD
Search
Configure Global Search
Log In
Files
F156728029
D45837.id140484.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Flag For Later
Award Token
Size
1 KB
Referenced Files
None
Subscribers
None
D45837.id140484.diff
View Options
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
@@ -897,6 +897,22 @@
.Fn _Static_assert
instead of the older
.Fn CTASSERT .
+.Pp
+.Fn __predict_true
+and
+.Fn __predict_false
+should only be used in frequently executed code, since it is wasteful to make
+predictions for infrequently run code, like subsystem initialization.
+When using branch prediction hints,
+atypical error conditions should use
+.Fn __predict_false
+(document the exceptions).
+Use
+.Fn __predict_true
+for operations expected to almost always succeed.
+Only use the annotation for the entire if statement, rather than individual clauses.
+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)
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Sat, May 16, 11:09 PM (13 h, 42 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
33158004
Default Alt Text
D45837.id140484.diff (1 KB)
Attached To
Mode
D45837: cdefs.h: Add back comment about branch prediction
Attached
Detach File
Event Timeline
Log In to Comment