lupino3/edumips64 — Issue #7: Incorrect behaviour of MOVN and MOVZ
Author: lupino3
Created: 2012-02-12 15:11:21+00:00
State: open

According to the MIPS64 manual, the MOVN instruction should behave in this way:

movn rd,rs,rt => if (rt != 0) then rd = rs;

running the following code:

daddi r1,r0,0 ; r1=0
daddi r2,r0,1 ; r2=1
daddi r3,r0,2 ; r3=2
movn r3,r2,r1 ; if (r1 != 0) r3=r2;
syscall 0

;result: r1=0, r2=1, r3=0 (instead of r3=2)
If you insert 2 NOP instructions before the MOVN instruction, the result is correct. So maybe the error is caused by some hazard in the pipeline:

daddi r1,r0,0 ; r1=0
daddi r2,r0,1 ; r2=1
daddi r3,r0,2 ; r3=2
nop
nop
movn r3,r2,r1 ; if (r1 != 0) r3=r2;
syscall 0

;correct final result: r1=0, r2=1, r3=2
The same goes for MOVZ.

If you enable forwarding, the instructions work correctly.