This is the mail archive of the
java-patches@sourceware.cygnus.com
mailing list for the Java project.
Re: Patch proposal: use __builtin_expect
- To: green at cygnus dot com, java-patches at sourceware dot cygnus dot com
- Subject: Re: Patch proposal: use __builtin_expect
- From: Andrew Haley <aph at pasanda dot cygnus dot co dot uk>
- Date: 22 Apr 2000 19:02:17 -0000
> Date: 22 Apr 2000 18:00:30 -0000
> From: Andrew Haley <aph@cygnus.co.uk>
>
> > Date: Sat, 22 Apr 2000 10:57:18 -0700
> > From: Anthony Green <green@cygnus.com>
> >
> > Andrew wrote:
> > > Hmm. So __builtin_expect means that we expect the result *not* to be
> > > true; it actually means "expect false".
> >
> > Not quite. You always provide the expected result. I always gave `0',
> > so it does mean expect false in those cases.
> >
> > __builtin_expect (x, 5)
> >
> > ...means we expect x to be 5. It seems safest/easiest to just expect 0.
>
> Ah, so it's easy to replace those examples with
>
> __builtin_expect (x, false)
>
> To say we expect the result to be false. Better, no?
Or, come to think of it
#define if_unusually(x) __builtin_expect ((x), false)
jint
_Jv_MonitorEnter (jobject obj)
{
#ifndef HANDLE_SEGV
if_unusually(! obj)
JvThrow (new java::lang::NullPointerException);
#endif
if_unusually(INIT_NEEDED (obj))
obj->sync_init ();
_Jv_SyncInfo *si = (_Jv_SyncInfo *) obj->sync_info;
return _Jv_MutexLock (&si->mutex);
}
I'm not sure about the name "if_unusually"; maybe "if_exceptionally"
or just "UNUSUAL" might be better. But I am sure that the syntax
should be sugared somehow...
Andrew.