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

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

Thread Previous | Thread Next
January 28, 2013 16:32
Re: use of LIKELY() and UNLIKELY() branch predictors
Message ID:
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.


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