This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: __builtin_expect for indirect function calls
- From: trevor_smigiel at playstation dot sony dot com
- To: Hans-Peter Nilsson <hp at bitrange dot com>
- Cc: gcc <gcc at gcc dot gnu dot org>, Russell_Olsen at playstation dot sony dot com, Mark Mitchell <mark at codesourcery dot com>, Andrew_Pinski at PlayStation dot Sony dot Com, Mark Mendell <mendell at ca dot ibm dot com>
- Date: Thu, 3 Jan 2008 15:43:07 -0800
- Subject: Re: __builtin_expect for indirect function calls
- References: <20071218000552.GV3656@playstation.sony.com> <20071221220630.Y67443@dair.pair.com>
> >
> > which returns the value of FP with the same type as FP, and tells the
> > compiler that PFP is the expected target of FP. Trival examples:
> >
> > typedef void (*fptr_t)(void);
> >
> > extern void foo(void);
> >
> > void
> > call_fp (fptr_t fp)
> > {
> > /* Call the function pointed to by fp, but predict it as if it is
> > calling foo() */
> > __builtin_expect_call (fp, foo)();
>
> __builtin_expect (fp, foo); /* alt __builtin_expect (fp == foo, 1); */
> fp ();
> > }
> >
> > void
> > call_fp_predicted (fptr_t fp, fptr_t predicted)
> > {
> > /* same as above but the function we are calling doesn't have to be
> > known at compile time */
> > __builtin_expect_call (fp, predicted)();
>
> __builtin_expect (fp, predicted);
> fp();
>
> I guess the information just isn't readily available in the
> preferred form when needed and *that* part could more or less
> simply be fixed?
The main reason I didn't like this is that in some other context 'fp'
could be any expression, potentially with side effects. This would
require either special handling by the compiler, or the user would have
to be sure to write it such that the side effects only happen once.
Trevor