On Mon, 17 Dec 2007, [EMAIL PROTECTED] wrote:
> When we can't hint the real target, we want to hint the most common
> target.   There are potentially clever ways for the compiler to do this
> automatically, but I'm most interested in giving the user some way to do
> it explicitly.  One possiblity is to have something similar to
> __builtin_expect, but for functions.  For example, I propose:
>
>   __builtin_expect_call (FP, PFP)

Is there a hidden benefit?  I mean, isn't this really
expressable using builtin_expect as-is, at least when it comes
to the syntax?  Like:

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

brgds, H-P

Reply via email to