Linux PARISC architecture development
 help / color / mirror / Atom feed
From: Christopher Neufeld <neufeld@physics.utoronto.ca>
To: hppa-linux@thepuffingroup.com
Subject: [hppa-linux] GCC and static branch prediction
Date: Tue, 23 Mar 1999 11:12:33 -0500 (EST)	[thread overview]
Message-ID: <199903231612.LAA02124@caliban.physics.utoronto.ca> (raw)

   Hi,

   A few of us were discussing recently a way to take advantage of static
branch prediction in the PA-RISC architecture. The problem is that there
is no ANSI C construct for specifying whether a branch is likely taken,
or likely not taken.
   I wonder, though, if we can't maybe throw something together which
would work "well enough".

   What I'm thinking of is getting a couple of assembly NOPs (ones which
are not usually output by gcc / gas), and making macros for them to
inline the assembly into a C function.


[ ... do some stuff ... ]
if (error) {
	PARISC_BRANCH_LIKELY_TAKEN; /* i.e. usually don't enter the if() */
	[ ... do some more stuff ... ]
}
[ ... do some more stuff ... ]


or,


while (locked(ptr)) {
	do_other_things();

}
PARISC_BRANCH_LIKELY_TAKEN;  /* i.e. usually repeat the loop */


Now, if we can make an insn pattern which matches the noop to the branch
which came just before it, we can get the optimizer to produce the
correct static branch prediction on the preceding operation (and also,
while it's optimizing, delete the NOP). For other architectures, the
macros are defined away, and the macros need only be used in places where
we really need the extra boost (preferably only in the arch/parisc
directories, imagine Linus' face if we started dropping these macros all
over the kernel!).

   As I see it, there are a few things to worry about. Unrolling loops;
if(){}else{} clauses where the optimizer changes the sense of the test
for reasons known to itself, resulting in pessimized static branch
settings; correct interpretation of nested, optimized branches; any glue
code which is stuck on at the beginning and end of asm() statements which
may not be discarded even when the asm() consists solely of a NOP;
probably many others.


   Any thoughts?


-- 
 Christopher Neufeld                   neufeld@physics.utoronto.ca
 Home page:  http://caliban.physics.utoronto.ca/neufeld/Intro.html
 "Don't edit reality for the sake of simplicity"

             reply	other threads:[~1999-03-23 16:12 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1999-03-23 16:12 Christopher Neufeld [this message]
1999-03-23 17:21 ` [hppa-linux] GCC and static branch prediction Alan Cox

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=199903231612.LAA02124@caliban.physics.utoronto.ca \
    --to=neufeld@physics.utoronto.ca \
    --cc=hppa-linux@thepuffingroup.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