Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitaa3ca5e

Browse files
committed
Add likely/unlikely() branch hint macros.
These are useful for very hot code paths. Because it's easy to guesswrongly about likelihood, and because such likelihoods change over time,they should be used sparingly.Past tests have shown it'd be a good idea to use them in some places,e.g. in error checks around ereports that ERROR out, but that's work forlater.Discussion: <20160727004333.r3e2k2y6fvk2ntup@alap3.anarazel.de>
1 parent32fdf42 commitaa3ca5e

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

‎src/include/c.h

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -939,6 +939,22 @@ typedef NameData *Name;
939939
#endif
940940

941941

942+
/*
943+
* Hints to the compiler about the likelihood of a branch. Both likely() and
944+
* unlikely() return the boolean value of the contained expression.
945+
*
946+
* These should only be used sparingly, in very hot code paths. It's very easy
947+
* to mis-estimate likelihoods.
948+
*/
949+
#if__GNUC__ >=3
950+
#definelikely(x)__builtin_expect((x) != 0, 1)
951+
#defineunlikely(x) __builtin_expect((x) != 0, 0)
952+
#else
953+
#definelikely(x)((x) != 0)
954+
#defineunlikely(x) ((x) != 0)
955+
#endif
956+
957+
942958
/* ----------------------------------------------------------------
943959
*Section 8:random stuff
944960
* ----------------------------------------------------------------

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp