From: "Kevin D. Kissell" <kevink@mips.com>
To: "Ralf Baechle" <ralf@oss.sgi.com>,
"Maciej W. Rozycki" <macro@ds2.pg.gda.pl>
Cc: "Thiemo Seufer" <ica2_ts@csv.ica.uni-stuttgart.de>,
<linux-mips@oss.sgi.com>
Subject: Re: sti() does not work.
Date: Sat, 14 Jul 2001 13:39:58 +0200 [thread overview]
Message-ID: <007f01c10c59$bbe8bfa0$0deca8c0@Ulysses> (raw)
In-Reply-To: 20010714130448.C6713@bacchus.dhis.org
> Real wild pig hackers on R3000 were writing code which knows that in the
> load delay slot they still have the old register value available. So you
> can implement var1++; var2++ as:
>
> .set noreorder
> lw $reg, var1($gp)
> nop
> addiu $reg, $reg, 1
> lw $reg, var2($gp)
> sw $reg, var1($gp)
> addiu $reg, $reg, 1
> sw $reg, var2($gp)
>
> .common var1, 4, 4
> .common var2, 4, 4
>
> Of course only safe with interrupts disabled. So in a sense introducing
> the load interlock broke semantics of MIPS machine code ;-)
Architecturally, the target register value is UNDEFINED during
the load delay slot on a MIPS I CPU. Anyone who coded to any
particular assumption regarding its value was coding to a
specific CPU implementation. Introducing the load interlock
in later versions of the ISA and later implementations did not
reach backward in time and break the old hardware. The
implementation-specific code still works for its specific
implementation. Refining the spec did not break the code for later
implementations - it was *always* broken for later implementations! ;-)
In a less pedantic tone, there actually is an architecturally
legal case where an assembly coder can justify the use of
noreorder for something other than CP0 pipeline hazards.
If what I want to do is to test a value, branch on the result,
and modify that value regardless of whether the branch is
taken, I can code something like:
.set noreorder
bltz t0,foo
sra t0,t0,2
.set reorder
<other code>
foo:
Whereas otherwise I need to either consume another
register or replicate the shift both after the branch and
after foo. If I'm very very lucky, the assembler will "hoist"
such a replicated instruction into the delay slot - a good
compiler back-end optimiser certainly would. But I'm not
aware of any MIPS assembler that would perform that
optimisation - certainly the GNU assembler does not.
Kevin K.
WARNING: multiple messages have this Message-ID (diff)
From: "Kevin D. Kissell" <kevink@mips.com>
To: Ralf Baechle <ralf@oss.sgi.com>,
"Maciej W. Rozycki" <macro@ds2.pg.gda.pl>
Cc: Thiemo Seufer <ica2_ts@csv.ica.uni-stuttgart.de>, linux-mips@oss.sgi.com
Subject: Re: sti() does not work.
Date: Sat, 14 Jul 2001 13:39:58 +0200 [thread overview]
Message-ID: <007f01c10c59$bbe8bfa0$0deca8c0@Ulysses> (raw)
Message-ID: <20010714113958.nhTd9Pt9-QCAVWyunyyYiv5IHSOidAreDCHq4qMq-0c@z> (raw)
In-Reply-To: 20010714130448.C6713@bacchus.dhis.org
> Real wild pig hackers on R3000 were writing code which knows that in the
> load delay slot they still have the old register value available. So you
> can implement var1++; var2++ as:
>
> .set noreorder
> lw $reg, var1($gp)
> nop
> addiu $reg, $reg, 1
> lw $reg, var2($gp)
> sw $reg, var1($gp)
> addiu $reg, $reg, 1
> sw $reg, var2($gp)
>
> .common var1, 4, 4
> .common var2, 4, 4
>
> Of course only safe with interrupts disabled. So in a sense introducing
> the load interlock broke semantics of MIPS machine code ;-)
Architecturally, the target register value is UNDEFINED during
the load delay slot on a MIPS I CPU. Anyone who coded to any
particular assumption regarding its value was coding to a
specific CPU implementation. Introducing the load interlock
in later versions of the ISA and later implementations did not
reach backward in time and break the old hardware. The
implementation-specific code still works for its specific
implementation. Refining the spec did not break the code for later
implementations - it was *always* broken for later implementations! ;-)
In a less pedantic tone, there actually is an architecturally
legal case where an assembly coder can justify the use of
noreorder for something other than CP0 pipeline hazards.
If what I want to do is to test a value, branch on the result,
and modify that value regardless of whether the branch is
taken, I can code something like:
.set noreorder
bltz t0,foo
sra t0,t0,2
.set reorder
<other code>
foo:
Whereas otherwise I need to either consume another
register or replicate the shift both after the branch and
after foo. If I'm very very lucky, the assembler will "hoist"
such a replicated instruction into the delay slot - a good
compiler back-end optimiser certainly would. But I'm not
aware of any MIPS assembler that would perform that
optimisation - certainly the GNU assembler does not.
Kevin K.
next prev parent reply other threads:[~2001-07-14 11:35 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2001-07-03 22:48 sti() does not work Steven Liu
2001-07-03 22:48 ` Steven Liu
2001-07-04 10:23 ` Thiemo Seufer
2001-07-04 12:23 ` Gleb O. Raiko
2001-07-04 13:26 ` Ralf Baechle
2001-07-05 11:35 ` Maciej W. Rozycki
2001-07-13 11:35 ` Ralf Baechle
2001-07-13 14:01 ` Maciej W. Rozycki
2001-07-14 11:04 ` Ralf Baechle
2001-07-14 11:39 ` Kevin D. Kissell [this message]
2001-07-14 11:39 ` Kevin D. Kissell
2001-07-16 12:46 ` Maciej W. Rozycki
2001-07-04 13:29 ` Ralf Baechle
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='007f01c10c59$bbe8bfa0$0deca8c0@Ulysses' \
--to=kevink@mips.com \
--cc=ica2_ts@csv.ica.uni-stuttgart.de \
--cc=linux-mips@oss.sgi.com \
--cc=macro@ds2.pg.gda.pl \
--cc=ralf@oss.sgi.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