This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: __builtin_expect for indirect function calls


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]