This is the mail archive of the binutils@sourceware.org mailing list for the binutils project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [MIPS] avoiding certain instruction in delay slots


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]