From: Ivan Kokshaysky <ink@jurassic.park.msu.ru>
To: Richard Henderson <rth@twiddle.net>
Cc: linux-kernel@vger.kernel.org
Subject: Re: [patch] 2.4.4 alpha semaphores optimization
Date: Sat, 5 May 2001 18:17:18 +0400 [thread overview]
Message-ID: <20010505181718.B2302@jurassic.park.msu.ru> (raw)
In-Reply-To: <20010503194747.A552@jurassic.park.msu.ru> <20010504141318.B11122@twiddle.net>
In-Reply-To: <20010504141318.B11122@twiddle.net>; from rth@twiddle.net on Fri, May 04, 2001 at 02:13:18PM -0700
On Fri, May 04, 2001 at 02:13:18PM -0700, Richard Henderson wrote:
> Eh? Would you give me an example that isn't working properly?
Sure.
bar.c:
-----------------
extern void rarely_executed_code(void);
static inline void foo_no_be(void)
{
int ret;
__asm__ __volatile__("nop\n": "=r" (ret));
if (ret < 0)
rarely_executed_code();
}
static inline void foo(void)
{
int ret;
__asm__ __volatile__("unop\n": "=r" (ret));
if (__builtin_expect(ret < 0, 0))
rarely_executed_code();
}
#define foo_macro() ({ \
int ret; \
__asm__ __volatile__("fnop\n": "=r" (ret)); \
if (__builtin_expect(ret < 0, 0)) \
rearly_executed_code(); \
})
void bar(void)
{
foo_no_be();
foo();
foo_macro();
}
---------------
bar.s, compiled with 'gcc -O2 -S bar.c':
--------------
[...]
$bar..ng:
lda $30,-16($30)
stq $26,0($30)
.prologue 1
nop
.align 3 #realign
addl $1,$31,$1
blt $1,$L12 # (ret < 0) predicted to be "false", and gcc
# put the code out of line quite nicely.
$L8:
unop
.align 3 #realign
srl $1,31,$1
blbc $1,$L10 # Oops. The slow path code is in line...
jsr $26,rarely_executed_code
ldgp $29,0($26)
$L10:
fnop
.align 3 #realign
srl $1,31,$1
blbs $1,$L13 # This works.
$L11:
ldq $26,0($30)
nop
lda $30,16($30)
ret $31,($26),1
.align 4
$L13:
jsr $26,rearly_executed_code
ldgp $29,0($26)
br $31,$L11
.align 4
$L12:
jsr $26,rarely_executed_code
ldgp $29,0($26)
br $31,$L8
.end bar
.ident "GCC: (GNU) 3.0 20010430 (prerelease)"
---------------
So one of the questions: can one rely on current branch predictions
algorithms (val < 0, val = 0 false etc.) in the long term?
Ivan.
next prev parent reply other threads:[~2001-05-05 14:18 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2001-05-03 15:47 Ivan Kokshaysky
2001-05-03 17:28 ` Andrea Arcangeli
2001-05-04 9:15 ` Ivan Kokshaysky
2001-05-04 14:33 ` Andrea Arcangeli
2001-05-04 17:02 ` Ivan Kokshaysky
2001-05-04 17:16 ` Andrea Arcangeli
2001-05-04 9:22 ` David Howells
2001-05-04 9:54 ` Ivan Kokshaysky
2001-05-04 16:46 ` Ivan Kokshaysky
2001-05-04 21:12 ` Richard Henderson
2001-05-05 13:55 ` Ivan Kokshaysky
2001-05-06 6:55 ` Ivan Kokshaysky
2001-05-04 21:13 ` Richard Henderson
2001-05-05 14:17 ` Ivan Kokshaysky [this message]
2001-05-05 17:06 ` __builtin_expect vs inlining Richard Henderson
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=20010505181718.B2302@jurassic.park.msu.ru \
--to=ink@jurassic.park.msu.ru \
--cc=linux-kernel@vger.kernel.org \
--cc=rth@twiddle.net \
/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
all inboxes | Powered by JetHome®