From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 2319 invoked by alias); 22 Dec 2007 03:16:39 -0000 Received: (qmail 2311 invoked by uid 22791); 22 Dec 2007 03:16:39 -0000 X-Spam-Check-By: sourceware.org Received: from dair.pair.com (HELO dair.pair.com) (209.68.1.49) by sourceware.org (qpsmtpd/0.31) with SMTP; Sat, 22 Dec 2007 03:16:34 +0000 Received: (qmail 88275 invoked by uid 20157); 22 Dec 2007 03:16:32 -0000 Received: from localhost (sendmail-bs@127.0.0.1) by localhost with SMTP; 22 Dec 2007 03:16:32 -0000 Date: Sat, 22 Dec 2007 03:42:00 -0000 From: Hans-Peter Nilsson To: trevor_smigiel@playstation.sony.com cc: gcc , Russell_Olsen@playstation.sony.com Subject: Re: __builtin_expect for indirect function calls In-Reply-To: <20071218000552.GV3656@playstation.sony.com> Message-ID: <20071221220630.Y67443@dair.pair.com> References: <20071218000552.GV3656@playstation.sony.com> MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII X-IsSubscribed: yes Mailing-List: contact gcc-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-owner@gcc.gnu.org X-SW-Source: 2007-12/txt/msg00657.txt.bz2 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