public inbox for gcc@gcc.gnu.org
 help / color / mirror / Atom feed
From: trevor_smigiel@playstation.sony.com
To: Mark Mitchell <mark@codesourcery.com>
Cc: Hans-Peter Nilsson <hp@bitrange.com>, gcc <gcc@gcc.gnu.org>,
	        Russell_Olsen@playstation.sony.com,
	Andrew_Pinski@PlayStation.Sony.Com,
	        Mark Mendell <mendell@ca.ibm.com>
Subject: Re: __builtin_expect for indirect function calls
Date: Thu, 03 Jan 2008 23:36:00 -0000	[thread overview]
Message-ID: <20080103233308.GD5853@playstation.sony.com> (raw)
In-Reply-To: <4772A350.6030907@codesourcery.com>

If possible, I agree it seems natural to extend __builtin_expect.  My
concern would be backwards compatibility.

Currently, the prototype for __builtin_expect is

    long __builtin_expect (long expression, long constant);

Extending it to functions would change it to

    T __builtin_expect (T expression, T expected);

With these additional semantics and restrictions:
    - when the return value is being used as a call expression:
      * T is the type of 'expression'
      * 'expected' is allowed to be a non-constant
    - when the return value is not being used as a call expression:
      * T is type 'long;
      * 'expected' must be a compile-time constant

Given the above definition, I don't think there is any backwards
compatibility issues because we are inspecting the context of the
use of __builtin_expect.

Rather than the above definition, we could choose not to inspect the
context and just say:
    * T is the type of 'expression'
    * 'expected' is allowed to be a non-constant

In this case I think there would only be compatibility issues with
unusual uses of __builtin_expect, for example, if it was being used in a
function argument and its type effected overload resolution. Or if the
argument was a float and was being implicitly converted to a long (with
a warning).  There would also be code which previously gave warnings but
does not with the extended __builtin_expect.

I'm ok with either of these definitions, if extending __builtin_expect
is the preferred way to go.

Are either of these definitions ok?  Or are there other ideas how to
define it?

Trevor

* Mark Mitchell <mark@codesourcery.com> [2008-01-03 12:12]:
> Hans-Peter Nilsson wrote:
> > 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?  
> 
> That was my first thought as well.  Before we add __builtin_expect_call,
> I think there needs to be a justification of why this can't be done with
> __builtin_expect as-is.
> 
> -- 
> Mark Mitchell
> CodeSourcery
> mark@codesourcery.com
> (650) 331-3385 x713

  reply	other threads:[~2008-01-03 23:36 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-12-18  0:52 trevor_smigiel
2007-12-18  2:27 ` Jonathan Adamczewski
2007-12-22  3:42 ` Hans-Peter Nilsson
2007-12-26 19:10   ` Mark Mitchell
2008-01-03 23:36     ` trevor_smigiel [this message]
2008-01-05  5:44       ` Mark Mitchell
2008-01-05 10:40         ` Richard Guenther
2008-01-06 19:44           ` Mark Mitchell
2008-01-07 21:15             ` Mark Mendell
2008-01-08 15:36               ` Dave Korn
2008-01-08 15:51                 ` Dave Korn
2008-01-03 23:46   ` trevor_smigiel
2008-01-06 20:42 Ross Ridge

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20080103233308.GD5853@playstation.sony.com \
    --to=trevor_smigiel@playstation.sony.com \
    --cc=Andrew_Pinski@PlayStation.Sony.Com \
    --cc=Russell_Olsen@playstation.sony.com \
    --cc=gcc@gcc.gnu.org \
    --cc=hp@bitrange.com \
    --cc=mark@codesourcery.com \
    --cc=mendell@ca.ibm.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).