diff --git a/core/rexcode/isa/x86/encoder.odin b/core/rexcode/isa/x86/encoder.odin index dc28256aa..88b709d99 100644 --- a/core/rexcode/isa/x86/encoder.odin +++ b/core/rexcode/isa/x86/encoder.odin @@ -117,19 +117,26 @@ encode :: proc( #partial switch op.kind { case .REGISTER: // R8-R15, XMM8-31, YMM8-31, ZMM8-31 require REX/VEX/EVEX extension. - if reg_needs_rex(op.reg) { invalid = true; break } + if reg_needs_rex(op.reg) { + invalid = true + break + } // SPL/BPL/SIL/DIL (REG_GPR8 hw 4-7) don't exist in i386; // those encodings decode as AH/CH/DH/BH there. Users // wanting high-byte regs should use REG_GPR8H (AH..BH). if reg_class(op.reg) == REG_GPR8 { hw := reg_hw(op.reg) - if hw >= 4 && hw <= 7 { invalid = true; break } + if hw >= 4 && hw <= 7 { + invalid = true + break + } } case .MEMORY: m := op.mem if (mem_has_base(m) && m.base_ext) || (mem_has_index(m) && m.index_ext) { - invalid = true; break + invalid = true + break } } } @@ -222,17 +229,26 @@ encode :: proc( // only the explicit slots (skipping implicit). For non-implicit forms // the two are identical (operand_count == total), so nothing changes. total_form_ops := 0 - for op in enc.ops { if op == .NONE { break }; total_form_ops += 1 } + for op in enc.ops { + if op == .NONE { + break + } + total_form_ops += 1 + } fully_explicit := int(inst.operand_count) == total_form_ops user_idx := 0 for op, i in enc.ops { - if op == .NONE { break } + if op == .NONE { + break + } uop: ^Operand if fully_explicit { uop = &inst.ops[i] } else if !is_implicit_op_inline(op) { - if user_idx < int(inst.operand_count) { uop = &inst.ops[user_idx] } + if user_idx < int(inst.operand_count) { + uop = &inst.ops[user_idx] + } user_idx += 1 } if uop != nil { @@ -309,8 +325,14 @@ encode :: proc( #partial switch enc.flags.vex_type{ case .VEX: // VEX prefix encoding - r: u8 = 1; x: u8 = 1; b: u8 = 1 - vvvv: u8 = 0xF; l: u8 = 0; pp: u8 = 0; mmmmm: u8 = 1; w: u8 = 0 + r: u8 = 1 + x: u8 = 1 + b: u8 = 1 + vvvv: u8 = 0xF + l: u8 = 0 + pp: u8 = 0 + mmmmm: u8 = 1 + w: u8 = 0 #partial switch enc.flags.esc { case ._0F: mmmmm = 1 @@ -336,7 +358,9 @@ encode :: proc( // contributions, gate by kind, clear the inverted bit via AND-mask). for enc_type, i in enc.enc { user_op := user_ops[i] - if user_op == nil { continue } + if user_op == nil { + continue + } is_reg := user_op.kind == .REGISTER is_mem := user_op.kind == .MEMORY @@ -371,9 +395,19 @@ encode :: proc( case .EVEX: // EVEX prefix encoding (4 bytes) - r: u8 = 1; x: u8 = 1; b: u8 = 1; rr: u8 = 1 - mm: u8 = 1; w: u8 = 0; vvvv: u8 = 0xF; pp: u8 = 0 - z: u8 = 0; ll: u8 = 0; bb: u8 = 0; vvv: u8 = 1; aaa: u8 = 0 + r: u8 = 1 + x: u8 = 1 + b: u8 = 1 + rr: u8 = 1 + mm: u8 = 1 + w: u8 = 0 + vvvv: u8 = 0xF + pp: u8 = 0 + z: u8 = 0 + ll: u8 = 0 + bb: u8 = 0 + vvv: u8 = 1 + aaa: u8 = 0 #partial switch enc.flags.esc { case ._0F: mm = 1 @@ -398,7 +432,9 @@ encode :: proc( for i in 0..<4 { user_op := user_ops[i] - if user_op == nil { continue } + if user_op == nil { + continue + } is_reg := user_op.kind == .REGISTER is_mem := user_op.kind == .MEMORY @@ -511,10 +547,12 @@ encode :: proc( out[pos] = 0x0F pos += 1 case ._0F38: - out[pos] = 0x0F; out[pos+1] = 0x38 + out[pos+0] = 0x0F + out[pos+1] = 0x38 pos += 2 case ._0F3A: - out[pos] = 0x0F; out[pos+1] = 0x3A + out[pos+0] = 0x0F + out[pos+1] = 0x3A pos += 2 } } @@ -653,7 +691,10 @@ encode :: proc( // bytes are written past the real size. if disp_is_label { append(&pending_relocations, Relocation{byte_count + pos, disp_label_id, 0, .REL32, 4, u16(instruction_index)}) - out[pos] = 0; out[pos+1] = 0; out[pos+2] = 0; out[pos+3] = 0 + out[pos+0] = 0 + out[pos+1] = 0 + out[pos+2] = 0 + out[pos+3] = 0 pos += 4 } else { for _ in 0..> 8) + out[pos=0] = u8(v) + out[pos+1] = u8(v >> 8) pos += 2 } case .ID: #partial switch user_op.kind { case .IMMEDIATE: v := u32(user_op.immediate) - out[pos] = u8(v); out[pos+1] = u8(v >> 8); out[pos+2] = u8(v >> 16); out[pos+3] = u8(v >> 24) + out[pos+0] = u8(v) + out[pos+1] = u8(v >> 8) + out[pos+2] = u8(v >> 16) + out[pos+3] = u8(v >> 24) pos += 4 case .RELATIVE: label_id := u32(user_op.relative) append(&pending_relocations, Relocation{byte_count + pos, label_id, 0, .REL32, 4, u16(instruction_index)}) - out[pos] = 0; out[pos+1] = 0; out[pos+2] = 0; out[pos+3] = 0 + out[pos+0] = 0 + out[pos+1] = 0 + out[pos+2] = 0 + out[pos+3] = 0 pos += 4 } case .IQ: @@ -718,13 +768,25 @@ encode :: proc( // movabs reg,