load delay

Discuss the development of new homebrew software, tools and libraries.

Moderators: cheriff, TyRaNiD

Post Reply
johnmph
Posts: 119
Joined: Sat Jul 23, 2005 11:48 pm

load delay

Post by johnmph »

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 »

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?
http://www.dtek.chalmers.se/~tronic/PSPTexTool.zip Free texture converter for PSP with source. More to come.
BlackDiamond
Posts: 16
Joined: Sat Jul 02, 2005 7:31 pm
Location: Paris, FRANCE

Post by BlackDiamond »

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.
User avatar
groepaz
Posts: 305
Joined: Thu Sep 01, 2005 7:44 am
Contact:

Post by groepaz »

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 »

yep, got rid of the 2 wasted cycles :)
johnmph
Posts: 119
Joined: Sat Jul 23, 2005 11:48 pm

Post by johnmph »

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 »

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 »

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 ;-)
Post Reply