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

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

Thread Previous | Thread Next
Tim Bunce
January 28, 2013 22:35
Re: use of LIKELY() and UNLIKELY() branch predictors
Message ID:
On Mon, Jan 28, 2013 at 04:32:05PM +0000, Zefram wrote:
> Dave Mitchell wrote:
> >1) Has anyone looked at this recently to know whether gcc does anything
> >useful with it?
> Yes, it does.  I'm using this facility in a module that I'm currently
> writing, and I perused some of the generated assembly code to see
> whether it makes a difference.  gcc tends to arrange for the unlikely
> case to be taking a branch, while the likely case is to continue inline.
> This is the same thing that I do when writing assembly code manually.
> (amd64, gcc 4.4.5.)
> >2) does anyone know whether other compilers provide similar facilities,
> >and so want to contribute suitable macro defs?
> It seems quite likely that other compilers implementing it would imitate
> gcc's syntax for it.  Configure will pick it up in such cases.
> >3) if it is useful, should we be using it in lots of places?
> In any hot code, yes.

I recall suggesting this a few years ago and Nicholas doing some
experiments that proved inconclusive. My recollection is that I thought
they needed to be applied in many more places. Specifically, there are
many low-level macros that look like interetsing targets, along with
many places in hot code paths.

Experimenting with this has been at the top of my list of "things I'd do
if I had more time to work on the perl core", so I'm delighted you're
looking into it Dave.


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