#author("2025-09-13T01:49:21+09:00","default:guest","guest") #author("2025-09-13T01:52:54+09:00","default:guest","guest") *参照元 [#zf5c4d3b] #backlinks *説明 [#m3dd331a] -パス: [[linux-5.15/include/linux/compiler.h]] -falseと評価される可能性が高い分岐処理を高速化する。 --if (unlikely(a)) ...のように使う。 **引数 [#r8813a1d] -x --何らかの式 **返り値 [#r7e0dcb1] -x --xの値そのまま **参考 [#ddd79b30] *実装 [#z0b29265] /* * Note: DISABLE_BRANCH_PROFILING can be used by special lowlevel code * to disable branch tracing on a per file basis. */ #if defined(CONFIG_TRACE_BRANCH_PROFILING) \ && !defined(DISABLE_BRANCH_PROFILING) && !defined(__CHECKER__) /* * Using __builtin_constant_p(x) to ignore cases where the return * value is always the same. This idea is taken from a similar patch * written by Daniel Walker. */ //... # ifndef unlikely # define unlikely(x) (__branch_check__(x, 0, __builtin_constant_p(x))) # endif #endif /* CONFIG_PROFILE_ALL_BRANCHES */ #else //... # define unlikely(x) __builtin_expect(!!(x), 0) //... #endif -CONFIG_TRACE_BRANCH_PROFILINGが有効ならば__builtin_constant_p()を使う。 -CONFIG_TRACE_BRANCH_PROFILINGが有効ならば__branch_check__()を使うが、内部で__builtin_expect()を使っている。やっていることはどちらも一緒。 --__builtin_constant_p はコンパイラ組み込み関数。引数がコンパイル時の定数であれば1を返す。 --[[linux-5.15/__branch_check__()]] -CONFIG_TRACE_BRANCH_PROFILINGが無効ならば__builtin_expect()を使う。 --!!(x)とするのは1ではないtrue値を1に、0ではないfalse値を0にするため。 *コメント [#ne2fe80e]