From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 12748 invoked by alias); 18 Dec 2007 00:06:18 -0000 Received: (qmail 12739 invoked by uid 22791); 18 Dec 2007 00:06:17 -0000 X-Spam-Check-By: sourceware.org Received: from outbound-sin.frontbridge.com (HELO outbound8-sin-R.bigfish.com) (207.46.51.80) by sourceware.org (qpsmtpd/0.31) with ESMTP; Tue, 18 Dec 2007 00:06:10 +0000 Received: from outbound8-sin.bigfish.com (localhost.localdomain [127.0.0.1]) by outbound8-sin-R.bigfish.com (Postfix) with ESMTP id 8EB5118D8E9C; Tue, 18 Dec 2007 00:04:33 +0000 (UTC) Received: from mail34-sin-R.bigfish.com (unknown [10.3.40.3]) by outbound8-sin.bigfish.com (Postfix) with ESMTP id 806F34E805B; Tue, 18 Dec 2007 00:04:33 +0000 (UTC) Received: from mail34-sin (localhost.localdomain [127.0.0.1]) by mail34-sin-R.bigfish.com (Postfix) with ESMTP id BF1BDC6813A; Tue, 18 Dec 2007 00:03:52 +0000 (UTC) X-BigFish: V X-MS-Exchange-Organization-Antispam-Report: OrigIP: 160.33.98.75;Service: EHS Received: by mail34-sin (MessageSwitch) id 1197936231662493_13943; Tue, 18 Dec 2007 00:03:51 +0000 (UCT) Received: from mail8.fw-bc.sony.com (mail8.fw-bc.sony.com [160.33.98.75]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mail34-sin.bigfish.com (Postfix) with ESMTP id 2EE15468088; Tue, 18 Dec 2007 00:03:48 +0000 (UTC) Received: from mail3.sjc.in.sel.sony.com (mail3.sjc.in.sel.sony.com [43.134.1.211]) by mail8.fw-bc.sony.com (8.12.11/8.12.11) with ESMTP id lBI05srm017834; Tue, 18 Dec 2007 00:05:54 GMT Received: from constantine.playstation.sony.com ([162.49.67.15]) by mail3.sjc.in.sel.sony.com (8.12.11/8.12.11) with ESMTP id lBI05saZ014225; Tue, 18 Dec 2007 00:05:54 GMT Received: from deagol.playstation.sony.com ([10.98.10.144]) by constantine.playstation.sony.com (Lotus Domino Release 7.0.2FP2) with ESMTP id 2007121716055261-442 ; Mon, 17 Dec 2007 16:05:52 -0800 Received: from trevor by deagol.playstation.sony.com with local (Exim 3.36 #1 (Debian)) id 1J4Py4-0005Pe-00; Mon, 17 Dec 2007 16:05:52 -0800 Date: Tue, 18 Dec 2007 00:52:00 -0000 To: gcc Cc: Ulrich Weigand , Russell_Olsen@playstation.sony.com Subject: __builtin_expect for indirect function calls Message-ID: <20071218000552.GV3656@playstation.sony.com> MIME-Version: 1.0 User-Agent: Mutt/1.5.13 (2006-08-11) From: trevor_smigiel@playstation.sony.com Content-Type: text/plain; charset=us-ascii Content-Disposition: inline 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/msg00498.txt.bz2 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