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

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

Thread Previous | Thread Next
From:
Zefram
Date:
January 28, 2013 16:32
Subject:
Re: use of LIKELY() and UNLIKELY() branch predictors
Message ID:
20130128163205.GA13883@lake.fysh.org
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.

-zefram

Thread Previous | 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