Removed unnecessary instructions
This commit is contained in:
parent
88be002c45
commit
cdbfa744b7
@ -11,20 +11,27 @@ func (f *Machine) RegisterNumber(mnemonic asm.Mnemonic, a cpu.Register, b int) {
|
|||||||
f.SaveRegister(a)
|
f.SaveRegister(a)
|
||||||
}
|
}
|
||||||
|
|
||||||
if sizeof.Signed(int64(b)) == 8 {
|
// The `MOVE` operation is very flexible and works with any type of immediate number.
|
||||||
tmp := f.NewRegister()
|
if mnemonic == asm.MOVE {
|
||||||
f.Assembler.RegisterNumber(asm.MOVE, tmp, b)
|
|
||||||
f.UseRegister(tmp)
|
|
||||||
f.postInstruction()
|
|
||||||
f.Assembler.RegisterRegister(mnemonic, a, tmp)
|
|
||||||
f.postInstruction()
|
|
||||||
f.FreeRegister(tmp)
|
|
||||||
} else {
|
|
||||||
f.Assembler.RegisterNumber(mnemonic, a, b)
|
f.Assembler.RegisterNumber(mnemonic, a, b)
|
||||||
|
f.UseRegister(a)
|
||||||
f.postInstruction()
|
f.postInstruction()
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if mnemonic == asm.MOVE {
|
// If the number only needs 32 bits, we can encode the instruction.
|
||||||
f.UseRegister(a)
|
if sizeof.Signed(int64(b)) <= 4 {
|
||||||
|
f.Assembler.RegisterNumber(mnemonic, a, b)
|
||||||
|
f.postInstruction()
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// If the number needs 64 bits, we need to use a temporary register.
|
||||||
|
tmp := f.NewRegister()
|
||||||
|
f.Assembler.RegisterNumber(asm.MOVE, tmp, b)
|
||||||
|
f.UseRegister(tmp)
|
||||||
|
f.postInstruction()
|
||||||
|
f.Assembler.RegisterRegister(mnemonic, a, tmp)
|
||||||
|
f.postInstruction()
|
||||||
|
f.FreeRegister(tmp)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user