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

use of LIKELY() and UNLIKELY() branch predictors

Thread Next
From:
Dave Mitchell
Date:
January 28, 2013 16:24
Subject:
use of LIKELY() and UNLIKELY() branch predictors
Message ID:
20130128162438.GG2066@iabyn.com
Perl defines the LIKELY() and UNLIKELY() macros, which (under gcc)
tell the compiler whether a particular expression is likely to be true or
not. This allows you to re-write something like

    if (rare_condition) {
	.. do something rare, e.g. warn ...
    }

as

    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?

-- 
If life gives you lemons, you'll probably develop a citric acid allergy.

Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About