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: Hans-Peter Nilsson <hp at bitrange dot com>
- To: trevor_smigiel at playstation dot sony dot com
- Cc: gcc <gcc at gcc dot gnu dot org>, Russell_Olsen at playstation dot sony dot com
- Date: Fri, 21 Dec 2007 22:16:32 -0500 (EST)
- Subject: Re: __builtin_expect for indirect function calls
- References: <20071218000552.GV3656@playstation.sony.com>
On Mon, 17 Dec 2007, trevor_smigiel@playstation.sony.com 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