Discuss the development of new homebrew software, tools and libraries.
Moderators: cheriff , TyRaNiD
johnmph
Posts: 119 Joined: Sat Jul 23, 2005 11:48 pm
Post
by johnmph » Wed May 24, 2006 9:18 pm
Hello, i would like to know why this small code works :
Code: Select all
.set noreorder
.global func
.ent func
func:
lw $a2, 0x0($a0)
sw $a2, 0x0($a1)
jr $ra
nop
.end func
In the mips documentation, load in memory uses delay : "you *must* have an instruction following a load that does not use the result of the load".
However, this code uses the result of the load immediately after and he works.
Is what it is because the compiler arranges the code ? (even with .set noreorder directive ?)
ector
Posts: 195 Joined: Thu May 12, 2005 10:22 pm
Post
by ector » Wed May 24, 2006 9:39 pm
No modern MIPS CPU:s that I know of have this limitation. They all added forwarding, fixing this problem, in something like 1992. What documentation are you reading?
BlackDiamond
Posts: 16 Joined: Sat Jul 02, 2005 7:31 pm
Location: Paris, FRANCE
Post
by BlackDiamond » Wed May 24, 2006 10:12 pm
Modern MIPS CPUs can (partially) stall the pipeline and wait for the result to be availiable. So no interlaced instruction is needed but the delay is still here.
groepaz
Posts: 305 Joined: Thu Sep 01, 2005 7:44 am
Contact:
Post
by groepaz » Wed May 24, 2006 10:20 pm
conclusion, make it
Code: Select all
lw $a2, 0x0($a0)
jr $ra
sw $a2, 0x0($a1)
:)
BlackDiamond
Posts: 16 Joined: Sat Jul 02, 2005 7:31 pm
Location: Paris, FRANCE
Post
by BlackDiamond » Thu May 25, 2006 12:36 am
yep, got rid of the 2 wasted cycles :)
johnmph
Posts: 119 Joined: Sat Jul 23, 2005 11:48 pm
Post
by johnmph » Thu May 25, 2006 12:58 am
Thanks all.
groepaz wrote: conclusion, make it
Code: Select all
lw $a2, 0x0($a0)
jr $ra
sw $a2, 0x0($a1)
:)
yes, it's the code that i will use.
johnmph
Posts: 119 Joined: Sat Jul 23, 2005 11:48 pm
Post
by johnmph » Sun May 28, 2006 10:01 pm
one more question :
write in memory has also a delay like read ?
In documentation, it talks about load only.
Thanks
johnmph
Posts: 119 Joined: Sat Jul 23, 2005 11:48 pm
Post
by johnmph » Mon May 29, 2006 5:58 am
johnmph wrote: one more question :
write in memory has also a delay like read ?
In documentation, it talks about load only.
Thanks
oups, stupid question.
Even if write has a delay, registers are not affected and even if i read memory just after having written this memory, load creates a delay, thus no problem ;-)