partition function into cold and hot function by using __builtin_expect

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



GCC already has function attribute *cold*, which hint compiler to separate cold and hot part of a caller function into different functions, and here is a example:  https://godbolt.org/z/j7sK4hd48 <https://godbolt.org/z/j7sK4hd48>
"
cold

The cold attribute on functions is used to inform the compiler that the function is unlikely to be executed. The function is optimized for size rather than speed and on many targets it is placed into a special subsection of the text section so all cold functions appear close together, improving code locality of non-cold parts of program. The paths leading to calls of cold functions within code are marked as unlikely by the branch prediction mechanism. It is thus useful to mark functions used to handle unlikely conditions, such as perror, as cold to improve optimization of hot functions that do call marked functions in rare occasions.
When profile feedback is available, via -fprofile-use, cold functions are automatically detected and this attribute is ignored.

“

Which I want was the builtin function __builtin_expect can also do such hint for compiler, and result in split expected and unexpected part of a function into two function (named cold and hot).

Is this a plan for gcc in the future ? 





[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux