2 msgWhere to find the sources implementing GCC DFA ...
1 msgcompiling failed.
1 msgRFC: New mangling for java resources.
1 msg[www] get VTA branch entry to refer to design d...
2 msgDisabling the heuristic inliner
1 msggcc-4.2-20071219 is now available
23 msg-Wparentheses lumps too much together
11 msgStrange error message from gdb
1 msgA proposal to align GCC stack - update
1 msgvliw scheduling - TImode bug?
1 msgdarwin libgomp build oddity
16 msgRegression count, and how to keep bugs around f...
4 msgRe: Objective-C 2.0 in GCC
27 msgA proposal to align GCC stack

__builtin_expect for indirect function calls
\ trevor_smigiel (18 Dec 2007)
. \ Jonathan Adamczewski (18 Dec 2007)
. \ Hans-Peter Nilsson (22 Dec 2007)
. . \ Mark Mitchell (26 Dec 2007)
. . . \ trevor_smigiel (3 Jan 2008)
. . . . \ Mark Mitchell (5 Jan 2008)
. . . . . \ Richard Guenther (5 Jan 2008)
. . . . . . \ Mark Mitchell (6 Jan 2008)
. . . . . . . \ Mark Mendell (7 Jan 2008)
. . . . . . . . \ Dave Korn (8 Jan 2008)
. . . . . . . . . \ Dave Korn (8 Jan 2008)
. . \ trevor_smigiel (3 Jan 2008)
. \ (Ross Ridge) (6 Jan 2008)

1 msggcc-4.1-20071217 is now available
2 msgRe: gcc don't allow commas between clauses for ...
1 msgunable to find a register to spill in class ‘MD...
3 msgRe: Problem with posix threads
4 msgProblem with SSA inlining and default defs
Subject:__builtin_expect for indirect function calls
Group:Gcc
From:trevor_smigiel
Date:18 Dec 2007


Hi,

I'm looking for comments on a possible GCC extensions described below.

For the target I'm interested in, Cell SPU, taken branches are only
predicted correctly by explicitly inserting a specific instructions (a
hint instruction) that says "the branch at address A is branching to
address B". This allows the processor to prefetch the instructions at
B, potentially with no penalty.

For indirect function calls, the ideal case is we know the target soon
enough at run-time that the hint instruction simply specifies the real
target. Soon enough means about 18 cycles before the execution of the
branch. I don't have any numbers as to how often this happens, but
there are enough cases where it doesn't.

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)

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)();
}

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)();
}

I believe I can add this just for the SPU target without effecting
anything else, but it could be useful for other targets.

Are there any comments about the name, semantics, or usefulness of this
extension?

Thanks,
Trevor




© 2004-2008 readlist.com