__builtin_expect with other compilers
Lisandro Dalcin
dalcinl at gmail.com
Mon Nov 30 08:07:40 CST 2009
On Mon, Nov 30, 2009 at 9:49 AM, Jed Brown <jed at 59a2.org> wrote:
> I noticed that GCC mispredicts the conditional in CHKERRQ. At high
> optimization levels it still relocates most of the PetscError call, but
> the non-error path is cleaner with
>
> #define CHKERRQ(n) if (UNLIKELY(n)) {return PetscError(__LINE__,__FUNCT__,__FILE__,__SDIR__,n,0," ");}
>
I wanted to comment on this from long time ago, but never got time to
investigate
> where the following definitions are typical
>
> #define UNLIKELY(c) __builtin_expect(!!(c),0)
> #define LIKELY(c) __builtin_expect(!!(c),1)
>
Indeed. Cython (used in petsc4py) uses these definitions everywhere.
>
> I'm not familiar with the analogues for other compilers.
>
IIRC, Intel compilers do support __builtin_expect, too.
> I don't
> suggest cluttering the code with such hints, but just putting it in
> CHKERRQ would decrease code size for the non-error path which seems like
> a good thing.
>
A big +1 from my side. This will alleviate (at least with gcc and icc)
some Matt's concerns about miss-predictions we discussed long ago. At
that time, I was asking for optimized builds to "#define CHKERRQ(ierr)
if (ierr) return ierr;" instead of empty.
--
Lisandro Dalcín
---------------
Centro Internacional de Métodos Computacionales en Ingeniería (CIMEC)
Instituto de Desarrollo Tecnológico para la Industria Química (INTEC)
Consejo Nacional de Investigaciones Científicas y Técnicas (CONICET)
PTLC - Güemes 3450, (3000) Santa Fe, Argentina
Tel/Fax: +54-(0)342-451.1594
More information about the petsc-dev
mailing list