|
From: | Paul Eggert |
Subject: | Re: Using __builtin_expect (likely/unlikely macros) |
Date: | Tue, 16 Apr 2019 08:22:36 -0700 |
User-agent: | Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.6.1 |
Stefan Monnier wrote:
FWIW, the fact that a function is "_Noreturn" doesn't necessarily mean that a call to it is unlikely (in many cases it is, I guess, but definitely not all), so maybe GCC maintainers consciously decided not to link the two.
Possibly they did. In hindsight I'd argue that was a mistake. If one has no other evidence about the likelihood of a branch, a branch to a _Noreturn call should default to being unlikely.
BTW I think instead of marking branches as likely or unlikely, I'd prefer to tell GCC that some functions "should be slow" (e.g. emacs_abort) so it optimizes the code paths that don't go through those functions to the detriment of those that do.
GCC has the function attribute 'cold' for that. This is less intrusive than __builtin_expect and so would be preferable. Still, the GCC manual says that __attribute__ ((cold)) is ignored when profile feedback is available, which is another indication that people who care about performance should be using -fprofile-use etc. And as far as I know __attribute__ ((cold)) is rarely used: even glibc uses it only once, in obscure code never used on GNU/Linux. Presumably this is partly because the attribute didn't exist until about five years ago.
[Prev in Thread] | Current Thread | [Next in Thread] |