develooper Front page | perl.perl5.porters | Postings from January 2013

Re: use of LIKELY() and UNLIKELY() branch predictors

Thread Previous | Thread Next
January 29, 2013 15:34
Re: use of LIKELY() and UNLIKELY() branch predictors
Message ID:
On 29 January 2013 12:39, David Cantrell <> wrote:
> On Mon, Jan 28, 2013 at 04:24:38PM +0000, Dave Mitchell wrote:
>> Perl defines the LIKELY() and UNLIKELY() macros, which (under gcc)
>> tell the compiler whether a particular expression is likely to be true or
>> not...
>>     if (UNLIKELY(rare_condition)) {
>>       .. do something rare, e.g. warn ...
>>     }
>> which will hopefully allow the compiler to do clever things.
>> Now, my thoughts are:
>> 1) Has anyone looked at this recently to know whether gcc does anything
>> useful with it?
>> 2) does anyone know whether other compilers provide similar facilities,
>> and so want to contribute suitable macro defs?
>> 3) if it is useful, should we be using it in lots of places?
> 4) is the cost in making the perl source code even more impenetrable due
> to being a twisty maze of macros worth it?

Personally I dont think this is a case of impenetrable macros. In fact
the opposite.

These macros make the developers intent more clear even if they do nothing else.

For one of my XS projects I found a modest use of them made a small
but repeatedly measurable difference.


perl -Mre=debug -e "/just|another|perl|hacker/"

Thread Previous | Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About