This is the mail archive of the
binutils@sourceware.org
mailing list for the binutils project.
Re: [MIPS] avoiding certain instruction in delay slots
- From: "Maciej W. Rozycki" <macro at linux-mips dot org>
- To: Sven Anderson <sven at anderson dot de>
- Cc: binutils at sourceware dot org
- Date: Tue, 4 Feb 2014 09:00:14 +0000 (GMT)
- Subject: Re: [MIPS] avoiding certain instruction in delay slots
- Authentication-results: sourceware.org; auth=none
- References: <52EF785C dot 7010509 at anderson dot de> <87fvo0dz1g dot fsf at sandifor-thinkpad dot stglab dot manchester dot uk dot ibm dot com> <alpine dot LFD dot 2 dot 10 dot 1402031506320 dot 3940 at eddie dot linux-mips dot org> <8093B4BE-FDE3-4138-A698-BE1D01DEDBD8 at anderson dot de>
On Tue, 4 Feb 2014, Sven Anderson wrote:
> > You'd have to teach GAS to bail out on delay slots already scheduled
> > manually in handcoded assembly too, e.g.:
> >
> > .set noreorder
> > beqz $2, foo
> > lw $2, 8($sp)
> >
> > cannot be resolved automatically (the two instructions cannot be swapped
> > and NOP inserted in the delay slot instead; not that GAS already supports
> > it anyway) because of a data dependency on $2 and you do want to make the
> > user aware of this issue so that they can rewrite code instead.
>
> Is it really like that? I assumed the dependency would trigger a hazard
> and the branch would wait for $2 to be ready?
There is no hazard. The branch uses the old contents of $2 and then the
delay-slot instruction replaces the contents with a new value. Therefore
without rewriting this piece of code you can't move the LW instruction out
of the delay slot. This could be an equivalent:
.set noreorder
.set noat
move $1, $2
lw $2, 8($sp)
beqz $1, foo
nop
assuming that $1 is available (of course you don't need `.set noreorder'
and the manual delay slot scheduling with a NOP instruction here; I just
wrote it like this for illustration how actual code will look like).
In some cases it may be trickier, in particular where the delay-slot
instruction is a target of a branch, which might be possible in
hand-optimised code.
Maciej