Improved assembler performance
This commit is contained in:
@ -8,40 +8,49 @@ import (
|
||||
func (c *compiler) compileX86(x asm.Instruction) {
|
||||
switch x.Mnemonic {
|
||||
case asm.ADD:
|
||||
switch operands := x.Data.(type) {
|
||||
case *asm.RegisterNumber:
|
||||
switch x.Type {
|
||||
case asm.TypeRegisterNumber:
|
||||
operands := c.assembler.Param.RegisterNumber[x.Index]
|
||||
c.code = x86.AddRegisterNumber(c.code, operands.Register, operands.Number)
|
||||
case *asm.RegisterRegister:
|
||||
case asm.TypeRegisterRegister:
|
||||
operands := c.assembler.Param.RegisterRegister[x.Index]
|
||||
c.code = x86.AddRegisterRegister(c.code, operands.Destination, operands.Source)
|
||||
}
|
||||
|
||||
case asm.AND:
|
||||
switch operands := x.Data.(type) {
|
||||
case *asm.RegisterNumber:
|
||||
switch x.Type {
|
||||
case asm.TypeRegisterNumber:
|
||||
operands := c.assembler.Param.RegisterNumber[x.Index]
|
||||
c.code = x86.AndRegisterNumber(c.code, operands.Register, operands.Number)
|
||||
case *asm.RegisterRegister:
|
||||
case asm.TypeRegisterRegister:
|
||||
operands := c.assembler.Param.RegisterRegister[x.Index]
|
||||
c.code = x86.AndRegisterRegister(c.code, operands.Destination, operands.Source)
|
||||
}
|
||||
|
||||
case asm.SUB:
|
||||
switch operands := x.Data.(type) {
|
||||
case *asm.RegisterNumber:
|
||||
switch x.Type {
|
||||
case asm.TypeRegisterNumber:
|
||||
operands := c.assembler.Param.RegisterNumber[x.Index]
|
||||
c.code = x86.SubRegisterNumber(c.code, operands.Register, operands.Number)
|
||||
case *asm.RegisterRegister:
|
||||
case asm.TypeRegisterRegister:
|
||||
operands := c.assembler.Param.RegisterRegister[x.Index]
|
||||
c.code = x86.SubRegisterRegister(c.code, operands.Destination, operands.Source)
|
||||
}
|
||||
|
||||
case asm.MUL:
|
||||
switch operands := x.Data.(type) {
|
||||
case *asm.RegisterNumber:
|
||||
switch x.Type {
|
||||
case asm.TypeRegisterNumber:
|
||||
operands := c.assembler.Param.RegisterNumber[x.Index]
|
||||
c.code = x86.MulRegisterNumber(c.code, operands.Register, operands.Number)
|
||||
case *asm.RegisterRegister:
|
||||
case asm.TypeRegisterRegister:
|
||||
operands := c.assembler.Param.RegisterRegister[x.Index]
|
||||
c.code = x86.MulRegisterRegister(c.code, operands.Destination, operands.Source)
|
||||
}
|
||||
|
||||
case asm.DIV:
|
||||
switch operands := x.Data.(type) {
|
||||
case *asm.RegisterRegister:
|
||||
switch x.Type {
|
||||
case asm.TypeRegisterRegister:
|
||||
operands := c.assembler.Param.RegisterRegister[x.Index]
|
||||
if operands.Destination != x86.RAX {
|
||||
c.code = x86.MoveRegisterRegister(c.code, x86.RAX, operands.Destination)
|
||||
}
|
||||
@ -55,8 +64,9 @@ func (c *compiler) compileX86(x asm.Instruction) {
|
||||
}
|
||||
|
||||
case asm.MODULO:
|
||||
switch operands := x.Data.(type) {
|
||||
case *asm.RegisterRegister:
|
||||
switch x.Type {
|
||||
case asm.TypeRegisterRegister:
|
||||
operands := c.assembler.Param.RegisterRegister[x.Index]
|
||||
if operands.Destination != x86.RAX {
|
||||
c.code = x86.MoveRegisterRegister(c.code, x86.RAX, operands.Destination)
|
||||
}
|
||||
@ -76,10 +86,12 @@ func (c *compiler) compileX86(x asm.Instruction) {
|
||||
return
|
||||
|
||||
case asm.COMPARE:
|
||||
switch operands := x.Data.(type) {
|
||||
case *asm.RegisterNumber:
|
||||
switch x.Type {
|
||||
case asm.TypeRegisterNumber:
|
||||
operands := c.assembler.Param.RegisterNumber[x.Index]
|
||||
c.code = x86.CompareRegisterNumber(c.code, operands.Register, operands.Number)
|
||||
case *asm.RegisterRegister:
|
||||
case asm.TypeRegisterRegister:
|
||||
operands := c.assembler.Param.RegisterRegister[x.Index]
|
||||
c.code = x86.CompareRegisterRegister(c.code, operands.Destination, operands.Source)
|
||||
}
|
||||
|
||||
@ -90,7 +102,7 @@ func (c *compiler) compileX86(x asm.Instruction) {
|
||||
c.jump(x)
|
||||
|
||||
case asm.LABEL:
|
||||
label := x.Data.(*asm.Label)
|
||||
label := c.assembler.Param.Label[x.Index]
|
||||
c.codeLabels[label.Name] = Address(len(c.code))
|
||||
|
||||
case asm.LOAD:
|
||||
@ -100,30 +112,36 @@ func (c *compiler) compileX86(x asm.Instruction) {
|
||||
c.move(x)
|
||||
|
||||
case asm.NEGATE:
|
||||
switch operands := x.Data.(type) {
|
||||
case *asm.Register:
|
||||
switch x.Type {
|
||||
case asm.TypeRegister:
|
||||
operands := c.assembler.Param.Register[x.Index]
|
||||
c.code = x86.NegateRegister(c.code, operands.Register)
|
||||
}
|
||||
|
||||
case asm.OR:
|
||||
switch operands := x.Data.(type) {
|
||||
case *asm.RegisterNumber:
|
||||
switch x.Type {
|
||||
case asm.TypeRegisterNumber:
|
||||
operands := c.assembler.Param.RegisterNumber[x.Index]
|
||||
c.code = x86.OrRegisterNumber(c.code, operands.Register, operands.Number)
|
||||
case *asm.RegisterRegister:
|
||||
case asm.TypeRegisterRegister:
|
||||
operands := c.assembler.Param.RegisterRegister[x.Index]
|
||||
c.code = x86.OrRegisterRegister(c.code, operands.Destination, operands.Source)
|
||||
}
|
||||
|
||||
case asm.POP:
|
||||
switch operands := x.Data.(type) {
|
||||
case *asm.Register:
|
||||
switch x.Type {
|
||||
case asm.TypeRegister:
|
||||
operands := c.assembler.Param.Register[x.Index]
|
||||
c.code = x86.PopRegister(c.code, operands.Register)
|
||||
}
|
||||
|
||||
case asm.PUSH:
|
||||
switch operands := x.Data.(type) {
|
||||
case *asm.Number:
|
||||
switch x.Type {
|
||||
case asm.TypeNumber:
|
||||
operands := c.assembler.Param.Number[x.Index]
|
||||
c.code = x86.PushNumber(c.code, int32(operands.Number))
|
||||
case *asm.Register:
|
||||
case asm.TypeRegister:
|
||||
operands := c.assembler.Param.Register[x.Index]
|
||||
c.code = x86.PushRegister(c.code, operands.Register)
|
||||
}
|
||||
|
||||
@ -131,14 +149,16 @@ func (c *compiler) compileX86(x asm.Instruction) {
|
||||
c.code = x86.Return(c.code)
|
||||
|
||||
case asm.SHIFTL:
|
||||
switch operands := x.Data.(type) {
|
||||
case *asm.RegisterNumber:
|
||||
switch x.Type {
|
||||
case asm.TypeRegisterNumber:
|
||||
operands := c.assembler.Param.RegisterNumber[x.Index]
|
||||
c.code = x86.ShiftLeftNumber(c.code, operands.Register, byte(operands.Number)&0b111111)
|
||||
}
|
||||
|
||||
case asm.SHIFTRS:
|
||||
switch operands := x.Data.(type) {
|
||||
case *asm.RegisterNumber:
|
||||
switch x.Type {
|
||||
case asm.TypeRegisterNumber:
|
||||
operands := c.assembler.Param.RegisterNumber[x.Index]
|
||||
c.code = x86.ShiftRightSignedNumber(c.code, operands.Register, byte(operands.Number)&0b111111)
|
||||
}
|
||||
|
||||
@ -149,10 +169,12 @@ func (c *compiler) compileX86(x asm.Instruction) {
|
||||
c.code = x86.Syscall(c.code)
|
||||
|
||||
case asm.XOR:
|
||||
switch operands := x.Data.(type) {
|
||||
case *asm.RegisterNumber:
|
||||
switch x.Type {
|
||||
case asm.TypeRegisterNumber:
|
||||
operands := c.assembler.Param.RegisterNumber[x.Index]
|
||||
c.code = x86.XorRegisterNumber(c.code, operands.Register, operands.Number)
|
||||
case *asm.RegisterRegister:
|
||||
case asm.TypeRegisterRegister:
|
||||
operands := c.assembler.Param.RegisterRegister[x.Index]
|
||||
c.code = x86.XorRegisterRegister(c.code, operands.Destination, operands.Source)
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user