Reordered jump cases

This commit is contained in:
Eduard Urbach 2024-07-11 11:53:49 +02:00
parent e24d9ebb50
commit c2401bf826
Signed by: akyoto
GPG Key ID: C874F672B1AF20C0
2 changed files with 6 additions and 7 deletions

View File

@ -3,7 +3,7 @@ main() {
} }
fibonacci(x) { fibonacci(x) {
if x == 1 || x == 0 { if x <= 1 {
return x return x
} }

View File

@ -81,22 +81,22 @@ func (a Assembler) Finalize() ([]byte, []byte) {
code = x64.CompareRegisterRegister(code, operands.Destination, operands.Source) code = x64.CompareRegisterRegister(code, operands.Destination, operands.Source)
} }
case JUMP, JE, JNE, JG, JL, JGE, JLE: case JE, JNE, JG, JGE, JL, JLE, JUMP:
switch x.Mnemonic { switch x.Mnemonic {
case JUMP:
code = x64.Jump8(code, 0x00)
case JE: case JE:
code = x64.Jump8IfEqual(code, 0x00) code = x64.Jump8IfEqual(code, 0x00)
case JNE: case JNE:
code = x64.Jump8IfNotEqual(code, 0x00) code = x64.Jump8IfNotEqual(code, 0x00)
case JG: case JG:
code = x64.Jump8IfGreater(code, 0x00) code = x64.Jump8IfGreater(code, 0x00)
case JL:
code = x64.Jump8IfLess(code, 0x00)
case JGE: case JGE:
code = x64.Jump8IfGreaterOrEqual(code, 0x00) code = x64.Jump8IfGreaterOrEqual(code, 0x00)
case JL:
code = x64.Jump8IfLess(code, 0x00)
case JLE: case JLE:
code = x64.Jump8IfLessOrEqual(code, 0x00) code = x64.Jump8IfLessOrEqual(code, 0x00)
case JUMP:
code = x64.Jump8(code, 0x00)
} }
size := 1 size := 1
@ -183,7 +183,6 @@ restart:
jump = []byte{0x0F, 0x8F} jump = []byte{0x0F, 0x8F}
case 0xEB: // JMP case 0xEB: // JMP
jump = []byte{0xE9} jump = []byte{0xE9}
default: default:
panic(fmt.Errorf("failed to increase pointer size for instruction 0x%x", opCode)) panic(fmt.Errorf("failed to increase pointer size for instruction 0x%x", opCode))
} }