linux-mips
[Top] [All Lists]

Re: Delayed jumps and branches

To: linux-mips@linux-mips.org
Subject: Re: Delayed jumps and branches
From: Thiemo Seufer <ica2_ts@csv.ica.uni-stuttgart.de>
Date: Tue, 17 Sep 2002 17:42:01 +0200
In-reply-to: <20020917161959.33787757.g.c.bransby-99@student.lboro.ac.uk>
Original-recipient: rfc822;linux-mips@linux-mips.org
References: <20020917161959.33787757.g.c.bransby-99@student.lboro.ac.uk>
Sender: linux-mips-bounce@linux-mips.org
User-agent: Mutt/1.4i
Gareth wrote:
> Hi,
> 
> I have been going through my mips architecture book learning about the delay
> slots used in loads, jumps and branches and I am in need of some 
> clarification.
> The instruction just after the jump instruction is always executed wether the
> jump is taken or not, right?

There are no conditional jumps, so you are right. :-)

> So the compiler can re-aarange the assembly to
> take advantage of this, but if no instruction (that can be executed wether the
> jump is taken or not) can be placed after the jump, a nop is used intstead. So
> take this code for example :
> 
>     jal <my_function>
>     li  $s2, 3
>     li  $v0, 2

The register name is either "$2" or "v0".

> If the jump is not taken, it requires 3 cycles to execute these 3 
> instructions.
> If the jump is taken, it requires 3 cycles to execute the first instruction of
> my_function, and li $s2, 3 is executed.
> 
> Is my reasoning correct?

Yes, if it was e.g.

        beq     t0, zero, <my_function>

instead of jal. Note that the "branch likely" variants don't execute the
delay slot if not taken.


Thiemo

<Prev in Thread] Current Thread [Next in Thread>