简体   繁体   中英

Branch Prediction: Branch Order vs builtin_expect

I am learning about branch prediction in C++ and have a fairly straightforward question.

It seems the __builtin_expect term tells the compiler which clause to put first in the assembly code.

However if this is added manually by the programmer how is it any different than simply switching the if / else clauses in the C++ code?

The compiler's optimiser is allowed to reorder branches. The __builtin_expect is useful if the compiler gets (or is likely) to get it wrong.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM