public inbox for u-boot@lists.denx.de
 help / color / mirror / Atom feed
From: Murray Jensen <Murray.Jensen@csiro.au>
To: u-boot@lists.denx.de
Subject: [U-Boot-Users] relocate_code
Date: Sat, 04 Jan 2003 13:22:18 +1100	[thread overview]
Message-ID: <15932.1041646938@msa.cmst.csiro.au> (raw)
In-Reply-To: Your message of "Sat, 04 Jan 2003 00:22:21 +0800" <3E15B8BD.1030009@sohu.com>

On Sat, 04 Jan 2003 00:22:21 +0800, YanMin Qiao <sepherosa@sohu.com> writes:
...
>    cmplw    cr1,r3,r4
...
>    bge    cr1,2f
...
>1:    lwzu    r0,4(r8)
>    stwu    r0,4(r7)
>    bdnz    1b
>    b    4f
>
>2:    slwi    r0,r0,2        <<----------------- i think above code will 
>be enough for the two        
>    add    r8,r4,r0                                      situation
>    add    r7,r3,r0
>3:    lwzu    r0,-4(r8)
>    stwu    r0,-4(r7)
>    bdnz    3b

One is copying forwards, the other is copying backwards - you can see the
lwzu/stwu pair of instructions either add +4 or -4 to the registers
containing the source and destination addresses (the "u" means to update the
index register with the resulting memory address).

Be careful with the first "bge" above - it isn't testing the result of the
previous instruction, it is testing the result of the "cmplw" done quite a
few instructions beforehand and stored in "cr1" i.e. it will branch if "r3"
(the destination address) is >= "r4" (the source address) i.e. if it is
possible that the copy will overwrite the source.

The Powerpc CPU has four(?) condition code sets where results of operations
can be stored. While I don't understand the details, I presume it has
something to do with the instruction pipeline and avoiding unnecessary
flushes - esp. when you consider that the programmer can indicate whether a
branch is likely or not with a bit in the instruction - I presume (again)
that this determines whether the processor does pre-fetching or something
like that. Details of all this stuff is in the Powerpc Programmer's
Environment Manual (I think).

If you look through the latest linux kernel source you often see things like

	if (unlikely(<condition>)) {

or

	if (likely(<condition>)) {

On powerpc (I'm guessing) these macros will set an attribute for the compiler
which will result in this bit being set or cleared in the branch instruction
of the resulting assembly code - I guess it does something similar for later
Pentium processors (and nothing at all if the processor doesn't have these
sort of features). Cheers!
								Murray...
--
Murray Jensen, CSIRO Manufacturing & Infra. Tech.      Phone: +61 3 9662 7763
Locked Bag No. 9, Preston, Vic, 3072, Australia.         Fax: +61 3 9662 7853
Internet: Murray.Jensen at csiro.au

Hymod project: http://www.msa.cmst.csiro.au/projects/Hymod/

To the extent permitted by law, CSIRO does not represent, warrant and/or
guarantee that the integrity of this communication has been maintained or
that the communication is free of errors, virus, interception or interference.

The information contained in this e-mail may be confidential or privileged.
Any unauthorised use or disclosure is prohibited. If you have received this
e-mail in error, please delete it immediately and notify Murray Jensen on
+61 3 9662 7763. Thank you.

  reply	other threads:[~2003-01-04  2:22 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2003-01-03 16:22 [U-Boot-Users] relocate_code YanMin Qiao
2003-01-04  2:22 ` Murray Jensen [this message]
2003-01-04  2:45   ` YanMin Qiao
2003-01-04  8:08     ` Wolfgang Denk
2003-01-04 12:50     ` Murray Jensen
2003-01-04 13:28       ` YanMin Qiao
  -- strict thread matches above, loose matches on Subject: below --
2003-01-06 15:18 [U-Boot-Users] PPC405GP - uboot - can't get past stackloop Wolfgang Denk
2003-01-20 20:12 ` [U-Boot-Users] relocate code Jerry Walden
2003-01-20 21:23   ` Wolfgang Denk
2004-10-04  6:26 [U-Boot-Users] Relocate code raju rediff
2004-10-04  6:52 Holger L. Bille

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=15932.1041646938@msa.cmst.csiro.au \
    --to=murray.jensen@csiro.au \
    --cc=u-boot@lists.denx.de \
    /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