<NME> jit_instructions.rs <BEF> #![allow(non_snake_case)] use codegen; use codegen::BitSize; use cpu::cpu::{ FLAGS_ALL, FLAGS_DEFAULT, FLAGS_MASK, FLAG_ADJUST, FLAG_CARRY, FLAG_DIRECTION, FLAG_INTERRUPT, FLAG_IOPL, FLAG_OVERFLOW, FLAG_SUB, FLAG_VM, FLAG_ZERO, OPSIZE_8, OPSIZE_16, OPSIZE_32, }; use cpu::global_pointers; use jit::{Instruction, InstructionOperand, JitContext}; use modrm::{jit_add_seg_offset, jit_add_seg_offset_no_override, ModrmByte}; use prefix::SEG_PREFIX_ZERO; use prefix::{PREFIX_66, PREFIX_67, PREFIX_F2, PREFIX_F3}; use regs; use regs::{AX, BP, BX, CX, DI, DX, SI, SP}; use regs::{CS, DS, ES, FS, GS, SS}; use regs::{EAX, EBP, EBX, ECX, EDI, EDX, ESI, ESP}; use wasmgen::wasm_builder::{WasmBuilder, WasmLocal}; enum LocalOrImmediate<'a> { WasmLocal(&'a WasmLocal), Immediate(i32), } impl<'a> LocalOrImmediate<'a> { pub fn gen_get(&self, builder: &mut WasmBuilder) { match self { LocalOrImmediate::WasmLocal(l) => builder.get_local(l), LocalOrImmediate::Immediate(i) => builder.const_i32(*i), } } pub fn gen_get_mask255(&self, builder: &mut WasmBuilder) { match self { LocalOrImmediate::WasmLocal(l) => { builder.get_local(l); builder.const_i32(0xFF); builder.and_i32() }, LocalOrImmediate::Immediate(i) => builder.const_i32(*i & 0xFF), } } pub fn eq_local(&self, other_local: &WasmLocal) -> bool { match self { &LocalOrImmediate::WasmLocal(local) => local == other_local, LocalOrImmediate::Immediate(_) => false, } } pub fn is_zero(&self) -> bool { match self { LocalOrImmediate::Immediate(0) => true, _ => false, } } } pub fn jit_instruction(ctx: &mut JitContext, instr_flags: &mut u32) { ctx.cpu.prefixes = 0; ctx.start_of_current_instruction = ctx.cpu.eip; ::gen::jit::jit( ctx.cpu.read_imm8() as u32 | (ctx.cpu.osize_32() as u32) << 8, ctx, instr_flags, ); } pub fn jit_handle_prefix(ctx: &mut JitContext, instr_flags: &mut u32) { ::gen::jit::jit( ctx.cpu.read_imm8() as u32 | (ctx.cpu.osize_32() as u32) << 8, ctx, instr_flags, ); } pub fn jit_handle_segment_prefix(segment: u32, ctx: &mut JitContext, instr_flags: &mut u32) { dbg_assert!(segment <= 5); ctx.cpu.prefixes |= segment + 1; jit_handle_prefix(ctx, instr_flags) } pub fn instr16_0F_jit(ctx: &mut JitContext, instr_flags: &mut u32) { ::gen::jit0f::jit(ctx.cpu.read_imm8() as u32, ctx, instr_flags) } pub fn instr32_0F_jit(ctx: &mut JitContext, instr_flags: &mut u32) { ::gen::jit0f::jit(ctx.cpu.read_imm8() as u32 | 0x100, ctx, instr_flags) } pub fn instr_26_jit(ctx: &mut JitContext, instr_flags: &mut u32) { jit_handle_segment_prefix(ES, ctx, instr_flags) } pub fn instr_2E_jit(ctx: &mut JitContext, instr_flags: &mut u32) { jit_handle_segment_prefix(CS, ctx, instr_flags) } pub fn instr_36_jit(ctx: &mut JitContext, instr_flags: &mut u32) { jit_handle_segment_prefix(SS, ctx, instr_flags) } pub fn instr_3E_jit(ctx: &mut JitContext, instr_flags: &mut u32) { jit_handle_segment_prefix(DS, ctx, instr_flags) } pub fn instr_64_jit(ctx: &mut JitContext, instr_flags: &mut u32) { jit_handle_segment_prefix(FS, ctx, instr_flags) } pub fn instr_65_jit(ctx: &mut JitContext, instr_flags: &mut u32) { jit_handle_segment_prefix(GS, ctx, instr_flags) } pub fn instr_66_jit(ctx: &mut JitContext, instr_flags: &mut u32) { ctx.cpu.prefixes |= PREFIX_66; jit_handle_prefix(ctx, instr_flags) } pub fn instr_67_jit(ctx: &mut JitContext, instr_flags: &mut u32) { ctx.cpu.prefixes |= PREFIX_67; jit_handle_prefix(ctx, instr_flags) } pub fn instr_F0_jit(ctx: &mut JitContext, instr_flags: &mut u32) { // lock: Ignore jit_handle_prefix(ctx, instr_flags) } pub fn instr_F2_jit(ctx: &mut JitContext, instr_flags: &mut u32) { ctx.cpu.prefixes |= PREFIX_F2; jit_handle_prefix(ctx, instr_flags) } pub fn instr_F3_jit(ctx: &mut JitContext, instr_flags: &mut u32) { ctx.cpu.prefixes |= PREFIX_F3; jit_handle_prefix(ctx, instr_flags) } fn sse_read_f32_xmm_mem(ctx: &mut JitContext, name: &str, modrm_byte: ModrmByte, r: u32) { codegen::gen_modrm_resolve_safe_read32(ctx, modrm_byte); ctx.builder.reinterpret_i32_as_f32(); ctx.builder.const_i32(r as i32); ctx.builder.call_fn2_f32_i32(name); } fn sse_read_f32_xmm_xmm(ctx: &mut JitContext, name: &str, r1: u32, r2: u32) { ctx.builder .const_i32(global_pointers::get_reg_xmm_offset(r1) as i32); ctx.builder.load_aligned_f32(0); ctx.builder.const_i32(r2 as i32); ctx.builder.call_fn2_f32_i32(name); } fn sse_read64_xmm_mem(ctx: &mut JitContext, name: &str, modrm_byte: ModrmByte, r: u32) { codegen::gen_modrm_resolve_safe_read64(ctx, modrm_byte); ctx.builder.const_i32(r as i32); ctx.builder.call_fn2_i64_i32(name); } fn sse_read64_xmm_xmm(ctx: &mut JitContext, name: &str, r1: u32, r2: u32) { ctx.builder .const_i32(global_pointers::get_reg_xmm_offset(r1) as i32); ctx.builder.load_aligned_i64(0); ctx.builder.const_i32(r2 as i32); ctx.builder.call_fn2_i64_i32(name); } fn sse_read128_xmm_mem(ctx: &mut JitContext, name: &str, modrm_byte: ModrmByte, r: u32) { let dest = global_pointers::sse_scratch_register as u32; codegen::gen_modrm_resolve_safe_read128(ctx, modrm_byte, dest); ctx.builder.const_i32(dest as i32); ctx.builder.const_i32(r as i32); ctx.builder.call_fn2(name); } fn sse_read128_xmm_mem_imm( ctx: &mut JitContext, name: &str, modrm_byte: ModrmByte, r: u32, imm: u32, ) { let dest = global_pointers::sse_scratch_register as u32; codegen::gen_modrm_resolve_safe_read128(ctx, modrm_byte, dest); ctx.builder.const_i32(dest as i32); ctx.builder.const_i32(r as i32); ctx.builder.const_i32(imm as i32); ctx.builder.call_fn3(name); } fn sse_read128_xmm_xmm(ctx: &mut JitContext, name: &str, r1: u32, r2: u32) { // Make a copy to avoid aliasing problems: Called function expects a reg128, which must not // alias with memory codegen::gen_read_reg_xmm128_into_scratch(ctx, r1); let dest = global_pointers::sse_scratch_register; ctx.builder.const_i32(dest as i32); ctx.builder.const_i32(r2 as i32); ctx.builder.call_fn2(name); } fn sse_read128_xmm_xmm_imm(ctx: &mut JitContext, name: &str, r1: u32, r2: u32, imm: u32) { // Make a copy to avoid aliasing problems: Called function expects a reg128, which must not // alias with memory codegen::gen_read_reg_xmm128_into_scratch(ctx, r1); let dest = global_pointers::sse_scratch_register; ctx.builder.const_i32(dest as i32); ctx.builder.const_i32(r2 as i32); ctx.builder.const_i32(imm as i32); ctx.builder.call_fn3(name); } fn sse_mov_xmm_xmm(ctx: &mut JitContext, r1: u32, r2: u32) { ctx.builder .const_i32(global_pointers::get_reg_xmm_offset(r2) as i32); ctx.builder .const_i32(global_pointers::get_reg_xmm_offset(r1) as i32); ctx.builder.load_aligned_i64(0); ctx.builder.store_aligned_i64(0); ctx.builder .const_i32(global_pointers::get_reg_xmm_offset(r2) as i32 + 8); ctx.builder .const_i32(global_pointers::get_reg_xmm_offset(r1) as i32 + 8); ctx.builder.load_aligned_i64(0); ctx.builder.store_aligned_i64(0); } fn mmx_read64_mm_mem32(ctx: &mut JitContext, name: &str, modrm_byte: ModrmByte, r: u32) { codegen::gen_modrm_resolve_safe_read32(ctx, modrm_byte); ctx.builder.const_i32(r as i32); ctx.builder.call_fn2(name) } fn mmx_read64_mm_mm32(ctx: &mut JitContext, name: &str, r1: u32, r2: u32) { ctx.builder .const_i32(global_pointers::get_reg_mmx_offset(r1) as i32); ctx.builder.load_aligned_i32(0); ctx.builder.const_i32(r2 as i32); ctx.builder.call_fn2(name); } fn mmx_read64_mm_mem(ctx: &mut JitContext, name: &str, modrm_byte: ModrmByte, r: u32) { codegen::gen_modrm_resolve_safe_read64(ctx, modrm_byte); ctx.builder.const_i32(r as i32); ctx.builder.call_fn2_i64_i32(name) } fn mmx_read64_mm_mm(ctx: &mut JitContext, name: &str, r1: u32, r2: u32) { ctx.builder .const_i32(global_pointers::get_reg_mmx_offset(r1) as i32); ctx.builder.load_aligned_i64(0); ctx.builder.const_i32(r2 as i32); ctx.builder.call_fn2_i64_i32(name); } fn push16_reg_jit(ctx: &mut JitContext, r: u32) { codegen::gen_get_reg16(ctx, r); let value_local = ctx.builder.set_new_local(); codegen::gen_push16(ctx, &value_local); ctx.builder.free_local(value_local); } fn push32_reg_jit(ctx: &mut JitContext, r: u32) { let reg = ctx.reg(r); codegen::gen_push32(ctx, &reg); } fn push16_imm_jit(ctx: &mut JitContext, imm: u32) { ctx.builder.const_i32(imm as i32); let value_local = ctx.builder.set_new_local(); codegen::gen_push16(ctx, &value_local); ctx.builder.free_local(value_local); } fn push32_imm_jit(ctx: &mut JitContext, imm: u32) { ctx.builder.const_i32(imm as i32); let value_local = ctx.builder.set_new_local(); codegen::gen_push32(ctx, &value_local); ctx.builder.free_local(value_local); } fn push16_mem_jit(ctx: &mut JitContext, modrm_byte: ModrmByte) { codegen::gen_modrm_resolve_safe_read16(ctx, modrm_byte); let value_local = ctx.builder.set_new_local(); codegen::gen_push16(ctx, &value_local); ctx.builder.free_local(value_local); } fn push32_mem_jit(ctx: &mut JitContext, modrm_byte: ModrmByte) { codegen::gen_modrm_resolve_safe_read32(ctx, modrm_byte); let value_local = ctx.builder.set_new_local(); codegen::gen_push32(ctx, &value_local); ctx.builder.free_local(value_local); } fn pop16_reg_jit(ctx: &mut JitContext, reg: u32) { codegen::gen_pop16(ctx); codegen::gen_set_reg16_unmasked(ctx, reg); } fn pop32_reg_jit(ctx: &mut JitContext, reg: u32) { codegen::gen_pop32s(ctx); codegen::gen_set_reg32(ctx, reg); } fn group_arith_al_imm8( ctx: &mut JitContext, op: &dyn Fn(&mut JitContext, &WasmLocal, &LocalOrImmediate), imm8: u32, ) { op( ctx, &ctx.reg(regs::EAX), &LocalOrImmediate::Immediate(imm8 as i32), ); codegen::gen_set_reg8_unmasked(ctx, regs::EAX); } fn group_arith_ax_imm16(ctx: &mut JitContext, op: &str, imm16: u32) { codegen::gen_get_reg16(ctx, regs::AX); ctx.builder.const_i32(imm16 as i32); ctx.builder.call_fn2_ret(op); codegen::gen_set_reg16(ctx, regs::AX); } fn group_arith_eax_imm32( ctx: &mut JitContext, op: &dyn Fn(&mut JitContext, &WasmLocal, &LocalOrImmediate), imm32: u32, ) { op( ctx, &ctx.reg(regs::EAX), &LocalOrImmediate::Immediate(imm32 as i32), ); } macro_rules! define_instruction_read8( ($fn:expr, $name_mem:ident, $name_reg:ident) => ( pub fn $name_mem(ctx: &mut JitContext, modrm_byte: ModrmByte, r: u32) { codegen::gen_modrm_resolve_safe_read8(ctx, modrm_byte); let dest_operand = ctx.builder.set_new_local(); let source_operand = codegen::gen_get_reg8_or_alias_to_reg32(ctx, r); $fn(ctx, &dest_operand, &LocalOrImmediate::WasmLocal(&source_operand)); ctx.builder.free_local(dest_operand); codegen::gen_free_reg8_or_alias(ctx, r, source_operand); } pub fn $name_reg(ctx: &mut JitContext, r1: u32, r2: u32) { let dest_operand = codegen::gen_get_reg8_or_alias_to_reg32(ctx, r1); let source_operand = codegen::gen_get_reg8_or_alias_to_reg32(ctx, r2); $fn(ctx, &dest_operand, &LocalOrImmediate::WasmLocal(&source_operand)); codegen::gen_free_reg8_or_alias(ctx, r1, dest_operand); codegen::gen_free_reg8_or_alias(ctx, r2, source_operand); } ); ($fn:expr, $name_mem:ident, $name_reg:ident, $imm:ident) => ( pub fn $name_mem(ctx: &mut JitContext, modrm_byte: ModrmByte, imm: u32) { codegen::gen_modrm_resolve_safe_read8(ctx, modrm_byte); let dest_operand = ctx.builder.set_new_local(); let imm = mask_imm!(imm, $imm); $fn(ctx, &dest_operand, &LocalOrImmediate::Immediate(imm as i32)); ctx.builder.free_local(dest_operand); } pub fn $name_reg(ctx: &mut JitContext, r1: u32, imm: u32) { let imm = mask_imm!(imm, $imm); let dest_operand = codegen::gen_get_reg8_or_alias_to_reg32(ctx, r1); $fn(ctx, &dest_operand, &LocalOrImmediate::Immediate(imm as i32)); codegen::gen_free_reg8_or_alias(ctx, r1, dest_operand); } ); ); macro_rules! define_instruction_read16( ($fn:expr, $name_mem:ident, $name_reg:ident) => ( pub fn $name_mem(ctx: &mut JitContext, modrm_byte: ModrmByte, r: u32) { codegen::gen_modrm_resolve_safe_read16(ctx, modrm_byte); let dest_operand = ctx.builder.set_new_local(); $fn( ctx, &dest_operand, &LocalOrImmediate::WasmLocal(&ctx.reg(r)), ); ctx.builder.free_local(dest_operand); } pub fn $name_reg(ctx: &mut JitContext, r1: u32, r2: u32) { $fn( ctx, &ctx.reg(r1), &LocalOrImmediate::WasmLocal(&ctx.reg(r2)) ); } ); ($fn:expr, $name_mem:ident, $name_reg:ident, $imm:ident) => ( pub fn $name_mem(ctx: &mut JitContext, modrm_byte: ModrmByte, imm: u32) { codegen::gen_modrm_resolve_safe_read16(ctx, modrm_byte); let dest_operand = ctx.builder.set_new_local(); let imm = mask_imm!(imm, $imm); $fn( ctx, &dest_operand, &LocalOrImmediate::Immediate(imm as i32), ); ctx.builder.free_local(dest_operand); } pub fn $name_reg(ctx: &mut JitContext, r: u32, imm: u32) { let imm = mask_imm!(imm, $imm); $fn( ctx, &ctx.reg(r), &LocalOrImmediate::Immediate(imm as i32), ); } ); ); macro_rules! define_instruction_read32( ($fn:expr, $name_mem:ident, $name_reg:ident) => ( pub fn $name_mem(ctx: &mut JitContext, modrm_byte: ModrmByte, r: u32) { codegen::gen_modrm_resolve_safe_read32(ctx, modrm_byte); let dest_operand = ctx.builder.set_new_local(); $fn( ctx, &dest_operand, &LocalOrImmediate::WasmLocal(&ctx.reg(r)), ); ctx.builder.free_local(dest_operand); } pub fn $name_reg(ctx: &mut JitContext, r1: u32, r2: u32) { $fn( ctx, &ctx.reg(r1), &LocalOrImmediate::WasmLocal(&ctx.reg(r2)) ); } ); ($fn:expr, $name_mem:ident, $name_reg:ident, $imm:ident) => ( pub fn $name_mem(ctx: &mut JitContext, modrm_byte: ModrmByte, imm: u32) { codegen::gen_modrm_resolve_safe_read32(ctx, modrm_byte); let dest_operand = ctx.builder.set_new_local(); let imm = mask_imm!(imm, $imm); $fn( ctx, &dest_operand, &LocalOrImmediate::Immediate(imm as i32), ); ctx.builder.free_local(dest_operand); } pub fn $name_reg(ctx: &mut JitContext, r: u32, imm: u32) { let imm = mask_imm!(imm, $imm); $fn( ctx, &ctx.reg(r), &LocalOrImmediate::Immediate(imm as i32), ); } ); ); macro_rules! define_instruction_write_reg8( ($fn:expr, $name_mem:ident, $name_reg:ident) => ( pub fn $name_mem(ctx: &mut JitContext, modrm_byte: ModrmByte, r: u32) { codegen::gen_modrm_resolve_safe_read8(ctx, modrm_byte); let source_operand = ctx.builder.set_new_local(); let dest_operand = codegen::gen_get_reg8_or_alias_to_reg32(ctx, r); $fn(ctx, &dest_operand, &LocalOrImmediate::WasmLocal(&source_operand)); codegen::gen_set_reg8_unmasked(ctx, r); ctx.builder.free_local(source_operand); codegen::gen_free_reg8_or_alias(ctx, r, dest_operand); } pub fn $name_reg(ctx: &mut JitContext, r1: u32, r2: u32) { let source_operand = codegen::gen_get_reg8_or_alias_to_reg32(ctx, r1); let dest_operand = codegen::gen_get_reg8_or_alias_to_reg32(ctx, r2); $fn(ctx, &dest_operand, &LocalOrImmediate::WasmLocal(&source_operand)); codegen::gen_set_reg8_unmasked(ctx, r2); codegen::gen_free_reg8_or_alias(ctx, r1, source_operand); codegen::gen_free_reg8_or_alias(ctx, r2, dest_operand); } ) ); macro_rules! define_instruction_write_reg16( ($fn:expr, $name_mem:ident, $name_reg:ident) => ( pub fn $name_mem(ctx: &mut JitContext, modrm_byte: ModrmByte, r: u32) { codegen::gen_get_reg16(ctx, r); codegen::gen_modrm_resolve_safe_read16(ctx, modrm_byte); ctx.builder.call_fn2_ret($fn); codegen::gen_set_reg16(ctx, r); } pub fn $name_reg(ctx: &mut JitContext, r1: u32, r2: u32) { codegen::gen_get_reg16(ctx, r2); codegen::gen_get_reg16(ctx, r1); ctx.builder.call_fn2_ret($fn); codegen::gen_set_reg16(ctx, r2); } ) ); macro_rules! define_instruction_write_reg32( ($fn:expr, $name_mem:ident, $name_reg:ident) => ( pub fn $name_mem(ctx: &mut JitContext, modrm_byte: ModrmByte, r: u32) { codegen::gen_modrm_resolve_safe_read32(ctx, modrm_byte); let source_operand = ctx.builder.set_new_local(); $fn( ctx, &ctx.reg(r), &LocalOrImmediate::WasmLocal(&source_operand), ); ctx.builder.free_local(source_operand); } pub fn $name_reg(ctx: &mut JitContext, r1: u32, r2: u32) { $fn( ctx, &ctx.reg(r2), &LocalOrImmediate::WasmLocal(&ctx.reg(r1)), ); } ); ); macro_rules! mask_imm( ($imm:expr, imm8_5bits) => { $imm & 31 }; ($imm:expr, imm8) => { $imm }; ($imm:expr, imm8s) => { $imm }; ($imm:expr, imm8s_16bits) => { $imm & 0xFFFF }; ($imm:expr, imm16) => { $imm }; ($imm:expr, imm32) => { $imm }; ); macro_rules! define_instruction_read_write_mem8( ($fn:expr, $name_mem:ident, $name_reg:ident, reg) => ( pub fn $name_mem(ctx: &mut JitContext, modrm_byte: ModrmByte, r: u32) { codegen::gen_modrm_resolve_with_local(ctx, modrm_byte, &|ctx, addr| { codegen::gen_safe_read_write(ctx, BitSize::BYTE, &addr, &|ref mut ctx| { let dest_operand = ctx.builder.set_new_local(); let source_operand = codegen::gen_get_reg8_or_alias_to_reg32(ctx, r); $fn(ctx, &dest_operand, &LocalOrImmediate::WasmLocal(&source_operand)); codegen::gen_free_reg8_or_alias(ctx, r, source_operand); ctx.builder.free_local(dest_operand); }); }); } pub fn $name_reg(ctx: &mut JitContext, r1: u32, r2: u32) { let source_operand = codegen::gen_get_reg8_or_alias_to_reg32(ctx, r2); let dest_operand = codegen::gen_get_reg8_or_alias_to_reg32(ctx, r1); $fn(ctx, &dest_operand, &LocalOrImmediate::WasmLocal(&source_operand)); codegen::gen_set_reg8_unmasked(ctx, r1); codegen::gen_free_reg8_or_alias(ctx, r2, source_operand); codegen::gen_free_reg8_or_alias(ctx, r1, dest_operand); } ); ($fn:expr, $name_mem:ident, $name_reg:ident, constant_one) => ( pub fn $name_mem(ctx: &mut JitContext, modrm_byte: ModrmByte) { codegen::gen_modrm_resolve_with_local(ctx, modrm_byte, &|ctx, addr| { codegen::gen_safe_read_write(ctx, BitSize::BYTE, &addr, &|ref mut ctx| { ctx.builder.const_i32(1); ctx.builder.call_fn2_ret($fn); }); }); } pub fn $name_reg(ctx: &mut JitContext, r1: u32) { codegen::gen_get_reg8(ctx, r1); ctx.builder.const_i32(1); ctx.builder.call_fn2_ret($fn); codegen::gen_set_reg8(ctx, r1); } ); ($fn:expr, $name_mem:ident, $name_reg:ident, cl) => ( pub fn $name_mem(ctx: &mut JitContext, modrm_byte: ModrmByte) { codegen::gen_modrm_resolve_with_local(ctx, modrm_byte, &|ctx, addr| { codegen::gen_safe_read_write(ctx, BitSize::BYTE, &addr, &|ref mut ctx| { codegen::gen_get_reg8(ctx, regs::CL); ctx.builder.const_i32(31); ctx.builder.and_i32(); ctx.builder.call_fn2_ret($fn); }); }); } pub fn $name_reg(ctx: &mut JitContext, r1: u32) { codegen::gen_get_reg8(ctx, r1); codegen::gen_get_reg8(ctx, regs::CL); ctx.builder.const_i32(31); ctx.builder.and_i32(); ctx.builder.call_fn2_ret($fn); codegen::gen_set_reg8(ctx, r1); } ); ($fn:expr, $name_mem:ident, $name_reg:ident, none) => ( pub fn $name_mem(ctx: &mut JitContext, modrm_byte: ModrmByte) { codegen::gen_modrm_resolve_with_local(ctx, modrm_byte, &|ctx, addr| { codegen::gen_safe_read_write(ctx, BitSize::BYTE, &addr, &|ref mut ctx| { ctx.builder.call_fn1_ret($fn); }); }); } pub fn $name_reg(ctx: &mut JitContext, r1: u32) { codegen::gen_get_reg8(ctx, r1); ctx.builder.call_fn1_ret($fn); codegen::gen_set_reg8(ctx, r1); } ); ($fn:expr, $name_mem:ident, $name_reg:ident, ximm8) => ( pub fn $name_mem(ctx: &mut JitContext, modrm_byte: ModrmByte, imm: u32) { codegen::gen_modrm_resolve_with_local(ctx, modrm_byte, &|ctx, addr| { codegen::gen_safe_read_write(ctx, BitSize::BYTE, &addr, &|ref mut ctx| { let dest_operand = ctx.builder.set_new_local(); $fn(ctx, &dest_operand, &LocalOrImmediate::Immediate(imm as i32)); ctx.builder.free_local(dest_operand); }); }); } pub fn $name_reg(ctx: &mut JitContext, r1: u32, imm: u32) { let dest_operand = codegen::gen_get_reg8_or_alias_to_reg32(ctx, r1); $fn(ctx, &dest_operand, &LocalOrImmediate::Immediate(imm as i32)); codegen::gen_set_reg8_unmasked(ctx, r1); codegen::gen_free_reg8_or_alias(ctx, r1, dest_operand); } ); ($fn:expr, $name_mem:ident, $name_reg:ident, $imm:ident) => ( pub fn $name_mem(ctx: &mut JitContext, modrm_byte: ModrmByte, imm: u32) { codegen::gen_modrm_resolve_with_local(ctx, modrm_byte, &|ctx, addr| { let imm = mask_imm!(imm, $imm) as i32; codegen::gen_safe_read_write(ctx, BitSize::BYTE, &addr, &|ref mut ctx| { ctx.builder.const_i32(imm as i32); ctx.builder.call_fn2_ret($fn); }); }); } pub fn $name_reg(ctx: &mut JitContext, r1: u32, imm: u32) { let imm = mask_imm!(imm, $imm); codegen::gen_get_reg8(ctx, r1); ctx.builder.const_i32(imm as i32); ctx.builder.call_fn2_ret($fn); codegen::gen_set_reg8(ctx, r1); } ); ); macro_rules! define_instruction_read_write_mem16( ($fn:expr, $name_mem:ident, $name_reg:ident, reg) => ( pub fn $name_mem(ctx: &mut JitContext, modrm_byte: ModrmByte, r: u32) { codegen::gen_modrm_resolve_with_local(ctx, modrm_byte, &|ctx, addr| { codegen::gen_safe_read_write(ctx, BitSize::WORD, &addr, &|ref mut ctx| { codegen::gen_get_reg16(ctx, r); ctx.builder.call_fn2_ret($fn); }); }); } pub fn $name_reg(ctx: &mut JitContext, r1: u32, r2: u32) { codegen::gen_get_reg16(ctx, r1); codegen::gen_get_reg16(ctx, r2); ctx.builder.call_fn2_ret($fn); codegen::gen_set_reg16(ctx, r1); } ); ($fn:expr, $name_mem:ident, $name_reg:ident, constant_one) => ( pub fn $name_mem(ctx: &mut JitContext, modrm_byte: ModrmByte) { codegen::gen_modrm_resolve_with_local(ctx, modrm_byte, &|ctx, addr| { codegen::gen_safe_read_write(ctx, BitSize::WORD, &addr, &|ref mut ctx| { ctx.builder.const_i32(1); ctx.builder.call_fn2_ret($fn); }); }); } pub fn $name_reg(ctx: &mut JitContext, r1: u32) { codegen::gen_get_reg16(ctx, r1); ctx.builder.const_i32(1); ctx.builder.call_fn2_ret($fn); codegen::gen_set_reg16(ctx, r1); } ); ($fn:expr, $name_mem:ident, $name_reg:ident, cl) => ( pub fn $name_mem(ctx: &mut JitContext, modrm_byte: ModrmByte) { codegen::gen_modrm_resolve_with_local(ctx, modrm_byte, &|ctx, addr| { codegen::gen_safe_read_write(ctx, BitSize::WORD, &addr, &|ref mut ctx| { codegen::gen_get_reg8(ctx, regs::CL); ctx.builder.const_i32(31); ctx.builder.and_i32(); ctx.builder.call_fn2_ret($fn); }); }); } pub fn $name_reg(ctx: &mut JitContext, r1: u32) { codegen::gen_get_reg16(ctx, r1); codegen::gen_get_reg8(ctx, regs::CL); ctx.builder.const_i32(31); ctx.builder.and_i32(); ctx.builder.call_fn2_ret($fn); codegen::gen_set_reg16(ctx, r1); } ); ($fn:expr, $name_mem:ident, $name_reg:ident, reg, cl) => ( pub fn $name_mem(ctx: &mut JitContext, modrm_byte: ModrmByte, r: u32) { codegen::gen_modrm_resolve_with_local(ctx, modrm_byte, &|ctx, addr| { codegen::gen_safe_read_write(ctx, BitSize::WORD, &addr, &|ref mut ctx| { codegen::gen_get_reg16(ctx, r); codegen::gen_get_reg8(ctx, regs::CL); ctx.builder.const_i32(31); ctx.builder.and_i32(); ctx.builder.call_fn3_ret($fn); }); }); } pub fn $name_reg(ctx: &mut JitContext, r1: u32, r2: u32) { codegen::gen_get_reg16(ctx, r1); codegen::gen_get_reg16(ctx, r2); codegen::gen_get_reg8(ctx, regs::CL); ctx.builder.const_i32(31); ctx.builder.and_i32(); ctx.builder.call_fn3_ret($fn); codegen::gen_set_reg16(ctx, r1); } ); ($fn:expr, $name_mem:ident, $name_reg:ident, reg, $imm:ident) => ( pub fn $name_mem(ctx: &mut JitContext, modrm_byte: ModrmByte, r: u32, imm: u32) { codegen::gen_modrm_resolve_with_local(ctx, modrm_byte, &|ctx, addr| { let imm = mask_imm!(imm, $imm); codegen::gen_safe_read_write(ctx, BitSize::WORD, &addr, &|ref mut ctx| { codegen::gen_get_reg16(ctx, r); ctx.builder.const_i32(imm as i32); ctx.builder.call_fn3_ret($fn); }); }); } pub fn $name_reg(ctx: &mut JitContext, r1: u32, r2: u32, imm: u32) { let imm = mask_imm!(imm, $imm); codegen::gen_get_reg16(ctx, r1); codegen::gen_get_reg16(ctx, r2); ctx.builder.const_i32(imm as i32); ctx.builder.call_fn3_ret($fn); codegen::gen_set_reg16(ctx, r1); } ); ($fn:expr, $name_mem:ident, $name_reg:ident, none) => ( pub fn $name_mem(ctx: &mut JitContext, modrm_byte: ModrmByte) { codegen::gen_modrm_resolve_with_local(ctx, modrm_byte, &|ctx, addr| { codegen::gen_safe_read_write(ctx, BitSize::WORD, &addr, &|ref mut ctx| { let mut dest_operand = ctx.builder.set_new_local(); $fn(ctx, &mut dest_operand); ctx.builder.get_local(&dest_operand); ctx.builder.free_local(dest_operand); }); }); } pub fn $name_reg(ctx: &mut JitContext, r1: u32) { $fn(ctx, &mut ctx.reg(r1)); } ); ($fn:expr, $name_mem:ident, $name_reg:ident, $imm:ident) => ( pub fn $name_mem(ctx: &mut JitContext, modrm_byte: ModrmByte, imm: u32) { codegen::gen_modrm_resolve_with_local(ctx, modrm_byte, &|ctx, addr| { let imm = mask_imm!(imm, $imm) as i32; codegen::gen_safe_read_write(ctx, BitSize::WORD, &addr, &|ref mut ctx| { ctx.builder.const_i32(imm as i32); ctx.builder.call_fn2_ret($fn); }); }); } pub fn $name_reg(ctx: &mut JitContext, r1: u32, imm: u32) { let imm = mask_imm!(imm, $imm); codegen::gen_get_reg16(ctx, r1); ctx.builder.const_i32(imm as i32); ctx.builder.call_fn2_ret($fn); codegen::gen_set_reg16(ctx, r1); } ); ); macro_rules! define_instruction_read_write_mem32( ($fn:expr, $name_mem:ident, $name_reg:ident, reg) => ( pub fn $name_mem(ctx: &mut JitContext, modrm_byte: ModrmByte, r: u32) { codegen::gen_modrm_resolve_with_local(ctx, modrm_byte, &|ctx, addr| { codegen::gen_safe_read_write(ctx, BitSize::DWORD, &addr, &|ref mut ctx| { let dest_operand = ctx.builder.set_new_local(); $fn( ctx, &dest_operand, &LocalOrImmediate::WasmLocal(&ctx.reg(r)), ); ctx.builder.get_local(&dest_operand); ctx.builder.free_local(dest_operand); }); }); } pub fn $name_reg(ctx: &mut JitContext, r1: u32, r2: u32) { $fn( ctx, &ctx.reg(r1), &LocalOrImmediate::WasmLocal(&ctx.reg(r2)), ); } ); ($fn:expr, $name_mem:ident, $name_reg:ident, constant_one) => ( pub fn $name_mem(ctx: &mut JitContext, modrm_byte: ModrmByte) { codegen::gen_modrm_resolve_with_local(ctx, modrm_byte, &|ctx, addr| { codegen::gen_safe_read_write(ctx, BitSize::DWORD, &addr, &|ref mut ctx| { let dest_operand = ctx.builder.set_new_local(); $fn(ctx, &dest_operand, &LocalOrImmediate::Immediate(1)); ctx.builder.get_local(&dest_operand); ctx.builder.free_local(dest_operand); }); }); } pub fn $name_reg(ctx: &mut JitContext, r1: u32) { $fn(ctx, &ctx.reg(r1), &LocalOrImmediate::Immediate(1)); } ); ($fn:expr, $name_mem:ident, $name_reg:ident, cl) => ( pub fn $name_mem(ctx: &mut JitContext, modrm_byte: ModrmByte) { codegen::gen_modrm_resolve_with_local(ctx, modrm_byte, &|ctx, addr| { codegen::gen_safe_read_write(ctx, BitSize::DWORD, &addr, &|ref mut ctx| { let dest_operand = ctx.builder.set_new_local(); $fn( ctx, &dest_operand, &LocalOrImmediate::WasmLocal(&ctx.reg(regs::ECX)), ); ctx.builder.get_local(&dest_operand); ctx.builder.free_local(dest_operand); }); }); } pub fn $name_reg(ctx: &mut JitContext, r1: u32) { $fn( ctx, &ctx.reg(r1), &LocalOrImmediate::WasmLocal(&ctx.reg(regs::ECX)), ); } ); ($fn:expr, $name_mem:ident, $name_reg:ident, reg, cl) => ( pub fn $name_mem(ctx: &mut JitContext, modrm_byte: ModrmByte, r: u32) { codegen::gen_modrm_resolve_with_local(ctx, modrm_byte, &|ctx, addr| { codegen::gen_safe_read_write(ctx, BitSize::DWORD, &addr, &|ref mut ctx| { codegen::gen_get_reg32(ctx, r); codegen::gen_get_reg8(ctx, regs::CL); ctx.builder.const_i32(31); ctx.builder.and_i32(); ctx.builder.call_fn3_ret($fn); }); }); } pub fn $name_reg(ctx: &mut JitContext, r1: u32, r2: u32) { codegen::gen_get_reg32(ctx, r1); codegen::gen_get_reg32(ctx, r2); codegen::gen_get_reg8(ctx, regs::CL); ctx.builder.const_i32(31); ctx.builder.and_i32(); ctx.builder.call_fn3_ret($fn); codegen::gen_set_reg32(ctx, r1); } ); ($fn:expr, $name_mem:ident, $name_reg:ident, reg, $imm:ident) => ( pub fn $name_mem(ctx: &mut JitContext, modrm_byte: ModrmByte, r: u32, imm: u32) { codegen::gen_modrm_resolve_with_local(ctx, modrm_byte, &|ctx, addr| { let imm = mask_imm!(imm, $imm) as i32; codegen::gen_safe_read_write(ctx, BitSize::DWORD, &addr, &|ref mut ctx| { codegen::gen_get_reg32(ctx, r); ctx.builder.const_i32(imm as i32); ctx.builder.call_fn3_ret($fn); }); }); } pub fn $name_reg(ctx: &mut JitContext, r1: u32, r2: u32, imm: u32) { let imm = mask_imm!(imm, $imm); codegen::gen_get_reg32(ctx, r1); codegen::gen_get_reg32(ctx, r2); ctx.builder.const_i32(imm as i32); ctx.builder.call_fn3_ret($fn); codegen::gen_set_reg32(ctx, r1); } ); ($fn:expr, $name_mem:ident, $name_reg:ident, none) => ( pub fn $name_mem(ctx: &mut JitContext, modrm_byte: ModrmByte) { codegen::gen_modrm_resolve_with_local(ctx, modrm_byte, &|ctx, addr| { codegen::gen_safe_read_write(ctx, BitSize::DWORD, &addr, &|ref mut ctx| { let mut dest_operand = ctx.builder.set_new_local(); $fn(ctx, &mut dest_operand); ctx.builder.get_local(&dest_operand); ctx.builder.free_local(dest_operand); }); }); } pub fn $name_reg(ctx: &mut JitContext, r1: u32) { $fn(ctx, &mut ctx.reg(r1)); } ); ($fn:expr, $name_mem:ident, $name_reg:ident, $imm:ident) => ( pub fn $name_mem(ctx: &mut JitContext, modrm_byte: ModrmByte, imm: u32) { codegen::gen_modrm_resolve_with_local(ctx, modrm_byte, &|ctx, addr| { let imm = mask_imm!(imm, $imm); codegen::gen_safe_read_write(ctx, BitSize::DWORD, &addr, &|ref mut ctx| { let dest_operand = ctx.builder.set_new_local(); $fn( ctx, &dest_operand, &LocalOrImmediate::Immediate(imm as i32), ); ctx.builder.get_local(&dest_operand); ctx.builder.free_local(dest_operand); }); }); } pub fn $name_reg(ctx: &mut JitContext, r1: u32, imm: u32) { let imm = mask_imm!(imm, $imm); $fn( ctx, &ctx.reg(r1), &LocalOrImmediate::Immediate(imm as i32), ); } ); ); fn gen_add8(ctx: &mut JitContext, dest_operand: &WasmLocal, source_operand: &LocalOrImmediate) { ctx.current_instruction = Instruction::Arithmetic { opsize: OPSIZE_8 }; ctx.builder.const_i32(global_pointers::last_op1 as i32); ctx.builder.get_local(dest_operand); ctx.builder.const_i32(0xFF); ctx.builder.and_i32(); ctx.builder.store_aligned_i32(0); ctx.builder.const_i32(global_pointers::last_result as i32); ctx.builder.get_local(dest_operand); source_operand.gen_get(ctx.builder); ctx.builder.add_i32(); ctx.builder.const_i32(0xFF); ctx.builder.and_i32(); ctx.builder.store_aligned_i32(0); codegen::gen_set_last_op_size(ctx.builder, OPSIZE_8); codegen::gen_set_flags_changed(ctx.builder, FLAGS_ALL); ctx.builder .load_fixed_u8(global_pointers::last_result as u32); } fn gen_add32(ctx: &mut JitContext, dest_operand: &WasmLocal, source_operand: &LocalOrImmediate) { ctx.current_instruction = Instruction::Arithmetic { opsize: OPSIZE_32 }; codegen::gen_set_last_op1(ctx.builder, &dest_operand); ctx.builder.get_local(&dest_operand); source_operand.gen_get(ctx.builder); ctx.builder.add_i32(); ctx.builder.set_local(dest_operand); codegen::gen_set_last_result(ctx.builder, &dest_operand); codegen::gen_set_last_op_size(ctx.builder, OPSIZE_32); codegen::gen_set_flags_changed(ctx.builder, FLAGS_ALL); } fn gen_sub8(ctx: &mut JitContext, dest_operand: &WasmLocal, source_operand: &LocalOrImmediate) { ctx.current_instruction = Instruction::Arithmetic { opsize: OPSIZE_8 }; ctx.builder.const_i32(global_pointers::last_op1 as i32); ctx.builder.get_local(dest_operand); ctx.builder.const_i32(0xFF); ctx.builder.and_i32(); ctx.builder.store_aligned_i32(0); ctx.builder.const_i32(global_pointers::last_result as i32); ctx.builder.get_local(dest_operand); source_operand.gen_get(ctx.builder); ctx.builder.sub_i32(); ctx.builder.const_i32(0xFF); ctx.builder.and_i32(); ctx.builder.store_aligned_i32(0); codegen::gen_set_last_op_size(ctx.builder, OPSIZE_8); codegen::gen_set_flags_changed(ctx.builder, FLAGS_ALL | FLAG_SUB); ctx.builder .load_fixed_u8(global_pointers::last_result as u32); } fn gen_sub32(ctx: &mut JitContext, dest_operand: &WasmLocal, source_operand: &LocalOrImmediate) { ctx.current_instruction = Instruction::Sub { opsize: OPSIZE_32 }; codegen::gen_set_last_op1(ctx.builder, &dest_operand); ctx.builder.get_local(&dest_operand); source_operand.gen_get(ctx.builder); ctx.builder.sub_i32(); ctx.builder.set_local(dest_operand); codegen::gen_set_last_result(ctx.builder, &dest_operand); codegen::gen_set_last_op_size(ctx.builder, OPSIZE_32); codegen::gen_set_flags_changed(ctx.builder, FLAGS_ALL | FLAG_SUB); } fn gen_cmp( ctx: &mut JitContext, dest_operand: &WasmLocal, source_operand: &LocalOrImmediate, size: i32, ) { ctx.current_instruction = Instruction::Cmp { dest: if ctx.register_locals.iter().any(|l| l == dest_operand) { InstructionOperand::WasmLocal(dest_operand.unsafe_clone()) } else { InstructionOperand::Other }, source: match source_operand { &LocalOrImmediate::WasmLocal(source) => { if ctx.register_locals.iter().any(|l| l == source) { InstructionOperand::WasmLocal(source.unsafe_clone()) } else { InstructionOperand::Other } }, &LocalOrImmediate::Immediate(i) => InstructionOperand::Immediate(i), }, opsize: size, }; ctx.builder.const_i32(global_pointers::last_result as i32); if source_operand.is_zero() { ctx.builder.get_local(&dest_operand); } else { ctx.builder.get_local(&dest_operand); source_operand.gen_get(ctx.builder); ctx.builder.sub_i32(); } if size == OPSIZE_8 || size == OPSIZE_16 { ctx.builder .const_i32(if size == OPSIZE_8 { 0xFF } else { 0xFFFF }); ctx.builder.and_i32(); } ctx.builder.store_aligned_i32(0); ctx.builder.const_i32(global_pointers::last_op1 as i32); ctx.builder.get_local(&dest_operand); if size == OPSIZE_8 || size == OPSIZE_16 { ctx.builder .const_i32(if size == OPSIZE_8 { 0xFF } else { 0xFFFF }); ctx.builder.and_i32(); } ctx.builder.store_aligned_i32(0); codegen::gen_set_last_op_size(ctx.builder, size); codegen::gen_set_flags_changed(ctx.builder, FLAGS_ALL | FLAG_SUB); } fn gen_cmp8(ctx: &mut JitContext, dest: &WasmLocal, source: &LocalOrImmediate) { gen_cmp(ctx, dest, source, OPSIZE_8) } fn gen_cmp16(ctx: &mut JitContext, dest: &WasmLocal, source: &LocalOrImmediate) { gen_cmp(ctx, dest, source, OPSIZE_16) } fn gen_cmp32(ctx: &mut JitContext, dest: &WasmLocal, source: &LocalOrImmediate) { gen_cmp(ctx, dest, source, OPSIZE_32) } fn gen_adc8(ctx: &mut JitContext, dest_operand: &WasmLocal, source_operand: &LocalOrImmediate) { ctx.builder.get_local(dest_operand); ctx.builder.const_i32(0xFF); ctx.builder.and_i32(); source_operand.gen_get_mask255(ctx.builder); ctx.builder.call_fn2_ret("adc8"); ctx.builder.const_i32(0xFF); ctx.builder.and_i32(); } fn gen_adc32(ctx: &mut JitContext, dest_operand: &WasmLocal, source_operand: &LocalOrImmediate) { ctx.builder.get_local(&dest_operand); source_operand.gen_get(ctx.builder); ctx.builder.add_i32(); codegen::gen_getcf_unoptimised(ctx.builder); ctx.builder.add_i32(); let res = ctx.builder.set_new_local(); codegen::gen_set_last_result(ctx.builder, &res); codegen::gen_set_last_op_size(ctx.builder, OPSIZE_32); codegen::gen_set_flags_changed( ctx.builder, FLAGS_ALL & !FLAG_CARRY & !FLAG_OVERFLOW & !FLAG_ADJUST, ); ctx.builder.const_i32(global_pointers::flags as i32); codegen::gen_get_flags(ctx.builder); ctx.builder .const_i32(!FLAG_CARRY & !FLAG_ADJUST & !FLAG_OVERFLOW); ctx.builder.and_i32(); // cf: (dest_operand ^ ((dest_operand ^ source_operand) & (source_operand ^ res))) >> op_size & FLAG_CARRY ctx.builder.get_local(&dest_operand); ctx.builder.get_local(&dest_operand); source_operand.gen_get(ctx.builder); ctx.builder.xor_i32(); source_operand.gen_get(ctx.builder); ctx.builder.get_local(&res); ctx.builder.xor_i32(); ctx.builder.and_i32(); ctx.builder.xor_i32(); ctx.builder.const_i32(31); ctx.builder.shr_u_i32(); ctx.builder.const_i32(FLAG_CARRY); ctx.builder.and_i32(); ctx.builder.or_i32(); // af: (dest_operand ^ source_operand ^ res) & FLAG_ADJUST ctx.builder.get_local(&dest_operand); source_operand.gen_get(ctx.builder); ctx.builder.get_local(&res); ctx.builder.xor_i32(); ctx.builder.xor_i32(); ctx.builder.const_i32(FLAG_ADJUST); ctx.builder.and_i32(); ctx.builder.or_i32(); // of: ((source_operand ^ res) & (dest_operand ^ res)) >> op_size << 11 & FLAG_OVERFLOW source_operand.gen_get(ctx.builder); ctx.builder.get_local(&res); ctx.builder.xor_i32(); ctx.builder.get_local(&dest_operand); ctx.builder.get_local(&res); ctx.builder.xor_i32(); ctx.builder.and_i32(); ctx.builder.const_i32(31 - 11); ctx.builder.shr_u_i32(); ctx.builder.const_i32(FLAG_OVERFLOW); ctx.builder.and_i32(); ctx.builder.or_i32(); ctx.builder.store_aligned_i32(0); ctx.builder.get_local(&res); ctx.builder.set_local(dest_operand); ctx.builder.free_local(res); } fn gen_sbb8(ctx: &mut JitContext, dest_operand: &WasmLocal, source_operand: &LocalOrImmediate) { ctx.builder.get_local(dest_operand); ctx.builder.const_i32(0xFF); ctx.builder.and_i32(); source_operand.gen_get_mask255(ctx.builder); ctx.builder.call_fn2_ret("sbb8"); ctx.builder.const_i32(0xFF); ctx.builder.and_i32(); } fn gen_sbb32(ctx: &mut JitContext, dest_operand: &WasmLocal, source_operand: &LocalOrImmediate) { ctx.builder.get_local(&dest_operand); source_operand.gen_get(ctx.builder); ctx.builder.sub_i32(); codegen::gen_getcf_unoptimised(ctx.builder); ctx.builder.sub_i32(); let res = ctx.builder.set_new_local(); codegen::gen_set_last_result(ctx.builder, &res); codegen::gen_set_last_op_size(ctx.builder, OPSIZE_32); codegen::gen_set_flags_changed( ctx.builder, FLAGS_ALL & !FLAG_CARRY & !FLAG_OVERFLOW & !FLAG_ADJUST, ); ctx.builder.const_i32(global_pointers::flags as i32); codegen::gen_get_flags(ctx.builder); ctx.builder .const_i32(!FLAG_CARRY & !FLAG_ADJUST & !FLAG_OVERFLOW); ctx.builder.and_i32(); // cf: (res ^ ((res ^ source_operand) & (source_operand ^ dest_operand))) >> op_size & FLAG_CARRY ctx.builder.get_local(&res); ctx.builder.get_local(&res); source_operand.gen_get(ctx.builder); ctx.builder.xor_i32(); source_operand.gen_get(ctx.builder); ctx.builder.get_local(&dest_operand); ctx.builder.xor_i32(); ctx.builder.and_i32(); ctx.builder.xor_i32(); ctx.builder.const_i32(31); ctx.builder.shr_u_i32(); ctx.builder.const_i32(FLAG_CARRY); ctx.builder.and_i32(); ctx.builder.or_i32(); // af: (dest_operand ^ source_operand ^ res) & FLAG_ADJUST ctx.builder.get_local(&dest_operand); source_operand.gen_get(ctx.builder); ctx.builder.get_local(&res); ctx.builder.xor_i32(); ctx.builder.xor_i32(); ctx.builder.const_i32(FLAG_ADJUST); ctx.builder.and_i32(); ctx.builder.or_i32(); // of: ((source_operand ^ dest_operand) & (res ^ dest_operand)) >> op_size << 11 & FLAG_OVERFLOW source_operand.gen_get(ctx.builder); ctx.builder.get_local(&dest_operand); ctx.builder.xor_i32(); ctx.builder.get_local(&res); ctx.builder.get_local(&dest_operand); ctx.builder.xor_i32(); ctx.builder.and_i32(); ctx.builder.const_i32(31 - 11); ctx.builder.shr_u_i32(); ctx.builder.const_i32(FLAG_OVERFLOW); ctx.builder.and_i32(); ctx.builder.or_i32(); ctx.builder.store_aligned_i32(0); ctx.builder.get_local(&res); ctx.builder.set_local(dest_operand); ctx.builder.free_local(res); } fn gen_and8(ctx: &mut JitContext, dest_operand: &WasmLocal, source_operand: &LocalOrImmediate) { ctx.current_instruction = Instruction::Arithmetic { opsize: OPSIZE_8 }; ctx.builder.const_i32(global_pointers::last_result as i32); ctx.builder.get_local(dest_operand); source_operand.gen_get(ctx.builder); ctx.builder.and_i32(); ctx.builder.store_aligned_i32(0); codegen::gen_set_last_op_size(ctx.builder, OPSIZE_8); codegen::gen_set_flags_changed( ctx.builder, FLAGS_ALL & !FLAG_CARRY & !FLAG_OVERFLOW & !FLAG_ADJUST, ); codegen::gen_clear_flags_bits(ctx.builder, FLAG_CARRY | FLAG_OVERFLOW | FLAG_ADJUST); ctx.builder .load_fixed_u8(global_pointers::last_result as u32); } fn gen_and32(ctx: &mut JitContext, dest_operand: &WasmLocal, source_operand: &LocalOrImmediate) { ctx.current_instruction = Instruction::Arithmetic { opsize: OPSIZE_32 }; ctx.builder.get_local(&dest_operand); source_operand.gen_get(ctx.builder); ctx.builder.and_i32(); ctx.builder.set_local(dest_operand); codegen::gen_set_last_result(ctx.builder, &dest_operand); codegen::gen_set_last_op_size(ctx.builder, OPSIZE_32); codegen::gen_set_flags_changed( ctx.builder, FLAGS_ALL & !FLAG_CARRY & !FLAG_OVERFLOW & !FLAG_ADJUST, ); codegen::gen_clear_flags_bits(ctx.builder, FLAG_CARRY | FLAG_OVERFLOW | FLAG_ADJUST); } fn gen_test( ctx: &mut JitContext, dest_operand: &WasmLocal, source_operand: &LocalOrImmediate, size: i32, ) { ctx.current_instruction = Instruction::Arithmetic { opsize: size }; ctx.builder.const_i32(global_pointers::last_result as i32); if source_operand.eq_local(dest_operand) { ctx.builder.get_local(&dest_operand); } else { ctx.builder.get_local(&dest_operand); source_operand.gen_get(ctx.builder); ctx.builder.and_i32(); } ctx.builder.store_aligned_i32(0); codegen::gen_set_last_op_size(ctx.builder, size); codegen::gen_set_flags_changed( ctx.builder, FLAGS_ALL & !FLAG_CARRY & !FLAG_OVERFLOW & !FLAG_ADJUST, ); codegen::gen_clear_flags_bits(ctx.builder, FLAG_CARRY | FLAG_OVERFLOW | FLAG_ADJUST); } fn gen_test8(ctx: &mut JitContext, dest: &WasmLocal, source: &LocalOrImmediate) { gen_test(ctx, dest, source, OPSIZE_8) } fn gen_test16(ctx: &mut JitContext, dest: &WasmLocal, source: &LocalOrImmediate) { gen_test(ctx, dest, source, OPSIZE_16) } fn gen_test32(ctx: &mut JitContext, dest: &WasmLocal, source: &LocalOrImmediate) { gen_test(ctx, dest, source, OPSIZE_32) } fn gen_or8(ctx: &mut JitContext, dest_operand: &WasmLocal, source_operand: &LocalOrImmediate) { ctx.current_instruction = Instruction::Arithmetic { opsize: OPSIZE_8 }; ctx.builder.const_i32(global_pointers::last_result as i32); ctx.builder.get_local(dest_operand); source_operand.gen_get(ctx.builder); ctx.builder.or_i32(); ctx.builder.store_aligned_i32(0); codegen::gen_set_last_op_size(ctx.builder, OPSIZE_8); codegen::gen_set_flags_changed( ctx.builder, FLAGS_ALL & !FLAG_CARRY & !FLAG_OVERFLOW & !FLAG_ADJUST, ); codegen::gen_clear_flags_bits(ctx.builder, FLAG_CARRY | FLAG_OVERFLOW | FLAG_ADJUST); ctx.builder .load_fixed_u8(global_pointers::last_result as u32); } fn gen_or32(ctx: &mut JitContext, dest_operand: &WasmLocal, source_operand: &LocalOrImmediate) { ctx.current_instruction = Instruction::Arithmetic { opsize: OPSIZE_32 }; ctx.builder.get_local(&dest_operand); source_operand.gen_get(ctx.builder); ctx.builder.or_i32(); ctx.builder.set_local(dest_operand); codegen::gen_set_last_result(ctx.builder, &dest_operand); codegen::gen_set_last_op_size(ctx.builder, OPSIZE_32); codegen::gen_set_flags_changed( ctx.builder, FLAGS_ALL & !FLAG_CARRY & !FLAG_OVERFLOW & !FLAG_ADJUST, ); codegen::gen_clear_flags_bits(ctx.builder, FLAG_CARRY | FLAG_OVERFLOW | FLAG_ADJUST); } fn gen_xor8(ctx: &mut JitContext, dest_operand: &WasmLocal, source_operand: &LocalOrImmediate) { ctx.current_instruction = Instruction::Arithmetic { opsize: OPSIZE_8 }; ctx.builder.const_i32(global_pointers::last_result as i32); ctx.builder.get_local(dest_operand); source_operand.gen_get(ctx.builder); ctx.builder.xor_i32(); ctx.builder.store_aligned_i32(0); codegen::gen_set_last_op_size(ctx.builder, OPSIZE_8); codegen::gen_set_flags_changed( ctx.builder, FLAGS_ALL & !FLAG_CARRY & !FLAG_OVERFLOW & !FLAG_ADJUST, ); codegen::gen_clear_flags_bits(ctx.builder, FLAG_CARRY | FLAG_OVERFLOW | FLAG_ADJUST); ctx.builder .load_fixed_u8(global_pointers::last_result as u32); } fn gen_xor32(ctx: &mut JitContext, dest_operand: &WasmLocal, source_operand: &LocalOrImmediate) { ctx.current_instruction = Instruction::Arithmetic { opsize: OPSIZE_32 }; if source_operand.eq_local(dest_operand) { ctx.builder.const_i32(0); ctx.builder.set_local(dest_operand); // TODO: // - Set last_result to zero rather than reading from local // - Skip setting opsize (not relevant for SF, ZF, and PF on zero) } else { ctx.builder.get_local(&dest_operand); source_operand.gen_get(ctx.builder); ctx.builder.xor_i32(); ctx.builder.set_local(dest_operand); } codegen::gen_set_last_result(ctx.builder, &dest_operand); codegen::gen_set_last_op_size(ctx.builder, OPSIZE_32); codegen::gen_set_flags_changed( ctx.builder, FLAGS_ALL & !FLAG_CARRY & !FLAG_OVERFLOW & !FLAG_ADJUST, ); codegen::gen_clear_flags_bits(ctx.builder, FLAG_CARRY | FLAG_OVERFLOW | FLAG_ADJUST); } fn gen_rol32(ctx: &mut JitContext, dest_operand: &WasmLocal, source_operand: &LocalOrImmediate) { let builder = &mut ctx.builder; builder.get_local(dest_operand); match source_operand { LocalOrImmediate::WasmLocal(l) => { builder.get_local(l); builder.const_i32(31); builder.and_i32(); }, LocalOrImmediate::Immediate(i) => { builder.const_i32(*i & 31); }, } builder.const_i32(31); builder.and_i32(); builder.call_fn2_ret("rol32"); builder.set_local(dest_operand); } fn gen_ror32(ctx: &mut JitContext, dest_operand: &WasmLocal, source_operand: &LocalOrImmediate) { let builder = &mut ctx.builder; builder.get_local(dest_operand); match source_operand { LocalOrImmediate::WasmLocal(l) => { builder.get_local(l); builder.const_i32(31); builder.and_i32(); }, LocalOrImmediate::Immediate(i) => { builder.const_i32(*i & 31); }, } builder.const_i32(31); builder.and_i32(); builder.call_fn2_ret("ror32"); builder.set_local(dest_operand); } fn gen_rcl32(ctx: &mut JitContext, dest_operand: &WasmLocal, source_operand: &LocalOrImmediate) { let builder = &mut ctx.builder; builder.get_local(dest_operand); match source_operand { LocalOrImmediate::WasmLocal(l) => { builder.get_local(l); builder.const_i32(31); builder.and_i32(); }, LocalOrImmediate::Immediate(i) => { builder.const_i32(*i & 31); }, } builder.const_i32(31); builder.and_i32(); builder.call_fn2_ret("rcl32"); builder.set_local(dest_operand); } fn gen_rcr32(ctx: &mut JitContext, dest_operand: &WasmLocal, source_operand: &LocalOrImmediate) { let builder = &mut ctx.builder; builder.get_local(dest_operand); match source_operand { LocalOrImmediate::WasmLocal(l) => { builder.get_local(l); builder.const_i32(31); builder.and_i32(); }, LocalOrImmediate::Immediate(i) => { builder.const_i32(*i & 31); }, } builder.const_i32(31); builder.and_i32(); builder.call_fn2_ret("rcr32"); builder.set_local(dest_operand); } enum ShiftCount { Local(WasmLocal), Immediate(i32), } impl ShiftCount { pub fn gen_get(builder: &mut WasmBuilder, count: &ShiftCount) { match &count { ShiftCount::Local(l) => builder.get_local(l), ShiftCount::Immediate(i) => builder.const_i32(*i), } } pub fn gen_get_thirtytwo_minus(builder: &mut WasmBuilder, count: &ShiftCount) { match &count { ShiftCount::Local(l) => { builder.const_i32(32); builder.get_local(l); builder.sub_i32(); }, ShiftCount::Immediate(i) => builder.const_i32(32 - *i), } } pub fn gen_get_minus_one(builder: &mut WasmBuilder, count: &ShiftCount) { match &count { ShiftCount::Local(l) => { builder.get_local(l); builder.const_i32(1); builder.sub_i32() }, ShiftCount::Immediate(i) => builder.const_i32(*i - 1), } } } fn gen_shl32(ctx: &mut JitContext, dest_operand: &WasmLocal, source_operand: &LocalOrImmediate) { let builder = &mut ctx.builder; let count = match source_operand { LocalOrImmediate::WasmLocal(l) => { let exit = builder.block_void(); builder.get_local(l); builder.const_i32(31); // Note: mask can probably be avoided since wasm has the same semantics on shl_i32 builder.and_i32(); let count = builder.tee_new_local(); builder.eqz_i32(); builder.br_if(exit); ShiftCount::Local(count) }, LocalOrImmediate::Immediate(i) => { if *i & 31 == 0 { return; } ShiftCount::Immediate(*i & 31) }, }; builder.get_local(&dest_operand); ShiftCount::gen_get_thirtytwo_minus(builder, &count); builder.shr_u_i32(); builder.const_i32(1); builder.and_i32(); let b = builder.set_new_local(); builder.get_local(dest_operand); ShiftCount::gen_get(builder, &count); builder.shl_i32(); builder.set_local(dest_operand); codegen::gen_set_last_result(builder, dest_operand); codegen::gen_set_last_op_size(builder, OPSIZE_32); codegen::gen_set_flags_changed(builder, FLAGS_ALL & !FLAG_CARRY & !FLAG_OVERFLOW); builder.const_i32(global_pointers::flags as i32); codegen::gen_get_flags(builder); builder.const_i32(!(FLAG_CARRY | FLAG_OVERFLOW)); builder.and_i32(); builder.get_local(&b); builder.or_i32(); { builder.get_local(&b); builder.get_local(&dest_operand); builder.const_i32(31); builder.shr_u_i32(); builder.xor_i32(); builder.const_i32(11); builder.shl_i32(); builder.const_i32(FLAG_OVERFLOW); builder.and_i32(); builder.or_i32(); } builder.store_aligned_i32(0); builder.free_local(b); if let ShiftCount::Local(l) = count { builder.block_end(); builder.free_local(l); } } fn gen_shr32(ctx: &mut JitContext, dest_operand: &WasmLocal, source_operand: &LocalOrImmediate) { let builder = &mut ctx.builder; let count = match source_operand { LocalOrImmediate::WasmLocal(l) => { let exit = builder.block_void(); builder.get_local(l); builder.const_i32(31); // Note: mask can probably be avoided since wasm has the same semantics on shl_i32 builder.and_i32(); let count = builder.tee_new_local(); builder.eqz_i32(); builder.br_if(exit); ShiftCount::Local(count) }, LocalOrImmediate::Immediate(i) => { if *i & 31 == 0 { return; } ShiftCount::Immediate(*i & 31) }, }; builder.const_i32(global_pointers::flags as i32); codegen::gen_get_flags(builder); builder.const_i32(!(FLAG_CARRY | FLAG_OVERFLOW)); builder.and_i32(); { builder.get_local(dest_operand); ShiftCount::gen_get_minus_one(builder, &count); builder.shr_u_i32(); builder.const_i32(1); builder.and_i32(); builder.or_i32() } { builder.get_local(dest_operand); builder.const_i32(20); builder.shr_u_i32(); builder.const_i32(FLAG_OVERFLOW); builder.and_i32(); builder.or_i32() } builder.store_aligned_i32(0); builder.get_local(dest_operand); ShiftCount::gen_get(builder, &count); builder.shr_u_i32(); builder.set_local(dest_operand); codegen::gen_set_last_result(builder, dest_operand); codegen::gen_set_last_op_size(builder, OPSIZE_32); codegen::gen_set_flags_changed(builder, FLAGS_ALL & !FLAG_CARRY & !FLAG_OVERFLOW); if let ShiftCount::Local(l) = count { builder.block_end(); builder.free_local(l); } } fn gen_sar32(ctx: &mut JitContext, dest_operand: &WasmLocal, source_operand: &LocalOrImmediate) { let builder = &mut ctx.builder; let count = match source_operand { LocalOrImmediate::WasmLocal(l) => { let exit = builder.block_void(); builder.get_local(l); builder.const_i32(31); // Note: mask can probably be avoided since wasm has the same semantics on shl_i32 builder.and_i32(); let count = builder.tee_new_local(); builder.eqz_i32(); builder.br_if(exit); ShiftCount::Local(count) }, LocalOrImmediate::Immediate(i) => { if *i & 31 == 0 { return; } ShiftCount::Immediate(*i & 31) }, }; builder.const_i32(global_pointers::flags as i32); codegen::gen_get_flags(builder); builder.const_i32(!(FLAG_CARRY | FLAG_OVERFLOW)); builder.and_i32(); { builder.get_local(dest_operand); ShiftCount::gen_get_minus_one(builder, &count); builder.shr_u_i32(); builder.const_i32(1); builder.and_i32(); builder.or_i32() } builder.store_aligned_i32(0); builder.get_local(dest_operand); ShiftCount::gen_get(builder, &count); builder.shr_s_i32(); builder.set_local(dest_operand); codegen::gen_set_last_result(builder, dest_operand); codegen::gen_set_last_op_size(builder, OPSIZE_32); codegen::gen_set_flags_changed(builder, FLAGS_ALL & !FLAG_CARRY & !FLAG_OVERFLOW); if let ShiftCount::Local(l) = count { builder.block_end(); builder.free_local(l); } } fn gen_xadd32(ctx: &mut JitContext, dest_operand: &WasmLocal, r: u32) { ctx.builder.get_local(&ctx.register_locals[r as usize]); let tmp = ctx.builder.set_new_local(); ctx.builder.get_local(&dest_operand); codegen::gen_set_reg32(ctx, r); gen_add32(ctx, &dest_operand, &LocalOrImmediate::WasmLocal(&tmp)); ctx.builder.free_local(tmp); } fn gen_cmpxchg32(ctx: &mut JitContext, r: u32) { let source = ctx.builder.set_new_local(); ctx.builder.const_i32(global_pointers::last_result as i32); codegen::gen_get_reg32(ctx, regs::EAX); ctx.builder.get_local(&source); ctx.builder.sub_i32(); ctx.builder.store_aligned_i32(0); ctx.builder.const_i32(global_pointers::last_op1 as i32); codegen::gen_get_reg32(ctx, regs::EAX); ctx.builder.store_aligned_i32(0); codegen::gen_set_last_op_size(ctx.builder, OPSIZE_32); codegen::gen_set_flags_changed(ctx.builder, FLAGS_ALL | FLAG_SUB); codegen::gen_get_reg32(ctx, regs::EAX); ctx.builder.get_local(&source); ctx.builder.eq_i32(); ctx.builder.if_i32(); codegen::gen_get_reg32(ctx, r); ctx.builder.else_(); ctx.builder.get_local(&source); codegen::gen_set_reg32(ctx, regs::EAX); ctx.builder.get_local(&source); ctx.builder.block_end(); ctx.builder.free_local(source); } fn gen_mul32(ctx: &mut JitContext) { ctx.builder.extend_unsigned_i32_to_i64(); codegen::gen_get_reg32(ctx, regs::EAX); ctx.builder.extend_unsigned_i32_to_i64(); ctx.builder.mul_i64(); let result = ctx.builder.tee_new_local_i64(); ctx.builder.const_i64(32); ctx.builder.shr_u_i64(); ctx.builder.wrap_i64_to_i32(); codegen::gen_set_reg32(ctx, regs::EDX); ctx.builder.get_local_i64(&result); ctx.builder.free_local_i64(result); ctx.builder.wrap_i64_to_i32(); codegen::gen_set_reg32(ctx, regs::EAX); codegen::gen_get_reg32(ctx, regs::EDX); ctx.builder.if_void(); codegen::gen_set_flags_bits(ctx.builder, 1 | FLAG_OVERFLOW); ctx.builder.else_(); codegen::gen_clear_flags_bits(ctx.builder, 1 | FLAG_OVERFLOW); ctx.builder.block_end(); codegen::gen_set_last_result(ctx.builder, &ctx.register_locals[regs::EAX as usize]); codegen::gen_set_last_op_size(ctx.builder, OPSIZE_32); codegen::gen_set_flags_changed(ctx.builder, FLAGS_ALL & !1 & !FLAG_OVERFLOW); } fn gen_imul32(ctx: &mut JitContext) { ctx.builder.extend_signed_i32_to_i64(); codegen::gen_get_reg32(ctx, regs::EAX); ctx.builder.extend_signed_i32_to_i64(); ctx.builder.mul_i64(); let result = ctx.builder.tee_new_local_i64(); ctx.builder.const_i64(32); ctx.builder.shr_u_i64(); ctx.builder.wrap_i64_to_i32(); codegen::gen_set_reg32(ctx, regs::EDX); ctx.builder.get_local_i64(&result); ctx.builder.free_local_i64(result); ctx.builder.wrap_i64_to_i32(); codegen::gen_set_reg32(ctx, regs::EAX); codegen::gen_get_reg32(ctx, regs::EDX); codegen::gen_get_reg32(ctx, regs::EAX); ctx.builder.const_i32(31); ctx.builder.shr_s_i32(); ctx.builder.eq_i32(); ctx.builder.if_void(); codegen::gen_clear_flags_bits(ctx.builder, 1 | FLAG_OVERFLOW); ctx.builder.else_(); codegen::gen_set_flags_bits(ctx.builder, 1 | FLAG_OVERFLOW); ctx.builder.block_end(); codegen::gen_set_last_result(ctx.builder, &ctx.register_locals[regs::EAX as usize]); codegen::gen_set_last_op_size(ctx.builder, OPSIZE_32); codegen::gen_set_flags_changed(ctx.builder, FLAGS_ALL & !1 & !FLAG_OVERFLOW); } fn gen_imul_reg32( ctx: &mut JitContext, dest_operand: &WasmLocal, source_operand: &LocalOrImmediate, ) { gen_imul3_reg32(ctx.builder, dest_operand, dest_operand, source_operand); } fn gen_imul3_reg32( builder: &mut WasmBuilder, dest_operand: &WasmLocal, source_operand1: &WasmLocal, source_operand2: &LocalOrImmediate, ) { builder.get_local(&source_operand1); builder.extend_signed_i32_to_i64(); source_operand2.gen_get(builder); builder.extend_signed_i32_to_i64(); builder.mul_i64(); let result = builder.tee_new_local_i64(); builder.wrap_i64_to_i32(); builder.set_local(&dest_operand); codegen::gen_set_last_result(builder, &dest_operand); codegen::gen_set_last_op_size(builder, OPSIZE_32); codegen::gen_set_flags_changed(builder, FLAGS_ALL & !1 & !FLAG_OVERFLOW); builder.const_i32(global_pointers::flags as i32); builder.get_local_i64(&result); builder.wrap_i64_to_i32(); builder.extend_signed_i32_to_i64(); builder.get_local_i64(&result); builder.ne_i64(); builder.const_i32(1 | FLAG_OVERFLOW); builder.mul_i32(); codegen::gen_get_flags(builder); builder.const_i32(!1 & !FLAG_OVERFLOW); builder.and_i32(); builder.or_i32(); builder.store_aligned_i32(0); builder.free_local_i64(result); } fn gen_div32(ctx: &mut JitContext, source: &WasmLocal) { let done = ctx.builder.block_void(); { let exception = ctx.builder.block_void(); { ctx.builder.get_local(source); ctx.builder.eqz_i32(); ctx.builder.br_if(exception); codegen::gen_get_reg32(ctx, regs::EDX); ctx.builder.extend_unsigned_i32_to_i64(); ctx.builder.const_i64(32); ctx.builder.shl_i64(); codegen::gen_get_reg32(ctx, regs::EAX); ctx.builder.extend_unsigned_i32_to_i64(); ctx.builder.or_i64(); let dest_operand = ctx.builder.tee_new_local_i64(); ctx.builder.get_local(source); ctx.builder.extend_unsigned_i32_to_i64(); ctx.builder.div_i64(); let result = ctx.builder.tee_new_local_i64(); ctx.builder.const_i64(0xFFFF_FFFF); ctx.builder.gtu_i64(); ctx.builder.br_if(exception); ctx.builder.get_local_i64(&dest_operand); ctx.builder.get_local(source); ctx.builder.extend_unsigned_i32_to_i64(); ctx.builder.rem_i64(); ctx.builder.wrap_i64_to_i32(); codegen::gen_set_reg32(ctx, regs::EDX); ctx.builder.get_local_i64(&result); ctx.builder.wrap_i64_to_i32(); codegen::gen_set_reg32(ctx, regs::EAX); ctx.builder.br(done); ctx.builder.free_local_i64(dest_operand); ctx.builder.free_local_i64(result); } ctx.builder.block_end(); codegen::gen_trigger_de(ctx); } ctx.builder.block_end(); } fn gen_bt( builder: &mut WasmBuilder, bit_base: &WasmLocal, bit_offset: &LocalOrImmediate, offset_mask: u32, ) { builder.const_i32(global_pointers::flags as i32); codegen::gen_get_flags(builder); builder.const_i32(!1); builder.and_i32(); builder.get_local(bit_base); match bit_offset { LocalOrImmediate::WasmLocal(l) => { builder.get_local(l); builder.const_i32(offset_mask as i32); builder.and_i32(); }, LocalOrImmediate::Immediate(imm) => builder.const_i32(imm & offset_mask as i32), } builder.shr_u_i32(); builder.const_i32(1); builder.and_i32(); builder.or_i32(); builder.store_aligned_i32(0); codegen::gen_clear_flags_changed_bits(builder, 1); } fn gen_bts( builder: &mut WasmBuilder, dest_bit_base: &WasmLocal, bit_offset: &LocalOrImmediate, offset_mask: u32, ) { gen_bt(builder, dest_bit_base, bit_offset, offset_mask); builder.get_local(dest_bit_base); match bit_offset { LocalOrImmediate::WasmLocal(l) => { builder.const_i32(1); builder.get_local(l); builder.const_i32(offset_mask as i32); builder.and_i32(); builder.shl_i32(); }, LocalOrImmediate::Immediate(imm) => builder.const_i32(1 << (imm & offset_mask as i32)), } builder.or_i32(); builder.set_local(dest_bit_base); } fn gen_btc( builder: &mut WasmBuilder, dest_bit_base: &WasmLocal, bit_offset: &LocalOrImmediate, offset_mask: u32, ) { gen_bt(builder, dest_bit_base, bit_offset, offset_mask); builder.get_local(dest_bit_base); match bit_offset { LocalOrImmediate::WasmLocal(l) => { builder.const_i32(1); builder.get_local(l); builder.const_i32(offset_mask as i32); builder.and_i32(); builder.shl_i32(); }, LocalOrImmediate::Immediate(imm) => builder.const_i32(1 << (imm & offset_mask as i32)), } builder.xor_i32(); builder.set_local(dest_bit_base); } fn gen_btr( builder: &mut WasmBuilder, dest_bit_base: &WasmLocal, bit_offset: &LocalOrImmediate, offset_mask: u32, ) { gen_bt(builder, dest_bit_base, bit_offset, offset_mask); builder.get_local(dest_bit_base); match bit_offset { LocalOrImmediate::WasmLocal(l) => { builder.const_i32(1); builder.get_local(l); builder.const_i32(offset_mask as i32); builder.and_i32(); builder.shl_i32(); builder.const_i32(-1); builder.xor_i32(); }, LocalOrImmediate::Immediate(imm) => builder.const_i32(!(1 << (imm & offset_mask as i32))), } builder.and_i32(); builder.set_local(dest_bit_base); } fn gen_bit_rmw( ctx: &mut JitContext, modrm_byte: ModrmByte, op: &dyn Fn(&mut WasmBuilder, &WasmLocal, &LocalOrImmediate, u32), source_operand: &LocalOrImmediate, opsize: i32, ) { dbg_assert!(opsize == 16 || opsize == 32); codegen::gen_modrm_resolve(ctx, modrm_byte); match source_operand { LocalOrImmediate::WasmLocal(l) => { ctx.builder.get_local(l); if opsize == 16 { codegen::sign_extend_i16(ctx.builder); } ctx.builder.const_i32(3); ctx.builder.shr_s_i32(); ctx.builder.add_i32(); }, &LocalOrImmediate::Immediate(imm8) => { let offset = (imm8 as i32 & (opsize - 1)) >> 3; if offset != 0 { ctx.builder.const_i32(offset); ctx.builder.add_i32(); } }, } let address_local = ctx.builder.set_new_local(); codegen::gen_safe_read_write(ctx, BitSize::BYTE, &address_local, &|ref mut ctx| { let value_local = ctx.builder.set_new_local(); op(ctx.builder, &value_local, source_operand, 7); ctx.builder.get_local(&value_local); ctx.builder.free_local(value_local); }); ctx.builder.free_local(address_local); } fn gen_bsf32(ctx: &mut JitContext, dest_operand: &WasmLocal, source_operand: &LocalOrImmediate) { ctx.builder.get_local(&dest_operand); source_operand.gen_get(ctx.builder); ctx.builder.call_fn2_ret("bsf32"); ctx.builder.set_local(dest_operand); } fn gen_bsr32(ctx: &mut JitContext, dest_operand: &WasmLocal, source_operand: &LocalOrImmediate) { ctx.builder.get_local(&dest_operand); source_operand.gen_get(ctx.builder); ctx.builder.call_fn2_ret("bsr32"); ctx.builder.set_local(dest_operand); } fn gen_bswap(ctx: &mut JitContext, reg: i32) { let l = &ctx.register_locals[reg as usize]; ctx.builder.get_local(l); ctx.builder.const_i32(8); ctx.builder.rotl_i32(); ctx.builder.const_i32(0xFF00FF); ctx.builder.and_i32(); ctx.builder.get_local(l); ctx.builder.const_i32(24); ctx.builder.rotl_i32(); ctx.builder.const_i32(0xFF00FF00u32 as i32); ctx.builder.and_i32(); ctx.builder.or_i32(); ctx.builder.set_local(l); } define_instruction_read_write_mem8!(gen_add8, instr_00_mem_jit, instr_00_reg_jit, reg); define_instruction_read_write_mem16!("add16", instr16_01_mem_jit, instr16_01_reg_jit, reg); define_instruction_read_write_mem32!(gen_add32, instr32_01_mem_jit, instr32_01_reg_jit, reg); define_instruction_write_reg8!(gen_add8, instr_02_mem_jit, instr_02_reg_jit); define_instruction_write_reg16!("add16", instr16_03_mem_jit, instr16_03_reg_jit); define_instruction_write_reg32!(gen_add32, instr32_03_mem_jit, instr32_03_reg_jit); pub fn instr_04_jit(ctx: &mut JitContext, imm8: u32) { group_arith_al_imm8(ctx, &gen_add8, imm8); } pub fn instr16_05_jit(ctx: &mut JitContext, imm16: u32) { group_arith_ax_imm16(ctx, "add16", imm16); } pub fn instr32_05_jit(ctx: &mut JitContext, imm32: u32) { group_arith_eax_imm32(ctx, &gen_add32, imm32); } define_instruction_read_write_mem8!(gen_or8, instr_08_mem_jit, instr_08_reg_jit, reg); define_instruction_read_write_mem16!("or16", instr16_09_mem_jit, instr16_09_reg_jit, reg); define_instruction_read_write_mem32!(gen_or32, instr32_09_mem_jit, instr32_09_reg_jit, reg); define_instruction_write_reg8!(gen_or8, instr_0A_mem_jit, instr_0A_reg_jit); define_instruction_write_reg16!("or16", instr16_0B_mem_jit, instr16_0B_reg_jit); define_instruction_write_reg32!(gen_or32, instr32_0B_mem_jit, instr32_0B_reg_jit); pub fn instr_0C_jit(ctx: &mut JitContext, imm8: u32) { group_arith_al_imm8(ctx, &gen_or8, imm8); } pub fn instr16_0D_jit(ctx: &mut JitContext, imm16: u32) { group_arith_ax_imm16(ctx, "or16", imm16); } pub fn instr32_0D_jit(ctx: &mut JitContext, imm32: u32) { group_arith_eax_imm32(ctx, &gen_or32, imm32); } define_instruction_read_write_mem8!(gen_adc8, instr_10_mem_jit, instr_10_reg_jit, reg); define_instruction_read_write_mem16!("adc16", instr16_11_mem_jit, instr16_11_reg_jit, reg); define_instruction_read_write_mem32!(gen_adc32, instr32_11_mem_jit, instr32_11_reg_jit, reg); define_instruction_write_reg8!(gen_adc8, instr_12_mem_jit, instr_12_reg_jit); define_instruction_write_reg16!("adc16", instr16_13_mem_jit, instr16_13_reg_jit); define_instruction_write_reg32!(gen_adc32, instr32_13_mem_jit, instr32_13_reg_jit); pub fn instr_14_jit(ctx: &mut JitContext, imm8: u32) { group_arith_al_imm8(ctx, &gen_adc8, imm8); } pub fn instr16_15_jit(ctx: &mut JitContext, imm16: u32) { group_arith_ax_imm16(ctx, "adc16", imm16); } pub fn instr32_15_jit(ctx: &mut JitContext, imm32: u32) { group_arith_eax_imm32(ctx, &gen_adc32, imm32); } define_instruction_read_write_mem8!(gen_sbb8, instr_18_mem_jit, instr_18_reg_jit, reg); define_instruction_read_write_mem16!("sbb16", instr16_19_mem_jit, instr16_19_reg_jit, reg); define_instruction_read_write_mem32!(gen_sbb32, instr32_19_mem_jit, instr32_19_reg_jit, reg); define_instruction_write_reg8!(gen_sbb8, instr_1A_mem_jit, instr_1A_reg_jit); define_instruction_write_reg16!("sbb16", instr16_1B_mem_jit, instr16_1B_reg_jit); define_instruction_write_reg32!(gen_sbb32, instr32_1B_mem_jit, instr32_1B_reg_jit); pub fn instr_1C_jit(ctx: &mut JitContext, imm8: u32) { group_arith_al_imm8(ctx, &gen_sbb8, imm8); } pub fn instr16_1D_jit(ctx: &mut JitContext, imm16: u32) { group_arith_ax_imm16(ctx, "sbb16", imm16); } pub fn instr32_1D_jit(ctx: &mut JitContext, imm32: u32) { group_arith_eax_imm32(ctx, &gen_sbb32, imm32); } define_instruction_read_write_mem8!(gen_and8, instr_20_mem_jit, instr_20_reg_jit, reg); define_instruction_read_write_mem16!("and16", instr16_21_mem_jit, instr16_21_reg_jit, reg); define_instruction_read_write_mem32!(gen_and32, instr32_21_mem_jit, instr32_21_reg_jit, reg); define_instruction_write_reg8!(gen_and8, instr_22_mem_jit, instr_22_reg_jit); define_instruction_write_reg16!("and16", instr16_23_mem_jit, instr16_23_reg_jit); define_instruction_write_reg32!(gen_and32, instr32_23_mem_jit, instr32_23_reg_jit); pub fn instr_24_jit(ctx: &mut JitContext, imm8: u32) { group_arith_al_imm8(ctx, &gen_and8, imm8); } pub fn instr16_25_jit(ctx: &mut JitContext, imm16: u32) { group_arith_ax_imm16(ctx, "and16", imm16); } pub fn instr32_25_jit(ctx: &mut JitContext, imm32: u32) { group_arith_eax_imm32(ctx, &gen_and32, imm32); } define_instruction_read_write_mem8!(gen_sub8, instr_28_mem_jit, instr_28_reg_jit, reg); define_instruction_read_write_mem16!("sub16", instr16_29_mem_jit, instr16_29_reg_jit, reg); define_instruction_read_write_mem32!(gen_sub32, instr32_29_mem_jit, instr32_29_reg_jit, reg); define_instruction_write_reg8!(gen_sub8, instr_2A_mem_jit, instr_2A_reg_jit); define_instruction_write_reg16!("sub16", instr16_2B_mem_jit, instr16_2B_reg_jit); define_instruction_write_reg32!(gen_sub32, instr32_2B_mem_jit, instr32_2B_reg_jit); pub fn instr_2C_jit(ctx: &mut JitContext, imm8: u32) { group_arith_al_imm8(ctx, &gen_sub8, imm8); } pub fn instr16_2D_jit(ctx: &mut JitContext, imm16: u32) { group_arith_ax_imm16(ctx, "sub16", imm16); } pub fn instr32_2D_jit(ctx: &mut JitContext, imm32: u32) { group_arith_eax_imm32(ctx, &gen_sub32, imm32); } define_instruction_read_write_mem8!(gen_xor8, instr_30_mem_jit, instr_30_reg_jit, reg); define_instruction_read_write_mem16!("xor16", instr16_31_mem_jit, instr16_31_reg_jit, reg); define_instruction_read_write_mem32!(gen_xor32, instr32_31_mem_jit, instr32_31_reg_jit, reg); define_instruction_write_reg8!(gen_xor8, instr_32_mem_jit, instr_32_reg_jit); define_instruction_write_reg16!("xor16", instr16_33_mem_jit, instr16_33_reg_jit); define_instruction_write_reg32!(gen_xor32, instr32_33_mem_jit, instr32_33_reg_jit); pub fn instr_34_jit(ctx: &mut JitContext, imm8: u32) { group_arith_al_imm8(ctx, &gen_xor8, imm8); } pub fn instr16_35_jit(ctx: &mut JitContext, imm16: u32) { group_arith_ax_imm16(ctx, "xor16", imm16); } pub fn instr32_35_jit(ctx: &mut JitContext, imm32: u32) { group_arith_eax_imm32(ctx, &gen_xor32, imm32); } define_instruction_read8!(gen_cmp8, instr_38_mem_jit, instr_38_reg_jit); define_instruction_read16!(gen_cmp16, instr16_39_mem_jit, instr16_39_reg_jit); define_instruction_read32!(gen_cmp32, instr32_39_mem_jit, instr32_39_reg_jit); pub fn instr_3A_mem_jit(ctx: &mut JitContext, modrm_byte: ModrmByte, r: u32) { let dest_operand = codegen::gen_get_reg8_or_alias_to_reg32(ctx, r); codegen::gen_modrm_resolve_safe_read8(ctx, modrm_byte); let source_operand = ctx.builder.set_new_local(); gen_cmp8( ctx, &dest_operand, &LocalOrImmediate::WasmLocal(&source_operand), ); codegen::gen_free_reg8_or_alias(ctx, r, dest_operand); ctx.builder.free_local(source_operand); } pub fn instr_3A_reg_jit(ctx: &mut JitContext, r1: u32, r2: u32) { let dest_operand = codegen::gen_get_reg8_or_alias_to_reg32(ctx, r2); let source_operand = codegen::gen_get_reg8_or_alias_to_reg32(ctx, r1); gen_cmp8( ctx, &dest_operand, &LocalOrImmediate::WasmLocal(&source_operand), ); codegen::gen_free_reg8_or_alias(ctx, r2, dest_operand); codegen::gen_free_reg8_or_alias(ctx, r1, source_operand); } pub fn instr16_3B_mem_jit(ctx: &mut JitContext, modrm_byte: ModrmByte, r: u32) { codegen::gen_modrm_resolve_safe_read16(ctx, modrm_byte); let source_operand = ctx.builder.set_new_local(); gen_cmp16( ctx, &ctx.reg(r), &LocalOrImmediate::WasmLocal(&source_operand), ); ctx.builder.free_local(source_operand); } pub fn instr16_3B_reg_jit(ctx: &mut JitContext, r1: u32, r2: u32) { gen_cmp16( ctx, &ctx.reg(r2), &LocalOrImmediate::WasmLocal(&ctx.reg(r1)), ); } pub fn instr32_3B_mem_jit(ctx: &mut JitContext, modrm_byte: ModrmByte, r: u32) { codegen::gen_modrm_resolve_safe_read32(ctx, modrm_byte); let source_operand = ctx.builder.set_new_local(); gen_cmp32( ctx, &ctx.reg(r), &LocalOrImmediate::WasmLocal(&source_operand), ); ctx.builder.free_local(source_operand); } pub fn instr32_3B_reg_jit(ctx: &mut JitContext, r1: u32, r2: u32) { gen_cmp32( ctx, &ctx.reg(r2), &LocalOrImmediate::WasmLocal(&ctx.reg(r1)), ); } pub fn instr_3C_jit(ctx: &mut JitContext, imm8: u32) { gen_cmp8(ctx, &ctx.reg(0), &LocalOrImmediate::Immediate(imm8 as i32)); } pub fn instr16_3D_jit(ctx: &mut JitContext, imm16: u32) { gen_cmp16(ctx, &ctx.reg(0), &LocalOrImmediate::Immediate(imm16 as i32)); } pub fn instr32_3D_jit(ctx: &mut JitContext, imm32: u32) { gen_cmp32(ctx, &ctx.reg(0), &LocalOrImmediate::Immediate(imm32 as i32)); } fn gen_inc(ctx: &mut JitContext, dest_operand: &WasmLocal, size: i32) { ctx.current_instruction = Instruction::Arithmetic { opsize: size }; let builder = &mut ctx.builder; builder.const_i32(global_pointers::flags as i32); codegen::gen_get_flags(builder); builder.const_i32(!1); builder.and_i32(); codegen::gen_getcf_unoptimised(builder); builder.or_i32(); builder.store_aligned_i32(0); builder.const_i32(global_pointers::last_op1 as i32); builder.get_local(&dest_operand); if size == OPSIZE_8 || size == OPSIZE_16 { builder.const_i32(if size == OPSIZE_8 { 0xFF } else { 0xFFFF }); builder.and_i32(); } builder.store_aligned_i32(0); builder.get_local(dest_operand); builder.const_i32(1); builder.add_i32(); if size == OPSIZE_16 { codegen::gen_set_reg16_local(builder, dest_operand); } else { builder.set_local(dest_operand); } builder.const_i32(global_pointers::last_result as i32); builder.get_local(&dest_operand); if size == OPSIZE_16 { builder.const_i32(0xFFFF); builder.and_i32(); } builder.store_aligned_i32(0); codegen::gen_set_last_op_size(builder, size); codegen::gen_set_flags_changed(builder, FLAGS_ALL & !1); } fn gen_inc16(ctx: &mut JitContext, dest_operand: &WasmLocal) { gen_inc(ctx, dest_operand, OPSIZE_16); } fn gen_inc32(ctx: &mut JitContext, dest_operand: &WasmLocal) { gen_inc(ctx, dest_operand, OPSIZE_32); } fn gen_dec(ctx: &mut JitContext, dest_operand: &WasmLocal, size: i32) { ctx.current_instruction = Instruction::Arithmetic { opsize: size }; let builder = &mut ctx.builder; builder.const_i32(global_pointers::flags as i32); codegen::gen_get_flags(builder); builder.const_i32(!1); builder.and_i32(); codegen::gen_getcf_unoptimised(builder); builder.or_i32(); builder.store_aligned_i32(0); builder.const_i32(global_pointers::last_op1 as i32); builder.get_local(&dest_operand); if size == OPSIZE_8 || size == OPSIZE_16 { builder.const_i32(if size == OPSIZE_8 { 0xFF } else { 0xFFFF }); builder.and_i32(); } builder.store_aligned_i32(0); builder.get_local(dest_operand); builder.const_i32(1); builder.sub_i32(); if size == OPSIZE_16 { codegen::gen_set_reg16_local(builder, dest_operand); } else { builder.set_local(dest_operand); } builder.const_i32(global_pointers::last_result as i32); builder.get_local(&dest_operand); if size == OPSIZE_16 { builder.const_i32(0xFFFF); builder.and_i32(); } builder.store_aligned_i32(0); codegen::gen_set_last_op_size(builder, size); codegen::gen_set_flags_changed(builder, FLAGS_ALL & !1 | FLAG_SUB); } fn gen_dec16(ctx: &mut JitContext, dest_operand: &WasmLocal) { gen_dec(ctx, dest_operand, OPSIZE_16) } fn gen_dec32(ctx: &mut JitContext, dest_operand: &WasmLocal) { gen_dec(ctx, dest_operand, OPSIZE_32) } fn gen_inc16_r(ctx: &mut JitContext, r: u32) { gen_inc16(ctx, &mut ctx.reg(r)) } fn gen_inc32_r(ctx: &mut JitContext, r: u32) { gen_inc32(ctx, &mut ctx.reg(r)) } fn gen_dec16_r(ctx: &mut JitContext, r: u32) { gen_dec16(ctx, &mut ctx.reg(r)) } fn gen_dec32_r(ctx: &mut JitContext, r: u32) { gen_dec32(ctx, &mut ctx.reg(r)) } fn gen_not16(ctx: &mut JitContext, dest_operand: &WasmLocal) { let builder = &mut ctx.builder; builder.get_local(dest_operand); builder.const_i32(-1); builder.xor_i32(); codegen::gen_set_reg16_local(builder, dest_operand); } fn gen_not32(ctx: &mut JitContext, dest_operand: &WasmLocal) { let builder = &mut ctx.builder; builder.get_local(dest_operand); builder.const_i32(-1); builder.xor_i32(); builder.set_local(dest_operand); } fn gen_neg16(ctx: &mut JitContext, dest_operand: &WasmLocal) { let builder = &mut ctx.builder; builder.get_local(dest_operand); builder.call_fn1_ret("neg16"); codegen::gen_set_reg16_local(builder, dest_operand); } fn gen_neg32(ctx: &mut JitContext, dest_operand: &WasmLocal) { let builder = &mut ctx.builder; builder.const_i32(global_pointers::last_op1 as i32); builder.const_i32(0); builder.store_aligned_i32(0); builder.const_i32(0); builder.get_local(&dest_operand); builder.sub_i32(); builder.set_local(dest_operand); codegen::gen_set_last_result(builder, &dest_operand); codegen::gen_set_last_op_size(builder, OPSIZE_32); codegen::gen_set_flags_changed(builder, FLAGS_ALL | FLAG_SUB); } pub fn instr16_06_jit(ctx: &mut JitContext) { codegen::gen_get_sreg(ctx, regs::ES); let sreg = ctx.builder.set_new_local(); codegen::gen_push16(ctx, &sreg); ctx.builder.free_local(sreg); } pub fn instr32_06_jit(ctx: &mut JitContext) { codegen::gen_get_sreg(ctx, regs::ES); let sreg = ctx.builder.set_new_local(); codegen::gen_push32(ctx, &sreg); ctx.builder.free_local(sreg); } pub fn instr16_0E_jit(ctx: &mut JitContext) { codegen::gen_get_sreg(ctx, regs::CS); let sreg = ctx.builder.set_new_local(); codegen::gen_push16(ctx, &sreg); ctx.builder.free_local(sreg); } pub fn instr32_0E_jit(ctx: &mut JitContext) { codegen::gen_get_sreg(ctx, regs::CS); let sreg = ctx.builder.set_new_local(); codegen::gen_push32(ctx, &sreg); ctx.builder.free_local(sreg); } pub fn instr16_16_jit(ctx: &mut JitContext) { codegen::gen_get_sreg(ctx, regs::SS); let sreg = ctx.builder.set_new_local(); codegen::gen_push16(ctx, &sreg); ctx.builder.free_local(sreg); } pub fn instr32_16_jit(ctx: &mut JitContext) { codegen::gen_get_sreg(ctx, regs::SS); let sreg = ctx.builder.set_new_local(); codegen::gen_push32(ctx, &sreg); ctx.builder.free_local(sreg); } pub fn instr16_1E_jit(ctx: &mut JitContext) { codegen::gen_get_sreg(ctx, regs::DS); let sreg = ctx.builder.set_new_local(); codegen::gen_push16(ctx, &sreg); ctx.builder.free_local(sreg); } pub fn instr32_1E_jit(ctx: &mut JitContext) { codegen::gen_get_sreg(ctx, regs::DS); let sreg = ctx.builder.set_new_local(); codegen::gen_push32(ctx, &sreg); ctx.builder.free_local(sreg); } pub fn instr16_40_jit(ctx: &mut JitContext) { gen_inc16_r(ctx, AX); } pub fn instr32_40_jit(ctx: &mut JitContext) { gen_inc32_r(ctx, EAX); } pub fn instr16_41_jit(ctx: &mut JitContext) { gen_inc16_r(ctx, CX); } pub fn instr32_41_jit(ctx: &mut JitContext) { gen_inc32_r(ctx, ECX); } pub fn instr16_42_jit(ctx: &mut JitContext) { gen_inc16_r(ctx, DX); } pub fn instr32_42_jit(ctx: &mut JitContext) { gen_inc32_r(ctx, EDX); } pub fn instr16_43_jit(ctx: &mut JitContext) { gen_inc16_r(ctx, BX); } pub fn instr32_43_jit(ctx: &mut JitContext) { gen_inc32_r(ctx, EBX); } pub fn instr16_44_jit(ctx: &mut JitContext) { gen_inc16_r(ctx, SP); } pub fn instr32_44_jit(ctx: &mut JitContext) { gen_inc32_r(ctx, ESP); } pub fn instr16_45_jit(ctx: &mut JitContext) { gen_inc16_r(ctx, BP); } pub fn instr32_45_jit(ctx: &mut JitContext) { gen_inc32_r(ctx, EBP); } pub fn instr16_46_jit(ctx: &mut JitContext) { gen_inc16_r(ctx, SI); } pub fn instr32_46_jit(ctx: &mut JitContext) { gen_inc32_r(ctx, ESI); } pub fn instr16_47_jit(ctx: &mut JitContext) { gen_inc16_r(ctx, DI); } pub fn instr32_47_jit(ctx: &mut JitContext) { gen_inc32_r(ctx, EDI); } pub fn instr16_48_jit(ctx: &mut JitContext) { gen_dec16_r(ctx, AX); } pub fn instr32_48_jit(ctx: &mut JitContext) { gen_dec32_r(ctx, EAX); } pub fn instr16_49_jit(ctx: &mut JitContext) { gen_dec16_r(ctx, CX); } pub fn instr32_49_jit(ctx: &mut JitContext) { gen_dec32_r(ctx, ECX); } pub fn instr16_4A_jit(ctx: &mut JitContext) { gen_dec16_r(ctx, DX); } pub fn instr32_4A_jit(ctx: &mut JitContext) { gen_dec32_r(ctx, EDX); } pub fn instr16_4B_jit(ctx: &mut JitContext) { gen_dec16_r(ctx, BX); } pub fn instr32_4B_jit(ctx: &mut JitContext) { gen_dec32_r(ctx, EBX); } pub fn instr16_4C_jit(ctx: &mut JitContext) { gen_dec16_r(ctx, SP); } pub fn instr32_4C_jit(ctx: &mut JitContext) { gen_dec32_r(ctx, ESP); } pub fn instr16_4D_jit(ctx: &mut JitContext) { gen_dec16_r(ctx, BP); } pub fn instr32_4D_jit(ctx: &mut JitContext) { gen_dec32_r(ctx, EBP); } pub fn instr16_4E_jit(ctx: &mut JitContext) { gen_dec16_r(ctx, SI); } pub fn instr32_4E_jit(ctx: &mut JitContext) { gen_dec32_r(ctx, ESI); } pub fn instr16_4F_jit(ctx: &mut JitContext) { gen_dec16_r(ctx, DI); } pub fn instr32_4F_jit(ctx: &mut JitContext) { gen_dec32_r(ctx, EDI); } pub fn instr16_50_jit(ctx: &mut JitContext) { push16_reg_jit(ctx, AX); } pub fn instr32_50_jit(ctx: &mut JitContext) { push32_reg_jit(ctx, EAX); } pub fn instr16_51_jit(ctx: &mut JitContext) { push16_reg_jit(ctx, CX); } pub fn instr32_51_jit(ctx: &mut JitContext) { push32_reg_jit(ctx, ECX); } pub fn instr16_52_jit(ctx: &mut JitContext) { push16_reg_jit(ctx, DX); } pub fn instr32_52_jit(ctx: &mut JitContext) { push32_reg_jit(ctx, EDX); } pub fn instr16_53_jit(ctx: &mut JitContext) { push16_reg_jit(ctx, BX); } pub fn instr32_53_jit(ctx: &mut JitContext) { push32_reg_jit(ctx, EBX); } pub fn instr16_54_jit(ctx: &mut JitContext) { push16_reg_jit(ctx, SP); } pub fn instr32_54_jit(ctx: &mut JitContext) { push32_reg_jit(ctx, ESP); } pub fn instr16_55_jit(ctx: &mut JitContext) { push16_reg_jit(ctx, BP); } pub fn instr32_55_jit(ctx: &mut JitContext) { push32_reg_jit(ctx, EBP); } pub fn instr16_56_jit(ctx: &mut JitContext) { push16_reg_jit(ctx, SI); } pub fn instr32_56_jit(ctx: &mut JitContext) { push32_reg_jit(ctx, ESI); } pub fn instr16_57_jit(ctx: &mut JitContext) { push16_reg_jit(ctx, DI); } pub fn instr32_57_jit(ctx: &mut JitContext) { push32_reg_jit(ctx, EDI); } pub fn instr16_58_jit(ctx: &mut JitContext) { pop16_reg_jit(ctx, AX); } pub fn instr32_58_jit(ctx: &mut JitContext) { pop32_reg_jit(ctx, EAX); } pub fn instr16_59_jit(ctx: &mut JitContext) { pop16_reg_jit(ctx, CX); } pub fn instr32_59_jit(ctx: &mut JitContext) { pop32_reg_jit(ctx, ECX); } pub fn instr16_5A_jit(ctx: &mut JitContext) { pop16_reg_jit(ctx, DX); } pub fn instr32_5A_jit(ctx: &mut JitContext) { pop32_reg_jit(ctx, EDX); } pub fn instr16_5B_jit(ctx: &mut JitContext) { pop16_reg_jit(ctx, BX); } pub fn instr32_5B_jit(ctx: &mut JitContext) { pop32_reg_jit(ctx, EBX); } pub fn instr16_5C_jit(ctx: &mut JitContext) { pop16_reg_jit(ctx, SP); } pub fn instr32_5C_jit(ctx: &mut JitContext) { pop32_reg_jit(ctx, ESP); } pub fn instr16_5D_jit(ctx: &mut JitContext) { pop16_reg_jit(ctx, BP); } pub fn instr32_5D_jit(ctx: &mut JitContext) { pop32_reg_jit(ctx, EBP); } pub fn instr16_5E_jit(ctx: &mut JitContext) { pop16_reg_jit(ctx, SI); } pub fn instr32_5E_jit(ctx: &mut JitContext) { pop32_reg_jit(ctx, ESI); } pub fn instr16_5F_jit(ctx: &mut JitContext) { pop16_reg_jit(ctx, DI); } pub fn instr32_5F_jit(ctx: &mut JitContext) { pop32_reg_jit(ctx, EDI); } pub fn instr16_68_jit(ctx: &mut JitContext, imm16: u32) { push16_imm_jit(ctx, imm16) } pub fn instr32_68_jit(ctx: &mut JitContext, imm32: u32) { push32_imm_jit(ctx, imm32) } pub fn instr16_6A_jit(ctx: &mut JitContext, imm16: u32) { push16_imm_jit(ctx, imm16) } pub fn instr32_6A_jit(ctx: &mut JitContext, imm32: u32) { push32_imm_jit(ctx, imm32) } pub fn instr16_69_mem_jit(ctx: &mut JitContext, modrm_byte: ModrmByte, r: u32, imm16: u32) { codegen::gen_modrm_resolve_safe_read16(ctx, modrm_byte); ctx.builder.const_i32(imm16 as i32); ctx.builder.call_fn2_ret("imul_reg16"); codegen::gen_set_reg16(ctx, r); } pub fn instr16_69_reg_jit(ctx: &mut JitContext, r1: u32, r2: u32, imm16: u32) { codegen::gen_get_reg16(ctx, r1); ctx.builder.const_i32(imm16 as i32); ctx.builder.call_fn2_ret("imul_reg16"); codegen::gen_set_reg16(ctx, r2); } pub fn instr32_69_mem_jit(ctx: &mut JitContext, modrm_byte: ModrmByte, r: u32, imm32: u32) { codegen::gen_modrm_resolve_safe_read32(ctx, modrm_byte); let value_local = ctx.builder.set_new_local(); gen_imul3_reg32( ctx.builder, &ctx.register_locals[r as usize], &value_local, &LocalOrImmediate::Immediate(imm32 as i32), ); ctx.builder.free_local(value_local); } pub fn instr32_69_reg_jit(ctx: &mut JitContext, r1: u32, r2: u32, imm32: u32) { gen_imul3_reg32( ctx.builder, &ctx.register_locals[r2 as usize], &ctx.register_locals[r1 as usize], &LocalOrImmediate::Immediate(imm32 as i32), ); } pub fn instr16_6B_mem_jit(ctx: &mut JitContext, modrm_byte: ModrmByte, r: u32, imm8s: u32) { codegen::gen_modrm_resolve_safe_read16(ctx, modrm_byte); ctx.builder.const_i32(imm8s as i32); ctx.builder.call_fn2_ret("imul_reg16"); codegen::gen_set_reg16(ctx, r); } pub fn instr16_6B_reg_jit(ctx: &mut JitContext, r1: u32, r2: u32, imm8s: u32) { codegen::gen_get_reg16(ctx, r1); ctx.builder.const_i32(imm8s as i32); ctx.builder.call_fn2_ret("imul_reg16"); codegen::gen_set_reg16(ctx, r2); } pub fn instr32_6B_mem_jit(ctx: &mut JitContext, modrm_byte: ModrmByte, r: u32, imm8s: u32) { codegen::gen_modrm_resolve_safe_read32(ctx, modrm_byte); let value_local = ctx.builder.set_new_local(); gen_imul3_reg32( ctx.builder, &ctx.register_locals[r as usize], &value_local, &LocalOrImmediate::Immediate(imm8s as i32), ); ctx.builder.free_local(value_local); } pub fn instr32_6B_reg_jit(ctx: &mut JitContext, r1: u32, r2: u32, imm8s: u32) { gen_imul3_reg32( ctx.builder, &ctx.register_locals[r2 as usize], &ctx.register_locals[r1 as usize], &LocalOrImmediate::Immediate(imm8s as i32), ); } // Code for conditional jumps is generated automatically by the basic block codegen pub fn instr16_70_jit(_ctx: &mut JitContext, _imm: u32) {} pub fn instr32_70_jit(_ctx: &mut JitContext, _imm: u32) {} pub fn instr16_71_jit(_ctx: &mut JitContext, _imm: u32) {} pub fn instr32_71_jit(_ctx: &mut JitContext, _imm: u32) {} pub fn instr16_72_jit(_ctx: &mut JitContext, _imm: u32) {} pub fn instr32_72_jit(_ctx: &mut JitContext, _imm: u32) {} pub fn instr16_73_jit(_ctx: &mut JitContext, _imm: u32) {} pub fn instr32_73_jit(_ctx: &mut JitContext, _imm: u32) {} pub fn instr16_74_jit(_ctx: &mut JitContext, _imm: u32) {} pub fn instr32_74_jit(_ctx: &mut JitContext, _imm: u32) {} pub fn instr16_75_jit(_ctx: &mut JitContext, _imm: u32) {} pub fn instr32_75_jit(_ctx: &mut JitContext, _imm: u32) {} pub fn instr16_76_jit(_ctx: &mut JitContext, _imm: u32) {} pub fn instr32_76_jit(_ctx: &mut JitContext, _imm: u32) {} pub fn instr16_77_jit(_ctx: &mut JitContext, _imm: u32) {} pub fn instr32_77_jit(_ctx: &mut JitContext, _imm: u32) {} pub fn instr16_78_jit(_ctx: &mut JitContext, _imm: u32) {} pub fn instr32_78_jit(_ctx: &mut JitContext, _imm: u32) {} pub fn instr16_79_jit(_ctx: &mut JitContext, _imm: u32) {} pub fn instr32_79_jit(_ctx: &mut JitContext, _imm: u32) {} pub fn instr16_7A_jit(_ctx: &mut JitContext, _imm: u32) {} pub fn instr32_7A_jit(_ctx: &mut JitContext, _imm: u32) {} pub fn instr16_7B_jit(_ctx: &mut JitContext, _imm: u32) {} pub fn instr32_7B_jit(_ctx: &mut JitContext, _imm: u32) {} pub fn instr16_7C_jit(_ctx: &mut JitContext, _imm: u32) {} pub fn instr32_7C_jit(_ctx: &mut JitContext, _imm: u32) {} pub fn instr16_7D_jit(_ctx: &mut JitContext, _imm: u32) {} pub fn instr32_7D_jit(_ctx: &mut JitContext, _imm: u32) {} pub fn instr16_7E_jit(_ctx: &mut JitContext, _imm: u32) {} pub fn instr32_7E_jit(_ctx: &mut JitContext, _imm: u32) {} pub fn instr16_7F_jit(_ctx: &mut JitContext, _imm: u32) {} pub fn instr32_7F_jit(_ctx: &mut JitContext, _imm: u32) {} // loop/loopz/loopnz/jcxz: Conditional jump is generated in main loop pub fn instr16_E0_jit(ctx: &mut JitContext, _imm: u32) { codegen::decr_exc_asize(ctx) } pub fn instr32_E0_jit(ctx: &mut JitContext, _imm: u32) { codegen::decr_exc_asize(ctx) } pub fn instr16_E1_jit(ctx: &mut JitContext, _imm: u32) { codegen::decr_exc_asize(ctx) } pub fn instr32_E1_jit(ctx: &mut JitContext, _imm: u32) { codegen::decr_exc_asize(ctx) } pub fn instr16_E2_jit(ctx: &mut JitContext, _imm: u32) { codegen::decr_exc_asize(ctx) } pub fn instr32_E2_jit(ctx: &mut JitContext, _imm: u32) { codegen::decr_exc_asize(ctx) } pub fn instr16_E3_jit(_ctx: &mut JitContext, _imm: u32) {} pub fn instr32_E3_jit(_ctx: &mut JitContext, _imm: u32) {} define_instruction_read_write_mem8!(gen_add8, instr_80_0_mem_jit, instr_80_0_reg_jit, ximm8); define_instruction_read_write_mem8!(gen_or8, instr_80_1_mem_jit, instr_80_1_reg_jit, ximm8); define_instruction_read_write_mem8!(gen_adc8, instr_80_2_mem_jit, instr_80_2_reg_jit, ximm8); define_instruction_read_write_mem8!(gen_sbb8, instr_80_3_mem_jit, instr_80_3_reg_jit, ximm8); define_instruction_read_write_mem8!(gen_and8, instr_80_4_mem_jit, instr_80_4_reg_jit, ximm8); define_instruction_read_write_mem8!(gen_sub8, instr_80_5_mem_jit, instr_80_5_reg_jit, ximm8); define_instruction_read_write_mem8!(gen_xor8, instr_80_6_mem_jit, instr_80_6_reg_jit, ximm8); define_instruction_read_write_mem8!(gen_add8, instr_82_0_mem_jit, instr_82_0_reg_jit, ximm8); define_instruction_read_write_mem8!(gen_or8, instr_82_1_mem_jit, instr_82_1_reg_jit, ximm8); define_instruction_read_write_mem8!(gen_adc8, instr_82_2_mem_jit, instr_82_2_reg_jit, ximm8); define_instruction_read_write_mem8!(gen_sbb8, instr_82_3_mem_jit, instr_82_3_reg_jit, ximm8); define_instruction_read_write_mem8!(gen_and8, instr_82_4_mem_jit, instr_82_4_reg_jit, ximm8); define_instruction_read_write_mem8!(gen_sub8, instr_82_5_mem_jit, instr_82_5_reg_jit, ximm8); define_instruction_read_write_mem8!(gen_xor8, instr_82_6_mem_jit, instr_82_6_reg_jit, ximm8); define_instruction_read_write_mem16!("add16", instr16_81_0_mem_jit, instr16_81_0_reg_jit, imm16); define_instruction_read_write_mem32!(gen_add32, instr32_81_0_mem_jit, instr32_81_0_reg_jit, imm32); define_instruction_read_write_mem16!("or16", instr16_81_1_mem_jit, instr16_81_1_reg_jit, imm16); define_instruction_read_write_mem32!(gen_or32, instr32_81_1_mem_jit, instr32_81_1_reg_jit, imm32); define_instruction_read_write_mem16!("adc16", instr16_81_2_mem_jit, instr16_81_2_reg_jit, imm16); define_instruction_read_write_mem32!(gen_adc32, instr32_81_2_mem_jit, instr32_81_2_reg_jit, imm32); define_instruction_read_write_mem16!("sbb16", instr16_81_3_mem_jit, instr16_81_3_reg_jit, imm16); define_instruction_read_write_mem32!(gen_sbb32, instr32_81_3_mem_jit, instr32_81_3_reg_jit, imm32); define_instruction_read_write_mem16!("and16", instr16_81_4_mem_jit, instr16_81_4_reg_jit, imm16); define_instruction_read_write_mem32!(gen_and32, instr32_81_4_mem_jit, instr32_81_4_reg_jit, imm32); define_instruction_read_write_mem16!("sub16", instr16_81_5_mem_jit, instr16_81_5_reg_jit, imm16); define_instruction_read_write_mem32!(gen_sub32, instr32_81_5_mem_jit, instr32_81_5_reg_jit, imm32); define_instruction_read_write_mem16!("xor16", instr16_81_6_mem_jit, instr16_81_6_reg_jit, imm16); define_instruction_read_write_mem32!(gen_xor32, instr32_81_6_mem_jit, instr32_81_6_reg_jit, imm32); define_instruction_read_write_mem16!( "add16", instr16_83_0_mem_jit, instr16_83_0_reg_jit, imm8s_16bits ); define_instruction_read_write_mem32!(gen_add32, instr32_83_0_mem_jit, instr32_83_0_reg_jit, imm8s); define_instruction_read_write_mem16!( "or16", instr16_83_1_mem_jit, instr16_83_1_reg_jit, imm8s_16bits ); define_instruction_read_write_mem32!(gen_or32, instr32_83_1_mem_jit, instr32_83_1_reg_jit, imm8s); define_instruction_read_write_mem16!( "adc16", instr16_83_2_mem_jit, instr16_83_2_reg_jit, imm8s_16bits ); define_instruction_read_write_mem32!(gen_adc32, instr32_83_2_mem_jit, instr32_83_2_reg_jit, imm8s); define_instruction_read_write_mem16!( "sbb16", instr16_83_3_mem_jit, instr16_83_3_reg_jit, imm8s_16bits ); define_instruction_read_write_mem32!(gen_sbb32, instr32_83_3_mem_jit, instr32_83_3_reg_jit, imm8s); define_instruction_read_write_mem16!( "and16", instr16_83_4_mem_jit, instr16_83_4_reg_jit, imm8s_16bits ); define_instruction_read_write_mem32!(gen_and32, instr32_83_4_mem_jit, instr32_83_4_reg_jit, imm8s); define_instruction_read_write_mem16!( "sub16", instr16_83_5_mem_jit, instr16_83_5_reg_jit, imm8s_16bits ); define_instruction_read_write_mem32!(gen_sub32, instr32_83_5_mem_jit, instr32_83_5_reg_jit, imm8s); define_instruction_read_write_mem16!( "xor16", instr16_83_6_mem_jit, instr16_83_6_reg_jit, imm8s_16bits ); define_instruction_read_write_mem32!(gen_xor32, instr32_83_6_mem_jit, instr32_83_6_reg_jit, imm8s); define_instruction_read8!(gen_cmp8, instr_80_7_mem_jit, instr_80_7_reg_jit, imm8); define_instruction_read16!(gen_cmp16, instr16_81_7_mem_jit, instr16_81_7_reg_jit, imm16); define_instruction_read32!(gen_cmp32, instr32_81_7_mem_jit, instr32_81_7_reg_jit, imm32); define_instruction_read8!(gen_cmp8, instr_82_7_mem_jit, instr_82_7_reg_jit, imm8); define_instruction_read16!( gen_cmp16, instr16_83_7_mem_jit, instr16_83_7_reg_jit, imm8s_16bits ); define_instruction_read32!(gen_cmp32, instr32_83_7_mem_jit, instr32_83_7_reg_jit, imm8s); define_instruction_read8!(gen_test8, instr_84_mem_jit, instr_84_reg_jit); define_instruction_read16!(gen_test16, instr16_85_mem_jit, instr16_85_reg_jit); define_instruction_read32!(gen_test32, instr32_85_mem_jit, instr32_85_reg_jit); pub fn instr_86_mem_jit(ctx: &mut JitContext, modrm_byte: ModrmByte, r: u32) { codegen::gen_modrm_resolve_with_local(ctx, modrm_byte, &|ctx, addr| { codegen::gen_safe_read_write(ctx, BitSize::BYTE, &addr, &|ref mut ctx| { codegen::gen_get_reg8(ctx, r); let tmp = ctx.builder.set_new_local(); codegen::gen_set_reg8(ctx, r); ctx.builder.get_local(&tmp); ctx.builder.free_local(tmp); }); }); } pub fn instr_86_reg_jit(ctx: &mut JitContext, r1: u32, r2: u32) { codegen::gen_get_reg8(ctx, r2); let tmp = ctx.builder.set_new_local(); codegen::gen_get_reg8(ctx, r1); codegen::gen_set_reg8(ctx, r2); ctx.builder.get_local(&tmp); codegen::gen_set_reg8(ctx, r1); ctx.builder.free_local(tmp); } pub fn instr16_87_mem_jit(ctx: &mut JitContext, modrm_byte: ModrmByte, r: u32) { codegen::gen_modrm_resolve_with_local(ctx, modrm_byte, &|ctx, addr| { codegen::gen_safe_read_write(ctx, BitSize::WORD, &addr, &|ref mut ctx| { codegen::gen_get_reg16(ctx, r); let tmp = ctx.builder.set_new_local(); codegen::gen_set_reg16(ctx, r); ctx.builder.get_local(&tmp); ctx.builder.free_local(tmp); }); }); } pub fn instr32_87_mem_jit(ctx: &mut JitContext, modrm_byte: ModrmByte, r: u32) { codegen::gen_modrm_resolve_with_local(ctx, modrm_byte, &|ctx, addr| { codegen::gen_safe_read_write(ctx, BitSize::DWORD, &addr, &|ref mut ctx| { codegen::gen_get_reg32(ctx, r); let tmp = ctx.builder.set_new_local(); codegen::gen_set_reg32(ctx, r); ctx.builder.get_local(&tmp); ctx.builder.free_local(tmp); }); }); } pub fn instr16_87_reg_jit(ctx: &mut JitContext, r1: u32, r2: u32) { codegen::gen_get_reg16(ctx, r2); let tmp = ctx.builder.set_new_local(); codegen::gen_get_reg16(ctx, r1); codegen::gen_set_reg16(ctx, r2); ctx.builder.get_local(&tmp); codegen::gen_set_reg16(ctx, r1); ctx.builder.free_local(tmp); } pub fn instr32_87_reg_jit(ctx: &mut JitContext, r1: u32, r2: u32) { codegen::gen_get_reg32(ctx, r2); let tmp = ctx.builder.set_new_local(); codegen::gen_get_reg32(ctx, r1); codegen::gen_set_reg32(ctx, r2); ctx.builder.get_local(&tmp); codegen::gen_set_reg32(ctx, r1); ctx.builder.free_local(tmp); } pub fn instr_88_mem_jit(ctx: &mut JitContext, modrm_byte: ModrmByte, r: u32) { codegen::gen_modrm_resolve_with_local(ctx, modrm_byte, &|ctx, addr| { codegen::gen_get_reg8(ctx, r); let value_local = ctx.builder.set_new_local(); codegen::gen_safe_write8(ctx, &addr, &value_local); ctx.builder.free_local(value_local); }); } pub fn instr_88_reg_jit(ctx: &mut JitContext, r1: u32, r2: u32) { codegen::gen_set_reg8_r(ctx, r1, r2); } pub fn instr16_89_mem_jit(ctx: &mut JitContext, modrm_byte: ModrmByte, r: u32) { codegen::gen_modrm_resolve_with_local(ctx, modrm_byte, &|ctx, addr| { codegen::gen_safe_write16(ctx, addr, &ctx.reg(r)); }); } pub fn instr16_89_reg_jit(ctx: &mut JitContext, r1: u32, r2: u32) { codegen::gen_set_reg16_r(ctx, r1, r2); } pub fn instr32_89_mem_jit(ctx: &mut JitContext, modrm_byte: ModrmByte, r: u32) { codegen::gen_modrm_resolve_with_local(ctx, modrm_byte, &|ctx, addr| { codegen::gen_safe_write32(ctx, &addr, &ctx.reg(r)); }); } pub fn instr32_89_reg_jit(ctx: &mut JitContext, r1: u32, r2: u32) { codegen::gen_set_reg32_r(ctx, r1, r2); } pub fn instr_8A_mem_jit(ctx: &mut JitContext, modrm_byte: ModrmByte, r: u32) { // Pseudo: reg8[r] = safe_read8(modrm_resolve(modrm_byte)); codegen::gen_modrm_resolve_safe_read8(ctx, modrm_byte); codegen::gen_set_reg8_unmasked(ctx, r); } pub fn instr_8A_reg_jit(ctx: &mut JitContext, r1: u32, r2: u32) { codegen::gen_set_reg8_r(ctx, r2, r1); } pub fn instr16_8B_mem_jit(ctx: &mut JitContext, modrm_byte: ModrmByte, r: u32) { codegen::gen_modrm_resolve_safe_read16(ctx, modrm_byte); codegen::gen_set_reg16_unmasked(ctx, r); } pub fn instr16_8B_reg_jit(ctx: &mut JitContext, r1: u32, r2: u32) { codegen::gen_set_reg16_r(ctx, r2, r1); } pub fn instr32_8B_mem_jit(ctx: &mut JitContext, modrm_byte: ModrmByte, r: u32) { codegen::gen_modrm_resolve_safe_read32(ctx, modrm_byte); codegen::gen_set_reg32(ctx, r); } pub fn instr32_8B_reg_jit(ctx: &mut JitContext, r1: u32, r2: u32) { codegen::gen_set_reg32_r(ctx, r2, r1); } pub fn instr16_8C_mem_jit(ctx: &mut JitContext, modrm_byte: ModrmByte, r: u32) { codegen::gen_modrm_resolve(ctx, modrm_byte); let address_local = ctx.builder.set_new_local(); if r >= 6 { codegen::gen_trigger_ud(ctx); } else { codegen::gen_get_sreg(ctx, r); let value_local = ctx.builder.set_new_local(); codegen::gen_safe_write16(ctx, &address_local, &value_local); ctx.builder.free_local(value_local); } ctx.builder.free_local(address_local); } pub fn instr32_8C_mem_jit(ctx: &mut JitContext, modrm_byte: ModrmByte, r: u32) { codegen::gen_modrm_resolve(ctx, modrm_byte); let address_local = ctx.builder.set_new_local(); if r >= 6 { codegen::gen_trigger_ud(ctx); } else { codegen::gen_get_sreg(ctx, r); let value_local = ctx.builder.set_new_local(); codegen::gen_safe_write16(ctx, &address_local, &value_local); ctx.builder.free_local(value_local); } ctx.builder.free_local(address_local); } pub fn instr16_8C_reg_jit(ctx: &mut JitContext, r1: u32, r2: u32) { if r2 >= 6 { codegen::gen_trigger_ud(ctx); } else { codegen::gen_get_sreg(ctx, r2); codegen::gen_set_reg16(ctx, r1); } } pub fn instr32_8C_reg_jit(ctx: &mut JitContext, r1: u32, r2: u32) { if r2 >= 6 { codegen::gen_trigger_ud(ctx); } else { codegen::gen_get_sreg(ctx, r2); codegen::gen_set_reg32(ctx, r1); } } pub fn instr16_8D_mem_jit(ctx: &mut JitContext, modrm_byte: ModrmByte, reg: u32) { ctx.cpu.prefixes |= SEG_PREFIX_ZERO; codegen::gen_modrm_resolve(ctx, modrm_byte); codegen::gen_set_reg16(ctx, reg); } pub fn instr32_8D_mem_jit(ctx: &mut JitContext, modrm_byte: ModrmByte, reg: u32) { if !modrm_byte.is_nop(reg) { ctx.cpu.prefixes |= SEG_PREFIX_ZERO; codegen::gen_modrm_resolve(ctx, modrm_byte); codegen::gen_set_reg32(ctx, reg); } } pub fn instr16_8D_reg_jit(ctx: &mut JitContext, _r1: u32, _r2: u32) { codegen::gen_trigger_ud(ctx); } pub fn instr32_8D_reg_jit(ctx: &mut JitContext, _r1: u32, _r2: u32) { codegen::gen_trigger_ud(ctx); } pub fn instr16_8F_0_mem_jit(ctx: &mut JitContext, modrm_byte: ModrmByte) { // before gen_modrm_resolve, update esp to the new value codegen::gen_adjust_stack_reg(ctx, 2); codegen::gen_modrm_resolve(ctx, modrm_byte); let address_local = ctx.builder.set_new_local(); // pop takes care of updating esp, so undo the previous change codegen::gen_adjust_stack_reg(ctx, (-2i32) as u32); codegen::gen_pop16(ctx); let value_local = ctx.builder.set_new_local(); // undo the esp change of pop, as safe_write16 can fail codegen::gen_adjust_stack_reg(ctx, (-2i32) as u32); codegen::gen_safe_write16(ctx, &address_local, &value_local); ctx.builder.free_local(address_local); ctx.builder.free_local(value_local); // finally, actually update esp codegen::gen_adjust_stack_reg(ctx, 2); } pub fn instr16_8F_0_reg_jit(ctx: &mut JitContext, r: u32) { pop16_reg_jit(ctx, r); } pub fn instr32_8F_0_mem_jit(ctx: &mut JitContext, modrm_byte: ModrmByte) { codegen::gen_adjust_stack_reg(ctx, 4); codegen::gen_modrm_resolve(ctx, modrm_byte); let address_local = ctx.builder.set_new_local(); codegen::gen_adjust_stack_reg(ctx, (-4i32) as u32); codegen::gen_pop32s(ctx); let value_local = ctx.builder.set_new_local(); codegen::gen_adjust_stack_reg(ctx, (-4i32) as u32); codegen::gen_safe_write32(ctx, &address_local, &value_local); ctx.builder.free_local(address_local); ctx.builder.free_local(value_local); codegen::gen_adjust_stack_reg(ctx, 4); } pub fn instr32_8F_0_reg_jit(ctx: &mut JitContext, r: u32) { pop32_reg_jit(ctx, r); } define_instruction_read_write_mem16!( "rol16", instr16_C1_0_mem_jit, instr16_C1_0_reg_jit, imm8_5bits ); define_instruction_read_write_mem32!( gen_rol32, instr32_C1_0_mem_jit, instr32_C1_0_reg_jit, imm8_5bits ); define_instruction_read_write_mem16!( "ror16", instr16_C1_1_mem_jit, instr16_C1_1_reg_jit, imm8_5bits ); define_instruction_read_write_mem32!( gen_ror32, instr32_C1_1_mem_jit, instr32_C1_1_reg_jit, imm8_5bits ); define_instruction_read_write_mem16!( "rcl16", instr16_C1_2_mem_jit, instr16_C1_2_reg_jit, imm8_5bits ); define_instruction_read_write_mem32!( gen_rcl32, instr32_C1_2_mem_jit, instr32_C1_2_reg_jit, imm8_5bits ); define_instruction_read_write_mem16!( "rcr16", instr16_C1_3_mem_jit, instr16_C1_3_reg_jit, imm8_5bits ); define_instruction_read_write_mem32!( gen_rcr32, instr32_C1_3_mem_jit, instr32_C1_3_reg_jit, imm8_5bits ); define_instruction_read_write_mem16!( "shl16", instr16_C1_4_mem_jit, instr16_C1_4_reg_jit, imm8_5bits ); define_instruction_read_write_mem32!( gen_shl32, instr32_C1_4_mem_jit, instr32_C1_4_reg_jit, imm8_5bits ); define_instruction_read_write_mem16!( "shr16", instr16_C1_5_mem_jit, instr16_C1_5_reg_jit, imm8_5bits ); define_instruction_read_write_mem32!( gen_shr32, instr32_C1_5_mem_jit, pub fn instr_D9_4_mem_jit(ctx: &mut JitContext, modrm_byte: u8) {
{'commit': 'diff --git a/src/rust/cpu2/fpu.rs b/src/rust/cpu2/fpu.rs\nindex 01e283b8..70c0d58a 100644\n--- a/src/rust/cpu2/fpu.rs\n+++ b/src/rust/cpu2/fpu.rs\n@@ -435,8 +435,15 @@ pub unsafe fn fpu_fldcw(addr: i32) {\n pub unsafe fn fpu_fldenv(addr: i32) {\n     if is_osize_32() {\n         // TODO: Add readable_or_pagefault\n-        return_on_pagefault!(translate_address_read(addr));\n-        return_on_pagefault!(translate_address_read(addr + 28));\n+        if let Err(()) = translate_address_read(addr) {\n+            *page_fault = true;\n+            return;\n+        }\n+        if let Err(()) = translate_address_read(addr + 28) {\n+            *page_fault = true;\n+            return;\n+        }\n+        *page_fault = false;\n         *fpu_control_word = safe_read16(addr).unwrap();\n         fpu_set_status_word(safe_read16(addr + 4).unwrap());\n         fpu_set_tag_word(safe_read16(addr + 8).unwrap());\n@@ -478,7 +485,17 @@ pub unsafe fn fpu_fldm32(addr: i32) { fpu_push(return_on_pagefault!(safe_read32s\n #[no_mangle]\n pub unsafe fn fpu_fldm64(addr: i32) { fpu_push(return_on_pagefault!(fpu_load_m64(addr))); }\n #[no_mangle]\n-pub unsafe fn fpu_fldm80(addr: i32) { fpu_push(return_on_pagefault!(fpu_load_m80(addr))); }\n+pub unsafe fn fpu_fldm80(addr: i32) {\n+    match fpu_load_m80(addr) {\n+        Ok(x) => {\n+            *page_fault = false;\n+            fpu_push(x)\n+        },\n+        Err(()) => {\n+            *page_fault = true;\n+        },\n+    }\n+}\n #[no_mangle]\n pub unsafe fn fpu_fmul(target_index: i32, val: f64) {\n     let st0: f64 = fpu_get_st0();\n@@ -614,7 +631,13 @@ pub unsafe fn fpu_f64_to_f80(f: f64) -> (u64, u16) {\n #[no_mangle]\n pub unsafe fn fpu_fstenv(addr: i32) {\n     if is_osize_32() {\n-        return_on_pagefault!(writable_or_pagefault(addr, 26));\n+        match writable_or_pagefault(addr, 26) {\n+            Ok(()) => *page_fault = false,\n+            Err(()) => {\n+                *page_fault = true;\n+                return;\n+            },\n+        }\n         safe_write16(addr, *fpu_control_word).unwrap();\n         safe_write16(addr + 4, fpu_load_status_word()).unwrap();\n         safe_write16(addr + 8, fpu_load_tag_word()).unwrap();\ndiff --git a/src/rust/jit_instructions.rs b/src/rust/jit_instructions.rs\nindex 7df4b962..989a77c0 100644\n--- a/src/rust/jit_instructions.rs\n+++ b/src/rust/jit_instructions.rs\n@@ -3000,12 +3000,25 @@ pub fn instr_D9_3_reg_jit(ctx: &mut JitContext, r: u32) {\n \n pub fn instr_D9_4_mem_jit(ctx: &mut JitContext, modrm_byte: u8) {\n     codegen::gen_modrm_resolve(ctx, modrm_byte);\n-    // XXX: generated because fldenv might page-fault, but doesn\'t generate a proper block boundary\n+\n+    codegen::gen_set_previous_eip_offset_from_eip_with_low_bits(\n+        ctx.builder,\n+        ctx.start_of_current_instruction as i32 & 0xFFF,\n+    );\n+\n     codegen::gen_move_registers_from_locals_to_memory(ctx);\n     codegen::gen_call_fn1(ctx.builder, "fpu_fldenv");\n+    codegen::gen_move_registers_from_memory_to_locals(ctx);\n+\n+    ctx.builder\n+        .instruction_body\n+        .load_u8(global_pointers::PAGE_FAULT);\n+    ctx.builder.instruction_body.if_void();\n     codegen::gen_debug_track_jit_exit(ctx.builder, ctx.start_of_current_instruction);\n+    codegen::gen_move_registers_from_locals_to_memory(ctx);\n     codegen::gen_clear_prefixes(ctx);\n     ctx.builder.instruction_body.return_();\n+    ctx.builder.instruction_body.block_end();\n }\n pub fn instr_D9_4_reg_jit(ctx: &mut JitContext, r: u32) {\n     ctx.builder.instruction_body.const_i32(r as i32);\n@@ -3027,12 +3040,25 @@ pub fn instr_D9_5_reg_jit(ctx: &mut JitContext, r: u32) {\n \n pub fn instr_D9_6_mem_jit(ctx: &mut JitContext, modrm_byte: u8) {\n     codegen::gen_modrm_resolve(ctx, modrm_byte);\n-    // XXX: generated because fpu_fstenv might page-fault, but doesn\'t generate a proper block boundary\n+\n+    codegen::gen_set_previous_eip_offset_from_eip_with_low_bits(\n+        ctx.builder,\n+        ctx.start_of_current_instruction as i32 & 0xFFF,\n+    );\n+\n     codegen::gen_move_registers_from_locals_to_memory(ctx);\n     codegen::gen_call_fn1(ctx.builder, "fpu_fstenv");\n+    codegen::gen_move_registers_from_memory_to_locals(ctx);\n+\n+    ctx.builder\n+        .instruction_body\n+        .load_u8(global_pointers::PAGE_FAULT);\n+    ctx.builder.instruction_body.if_void();\n     codegen::gen_debug_track_jit_exit(ctx.builder, ctx.start_of_current_instruction);\n+    codegen::gen_move_registers_from_locals_to_memory(ctx);\n     codegen::gen_clear_prefixes(ctx);\n     ctx.builder.instruction_body.return_();\n+    ctx.builder.instruction_body.block_end();\n }\n pub fn instr_D9_6_reg_jit(ctx: &mut JitContext, r: u32) {\n     codegen::gen_fn1_const(ctx.builder, "instr_D9_6_reg", r);\n@@ -3108,12 +3134,25 @@ pub fn instr_DB_3_reg_jit(ctx: &mut JitContext, r: u32) {\n \n pub fn instr_DB_5_mem_jit(ctx: &mut JitContext, modrm_byte: u8) {\n     codegen::gen_modrm_resolve(ctx, modrm_byte);\n-    // XXX: generated because fpu_fldm80 might page-fault, but doesn\'t generate a proper block boundary\n+\n+    codegen::gen_set_previous_eip_offset_from_eip_with_low_bits(\n+        ctx.builder,\n+        ctx.start_of_current_instruction as i32 & 0xFFF,\n+    );\n+\n     codegen::gen_move_registers_from_locals_to_memory(ctx);\n     codegen::gen_call_fn1(ctx.builder, "fpu_fldm80");\n+    codegen::gen_move_registers_from_memory_to_locals(ctx);\n+\n+    ctx.builder\n+        .instruction_body\n+        .load_u8(global_pointers::PAGE_FAULT);\n+    ctx.builder.instruction_body.if_void();\n     codegen::gen_debug_track_jit_exit(ctx.builder, ctx.start_of_current_instruction);\n+    codegen::gen_move_registers_from_locals_to_memory(ctx);\n     codegen::gen_clear_prefixes(ctx);\n     ctx.builder.instruction_body.return_();\n+    ctx.builder.instruction_body.block_end();\n }\n pub fn instr_DB_5_reg_jit(ctx: &mut JitContext, r: u32) {\n     ctx.builder.instruction_body.const_i32(r as i32);\n', 'commit_subject': 'Fix fldm80/fstenv/fldenv: These instructions were generating and unconditional exit from jitted code but not updating eip. Changed to use the fallback mechanism for handling pagefaults', 'repo_name': 'copy/v86', 'committer': {'name': 'Fabian', 'email': 'f84e2e2dadd87384fb55f25886926b777e8378f1@copy.sh', 'time_sec': '1609463669', 'tz_offset': '-360', 'date': {'seconds': '1609463669'}}, 'commit_tree': '006306d20eab2b43a2b159d13e3a658d36581cb2', 'commit_message': 'Fix fldm80/fstenv/fldenv: These instructions were generating and unconditional exit from jitted code but not updating eip. Changed to use the fallback mechanism for handling pagefaults\n', 'language_name': 'JavaScript', 'license': 'bsd-2-clause', 'hunks': '@@ -3000,12 +3000,25 @@ pub fn instr_D9_3_reg_jit(ctx: &mut JitContext, r: u32) {\n \n pub fn instr_D9_4_mem_jit(ctx: &mut JitContext, modrm_byte: u8) {\n     codegen::gen_modrm_resolve(ctx, modrm_byte);\n-    // XXX: generated because fldenv might page-fault, but doesn\'t generate a proper block boundary\n+\n+    codegen::gen_set_previous_eip_offset_from_eip_with_low_bits(\n+        ctx.builder,\n+        ctx.start_of_current_instruction as i32 & 0xFFF,\n+    );\n+\n     codegen::gen_move_registers_from_locals_to_memory(ctx);\n     codegen::gen_call_fn1(ctx.builder, "fpu_fldenv");\n+    codegen::gen_move_registers_from_memory_to_locals(ctx);\n+\n+    ctx.builder\n+        .instruction_body\n+        .load_u8(global_pointers::PAGE_FAULT);\n+    ctx.builder.instruction_body.if_void();\n     codegen::gen_debug_track_jit_exit(ctx.builder, ctx.start_of_current_instruction);\n+    codegen::gen_move_registers_from_locals_to_memory(ctx);\n     codegen::gen_clear_prefixes(ctx);\n     ctx.builder.instruction_body.return_();\n+    ctx.builder.instruction_body.block_end();\n }\n pub fn instr_D9_4_reg_jit(ctx: &mut JitContext, r: u32) {\n     ctx.builder.instruction_body.const_i32(r as i32);\n@@ -3027,12 +3040,25 @@ pub fn instr_D9_5_reg_jit(ctx: &mut JitContext, r: u32) {\n \n pub fn instr_D9_6_mem_jit(ctx: &mut JitContext, modrm_byte: u8) {\n     codegen::gen_modrm_resolve(ctx, modrm_byte);\n-    // XXX: generated because fpu_fstenv might page-fault, but doesn\'t generate a proper block boundary\n+\n+    codegen::gen_set_previous_eip_offset_from_eip_with_low_bits(\n+        ctx.builder,\n+        ctx.start_of_current_instruction as i32 & 0xFFF,\n+    );\n+\n     codegen::gen_move_registers_from_locals_to_memory(ctx);\n     codegen::gen_call_fn1(ctx.builder, "fpu_fstenv");\n+    codegen::gen_move_registers_from_memory_to_locals(ctx);\n+\n+    ctx.builder\n+        .instruction_body\n+        .load_u8(global_pointers::PAGE_FAULT);\n+    ctx.builder.instruction_body.if_void();\n     codegen::gen_debug_track_jit_exit(ctx.builder, ctx.start_of_current_instruction);\n+    codegen::gen_move_registers_from_locals_to_memory(ctx);\n     codegen::gen_clear_prefixes(ctx);\n     ctx.builder.instruction_body.return_();\n+    ctx.builder.instruction_body.block_end();\n }\n pub fn instr_D9_6_reg_jit(ctx: &mut JitContext, r: u32) {\n     codegen::gen_fn1_const(ctx.builder, "instr_D9_6_reg", r);\n@@ -3108,12 +3134,25 @@ pub fn instr_DB_3_reg_jit(ctx: &mut JitContext, r: u32) {\n \n pub fn instr_DB_5_mem_jit(ctx: &mut JitContext, modrm_byte: u8) {\n     codegen::gen_modrm_resolve(ctx, modrm_byte);\n-    // XXX: generated because fpu_fldm80 might page-fault, but doesn\'t generate a proper block boundary\n+\n+    codegen::gen_set_previous_eip_offset_from_eip_with_low_bits(\n+        ctx.builder,\n+        ctx.start_of_current_instruction as i32 & 0xFFF,\n+    );\n+\n     codegen::gen_move_registers_from_locals_to_memory(ctx);\n     codegen::gen_call_fn1(ctx.builder, "fpu_fldm80");\n+    codegen::gen_move_registers_from_memory_to_locals(ctx);\n+\n+    ctx.builder\n+        .instruction_body\n+        .load_u8(global_pointers::PAGE_FAULT);\n+    ctx.builder.instruction_body.if_void();\n     codegen::gen_debug_track_jit_exit(ctx.builder, ctx.start_of_current_instruction);\n+    codegen::gen_move_registers_from_locals_to_memory(ctx);\n     codegen::gen_clear_prefixes(ctx);\n     ctx.builder.instruction_body.return_();\n+    ctx.builder.instruction_body.block_end();\n }\n pub fn instr_DB_5_reg_jit(ctx: &mut JitContext, r: u32) {\n     ctx.builder.instruction_body.const_i32(r as i32);\n', 'addition_count': 42, 'deletion_count': 3, 'src_file': 'a/src/rust/jit_instructions.rs', 'tgt_file': 'b/src/rust/jit_instructions.rs', 'file_extension': '.rs', 'before_file': '#![allow(non_snake_case)]\n\nuse codegen;\nuse codegen::BitSize;\nuse cpu::cpu::{\n    FLAGS_ALL, FLAGS_DEFAULT, FLAGS_MASK, FLAG_ADJUST, FLAG_CARRY, FLAG_DIRECTION, FLAG_INTERRUPT,\n    FLAG_IOPL, FLAG_OVERFLOW, FLAG_SUB, FLAG_VM, FLAG_ZERO, OPSIZE_8, OPSIZE_16, OPSIZE_32,\n};\nuse cpu::global_pointers;\nuse jit::{Instruction, InstructionOperand, JitContext};\nuse modrm::{jit_add_seg_offset, jit_add_seg_offset_no_override, ModrmByte};\nuse prefix::SEG_PREFIX_ZERO;\nuse prefix::{PREFIX_66, PREFIX_67, PREFIX_F2, PREFIX_F3};\nuse regs;\nuse regs::{AX, BP, BX, CX, DI, DX, SI, SP};\nuse regs::{CS, DS, ES, FS, GS, SS};\nuse regs::{EAX, EBP, EBX, ECX, EDI, EDX, ESI, ESP};\nuse wasmgen::wasm_builder::{WasmBuilder, WasmLocal};\n\nenum LocalOrImmediate<\'a> {\n    WasmLocal(&\'a WasmLocal),\n    Immediate(i32),\n}\n\nimpl<\'a> LocalOrImmediate<\'a> {\n    pub fn gen_get(&self, builder: &mut WasmBuilder) {\n        match self {\n            LocalOrImmediate::WasmLocal(l) => builder.get_local(l),\n            LocalOrImmediate::Immediate(i) => builder.const_i32(*i),\n        }\n    }\n    pub fn gen_get_mask255(&self, builder: &mut WasmBuilder) {\n        match self {\n            LocalOrImmediate::WasmLocal(l) => {\n                builder.get_local(l);\n                builder.const_i32(0xFF);\n                builder.and_i32()\n            },\n            LocalOrImmediate::Immediate(i) => builder.const_i32(*i & 0xFF),\n        }\n    }\n    pub fn eq_local(&self, other_local: &WasmLocal) -> bool {\n        match self {\n            &LocalOrImmediate::WasmLocal(local) => local == other_local,\n            LocalOrImmediate::Immediate(_) => false,\n        }\n    }\n    pub fn is_zero(&self) -> bool {\n        match self {\n            LocalOrImmediate::Immediate(0) => true,\n            _ => false,\n        }\n    }\n}\n\npub fn jit_instruction(ctx: &mut JitContext, instr_flags: &mut u32) {\n    ctx.cpu.prefixes = 0;\n    ctx.start_of_current_instruction = ctx.cpu.eip;\n    ::gen::jit::jit(\n        ctx.cpu.read_imm8() as u32 | (ctx.cpu.osize_32() as u32) << 8,\n        ctx,\n        instr_flags,\n    );\n}\n\npub fn jit_handle_prefix(ctx: &mut JitContext, instr_flags: &mut u32) {\n    ::gen::jit::jit(\n        ctx.cpu.read_imm8() as u32 | (ctx.cpu.osize_32() as u32) << 8,\n        ctx,\n        instr_flags,\n    );\n}\n\npub fn jit_handle_segment_prefix(segment: u32, ctx: &mut JitContext, instr_flags: &mut u32) {\n    dbg_assert!(segment <= 5);\n    ctx.cpu.prefixes |= segment + 1;\n    jit_handle_prefix(ctx, instr_flags)\n}\n\npub fn instr16_0F_jit(ctx: &mut JitContext, instr_flags: &mut u32) {\n    ::gen::jit0f::jit(ctx.cpu.read_imm8() as u32, ctx, instr_flags)\n}\npub fn instr32_0F_jit(ctx: &mut JitContext, instr_flags: &mut u32) {\n    ::gen::jit0f::jit(ctx.cpu.read_imm8() as u32 | 0x100, ctx, instr_flags)\n}\npub fn instr_26_jit(ctx: &mut JitContext, instr_flags: &mut u32) {\n    jit_handle_segment_prefix(ES, ctx, instr_flags)\n}\npub fn instr_2E_jit(ctx: &mut JitContext, instr_flags: &mut u32) {\n    jit_handle_segment_prefix(CS, ctx, instr_flags)\n}\npub fn instr_36_jit(ctx: &mut JitContext, instr_flags: &mut u32) {\n    jit_handle_segment_prefix(SS, ctx, instr_flags)\n}\npub fn instr_3E_jit(ctx: &mut JitContext, instr_flags: &mut u32) {\n    jit_handle_segment_prefix(DS, ctx, instr_flags)\n}\n\npub fn instr_64_jit(ctx: &mut JitContext, instr_flags: &mut u32) {\n    jit_handle_segment_prefix(FS, ctx, instr_flags)\n}\npub fn instr_65_jit(ctx: &mut JitContext, instr_flags: &mut u32) {\n    jit_handle_segment_prefix(GS, ctx, instr_flags)\n}\n\npub fn instr_66_jit(ctx: &mut JitContext, instr_flags: &mut u32) {\n    ctx.cpu.prefixes |= PREFIX_66;\n    jit_handle_prefix(ctx, instr_flags)\n}\npub fn instr_67_jit(ctx: &mut JitContext, instr_flags: &mut u32) {\n    ctx.cpu.prefixes |= PREFIX_67;\n    jit_handle_prefix(ctx, instr_flags)\n}\npub fn instr_F0_jit(ctx: &mut JitContext, instr_flags: &mut u32) {\n    // lock: Ignore\n    jit_handle_prefix(ctx, instr_flags)\n}\npub fn instr_F2_jit(ctx: &mut JitContext, instr_flags: &mut u32) {\n    ctx.cpu.prefixes |= PREFIX_F2;\n    jit_handle_prefix(ctx, instr_flags)\n}\npub fn instr_F3_jit(ctx: &mut JitContext, instr_flags: &mut u32) {\n    ctx.cpu.prefixes |= PREFIX_F3;\n    jit_handle_prefix(ctx, instr_flags)\n}\n\nfn sse_read_f32_xmm_mem(ctx: &mut JitContext, name: &str, modrm_byte: ModrmByte, r: u32) {\n    codegen::gen_modrm_resolve_safe_read32(ctx, modrm_byte);\n    ctx.builder.reinterpret_i32_as_f32();\n    ctx.builder.const_i32(r as i32);\n    ctx.builder.call_fn2_f32_i32(name);\n}\nfn sse_read_f32_xmm_xmm(ctx: &mut JitContext, name: &str, r1: u32, r2: u32) {\n    ctx.builder\n        .const_i32(global_pointers::get_reg_xmm_offset(r1) as i32);\n    ctx.builder.load_aligned_f32(0);\n    ctx.builder.const_i32(r2 as i32);\n    ctx.builder.call_fn2_f32_i32(name);\n}\n\nfn sse_read64_xmm_mem(ctx: &mut JitContext, name: &str, modrm_byte: ModrmByte, r: u32) {\n    codegen::gen_modrm_resolve_safe_read64(ctx, modrm_byte);\n    ctx.builder.const_i32(r as i32);\n    ctx.builder.call_fn2_i64_i32(name);\n}\nfn sse_read64_xmm_xmm(ctx: &mut JitContext, name: &str, r1: u32, r2: u32) {\n    ctx.builder\n        .const_i32(global_pointers::get_reg_xmm_offset(r1) as i32);\n    ctx.builder.load_aligned_i64(0);\n    ctx.builder.const_i32(r2 as i32);\n    ctx.builder.call_fn2_i64_i32(name);\n}\n\nfn sse_read128_xmm_mem(ctx: &mut JitContext, name: &str, modrm_byte: ModrmByte, r: u32) {\n    let dest = global_pointers::sse_scratch_register as u32;\n    codegen::gen_modrm_resolve_safe_read128(ctx, modrm_byte, dest);\n    ctx.builder.const_i32(dest as i32);\n    ctx.builder.const_i32(r as i32);\n    ctx.builder.call_fn2(name);\n}\nfn sse_read128_xmm_mem_imm(\n    ctx: &mut JitContext,\n    name: &str,\n    modrm_byte: ModrmByte,\n    r: u32,\n    imm: u32,\n) {\n    let dest = global_pointers::sse_scratch_register as u32;\n    codegen::gen_modrm_resolve_safe_read128(ctx, modrm_byte, dest);\n    ctx.builder.const_i32(dest as i32);\n    ctx.builder.const_i32(r as i32);\n    ctx.builder.const_i32(imm as i32);\n    ctx.builder.call_fn3(name);\n}\nfn sse_read128_xmm_xmm(ctx: &mut JitContext, name: &str, r1: u32, r2: u32) {\n    // Make a copy to avoid aliasing problems: Called function expects a reg128, which must not\n    // alias with memory\n    codegen::gen_read_reg_xmm128_into_scratch(ctx, r1);\n    let dest = global_pointers::sse_scratch_register;\n    ctx.builder.const_i32(dest as i32);\n    ctx.builder.const_i32(r2 as i32);\n    ctx.builder.call_fn2(name);\n}\nfn sse_read128_xmm_xmm_imm(ctx: &mut JitContext, name: &str, r1: u32, r2: u32, imm: u32) {\n    // Make a copy to avoid aliasing problems: Called function expects a reg128, which must not\n    // alias with memory\n    codegen::gen_read_reg_xmm128_into_scratch(ctx, r1);\n    let dest = global_pointers::sse_scratch_register;\n    ctx.builder.const_i32(dest as i32);\n    ctx.builder.const_i32(r2 as i32);\n    ctx.builder.const_i32(imm as i32);\n    ctx.builder.call_fn3(name);\n}\nfn sse_mov_xmm_xmm(ctx: &mut JitContext, r1: u32, r2: u32) {\n    ctx.builder\n        .const_i32(global_pointers::get_reg_xmm_offset(r2) as i32);\n    ctx.builder\n        .const_i32(global_pointers::get_reg_xmm_offset(r1) as i32);\n    ctx.builder.load_aligned_i64(0);\n    ctx.builder.store_aligned_i64(0);\n\n    ctx.builder\n        .const_i32(global_pointers::get_reg_xmm_offset(r2) as i32 + 8);\n    ctx.builder\n        .const_i32(global_pointers::get_reg_xmm_offset(r1) as i32 + 8);\n    ctx.builder.load_aligned_i64(0);\n    ctx.builder.store_aligned_i64(0);\n}\n\nfn mmx_read64_mm_mem32(ctx: &mut JitContext, name: &str, modrm_byte: ModrmByte, r: u32) {\n    codegen::gen_modrm_resolve_safe_read32(ctx, modrm_byte);\n    ctx.builder.const_i32(r as i32);\n    ctx.builder.call_fn2(name)\n}\nfn mmx_read64_mm_mm32(ctx: &mut JitContext, name: &str, r1: u32, r2: u32) {\n    ctx.builder\n        .const_i32(global_pointers::get_reg_mmx_offset(r1) as i32);\n    ctx.builder.load_aligned_i32(0);\n    ctx.builder.const_i32(r2 as i32);\n    ctx.builder.call_fn2(name);\n}\nfn mmx_read64_mm_mem(ctx: &mut JitContext, name: &str, modrm_byte: ModrmByte, r: u32) {\n    codegen::gen_modrm_resolve_safe_read64(ctx, modrm_byte);\n    ctx.builder.const_i32(r as i32);\n    ctx.builder.call_fn2_i64_i32(name)\n}\nfn mmx_read64_mm_mm(ctx: &mut JitContext, name: &str, r1: u32, r2: u32) {\n    ctx.builder\n        .const_i32(global_pointers::get_reg_mmx_offset(r1) as i32);\n    ctx.builder.load_aligned_i64(0);\n    ctx.builder.const_i32(r2 as i32);\n    ctx.builder.call_fn2_i64_i32(name);\n}\n\nfn push16_reg_jit(ctx: &mut JitContext, r: u32) {\n    codegen::gen_get_reg16(ctx, r);\n    let value_local = ctx.builder.set_new_local();\n    codegen::gen_push16(ctx, &value_local);\n    ctx.builder.free_local(value_local);\n}\nfn push32_reg_jit(ctx: &mut JitContext, r: u32) {\n    let reg = ctx.reg(r);\n    codegen::gen_push32(ctx, &reg);\n}\nfn push16_imm_jit(ctx: &mut JitContext, imm: u32) {\n    ctx.builder.const_i32(imm as i32);\n    let value_local = ctx.builder.set_new_local();\n    codegen::gen_push16(ctx, &value_local);\n    ctx.builder.free_local(value_local);\n}\nfn push32_imm_jit(ctx: &mut JitContext, imm: u32) {\n    ctx.builder.const_i32(imm as i32);\n    let value_local = ctx.builder.set_new_local();\n    codegen::gen_push32(ctx, &value_local);\n    ctx.builder.free_local(value_local);\n}\nfn push16_mem_jit(ctx: &mut JitContext, modrm_byte: ModrmByte) {\n    codegen::gen_modrm_resolve_safe_read16(ctx, modrm_byte);\n    let value_local = ctx.builder.set_new_local();\n    codegen::gen_push16(ctx, &value_local);\n    ctx.builder.free_local(value_local);\n}\nfn push32_mem_jit(ctx: &mut JitContext, modrm_byte: ModrmByte) {\n    codegen::gen_modrm_resolve_safe_read32(ctx, modrm_byte);\n    let value_local = ctx.builder.set_new_local();\n    codegen::gen_push32(ctx, &value_local);\n    ctx.builder.free_local(value_local);\n}\n\nfn pop16_reg_jit(ctx: &mut JitContext, reg: u32) {\n    codegen::gen_pop16(ctx);\n    codegen::gen_set_reg16_unmasked(ctx, reg);\n}\n\nfn pop32_reg_jit(ctx: &mut JitContext, reg: u32) {\n    codegen::gen_pop32s(ctx);\n    codegen::gen_set_reg32(ctx, reg);\n}\n\nfn group_arith_al_imm8(\n    ctx: &mut JitContext,\n    op: &dyn Fn(&mut JitContext, &WasmLocal, &LocalOrImmediate),\n    imm8: u32,\n) {\n    op(\n        ctx,\n        &ctx.reg(regs::EAX),\n        &LocalOrImmediate::Immediate(imm8 as i32),\n    );\n    codegen::gen_set_reg8_unmasked(ctx, regs::EAX);\n}\n\nfn group_arith_ax_imm16(ctx: &mut JitContext, op: &str, imm16: u32) {\n    codegen::gen_get_reg16(ctx, regs::AX);\n    ctx.builder.const_i32(imm16 as i32);\n    ctx.builder.call_fn2_ret(op);\n    codegen::gen_set_reg16(ctx, regs::AX);\n}\n\nfn group_arith_eax_imm32(\n    ctx: &mut JitContext,\n    op: &dyn Fn(&mut JitContext, &WasmLocal, &LocalOrImmediate),\n    imm32: u32,\n) {\n    op(\n        ctx,\n        &ctx.reg(regs::EAX),\n        &LocalOrImmediate::Immediate(imm32 as i32),\n    );\n}\n\nmacro_rules! define_instruction_read8(\n    ($fn:expr, $name_mem:ident, $name_reg:ident) => (\n        pub fn $name_mem(ctx: &mut JitContext, modrm_byte: ModrmByte, r: u32) {\n            codegen::gen_modrm_resolve_safe_read8(ctx, modrm_byte);\n            let dest_operand = ctx.builder.set_new_local();\n            let source_operand = codegen::gen_get_reg8_or_alias_to_reg32(ctx, r);\n            $fn(ctx, &dest_operand, &LocalOrImmediate::WasmLocal(&source_operand));\n            ctx.builder.free_local(dest_operand);\n            codegen::gen_free_reg8_or_alias(ctx, r, source_operand);\n        }\n\n        pub fn $name_reg(ctx: &mut JitContext, r1: u32, r2: u32) {\n            let dest_operand = codegen::gen_get_reg8_or_alias_to_reg32(ctx, r1);\n            let source_operand = codegen::gen_get_reg8_or_alias_to_reg32(ctx, r2);\n            $fn(ctx, &dest_operand, &LocalOrImmediate::WasmLocal(&source_operand));\n            codegen::gen_free_reg8_or_alias(ctx, r1, dest_operand);\n            codegen::gen_free_reg8_or_alias(ctx, r2, source_operand);\n        }\n    );\n\n    ($fn:expr, $name_mem:ident, $name_reg:ident, $imm:ident) => (\n        pub fn $name_mem(ctx: &mut JitContext, modrm_byte: ModrmByte, imm: u32) {\n            codegen::gen_modrm_resolve_safe_read8(ctx, modrm_byte);\n            let dest_operand = ctx.builder.set_new_local();\n            let imm = mask_imm!(imm, $imm);\n            $fn(ctx, &dest_operand, &LocalOrImmediate::Immediate(imm as i32));\n            ctx.builder.free_local(dest_operand);\n        }\n\n        pub fn $name_reg(ctx: &mut JitContext, r1: u32, imm: u32) {\n            let imm = mask_imm!(imm, $imm);\n            let dest_operand = codegen::gen_get_reg8_or_alias_to_reg32(ctx, r1);\n            $fn(ctx, &dest_operand, &LocalOrImmediate::Immediate(imm as i32));\n            codegen::gen_free_reg8_or_alias(ctx, r1, dest_operand);\n        }\n    );\n);\n\nmacro_rules! define_instruction_read16(\n    ($fn:expr, $name_mem:ident, $name_reg:ident) => (\n        pub fn $name_mem(ctx: &mut JitContext, modrm_byte: ModrmByte, r: u32) {\n            codegen::gen_modrm_resolve_safe_read16(ctx, modrm_byte);\n            let dest_operand = ctx.builder.set_new_local();\n            $fn(\n                ctx,\n                &dest_operand,\n                &LocalOrImmediate::WasmLocal(&ctx.reg(r)),\n            );\n            ctx.builder.free_local(dest_operand);\n        }\n\n        pub fn $name_reg(ctx: &mut JitContext, r1: u32, r2: u32) {\n            $fn(\n                ctx,\n                &ctx.reg(r1),\n                &LocalOrImmediate::WasmLocal(&ctx.reg(r2))\n            );\n        }\n    );\n\n    ($fn:expr, $name_mem:ident, $name_reg:ident, $imm:ident) => (\n        pub fn $name_mem(ctx: &mut JitContext, modrm_byte: ModrmByte, imm: u32) {\n            codegen::gen_modrm_resolve_safe_read16(ctx, modrm_byte);\n            let dest_operand = ctx.builder.set_new_local();\n            let imm = mask_imm!(imm, $imm);\n            $fn(\n                ctx,\n                &dest_operand,\n                &LocalOrImmediate::Immediate(imm as i32),\n            );\n            ctx.builder.free_local(dest_operand);\n        }\n\n        pub fn $name_reg(ctx: &mut JitContext, r: u32, imm: u32) {\n            let imm = mask_imm!(imm, $imm);\n            $fn(\n                ctx,\n                &ctx.reg(r),\n                &LocalOrImmediate::Immediate(imm as i32),\n            );\n        }\n    );\n);\n\nmacro_rules! define_instruction_read32(\n    ($fn:expr, $name_mem:ident, $name_reg:ident) => (\n        pub fn $name_mem(ctx: &mut JitContext, modrm_byte: ModrmByte, r: u32) {\n            codegen::gen_modrm_resolve_safe_read32(ctx, modrm_byte);\n            let dest_operand = ctx.builder.set_new_local();\n            $fn(\n                ctx,\n                &dest_operand,\n                &LocalOrImmediate::WasmLocal(&ctx.reg(r)),\n            );\n            ctx.builder.free_local(dest_operand);\n        }\n\n        pub fn $name_reg(ctx: &mut JitContext, r1: u32, r2: u32) {\n            $fn(\n                ctx,\n                &ctx.reg(r1),\n                &LocalOrImmediate::WasmLocal(&ctx.reg(r2))\n            );\n        }\n    );\n\n    ($fn:expr, $name_mem:ident, $name_reg:ident, $imm:ident) => (\n        pub fn $name_mem(ctx: &mut JitContext, modrm_byte: ModrmByte, imm: u32) {\n            codegen::gen_modrm_resolve_safe_read32(ctx, modrm_byte);\n            let dest_operand = ctx.builder.set_new_local();\n            let imm = mask_imm!(imm, $imm);\n            $fn(\n                ctx,\n                &dest_operand,\n                &LocalOrImmediate::Immediate(imm as i32),\n            );\n            ctx.builder.free_local(dest_operand);\n        }\n\n        pub fn $name_reg(ctx: &mut JitContext, r: u32, imm: u32) {\n            let imm = mask_imm!(imm, $imm);\n            $fn(\n                ctx,\n                &ctx.reg(r),\n                &LocalOrImmediate::Immediate(imm as i32),\n            );\n        }\n    );\n);\n\nmacro_rules! define_instruction_write_reg8(\n    ($fn:expr, $name_mem:ident, $name_reg:ident) => (\n        pub fn $name_mem(ctx: &mut JitContext, modrm_byte: ModrmByte, r: u32) {\n            codegen::gen_modrm_resolve_safe_read8(ctx, modrm_byte);\n            let source_operand = ctx.builder.set_new_local();\n            let dest_operand = codegen::gen_get_reg8_or_alias_to_reg32(ctx, r);\n            $fn(ctx, &dest_operand, &LocalOrImmediate::WasmLocal(&source_operand));\n            codegen::gen_set_reg8_unmasked(ctx, r);\n            ctx.builder.free_local(source_operand);\n            codegen::gen_free_reg8_or_alias(ctx, r, dest_operand);\n        }\n\n        pub fn $name_reg(ctx: &mut JitContext, r1: u32, r2: u32) {\n            let source_operand = codegen::gen_get_reg8_or_alias_to_reg32(ctx, r1);\n            let dest_operand = codegen::gen_get_reg8_or_alias_to_reg32(ctx, r2);\n            $fn(ctx, &dest_operand, &LocalOrImmediate::WasmLocal(&source_operand));\n            codegen::gen_set_reg8_unmasked(ctx, r2);\n            codegen::gen_free_reg8_or_alias(ctx, r1, source_operand);\n            codegen::gen_free_reg8_or_alias(ctx, r2, dest_operand);\n        }\n    )\n);\n\nmacro_rules! define_instruction_write_reg16(\n    ($fn:expr, $name_mem:ident, $name_reg:ident) => (\n        pub fn $name_mem(ctx: &mut JitContext, modrm_byte: ModrmByte, r: u32) {\n            codegen::gen_get_reg16(ctx, r);\n            codegen::gen_modrm_resolve_safe_read16(ctx, modrm_byte);\n            ctx.builder.call_fn2_ret($fn);\n            codegen::gen_set_reg16(ctx, r);\n        }\n\n        pub fn $name_reg(ctx: &mut JitContext, r1: u32, r2: u32) {\n            codegen::gen_get_reg16(ctx, r2);\n            codegen::gen_get_reg16(ctx, r1);\n            ctx.builder.call_fn2_ret($fn);\n            codegen::gen_set_reg16(ctx, r2);\n        }\n    )\n);\n\nmacro_rules! define_instruction_write_reg32(\n    ($fn:expr, $name_mem:ident, $name_reg:ident) => (\n        pub fn $name_mem(ctx: &mut JitContext, modrm_byte: ModrmByte, r: u32) {\n            codegen::gen_modrm_resolve_safe_read32(ctx, modrm_byte);\n            let source_operand = ctx.builder.set_new_local();\n            $fn(\n                ctx,\n                &ctx.reg(r),\n                &LocalOrImmediate::WasmLocal(&source_operand),\n            );\n            ctx.builder.free_local(source_operand);\n        }\n\n        pub fn $name_reg(ctx: &mut JitContext, r1: u32, r2: u32) {\n            $fn(\n                ctx,\n                &ctx.reg(r2),\n                &LocalOrImmediate::WasmLocal(&ctx.reg(r1)),\n            );\n        }\n    );\n);\n\nmacro_rules! mask_imm(\n    ($imm:expr, imm8_5bits) => { $imm & 31 };\n    ($imm:expr, imm8) => { $imm };\n    ($imm:expr, imm8s) => { $imm };\n    ($imm:expr, imm8s_16bits) => { $imm & 0xFFFF };\n    ($imm:expr, imm16) => { $imm };\n    ($imm:expr, imm32) => { $imm };\n);\n\nmacro_rules! define_instruction_read_write_mem8(\n    ($fn:expr, $name_mem:ident, $name_reg:ident, reg) => (\n        pub fn $name_mem(ctx: &mut JitContext, modrm_byte: ModrmByte, r: u32) {\n            codegen::gen_modrm_resolve_with_local(ctx, modrm_byte, &|ctx, addr| {\n                codegen::gen_safe_read_write(ctx, BitSize::BYTE, &addr, &|ref mut ctx| {\n                    let dest_operand = ctx.builder.set_new_local();\n                    let source_operand = codegen::gen_get_reg8_or_alias_to_reg32(ctx, r);\n                    $fn(ctx, &dest_operand, &LocalOrImmediate::WasmLocal(&source_operand));\n                    codegen::gen_free_reg8_or_alias(ctx, r, source_operand);\n                    ctx.builder.free_local(dest_operand);\n                });\n            });\n        }\n\n        pub fn $name_reg(ctx: &mut JitContext, r1: u32, r2: u32) {\n            let source_operand = codegen::gen_get_reg8_or_alias_to_reg32(ctx, r2);\n            let dest_operand = codegen::gen_get_reg8_or_alias_to_reg32(ctx, r1);\n            $fn(ctx, &dest_operand, &LocalOrImmediate::WasmLocal(&source_operand));\n            codegen::gen_set_reg8_unmasked(ctx, r1);\n            codegen::gen_free_reg8_or_alias(ctx, r2, source_operand);\n            codegen::gen_free_reg8_or_alias(ctx, r1, dest_operand);\n        }\n    );\n\n    ($fn:expr, $name_mem:ident, $name_reg:ident, constant_one) => (\n        pub fn $name_mem(ctx: &mut JitContext, modrm_byte: ModrmByte) {\n            codegen::gen_modrm_resolve_with_local(ctx, modrm_byte, &|ctx, addr| {\n                codegen::gen_safe_read_write(ctx, BitSize::BYTE, &addr, &|ref mut ctx| {\n                    ctx.builder.const_i32(1);\n                    ctx.builder.call_fn2_ret($fn);\n                });\n            });\n        }\n\n        pub fn $name_reg(ctx: &mut JitContext, r1: u32) {\n            codegen::gen_get_reg8(ctx, r1);\n            ctx.builder.const_i32(1);\n            ctx.builder.call_fn2_ret($fn);\n            codegen::gen_set_reg8(ctx, r1);\n        }\n    );\n\n    ($fn:expr, $name_mem:ident, $name_reg:ident, cl) => (\n        pub fn $name_mem(ctx: &mut JitContext, modrm_byte: ModrmByte) {\n            codegen::gen_modrm_resolve_with_local(ctx, modrm_byte, &|ctx, addr| {\n                codegen::gen_safe_read_write(ctx, BitSize::BYTE, &addr, &|ref mut ctx| {\n                    codegen::gen_get_reg8(ctx, regs::CL);\n                    ctx.builder.const_i32(31);\n                    ctx.builder.and_i32();\n                    ctx.builder.call_fn2_ret($fn);\n                });\n            });\n        }\n\n        pub fn $name_reg(ctx: &mut JitContext, r1: u32) {\n            codegen::gen_get_reg8(ctx, r1);\n            codegen::gen_get_reg8(ctx, regs::CL);\n            ctx.builder.const_i32(31);\n            ctx.builder.and_i32();\n            ctx.builder.call_fn2_ret($fn);\n            codegen::gen_set_reg8(ctx, r1);\n        }\n    );\n\n    ($fn:expr, $name_mem:ident, $name_reg:ident, none) => (\n        pub fn $name_mem(ctx: &mut JitContext, modrm_byte: ModrmByte) {\n            codegen::gen_modrm_resolve_with_local(ctx, modrm_byte, &|ctx, addr| {\n                codegen::gen_safe_read_write(ctx, BitSize::BYTE, &addr, &|ref mut ctx| {\n                    ctx.builder.call_fn1_ret($fn);\n                });\n            });\n        }\n\n        pub fn $name_reg(ctx: &mut JitContext, r1: u32) {\n            codegen::gen_get_reg8(ctx, r1);\n            ctx.builder.call_fn1_ret($fn);\n            codegen::gen_set_reg8(ctx, r1);\n        }\n    );\n\n    ($fn:expr, $name_mem:ident, $name_reg:ident, ximm8) => (\n        pub fn $name_mem(ctx: &mut JitContext, modrm_byte: ModrmByte, imm: u32) {\n            codegen::gen_modrm_resolve_with_local(ctx, modrm_byte, &|ctx, addr| {\n                codegen::gen_safe_read_write(ctx, BitSize::BYTE, &addr, &|ref mut ctx| {\n                    let dest_operand = ctx.builder.set_new_local();\n                    $fn(ctx, &dest_operand, &LocalOrImmediate::Immediate(imm as i32));\n                    ctx.builder.free_local(dest_operand);\n                });\n            });\n        }\n\n        pub fn $name_reg(ctx: &mut JitContext, r1: u32, imm: u32) {\n            let dest_operand = codegen::gen_get_reg8_or_alias_to_reg32(ctx, r1);\n            $fn(ctx, &dest_operand, &LocalOrImmediate::Immediate(imm as i32));\n            codegen::gen_set_reg8_unmasked(ctx, r1);\n            codegen::gen_free_reg8_or_alias(ctx, r1, dest_operand);\n        }\n    );\n\n    ($fn:expr, $name_mem:ident, $name_reg:ident, $imm:ident) => (\n        pub fn $name_mem(ctx: &mut JitContext, modrm_byte: ModrmByte, imm: u32) {\n            codegen::gen_modrm_resolve_with_local(ctx, modrm_byte, &|ctx, addr| {\n                let imm = mask_imm!(imm, $imm) as i32;\n                codegen::gen_safe_read_write(ctx, BitSize::BYTE, &addr, &|ref mut ctx| {\n                    ctx.builder.const_i32(imm as i32);\n                    ctx.builder.call_fn2_ret($fn);\n                });\n            });\n        }\n\n        pub fn $name_reg(ctx: &mut JitContext, r1: u32, imm: u32) {\n            let imm = mask_imm!(imm, $imm);\n            codegen::gen_get_reg8(ctx, r1);\n            ctx.builder.const_i32(imm as i32);\n            ctx.builder.call_fn2_ret($fn);\n            codegen::gen_set_reg8(ctx, r1);\n        }\n    );\n);\n\nmacro_rules! define_instruction_read_write_mem16(\n    ($fn:expr, $name_mem:ident, $name_reg:ident, reg) => (\n        pub fn $name_mem(ctx: &mut JitContext, modrm_byte: ModrmByte, r: u32) {\n            codegen::gen_modrm_resolve_with_local(ctx, modrm_byte, &|ctx, addr| {\n                codegen::gen_safe_read_write(ctx, BitSize::WORD, &addr, &|ref mut ctx| {\n                    codegen::gen_get_reg16(ctx, r);\n                    ctx.builder.call_fn2_ret($fn);\n                });\n            });\n        }\n\n        pub fn $name_reg(ctx: &mut JitContext, r1: u32, r2: u32) {\n            codegen::gen_get_reg16(ctx, r1);\n            codegen::gen_get_reg16(ctx, r2);\n            ctx.builder.call_fn2_ret($fn);\n            codegen::gen_set_reg16(ctx, r1);\n        }\n    );\n\n    ($fn:expr, $name_mem:ident, $name_reg:ident, constant_one) => (\n        pub fn $name_mem(ctx: &mut JitContext, modrm_byte: ModrmByte) {\n            codegen::gen_modrm_resolve_with_local(ctx, modrm_byte, &|ctx, addr| {\n                codegen::gen_safe_read_write(ctx, BitSize::WORD, &addr, &|ref mut ctx| {\n                    ctx.builder.const_i32(1);\n                    ctx.builder.call_fn2_ret($fn);\n                });\n            });\n        }\n\n        pub fn $name_reg(ctx: &mut JitContext, r1: u32) {\n            codegen::gen_get_reg16(ctx, r1);\n            ctx.builder.const_i32(1);\n            ctx.builder.call_fn2_ret($fn);\n            codegen::gen_set_reg16(ctx, r1);\n        }\n    );\n\n    ($fn:expr, $name_mem:ident, $name_reg:ident, cl) => (\n        pub fn $name_mem(ctx: &mut JitContext, modrm_byte: ModrmByte) {\n            codegen::gen_modrm_resolve_with_local(ctx, modrm_byte, &|ctx, addr| {\n                codegen::gen_safe_read_write(ctx, BitSize::WORD, &addr, &|ref mut ctx| {\n                    codegen::gen_get_reg8(ctx, regs::CL);\n                    ctx.builder.const_i32(31);\n                    ctx.builder.and_i32();\n                    ctx.builder.call_fn2_ret($fn);\n                });\n            });\n        }\n\n        pub fn $name_reg(ctx: &mut JitContext, r1: u32) {\n            codegen::gen_get_reg16(ctx, r1);\n            codegen::gen_get_reg8(ctx, regs::CL);\n                ctx.builder.const_i32(31);\n                ctx.builder.and_i32();\n            ctx.builder.call_fn2_ret($fn);\n            codegen::gen_set_reg16(ctx, r1);\n        }\n    );\n\n    ($fn:expr, $name_mem:ident, $name_reg:ident, reg, cl) => (\n        pub fn $name_mem(ctx: &mut JitContext, modrm_byte: ModrmByte, r: u32) {\n            codegen::gen_modrm_resolve_with_local(ctx, modrm_byte, &|ctx, addr| {\n                codegen::gen_safe_read_write(ctx, BitSize::WORD, &addr, &|ref mut ctx| {\n                    codegen::gen_get_reg16(ctx, r);\n                    codegen::gen_get_reg8(ctx, regs::CL);\n                    ctx.builder.const_i32(31);\n                    ctx.builder.and_i32();\n                    ctx.builder.call_fn3_ret($fn);\n                });\n            });\n        }\n\n        pub fn $name_reg(ctx: &mut JitContext, r1: u32, r2: u32) {\n            codegen::gen_get_reg16(ctx, r1);\n            codegen::gen_get_reg16(ctx, r2);\n            codegen::gen_get_reg8(ctx, regs::CL);\n            ctx.builder.const_i32(31);\n            ctx.builder.and_i32();\n            ctx.builder.call_fn3_ret($fn);\n            codegen::gen_set_reg16(ctx, r1);\n        }\n    );\n\n    ($fn:expr, $name_mem:ident, $name_reg:ident, reg, $imm:ident) => (\n        pub fn $name_mem(ctx: &mut JitContext, modrm_byte: ModrmByte, r: u32, imm: u32) {\n            codegen::gen_modrm_resolve_with_local(ctx, modrm_byte, &|ctx, addr| {\n                let imm = mask_imm!(imm, $imm);\n                codegen::gen_safe_read_write(ctx, BitSize::WORD, &addr, &|ref mut ctx| {\n                    codegen::gen_get_reg16(ctx, r);\n                    ctx.builder.const_i32(imm as i32);\n                    ctx.builder.call_fn3_ret($fn);\n                });\n            });\n        }\n\n        pub fn $name_reg(ctx: &mut JitContext, r1: u32, r2: u32, imm: u32) {\n            let imm = mask_imm!(imm, $imm);\n            codegen::gen_get_reg16(ctx, r1);\n            codegen::gen_get_reg16(ctx, r2);\n            ctx.builder.const_i32(imm as i32);\n            ctx.builder.call_fn3_ret($fn);\n            codegen::gen_set_reg16(ctx, r1);\n        }\n    );\n\n    ($fn:expr, $name_mem:ident, $name_reg:ident, none) => (\n        pub fn $name_mem(ctx: &mut JitContext, modrm_byte: ModrmByte) {\n            codegen::gen_modrm_resolve_with_local(ctx, modrm_byte, &|ctx, addr| {\n                codegen::gen_safe_read_write(ctx, BitSize::WORD, &addr, &|ref mut ctx| {\n                    let mut dest_operand = ctx.builder.set_new_local();\n                    $fn(ctx, &mut dest_operand);\n                    ctx.builder.get_local(&dest_operand);\n                    ctx.builder.free_local(dest_operand);\n                });\n            });\n        }\n\n        pub fn $name_reg(ctx: &mut JitContext, r1: u32) {\n            $fn(ctx, &mut ctx.reg(r1));\n        }\n    );\n\n    ($fn:expr, $name_mem:ident, $name_reg:ident, $imm:ident) => (\n        pub fn $name_mem(ctx: &mut JitContext, modrm_byte: ModrmByte, imm: u32) {\n            codegen::gen_modrm_resolve_with_local(ctx, modrm_byte, &|ctx, addr| {\n                let imm = mask_imm!(imm, $imm) as i32;\n                codegen::gen_safe_read_write(ctx, BitSize::WORD, &addr, &|ref mut ctx| {\n                    ctx.builder.const_i32(imm as i32);\n                    ctx.builder.call_fn2_ret($fn);\n                });\n            });\n        }\n\n        pub fn $name_reg(ctx: &mut JitContext, r1: u32, imm: u32) {\n            let imm = mask_imm!(imm, $imm);\n            codegen::gen_get_reg16(ctx, r1);\n            ctx.builder.const_i32(imm as i32);\n            ctx.builder.call_fn2_ret($fn);\n            codegen::gen_set_reg16(ctx, r1);\n        }\n    );\n);\n\nmacro_rules! define_instruction_read_write_mem32(\n    ($fn:expr, $name_mem:ident, $name_reg:ident, reg) => (\n        pub fn $name_mem(ctx: &mut JitContext, modrm_byte: ModrmByte, r: u32) {\n            codegen::gen_modrm_resolve_with_local(ctx, modrm_byte, &|ctx, addr| {\n                codegen::gen_safe_read_write(ctx, BitSize::DWORD, &addr, &|ref mut ctx| {\n                    let dest_operand = ctx.builder.set_new_local();\n                    $fn(\n                        ctx,\n                        &dest_operand,\n                        &LocalOrImmediate::WasmLocal(&ctx.reg(r)),\n                    );\n                    ctx.builder.get_local(&dest_operand);\n                    ctx.builder.free_local(dest_operand);\n                });\n            });\n        }\n\n        pub fn $name_reg(ctx: &mut JitContext, r1: u32, r2: u32) {\n            $fn(\n                ctx,\n                &ctx.reg(r1),\n                &LocalOrImmediate::WasmLocal(&ctx.reg(r2)),\n            );\n        }\n    );\n\n    ($fn:expr, $name_mem:ident, $name_reg:ident, constant_one) => (\n        pub fn $name_mem(ctx: &mut JitContext, modrm_byte: ModrmByte) {\n            codegen::gen_modrm_resolve_with_local(ctx, modrm_byte, &|ctx, addr| {\n                codegen::gen_safe_read_write(ctx, BitSize::DWORD, &addr, &|ref mut ctx| {\n                    let dest_operand = ctx.builder.set_new_local();\n                    $fn(ctx, &dest_operand, &LocalOrImmediate::Immediate(1));\n                    ctx.builder.get_local(&dest_operand);\n                    ctx.builder.free_local(dest_operand);\n                });\n            });\n        }\n\n        pub fn $name_reg(ctx: &mut JitContext, r1: u32) {\n            $fn(ctx, &ctx.reg(r1), &LocalOrImmediate::Immediate(1));\n        }\n    );\n\n    ($fn:expr, $name_mem:ident, $name_reg:ident, cl) => (\n        pub fn $name_mem(ctx: &mut JitContext, modrm_byte: ModrmByte) {\n            codegen::gen_modrm_resolve_with_local(ctx, modrm_byte, &|ctx, addr| {\n                codegen::gen_safe_read_write(ctx, BitSize::DWORD, &addr, &|ref mut ctx| {\n                    let dest_operand = ctx.builder.set_new_local();\n                    $fn(\n                        ctx,\n                        &dest_operand,\n                        &LocalOrImmediate::WasmLocal(&ctx.reg(regs::ECX)),\n                    );\n                    ctx.builder.get_local(&dest_operand);\n                    ctx.builder.free_local(dest_operand);\n                });\n            });\n        }\n\n        pub fn $name_reg(ctx: &mut JitContext, r1: u32) {\n            $fn(\n                ctx,\n                &ctx.reg(r1),\n                &LocalOrImmediate::WasmLocal(&ctx.reg(regs::ECX)),\n            );\n        }\n    );\n\n    ($fn:expr, $name_mem:ident, $name_reg:ident, reg, cl) => (\n        pub fn $name_mem(ctx: &mut JitContext, modrm_byte: ModrmByte, r: u32) {\n            codegen::gen_modrm_resolve_with_local(ctx, modrm_byte, &|ctx, addr| {\n                codegen::gen_safe_read_write(ctx, BitSize::DWORD, &addr, &|ref mut ctx| {\n                    codegen::gen_get_reg32(ctx, r);\n                    codegen::gen_get_reg8(ctx, regs::CL);\n                    ctx.builder.const_i32(31);\n                    ctx.builder.and_i32();\n                    ctx.builder.call_fn3_ret($fn);\n                });\n            });\n        }\n\n        pub fn $name_reg(ctx: &mut JitContext, r1: u32, r2: u32) {\n            codegen::gen_get_reg32(ctx, r1);\n            codegen::gen_get_reg32(ctx, r2);\n            codegen::gen_get_reg8(ctx, regs::CL);\n            ctx.builder.const_i32(31);\n            ctx.builder.and_i32();\n            ctx.builder.call_fn3_ret($fn);\n            codegen::gen_set_reg32(ctx, r1);\n        }\n    );\n\n    ($fn:expr, $name_mem:ident, $name_reg:ident, reg, $imm:ident) => (\n        pub fn $name_mem(ctx: &mut JitContext, modrm_byte: ModrmByte, r: u32, imm: u32) {\n            codegen::gen_modrm_resolve_with_local(ctx, modrm_byte, &|ctx, addr| {\n                let imm = mask_imm!(imm, $imm) as i32;\n                codegen::gen_safe_read_write(ctx, BitSize::DWORD, &addr, &|ref mut ctx| {\n                    codegen::gen_get_reg32(ctx, r);\n                    ctx.builder.const_i32(imm as i32);\n                    ctx.builder.call_fn3_ret($fn);\n                });\n            });\n        }\n\n        pub fn $name_reg(ctx: &mut JitContext, r1: u32, r2: u32, imm: u32) {\n            let imm = mask_imm!(imm, $imm);\n            codegen::gen_get_reg32(ctx, r1);\n            codegen::gen_get_reg32(ctx, r2);\n            ctx.builder.const_i32(imm as i32);\n            ctx.builder.call_fn3_ret($fn);\n            codegen::gen_set_reg32(ctx, r1);\n        }\n    );\n\n    ($fn:expr, $name_mem:ident, $name_reg:ident, none) => (\n        pub fn $name_mem(ctx: &mut JitContext, modrm_byte: ModrmByte) {\n            codegen::gen_modrm_resolve_with_local(ctx, modrm_byte, &|ctx, addr| {\n                codegen::gen_safe_read_write(ctx, BitSize::DWORD, &addr, &|ref mut ctx| {\n                    let mut dest_operand = ctx.builder.set_new_local();\n                    $fn(ctx, &mut dest_operand);\n                    ctx.builder.get_local(&dest_operand);\n                    ctx.builder.free_local(dest_operand);\n                });\n            });\n        }\n\n        pub fn $name_reg(ctx: &mut JitContext, r1: u32) {\n            $fn(ctx, &mut ctx.reg(r1));\n        }\n    );\n\n    ($fn:expr, $name_mem:ident, $name_reg:ident, $imm:ident) => (\n        pub fn $name_mem(ctx: &mut JitContext, modrm_byte: ModrmByte, imm: u32) {\n            codegen::gen_modrm_resolve_with_local(ctx, modrm_byte, &|ctx, addr| {\n                let imm = mask_imm!(imm, $imm);\n                codegen::gen_safe_read_write(ctx, BitSize::DWORD, &addr, &|ref mut ctx| {\n                    let dest_operand = ctx.builder.set_new_local();\n                    $fn(\n                        ctx,\n                        &dest_operand,\n                        &LocalOrImmediate::Immediate(imm as i32),\n                    );\n                    ctx.builder.get_local(&dest_operand);\n                    ctx.builder.free_local(dest_operand);\n                });\n            });\n        }\n\n        pub fn $name_reg(ctx: &mut JitContext, r1: u32, imm: u32) {\n            let imm = mask_imm!(imm, $imm);\n            $fn(\n                ctx,\n                &ctx.reg(r1),\n                &LocalOrImmediate::Immediate(imm as i32),\n            );\n        }\n    );\n);\n\nfn gen_add8(ctx: &mut JitContext, dest_operand: &WasmLocal, source_operand: &LocalOrImmediate) {\n    ctx.current_instruction = Instruction::Arithmetic { opsize: OPSIZE_8 };\n\n    ctx.builder.const_i32(global_pointers::last_op1 as i32);\n    ctx.builder.get_local(dest_operand);\n    ctx.builder.const_i32(0xFF);\n    ctx.builder.and_i32();\n    ctx.builder.store_aligned_i32(0);\n\n    ctx.builder.const_i32(global_pointers::last_result as i32);\n    ctx.builder.get_local(dest_operand);\n    source_operand.gen_get(ctx.builder);\n    ctx.builder.add_i32();\n    ctx.builder.const_i32(0xFF);\n    ctx.builder.and_i32();\n    ctx.builder.store_aligned_i32(0);\n\n    codegen::gen_set_last_op_size(ctx.builder, OPSIZE_8);\n    codegen::gen_set_flags_changed(ctx.builder, FLAGS_ALL);\n\n    ctx.builder\n        .load_fixed_u8(global_pointers::last_result as u32);\n}\nfn gen_add32(ctx: &mut JitContext, dest_operand: &WasmLocal, source_operand: &LocalOrImmediate) {\n    ctx.current_instruction = Instruction::Arithmetic { opsize: OPSIZE_32 };\n\n    codegen::gen_set_last_op1(ctx.builder, &dest_operand);\n\n    ctx.builder.get_local(&dest_operand);\n    source_operand.gen_get(ctx.builder);\n    ctx.builder.add_i32();\n    ctx.builder.set_local(dest_operand);\n\n    codegen::gen_set_last_result(ctx.builder, &dest_operand);\n    codegen::gen_set_last_op_size(ctx.builder, OPSIZE_32);\n    codegen::gen_set_flags_changed(ctx.builder, FLAGS_ALL);\n}\n\nfn gen_sub8(ctx: &mut JitContext, dest_operand: &WasmLocal, source_operand: &LocalOrImmediate) {\n    ctx.current_instruction = Instruction::Arithmetic { opsize: OPSIZE_8 };\n\n    ctx.builder.const_i32(global_pointers::last_op1 as i32);\n    ctx.builder.get_local(dest_operand);\n    ctx.builder.const_i32(0xFF);\n    ctx.builder.and_i32();\n    ctx.builder.store_aligned_i32(0);\n\n    ctx.builder.const_i32(global_pointers::last_result as i32);\n    ctx.builder.get_local(dest_operand);\n    source_operand.gen_get(ctx.builder);\n    ctx.builder.sub_i32();\n    ctx.builder.const_i32(0xFF);\n    ctx.builder.and_i32();\n    ctx.builder.store_aligned_i32(0);\n\n    codegen::gen_set_last_op_size(ctx.builder, OPSIZE_8);\n    codegen::gen_set_flags_changed(ctx.builder, FLAGS_ALL | FLAG_SUB);\n\n    ctx.builder\n        .load_fixed_u8(global_pointers::last_result as u32);\n}\nfn gen_sub32(ctx: &mut JitContext, dest_operand: &WasmLocal, source_operand: &LocalOrImmediate) {\n    ctx.current_instruction = Instruction::Sub { opsize: OPSIZE_32 };\n\n    codegen::gen_set_last_op1(ctx.builder, &dest_operand);\n\n    ctx.builder.get_local(&dest_operand);\n    source_operand.gen_get(ctx.builder);\n    ctx.builder.sub_i32();\n    ctx.builder.set_local(dest_operand);\n\n    codegen::gen_set_last_result(ctx.builder, &dest_operand);\n    codegen::gen_set_last_op_size(ctx.builder, OPSIZE_32);\n    codegen::gen_set_flags_changed(ctx.builder, FLAGS_ALL | FLAG_SUB);\n}\n\nfn gen_cmp(\n    ctx: &mut JitContext,\n    dest_operand: &WasmLocal,\n    source_operand: &LocalOrImmediate,\n    size: i32,\n) {\n    ctx.current_instruction = Instruction::Cmp {\n        dest: if ctx.register_locals.iter().any(|l| l == dest_operand) {\n            InstructionOperand::WasmLocal(dest_operand.unsafe_clone())\n        }\n        else {\n            InstructionOperand::Other\n        },\n        source: match source_operand {\n            &LocalOrImmediate::WasmLocal(source) => {\n                if ctx.register_locals.iter().any(|l| l == source) {\n                    InstructionOperand::WasmLocal(source.unsafe_clone())\n                }\n                else {\n                    InstructionOperand::Other\n                }\n            },\n            &LocalOrImmediate::Immediate(i) => InstructionOperand::Immediate(i),\n        },\n        opsize: size,\n    };\n\n    ctx.builder.const_i32(global_pointers::last_result as i32);\n    if source_operand.is_zero() {\n        ctx.builder.get_local(&dest_operand);\n    }\n    else {\n        ctx.builder.get_local(&dest_operand);\n        source_operand.gen_get(ctx.builder);\n        ctx.builder.sub_i32();\n    }\n    if size == OPSIZE_8 || size == OPSIZE_16 {\n        ctx.builder\n            .const_i32(if size == OPSIZE_8 { 0xFF } else { 0xFFFF });\n        ctx.builder.and_i32();\n    }\n    ctx.builder.store_aligned_i32(0);\n\n    ctx.builder.const_i32(global_pointers::last_op1 as i32);\n    ctx.builder.get_local(&dest_operand);\n    if size == OPSIZE_8 || size == OPSIZE_16 {\n        ctx.builder\n            .const_i32(if size == OPSIZE_8 { 0xFF } else { 0xFFFF });\n        ctx.builder.and_i32();\n    }\n    ctx.builder.store_aligned_i32(0);\n    codegen::gen_set_last_op_size(ctx.builder, size);\n    codegen::gen_set_flags_changed(ctx.builder, FLAGS_ALL | FLAG_SUB);\n}\nfn gen_cmp8(ctx: &mut JitContext, dest: &WasmLocal, source: &LocalOrImmediate) {\n    gen_cmp(ctx, dest, source, OPSIZE_8)\n}\nfn gen_cmp16(ctx: &mut JitContext, dest: &WasmLocal, source: &LocalOrImmediate) {\n    gen_cmp(ctx, dest, source, OPSIZE_16)\n}\nfn gen_cmp32(ctx: &mut JitContext, dest: &WasmLocal, source: &LocalOrImmediate) {\n    gen_cmp(ctx, dest, source, OPSIZE_32)\n}\n\nfn gen_adc8(ctx: &mut JitContext, dest_operand: &WasmLocal, source_operand: &LocalOrImmediate) {\n    ctx.builder.get_local(dest_operand);\n    ctx.builder.const_i32(0xFF);\n    ctx.builder.and_i32();\n    source_operand.gen_get_mask255(ctx.builder);\n    ctx.builder.call_fn2_ret("adc8");\n    ctx.builder.const_i32(0xFF);\n    ctx.builder.and_i32();\n}\nfn gen_adc32(ctx: &mut JitContext, dest_operand: &WasmLocal, source_operand: &LocalOrImmediate) {\n    ctx.builder.get_local(&dest_operand);\n    source_operand.gen_get(ctx.builder);\n    ctx.builder.add_i32();\n    codegen::gen_getcf_unoptimised(ctx.builder);\n    ctx.builder.add_i32();\n    let res = ctx.builder.set_new_local();\n\n    codegen::gen_set_last_result(ctx.builder, &res);\n    codegen::gen_set_last_op_size(ctx.builder, OPSIZE_32);\n    codegen::gen_set_flags_changed(\n        ctx.builder,\n        FLAGS_ALL & !FLAG_CARRY & !FLAG_OVERFLOW & !FLAG_ADJUST,\n    );\n\n    ctx.builder.const_i32(global_pointers::flags as i32);\n    codegen::gen_get_flags(ctx.builder);\n    ctx.builder\n        .const_i32(!FLAG_CARRY & !FLAG_ADJUST & !FLAG_OVERFLOW);\n    ctx.builder.and_i32();\n\n    // cf: (dest_operand ^ ((dest_operand ^ source_operand) & (source_operand ^ res))) >> op_size & FLAG_CARRY\n    ctx.builder.get_local(&dest_operand);\n    ctx.builder.get_local(&dest_operand);\n    source_operand.gen_get(ctx.builder);\n    ctx.builder.xor_i32();\n    source_operand.gen_get(ctx.builder);\n    ctx.builder.get_local(&res);\n    ctx.builder.xor_i32();\n    ctx.builder.and_i32();\n    ctx.builder.xor_i32();\n    ctx.builder.const_i32(31);\n    ctx.builder.shr_u_i32();\n    ctx.builder.const_i32(FLAG_CARRY);\n    ctx.builder.and_i32();\n    ctx.builder.or_i32();\n\n    // af: (dest_operand ^ source_operand ^ res) & FLAG_ADJUST\n    ctx.builder.get_local(&dest_operand);\n    source_operand.gen_get(ctx.builder);\n    ctx.builder.get_local(&res);\n    ctx.builder.xor_i32();\n    ctx.builder.xor_i32();\n    ctx.builder.const_i32(FLAG_ADJUST);\n    ctx.builder.and_i32();\n    ctx.builder.or_i32();\n\n    // of: ((source_operand ^ res) & (dest_operand ^ res)) >> op_size << 11 & FLAG_OVERFLOW\n    source_operand.gen_get(ctx.builder);\n    ctx.builder.get_local(&res);\n    ctx.builder.xor_i32();\n    ctx.builder.get_local(&dest_operand);\n    ctx.builder.get_local(&res);\n    ctx.builder.xor_i32();\n    ctx.builder.and_i32();\n    ctx.builder.const_i32(31 - 11);\n    ctx.builder.shr_u_i32();\n    ctx.builder.const_i32(FLAG_OVERFLOW);\n    ctx.builder.and_i32();\n    ctx.builder.or_i32();\n\n    ctx.builder.store_aligned_i32(0);\n\n    ctx.builder.get_local(&res);\n    ctx.builder.set_local(dest_operand);\n    ctx.builder.free_local(res);\n}\n\nfn gen_sbb8(ctx: &mut JitContext, dest_operand: &WasmLocal, source_operand: &LocalOrImmediate) {\n    ctx.builder.get_local(dest_operand);\n    ctx.builder.const_i32(0xFF);\n    ctx.builder.and_i32();\n    source_operand.gen_get_mask255(ctx.builder);\n    ctx.builder.call_fn2_ret("sbb8");\n    ctx.builder.const_i32(0xFF);\n    ctx.builder.and_i32();\n}\nfn gen_sbb32(ctx: &mut JitContext, dest_operand: &WasmLocal, source_operand: &LocalOrImmediate) {\n    ctx.builder.get_local(&dest_operand);\n    source_operand.gen_get(ctx.builder);\n    ctx.builder.sub_i32();\n    codegen::gen_getcf_unoptimised(ctx.builder);\n    ctx.builder.sub_i32();\n    let res = ctx.builder.set_new_local();\n\n    codegen::gen_set_last_result(ctx.builder, &res);\n    codegen::gen_set_last_op_size(ctx.builder, OPSIZE_32);\n    codegen::gen_set_flags_changed(\n        ctx.builder,\n        FLAGS_ALL & !FLAG_CARRY & !FLAG_OVERFLOW & !FLAG_ADJUST,\n    );\n\n    ctx.builder.const_i32(global_pointers::flags as i32);\n    codegen::gen_get_flags(ctx.builder);\n    ctx.builder\n        .const_i32(!FLAG_CARRY & !FLAG_ADJUST & !FLAG_OVERFLOW);\n    ctx.builder.and_i32();\n\n    // cf: (res ^ ((res ^ source_operand) & (source_operand ^ dest_operand))) >> op_size & FLAG_CARRY\n    ctx.builder.get_local(&res);\n    ctx.builder.get_local(&res);\n    source_operand.gen_get(ctx.builder);\n    ctx.builder.xor_i32();\n    source_operand.gen_get(ctx.builder);\n    ctx.builder.get_local(&dest_operand);\n    ctx.builder.xor_i32();\n    ctx.builder.and_i32();\n    ctx.builder.xor_i32();\n    ctx.builder.const_i32(31);\n    ctx.builder.shr_u_i32();\n    ctx.builder.const_i32(FLAG_CARRY);\n    ctx.builder.and_i32();\n    ctx.builder.or_i32();\n\n    // af: (dest_operand ^ source_operand ^ res) & FLAG_ADJUST\n    ctx.builder.get_local(&dest_operand);\n    source_operand.gen_get(ctx.builder);\n    ctx.builder.get_local(&res);\n    ctx.builder.xor_i32();\n    ctx.builder.xor_i32();\n    ctx.builder.const_i32(FLAG_ADJUST);\n    ctx.builder.and_i32();\n    ctx.builder.or_i32();\n\n    // of: ((source_operand ^ dest_operand) & (res ^ dest_operand)) >> op_size << 11 & FLAG_OVERFLOW\n    source_operand.gen_get(ctx.builder);\n    ctx.builder.get_local(&dest_operand);\n    ctx.builder.xor_i32();\n    ctx.builder.get_local(&res);\n    ctx.builder.get_local(&dest_operand);\n    ctx.builder.xor_i32();\n    ctx.builder.and_i32();\n    ctx.builder.const_i32(31 - 11);\n    ctx.builder.shr_u_i32();\n    ctx.builder.const_i32(FLAG_OVERFLOW);\n    ctx.builder.and_i32();\n    ctx.builder.or_i32();\n\n    ctx.builder.store_aligned_i32(0);\n\n    ctx.builder.get_local(&res);\n    ctx.builder.set_local(dest_operand);\n    ctx.builder.free_local(res);\n}\n\nfn gen_and8(ctx: &mut JitContext, dest_operand: &WasmLocal, source_operand: &LocalOrImmediate) {\n    ctx.current_instruction = Instruction::Arithmetic { opsize: OPSIZE_8 };\n\n    ctx.builder.const_i32(global_pointers::last_result as i32);\n    ctx.builder.get_local(dest_operand);\n    source_operand.gen_get(ctx.builder);\n    ctx.builder.and_i32();\n    ctx.builder.store_aligned_i32(0);\n\n    codegen::gen_set_last_op_size(ctx.builder, OPSIZE_8);\n    codegen::gen_set_flags_changed(\n        ctx.builder,\n        FLAGS_ALL & !FLAG_CARRY & !FLAG_OVERFLOW & !FLAG_ADJUST,\n    );\n    codegen::gen_clear_flags_bits(ctx.builder, FLAG_CARRY | FLAG_OVERFLOW | FLAG_ADJUST);\n\n    ctx.builder\n        .load_fixed_u8(global_pointers::last_result as u32);\n}\nfn gen_and32(ctx: &mut JitContext, dest_operand: &WasmLocal, source_operand: &LocalOrImmediate) {\n    ctx.current_instruction = Instruction::Arithmetic { opsize: OPSIZE_32 };\n\n    ctx.builder.get_local(&dest_operand);\n    source_operand.gen_get(ctx.builder);\n    ctx.builder.and_i32();\n    ctx.builder.set_local(dest_operand);\n\n    codegen::gen_set_last_result(ctx.builder, &dest_operand);\n    codegen::gen_set_last_op_size(ctx.builder, OPSIZE_32);\n    codegen::gen_set_flags_changed(\n        ctx.builder,\n        FLAGS_ALL & !FLAG_CARRY & !FLAG_OVERFLOW & !FLAG_ADJUST,\n    );\n    codegen::gen_clear_flags_bits(ctx.builder, FLAG_CARRY | FLAG_OVERFLOW | FLAG_ADJUST);\n}\n\nfn gen_test(\n    ctx: &mut JitContext,\n    dest_operand: &WasmLocal,\n    source_operand: &LocalOrImmediate,\n    size: i32,\n) {\n    ctx.current_instruction = Instruction::Arithmetic { opsize: size };\n\n    ctx.builder.const_i32(global_pointers::last_result as i32);\n    if source_operand.eq_local(dest_operand) {\n        ctx.builder.get_local(&dest_operand);\n    }\n    else {\n        ctx.builder.get_local(&dest_operand);\n        source_operand.gen_get(ctx.builder);\n        ctx.builder.and_i32();\n    }\n    ctx.builder.store_aligned_i32(0);\n\n    codegen::gen_set_last_op_size(ctx.builder, size);\n    codegen::gen_set_flags_changed(\n        ctx.builder,\n        FLAGS_ALL & !FLAG_CARRY & !FLAG_OVERFLOW & !FLAG_ADJUST,\n    );\n    codegen::gen_clear_flags_bits(ctx.builder, FLAG_CARRY | FLAG_OVERFLOW | FLAG_ADJUST);\n}\nfn gen_test8(ctx: &mut JitContext, dest: &WasmLocal, source: &LocalOrImmediate) {\n    gen_test(ctx, dest, source, OPSIZE_8)\n}\nfn gen_test16(ctx: &mut JitContext, dest: &WasmLocal, source: &LocalOrImmediate) {\n    gen_test(ctx, dest, source, OPSIZE_16)\n}\nfn gen_test32(ctx: &mut JitContext, dest: &WasmLocal, source: &LocalOrImmediate) {\n    gen_test(ctx, dest, source, OPSIZE_32)\n}\n\nfn gen_or8(ctx: &mut JitContext, dest_operand: &WasmLocal, source_operand: &LocalOrImmediate) {\n    ctx.current_instruction = Instruction::Arithmetic { opsize: OPSIZE_8 };\n\n    ctx.builder.const_i32(global_pointers::last_result as i32);\n    ctx.builder.get_local(dest_operand);\n    source_operand.gen_get(ctx.builder);\n    ctx.builder.or_i32();\n    ctx.builder.store_aligned_i32(0);\n\n    codegen::gen_set_last_op_size(ctx.builder, OPSIZE_8);\n    codegen::gen_set_flags_changed(\n        ctx.builder,\n        FLAGS_ALL & !FLAG_CARRY & !FLAG_OVERFLOW & !FLAG_ADJUST,\n    );\n    codegen::gen_clear_flags_bits(ctx.builder, FLAG_CARRY | FLAG_OVERFLOW | FLAG_ADJUST);\n\n    ctx.builder\n        .load_fixed_u8(global_pointers::last_result as u32);\n}\nfn gen_or32(ctx: &mut JitContext, dest_operand: &WasmLocal, source_operand: &LocalOrImmediate) {\n    ctx.current_instruction = Instruction::Arithmetic { opsize: OPSIZE_32 };\n\n    ctx.builder.get_local(&dest_operand);\n    source_operand.gen_get(ctx.builder);\n    ctx.builder.or_i32();\n    ctx.builder.set_local(dest_operand);\n\n    codegen::gen_set_last_result(ctx.builder, &dest_operand);\n    codegen::gen_set_last_op_size(ctx.builder, OPSIZE_32);\n    codegen::gen_set_flags_changed(\n        ctx.builder,\n        FLAGS_ALL & !FLAG_CARRY & !FLAG_OVERFLOW & !FLAG_ADJUST,\n    );\n    codegen::gen_clear_flags_bits(ctx.builder, FLAG_CARRY | FLAG_OVERFLOW | FLAG_ADJUST);\n}\n\nfn gen_xor8(ctx: &mut JitContext, dest_operand: &WasmLocal, source_operand: &LocalOrImmediate) {\n    ctx.current_instruction = Instruction::Arithmetic { opsize: OPSIZE_8 };\n\n    ctx.builder.const_i32(global_pointers::last_result as i32);\n    ctx.builder.get_local(dest_operand);\n    source_operand.gen_get(ctx.builder);\n    ctx.builder.xor_i32();\n    ctx.builder.store_aligned_i32(0);\n\n    codegen::gen_set_last_op_size(ctx.builder, OPSIZE_8);\n    codegen::gen_set_flags_changed(\n        ctx.builder,\n        FLAGS_ALL & !FLAG_CARRY & !FLAG_OVERFLOW & !FLAG_ADJUST,\n    );\n    codegen::gen_clear_flags_bits(ctx.builder, FLAG_CARRY | FLAG_OVERFLOW | FLAG_ADJUST);\n\n    ctx.builder\n        .load_fixed_u8(global_pointers::last_result as u32);\n}\nfn gen_xor32(ctx: &mut JitContext, dest_operand: &WasmLocal, source_operand: &LocalOrImmediate) {\n    ctx.current_instruction = Instruction::Arithmetic { opsize: OPSIZE_32 };\n\n    if source_operand.eq_local(dest_operand) {\n        ctx.builder.const_i32(0);\n        ctx.builder.set_local(dest_operand);\n    // TODO:\n    // - Set last_result to zero rather than reading from local\n    // - Skip setting opsize (not relevant for SF, ZF, and PF on zero)\n    }\n    else {\n        ctx.builder.get_local(&dest_operand);\n        source_operand.gen_get(ctx.builder);\n        ctx.builder.xor_i32();\n        ctx.builder.set_local(dest_operand);\n    }\n\n    codegen::gen_set_last_result(ctx.builder, &dest_operand);\n    codegen::gen_set_last_op_size(ctx.builder, OPSIZE_32);\n    codegen::gen_set_flags_changed(\n        ctx.builder,\n        FLAGS_ALL & !FLAG_CARRY & !FLAG_OVERFLOW & !FLAG_ADJUST,\n    );\n    codegen::gen_clear_flags_bits(ctx.builder, FLAG_CARRY | FLAG_OVERFLOW | FLAG_ADJUST);\n}\n\nfn gen_rol32(ctx: &mut JitContext, dest_operand: &WasmLocal, source_operand: &LocalOrImmediate) {\n    let builder = &mut ctx.builder;\n    builder.get_local(dest_operand);\n    match source_operand {\n        LocalOrImmediate::WasmLocal(l) => {\n            builder.get_local(l);\n            builder.const_i32(31);\n            builder.and_i32();\n        },\n        LocalOrImmediate::Immediate(i) => {\n            builder.const_i32(*i & 31);\n        },\n    }\n    builder.const_i32(31);\n    builder.and_i32();\n    builder.call_fn2_ret("rol32");\n    builder.set_local(dest_operand);\n}\nfn gen_ror32(ctx: &mut JitContext, dest_operand: &WasmLocal, source_operand: &LocalOrImmediate) {\n    let builder = &mut ctx.builder;\n    builder.get_local(dest_operand);\n    match source_operand {\n        LocalOrImmediate::WasmLocal(l) => {\n            builder.get_local(l);\n            builder.const_i32(31);\n            builder.and_i32();\n        },\n        LocalOrImmediate::Immediate(i) => {\n            builder.const_i32(*i & 31);\n        },\n    }\n    builder.const_i32(31);\n    builder.and_i32();\n    builder.call_fn2_ret("ror32");\n    builder.set_local(dest_operand);\n}\n\nfn gen_rcl32(ctx: &mut JitContext, dest_operand: &WasmLocal, source_operand: &LocalOrImmediate) {\n    let builder = &mut ctx.builder;\n    builder.get_local(dest_operand);\n    match source_operand {\n        LocalOrImmediate::WasmLocal(l) => {\n            builder.get_local(l);\n            builder.const_i32(31);\n            builder.and_i32();\n        },\n        LocalOrImmediate::Immediate(i) => {\n            builder.const_i32(*i & 31);\n        },\n    }\n    builder.const_i32(31);\n    builder.and_i32();\n    builder.call_fn2_ret("rcl32");\n    builder.set_local(dest_operand);\n}\nfn gen_rcr32(ctx: &mut JitContext, dest_operand: &WasmLocal, source_operand: &LocalOrImmediate) {\n    let builder = &mut ctx.builder;\n    builder.get_local(dest_operand);\n    match source_operand {\n        LocalOrImmediate::WasmLocal(l) => {\n            builder.get_local(l);\n            builder.const_i32(31);\n            builder.and_i32();\n        },\n        LocalOrImmediate::Immediate(i) => {\n            builder.const_i32(*i & 31);\n        },\n    }\n    builder.const_i32(31);\n    builder.and_i32();\n    builder.call_fn2_ret("rcr32");\n    builder.set_local(dest_operand);\n}\n\nenum ShiftCount {\n    Local(WasmLocal),\n    Immediate(i32),\n}\nimpl ShiftCount {\n    pub fn gen_get(builder: &mut WasmBuilder, count: &ShiftCount) {\n        match &count {\n            ShiftCount::Local(l) => builder.get_local(l),\n            ShiftCount::Immediate(i) => builder.const_i32(*i),\n        }\n    }\n    pub fn gen_get_thirtytwo_minus(builder: &mut WasmBuilder, count: &ShiftCount) {\n        match &count {\n            ShiftCount::Local(l) => {\n                builder.const_i32(32);\n                builder.get_local(l);\n                builder.sub_i32();\n            },\n            ShiftCount::Immediate(i) => builder.const_i32(32 - *i),\n        }\n    }\n    pub fn gen_get_minus_one(builder: &mut WasmBuilder, count: &ShiftCount) {\n        match &count {\n            ShiftCount::Local(l) => {\n                builder.get_local(l);\n                builder.const_i32(1);\n                builder.sub_i32()\n            },\n            ShiftCount::Immediate(i) => builder.const_i32(*i - 1),\n        }\n    }\n}\n\nfn gen_shl32(ctx: &mut JitContext, dest_operand: &WasmLocal, source_operand: &LocalOrImmediate) {\n    let builder = &mut ctx.builder;\n    let count = match source_operand {\n        LocalOrImmediate::WasmLocal(l) => {\n            let exit = builder.block_void();\n            builder.get_local(l);\n            builder.const_i32(31); // Note: mask can probably be avoided since wasm has the same semantics on shl_i32\n            builder.and_i32();\n            let count = builder.tee_new_local();\n            builder.eqz_i32();\n            builder.br_if(exit);\n            ShiftCount::Local(count)\n        },\n        LocalOrImmediate::Immediate(i) => {\n            if *i & 31 == 0 {\n                return;\n            }\n            ShiftCount::Immediate(*i & 31)\n        },\n    };\n\n    builder.get_local(&dest_operand);\n    ShiftCount::gen_get_thirtytwo_minus(builder, &count);\n    builder.shr_u_i32();\n    builder.const_i32(1);\n    builder.and_i32();\n    let b = builder.set_new_local();\n\n    builder.get_local(dest_operand);\n    ShiftCount::gen_get(builder, &count);\n    builder.shl_i32();\n    builder.set_local(dest_operand);\n\n    codegen::gen_set_last_result(builder, dest_operand);\n    codegen::gen_set_last_op_size(builder, OPSIZE_32);\n    codegen::gen_set_flags_changed(builder, FLAGS_ALL & !FLAG_CARRY & !FLAG_OVERFLOW);\n\n    builder.const_i32(global_pointers::flags as i32);\n    codegen::gen_get_flags(builder);\n    builder.const_i32(!(FLAG_CARRY | FLAG_OVERFLOW));\n    builder.and_i32();\n    builder.get_local(&b);\n    builder.or_i32();\n    {\n        builder.get_local(&b);\n        builder.get_local(&dest_operand);\n        builder.const_i32(31);\n        builder.shr_u_i32();\n        builder.xor_i32();\n        builder.const_i32(11);\n        builder.shl_i32();\n        builder.const_i32(FLAG_OVERFLOW);\n        builder.and_i32();\n        builder.or_i32();\n    }\n    builder.store_aligned_i32(0);\n\n    builder.free_local(b);\n\n    if let ShiftCount::Local(l) = count {\n        builder.block_end();\n        builder.free_local(l);\n    }\n}\nfn gen_shr32(ctx: &mut JitContext, dest_operand: &WasmLocal, source_operand: &LocalOrImmediate) {\n    let builder = &mut ctx.builder;\n    let count = match source_operand {\n        LocalOrImmediate::WasmLocal(l) => {\n            let exit = builder.block_void();\n            builder.get_local(l);\n            builder.const_i32(31); // Note: mask can probably be avoided since wasm has the same semantics on shl_i32\n            builder.and_i32();\n            let count = builder.tee_new_local();\n            builder.eqz_i32();\n            builder.br_if(exit);\n            ShiftCount::Local(count)\n        },\n        LocalOrImmediate::Immediate(i) => {\n            if *i & 31 == 0 {\n                return;\n            }\n            ShiftCount::Immediate(*i & 31)\n        },\n    };\n\n    builder.const_i32(global_pointers::flags as i32);\n    codegen::gen_get_flags(builder);\n    builder.const_i32(!(FLAG_CARRY | FLAG_OVERFLOW));\n    builder.and_i32();\n    {\n        builder.get_local(dest_operand);\n        ShiftCount::gen_get_minus_one(builder, &count);\n        builder.shr_u_i32();\n        builder.const_i32(1);\n        builder.and_i32();\n        builder.or_i32()\n    }\n    {\n        builder.get_local(dest_operand);\n        builder.const_i32(20);\n        builder.shr_u_i32();\n        builder.const_i32(FLAG_OVERFLOW);\n        builder.and_i32();\n        builder.or_i32()\n    }\n    builder.store_aligned_i32(0);\n\n    builder.get_local(dest_operand);\n    ShiftCount::gen_get(builder, &count);\n    builder.shr_u_i32();\n    builder.set_local(dest_operand);\n\n    codegen::gen_set_last_result(builder, dest_operand);\n    codegen::gen_set_last_op_size(builder, OPSIZE_32);\n    codegen::gen_set_flags_changed(builder, FLAGS_ALL & !FLAG_CARRY & !FLAG_OVERFLOW);\n\n    if let ShiftCount::Local(l) = count {\n        builder.block_end();\n        builder.free_local(l);\n    }\n}\nfn gen_sar32(ctx: &mut JitContext, dest_operand: &WasmLocal, source_operand: &LocalOrImmediate) {\n    let builder = &mut ctx.builder;\n    let count = match source_operand {\n        LocalOrImmediate::WasmLocal(l) => {\n            let exit = builder.block_void();\n            builder.get_local(l);\n            builder.const_i32(31); // Note: mask can probably be avoided since wasm has the same semantics on shl_i32\n            builder.and_i32();\n            let count = builder.tee_new_local();\n            builder.eqz_i32();\n            builder.br_if(exit);\n            ShiftCount::Local(count)\n        },\n        LocalOrImmediate::Immediate(i) => {\n            if *i & 31 == 0 {\n                return;\n            }\n            ShiftCount::Immediate(*i & 31)\n        },\n    };\n\n    builder.const_i32(global_pointers::flags as i32);\n    codegen::gen_get_flags(builder);\n    builder.const_i32(!(FLAG_CARRY | FLAG_OVERFLOW));\n    builder.and_i32();\n    {\n        builder.get_local(dest_operand);\n        ShiftCount::gen_get_minus_one(builder, &count);\n        builder.shr_u_i32();\n        builder.const_i32(1);\n        builder.and_i32();\n        builder.or_i32()\n    }\n    builder.store_aligned_i32(0);\n\n    builder.get_local(dest_operand);\n    ShiftCount::gen_get(builder, &count);\n    builder.shr_s_i32();\n    builder.set_local(dest_operand);\n\n    codegen::gen_set_last_result(builder, dest_operand);\n    codegen::gen_set_last_op_size(builder, OPSIZE_32);\n    codegen::gen_set_flags_changed(builder, FLAGS_ALL & !FLAG_CARRY & !FLAG_OVERFLOW);\n\n    if let ShiftCount::Local(l) = count {\n        builder.block_end();\n        builder.free_local(l);\n    }\n}\n\nfn gen_xadd32(ctx: &mut JitContext, dest_operand: &WasmLocal, r: u32) {\n    ctx.builder.get_local(&ctx.register_locals[r as usize]);\n    let tmp = ctx.builder.set_new_local();\n\n    ctx.builder.get_local(&dest_operand);\n    codegen::gen_set_reg32(ctx, r);\n\n    gen_add32(ctx, &dest_operand, &LocalOrImmediate::WasmLocal(&tmp));\n\n    ctx.builder.free_local(tmp);\n}\n\nfn gen_cmpxchg32(ctx: &mut JitContext, r: u32) {\n    let source = ctx.builder.set_new_local();\n\n    ctx.builder.const_i32(global_pointers::last_result as i32);\n    codegen::gen_get_reg32(ctx, regs::EAX);\n    ctx.builder.get_local(&source);\n    ctx.builder.sub_i32();\n    ctx.builder.store_aligned_i32(0);\n\n    ctx.builder.const_i32(global_pointers::last_op1 as i32);\n    codegen::gen_get_reg32(ctx, regs::EAX);\n    ctx.builder.store_aligned_i32(0);\n    codegen::gen_set_last_op_size(ctx.builder, OPSIZE_32);\n    codegen::gen_set_flags_changed(ctx.builder, FLAGS_ALL | FLAG_SUB);\n\n    codegen::gen_get_reg32(ctx, regs::EAX);\n    ctx.builder.get_local(&source);\n    ctx.builder.eq_i32();\n    ctx.builder.if_i32();\n    codegen::gen_get_reg32(ctx, r);\n    ctx.builder.else_();\n    ctx.builder.get_local(&source);\n    codegen::gen_set_reg32(ctx, regs::EAX);\n    ctx.builder.get_local(&source);\n    ctx.builder.block_end();\n\n    ctx.builder.free_local(source);\n}\n\nfn gen_mul32(ctx: &mut JitContext) {\n    ctx.builder.extend_unsigned_i32_to_i64();\n\n    codegen::gen_get_reg32(ctx, regs::EAX);\n    ctx.builder.extend_unsigned_i32_to_i64();\n    ctx.builder.mul_i64();\n\n    let result = ctx.builder.tee_new_local_i64();\n    ctx.builder.const_i64(32);\n    ctx.builder.shr_u_i64();\n    ctx.builder.wrap_i64_to_i32();\n    codegen::gen_set_reg32(ctx, regs::EDX);\n\n    ctx.builder.get_local_i64(&result);\n    ctx.builder.free_local_i64(result);\n    ctx.builder.wrap_i64_to_i32();\n    codegen::gen_set_reg32(ctx, regs::EAX);\n\n    codegen::gen_get_reg32(ctx, regs::EDX);\n    ctx.builder.if_void();\n    codegen::gen_set_flags_bits(ctx.builder, 1 | FLAG_OVERFLOW);\n    ctx.builder.else_();\n    codegen::gen_clear_flags_bits(ctx.builder, 1 | FLAG_OVERFLOW);\n    ctx.builder.block_end();\n\n    codegen::gen_set_last_result(ctx.builder, &ctx.register_locals[regs::EAX as usize]);\n    codegen::gen_set_last_op_size(ctx.builder, OPSIZE_32);\n    codegen::gen_set_flags_changed(ctx.builder, FLAGS_ALL & !1 & !FLAG_OVERFLOW);\n}\n\nfn gen_imul32(ctx: &mut JitContext) {\n    ctx.builder.extend_signed_i32_to_i64();\n\n    codegen::gen_get_reg32(ctx, regs::EAX);\n    ctx.builder.extend_signed_i32_to_i64();\n    ctx.builder.mul_i64();\n\n    let result = ctx.builder.tee_new_local_i64();\n    ctx.builder.const_i64(32);\n    ctx.builder.shr_u_i64();\n    ctx.builder.wrap_i64_to_i32();\n    codegen::gen_set_reg32(ctx, regs::EDX);\n\n    ctx.builder.get_local_i64(&result);\n    ctx.builder.free_local_i64(result);\n    ctx.builder.wrap_i64_to_i32();\n    codegen::gen_set_reg32(ctx, regs::EAX);\n\n    codegen::gen_get_reg32(ctx, regs::EDX);\n    codegen::gen_get_reg32(ctx, regs::EAX);\n    ctx.builder.const_i32(31);\n    ctx.builder.shr_s_i32();\n    ctx.builder.eq_i32();\n    ctx.builder.if_void();\n    codegen::gen_clear_flags_bits(ctx.builder, 1 | FLAG_OVERFLOW);\n    ctx.builder.else_();\n    codegen::gen_set_flags_bits(ctx.builder, 1 | FLAG_OVERFLOW);\n    ctx.builder.block_end();\n\n    codegen::gen_set_last_result(ctx.builder, &ctx.register_locals[regs::EAX as usize]);\n    codegen::gen_set_last_op_size(ctx.builder, OPSIZE_32);\n    codegen::gen_set_flags_changed(ctx.builder, FLAGS_ALL & !1 & !FLAG_OVERFLOW);\n}\n\nfn gen_imul_reg32(\n    ctx: &mut JitContext,\n    dest_operand: &WasmLocal,\n    source_operand: &LocalOrImmediate,\n) {\n    gen_imul3_reg32(ctx.builder, dest_operand, dest_operand, source_operand);\n}\n\nfn gen_imul3_reg32(\n    builder: &mut WasmBuilder,\n    dest_operand: &WasmLocal,\n    source_operand1: &WasmLocal,\n    source_operand2: &LocalOrImmediate,\n) {\n    builder.get_local(&source_operand1);\n    builder.extend_signed_i32_to_i64();\n    source_operand2.gen_get(builder);\n    builder.extend_signed_i32_to_i64();\n    builder.mul_i64();\n\n    let result = builder.tee_new_local_i64();\n    builder.wrap_i64_to_i32();\n    builder.set_local(&dest_operand);\n\n    codegen::gen_set_last_result(builder, &dest_operand);\n    codegen::gen_set_last_op_size(builder, OPSIZE_32);\n    codegen::gen_set_flags_changed(builder, FLAGS_ALL & !1 & !FLAG_OVERFLOW);\n\n    builder.const_i32(global_pointers::flags as i32);\n    builder.get_local_i64(&result);\n    builder.wrap_i64_to_i32();\n    builder.extend_signed_i32_to_i64();\n    builder.get_local_i64(&result);\n    builder.ne_i64();\n    builder.const_i32(1 | FLAG_OVERFLOW);\n    builder.mul_i32();\n    codegen::gen_get_flags(builder);\n    builder.const_i32(!1 & !FLAG_OVERFLOW);\n    builder.and_i32();\n    builder.or_i32();\n    builder.store_aligned_i32(0);\n\n    builder.free_local_i64(result);\n}\n\nfn gen_div32(ctx: &mut JitContext, source: &WasmLocal) {\n    let done = ctx.builder.block_void();\n    {\n        let exception = ctx.builder.block_void();\n        {\n            ctx.builder.get_local(source);\n            ctx.builder.eqz_i32();\n            ctx.builder.br_if(exception);\n\n            codegen::gen_get_reg32(ctx, regs::EDX);\n            ctx.builder.extend_unsigned_i32_to_i64();\n            ctx.builder.const_i64(32);\n            ctx.builder.shl_i64();\n            codegen::gen_get_reg32(ctx, regs::EAX);\n            ctx.builder.extend_unsigned_i32_to_i64();\n            ctx.builder.or_i64();\n            let dest_operand = ctx.builder.tee_new_local_i64();\n\n            ctx.builder.get_local(source);\n            ctx.builder.extend_unsigned_i32_to_i64();\n            ctx.builder.div_i64();\n            let result = ctx.builder.tee_new_local_i64();\n            ctx.builder.const_i64(0xFFFF_FFFF);\n            ctx.builder.gtu_i64();\n            ctx.builder.br_if(exception);\n\n            ctx.builder.get_local_i64(&dest_operand);\n            ctx.builder.get_local(source);\n            ctx.builder.extend_unsigned_i32_to_i64();\n            ctx.builder.rem_i64();\n            ctx.builder.wrap_i64_to_i32();\n            codegen::gen_set_reg32(ctx, regs::EDX);\n\n            ctx.builder.get_local_i64(&result);\n            ctx.builder.wrap_i64_to_i32();\n            codegen::gen_set_reg32(ctx, regs::EAX);\n            ctx.builder.br(done);\n\n            ctx.builder.free_local_i64(dest_operand);\n            ctx.builder.free_local_i64(result);\n        }\n        ctx.builder.block_end();\n\n        codegen::gen_trigger_de(ctx);\n    }\n    ctx.builder.block_end();\n}\n\nfn gen_bt(\n    builder: &mut WasmBuilder,\n    bit_base: &WasmLocal,\n    bit_offset: &LocalOrImmediate,\n    offset_mask: u32,\n) {\n    builder.const_i32(global_pointers::flags as i32);\n    codegen::gen_get_flags(builder);\n    builder.const_i32(!1);\n    builder.and_i32();\n    builder.get_local(bit_base);\n    match bit_offset {\n        LocalOrImmediate::WasmLocal(l) => {\n            builder.get_local(l);\n            builder.const_i32(offset_mask as i32);\n            builder.and_i32();\n        },\n        LocalOrImmediate::Immediate(imm) => builder.const_i32(imm & offset_mask as i32),\n    }\n    builder.shr_u_i32();\n    builder.const_i32(1);\n    builder.and_i32();\n    builder.or_i32();\n    builder.store_aligned_i32(0);\n\n    codegen::gen_clear_flags_changed_bits(builder, 1);\n}\nfn gen_bts(\n    builder: &mut WasmBuilder,\n    dest_bit_base: &WasmLocal,\n    bit_offset: &LocalOrImmediate,\n    offset_mask: u32,\n) {\n    gen_bt(builder, dest_bit_base, bit_offset, offset_mask);\n\n    builder.get_local(dest_bit_base);\n    match bit_offset {\n        LocalOrImmediate::WasmLocal(l) => {\n            builder.const_i32(1);\n            builder.get_local(l);\n            builder.const_i32(offset_mask as i32);\n            builder.and_i32();\n            builder.shl_i32();\n        },\n        LocalOrImmediate::Immediate(imm) => builder.const_i32(1 << (imm & offset_mask as i32)),\n    }\n    builder.or_i32();\n    builder.set_local(dest_bit_base);\n}\nfn gen_btc(\n    builder: &mut WasmBuilder,\n    dest_bit_base: &WasmLocal,\n    bit_offset: &LocalOrImmediate,\n    offset_mask: u32,\n) {\n    gen_bt(builder, dest_bit_base, bit_offset, offset_mask);\n\n    builder.get_local(dest_bit_base);\n    match bit_offset {\n        LocalOrImmediate::WasmLocal(l) => {\n            builder.const_i32(1);\n            builder.get_local(l);\n            builder.const_i32(offset_mask as i32);\n            builder.and_i32();\n            builder.shl_i32();\n        },\n        LocalOrImmediate::Immediate(imm) => builder.const_i32(1 << (imm & offset_mask as i32)),\n    }\n    builder.xor_i32();\n    builder.set_local(dest_bit_base);\n}\nfn gen_btr(\n    builder: &mut WasmBuilder,\n    dest_bit_base: &WasmLocal,\n    bit_offset: &LocalOrImmediate,\n    offset_mask: u32,\n) {\n    gen_bt(builder, dest_bit_base, bit_offset, offset_mask);\n\n    builder.get_local(dest_bit_base);\n    match bit_offset {\n        LocalOrImmediate::WasmLocal(l) => {\n            builder.const_i32(1);\n            builder.get_local(l);\n            builder.const_i32(offset_mask as i32);\n            builder.and_i32();\n            builder.shl_i32();\n            builder.const_i32(-1);\n            builder.xor_i32();\n        },\n        LocalOrImmediate::Immediate(imm) => builder.const_i32(!(1 << (imm & offset_mask as i32))),\n    }\n    builder.and_i32();\n    builder.set_local(dest_bit_base);\n}\n\nfn gen_bit_rmw(\n    ctx: &mut JitContext,\n    modrm_byte: ModrmByte,\n    op: &dyn Fn(&mut WasmBuilder, &WasmLocal, &LocalOrImmediate, u32),\n    source_operand: &LocalOrImmediate,\n    opsize: i32,\n) {\n    dbg_assert!(opsize == 16 || opsize == 32);\n    codegen::gen_modrm_resolve(ctx, modrm_byte);\n    match source_operand {\n        LocalOrImmediate::WasmLocal(l) => {\n            ctx.builder.get_local(l);\n            if opsize == 16 {\n                codegen::sign_extend_i16(ctx.builder);\n            }\n            ctx.builder.const_i32(3);\n            ctx.builder.shr_s_i32();\n            ctx.builder.add_i32();\n        },\n        &LocalOrImmediate::Immediate(imm8) => {\n            let offset = (imm8 as i32 & (opsize - 1)) >> 3;\n            if offset != 0 {\n                ctx.builder.const_i32(offset);\n                ctx.builder.add_i32();\n            }\n        },\n    }\n    let address_local = ctx.builder.set_new_local();\n    codegen::gen_safe_read_write(ctx, BitSize::BYTE, &address_local, &|ref mut ctx| {\n        let value_local = ctx.builder.set_new_local();\n        op(ctx.builder, &value_local, source_operand, 7);\n        ctx.builder.get_local(&value_local);\n        ctx.builder.free_local(value_local);\n    });\n    ctx.builder.free_local(address_local);\n}\n\nfn gen_bsf32(ctx: &mut JitContext, dest_operand: &WasmLocal, source_operand: &LocalOrImmediate) {\n    ctx.builder.get_local(&dest_operand);\n    source_operand.gen_get(ctx.builder);\n    ctx.builder.call_fn2_ret("bsf32");\n    ctx.builder.set_local(dest_operand);\n}\n\nfn gen_bsr32(ctx: &mut JitContext, dest_operand: &WasmLocal, source_operand: &LocalOrImmediate) {\n    ctx.builder.get_local(&dest_operand);\n    source_operand.gen_get(ctx.builder);\n    ctx.builder.call_fn2_ret("bsr32");\n    ctx.builder.set_local(dest_operand);\n}\n\nfn gen_bswap(ctx: &mut JitContext, reg: i32) {\n    let l = &ctx.register_locals[reg as usize];\n\n    ctx.builder.get_local(l);\n    ctx.builder.const_i32(8);\n    ctx.builder.rotl_i32();\n    ctx.builder.const_i32(0xFF00FF);\n    ctx.builder.and_i32();\n\n    ctx.builder.get_local(l);\n    ctx.builder.const_i32(24);\n    ctx.builder.rotl_i32();\n    ctx.builder.const_i32(0xFF00FF00u32 as i32);\n    ctx.builder.and_i32();\n\n    ctx.builder.or_i32();\n\n    ctx.builder.set_local(l);\n}\n\ndefine_instruction_read_write_mem8!(gen_add8, instr_00_mem_jit, instr_00_reg_jit, reg);\ndefine_instruction_read_write_mem16!("add16", instr16_01_mem_jit, instr16_01_reg_jit, reg);\ndefine_instruction_read_write_mem32!(gen_add32, instr32_01_mem_jit, instr32_01_reg_jit, reg);\n\ndefine_instruction_write_reg8!(gen_add8, instr_02_mem_jit, instr_02_reg_jit);\ndefine_instruction_write_reg16!("add16", instr16_03_mem_jit, instr16_03_reg_jit);\ndefine_instruction_write_reg32!(gen_add32, instr32_03_mem_jit, instr32_03_reg_jit);\n\npub fn instr_04_jit(ctx: &mut JitContext, imm8: u32) { group_arith_al_imm8(ctx, &gen_add8, imm8); }\npub fn instr16_05_jit(ctx: &mut JitContext, imm16: u32) {\n    group_arith_ax_imm16(ctx, "add16", imm16);\n}\npub fn instr32_05_jit(ctx: &mut JitContext, imm32: u32) {\n    group_arith_eax_imm32(ctx, &gen_add32, imm32);\n}\n\ndefine_instruction_read_write_mem8!(gen_or8, instr_08_mem_jit, instr_08_reg_jit, reg);\ndefine_instruction_read_write_mem16!("or16", instr16_09_mem_jit, instr16_09_reg_jit, reg);\ndefine_instruction_read_write_mem32!(gen_or32, instr32_09_mem_jit, instr32_09_reg_jit, reg);\n\ndefine_instruction_write_reg8!(gen_or8, instr_0A_mem_jit, instr_0A_reg_jit);\ndefine_instruction_write_reg16!("or16", instr16_0B_mem_jit, instr16_0B_reg_jit);\ndefine_instruction_write_reg32!(gen_or32, instr32_0B_mem_jit, instr32_0B_reg_jit);\n\npub fn instr_0C_jit(ctx: &mut JitContext, imm8: u32) { group_arith_al_imm8(ctx, &gen_or8, imm8); }\npub fn instr16_0D_jit(ctx: &mut JitContext, imm16: u32) {\n    group_arith_ax_imm16(ctx, "or16", imm16);\n}\npub fn instr32_0D_jit(ctx: &mut JitContext, imm32: u32) {\n    group_arith_eax_imm32(ctx, &gen_or32, imm32);\n}\n\ndefine_instruction_read_write_mem8!(gen_adc8, instr_10_mem_jit, instr_10_reg_jit, reg);\ndefine_instruction_read_write_mem16!("adc16", instr16_11_mem_jit, instr16_11_reg_jit, reg);\ndefine_instruction_read_write_mem32!(gen_adc32, instr32_11_mem_jit, instr32_11_reg_jit, reg);\n\ndefine_instruction_write_reg8!(gen_adc8, instr_12_mem_jit, instr_12_reg_jit);\ndefine_instruction_write_reg16!("adc16", instr16_13_mem_jit, instr16_13_reg_jit);\ndefine_instruction_write_reg32!(gen_adc32, instr32_13_mem_jit, instr32_13_reg_jit);\n\npub fn instr_14_jit(ctx: &mut JitContext, imm8: u32) { group_arith_al_imm8(ctx, &gen_adc8, imm8); }\npub fn instr16_15_jit(ctx: &mut JitContext, imm16: u32) {\n    group_arith_ax_imm16(ctx, "adc16", imm16);\n}\npub fn instr32_15_jit(ctx: &mut JitContext, imm32: u32) {\n    group_arith_eax_imm32(ctx, &gen_adc32, imm32);\n}\n\ndefine_instruction_read_write_mem8!(gen_sbb8, instr_18_mem_jit, instr_18_reg_jit, reg);\ndefine_instruction_read_write_mem16!("sbb16", instr16_19_mem_jit, instr16_19_reg_jit, reg);\ndefine_instruction_read_write_mem32!(gen_sbb32, instr32_19_mem_jit, instr32_19_reg_jit, reg);\n\ndefine_instruction_write_reg8!(gen_sbb8, instr_1A_mem_jit, instr_1A_reg_jit);\ndefine_instruction_write_reg16!("sbb16", instr16_1B_mem_jit, instr16_1B_reg_jit);\ndefine_instruction_write_reg32!(gen_sbb32, instr32_1B_mem_jit, instr32_1B_reg_jit);\n\npub fn instr_1C_jit(ctx: &mut JitContext, imm8: u32) { group_arith_al_imm8(ctx, &gen_sbb8, imm8); }\npub fn instr16_1D_jit(ctx: &mut JitContext, imm16: u32) {\n    group_arith_ax_imm16(ctx, "sbb16", imm16);\n}\npub fn instr32_1D_jit(ctx: &mut JitContext, imm32: u32) {\n    group_arith_eax_imm32(ctx, &gen_sbb32, imm32);\n}\n\ndefine_instruction_read_write_mem8!(gen_and8, instr_20_mem_jit, instr_20_reg_jit, reg);\ndefine_instruction_read_write_mem16!("and16", instr16_21_mem_jit, instr16_21_reg_jit, reg);\ndefine_instruction_read_write_mem32!(gen_and32, instr32_21_mem_jit, instr32_21_reg_jit, reg);\n\ndefine_instruction_write_reg8!(gen_and8, instr_22_mem_jit, instr_22_reg_jit);\ndefine_instruction_write_reg16!("and16", instr16_23_mem_jit, instr16_23_reg_jit);\ndefine_instruction_write_reg32!(gen_and32, instr32_23_mem_jit, instr32_23_reg_jit);\n\npub fn instr_24_jit(ctx: &mut JitContext, imm8: u32) { group_arith_al_imm8(ctx, &gen_and8, imm8); }\npub fn instr16_25_jit(ctx: &mut JitContext, imm16: u32) {\n    group_arith_ax_imm16(ctx, "and16", imm16);\n}\npub fn instr32_25_jit(ctx: &mut JitContext, imm32: u32) {\n    group_arith_eax_imm32(ctx, &gen_and32, imm32);\n}\n\ndefine_instruction_read_write_mem8!(gen_sub8, instr_28_mem_jit, instr_28_reg_jit, reg);\ndefine_instruction_read_write_mem16!("sub16", instr16_29_mem_jit, instr16_29_reg_jit, reg);\ndefine_instruction_read_write_mem32!(gen_sub32, instr32_29_mem_jit, instr32_29_reg_jit, reg);\n\ndefine_instruction_write_reg8!(gen_sub8, instr_2A_mem_jit, instr_2A_reg_jit);\ndefine_instruction_write_reg16!("sub16", instr16_2B_mem_jit, instr16_2B_reg_jit);\ndefine_instruction_write_reg32!(gen_sub32, instr32_2B_mem_jit, instr32_2B_reg_jit);\n\npub fn instr_2C_jit(ctx: &mut JitContext, imm8: u32) { group_arith_al_imm8(ctx, &gen_sub8, imm8); }\npub fn instr16_2D_jit(ctx: &mut JitContext, imm16: u32) {\n    group_arith_ax_imm16(ctx, "sub16", imm16);\n}\npub fn instr32_2D_jit(ctx: &mut JitContext, imm32: u32) {\n    group_arith_eax_imm32(ctx, &gen_sub32, imm32);\n}\n\ndefine_instruction_read_write_mem8!(gen_xor8, instr_30_mem_jit, instr_30_reg_jit, reg);\ndefine_instruction_read_write_mem16!("xor16", instr16_31_mem_jit, instr16_31_reg_jit, reg);\ndefine_instruction_read_write_mem32!(gen_xor32, instr32_31_mem_jit, instr32_31_reg_jit, reg);\n\ndefine_instruction_write_reg8!(gen_xor8, instr_32_mem_jit, instr_32_reg_jit);\ndefine_instruction_write_reg16!("xor16", instr16_33_mem_jit, instr16_33_reg_jit);\ndefine_instruction_write_reg32!(gen_xor32, instr32_33_mem_jit, instr32_33_reg_jit);\n\npub fn instr_34_jit(ctx: &mut JitContext, imm8: u32) { group_arith_al_imm8(ctx, &gen_xor8, imm8); }\npub fn instr16_35_jit(ctx: &mut JitContext, imm16: u32) {\n    group_arith_ax_imm16(ctx, "xor16", imm16);\n}\npub fn instr32_35_jit(ctx: &mut JitContext, imm32: u32) {\n    group_arith_eax_imm32(ctx, &gen_xor32, imm32);\n}\n\ndefine_instruction_read8!(gen_cmp8, instr_38_mem_jit, instr_38_reg_jit);\ndefine_instruction_read16!(gen_cmp16, instr16_39_mem_jit, instr16_39_reg_jit);\ndefine_instruction_read32!(gen_cmp32, instr32_39_mem_jit, instr32_39_reg_jit);\n\npub fn instr_3A_mem_jit(ctx: &mut JitContext, modrm_byte: ModrmByte, r: u32) {\n    let dest_operand = codegen::gen_get_reg8_or_alias_to_reg32(ctx, r);\n    codegen::gen_modrm_resolve_safe_read8(ctx, modrm_byte);\n    let source_operand = ctx.builder.set_new_local();\n    gen_cmp8(\n        ctx,\n        &dest_operand,\n        &LocalOrImmediate::WasmLocal(&source_operand),\n    );\n    codegen::gen_free_reg8_or_alias(ctx, r, dest_operand);\n    ctx.builder.free_local(source_operand);\n}\n\npub fn instr_3A_reg_jit(ctx: &mut JitContext, r1: u32, r2: u32) {\n    let dest_operand = codegen::gen_get_reg8_or_alias_to_reg32(ctx, r2);\n    let source_operand = codegen::gen_get_reg8_or_alias_to_reg32(ctx, r1);\n    gen_cmp8(\n        ctx,\n        &dest_operand,\n        &LocalOrImmediate::WasmLocal(&source_operand),\n    );\n    codegen::gen_free_reg8_or_alias(ctx, r2, dest_operand);\n    codegen::gen_free_reg8_or_alias(ctx, r1, source_operand);\n}\n\npub fn instr16_3B_mem_jit(ctx: &mut JitContext, modrm_byte: ModrmByte, r: u32) {\n    codegen::gen_modrm_resolve_safe_read16(ctx, modrm_byte);\n    let source_operand = ctx.builder.set_new_local();\n    gen_cmp16(\n        ctx,\n        &ctx.reg(r),\n        &LocalOrImmediate::WasmLocal(&source_operand),\n    );\n    ctx.builder.free_local(source_operand);\n}\n\npub fn instr16_3B_reg_jit(ctx: &mut JitContext, r1: u32, r2: u32) {\n    gen_cmp16(\n        ctx,\n        &ctx.reg(r2),\n        &LocalOrImmediate::WasmLocal(&ctx.reg(r1)),\n    );\n}\n\npub fn instr32_3B_mem_jit(ctx: &mut JitContext, modrm_byte: ModrmByte, r: u32) {\n    codegen::gen_modrm_resolve_safe_read32(ctx, modrm_byte);\n    let source_operand = ctx.builder.set_new_local();\n    gen_cmp32(\n        ctx,\n        &ctx.reg(r),\n        &LocalOrImmediate::WasmLocal(&source_operand),\n    );\n    ctx.builder.free_local(source_operand);\n}\n\npub fn instr32_3B_reg_jit(ctx: &mut JitContext, r1: u32, r2: u32) {\n    gen_cmp32(\n        ctx,\n        &ctx.reg(r2),\n        &LocalOrImmediate::WasmLocal(&ctx.reg(r1)),\n    );\n}\n\npub fn instr_3C_jit(ctx: &mut JitContext, imm8: u32) {\n    gen_cmp8(ctx, &ctx.reg(0), &LocalOrImmediate::Immediate(imm8 as i32));\n}\n\npub fn instr16_3D_jit(ctx: &mut JitContext, imm16: u32) {\n    gen_cmp16(ctx, &ctx.reg(0), &LocalOrImmediate::Immediate(imm16 as i32));\n}\n\npub fn instr32_3D_jit(ctx: &mut JitContext, imm32: u32) {\n    gen_cmp32(ctx, &ctx.reg(0), &LocalOrImmediate::Immediate(imm32 as i32));\n}\n\nfn gen_inc(ctx: &mut JitContext, dest_operand: &WasmLocal, size: i32) {\n    ctx.current_instruction = Instruction::Arithmetic { opsize: size };\n\n    let builder = &mut ctx.builder;\n    builder.const_i32(global_pointers::flags as i32);\n    codegen::gen_get_flags(builder);\n    builder.const_i32(!1);\n    builder.and_i32();\n    codegen::gen_getcf_unoptimised(builder);\n    builder.or_i32();\n    builder.store_aligned_i32(0);\n\n    builder.const_i32(global_pointers::last_op1 as i32);\n    builder.get_local(&dest_operand);\n    if size == OPSIZE_8 || size == OPSIZE_16 {\n        builder.const_i32(if size == OPSIZE_8 { 0xFF } else { 0xFFFF });\n        builder.and_i32();\n    }\n    builder.store_aligned_i32(0);\n\n    builder.get_local(dest_operand);\n    builder.const_i32(1);\n    builder.add_i32();\n    if size == OPSIZE_16 {\n        codegen::gen_set_reg16_local(builder, dest_operand);\n    }\n    else {\n        builder.set_local(dest_operand);\n    }\n\n    builder.const_i32(global_pointers::last_result as i32);\n    builder.get_local(&dest_operand);\n    if size == OPSIZE_16 {\n        builder.const_i32(0xFFFF);\n        builder.and_i32();\n    }\n    builder.store_aligned_i32(0);\n    codegen::gen_set_last_op_size(builder, size);\n    codegen::gen_set_flags_changed(builder, FLAGS_ALL & !1);\n}\nfn gen_inc16(ctx: &mut JitContext, dest_operand: &WasmLocal) {\n    gen_inc(ctx, dest_operand, OPSIZE_16);\n}\nfn gen_inc32(ctx: &mut JitContext, dest_operand: &WasmLocal) {\n    gen_inc(ctx, dest_operand, OPSIZE_32);\n}\n\nfn gen_dec(ctx: &mut JitContext, dest_operand: &WasmLocal, size: i32) {\n    ctx.current_instruction = Instruction::Arithmetic { opsize: size };\n\n    let builder = &mut ctx.builder;\n    builder.const_i32(global_pointers::flags as i32);\n    codegen::gen_get_flags(builder);\n    builder.const_i32(!1);\n    builder.and_i32();\n    codegen::gen_getcf_unoptimised(builder);\n    builder.or_i32();\n    builder.store_aligned_i32(0);\n\n    builder.const_i32(global_pointers::last_op1 as i32);\n    builder.get_local(&dest_operand);\n    if size == OPSIZE_8 || size == OPSIZE_16 {\n        builder.const_i32(if size == OPSIZE_8 { 0xFF } else { 0xFFFF });\n        builder.and_i32();\n    }\n    builder.store_aligned_i32(0);\n\n    builder.get_local(dest_operand);\n    builder.const_i32(1);\n    builder.sub_i32();\n    if size == OPSIZE_16 {\n        codegen::gen_set_reg16_local(builder, dest_operand);\n    }\n    else {\n        builder.set_local(dest_operand);\n    }\n\n    builder.const_i32(global_pointers::last_result as i32);\n    builder.get_local(&dest_operand);\n    if size == OPSIZE_16 {\n        builder.const_i32(0xFFFF);\n        builder.and_i32();\n    }\n    builder.store_aligned_i32(0);\n    codegen::gen_set_last_op_size(builder, size);\n    codegen::gen_set_flags_changed(builder, FLAGS_ALL & !1 | FLAG_SUB);\n}\nfn gen_dec16(ctx: &mut JitContext, dest_operand: &WasmLocal) {\n    gen_dec(ctx, dest_operand, OPSIZE_16)\n}\nfn gen_dec32(ctx: &mut JitContext, dest_operand: &WasmLocal) {\n    gen_dec(ctx, dest_operand, OPSIZE_32)\n}\n\nfn gen_inc16_r(ctx: &mut JitContext, r: u32) { gen_inc16(ctx, &mut ctx.reg(r)) }\nfn gen_inc32_r(ctx: &mut JitContext, r: u32) { gen_inc32(ctx, &mut ctx.reg(r)) }\nfn gen_dec16_r(ctx: &mut JitContext, r: u32) { gen_dec16(ctx, &mut ctx.reg(r)) }\nfn gen_dec32_r(ctx: &mut JitContext, r: u32) { gen_dec32(ctx, &mut ctx.reg(r)) }\n\nfn gen_not16(ctx: &mut JitContext, dest_operand: &WasmLocal) {\n    let builder = &mut ctx.builder;\n    builder.get_local(dest_operand);\n    builder.const_i32(-1);\n    builder.xor_i32();\n    codegen::gen_set_reg16_local(builder, dest_operand);\n}\nfn gen_not32(ctx: &mut JitContext, dest_operand: &WasmLocal) {\n    let builder = &mut ctx.builder;\n    builder.get_local(dest_operand);\n    builder.const_i32(-1);\n    builder.xor_i32();\n    builder.set_local(dest_operand);\n}\n\nfn gen_neg16(ctx: &mut JitContext, dest_operand: &WasmLocal) {\n    let builder = &mut ctx.builder;\n    builder.get_local(dest_operand);\n    builder.call_fn1_ret("neg16");\n    codegen::gen_set_reg16_local(builder, dest_operand);\n}\nfn gen_neg32(ctx: &mut JitContext, dest_operand: &WasmLocal) {\n    let builder = &mut ctx.builder;\n    builder.const_i32(global_pointers::last_op1 as i32);\n    builder.const_i32(0);\n    builder.store_aligned_i32(0);\n\n    builder.const_i32(0);\n    builder.get_local(&dest_operand);\n    builder.sub_i32();\n    builder.set_local(dest_operand);\n\n    codegen::gen_set_last_result(builder, &dest_operand);\n    codegen::gen_set_last_op_size(builder, OPSIZE_32);\n    codegen::gen_set_flags_changed(builder, FLAGS_ALL | FLAG_SUB);\n}\n\npub fn instr16_06_jit(ctx: &mut JitContext) {\n    codegen::gen_get_sreg(ctx, regs::ES);\n    let sreg = ctx.builder.set_new_local();\n    codegen::gen_push16(ctx, &sreg);\n    ctx.builder.free_local(sreg);\n}\npub fn instr32_06_jit(ctx: &mut JitContext) {\n    codegen::gen_get_sreg(ctx, regs::ES);\n    let sreg = ctx.builder.set_new_local();\n    codegen::gen_push32(ctx, &sreg);\n    ctx.builder.free_local(sreg);\n}\n\npub fn instr16_0E_jit(ctx: &mut JitContext) {\n    codegen::gen_get_sreg(ctx, regs::CS);\n    let sreg = ctx.builder.set_new_local();\n    codegen::gen_push16(ctx, &sreg);\n    ctx.builder.free_local(sreg);\n}\npub fn instr32_0E_jit(ctx: &mut JitContext) {\n    codegen::gen_get_sreg(ctx, regs::CS);\n    let sreg = ctx.builder.set_new_local();\n    codegen::gen_push32(ctx, &sreg);\n    ctx.builder.free_local(sreg);\n}\n\npub fn instr16_16_jit(ctx: &mut JitContext) {\n    codegen::gen_get_sreg(ctx, regs::SS);\n    let sreg = ctx.builder.set_new_local();\n    codegen::gen_push16(ctx, &sreg);\n    ctx.builder.free_local(sreg);\n}\npub fn instr32_16_jit(ctx: &mut JitContext) {\n    codegen::gen_get_sreg(ctx, regs::SS);\n    let sreg = ctx.builder.set_new_local();\n    codegen::gen_push32(ctx, &sreg);\n    ctx.builder.free_local(sreg);\n}\n\npub fn instr16_1E_jit(ctx: &mut JitContext) {\n    codegen::gen_get_sreg(ctx, regs::DS);\n    let sreg = ctx.builder.set_new_local();\n    codegen::gen_push16(ctx, &sreg);\n    ctx.builder.free_local(sreg);\n}\npub fn instr32_1E_jit(ctx: &mut JitContext) {\n    codegen::gen_get_sreg(ctx, regs::DS);\n    let sreg = ctx.builder.set_new_local();\n    codegen::gen_push32(ctx, &sreg);\n    ctx.builder.free_local(sreg);\n}\n\npub fn instr16_40_jit(ctx: &mut JitContext) { gen_inc16_r(ctx, AX); }\npub fn instr32_40_jit(ctx: &mut JitContext) { gen_inc32_r(ctx, EAX); }\npub fn instr16_41_jit(ctx: &mut JitContext) { gen_inc16_r(ctx, CX); }\npub fn instr32_41_jit(ctx: &mut JitContext) { gen_inc32_r(ctx, ECX); }\npub fn instr16_42_jit(ctx: &mut JitContext) { gen_inc16_r(ctx, DX); }\npub fn instr32_42_jit(ctx: &mut JitContext) { gen_inc32_r(ctx, EDX); }\npub fn instr16_43_jit(ctx: &mut JitContext) { gen_inc16_r(ctx, BX); }\npub fn instr32_43_jit(ctx: &mut JitContext) { gen_inc32_r(ctx, EBX); }\npub fn instr16_44_jit(ctx: &mut JitContext) { gen_inc16_r(ctx, SP); }\npub fn instr32_44_jit(ctx: &mut JitContext) { gen_inc32_r(ctx, ESP); }\npub fn instr16_45_jit(ctx: &mut JitContext) { gen_inc16_r(ctx, BP); }\npub fn instr32_45_jit(ctx: &mut JitContext) { gen_inc32_r(ctx, EBP); }\npub fn instr16_46_jit(ctx: &mut JitContext) { gen_inc16_r(ctx, SI); }\npub fn instr32_46_jit(ctx: &mut JitContext) { gen_inc32_r(ctx, ESI); }\npub fn instr16_47_jit(ctx: &mut JitContext) { gen_inc16_r(ctx, DI); }\npub fn instr32_47_jit(ctx: &mut JitContext) { gen_inc32_r(ctx, EDI); }\n\npub fn instr16_48_jit(ctx: &mut JitContext) { gen_dec16_r(ctx, AX); }\npub fn instr32_48_jit(ctx: &mut JitContext) { gen_dec32_r(ctx, EAX); }\npub fn instr16_49_jit(ctx: &mut JitContext) { gen_dec16_r(ctx, CX); }\npub fn instr32_49_jit(ctx: &mut JitContext) { gen_dec32_r(ctx, ECX); }\npub fn instr16_4A_jit(ctx: &mut JitContext) { gen_dec16_r(ctx, DX); }\npub fn instr32_4A_jit(ctx: &mut JitContext) { gen_dec32_r(ctx, EDX); }\npub fn instr16_4B_jit(ctx: &mut JitContext) { gen_dec16_r(ctx, BX); }\npub fn instr32_4B_jit(ctx: &mut JitContext) { gen_dec32_r(ctx, EBX); }\npub fn instr16_4C_jit(ctx: &mut JitContext) { gen_dec16_r(ctx, SP); }\npub fn instr32_4C_jit(ctx: &mut JitContext) { gen_dec32_r(ctx, ESP); }\npub fn instr16_4D_jit(ctx: &mut JitContext) { gen_dec16_r(ctx, BP); }\npub fn instr32_4D_jit(ctx: &mut JitContext) { gen_dec32_r(ctx, EBP); }\npub fn instr16_4E_jit(ctx: &mut JitContext) { gen_dec16_r(ctx, SI); }\npub fn instr32_4E_jit(ctx: &mut JitContext) { gen_dec32_r(ctx, ESI); }\npub fn instr16_4F_jit(ctx: &mut JitContext) { gen_dec16_r(ctx, DI); }\npub fn instr32_4F_jit(ctx: &mut JitContext) { gen_dec32_r(ctx, EDI); }\n\npub fn instr16_50_jit(ctx: &mut JitContext) { push16_reg_jit(ctx, AX); }\npub fn instr32_50_jit(ctx: &mut JitContext) { push32_reg_jit(ctx, EAX); }\npub fn instr16_51_jit(ctx: &mut JitContext) { push16_reg_jit(ctx, CX); }\npub fn instr32_51_jit(ctx: &mut JitContext) { push32_reg_jit(ctx, ECX); }\npub fn instr16_52_jit(ctx: &mut JitContext) { push16_reg_jit(ctx, DX); }\npub fn instr32_52_jit(ctx: &mut JitContext) { push32_reg_jit(ctx, EDX); }\npub fn instr16_53_jit(ctx: &mut JitContext) { push16_reg_jit(ctx, BX); }\npub fn instr32_53_jit(ctx: &mut JitContext) { push32_reg_jit(ctx, EBX); }\npub fn instr16_54_jit(ctx: &mut JitContext) { push16_reg_jit(ctx, SP); }\npub fn instr32_54_jit(ctx: &mut JitContext) { push32_reg_jit(ctx, ESP); }\npub fn instr16_55_jit(ctx: &mut JitContext) { push16_reg_jit(ctx, BP); }\npub fn instr32_55_jit(ctx: &mut JitContext) { push32_reg_jit(ctx, EBP); }\npub fn instr16_56_jit(ctx: &mut JitContext) { push16_reg_jit(ctx, SI); }\npub fn instr32_56_jit(ctx: &mut JitContext) { push32_reg_jit(ctx, ESI); }\npub fn instr16_57_jit(ctx: &mut JitContext) { push16_reg_jit(ctx, DI); }\npub fn instr32_57_jit(ctx: &mut JitContext) { push32_reg_jit(ctx, EDI); }\n\npub fn instr16_58_jit(ctx: &mut JitContext) { pop16_reg_jit(ctx, AX); }\npub fn instr32_58_jit(ctx: &mut JitContext) { pop32_reg_jit(ctx, EAX); }\npub fn instr16_59_jit(ctx: &mut JitContext) { pop16_reg_jit(ctx, CX); }\npub fn instr32_59_jit(ctx: &mut JitContext) { pop32_reg_jit(ctx, ECX); }\npub fn instr16_5A_jit(ctx: &mut JitContext) { pop16_reg_jit(ctx, DX); }\npub fn instr32_5A_jit(ctx: &mut JitContext) { pop32_reg_jit(ctx, EDX); }\npub fn instr16_5B_jit(ctx: &mut JitContext) { pop16_reg_jit(ctx, BX); }\npub fn instr32_5B_jit(ctx: &mut JitContext) { pop32_reg_jit(ctx, EBX); }\npub fn instr16_5C_jit(ctx: &mut JitContext) { pop16_reg_jit(ctx, SP); }\npub fn instr32_5C_jit(ctx: &mut JitContext) { pop32_reg_jit(ctx, ESP); }\npub fn instr16_5D_jit(ctx: &mut JitContext) { pop16_reg_jit(ctx, BP); }\npub fn instr32_5D_jit(ctx: &mut JitContext) { pop32_reg_jit(ctx, EBP); }\npub fn instr16_5E_jit(ctx: &mut JitContext) { pop16_reg_jit(ctx, SI); }\npub fn instr32_5E_jit(ctx: &mut JitContext) { pop32_reg_jit(ctx, ESI); }\npub fn instr16_5F_jit(ctx: &mut JitContext) { pop16_reg_jit(ctx, DI); }\npub fn instr32_5F_jit(ctx: &mut JitContext) { pop32_reg_jit(ctx, EDI); }\n\npub fn instr16_68_jit(ctx: &mut JitContext, imm16: u32) { push16_imm_jit(ctx, imm16) }\npub fn instr32_68_jit(ctx: &mut JitContext, imm32: u32) { push32_imm_jit(ctx, imm32) }\npub fn instr16_6A_jit(ctx: &mut JitContext, imm16: u32) { push16_imm_jit(ctx, imm16) }\npub fn instr32_6A_jit(ctx: &mut JitContext, imm32: u32) { push32_imm_jit(ctx, imm32) }\n\npub fn instr16_69_mem_jit(ctx: &mut JitContext, modrm_byte: ModrmByte, r: u32, imm16: u32) {\n    codegen::gen_modrm_resolve_safe_read16(ctx, modrm_byte);\n    ctx.builder.const_i32(imm16 as i32);\n    ctx.builder.call_fn2_ret("imul_reg16");\n    codegen::gen_set_reg16(ctx, r);\n}\npub fn instr16_69_reg_jit(ctx: &mut JitContext, r1: u32, r2: u32, imm16: u32) {\n    codegen::gen_get_reg16(ctx, r1);\n    ctx.builder.const_i32(imm16 as i32);\n    ctx.builder.call_fn2_ret("imul_reg16");\n    codegen::gen_set_reg16(ctx, r2);\n}\n\npub fn instr32_69_mem_jit(ctx: &mut JitContext, modrm_byte: ModrmByte, r: u32, imm32: u32) {\n    codegen::gen_modrm_resolve_safe_read32(ctx, modrm_byte);\n    let value_local = ctx.builder.set_new_local();\n    gen_imul3_reg32(\n        ctx.builder,\n        &ctx.register_locals[r as usize],\n        &value_local,\n        &LocalOrImmediate::Immediate(imm32 as i32),\n    );\n    ctx.builder.free_local(value_local);\n}\npub fn instr32_69_reg_jit(ctx: &mut JitContext, r1: u32, r2: u32, imm32: u32) {\n    gen_imul3_reg32(\n        ctx.builder,\n        &ctx.register_locals[r2 as usize],\n        &ctx.register_locals[r1 as usize],\n        &LocalOrImmediate::Immediate(imm32 as i32),\n    );\n}\n\npub fn instr16_6B_mem_jit(ctx: &mut JitContext, modrm_byte: ModrmByte, r: u32, imm8s: u32) {\n    codegen::gen_modrm_resolve_safe_read16(ctx, modrm_byte);\n    ctx.builder.const_i32(imm8s as i32);\n    ctx.builder.call_fn2_ret("imul_reg16");\n    codegen::gen_set_reg16(ctx, r);\n}\npub fn instr16_6B_reg_jit(ctx: &mut JitContext, r1: u32, r2: u32, imm8s: u32) {\n    codegen::gen_get_reg16(ctx, r1);\n    ctx.builder.const_i32(imm8s as i32);\n    ctx.builder.call_fn2_ret("imul_reg16");\n    codegen::gen_set_reg16(ctx, r2);\n}\n\npub fn instr32_6B_mem_jit(ctx: &mut JitContext, modrm_byte: ModrmByte, r: u32, imm8s: u32) {\n    codegen::gen_modrm_resolve_safe_read32(ctx, modrm_byte);\n    let value_local = ctx.builder.set_new_local();\n    gen_imul3_reg32(\n        ctx.builder,\n        &ctx.register_locals[r as usize],\n        &value_local,\n        &LocalOrImmediate::Immediate(imm8s as i32),\n    );\n    ctx.builder.free_local(value_local);\n}\npub fn instr32_6B_reg_jit(ctx: &mut JitContext, r1: u32, r2: u32, imm8s: u32) {\n    gen_imul3_reg32(\n        ctx.builder,\n        &ctx.register_locals[r2 as usize],\n        &ctx.register_locals[r1 as usize],\n        &LocalOrImmediate::Immediate(imm8s as i32),\n    );\n}\n\n// Code for conditional jumps is generated automatically by the basic block codegen\npub fn instr16_70_jit(_ctx: &mut JitContext, _imm: u32) {}\npub fn instr32_70_jit(_ctx: &mut JitContext, _imm: u32) {}\npub fn instr16_71_jit(_ctx: &mut JitContext, _imm: u32) {}\npub fn instr32_71_jit(_ctx: &mut JitContext, _imm: u32) {}\npub fn instr16_72_jit(_ctx: &mut JitContext, _imm: u32) {}\npub fn instr32_72_jit(_ctx: &mut JitContext, _imm: u32) {}\npub fn instr16_73_jit(_ctx: &mut JitContext, _imm: u32) {}\npub fn instr32_73_jit(_ctx: &mut JitContext, _imm: u32) {}\npub fn instr16_74_jit(_ctx: &mut JitContext, _imm: u32) {}\npub fn instr32_74_jit(_ctx: &mut JitContext, _imm: u32) {}\npub fn instr16_75_jit(_ctx: &mut JitContext, _imm: u32) {}\npub fn instr32_75_jit(_ctx: &mut JitContext, _imm: u32) {}\npub fn instr16_76_jit(_ctx: &mut JitContext, _imm: u32) {}\npub fn instr32_76_jit(_ctx: &mut JitContext, _imm: u32) {}\npub fn instr16_77_jit(_ctx: &mut JitContext, _imm: u32) {}\npub fn instr32_77_jit(_ctx: &mut JitContext, _imm: u32) {}\npub fn instr16_78_jit(_ctx: &mut JitContext, _imm: u32) {}\npub fn instr32_78_jit(_ctx: &mut JitContext, _imm: u32) {}\npub fn instr16_79_jit(_ctx: &mut JitContext, _imm: u32) {}\npub fn instr32_79_jit(_ctx: &mut JitContext, _imm: u32) {}\npub fn instr16_7A_jit(_ctx: &mut JitContext, _imm: u32) {}\npub fn instr32_7A_jit(_ctx: &mut JitContext, _imm: u32) {}\npub fn instr16_7B_jit(_ctx: &mut JitContext, _imm: u32) {}\npub fn instr32_7B_jit(_ctx: &mut JitContext, _imm: u32) {}\npub fn instr16_7C_jit(_ctx: &mut JitContext, _imm: u32) {}\npub fn instr32_7C_jit(_ctx: &mut JitContext, _imm: u32) {}\npub fn instr16_7D_jit(_ctx: &mut JitContext, _imm: u32) {}\npub fn instr32_7D_jit(_ctx: &mut JitContext, _imm: u32) {}\npub fn instr16_7E_jit(_ctx: &mut JitContext, _imm: u32) {}\npub fn instr32_7E_jit(_ctx: &mut JitContext, _imm: u32) {}\npub fn instr16_7F_jit(_ctx: &mut JitContext, _imm: u32) {}\npub fn instr32_7F_jit(_ctx: &mut JitContext, _imm: u32) {}\n\n// loop/loopz/loopnz/jcxz: Conditional jump is generated in main loop\npub fn instr16_E0_jit(ctx: &mut JitContext, _imm: u32) { codegen::decr_exc_asize(ctx) }\npub fn instr32_E0_jit(ctx: &mut JitContext, _imm: u32) { codegen::decr_exc_asize(ctx) }\npub fn instr16_E1_jit(ctx: &mut JitContext, _imm: u32) { codegen::decr_exc_asize(ctx) }\npub fn instr32_E1_jit(ctx: &mut JitContext, _imm: u32) { codegen::decr_exc_asize(ctx) }\npub fn instr16_E2_jit(ctx: &mut JitContext, _imm: u32) { codegen::decr_exc_asize(ctx) }\npub fn instr32_E2_jit(ctx: &mut JitContext, _imm: u32) { codegen::decr_exc_asize(ctx) }\npub fn instr16_E3_jit(_ctx: &mut JitContext, _imm: u32) {}\npub fn instr32_E3_jit(_ctx: &mut JitContext, _imm: u32) {}\n\ndefine_instruction_read_write_mem8!(gen_add8, instr_80_0_mem_jit, instr_80_0_reg_jit, ximm8);\ndefine_instruction_read_write_mem8!(gen_or8, instr_80_1_mem_jit, instr_80_1_reg_jit, ximm8);\ndefine_instruction_read_write_mem8!(gen_adc8, instr_80_2_mem_jit, instr_80_2_reg_jit, ximm8);\ndefine_instruction_read_write_mem8!(gen_sbb8, instr_80_3_mem_jit, instr_80_3_reg_jit, ximm8);\ndefine_instruction_read_write_mem8!(gen_and8, instr_80_4_mem_jit, instr_80_4_reg_jit, ximm8);\ndefine_instruction_read_write_mem8!(gen_sub8, instr_80_5_mem_jit, instr_80_5_reg_jit, ximm8);\ndefine_instruction_read_write_mem8!(gen_xor8, instr_80_6_mem_jit, instr_80_6_reg_jit, ximm8);\n\ndefine_instruction_read_write_mem8!(gen_add8, instr_82_0_mem_jit, instr_82_0_reg_jit, ximm8);\ndefine_instruction_read_write_mem8!(gen_or8, instr_82_1_mem_jit, instr_82_1_reg_jit, ximm8);\ndefine_instruction_read_write_mem8!(gen_adc8, instr_82_2_mem_jit, instr_82_2_reg_jit, ximm8);\ndefine_instruction_read_write_mem8!(gen_sbb8, instr_82_3_mem_jit, instr_82_3_reg_jit, ximm8);\ndefine_instruction_read_write_mem8!(gen_and8, instr_82_4_mem_jit, instr_82_4_reg_jit, ximm8);\ndefine_instruction_read_write_mem8!(gen_sub8, instr_82_5_mem_jit, instr_82_5_reg_jit, ximm8);\ndefine_instruction_read_write_mem8!(gen_xor8, instr_82_6_mem_jit, instr_82_6_reg_jit, ximm8);\n\ndefine_instruction_read_write_mem16!("add16", instr16_81_0_mem_jit, instr16_81_0_reg_jit, imm16);\ndefine_instruction_read_write_mem32!(gen_add32, instr32_81_0_mem_jit, instr32_81_0_reg_jit, imm32);\n\ndefine_instruction_read_write_mem16!("or16", instr16_81_1_mem_jit, instr16_81_1_reg_jit, imm16);\ndefine_instruction_read_write_mem32!(gen_or32, instr32_81_1_mem_jit, instr32_81_1_reg_jit, imm32);\n\ndefine_instruction_read_write_mem16!("adc16", instr16_81_2_mem_jit, instr16_81_2_reg_jit, imm16);\ndefine_instruction_read_write_mem32!(gen_adc32, instr32_81_2_mem_jit, instr32_81_2_reg_jit, imm32);\n\ndefine_instruction_read_write_mem16!("sbb16", instr16_81_3_mem_jit, instr16_81_3_reg_jit, imm16);\ndefine_instruction_read_write_mem32!(gen_sbb32, instr32_81_3_mem_jit, instr32_81_3_reg_jit, imm32);\n\ndefine_instruction_read_write_mem16!("and16", instr16_81_4_mem_jit, instr16_81_4_reg_jit, imm16);\ndefine_instruction_read_write_mem32!(gen_and32, instr32_81_4_mem_jit, instr32_81_4_reg_jit, imm32);\n\ndefine_instruction_read_write_mem16!("sub16", instr16_81_5_mem_jit, instr16_81_5_reg_jit, imm16);\ndefine_instruction_read_write_mem32!(gen_sub32, instr32_81_5_mem_jit, instr32_81_5_reg_jit, imm32);\n\ndefine_instruction_read_write_mem16!("xor16", instr16_81_6_mem_jit, instr16_81_6_reg_jit, imm16);\ndefine_instruction_read_write_mem32!(gen_xor32, instr32_81_6_mem_jit, instr32_81_6_reg_jit, imm32);\n\ndefine_instruction_read_write_mem16!(\n    "add16",\n    instr16_83_0_mem_jit,\n    instr16_83_0_reg_jit,\n    imm8s_16bits\n);\ndefine_instruction_read_write_mem32!(gen_add32, instr32_83_0_mem_jit, instr32_83_0_reg_jit, imm8s);\n\ndefine_instruction_read_write_mem16!(\n    "or16",\n    instr16_83_1_mem_jit,\n    instr16_83_1_reg_jit,\n    imm8s_16bits\n);\ndefine_instruction_read_write_mem32!(gen_or32, instr32_83_1_mem_jit, instr32_83_1_reg_jit, imm8s);\n\ndefine_instruction_read_write_mem16!(\n    "adc16",\n    instr16_83_2_mem_jit,\n    instr16_83_2_reg_jit,\n    imm8s_16bits\n);\ndefine_instruction_read_write_mem32!(gen_adc32, instr32_83_2_mem_jit, instr32_83_2_reg_jit, imm8s);\n\ndefine_instruction_read_write_mem16!(\n    "sbb16",\n    instr16_83_3_mem_jit,\n    instr16_83_3_reg_jit,\n    imm8s_16bits\n);\ndefine_instruction_read_write_mem32!(gen_sbb32, instr32_83_3_mem_jit, instr32_83_3_reg_jit, imm8s);\n\ndefine_instruction_read_write_mem16!(\n    "and16",\n    instr16_83_4_mem_jit,\n    instr16_83_4_reg_jit,\n    imm8s_16bits\n);\ndefine_instruction_read_write_mem32!(gen_and32, instr32_83_4_mem_jit, instr32_83_4_reg_jit, imm8s);\n\ndefine_instruction_read_write_mem16!(\n    "sub16",\n    instr16_83_5_mem_jit,\n    instr16_83_5_reg_jit,\n    imm8s_16bits\n);\ndefine_instruction_read_write_mem32!(gen_sub32, instr32_83_5_mem_jit, instr32_83_5_reg_jit, imm8s);\n\ndefine_instruction_read_write_mem16!(\n    "xor16",\n    instr16_83_6_mem_jit,\n    instr16_83_6_reg_jit,\n    imm8s_16bits\n);\ndefine_instruction_read_write_mem32!(gen_xor32, instr32_83_6_mem_jit, instr32_83_6_reg_jit, imm8s);\n\ndefine_instruction_read8!(gen_cmp8, instr_80_7_mem_jit, instr_80_7_reg_jit, imm8);\ndefine_instruction_read16!(gen_cmp16, instr16_81_7_mem_jit, instr16_81_7_reg_jit, imm16);\ndefine_instruction_read32!(gen_cmp32, instr32_81_7_mem_jit, instr32_81_7_reg_jit, imm32);\n\ndefine_instruction_read8!(gen_cmp8, instr_82_7_mem_jit, instr_82_7_reg_jit, imm8);\n\ndefine_instruction_read16!(\n    gen_cmp16,\n    instr16_83_7_mem_jit,\n    instr16_83_7_reg_jit,\n    imm8s_16bits\n);\ndefine_instruction_read32!(gen_cmp32, instr32_83_7_mem_jit, instr32_83_7_reg_jit, imm8s);\n\ndefine_instruction_read8!(gen_test8, instr_84_mem_jit, instr_84_reg_jit);\ndefine_instruction_read16!(gen_test16, instr16_85_mem_jit, instr16_85_reg_jit);\ndefine_instruction_read32!(gen_test32, instr32_85_mem_jit, instr32_85_reg_jit);\n\npub fn instr_86_mem_jit(ctx: &mut JitContext, modrm_byte: ModrmByte, r: u32) {\n    codegen::gen_modrm_resolve_with_local(ctx, modrm_byte, &|ctx, addr| {\n        codegen::gen_safe_read_write(ctx, BitSize::BYTE, &addr, &|ref mut ctx| {\n            codegen::gen_get_reg8(ctx, r);\n            let tmp = ctx.builder.set_new_local();\n            codegen::gen_set_reg8(ctx, r);\n            ctx.builder.get_local(&tmp);\n            ctx.builder.free_local(tmp);\n        });\n    });\n}\npub fn instr_86_reg_jit(ctx: &mut JitContext, r1: u32, r2: u32) {\n    codegen::gen_get_reg8(ctx, r2);\n    let tmp = ctx.builder.set_new_local();\n    codegen::gen_get_reg8(ctx, r1);\n    codegen::gen_set_reg8(ctx, r2);\n    ctx.builder.get_local(&tmp);\n    codegen::gen_set_reg8(ctx, r1);\n    ctx.builder.free_local(tmp);\n}\npub fn instr16_87_mem_jit(ctx: &mut JitContext, modrm_byte: ModrmByte, r: u32) {\n    codegen::gen_modrm_resolve_with_local(ctx, modrm_byte, &|ctx, addr| {\n        codegen::gen_safe_read_write(ctx, BitSize::WORD, &addr, &|ref mut ctx| {\n            codegen::gen_get_reg16(ctx, r);\n            let tmp = ctx.builder.set_new_local();\n            codegen::gen_set_reg16(ctx, r);\n            ctx.builder.get_local(&tmp);\n            ctx.builder.free_local(tmp);\n        });\n    });\n}\npub fn instr32_87_mem_jit(ctx: &mut JitContext, modrm_byte: ModrmByte, r: u32) {\n    codegen::gen_modrm_resolve_with_local(ctx, modrm_byte, &|ctx, addr| {\n        codegen::gen_safe_read_write(ctx, BitSize::DWORD, &addr, &|ref mut ctx| {\n            codegen::gen_get_reg32(ctx, r);\n            let tmp = ctx.builder.set_new_local();\n            codegen::gen_set_reg32(ctx, r);\n            ctx.builder.get_local(&tmp);\n            ctx.builder.free_local(tmp);\n        });\n    });\n}\npub fn instr16_87_reg_jit(ctx: &mut JitContext, r1: u32, r2: u32) {\n    codegen::gen_get_reg16(ctx, r2);\n    let tmp = ctx.builder.set_new_local();\n    codegen::gen_get_reg16(ctx, r1);\n    codegen::gen_set_reg16(ctx, r2);\n    ctx.builder.get_local(&tmp);\n    codegen::gen_set_reg16(ctx, r1);\n    ctx.builder.free_local(tmp);\n}\npub fn instr32_87_reg_jit(ctx: &mut JitContext, r1: u32, r2: u32) {\n    codegen::gen_get_reg32(ctx, r2);\n    let tmp = ctx.builder.set_new_local();\n    codegen::gen_get_reg32(ctx, r1);\n    codegen::gen_set_reg32(ctx, r2);\n    ctx.builder.get_local(&tmp);\n    codegen::gen_set_reg32(ctx, r1);\n    ctx.builder.free_local(tmp);\n}\n\npub fn instr_88_mem_jit(ctx: &mut JitContext, modrm_byte: ModrmByte, r: u32) {\n    codegen::gen_modrm_resolve_with_local(ctx, modrm_byte, &|ctx, addr| {\n        codegen::gen_get_reg8(ctx, r);\n        let value_local = ctx.builder.set_new_local();\n        codegen::gen_safe_write8(ctx, &addr, &value_local);\n        ctx.builder.free_local(value_local);\n    });\n}\npub fn instr_88_reg_jit(ctx: &mut JitContext, r1: u32, r2: u32) {\n    codegen::gen_set_reg8_r(ctx, r1, r2);\n}\n\npub fn instr16_89_mem_jit(ctx: &mut JitContext, modrm_byte: ModrmByte, r: u32) {\n    codegen::gen_modrm_resolve_with_local(ctx, modrm_byte, &|ctx, addr| {\n        codegen::gen_safe_write16(ctx, addr, &ctx.reg(r));\n    });\n}\npub fn instr16_89_reg_jit(ctx: &mut JitContext, r1: u32, r2: u32) {\n    codegen::gen_set_reg16_r(ctx, r1, r2);\n}\npub fn instr32_89_mem_jit(ctx: &mut JitContext, modrm_byte: ModrmByte, r: u32) {\n    codegen::gen_modrm_resolve_with_local(ctx, modrm_byte, &|ctx, addr| {\n        codegen::gen_safe_write32(ctx, &addr, &ctx.reg(r));\n    });\n}\npub fn instr32_89_reg_jit(ctx: &mut JitContext, r1: u32, r2: u32) {\n    codegen::gen_set_reg32_r(ctx, r1, r2);\n}\n\npub fn instr_8A_mem_jit(ctx: &mut JitContext, modrm_byte: ModrmByte, r: u32) {\n    // Pseudo: reg8[r] = safe_read8(modrm_resolve(modrm_byte));\n    codegen::gen_modrm_resolve_safe_read8(ctx, modrm_byte);\n    codegen::gen_set_reg8_unmasked(ctx, r);\n}\npub fn instr_8A_reg_jit(ctx: &mut JitContext, r1: u32, r2: u32) {\n    codegen::gen_set_reg8_r(ctx, r2, r1);\n}\n\npub fn instr16_8B_mem_jit(ctx: &mut JitContext, modrm_byte: ModrmByte, r: u32) {\n    codegen::gen_modrm_resolve_safe_read16(ctx, modrm_byte);\n    codegen::gen_set_reg16_unmasked(ctx, r);\n}\npub fn instr16_8B_reg_jit(ctx: &mut JitContext, r1: u32, r2: u32) {\n    codegen::gen_set_reg16_r(ctx, r2, r1);\n}\npub fn instr32_8B_mem_jit(ctx: &mut JitContext, modrm_byte: ModrmByte, r: u32) {\n    codegen::gen_modrm_resolve_safe_read32(ctx, modrm_byte);\n    codegen::gen_set_reg32(ctx, r);\n}\npub fn instr32_8B_reg_jit(ctx: &mut JitContext, r1: u32, r2: u32) {\n    codegen::gen_set_reg32_r(ctx, r2, r1);\n}\n\npub fn instr16_8C_mem_jit(ctx: &mut JitContext, modrm_byte: ModrmByte, r: u32) {\n    codegen::gen_modrm_resolve(ctx, modrm_byte);\n    let address_local = ctx.builder.set_new_local();\n    if r >= 6 {\n        codegen::gen_trigger_ud(ctx);\n    }\n    else {\n        codegen::gen_get_sreg(ctx, r);\n        let value_local = ctx.builder.set_new_local();\n        codegen::gen_safe_write16(ctx, &address_local, &value_local);\n        ctx.builder.free_local(value_local);\n    }\n    ctx.builder.free_local(address_local);\n}\npub fn instr32_8C_mem_jit(ctx: &mut JitContext, modrm_byte: ModrmByte, r: u32) {\n    codegen::gen_modrm_resolve(ctx, modrm_byte);\n    let address_local = ctx.builder.set_new_local();\n    if r >= 6 {\n        codegen::gen_trigger_ud(ctx);\n    }\n    else {\n        codegen::gen_get_sreg(ctx, r);\n        let value_local = ctx.builder.set_new_local();\n        codegen::gen_safe_write16(ctx, &address_local, &value_local);\n        ctx.builder.free_local(value_local);\n    }\n    ctx.builder.free_local(address_local);\n}\npub fn instr16_8C_reg_jit(ctx: &mut JitContext, r1: u32, r2: u32) {\n    if r2 >= 6 {\n        codegen::gen_trigger_ud(ctx);\n    }\n    else {\n        codegen::gen_get_sreg(ctx, r2);\n        codegen::gen_set_reg16(ctx, r1);\n    }\n}\npub fn instr32_8C_reg_jit(ctx: &mut JitContext, r1: u32, r2: u32) {\n    if r2 >= 6 {\n        codegen::gen_trigger_ud(ctx);\n    }\n    else {\n        codegen::gen_get_sreg(ctx, r2);\n        codegen::gen_set_reg32(ctx, r1);\n    }\n}\n\npub fn instr16_8D_mem_jit(ctx: &mut JitContext, modrm_byte: ModrmByte, reg: u32) {\n    ctx.cpu.prefixes |= SEG_PREFIX_ZERO;\n    codegen::gen_modrm_resolve(ctx, modrm_byte);\n    codegen::gen_set_reg16(ctx, reg);\n}\npub fn instr32_8D_mem_jit(ctx: &mut JitContext, modrm_byte: ModrmByte, reg: u32) {\n    if !modrm_byte.is_nop(reg) {\n        ctx.cpu.prefixes |= SEG_PREFIX_ZERO;\n        codegen::gen_modrm_resolve(ctx, modrm_byte);\n        codegen::gen_set_reg32(ctx, reg);\n    }\n}\n\npub fn instr16_8D_reg_jit(ctx: &mut JitContext, _r1: u32, _r2: u32) {\n    codegen::gen_trigger_ud(ctx);\n}\n\npub fn instr32_8D_reg_jit(ctx: &mut JitContext, _r1: u32, _r2: u32) {\n    codegen::gen_trigger_ud(ctx);\n}\n\npub fn instr16_8F_0_mem_jit(ctx: &mut JitContext, modrm_byte: ModrmByte) {\n    // before gen_modrm_resolve, update esp to the new value\n    codegen::gen_adjust_stack_reg(ctx, 2);\n\n    codegen::gen_modrm_resolve(ctx, modrm_byte);\n    let address_local = ctx.builder.set_new_local();\n\n    // pop takes care of updating esp, so undo the previous change\n    codegen::gen_adjust_stack_reg(ctx, (-2i32) as u32);\n    codegen::gen_pop16(ctx);\n    let value_local = ctx.builder.set_new_local();\n\n    // undo the esp change of pop, as safe_write16 can fail\n    codegen::gen_adjust_stack_reg(ctx, (-2i32) as u32);\n\n    codegen::gen_safe_write16(ctx, &address_local, &value_local);\n\n    ctx.builder.free_local(address_local);\n    ctx.builder.free_local(value_local);\n\n    // finally, actually update esp\n    codegen::gen_adjust_stack_reg(ctx, 2);\n}\npub fn instr16_8F_0_reg_jit(ctx: &mut JitContext, r: u32) { pop16_reg_jit(ctx, r); }\npub fn instr32_8F_0_mem_jit(ctx: &mut JitContext, modrm_byte: ModrmByte) {\n    codegen::gen_adjust_stack_reg(ctx, 4);\n\n    codegen::gen_modrm_resolve(ctx, modrm_byte);\n    let address_local = ctx.builder.set_new_local();\n\n    codegen::gen_adjust_stack_reg(ctx, (-4i32) as u32);\n    codegen::gen_pop32s(ctx);\n    let value_local = ctx.builder.set_new_local();\n    codegen::gen_adjust_stack_reg(ctx, (-4i32) as u32);\n\n    codegen::gen_safe_write32(ctx, &address_local, &value_local);\n\n    ctx.builder.free_local(address_local);\n    ctx.builder.free_local(value_local);\n\n    codegen::gen_adjust_stack_reg(ctx, 4);\n}\npub fn instr32_8F_0_reg_jit(ctx: &mut JitContext, r: u32) { pop32_reg_jit(ctx, r); }\n\ndefine_instruction_read_write_mem16!(\n    "rol16",\n    instr16_C1_0_mem_jit,\n    instr16_C1_0_reg_jit,\n    imm8_5bits\n);\ndefine_instruction_read_write_mem32!(\n    gen_rol32,\n    instr32_C1_0_mem_jit,\n    instr32_C1_0_reg_jit,\n    imm8_5bits\n);\n\ndefine_instruction_read_write_mem16!(\n    "ror16",\n    instr16_C1_1_mem_jit,\n    instr16_C1_1_reg_jit,\n    imm8_5bits\n);\ndefine_instruction_read_write_mem32!(\n    gen_ror32,\n    instr32_C1_1_mem_jit,\n    instr32_C1_1_reg_jit,\n    imm8_5bits\n);\n\ndefine_instruction_read_write_mem16!(\n    "rcl16",\n    instr16_C1_2_mem_jit,\n    instr16_C1_2_reg_jit,\n    imm8_5bits\n);\ndefine_instruction_read_write_mem32!(\n    gen_rcl32,\n    instr32_C1_2_mem_jit,\n    instr32_C1_2_reg_jit,\n    imm8_5bits\n);\n\ndefine_instruction_read_write_mem16!(\n    "rcr16",\n    instr16_C1_3_mem_jit,\n    instr16_C1_3_reg_jit,\n    imm8_5bits\n);\ndefine_instruction_read_write_mem32!(\n    gen_rcr32,\n    instr32_C1_3_mem_jit,\n    instr32_C1_3_reg_jit,\n    imm8_5bits\n);\n\ndefine_instruction_read_write_mem16!(\n    "shl16",\n    instr16_C1_4_mem_jit,\n    instr16_C1_4_reg_jit,\n    imm8_5bits\n);\ndefine_instruction_read_write_mem32!(\n    gen_shl32,\n    instr32_C1_4_mem_jit,\n    instr32_C1_4_reg_jit,\n    imm8_5bits\n);\n\ndefine_instruction_read_write_mem16!(\n    "shr16",\n    instr16_C1_5_mem_jit,\n    instr16_C1_5_reg_jit,\n    imm8_5bits\n);\ndefine_instruction_read_write_mem32!(\n    gen_shr32,\n    instr32_C1_5_mem_jit,\n\npub fn instr_D9_4_mem_jit(ctx: &mut JitContext, modrm_byte: u8) {\n    codegen::gen_modrm_resolve(ctx, modrm_byte);\n    // XXX: generated because fldenv might page-fault, but doesn\'t generate a proper block boundary\n    codegen::gen_move_registers_from_locals_to_memory(ctx);\n    codegen::gen_call_fn1(ctx.builder, "fpu_fldenv");\n    codegen::gen_debug_track_jit_exit(ctx.builder, ctx.start_of_current_instruction);\n    codegen::gen_clear_prefixes(ctx);\n    ctx.builder.instruction_body.return_();\n}\npub fn instr_D9_4_reg_jit(ctx: &mut JitContext, r: u32) {\n    ctx.builder.instruction_body.const_i32(r as i32);\n    instr32_C1_7_mem_jit,\n    instr32_C1_7_reg_jit,\n    imm8_5bits\n);\n\npub fn instr16_E8_jit(ctx: &mut JitContext, _imm: u32) {\n    codegen::gen_get_real_eip(ctx);\n    let value_local = ctx.builder.set_new_local();\n    codegen::gen_push16(ctx, &value_local);\n    ctx.builder.free_local(value_local);\n}\npub fn instr32_E8_jit(ctx: &mut JitContext, _imm: u32) {\n    codegen::gen_get_real_eip(ctx);\n    let value_local = ctx.builder.set_new_local();\n    codegen::gen_push32(ctx, &value_local);\n\npub fn instr_D9_6_mem_jit(ctx: &mut JitContext, modrm_byte: u8) {\n    codegen::gen_modrm_resolve(ctx, modrm_byte);\n    // XXX: generated because fpu_fstenv might page-fault, but doesn\'t generate a proper block boundary\n    codegen::gen_move_registers_from_locals_to_memory(ctx);\n    codegen::gen_call_fn1(ctx.builder, "fpu_fstenv");\n    codegen::gen_debug_track_jit_exit(ctx.builder, ctx.start_of_current_instruction);\n    codegen::gen_clear_prefixes(ctx);\n    ctx.builder.instruction_body.return_();\n}\npub fn instr_D9_6_reg_jit(ctx: &mut JitContext, r: u32) {\n    codegen::gen_fn1_const(ctx.builder, "instr_D9_6_reg", r);\n    codegen::gen_adjust_stack_reg(ctx, imm16);\n}\n\npub fn instr16_C3_jit(ctx: &mut JitContext) {\n    ctx.builder.const_i32(0);\n    codegen::gen_pop16(ctx);\n    codegen::gen_add_cs_offset(ctx);\n    ctx.builder\n        .store_aligned_i32(global_pointers::instruction_pointer as u32);\n}\n\npub fn instr32_C3_jit(ctx: &mut JitContext) {\n    ctx.builder.const_i32(0);\n    codegen::gen_pop32s(ctx);\n    codegen::gen_add_cs_offset(ctx);\n    ctx.builder\n        .store_aligned_i32(global_pointers::instruction_pointer as u32);\n}\n\npub fn instr16_C9_jit(ctx: &mut JitContext) { codegen::gen_leave(ctx, false); }\npub fn instr32_C9_jit(ctx: &mut JitContext) { codegen::gen_leave(ctx, true); }\n\npub fn gen_mov_reg8_imm(ctx: &mut JitContext, r: u32, imm: u32) {\n    ctx.builder.const_i32(imm as i32);\n    codegen::gen_set_reg8_unmasked(ctx, r);\n}\n\npub fn instr_B0_jit(ctx: &mut JitContext, imm: u32) { gen_mov_reg8_imm(ctx, 0, imm) }\npub fn instr_B1_jit(ctx: &mut JitContext, imm: u32) { gen_mov_reg8_imm(ctx, 1, imm) }\npub fn instr_B2_jit(ctx: &mut JitContext, imm: u32) { gen_mov_reg8_imm(ctx, 2, imm) }\npub fn instr_B3_jit(ctx: &mut JitContext, imm: u32) { gen_mov_reg8_imm(ctx, 3, imm) }\npub fn instr_B4_jit(ctx: &mut JitContext, imm: u32) { gen_mov_reg8_imm(ctx, 4, imm) }\npub fn instr_B5_jit(ctx: &mut JitContext, imm: u32) { gen_mov_reg8_imm(ctx, 5, imm) }\npub fn instr_B6_jit(ctx: &mut JitContext, imm: u32) { gen_mov_reg8_imm(ctx, 6, imm) }\npub fn instr_B7_jit(ctx: &mut JitContext, imm: u32) { gen_mov_reg8_imm(ctx, 7, imm) }\n\npub fn gen_mov_reg16_imm(ctx: &mut JitContext, r: u32, imm: u32) {\n    ctx.builder.const_i32(imm as i32);\n    codegen::gen_set_reg16_unmasked(ctx, r);\n}\n\npub fn instr16_B8_jit(ctx: &mut JitContext, imm: u32) { gen_mov_reg16_imm(ctx, 0, imm) }\npub fn instr16_B9_jit(ctx: &mut JitContext, imm: u32) { gen_mov_reg16_imm(ctx, 1, imm) }\npub fn instr16_BA_jit(ctx: &mut JitContext, imm: u32) { gen_mov_reg16_imm(ctx, 2, imm) }\npub fn instr16_BB_jit(ctx: &mut JitContext, imm: u32) { gen_mov_reg16_imm(ctx, 3, imm) }\npub fn instr16_BC_jit(ctx: &mut JitContext, imm: u32) { gen_mov_reg16_imm(ctx, 4, imm) }\npub fn instr16_BD_jit(ctx: &mut JitContext, imm: u32) { gen_mov_reg16_imm(ctx, 5, imm) }\npub fn instr16_BE_jit(ctx: &mut JitContext, imm: u32) { gen_mov_reg16_imm(ctx, 6, imm) }\npub fn instr16_BF_jit(ctx: &mut JitContext, imm: u32) { gen_mov_reg16_imm(ctx, 7, imm) }\n\npub fn gen_mov_reg32_imm(ctx: &mut JitContext, r: u32, imm: u32) {\n    ctx.builder.const_i32(imm as i32);\n    codegen::gen_set_reg32(ctx, r);\n}\n\npub fn instr32_B8_jit(ctx: &mut JitContext, imm: u32) { gen_mov_reg32_imm(ctx, 0, imm) }\npub fn instr32_B9_jit(ctx: &mut JitContext, imm: u32) { gen_mov_reg32_imm(ctx, 1, imm) }\npub fn instr32_BA_jit(ctx: &mut JitContext, imm: u32) { gen_mov_reg32_imm(ctx, 2, imm) }\npub fn instr32_BB_jit(ctx: &mut JitContext, imm: u32) { gen_mov_reg32_imm(ctx, 3, imm) }\npub fn instr32_BC_jit(ctx: &mut JitContext, imm: u32) { gen_mov_reg32_imm(ctx, 4, imm) }\npub fn instr32_BD_jit(ctx: &mut JitContext, imm: u32) { gen_mov_reg32_imm(ctx, 5, imm) }\npub fn instr32_BE_jit(ctx: &mut JitContext, imm: u32) { gen_mov_reg32_imm(ctx, 6, imm) }\npub fn instr32_BF_jit(ctx: &mut JitContext, imm: u32) { gen_mov_reg32_imm(ctx, 7, imm) }\n\ndefine_instruction_read_write_mem8!("rol8", instr_C0_0_mem_jit, instr_C0_0_reg_jit, imm8_5bits);\ndefine_instruction_read_write_mem8!("ror8", instr_C0_1_mem_jit, instr_C0_1_reg_jit, imm8_5bits);\ndefine_instruction_read_write_mem8!("rcl8", instr_C0_2_mem_jit, instr_C0_2_reg_jit, imm8_5bits);\ndefine_instruction_read_write_mem8!("rcr8", instr_C0_3_mem_jit, instr_C0_3_reg_jit, imm8_5bits);\ndefine_instruction_read_write_mem8!("shl8", instr_C0_4_mem_jit, instr_C0_4_reg_jit, imm8_5bits);\n\npub fn instr_DB_5_mem_jit(ctx: &mut JitContext, modrm_byte: u8) {\n    codegen::gen_modrm_resolve(ctx, modrm_byte);\n    // XXX: generated because fpu_fldm80 might page-fault, but doesn\'t generate a proper block boundary\n    codegen::gen_move_registers_from_locals_to_memory(ctx);\n    codegen::gen_call_fn1(ctx.builder, "fpu_fldm80");\n    codegen::gen_debug_track_jit_exit(ctx.builder, ctx.start_of_current_instruction);\n    codegen::gen_clear_prefixes(ctx);\n    ctx.builder.instruction_body.return_();\n}\npub fn instr_DB_5_reg_jit(ctx: &mut JitContext, r: u32) {\n    ctx.builder.instruction_body.const_i32(r as i32);\n\ndefine_instruction_read_write_mem16!(\n    "ror16",\n    instr16_D1_1_mem_jit,\n    instr16_D1_1_reg_jit,\n    constant_one\n);\ndefine_instruction_read_write_mem32!(\n    gen_ror32,\n    instr32_D1_1_mem_jit,\n    instr32_D1_1_reg_jit,\n    constant_one\n);\n\ndefine_instruction_read_write_mem16!(\n    "rcl16",\n    instr16_D1_2_mem_jit,\n    instr16_D1_2_reg_jit,\n    constant_one\n);\ndefine_instruction_read_write_mem32!(\n    gen_rcl32,\n    instr32_D1_2_mem_jit,\n    instr32_D1_2_reg_jit,\n    constant_one\n);\n\ndefine_instruction_read_write_mem16!(\n    "rcr16",\n    instr16_D1_3_mem_jit,\n    instr16_D1_3_reg_jit,\n    constant_one\n);\ndefine_instruction_read_write_mem32!(\n    gen_rcr32,\n    instr32_D1_3_mem_jit,\n    instr32_D1_3_reg_jit,\n    constant_one\n);\n\ndefine_instruction_read_write_mem16!(\n    "shl16",\n    instr16_D1_4_mem_jit,\n    instr16_D1_4_reg_jit,\n    constant_one\n);\ndefine_instruction_read_write_mem32!(\n    gen_shl32,\n    instr32_D1_4_mem_jit,\n    instr32_D1_4_reg_jit,\n    constant_one\n);\n\ndefine_instruction_read_write_mem16!(\n    "shr16",\n    instr16_D1_5_mem_jit,\n    instr16_D1_5_reg_jit,\n    constant_one\n);\ndefine_instruction_read_write_mem32!(\n    gen_shr32,\n    instr32_D1_5_mem_jit,\n    instr32_D1_5_reg_jit,\n    constant_one\n);\n\ndefine_instruction_read_write_mem16!(\n    "shl16",\n    instr16_D1_6_mem_jit,\n    instr16_D1_6_reg_jit,\n    constant_one\n);\ndefine_instruction_read_write_mem32!(\n    gen_shl32,\n    instr32_D1_6_mem_jit,\n    instr32_D1_6_reg_jit,\n    constant_one\n);\n\ndefine_instruction_read_write_mem16!(\n    "sar16",\n    instr16_D1_7_mem_jit,\n    instr16_D1_7_reg_jit,\n    constant_one\n);\ndefine_instruction_read_write_mem32!(\n    gen_sar32,\n    instr32_D1_7_mem_jit,\n    instr32_D1_7_reg_jit,\n    constant_one\n);\n\ndefine_instruction_read_write_mem8!("rol8", instr_D2_0_mem_jit, instr_D2_0_reg_jit, cl);\ndefine_instruction_read_write_mem8!("ror8", instr_D2_1_mem_jit, instr_D2_1_reg_jit, cl);\ndefine_instruction_read_write_mem8!("rcl8", instr_D2_2_mem_jit, instr_D2_2_reg_jit, cl);\ndefine_instruction_read_write_mem8!("rcr8", instr_D2_3_mem_jit, instr_D2_3_reg_jit, cl);\ndefine_instruction_read_write_mem8!("shl8", instr_D2_4_mem_jit, instr_D2_4_reg_jit, cl);\ndefine_instruction_read_write_mem8!("shr8", instr_D2_5_mem_jit, instr_D2_5_reg_jit, cl);\ndefine_instruction_read_write_mem8!("shl8", instr_D2_6_mem_jit, instr_D2_6_reg_jit, cl);\ndefine_instruction_read_write_mem8!("sar8", instr_D2_7_mem_jit, instr_D2_7_reg_jit, cl);\n\ndefine_instruction_read_write_mem16!("rol16", instr16_D3_0_mem_jit, instr16_D3_0_reg_jit, cl);\ndefine_instruction_read_write_mem32!(gen_rol32, instr32_D3_0_mem_jit, instr32_D3_0_reg_jit, cl);\n\ndefine_instruction_read_write_mem16!("ror16", instr16_D3_1_mem_jit, instr16_D3_1_reg_jit, cl);\ndefine_instruction_read_write_mem32!(gen_ror32, instr32_D3_1_mem_jit, instr32_D3_1_reg_jit, cl);\n\ndefine_instruction_read_write_mem16!("rcl16", instr16_D3_2_mem_jit, instr16_D3_2_reg_jit, cl);\ndefine_instruction_read_write_mem32!(gen_rcl32, instr32_D3_2_mem_jit, instr32_D3_2_reg_jit, cl);\n\ndefine_instruction_read_write_mem16!("rcr16", instr16_D3_3_mem_jit, instr16_D3_3_reg_jit, cl);\ndefine_instruction_read_write_mem32!(gen_rcr32, instr32_D3_3_mem_jit, instr32_D3_3_reg_jit, cl);\n\ndefine_instruction_read_write_mem16!("shl16", instr16_D3_4_mem_jit, instr16_D3_4_reg_jit, cl);\ndefine_instruction_read_write_mem32!(gen_shl32, instr32_D3_4_mem_jit, instr32_D3_4_reg_jit, cl);\n\ndefine_instruction_read_write_mem16!("shr16", instr16_D3_5_mem_jit, instr16_D3_5_reg_jit, cl);\ndefine_instruction_read_write_mem32!(gen_shr32, instr32_D3_5_mem_jit, instr32_D3_5_reg_jit, cl);\n\ndefine_instruction_read_write_mem16!("shl16", instr16_D3_6_mem_jit, instr16_D3_6_reg_jit, cl);\ndefine_instruction_read_write_mem32!(gen_shl32, instr32_D3_6_mem_jit, instr32_D3_6_reg_jit, cl);\n\ndefine_instruction_read_write_mem16!("sar16", instr16_D3_7_mem_jit, instr16_D3_7_reg_jit, cl);\ndefine_instruction_read_write_mem32!(gen_sar32, instr32_D3_7_mem_jit, instr32_D3_7_reg_jit, cl);\n\npub fn instr_D7_jit(ctx: &mut JitContext) {\n    if ctx.cpu.asize_32() {\n        codegen::gen_get_reg32(ctx, regs::EBX);\n    }\n    else {\n        codegen::gen_get_reg16(ctx, regs::BX);\n    }\n    codegen::gen_get_reg8(ctx, regs::AL);\n    ctx.builder.add_i32();\n    if !ctx.cpu.asize_32() {\n        ctx.builder.const_i32(0xFFFF);\n        ctx.builder.and_i32();\n    }\n    jit_add_seg_offset(ctx, regs::DS);\n    let address_local = ctx.builder.set_new_local();\n    codegen::gen_safe_read8(ctx, &address_local);\n    ctx.builder.free_local(address_local);\n    codegen::gen_set_reg8(ctx, regs::AL);\n}\n\nfn instr_group_D8_mem_jit(ctx: &mut JitContext, modrm_byte: ModrmByte, op: &str) {\n    ctx.builder.const_i32(0);\n    codegen::gen_fpu_load_m32(ctx, modrm_byte);\n    ctx.builder.call_fn3_i32_i64_i32(op)\n}\nfn instr_group_D8_reg_jit(ctx: &mut JitContext, r: u32, op: &str) {\n    ctx.builder.const_i32(0);\n    codegen::gen_fpu_get_sti(ctx, r);\n    ctx.builder.call_fn3_i32_i64_i32(op)\n}\n\npub fn instr_D8_0_mem_jit(ctx: &mut JitContext, modrm_byte: ModrmByte) {\n    instr_group_D8_mem_jit(ctx, modrm_byte, "fpu_fadd")\n}\npub fn instr_D8_0_reg_jit(ctx: &mut JitContext, r: u32) {\n    instr_group_D8_reg_jit(ctx, r, "fpu_fadd")\n}\npub fn instr_D8_1_mem_jit(ctx: &mut JitContext, modrm_byte: ModrmByte) {\n    instr_group_D8_mem_jit(ctx, modrm_byte, "fpu_fmul")\n}\npub fn instr_D8_1_reg_jit(ctx: &mut JitContext, r: u32) {\n    instr_group_D8_reg_jit(ctx, r, "fpu_fmul")\n}\npub fn instr_D8_2_mem_jit(ctx: &mut JitContext, modrm_byte: ModrmByte) {\n    codegen::gen_fpu_load_m32(ctx, modrm_byte);\n    ctx.builder.call_fn2_i64_i32("fpu_fcom")\n}\npub fn instr_D8_2_reg_jit(ctx: &mut JitContext, r: u32) {\n    codegen::gen_fpu_get_sti(ctx, r);\n    ctx.builder.call_fn2_i64_i32("fpu_fcom")\n}\npub fn instr_D8_3_mem_jit(ctx: &mut JitContext, modrm_byte: ModrmByte) {\n    codegen::gen_fpu_load_m32(ctx, modrm_byte);\n    ctx.builder.call_fn2_i64_i32("fpu_fcomp")\n}\npub fn instr_D8_3_reg_jit(ctx: &mut JitContext, r: u32) {\n    codegen::gen_fpu_get_sti(ctx, r);\n    ctx.builder.call_fn2_i64_i32("fpu_fcomp")\n}\npub fn instr_D8_4_mem_jit(ctx: &mut JitContext, modrm_byte: ModrmByte) {\n    instr_group_D8_mem_jit(ctx, modrm_byte, "fpu_fsub")\n}\npub fn instr_D8_4_reg_jit(ctx: &mut JitContext, r: u32) {\n    instr_group_D8_reg_jit(ctx, r, "fpu_fsub")\n}\npub fn instr_D8_5_mem_jit(ctx: &mut JitContext, modrm_byte: ModrmByte) {\n    instr_group_D8_mem_jit(ctx, modrm_byte, "fpu_fsubr")\n}\npub fn instr_D8_5_reg_jit(ctx: &mut JitContext, r: u32) {\n    instr_group_D8_reg_jit(ctx, r, "fpu_fsubr")\n}\npub fn instr_D8_6_mem_jit(ctx: &mut JitContext, modrm_byte: ModrmByte) {\n    instr_group_D8_mem_jit(ctx, modrm_byte, "fpu_fdiv")\n}\npub fn instr_D8_6_reg_jit(ctx: &mut JitContext, r: u32) {\n    instr_group_D8_reg_jit(ctx, r, "fpu_fdiv")\n}\npub fn instr_D8_7_mem_jit(ctx: &mut JitContext, modrm_byte: ModrmByte) {\n    instr_group_D8_mem_jit(ctx, modrm_byte, "fpu_fdivr")\n}\npub fn instr_D8_7_reg_jit(ctx: &mut JitContext, r: u32) {\n    instr_group_D8_reg_jit(ctx, r, "fpu_fdivr")\n}\n\npub fn instr16_D9_0_mem_jit(ctx: &mut JitContext, modrm_byte: ModrmByte) {\n    codegen::gen_fpu_load_m32(ctx, modrm_byte);\n    ctx.builder.call_fn2_i64_i32("fpu_push");\n}\npub fn instr16_D9_0_reg_jit(ctx: &mut JitContext, r: u32) {\n    codegen::gen_fpu_get_sti(ctx, r);\n    ctx.builder.call_fn2_i64_i32("fpu_push");\n}\npub fn instr32_D9_0_reg_jit(ctx: &mut JitContext, r: u32) { instr16_D9_0_reg_jit(ctx, r) }\npub fn instr32_D9_0_mem_jit(ctx: &mut JitContext, modrm_byte: ModrmByte) {\n    instr16_D9_0_mem_jit(ctx, modrm_byte)\n}\n\npub fn instr16_D9_1_mem_jit(ctx: &mut JitContext, modrm_byte: ModrmByte) {\n    codegen::gen_modrm_resolve(ctx, modrm_byte);\n    codegen::gen_trigger_ud(ctx);\n}\npub fn instr16_D9_1_reg_jit(ctx: &mut JitContext, r: u32) {\n    ctx.builder.const_i32(r as i32);\n    ctx.builder.call_fn1("fpu_fxch");\n}\npub fn instr32_D9_1_reg_jit(ctx: &mut JitContext, r: u32) { instr16_D9_1_reg_jit(ctx, r) }\npub fn instr32_D9_1_mem_jit(ctx: &mut JitContext, modrm_byte: ModrmByte) {\n    instr16_D9_1_mem_jit(ctx, modrm_byte)\n}\n\npub fn instr16_D9_2_mem_jit(ctx: &mut JitContext, modrm_byte: ModrmByte) {\n    codegen::gen_modrm_resolve(ctx, modrm_byte);\n    let address_local = ctx.builder.set_new_local();\n    codegen::gen_fpu_get_sti(ctx, 0);\n    ctx.builder.call_fn2_i64_i32_ret("f80_to_f32");\n    let value_local = ctx.builder.set_new_local();\n    codegen::gen_safe_write32(ctx, &address_local, &value_local);\n    ctx.builder.free_local(address_local);\n    ctx.builder.free_local(value_local);\n}\npub fn instr16_D9_2_reg_jit(ctx: &mut JitContext, r: u32) {\n    if r != 0 {\n        codegen::gen_trigger_ud(ctx);\n    }\n}\npub fn instr32_D9_2_reg_jit(ctx: &mut JitContext, r: u32) { instr16_D9_2_reg_jit(ctx, r) }\npub fn instr32_D9_2_mem_jit(ctx: &mut JitContext, modrm_byte: ModrmByte) {\n    instr16_D9_2_mem_jit(ctx, modrm_byte)\n}\n\npub fn instr16_D9_3_mem_jit(ctx: &mut JitContext, modrm_byte: ModrmByte) {\n    codegen::gen_modrm_resolve(ctx, modrm_byte);\n    let address_local = ctx.builder.set_new_local();\n    codegen::gen_fpu_get_sti(ctx, 0);\n    ctx.builder.call_fn2_i64_i32_ret("f80_to_f32");\n    let value_local = ctx.builder.set_new_local();\n    codegen::gen_safe_write32(ctx, &address_local, &value_local);\n    ctx.builder.free_local(address_local);\n    ctx.builder.free_local(value_local);\n    codegen::gen_fn0_const(ctx.builder, "fpu_pop");\n}\npub fn instr16_D9_3_reg_jit(ctx: &mut JitContext, r: u32) {\n    codegen::gen_fn1_const(ctx.builder, "fpu_fstp", r);\n}\npub fn instr32_D9_3_reg_jit(ctx: &mut JitContext, r: u32) { instr16_D9_3_reg_jit(ctx, r) }\npub fn instr32_D9_3_mem_jit(ctx: &mut JitContext, modrm_byte: ModrmByte) {\n    instr16_D9_3_mem_jit(ctx, modrm_byte)\n}\n\npub fn instr16_D9_4_mem_jit(ctx: &mut JitContext, modrm_byte: ModrmByte) {\n    codegen::gen_modrm_resolve(ctx, modrm_byte);\n\n    codegen::gen_set_previous_eip_offset_from_eip_with_low_bits(\n        ctx.builder,\n        ctx.start_of_current_instruction as i32 & 0xFFF,\n    );\n\n    codegen::gen_move_registers_from_locals_to_memory(ctx);\n    ctx.builder.call_fn1("fpu_fldenv32");\n    codegen::gen_move_registers_from_memory_to_locals(ctx);\n\n    codegen::gen_get_page_fault(ctx.builder);\n    ctx.builder.if_void();\n    codegen::gen_debug_track_jit_exit(ctx.builder, ctx.start_of_current_instruction);\n    ctx.builder.br(ctx.exit_label);\n    ctx.builder.block_end();\n}\npub fn instr16_D9_4_reg_jit(ctx: &mut JitContext, r: u32) {\n    match r {\n        0 | 1 | 4 | 5 => {\n            ctx.builder.const_i32(r as i32);\n            ctx.builder.call_fn1("instr16_D9_4_reg");\n        },\n        _ => codegen::gen_trigger_ud(ctx),\n    }\n}\npub fn instr32_D9_4_reg_jit(ctx: &mut JitContext, r: u32) { instr16_D9_4_reg_jit(ctx, r) }\npub fn instr32_D9_4_mem_jit(ctx: &mut JitContext, modrm_byte: ModrmByte) {\n    instr16_D9_4_mem_jit(ctx, modrm_byte)\n}\n\npub fn instr16_D9_5_mem_jit(ctx: &mut JitContext, modrm_byte: ModrmByte) {\n    codegen::gen_modrm_resolve_safe_read16(ctx, modrm_byte);\n    ctx.builder.call_fn1("set_control_word");\n}\npub fn instr16_D9_5_reg_jit(ctx: &mut JitContext, r: u32) {\n    if r == 7 {\n        codegen::gen_trigger_ud(ctx);\n    }\n    else {\n        codegen::gen_fn1_const(ctx.builder, "instr16_D9_5_reg", r);\n    }\n}\npub fn instr32_D9_5_reg_jit(ctx: &mut JitContext, r: u32) { instr16_D9_5_reg_jit(ctx, r) }\npub fn instr32_D9_5_mem_jit(ctx: &mut JitContext, modrm_byte: ModrmByte) {\n    instr16_D9_5_mem_jit(ctx, modrm_byte)\n}\n\npub fn instr16_D9_6_mem_jit(ctx: &mut JitContext, modrm_byte: ModrmByte) {\n    codegen::gen_modrm_resolve(ctx, modrm_byte);\n\n    codegen::gen_set_previous_eip_offset_from_eip_with_low_bits(\n        ctx.builder,\n        ctx.start_of_current_instruction as i32 & 0xFFF,\n    );\n\n    codegen::gen_move_registers_from_locals_to_memory(ctx);\n    ctx.builder.call_fn1("fpu_fstenv32");\n    codegen::gen_move_registers_from_memory_to_locals(ctx);\n\n    codegen::gen_get_page_fault(ctx.builder);\n    ctx.builder.if_void();\n    codegen::gen_debug_track_jit_exit(ctx.builder, ctx.start_of_current_instruction);\n    ctx.builder.br(ctx.exit_label);\n    ctx.builder.block_end();\n}\npub fn instr16_D9_6_reg_jit(ctx: &mut JitContext, r: u32) {\n    codegen::gen_fn1_const(ctx.builder, "instr16_D9_6_reg", r);\n}\npub fn instr32_D9_6_reg_jit(ctx: &mut JitContext, r: u32) { instr16_D9_6_reg_jit(ctx, r) }\npub fn instr32_D9_6_mem_jit(ctx: &mut JitContext, modrm_byte: ModrmByte) {\n    instr16_D9_6_mem_jit(ctx, modrm_byte)\n}\n\npub fn instr16_D9_7_mem_jit(ctx: &mut JitContext, modrm_byte: ModrmByte) {\n    codegen::gen_modrm_resolve(ctx, modrm_byte);\n    let address_local = ctx.builder.set_new_local();\n    ctx.builder\n        .const_i32(global_pointers::fpu_control_word as i32);\n    ctx.builder.load_aligned_u16(0);\n    let value_local = ctx.builder.set_new_local();\n    codegen::gen_safe_write16(ctx, &address_local, &value_local);\n    ctx.builder.free_local(address_local);\n    ctx.builder.free_local(value_local);\n}\npub fn instr16_D9_7_reg_jit(ctx: &mut JitContext, r: u32) {\n    codegen::gen_fn1_const(ctx.builder, "instr16_D9_7_reg", r);\n}\npub fn instr32_D9_7_reg_jit(ctx: &mut JitContext, r: u32) { instr16_D9_7_reg_jit(ctx, r) }\npub fn instr32_D9_7_mem_jit(ctx: &mut JitContext, modrm_byte: ModrmByte) {\n    instr16_D9_7_mem_jit(ctx, modrm_byte)\n}\n\npub fn instr_DA_5_mem_jit(ctx: &mut JitContext, modrm_byte: ModrmByte) {\n    ctx.builder.const_i32(0);\n    codegen::gen_fpu_load_i32(ctx, modrm_byte);\n    ctx.builder.call_fn3_i32_i64_i32("fpu_fsubr")\n}\npub fn instr_DA_5_reg_jit(ctx: &mut JitContext, r: u32) {\n    if r == 1 {\n        codegen::gen_fn0_const(ctx.builder, "fpu_fucompp");\n    }\n    else {\n        codegen::gen_trigger_ud(ctx);\n    };\n}\n\npub fn instr_DB_0_mem_jit(ctx: &mut JitContext, modrm_byte: ModrmByte) {\n    codegen::gen_fpu_load_i32(ctx, modrm_byte);\n    ctx.builder.call_fn2_i64_i32("fpu_push");\n}\npub fn instr_DB_0_reg_jit(ctx: &mut JitContext, r: u32) {\n    codegen::gen_fn1_const(ctx.builder, "instr_DB_0_reg", r);\n}\n\npub fn instr_DB_2_mem_jit(ctx: &mut JitContext, modrm_byte: ModrmByte) {\n    codegen::gen_modrm_resolve(ctx, modrm_byte);\n    let address_local = ctx.builder.set_new_local();\n    codegen::gen_fpu_get_sti(ctx, 0);\n    ctx.builder.call_fn2_i64_i32_ret("fpu_convert_to_i32");\n    let value_local = ctx.builder.set_new_local();\n    codegen::gen_safe_write32(ctx, &address_local, &value_local);\n    ctx.builder.free_local(address_local);\n    ctx.builder.free_local(value_local);\n}\npub fn instr_DB_2_reg_jit(ctx: &mut JitContext, r: u32) {\n    codegen::gen_fn1_const(ctx.builder, "instr_DB_2_reg", r);\n}\npub fn instr_DB_3_mem_jit(ctx: &mut JitContext, modrm_byte: ModrmByte) {\n    codegen::gen_modrm_resolve(ctx, modrm_byte);\n    let address_local = ctx.builder.set_new_local();\n    codegen::gen_fpu_get_sti(ctx, 0);\n    ctx.builder.call_fn2_i64_i32_ret("fpu_convert_to_i32");\n    let value_local = ctx.builder.set_new_local();\n    codegen::gen_safe_write32(ctx, &address_local, &value_local);\n    ctx.builder.free_local(address_local);\n    ctx.builder.free_local(value_local);\n    codegen::gen_fn0_const(ctx.builder, "fpu_pop");\n}\npub fn instr_DB_3_reg_jit(ctx: &mut JitContext, r: u32) {\n    codegen::gen_fn1_const(ctx.builder, "instr_DB_3_reg", r);\n}\n\npub fn instr_DB_5_mem_jit(ctx: &mut JitContext, modrm_byte: ModrmByte) {\n    codegen::gen_modrm_resolve(ctx, modrm_byte);\n\n    codegen::gen_set_previous_eip_offset_from_eip_with_low_bits(\n        ctx.builder,\n        ctx.start_of_current_instruction as i32 & 0xFFF,\n    );\n\n    codegen::gen_move_registers_from_locals_to_memory(ctx);\n    ctx.builder.call_fn1("fpu_fldm80");\n    codegen::gen_move_registers_from_memory_to_locals(ctx);\n\n    codegen::gen_get_page_fault(ctx.builder);\n    ctx.builder.if_void();\n    codegen::gen_debug_track_jit_exit(ctx.builder, ctx.start_of_current_instruction);\n    ctx.builder.br(ctx.exit_label);\n    ctx.builder.block_end();\n}\npub fn instr_DB_5_reg_jit(ctx: &mut JitContext, r: u32) {\n    ctx.builder.const_i32(r as i32);\n    ctx.builder.call_fn1("fpu_fucomi");\n}\n\npub fn instr_DB_6_mem_jit(ctx: &mut JitContext, _modrm_byte: ModrmByte) {\n    codegen::gen_trigger_ud(ctx);\n}\npub fn instr_DB_6_reg_jit(ctx: &mut JitContext, r: u32) {\n    ctx.builder.const_i32(r as i32);\n    ctx.builder.call_fn1("fpu_fcomi");\n}\n\nfn instr_group_DC_mem_jit(ctx: &mut JitContext, modrm_byte: ModrmByte, op: &str) {\n    ctx.builder.const_i32(0);\n    codegen::gen_fpu_load_m64(ctx, modrm_byte);\n    ctx.builder.call_fn3_i32_i64_i32(op)\n}\nfn instr_group_DC_reg_jit(ctx: &mut JitContext, r: u32, op: &str) {\n    ctx.builder.const_i32(r as i32);\n    codegen::gen_fpu_get_sti(ctx, r);\n    ctx.builder.call_fn3_i32_i64_i32(op)\n}\n\npub fn instr_DC_0_mem_jit(ctx: &mut JitContext, modrm_byte: ModrmByte) {\n    instr_group_DC_mem_jit(ctx, modrm_byte, "fpu_fadd")\n}\npub fn instr_DC_0_reg_jit(ctx: &mut JitContext, r: u32) {\n    instr_group_DC_reg_jit(ctx, r, "fpu_fadd")\n}\npub fn instr_DC_1_mem_jit(ctx: &mut JitContext, modrm_byte: ModrmByte) {\n    instr_group_DC_mem_jit(ctx, modrm_byte, "fpu_fmul")\n}\npub fn instr_DC_1_reg_jit(ctx: &mut JitContext, r: u32) {\n    instr_group_DC_reg_jit(ctx, r, "fpu_fmul")\n}\npub fn instr_DC_2_mem_jit(ctx: &mut JitContext, modrm_byte: ModrmByte) {\n    codegen::gen_fpu_load_m64(ctx, modrm_byte);\n    ctx.builder.call_fn2_i64_i32("fpu_fcom")\n}\npub fn instr_DC_2_reg_jit(ctx: &mut JitContext, r: u32) {\n    codegen::gen_fpu_get_sti(ctx, r);\n    ctx.builder.call_fn2_i64_i32("fpu_fcom")\n}\npub fn instr_DC_3_mem_jit(ctx: &mut JitContext, modrm_byte: ModrmByte) {\n    codegen::gen_fpu_load_m64(ctx, modrm_byte);\n    ctx.builder.call_fn2_i64_i32("fpu_fcomp")\n}\npub fn instr_DC_3_reg_jit(ctx: &mut JitContext, r: u32) {\n    codegen::gen_fpu_get_sti(ctx, r);\n    ctx.builder.call_fn2_i64_i32("fpu_fcomp")\n}\npub fn instr_DC_4_mem_jit(ctx: &mut JitContext, modrm_byte: ModrmByte) {\n    instr_group_DC_mem_jit(ctx, modrm_byte, "fpu_fsub")\n}\npub fn instr_DC_4_reg_jit(ctx: &mut JitContext, r: u32) {\n    instr_group_DC_reg_jit(ctx, r, "fpu_fsub")\n}\npub fn instr_DC_5_mem_jit(ctx: &mut JitContext, modrm_byte: ModrmByte) {\n    instr_group_DC_mem_jit(ctx, modrm_byte, "fpu_fsubr")\n}\npub fn instr_DC_5_reg_jit(ctx: &mut JitContext, r: u32) {\n    instr_group_DC_reg_jit(ctx, r, "fpu_fsubr")\n}\npub fn instr_DC_6_mem_jit(ctx: &mut JitContext, modrm_byte: ModrmByte) {\n    instr_group_DC_mem_jit(ctx, modrm_byte, "fpu_fdiv")\n}\npub fn instr_DC_6_reg_jit(ctx: &mut JitContext, r: u32) {\n    instr_group_DC_reg_jit(ctx, r, "fpu_fdiv")\n}\npub fn instr_DC_7_mem_jit(ctx: &mut JitContext, modrm_byte: ModrmByte) {\n    instr_group_DC_mem_jit(ctx, modrm_byte, "fpu_fdivr")\n}\npub fn instr_DC_7_reg_jit(ctx: &mut JitContext, r: u32) {\n    instr_group_DC_reg_jit(ctx, r, "fpu_fdivr")\n}\n\npub fn instr16_DD_0_mem_jit(ctx: &mut JitContext, modrm_byte: ModrmByte) {\n    codegen::gen_fpu_load_m64(ctx, modrm_byte);\n    ctx.builder.call_fn2_i64_i32("fpu_push");\n}\npub fn instr16_DD_0_reg_jit(ctx: &mut JitContext, r: u32) {\n    codegen::gen_fn1_const(ctx.builder, "fpu_ffree", r);\n}\npub fn instr32_DD_0_reg_jit(ctx: &mut JitContext, r: u32) { instr16_DD_0_reg_jit(ctx, r) }\npub fn instr32_DD_0_mem_jit(ctx: &mut JitContext, modrm_byte: ModrmByte) {\n    instr16_DD_0_mem_jit(ctx, modrm_byte)\n}\n\npub fn instr16_DD_2_mem_jit(ctx: &mut JitContext, modrm_byte: ModrmByte) {\n    codegen::gen_modrm_resolve(ctx, modrm_byte);\n    let address_local = ctx.builder.set_new_local();\n    codegen::gen_fpu_get_sti(ctx, 0);\n    ctx.builder.call_fn2_i64_i32_ret_i64("f80_to_f64");\n    let value_local = ctx.builder.set_new_local_i64();\n    codegen::gen_safe_write64(ctx, &address_local, &value_local);\n    ctx.builder.free_local(address_local);\n    ctx.builder.free_local_i64(value_local);\n}\npub fn instr16_DD_2_reg_jit(ctx: &mut JitContext, r: u32) {\n    codegen::gen_fn1_const(ctx.builder, "fpu_fst", r);\n}\npub fn instr32_DD_2_reg_jit(ctx: &mut JitContext, r: u32) { instr16_DD_2_reg_jit(ctx, r) }\npub fn instr32_DD_2_mem_jit(ctx: &mut JitContext, modrm_byte: ModrmByte) {\n    instr16_DD_2_mem_jit(ctx, modrm_byte)\n}\n\npub fn instr16_DD_3_mem_jit(ctx: &mut JitContext, modrm_byte: ModrmByte) {\n    codegen::gen_modrm_resolve(ctx, modrm_byte);\n    let address_local = ctx.builder.set_new_local();\n    codegen::gen_fpu_get_sti(ctx, 0);\n    ctx.builder.call_fn2_i64_i32_ret_i64("f80_to_f64");\n    let value_local = ctx.builder.set_new_local_i64();\n    codegen::gen_safe_write64(ctx, &address_local, &value_local);\n    codegen::gen_fn0_const(ctx.builder, "fpu_pop");\n    ctx.builder.free_local(address_local);\n    ctx.builder.free_local_i64(value_local);\n}\npub fn instr16_DD_3_reg_jit(ctx: &mut JitContext, r: u32) {\n    codegen::gen_fn1_const(ctx.builder, "fpu_fstp", r);\n}\npub fn instr32_DD_3_reg_jit(ctx: &mut JitContext, r: u32) { instr16_DD_3_reg_jit(ctx, r) }\npub fn instr32_DD_3_mem_jit(ctx: &mut JitContext, modrm_byte: ModrmByte) {\n    instr16_DD_3_mem_jit(ctx, modrm_byte)\n}\n\npub fn instr16_DD_5_mem_jit(ctx: &mut JitContext, modrm_byte: ModrmByte) {\n    codegen::gen_modrm_resolve(ctx, modrm_byte);\n    codegen::gen_trigger_ud(ctx);\n}\npub fn instr16_DD_5_reg_jit(ctx: &mut JitContext, r: u32) {\n    ctx.builder.const_i32(r as i32);\n    ctx.builder.call_fn1("fpu_fucomp");\n}\npub fn instr32_DD_5_reg_jit(ctx: &mut JitContext, r: u32) { instr16_DD_5_reg_jit(ctx, r) }\npub fn instr32_DD_5_mem_jit(ctx: &mut JitContext, modrm_byte: ModrmByte) {\n    instr16_DD_5_mem_jit(ctx, modrm_byte)\n}\n\nfn instr_group_DE_mem_jit(ctx: &mut JitContext, modrm_byte: ModrmByte, op: &str) {\n    ctx.builder.const_i32(0);\n    codegen::gen_fpu_load_i16(ctx, modrm_byte);\n    ctx.builder.call_fn3_i32_i64_i32(op)\n}\nfn instr_group_DE_reg_jit(ctx: &mut JitContext, r: u32, op: &str) {\n    ctx.builder.const_i32(r as i32);\n    codegen::gen_fpu_get_sti(ctx, r);\n    ctx.builder.call_fn3_i32_i64_i32(op);\n    codegen::gen_fn0_const(ctx.builder, "fpu_pop")\n}\n\npub fn instr_DE_0_mem_jit(ctx: &mut JitContext, modrm_byte: ModrmByte) {\n    instr_group_DE_mem_jit(ctx, modrm_byte, "fpu_fadd")\n}\npub fn instr_DE_0_reg_jit(ctx: &mut JitContext, r: u32) {\n    instr_group_DE_reg_jit(ctx, r, "fpu_fadd")\n}\npub fn instr_DE_1_mem_jit(ctx: &mut JitContext, modrm_byte: ModrmByte) {\n    instr_group_DE_mem_jit(ctx, modrm_byte, "fpu_fmul")\n}\npub fn instr_DE_1_reg_jit(ctx: &mut JitContext, r: u32) {\n    instr_group_DE_reg_jit(ctx, r, "fpu_fmul")\n}\npub fn instr_DE_2_mem_jit(ctx: &mut JitContext, modrm_byte: ModrmByte) {\n    codegen::gen_fpu_load_i16(ctx, modrm_byte);\n    ctx.builder.call_fn2_i64_i32("fpu_fcom")\n}\npub fn instr_DE_2_reg_jit(ctx: &mut JitContext, r: u32) {\n    codegen::gen_fpu_get_sti(ctx, r);\n    ctx.builder.call_fn2_i64_i32("fpu_fcom");\n    codegen::gen_fn0_const(ctx.builder, "fpu_pop")\n}\npub fn instr_DE_3_mem_jit(ctx: &mut JitContext, modrm_byte: ModrmByte) {\n    codegen::gen_fpu_load_i16(ctx, modrm_byte);\n    ctx.builder.call_fn2_i64_i32("fpu_fcomp")\n}\npub fn instr_DE_3_reg_jit(ctx: &mut JitContext, r: u32) {\n    if r == 1 {\n        codegen::gen_fpu_get_sti(ctx, r);\n        ctx.builder.call_fn2_i64_i32("fpu_fcomp");\n        codegen::gen_fn0_const(ctx.builder, "fpu_pop")\n    }\n    else {\n        codegen::gen_trigger_ud(ctx);\n    }\n}\npub fn instr_DE_4_mem_jit(ctx: &mut JitContext, modrm_byte: ModrmByte) {\n    instr_group_DE_mem_jit(ctx, modrm_byte, "fpu_fsub")\n}\npub fn instr_DE_4_reg_jit(ctx: &mut JitContext, r: u32) {\n    instr_group_DE_reg_jit(ctx, r, "fpu_fsub")\n}\npub fn instr_DE_5_mem_jit(ctx: &mut JitContext, modrm_byte: ModrmByte) {\n    instr_group_DE_mem_jit(ctx, modrm_byte, "fpu_fsubr")\n}\npub fn instr_DE_5_reg_jit(ctx: &mut JitContext, r: u32) {\n    instr_group_DE_reg_jit(ctx, r, "fpu_fsubr")\n}\npub fn instr_DE_6_mem_jit(ctx: &mut JitContext, modrm_byte: ModrmByte) {\n    instr_group_DE_mem_jit(ctx, modrm_byte, "fpu_fdiv")\n}\npub fn instr_DE_6_reg_jit(ctx: &mut JitContext, r: u32) {\n    instr_group_DE_reg_jit(ctx, r, "fpu_fdiv")\n}\npub fn instr_DE_7_mem_jit(ctx: &mut JitContext, modrm_byte: ModrmByte) {\n    instr_group_DE_mem_jit(ctx, modrm_byte, "fpu_fdivr")\n}\npub fn instr_DE_7_reg_jit(ctx: &mut JitContext, r: u32) {\n    instr_group_DE_reg_jit(ctx, r, "fpu_fdivr")\n}\n\npub fn instr_DF_2_mem_jit(ctx: &mut JitContext, modrm_byte: ModrmByte) {\n    codegen::gen_modrm_resolve(ctx, modrm_byte);\n    let address_local = ctx.builder.set_new_local();\n    codegen::gen_fpu_get_sti(ctx, 0);\n    ctx.builder.call_fn2_i64_i32_ret("fpu_convert_to_i16");\n    let value_local = ctx.builder.set_new_local();\n    codegen::gen_safe_write16(ctx, &address_local, &value_local);\n    ctx.builder.free_local(address_local);\n    ctx.builder.free_local(value_local);\n}\npub fn instr_DF_2_reg_jit(ctx: &mut JitContext, r: u32) {\n    codegen::gen_fn1_const(ctx.builder, "fpu_fstp", r);\n}\npub fn instr_DF_3_mem_jit(ctx: &mut JitContext, modrm_byte: ModrmByte) {\n    codegen::gen_modrm_resolve(ctx, modrm_byte);\n    let address_local = ctx.builder.set_new_local();\n    codegen::gen_fpu_get_sti(ctx, 0);\n    ctx.builder.call_fn2_i64_i32_ret("fpu_convert_to_i16");\n    let value_local = ctx.builder.set_new_local();\n    codegen::gen_safe_write16(ctx, &address_local, &value_local);\n    ctx.builder.free_local(address_local);\n    ctx.builder.free_local(value_local);\n    codegen::gen_fn0_const(ctx.builder, "fpu_pop");\n}\npub fn instr_DF_3_reg_jit(ctx: &mut JitContext, r: u32) {\n    codegen::gen_fn1_const(ctx.builder, "fpu_fstp", r);\n}\n\npub fn instr_DF_4_mem_jit(ctx: &mut JitContext, modrm_byte: ModrmByte) {\n    dbg_log!("fbld");\n    codegen::gen_modrm_resolve(ctx, modrm_byte);\n    codegen::gen_trigger_ud(ctx);\n}\npub fn instr_DF_4_reg_jit(ctx: &mut JitContext, r: u32) {\n    if r == 0 {\n        ctx.builder.call_fn0_ret("fpu_load_status_word");\n        codegen::gen_set_reg16(ctx, regs::AX);\n    }\n    else {\n        codegen::gen_trigger_ud(ctx);\n    };\n}\n\npub fn instr_DF_5_mem_jit(ctx: &mut JitContext, modrm_byte: ModrmByte) {\n    codegen::gen_fpu_load_i64(ctx, modrm_byte);\n    ctx.builder.call_fn2_i64_i32("fpu_push");\n}\npub fn instr_DF_5_reg_jit(ctx: &mut JitContext, r: u32) {\n    codegen::gen_fn1_const(ctx.builder, "fpu_fucomip", r);\n}\n\npub fn instr_DF_6_mem_jit(ctx: &mut JitContext, modrm_byte: ModrmByte) {\n    codegen::gen_modrm_resolve(ctx, modrm_byte);\n\n    codegen::gen_set_previous_eip_offset_from_eip_with_low_bits(\n        ctx.builder,\n        ctx.start_of_current_instruction as i32 & 0xFFF,\n    );\n\n    codegen::gen_move_registers_from_locals_to_memory(ctx);\n    ctx.builder.call_fn1("fpu_fbstp");\n    codegen::gen_move_registers_from_memory_to_locals(ctx);\n\n    codegen::gen_get_page_fault(ctx.builder);\n    ctx.builder.if_void();\n    codegen::gen_debug_track_jit_exit(ctx.builder, ctx.start_of_current_instruction);\n    ctx.builder.br(ctx.exit_label);\n    ctx.builder.block_end();\n}\npub fn instr_DF_6_reg_jit(ctx: &mut JitContext, r: u32) {\n    ctx.builder.const_i32(r as i32);\n    ctx.builder.call_fn1("fpu_fcomip");\n}\n\npub fn instr_DF_7_reg_jit(ctx: &mut JitContext, _r: u32) { codegen::gen_trigger_ud(ctx); }\npub fn instr_DF_7_mem_jit(ctx: &mut JitContext, modrm_byte: ModrmByte) {\n    codegen::gen_modrm_resolve(ctx, modrm_byte);\n    let address_local = ctx.builder.set_new_local();\n    codegen::gen_fpu_get_sti(ctx, 0);\n    ctx.builder.call_fn2_i64_i32_ret_i64("fpu_convert_to_i64");\n    let value_local = ctx.builder.set_new_local_i64();\n    codegen::gen_safe_write64(ctx, &address_local, &value_local);\n    ctx.builder.free_local(address_local);\n    ctx.builder.free_local_i64(value_local);\n    codegen::gen_fn0_const(ctx.builder, "fpu_pop");\n}\n\npub fn instr16_EB_jit(_ctx: &mut JitContext, _imm8: u32) {\n    //\n}\n\npub fn instr32_EB_jit(_ctx: &mut JitContext, _imm8: u32) {\n    // jmp near\n}\n\ndefine_instruction_read8!(gen_test8, instr_F6_0_mem_jit, instr_F6_0_reg_jit, imm8);\ndefine_instruction_read16!(\n    gen_test16,\n    instr16_F7_0_mem_jit,\n    instr16_F7_0_reg_jit,\n    imm16\n);\ndefine_instruction_read32!(\n    gen_test32,\n    instr32_F7_0_mem_jit,\n    instr32_F7_0_reg_jit,\n    imm32\n);\n\npub fn instr_F6_1_mem_jit(ctx: &mut JitContext, modrm_byte: ModrmByte, imm: u32) {\n    instr_F6_0_mem_jit(ctx, modrm_byte, imm)\n}\npub fn instr_F6_1_reg_jit(ctx: &mut JitContext, r: u32, imm: u32) {\n    instr_F6_0_reg_jit(ctx, r, imm)\n}\npub fn instr16_F7_1_mem_jit(ctx: &mut JitContext, modrm_byte: ModrmByte, imm: u32) {\n    instr16_F7_0_mem_jit(ctx, modrm_byte, imm)\n}\npub fn instr16_F7_1_reg_jit(ctx: &mut JitContext, r: u32, imm: u32) {\n    instr16_F7_0_reg_jit(ctx, r, imm)\n}\npub fn instr32_F7_1_mem_jit(ctx: &mut JitContext, modrm_byte: ModrmByte, imm: u32) {\n    instr32_F7_0_mem_jit(ctx, modrm_byte, imm)\n}\npub fn instr32_F7_1_reg_jit(ctx: &mut JitContext, r: u32, imm: u32) {\n    instr32_F7_0_reg_jit(ctx, r, imm)\n}\n\ndefine_instruction_read_write_mem8!("not8", instr_F6_2_mem_jit, instr_F6_2_reg_jit, none);\ndefine_instruction_read_write_mem8!("neg8", instr_F6_3_mem_jit, instr_F6_3_reg_jit, none);\n\ndefine_instruction_read_write_mem16!(gen_not16, instr16_F7_2_mem_jit, instr16_F7_2_reg_jit, none);\ndefine_instruction_read_write_mem32!(gen_not32, instr32_F7_2_mem_jit, instr32_F7_2_reg_jit, none);\ndefine_instruction_read_write_mem16!(gen_neg16, instr16_F7_3_mem_jit, instr16_F7_3_reg_jit, none);\ndefine_instruction_read_write_mem32!(gen_neg32, instr32_F7_3_mem_jit, instr32_F7_3_reg_jit, none);\n\npub fn instr16_F7_4_mem_jit(ctx: &mut JitContext, modrm_byte: ModrmByte) {\n    codegen::gen_modrm_resolve_safe_read16(ctx, modrm_byte);\n    codegen::gen_move_registers_from_locals_to_memory(ctx);\n    ctx.builder.call_fn1("mul16");\n    codegen::gen_move_registers_from_memory_to_locals(ctx);\n}\npub fn instr16_F7_4_reg_jit(ctx: &mut JitContext, r: u32) {\n    codegen::gen_get_reg16(ctx, r);\n    codegen::gen_move_registers_from_locals_to_memory(ctx);\n    ctx.builder.call_fn1("mul16");\n    codegen::gen_move_registers_from_memory_to_locals(ctx);\n}\npub fn instr32_F7_4_mem_jit(ctx: &mut JitContext, modrm_byte: ModrmByte) {\n    codegen::gen_modrm_resolve_safe_read32(ctx, modrm_byte);\n    gen_mul32(ctx);\n}\npub fn instr32_F7_4_reg_jit(ctx: &mut JitContext, r: u32) {\n    codegen::gen_get_reg32(ctx, r);\n    gen_mul32(ctx);\n}\n\npub fn instr16_F7_5_mem_jit(ctx: &mut JitContext, modrm_byte: ModrmByte) {\n    codegen::gen_modrm_resolve_safe_read16(ctx, modrm_byte);\n    codegen::sign_extend_i16(ctx.builder);\n    codegen::gen_move_registers_from_locals_to_memory(ctx);\n    ctx.builder.call_fn1("imul16");\n    codegen::gen_move_registers_from_memory_to_locals(ctx);\n}\npub fn instr16_F7_5_reg_jit(ctx: &mut JitContext, r: u32) {\n    codegen::gen_get_reg16(ctx, r);\n    codegen::sign_extend_i16(ctx.builder);\n    codegen::gen_move_registers_from_locals_to_memory(ctx);\n    ctx.builder.call_fn1("imul16");\n    codegen::gen_move_registers_from_memory_to_locals(ctx);\n}\npub fn instr32_F7_5_mem_jit(ctx: &mut JitContext, modrm_byte: ModrmByte) {\n    codegen::gen_modrm_resolve_safe_read32(ctx, modrm_byte);\n    gen_imul32(ctx);\n}\npub fn instr32_F7_5_reg_jit(ctx: &mut JitContext, r: u32) {\n    codegen::gen_get_reg32(ctx, r);\n    gen_imul32(ctx);\n}\n\npub fn instr16_F7_6_mem_jit(ctx: &mut JitContext, modrm_byte: ModrmByte) {\n    codegen::gen_modrm_resolve_safe_read16(ctx, modrm_byte);\n    codegen::gen_move_registers_from_locals_to_memory(ctx);\n    ctx.builder.call_fn1_ret("div16_without_fault");\n    codegen::gen_move_registers_from_memory_to_locals(ctx);\n    ctx.builder.eqz_i32();\n    ctx.builder.if_void();\n    codegen::gen_trigger_de(ctx);\n    ctx.builder.block_end();\n}\npub fn instr16_F7_6_reg_jit(ctx: &mut JitContext, r: u32) {\n    codegen::gen_get_reg16(ctx, r);\n    codegen::gen_move_registers_from_locals_to_memory(ctx);\n    ctx.builder.call_fn1_ret("div16_without_fault");\n    codegen::gen_move_registers_from_memory_to_locals(ctx);\n    ctx.builder.eqz_i32();\n    ctx.builder.if_void();\n    codegen::gen_trigger_de(ctx);\n    ctx.builder.block_end();\n}\n\npub fn instr32_F7_6_mem_jit(ctx: &mut JitContext, modrm_byte: ModrmByte) {\n    if false {\n        codegen::gen_modrm_resolve_safe_read32(ctx, modrm_byte);\n        codegen::gen_move_registers_from_locals_to_memory(ctx);\n        ctx.builder.call_fn1_ret("div32_without_fault");\n        codegen::gen_move_registers_from_memory_to_locals(ctx);\n        ctx.builder.eqz_i32();\n        ctx.builder.if_void();\n        codegen::gen_trigger_de(ctx);\n        ctx.builder.block_end();\n    }\n    else {\n        codegen::gen_modrm_resolve_safe_read32(ctx, modrm_byte);\n        let source_operand = ctx.builder.set_new_local();\n        gen_div32(ctx, &source_operand);\n        ctx.builder.free_local(source_operand);\n    }\n}\npub fn instr32_F7_6_reg_jit(ctx: &mut JitContext, r: u32) {\n    if false {\n        codegen::gen_get_reg32(ctx, r);\n        codegen::gen_move_registers_from_locals_to_memory(ctx);\n        ctx.builder.call_fn1_ret("div32_without_fault");\n        codegen::gen_move_registers_from_memory_to_locals(ctx);\n        ctx.builder.eqz_i32();\n        ctx.builder.if_void();\n        codegen::gen_trigger_de(ctx);\n        ctx.builder.block_end();\n    }\n    else {\n        gen_div32(ctx, &ctx.reg(r));\n    }\n}\n\npub fn instr16_F7_7_mem_jit(ctx: &mut JitContext, modrm_byte: ModrmByte) {\n    codegen::gen_modrm_resolve_safe_read16(ctx, modrm_byte);\n    codegen::sign_extend_i16(ctx.builder);\n    codegen::gen_move_registers_from_locals_to_memory(ctx);\n    ctx.builder.call_fn1_ret("idiv16_without_fault");\n    codegen::gen_move_registers_from_memory_to_locals(ctx);\n    ctx.builder.eqz_i32();\n    ctx.builder.if_void();\n    codegen::gen_trigger_de(ctx);\n    ctx.builder.block_end();\n}\npub fn instr16_F7_7_reg_jit(ctx: &mut JitContext, r: u32) {\n    codegen::gen_get_reg16(ctx, r);\n    codegen::sign_extend_i16(ctx.builder);\n    codegen::gen_move_registers_from_locals_to_memory(ctx);\n    ctx.builder.call_fn1_ret("idiv16_without_fault");\n    codegen::gen_move_registers_from_memory_to_locals(ctx);\n    ctx.builder.eqz_i32();\n    ctx.builder.if_void();\n    codegen::gen_trigger_de(ctx);\n    ctx.builder.block_end();\n}\npub fn instr32_F7_7_mem_jit(ctx: &mut JitContext, modrm_byte: ModrmByte) {\n    codegen::gen_modrm_resolve_safe_read32(ctx, modrm_byte);\n    codegen::gen_move_registers_from_locals_to_memory(ctx);\n    ctx.builder.call_fn1_ret("idiv32_without_fault");\n    codegen::gen_move_registers_from_memory_to_locals(ctx);\n    ctx.builder.eqz_i32();\n    ctx.builder.if_void();\n    codegen::gen_trigger_de(ctx);\n    ctx.builder.block_end();\n}\npub fn instr32_F7_7_reg_jit(ctx: &mut JitContext, r: u32) {\n    codegen::gen_get_reg32(ctx, r);\n    codegen::gen_move_registers_from_locals_to_memory(ctx);\n    ctx.builder.call_fn1_ret("idiv32_without_fault");\n    codegen::gen_move_registers_from_memory_to_locals(ctx);\n    ctx.builder.eqz_i32();\n    ctx.builder.if_void();\n    codegen::gen_trigger_de(ctx);\n    ctx.builder.block_end();\n}\n\npub fn instr_F8_jit(ctx: &mut JitContext) {\n    codegen::gen_clear_flags_changed_bits(ctx.builder, 1);\n    codegen::gen_clear_flags_bits(ctx.builder, 1);\n}\npub fn instr_F9_jit(ctx: &mut JitContext) {\n    codegen::gen_clear_flags_changed_bits(ctx.builder, 1);\n    codegen::gen_set_flags_bits(ctx.builder, 1);\n}\n\npub fn instr_FA_jit(ctx: &mut JitContext) {\n    ctx.builder.call_fn0_ret("instr_FA_without_fault");\n    ctx.builder.eqz_i32();\n    ctx.builder.if_void();\n    codegen::gen_trigger_gp(ctx, 0);\n    ctx.builder.block_end();\n}\n\npub fn instr_FB_jit(ctx: &mut JitContext) {\n    ctx.builder.call_fn0_ret("instr_FB_without_fault");\n    ctx.builder.eqz_i32();\n    ctx.builder.if_void();\n    codegen::gen_trigger_gp(ctx, 0);\n    ctx.builder.block_end();\n    // handle_irqs is specially handled in jit to be called one instruction after this one\n}\n\npub fn instr_FC_jit(ctx: &mut JitContext) {\n    ctx.builder.const_i32(global_pointers::flags as i32);\n    codegen::gen_get_flags(ctx.builder);\n    ctx.builder.const_i32(!FLAG_DIRECTION);\n    ctx.builder.and_i32();\n    ctx.builder.store_aligned_i32(0);\n}\n\npub fn instr_FD_jit(ctx: &mut JitContext) {\n    ctx.builder.const_i32(global_pointers::flags as i32);\n    codegen::gen_get_flags(ctx.builder);\n    ctx.builder.const_i32(FLAG_DIRECTION);\n    ctx.builder.or_i32();\n    ctx.builder.store_aligned_i32(0);\n}\n\ndefine_instruction_read_write_mem8!("inc8", instr_FE_0_mem_jit, instr_FE_0_reg_jit, none);\ndefine_instruction_read_write_mem8!("dec8", instr_FE_1_mem_jit, instr_FE_1_reg_jit, none);\n\ndefine_instruction_read_write_mem16!(gen_inc16, instr16_FF_0_mem_jit, instr16_FF_0_reg_jit, none);\ndefine_instruction_read_write_mem32!(gen_inc32, instr32_FF_0_mem_jit, instr32_FF_0_reg_jit, none);\n\ndefine_instruction_read_write_mem16!(gen_dec16, instr16_FF_1_mem_jit, instr16_FF_1_reg_jit, none);\ndefine_instruction_read_write_mem32!(gen_dec32, instr32_FF_1_mem_jit, instr32_FF_1_reg_jit, none);\n\npub fn instr16_FF_2_mem_jit(ctx: &mut JitContext, modrm_byte: ModrmByte) {\n    codegen::gen_modrm_resolve_safe_read16(ctx, modrm_byte);\n    codegen::gen_add_cs_offset(ctx);\n    let new_eip = ctx.builder.set_new_local();\n\n    codegen::gen_get_real_eip(ctx);\n    let value_local = ctx.builder.set_new_local();\n    codegen::gen_push16(ctx, &value_local);\n    ctx.builder.free_local(value_local);\n\n    ctx.builder.const_i32(0);\n    ctx.builder.get_local(&new_eip);\n    ctx.builder\n        .store_aligned_i32(global_pointers::instruction_pointer as u32);\n    ctx.builder.free_local(new_eip);\n}\npub fn instr16_FF_2_reg_jit(ctx: &mut JitContext, r: u32) {\n    codegen::gen_get_real_eip(ctx);\n    let value_local = ctx.builder.set_new_local();\n    codegen::gen_push16(ctx, &value_local);\n    ctx.builder.free_local(value_local);\n\n    ctx.builder.const_i32(0);\n    codegen::gen_get_reg16(ctx, r);\n    codegen::gen_add_cs_offset(ctx);\n    ctx.builder\n        .store_aligned_i32(global_pointers::instruction_pointer as u32);\n}\npub fn instr32_FF_2_mem_jit(ctx: &mut JitContext, modrm_byte: ModrmByte) {\n    codegen::gen_modrm_resolve_safe_read32(ctx, modrm_byte);\n    codegen::gen_add_cs_offset(ctx);\n    let new_eip = ctx.builder.set_new_local();\n\n    codegen::gen_get_real_eip(ctx);\n    let value_local = ctx.builder.set_new_local();\n    codegen::gen_push32(ctx, &value_local);\n    ctx.builder.free_local(value_local);\n\n    ctx.builder.const_i32(0);\n    ctx.builder.get_local(&new_eip);\n    ctx.builder\n        .store_aligned_i32(global_pointers::instruction_pointer as u32);\n    ctx.builder.free_local(new_eip);\n}\npub fn instr32_FF_2_reg_jit(ctx: &mut JitContext, r: u32) {\n    codegen::gen_get_real_eip(ctx);\n    let value_local = ctx.builder.set_new_local();\n    codegen::gen_push32(ctx, &value_local);\n    ctx.builder.free_local(value_local);\n\n    ctx.builder.const_i32(0);\n    codegen::gen_get_reg32(ctx, r);\n    codegen::gen_add_cs_offset(ctx);\n    ctx.builder\n        .store_aligned_i32(global_pointers::instruction_pointer as u32);\n}\n\npub fn instr16_FF_4_mem_jit(ctx: &mut JitContext, modrm_byte: ModrmByte) {\n    ctx.builder.const_i32(0);\n    codegen::gen_modrm_resolve_safe_read16(ctx, modrm_byte);\n    codegen::gen_add_cs_offset(ctx);\n    ctx.builder\n        .store_aligned_i32(global_pointers::instruction_pointer as u32);\n}\npub fn instr16_FF_4_reg_jit(ctx: &mut JitContext, r: u32) {\n    ctx.builder.const_i32(0);\n    codegen::gen_get_reg16(ctx, r);\n    codegen::gen_add_cs_offset(ctx);\n    ctx.builder\n        .store_aligned_i32(global_pointers::instruction_pointer as u32);\n}\npub fn instr32_FF_4_mem_jit(ctx: &mut JitContext, modrm_byte: ModrmByte) {\n    ctx.builder.const_i32(0);\n    codegen::gen_modrm_resolve_safe_read32(ctx, modrm_byte);\n    codegen::gen_add_cs_offset(ctx);\n    ctx.builder\n        .store_aligned_i32(global_pointers::instruction_pointer as u32);\n}\npub fn instr32_FF_4_reg_jit(ctx: &mut JitContext, r: u32) {\n    ctx.builder.const_i32(0);\n    codegen::gen_get_reg32(ctx, r);\n    codegen::gen_add_cs_offset(ctx);\n    ctx.builder\n        .store_aligned_i32(global_pointers::instruction_pointer as u32);\n}\n\npub fn instr16_FF_6_mem_jit(ctx: &mut JitContext, modrm_byte: ModrmByte) {\n    push16_mem_jit(ctx, modrm_byte)\n}\npub fn instr16_FF_6_reg_jit(ctx: &mut JitContext, r: u32) { push16_reg_jit(ctx, r) }\npub fn instr32_FF_6_mem_jit(ctx: &mut JitContext, modrm_byte: ModrmByte) {\n    push32_mem_jit(ctx, modrm_byte)\n}\npub fn instr32_FF_6_reg_jit(ctx: &mut JitContext, r: u32) { push32_reg_jit(ctx, r) }\n\n// Code for conditional jumps is generated automatically by the basic block codegen\npub fn instr16_0F80_jit(_ctx: &mut JitContext, _imm: u32) {}\npub fn instr16_0F81_jit(_ctx: &mut JitContext, _imm: u32) {}\npub fn instr16_0F82_jit(_ctx: &mut JitContext, _imm: u32) {}\npub fn instr16_0F83_jit(_ctx: &mut JitContext, _imm: u32) {}\npub fn instr16_0F84_jit(_ctx: &mut JitContext, _imm: u32) {}\npub fn instr16_0F85_jit(_ctx: &mut JitContext, _imm: u32) {}\npub fn instr16_0F86_jit(_ctx: &mut JitContext, _imm: u32) {}\npub fn instr16_0F87_jit(_ctx: &mut JitContext, _imm: u32) {}\npub fn instr16_0F88_jit(_ctx: &mut JitContext, _imm: u32) {}\npub fn instr16_0F89_jit(_ctx: &mut JitContext, _imm: u32) {}\npub fn instr16_0F8A_jit(_ctx: &mut JitContext, _imm: u32) {}\npub fn instr16_0F8B_jit(_ctx: &mut JitContext, _imm: u32) {}\npub fn instr16_0F8C_jit(_ctx: &mut JitContext, _imm: u32) {}\npub fn instr16_0F8D_jit(_ctx: &mut JitContext, _imm: u32) {}\npub fn instr16_0F8E_jit(_ctx: &mut JitContext, _imm: u32) {}\npub fn instr16_0F8F_jit(_ctx: &mut JitContext, _imm: u32) {}\npub fn instr32_0F80_jit(_ctx: &mut JitContext, _imm: u32) {}\npub fn instr32_0F81_jit(_ctx: &mut JitContext, _imm: u32) {}\npub fn instr32_0F82_jit(_ctx: &mut JitContext, _imm: u32) {}\npub fn instr32_0F83_jit(_ctx: &mut JitContext, _imm: u32) {}\npub fn instr32_0F84_jit(_ctx: &mut JitContext, _imm: u32) {}\npub fn instr32_0F85_jit(_ctx: &mut JitContext, _imm: u32) {}\npub fn instr32_0F86_jit(_ctx: &mut JitContext, _imm: u32) {}\npub fn instr32_0F87_jit(_ctx: &mut JitContext, _imm: u32) {}\npub fn instr32_0F88_jit(_ctx: &mut JitContext, _imm: u32) {}\npub fn instr32_0F89_jit(_ctx: &mut JitContext, _imm: u32) {}\npub fn instr32_0F8A_jit(_ctx: &mut JitContext, _imm: u32) {}\npub fn instr32_0F8B_jit(_ctx: &mut JitContext, _imm: u32) {}\npub fn instr32_0F8C_jit(_ctx: &mut JitContext, _imm: u32) {}\npub fn instr32_0F8D_jit(_ctx: &mut JitContext, _imm: u32) {}\npub fn instr32_0F8E_jit(_ctx: &mut JitContext, _imm: u32) {}\npub fn instr32_0F8F_jit(_ctx: &mut JitContext, _imm: u32) {}\n\npub fn instr_90_jit(_ctx: &mut JitContext) {}\n\nfn gen_xchg_reg16(ctx: &mut JitContext, r: u32) {\n    codegen::gen_get_reg16(ctx, r);\n    let tmp = ctx.builder.set_new_local();\n    codegen::gen_get_reg16(ctx, regs::AX);\n    codegen::gen_set_reg16(ctx, r);\n    ctx.builder.get_local(&tmp);\n    codegen::gen_set_reg16(ctx, regs::AX);\n    ctx.builder.free_local(tmp);\n}\n\nfn gen_xchg_reg32(ctx: &mut JitContext, r: u32) {\n    codegen::gen_get_reg32(ctx, r);\n    let tmp = ctx.builder.set_new_local();\n    codegen::gen_get_reg32(ctx, regs::EAX);\n    codegen::gen_set_reg32(ctx, r);\n    ctx.builder.get_local(&tmp);\n    codegen::gen_set_reg32(ctx, regs::EAX);\n    ctx.builder.free_local(tmp);\n}\n\npub fn instr16_91_jit(ctx: &mut JitContext) { gen_xchg_reg16(ctx, regs::CX); }\npub fn instr16_92_jit(ctx: &mut JitContext) { gen_xchg_reg16(ctx, regs::DX); }\npub fn instr16_93_jit(ctx: &mut JitContext) { gen_xchg_reg16(ctx, regs::BX); }\npub fn instr16_94_jit(ctx: &mut JitContext) { gen_xchg_reg16(ctx, regs::SP); }\npub fn instr16_95_jit(ctx: &mut JitContext) { gen_xchg_reg16(ctx, regs::BP); }\npub fn instr16_96_jit(ctx: &mut JitContext) { gen_xchg_reg16(ctx, regs::SI); }\npub fn instr16_97_jit(ctx: &mut JitContext) { gen_xchg_reg16(ctx, regs::DI); }\n\npub fn instr32_91_jit(ctx: &mut JitContext) { gen_xchg_reg32(ctx, regs::CX); }\npub fn instr32_92_jit(ctx: &mut JitContext) { gen_xchg_reg32(ctx, regs::DX); }\npub fn instr32_93_jit(ctx: &mut JitContext) { gen_xchg_reg32(ctx, regs::BX); }\npub fn instr32_94_jit(ctx: &mut JitContext) { gen_xchg_reg32(ctx, regs::SP); }\npub fn instr32_95_jit(ctx: &mut JitContext) { gen_xchg_reg32(ctx, regs::BP); }\npub fn instr32_96_jit(ctx: &mut JitContext) { gen_xchg_reg32(ctx, regs::SI); }\npub fn instr32_97_jit(ctx: &mut JitContext) { gen_xchg_reg32(ctx, regs::DI); }\n\npub fn instr16_98_jit(ctx: &mut JitContext) {\n    codegen::gen_get_reg32(ctx, regs::EAX);\n    codegen::sign_extend_i8(ctx.builder);\n    codegen::gen_set_reg16(ctx, regs::AX);\n}\npub fn instr32_98_jit(ctx: &mut JitContext) {\n    codegen::gen_get_reg32(ctx, regs::EAX);\n    codegen::sign_extend_i16(ctx.builder);\n    codegen::gen_set_reg32(ctx, regs::EAX);\n}\n\npub fn instr16_99_jit(ctx: &mut JitContext) {\n    codegen::gen_get_reg16(ctx, regs::AX);\n    ctx.builder.const_i32(16);\n    ctx.builder.shl_i32();\n    ctx.builder.const_i32(31);\n    ctx.builder.shr_s_i32();\n    codegen::gen_set_reg16(ctx, regs::DX);\n}\npub fn instr32_99_jit(ctx: &mut JitContext) {\n    codegen::gen_get_reg32(ctx, regs::EAX);\n    ctx.builder.const_i32(31);\n    ctx.builder.shr_s_i32();\n    codegen::gen_set_reg32(ctx, regs::EDX);\n}\n\nfn gen_pushf_popf_check(ctx: &mut JitContext) {\n    // 0 != *flags & FLAG_VM && getiopl() < 3\n    codegen::gen_get_flags(ctx.builder);\n    ctx.builder.const_i32(FLAG_VM);\n    ctx.builder.and_i32();\n    ctx.builder.const_i32(FLAG_VM);\n    ctx.builder.eq_i32();\n    codegen::gen_get_flags(ctx.builder);\n    ctx.builder.const_i32(FLAG_IOPL);\n    ctx.builder.and_i32();\n    ctx.builder.const_i32(FLAG_IOPL);\n    ctx.builder.ne_i32();\n    ctx.builder.and_i32();\n}\n\npub fn instr16_9C_jit(ctx: &mut JitContext) {\n    gen_pushf_popf_check(ctx);\n    ctx.builder.if_void();\n    codegen::gen_trigger_gp(ctx, 0);\n    ctx.builder.else_();\n    ctx.builder.call_fn0_ret("get_eflags");\n    let value = ctx.builder.set_new_local();\n    codegen::gen_push16(ctx, &value);\n    ctx.builder.block_end();\n    ctx.builder.free_local(value);\n}\npub fn instr32_9C_jit(ctx: &mut JitContext) {\n    gen_pushf_popf_check(ctx);\n    ctx.builder.if_void();\n    codegen::gen_trigger_gp(ctx, 0);\n    ctx.builder.else_();\n    ctx.builder.call_fn0_ret("get_eflags");\n    ctx.builder.const_i32(0xFCFFFF);\n    ctx.builder.and_i32();\n    let value = ctx.builder.set_new_local();\n    codegen::gen_push32(ctx, &value);\n    ctx.builder.block_end();\n    ctx.builder.free_local(value);\n}\n\nfn gen_popf(ctx: &mut JitContext, is_32: bool) {\n    gen_pushf_popf_check(ctx);\n    ctx.builder.if_void();\n    codegen::gen_trigger_gp(ctx, 0);\n    ctx.builder.else_();\n\n    codegen::gen_get_flags(ctx.builder);\n    let old_eflags = ctx.builder.set_new_local();\n\n    if is_32 {\n        codegen::gen_pop32s(ctx);\n    }\n    else {\n        ctx.builder.get_local(&old_eflags);\n        ctx.builder.const_i32(!0xFFFF);\n        ctx.builder.and_i32();\n        codegen::gen_pop16(ctx);\n        ctx.builder.or_i32();\n    }\n\n    ctx.builder.call_fn1("update_eflags");\n\n    ctx.builder.get_local(&old_eflags);\n    ctx.builder.free_local(old_eflags);\n    ctx.builder.const_i32(FLAG_INTERRUPT);\n    ctx.builder.and_i32();\n    ctx.builder.eqz_i32();\n\n    codegen::gen_get_flags(ctx.builder);\n    ctx.builder.const_i32(FLAG_INTERRUPT);\n    ctx.builder.and_i32();\n    ctx.builder.eqz_i32();\n    ctx.builder.eqz_i32();\n\n    ctx.builder.and_i32();\n    ctx.builder.if_void();\n    {\n        codegen::gen_set_eip_to_after_current_instruction(ctx);\n        codegen::gen_debug_track_jit_exit(ctx.builder, ctx.start_of_current_instruction);\n        codegen::gen_move_registers_from_locals_to_memory(ctx);\n        codegen::gen_fn0_const(ctx.builder, "handle_irqs");\n\n        codegen::gen_update_instruction_counter(ctx);\n        ctx.builder.return_();\n    }\n    ctx.builder.block_end();\n\n    ctx.builder.block_end();\n}\n\npub fn instr16_9D_jit(ctx: &mut JitContext) { gen_popf(ctx, false) }\npub fn instr32_9D_jit(ctx: &mut JitContext) { gen_popf(ctx, true) }\n\npub fn instr_9E_jit(ctx: &mut JitContext) {\n    ctx.builder.const_i32(global_pointers::flags as i32);\n    codegen::gen_get_flags(ctx.builder);\n    ctx.builder.const_i32(!0xFF);\n    ctx.builder.and_i32();\n    codegen::gen_get_reg8(ctx, regs::AH);\n    ctx.builder.or_i32();\n    ctx.builder.const_i32(FLAGS_MASK);\n    ctx.builder.and_i32();\n    ctx.builder.const_i32(FLAGS_DEFAULT);\n    ctx.builder.or_i32();\n    ctx.builder.store_aligned_i32(0);\n\n    codegen::gen_clear_flags_changed_bits(ctx.builder, 0xFF);\n}\n\npub fn instr_9F_jit(ctx: &mut JitContext) {\n    ctx.builder.call_fn0_ret("get_eflags");\n    codegen::gen_set_reg8(ctx, regs::AH);\n}\n\npub fn instr_A0_jit(ctx: &mut JitContext, immaddr: u32) {\n    ctx.builder.const_i32(immaddr as i32);\n    jit_add_seg_offset(ctx, regs::DS);\n    let address_local = ctx.builder.set_new_local();\n    codegen::gen_safe_read8(ctx, &address_local);\n    ctx.builder.free_local(address_local);\n    codegen::gen_set_reg8(ctx, regs::AL);\n}\npub fn instr16_A1_jit(ctx: &mut JitContext, immaddr: u32) {\n    ctx.builder.const_i32(immaddr as i32);\n    jit_add_seg_offset(ctx, regs::DS);\n    let address_local = ctx.builder.set_new_local();\n    codegen::gen_safe_read16(ctx, &address_local);\n    ctx.builder.free_local(address_local);\n    codegen::gen_set_reg16(ctx, regs::AX);\n}\npub fn instr32_A1_jit(ctx: &mut JitContext, immaddr: u32) {\n    ctx.builder.const_i32(immaddr as i32);\n    jit_add_seg_offset(ctx, regs::DS);\n    let address_local = ctx.builder.set_new_local();\n    codegen::gen_safe_read32(ctx, &address_local);\n    ctx.builder.free_local(address_local);\n    codegen::gen_set_reg32(ctx, regs::EAX);\n}\n\npub fn instr_A2_jit(ctx: &mut JitContext, immaddr: u32) {\n    ctx.builder.const_i32(immaddr as i32);\n    jit_add_seg_offset(ctx, regs::DS);\n    let address_local = ctx.builder.set_new_local();\n    codegen::gen_safe_write8(ctx, &address_local, &ctx.reg(regs::EAX));\n    ctx.builder.free_local(address_local);\n}\npub fn instr16_A3_jit(ctx: &mut JitContext, immaddr: u32) {\n    ctx.builder.const_i32(immaddr as i32);\n    jit_add_seg_offset(ctx, regs::DS);\n    let address_local = ctx.builder.set_new_local();\n    codegen::gen_safe_write16(ctx, &address_local, &ctx.reg(regs::EAX));\n    ctx.builder.free_local(address_local);\n}\npub fn instr32_A3_jit(ctx: &mut JitContext, immaddr: u32) {\n    ctx.builder.const_i32(immaddr as i32);\n    jit_add_seg_offset(ctx, regs::DS);\n    let address_local = ctx.builder.set_new_local();\n    codegen::gen_safe_write32(ctx, &address_local, &ctx.reg(regs::EAX));\n    ctx.builder.free_local(address_local);\n}\n\npub fn instr_A8_jit(ctx: &mut JitContext, imm8: u32) {\n    gen_test8(ctx, &ctx.reg(0), &LocalOrImmediate::Immediate(imm8 as i32));\n}\n\npub fn instr16_A9_jit(ctx: &mut JitContext, imm16: u32) {\n    gen_test16(ctx, &ctx.reg(0), &LocalOrImmediate::Immediate(imm16 as i32));\n}\n\npub fn instr32_A9_jit(ctx: &mut JitContext, imm32: u32) {\n    gen_test32(ctx, &ctx.reg(0), &LocalOrImmediate::Immediate(imm32 as i32));\n}\n\n#[derive(PartialEq)]\nenum String {\n    INS,\n    OUTS,\n    MOVS,\n    CMPS,\n    STOS,\n    LODS,\n    SCAS,\n}\nfn gen_string_ins(ctx: &mut JitContext, ins: String, size: u8, prefix: u8) {\n    dbg_assert!(prefix == 0 || prefix == 0xF2 || prefix == 0xF3);\n    dbg_assert!(size == 8 || size == 16 || size == 32);\n\n    if prefix == 0 {\n        fn get_direction(ctx: &mut JitContext, size: u8) {\n            let bytes: i32 = (size / 8).into();\n            dbg_assert!(bytes == 1 || bytes == 2 || bytes == 4);\n            ctx.builder.const_i32(-bytes);\n            ctx.builder.const_i32(bytes);\n            codegen::gen_get_flags(ctx.builder);\n            ctx.builder.const_i32(FLAG_DIRECTION);\n            ctx.builder.and_i32();\n            ctx.builder.select();\n        }\n\n        match &ins {\n            String::LODS => {\n                if ctx.cpu.asize_32() {\n                    codegen::gen_get_reg32(ctx, regs::ESI);\n                }\n                else {\n                    codegen::gen_get_reg16(ctx, regs::ESI);\n                }\n                jit_add_seg_offset(ctx, regs::DS);\n                let address_local = ctx.builder.set_new_local();\n                if size == 8 {\n                    codegen::gen_safe_read8(ctx, &address_local);\n                    ctx.builder.free_local(address_local);\n                    codegen::gen_set_reg8_unmasked(ctx, regs::AL);\n                }\n                else if size == 16 {\n                    codegen::gen_safe_read16(ctx, &address_local);\n                    ctx.builder.free_local(address_local);\n                    codegen::gen_set_reg16(ctx, regs::AX);\n                }\n                else {\n                    codegen::gen_safe_read32(ctx, &address_local);\n                    ctx.builder.free_local(address_local);\n                    codegen::gen_set_reg32(ctx, regs::EAX);\n                }\n\n                codegen::gen_get_reg32(ctx, regs::ESI);\n                get_direction(ctx, size);\n                ctx.builder.add_i32();\n                if ctx.cpu.asize_32() {\n                    codegen::gen_set_reg32(ctx, regs::ESI);\n                }\n                else {\n                    codegen::gen_set_reg16(ctx, regs::ESI);\n                }\n                return;\n            },\n            String::SCAS => {\n                if ctx.cpu.asize_32() {\n                    codegen::gen_get_reg32(ctx, regs::EDI);\n                }\n                else {\n                    codegen::gen_get_reg16(ctx, regs::EDI);\n                }\n                jit_add_seg_offset_no_override(ctx, regs::ES);\n                let address_local = ctx.builder.set_new_local();\n                if size == 8 {\n                    codegen::gen_safe_read8(ctx, &address_local);\n                    ctx.builder.free_local(address_local);\n                    let value = ctx.builder.set_new_local();\n                    gen_cmp8(\n                        ctx,\n                        &ctx.reg(regs::EAX),\n                        &LocalOrImmediate::WasmLocal(&value),\n                    );\n                    ctx.builder.free_local(value);\n                }\n                else if size == 16 {\n                    codegen::gen_safe_read16(ctx, &address_local);\n                    ctx.builder.free_local(address_local);\n                    let value = ctx.builder.set_new_local();\n                    gen_cmp16(\n                        ctx,\n                        &ctx.reg(regs::EAX),\n                        &LocalOrImmediate::WasmLocal(&value),\n                    );\n                    ctx.builder.free_local(value);\n                }\n                else {\n                    codegen::gen_safe_read32(ctx, &address_local);\n                    ctx.builder.free_local(address_local);\n                    let value = ctx.builder.set_new_local();\n                    gen_cmp32(\n                        ctx,\n                        &ctx.reg(regs::EAX),\n                        &LocalOrImmediate::WasmLocal(&value),\n                    );\n                    ctx.builder.free_local(value);\n                }\n\n                codegen::gen_get_reg32(ctx, regs::EDI);\n                get_direction(ctx, size);\n                ctx.builder.add_i32();\n                if ctx.cpu.asize_32() {\n                    codegen::gen_set_reg32(ctx, regs::EDI);\n                }\n                else {\n                    codegen::gen_set_reg16(ctx, regs::EDI);\n                }\n                return;\n            },\n            String::STOS => {\n                if ctx.cpu.asize_32() {\n                    codegen::gen_get_reg32(ctx, regs::EDI);\n                }\n                else {\n                    codegen::gen_get_reg16(ctx, regs::EDI);\n                }\n                jit_add_seg_offset_no_override(ctx, regs::ES);\n                let address_local = ctx.builder.set_new_local();\n                if size == 8 {\n                    codegen::gen_safe_write8(ctx, &address_local, &ctx.reg(regs::AL));\n                    ctx.builder.free_local(address_local);\n                }\n                else if size == 16 {\n                    codegen::gen_safe_write16(ctx, &address_local, &ctx.reg(regs::AX));\n                    ctx.builder.free_local(address_local);\n                }\n                else {\n                    codegen::gen_safe_write32(ctx, &address_local, &ctx.reg(regs::EAX));\n                    ctx.builder.free_local(address_local);\n                }\n\n                codegen::gen_get_reg32(ctx, regs::EDI);\n                get_direction(ctx, size);\n                ctx.builder.add_i32();\n                if ctx.cpu.asize_32() {\n                    codegen::gen_set_reg32(ctx, regs::EDI);\n                }\n                else {\n                    codegen::gen_set_reg16(ctx, regs::EDI);\n                }\n                return;\n            },\n            String::MOVS => {\n                if ctx.cpu.asize_32() {\n                    codegen::gen_get_reg32(ctx, regs::EDI);\n                }\n                else {\n                    codegen::gen_get_reg16(ctx, regs::EDI);\n                }\n                jit_add_seg_offset_no_override(ctx, regs::ES);\n                let dest_address = ctx.builder.set_new_local();\n\n                if ctx.cpu.asize_32() {\n                    codegen::gen_get_reg32(ctx, regs::ESI);\n                }\n                else {\n                    codegen::gen_get_reg16(ctx, regs::ESI);\n                }\n                jit_add_seg_offset(ctx, regs::DS);\n                let source_address = ctx.builder.set_new_local();\n\n                if size == 8 {\n                    codegen::gen_safe_read8(ctx, &source_address);\n                    ctx.builder.free_local(source_address);\n                    let value = ctx.builder.set_new_local();\n                    codegen::gen_safe_write8(ctx, &dest_address, &value);\n                    ctx.builder.free_local(value);\n                }\n                else if size == 16 {\n                    codegen::gen_safe_read16(ctx, &source_address);\n                    ctx.builder.free_local(source_address);\n                    let value = ctx.builder.set_new_local();\n                    codegen::gen_safe_write16(ctx, &dest_address, &value);\n                    ctx.builder.free_local(value);\n                }\n                else {\n                    codegen::gen_safe_read32(ctx, &source_address);\n                    ctx.builder.free_local(source_address);\n                    let value = ctx.builder.set_new_local();\n                    codegen::gen_safe_write32(ctx, &dest_address, &value);\n                    ctx.builder.free_local(value);\n                }\n\n                ctx.builder.free_local(dest_address);\n\n                codegen::gen_get_reg32(ctx, regs::EDI);\n                get_direction(ctx, size);\n                ctx.builder.add_i32();\n                if ctx.cpu.asize_32() {\n                    codegen::gen_set_reg32(ctx, regs::EDI);\n                }\n                else {\n                    codegen::gen_set_reg16(ctx, regs::EDI);\n                }\n\n                codegen::gen_get_reg32(ctx, regs::ESI);\n                get_direction(ctx, size);\n                ctx.builder.add_i32();\n                if ctx.cpu.asize_32() {\n                    codegen::gen_set_reg32(ctx, regs::ESI);\n                }\n                else {\n                    codegen::gen_set_reg16(ctx, regs::ESI);\n                }\n                return;\n            },\n            _ => {},\n        }\n    }\n\n    let mut args = 0;\n    args += 1;\n    ctx.builder.const_i32(ctx.cpu.asize_32() as i32);\n\n    if ins == String::OUTS || ins == String::CMPS || ins == String::LODS || ins == String::MOVS {\n        args += 1;\n        ctx.builder.const_i32(0);\n        jit_add_seg_offset(ctx, regs::DS);\n    }\n\n    let name = format!(\n        "{}{}{}",\n        match ins {\n            String::INS => "ins",\n            String::OUTS => "outs",\n            String::MOVS => "movs",\n            String::CMPS => "cmps",\n            String::STOS => "stos",\n            String::LODS => "lods",\n            String::SCAS => "scas",\n        },\n        if size == 8 {\n            "b"\n        }\n        else if size == 16 {\n            "w"\n        }\n        else {\n            "d"\n        },\n        if prefix == 0xF2 || prefix == 0xF3 {\n            match ins {\n                String::CMPS | String::SCAS => {\n                    if prefix == 0xF2 {\n                        "_repnz"\n                    }\n                    else {\n                        "_repz"\n                    }\n                },\n                _ => "_rep",\n            }\n        }\n        else {\n            "_no_rep"\n        }\n    );\n\n    codegen::gen_move_registers_from_locals_to_memory(ctx);\n    if args == 1 {\n        ctx.builder.call_fn1(&name)\n    }\n    else if args == 2 {\n        ctx.builder.call_fn2(&name)\n    }\n    else {\n        dbg_assert!(false);\n    }\n    codegen::gen_move_registers_from_memory_to_locals(ctx);\n}\n\npub fn instr_6C_jit(ctx: &mut JitContext) { gen_string_ins(ctx, String::INS, 8, 0) }\npub fn instr_F26C_jit(ctx: &mut JitContext) { gen_string_ins(ctx, String::INS, 8, 0xF2) }\npub fn instr_F36C_jit(ctx: &mut JitContext) { gen_string_ins(ctx, String::INS, 8, 0xF3) }\npub fn instr16_6D_jit(ctx: &mut JitContext) { gen_string_ins(ctx, String::INS, 16, 0) }\npub fn instr16_F26D_jit(ctx: &mut JitContext) { gen_string_ins(ctx, String::INS, 16, 0xF2) }\npub fn instr16_F36D_jit(ctx: &mut JitContext) { gen_string_ins(ctx, String::INS, 16, 0xF3) }\npub fn instr32_6D_jit(ctx: &mut JitContext) { gen_string_ins(ctx, String::INS, 32, 0) }\npub fn instr32_F26D_jit(ctx: &mut JitContext) { gen_string_ins(ctx, String::INS, 32, 0xF2) }\npub fn instr32_F36D_jit(ctx: &mut JitContext) { gen_string_ins(ctx, String::INS, 32, 0xF3) }\npub fn instr_6E_jit(ctx: &mut JitContext) { gen_string_ins(ctx, String::OUTS, 8, 0) }\npub fn instr_F26E_jit(ctx: &mut JitContext) { gen_string_ins(ctx, String::OUTS, 8, 0xF2) }\npub fn instr_F36E_jit(ctx: &mut JitContext) { gen_string_ins(ctx, String::OUTS, 8, 0xF3) }\npub fn instr16_6F_jit(ctx: &mut JitContext) { gen_string_ins(ctx, String::OUTS, 16, 0) }\npub fn instr16_F26F_jit(ctx: &mut JitContext) { gen_string_ins(ctx, String::OUTS, 16, 0xF2) }\npub fn instr16_F36F_jit(ctx: &mut JitContext) { gen_string_ins(ctx, String::OUTS, 16, 0xF3) }\npub fn instr32_6F_jit(ctx: &mut JitContext) { gen_string_ins(ctx, String::OUTS, 32, 0) }\npub fn instr32_F26F_jit(ctx: &mut JitContext) { gen_string_ins(ctx, String::OUTS, 32, 0xF2) }\npub fn instr32_F36F_jit(ctx: &mut JitContext) { gen_string_ins(ctx, String::OUTS, 32, 0xF3) }\npub fn instr_A4_jit(ctx: &mut JitContext) { gen_string_ins(ctx, String::MOVS, 8, 0) }\npub fn instr_F2A4_jit(ctx: &mut JitContext) { gen_string_ins(ctx, String::MOVS, 8, 0xF2) }\npub fn instr_F3A4_jit(ctx: &mut JitContext) { gen_string_ins(ctx, String::MOVS, 8, 0xF3) }\npub fn instr16_A5_jit(ctx: &mut JitContext) { gen_string_ins(ctx, String::MOVS, 16, 0) }\npub fn instr16_F2A5_jit(ctx: &mut JitContext) { gen_string_ins(ctx, String::MOVS, 16, 0xF2) }\npub fn instr16_F3A5_jit(ctx: &mut JitContext) { gen_string_ins(ctx, String::MOVS, 16, 0xF3) }\npub fn instr32_A5_jit(ctx: &mut JitContext) { gen_string_ins(ctx, String::MOVS, 32, 0) }\npub fn instr32_F2A5_jit(ctx: &mut JitContext) { gen_string_ins(ctx, String::MOVS, 32, 0xF2) }\npub fn instr32_F3A5_jit(ctx: &mut JitContext) { gen_string_ins(ctx, String::MOVS, 32, 0xF3) }\npub fn instr_A6_jit(ctx: &mut JitContext) { gen_string_ins(ctx, String::CMPS, 8, 0) }\npub fn instr_F2A6_jit(ctx: &mut JitContext) { gen_string_ins(ctx, String::CMPS, 8, 0xF2) }\npub fn instr_F3A6_jit(ctx: &mut JitContext) { gen_string_ins(ctx, String::CMPS, 8, 0xF3) }\npub fn instr16_A7_jit(ctx: &mut JitContext) { gen_string_ins(ctx, String::CMPS, 16, 0) }\npub fn instr16_F2A7_jit(ctx: &mut JitContext) { gen_string_ins(ctx, String::CMPS, 16, 0xF2) }\npub fn instr16_F3A7_jit(ctx: &mut JitContext) { gen_string_ins(ctx, String::CMPS, 16, 0xF3) }\npub fn instr32_A7_jit(ctx: &mut JitContext) { gen_string_ins(ctx, String::CMPS, 32, 0) }\npub fn instr32_F2A7_jit(ctx: &mut JitContext) { gen_string_ins(ctx, String::CMPS, 32, 0xF2) }\npub fn instr32_F3A7_jit(ctx: &mut JitContext) { gen_string_ins(ctx, String::CMPS, 32, 0xF3) }\npub fn instr_AA_jit(ctx: &mut JitContext) { gen_string_ins(ctx, String::STOS, 8, 0) }\npub fn instr_F2AA_jit(ctx: &mut JitContext) { gen_string_ins(ctx, String::STOS, 8, 0xF2) }\npub fn instr_F3AA_jit(ctx: &mut JitContext) { gen_string_ins(ctx, String::STOS, 8, 0xF3) }\npub fn instr16_AB_jit(ctx: &mut JitContext) { gen_string_ins(ctx, String::STOS, 16, 0) }\npub fn instr16_F2AB_jit(ctx: &mut JitContext) { gen_string_ins(ctx, String::STOS, 16, 0xF2) }\npub fn instr16_F3AB_jit(ctx: &mut JitContext) { gen_string_ins(ctx, String::STOS, 16, 0xF3) }\npub fn instr32_AB_jit(ctx: &mut JitContext) { gen_string_ins(ctx, String::STOS, 32, 0) }\npub fn instr32_F2AB_jit(ctx: &mut JitContext) { gen_string_ins(ctx, String::STOS, 32, 0xF2) }\npub fn instr32_F3AB_jit(ctx: &mut JitContext) { gen_string_ins(ctx, String::STOS, 32, 0xF3) }\npub fn instr_AC_jit(ctx: &mut JitContext) { gen_string_ins(ctx, String::LODS, 8, 0) }\npub fn instr_F2AC_jit(ctx: &mut JitContext) { gen_string_ins(ctx, String::LODS, 8, 0xF2) }\npub fn instr_F3AC_jit(ctx: &mut JitContext) { gen_string_ins(ctx, String::LODS, 8, 0xF3) }\npub fn instr16_AD_jit(ctx: &mut JitContext) { gen_string_ins(ctx, String::LODS, 16, 0) }\npub fn instr16_F2AD_jit(ctx: &mut JitContext) { gen_string_ins(ctx, String::LODS, 16, 0xF2) }\npub fn instr16_F3AD_jit(ctx: &mut JitContext) { gen_string_ins(ctx, String::LODS, 16, 0xF3) }\npub fn instr32_AD_jit(ctx: &mut JitContext) { gen_string_ins(ctx, String::LODS, 32, 0) }\npub fn instr32_F2AD_jit(ctx: &mut JitContext) { gen_string_ins(ctx, String::LODS, 32, 0xF2) }\npub fn instr32_F3AD_jit(ctx: &mut JitContext) { gen_string_ins(ctx, String::LODS, 32, 0xF3) }\npub fn instr_AE_jit(ctx: &mut JitContext) { gen_string_ins(ctx, String::SCAS, 8, 0) }\npub fn instr_F2AE_jit(ctx: &mut JitContext) { gen_string_ins(ctx, String::SCAS, 8, 0xF2) }\npub fn instr_F3AE_jit(ctx: &mut JitContext) { gen_string_ins(ctx, String::SCAS, 8, 0xF3) }\npub fn instr16_AF_jit(ctx: &mut JitContext) { gen_string_ins(ctx, String::SCAS, 16, 0) }\npub fn instr16_F2AF_jit(ctx: &mut JitContext) { gen_string_ins(ctx, String::SCAS, 16, 0xF2) }\npub fn instr16_F3AF_jit(ctx: &mut JitContext) { gen_string_ins(ctx, String::SCAS, 16, 0xF3) }\npub fn instr32_AF_jit(ctx: &mut JitContext) { gen_string_ins(ctx, String::SCAS, 32, 0) }\npub fn instr32_F2AF_jit(ctx: &mut JitContext) { gen_string_ins(ctx, String::SCAS, 32, 0xF2) }\npub fn instr32_F3AF_jit(ctx: &mut JitContext) { gen_string_ins(ctx, String::SCAS, 32, 0xF3) }\n\npub fn instr_0F31_jit(ctx: &mut JitContext) {\n    ctx.builder.load_fixed_u8(global_pointers::cpl as u32);\n    ctx.builder.eqz_i32();\n\n    dbg_assert!(regs::CR4_TSD < 0x100);\n    ctx.builder\n        .load_fixed_u8(global_pointers::get_creg_offset(4));\n    ctx.builder.const_i32(regs::CR4_TSD as i32);\n    ctx.builder.and_i32();\n    ctx.builder.eqz_i32();\n\n    ctx.builder.or_i32();\n    ctx.builder.if_void();\n    ctx.builder.call_fn0_ret_i64("read_tsc");\n\n    let tsc = ctx.builder.tee_new_local_i64();\n    ctx.builder.wrap_i64_to_i32();\n    codegen::gen_set_reg32(ctx, regs::EAX);\n\n    ctx.builder.get_local_i64(&tsc);\n    ctx.builder.const_i64(32);\n    ctx.builder.shr_u_i64();\n    ctx.builder.wrap_i64_to_i32();\n    codegen::gen_set_reg32(ctx, regs::EDX);\n\n    ctx.builder.free_local_i64(tsc);\n    ctx.builder.else_();\n    codegen::gen_trigger_gp(ctx, 0);\n    ctx.builder.block_end();\n}\n\npub fn instr_0F18_mem_jit(_ctx: &mut JitContext, _modrm_byte: ModrmByte, _reg: u32) {}\npub fn instr_0F18_reg_jit(_ctx: &mut JitContext, _r1: u32, _r2: u32) {}\n\npub fn instr_0F19_mem_jit(_ctx: &mut JitContext, _modrm_byte: ModrmByte, _reg: u32) {}\npub fn instr_0F19_reg_jit(_ctx: &mut JitContext, _r1: u32, _r2: u32) {}\n\npub fn instr_0F1C_mem_jit(_ctx: &mut JitContext, _modrm_byte: ModrmByte, _reg: u32) {}\npub fn instr_0F1C_reg_jit(_ctx: &mut JitContext, _r1: u32, _r2: u32) {}\npub fn instr_0F1D_mem_jit(_ctx: &mut JitContext, _modrm_byte: ModrmByte, _reg: u32) {}\npub fn instr_0F1D_reg_jit(_ctx: &mut JitContext, _r1: u32, _r2: u32) {}\npub fn instr_0F1E_mem_jit(_ctx: &mut JitContext, _modrm_byte: ModrmByte, _reg: u32) {}\npub fn instr_0F1E_reg_jit(_ctx: &mut JitContext, _r1: u32, _r2: u32) {}\npub fn instr_0F1F_mem_jit(_ctx: &mut JitContext, _modrm_byte: ModrmByte, _reg: u32) {}\npub fn instr_0F1F_reg_jit(_ctx: &mut JitContext, _r1: u32, _r2: u32) {}\n\ndefine_instruction_read_write_mem16!(\n    "shld16",\n    instr16_0FA4_mem_jit,\n    instr16_0FA4_reg_jit,\n    reg,\n    imm8_5bits\n);\ndefine_instruction_read_write_mem32!(\n    "shld32",\n    instr32_0FA4_mem_jit,\n    instr32_0FA4_reg_jit,\n    reg,\n    imm8_5bits\n);\ndefine_instruction_read_write_mem16!(\n    "shld16",\n    instr16_0FA5_mem_jit,\n    instr16_0FA5_reg_jit,\n    reg,\n    cl\n);\ndefine_instruction_read_write_mem32!(\n    "shld32",\n    instr32_0FA5_mem_jit,\n    instr32_0FA5_reg_jit,\n    reg,\n    cl\n);\n\ndefine_instruction_read_write_mem16!(\n    "shrd16",\n    instr16_0FAC_mem_jit,\n    instr16_0FAC_reg_jit,\n    reg,\n    imm8_5bits\n);\ndefine_instruction_read_write_mem32!(\n    "shrd32",\n    instr32_0FAC_mem_jit,\n    instr32_0FAC_reg_jit,\n    reg,\n    imm8_5bits\n);\ndefine_instruction_read_write_mem16!(\n    "shrd16",\n    instr16_0FAD_mem_jit,\n    instr16_0FAD_reg_jit,\n    reg,\n    cl\n);\ndefine_instruction_read_write_mem32!(\n    "shrd32",\n    instr32_0FAD_mem_jit,\n    instr32_0FAD_reg_jit,\n    reg,\n    cl\n);\n\npub fn instr16_0FB1_reg_jit(ctx: &mut JitContext, r1: u32, r2: u32) {\n    codegen::gen_get_reg16(ctx, r1);\n    ctx.builder.const_i32(r2 as i32);\n    codegen::gen_move_registers_from_locals_to_memory(ctx);\n    ctx.builder.call_fn2_ret("cmpxchg16");\n    codegen::gen_move_registers_from_memory_to_locals(ctx);\n    codegen::gen_set_reg16(ctx, r1);\n}\npub fn instr16_0FB1_mem_jit(ctx: &mut JitContext, modrm_byte: ModrmByte, r: u32) {\n    codegen::gen_modrm_resolve(ctx, modrm_byte);\n    let address_local = ctx.builder.set_new_local();\n    codegen::gen_safe_read_write(ctx, BitSize::WORD, &address_local, &|ref mut ctx| {\n        ctx.builder.const_i32(r as i32);\n        codegen::gen_move_registers_from_locals_to_memory(ctx);\n        ctx.builder.call_fn2_ret("cmpxchg16");\n        codegen::gen_move_registers_from_memory_to_locals(ctx);\n    });\n    ctx.builder.free_local(address_local);\n}\n\npub fn instr32_0FB1_reg_jit(ctx: &mut JitContext, r1: u32, r2: u32) {\n    codegen::gen_get_reg32(ctx, r1);\n    gen_cmpxchg32(ctx, r2);\n    codegen::gen_set_reg32(ctx, r1);\n}\npub fn instr32_0FB1_mem_jit(ctx: &mut JitContext, modrm_byte: ModrmByte, r: u32) {\n    codegen::gen_modrm_resolve(ctx, modrm_byte);\n    let address_local = ctx.builder.set_new_local();\n    codegen::gen_safe_read_write(ctx, BitSize::DWORD, &address_local, &|ref mut ctx| {\n        gen_cmpxchg32(ctx, r);\n    });\n    ctx.builder.free_local(address_local);\n}\n\npub fn instr16_0FB6_reg_jit(ctx: &mut JitContext, r1: u32, r2: u32) {\n    codegen::gen_get_reg8(ctx, r1);\n    codegen::gen_set_reg16_unmasked(ctx, r2);\n}\npub fn instr16_0FB6_mem_jit(ctx: &mut JitContext, modrm_byte: ModrmByte, r: u32) {\n    codegen::gen_modrm_resolve_safe_read8(ctx, modrm_byte);\n    codegen::gen_set_reg16_unmasked(ctx, r);\n}\n\npub fn instr32_0FB6_reg_jit(ctx: &mut JitContext, r1: u32, r2: u32) {\n    codegen::gen_get_reg8(ctx, r1);\n    codegen::gen_set_reg32(ctx, r2);\n}\npub fn instr32_0FB6_mem_jit(ctx: &mut JitContext, modrm_byte: ModrmByte, r: u32) {\n    codegen::gen_modrm_resolve_safe_read8(ctx, modrm_byte);\n    codegen::gen_set_reg32(ctx, r);\n}\n\npub fn instr16_0FB7_mem_jit(ctx: &mut JitContext, modrm_byte: ModrmByte, r: u32) {\n    codegen::gen_modrm_resolve_safe_read16(ctx, modrm_byte);\n    codegen::gen_set_reg16(ctx, r);\n}\npub fn instr16_0FB7_reg_jit(ctx: &mut JitContext, r1: u32, r2: u32) {\n    codegen::gen_get_reg16(ctx, r1);\n    codegen::gen_set_reg16(ctx, r2);\n}\npub fn instr32_0FB7_mem_jit(ctx: &mut JitContext, modrm_byte: ModrmByte, r: u32) {\n    codegen::gen_modrm_resolve_safe_read16(ctx, modrm_byte);\n    codegen::gen_set_reg32(ctx, r);\n}\npub fn instr32_0FB7_reg_jit(ctx: &mut JitContext, r1: u32, r2: u32) {\n    codegen::gen_get_reg16(ctx, r1);\n    codegen::gen_set_reg32(ctx, r2);\n}\n\npub fn instr16_F30FB8_mem_jit(ctx: &mut JitContext, modrm_byte: ModrmByte, r: u32) {\n    codegen::gen_modrm_resolve_safe_read16(ctx, modrm_byte);\n    ctx.builder.call_fn1_ret("popcnt");\n    codegen::gen_set_reg16(ctx, r);\n}\npub fn instr16_F30FB8_reg_jit(ctx: &mut JitContext, r1: u32, r2: u32) {\n    codegen::gen_get_reg16(ctx, r1);\n    ctx.builder.call_fn1_ret("popcnt");\n    codegen::gen_set_reg16(ctx, r2);\n}\npub fn instr32_F30FB8_mem_jit(ctx: &mut JitContext, modrm_byte: ModrmByte, r: u32) {\n    codegen::gen_modrm_resolve_safe_read32(ctx, modrm_byte);\n    ctx.builder.call_fn1_ret("popcnt");\n    codegen::gen_set_reg32(ctx, r);\n}\npub fn instr32_F30FB8_reg_jit(ctx: &mut JitContext, r1: u32, r2: u32) {\n    codegen::gen_get_reg32(ctx, r1);\n    ctx.builder.call_fn1_ret("popcnt");\n    codegen::gen_set_reg32(ctx, r2);\n}\n\ndefine_instruction_write_reg16!("bsf16", instr16_0FBC_mem_jit, instr16_0FBC_reg_jit);\ndefine_instruction_write_reg32!(gen_bsf32, instr32_0FBC_mem_jit, instr32_0FBC_reg_jit);\ndefine_instruction_write_reg16!("bsr16", instr16_0FBD_mem_jit, instr16_0FBD_reg_jit);\ndefine_instruction_write_reg32!(gen_bsr32, instr32_0FBD_mem_jit, instr32_0FBD_reg_jit);\n\npub fn instr16_0FBE_reg_jit(ctx: &mut JitContext, r1: u32, r2: u32) {\n    codegen::gen_get_reg8(ctx, r1);\n    codegen::sign_extend_i8(ctx.builder);\n    codegen::gen_set_reg16(ctx, r2);\n}\npub fn instr16_0FBE_mem_jit(ctx: &mut JitContext, modrm_byte: ModrmByte, r: u32) {\n    codegen::gen_modrm_resolve_safe_read8(ctx, modrm_byte); // TODO: Could use sign-extended read\n    codegen::sign_extend_i8(ctx.builder);\n    codegen::gen_set_reg16(ctx, r);\n}\n\npub fn instr32_0FBE_reg_jit(ctx: &mut JitContext, r1: u32, r2: u32) {\n    match r1 {\n        regs::AL | regs::CL | regs::DL | regs::BL => {\n            ctx.builder.get_local(&ctx.register_locals[r1 as usize]);\n            ctx.builder.const_i32(24);\n            ctx.builder.shl_i32();\n        },\n        regs::AH | regs::CH | regs::DH | regs::BH => {\n            ctx.builder\n                .get_local(&ctx.register_locals[(r1 - 4) as usize]);\n            ctx.builder.const_i32(16);\n            ctx.builder.shl_i32();\n        },\n        _ => assert!(false),\n    }\n    ctx.builder.const_i32(24);\n    ctx.builder.shr_s_i32();\n    codegen::gen_set_reg32(ctx, r2);\n}\npub fn instr32_0FBE_mem_jit(ctx: &mut JitContext, modrm_byte: ModrmByte, r: u32) {\n    codegen::gen_modrm_resolve_safe_read8(ctx, modrm_byte); // TODO: Could use sign-extended read\n    codegen::sign_extend_i8(ctx.builder);\n    codegen::gen_set_reg32(ctx, r);\n}\n\npub fn instr16_0FBF_reg_jit(ctx: &mut JitContext, r1: u32, r2: u32) {\n    codegen::gen_get_reg16(ctx, r1);\n    codegen::gen_set_reg16_unmasked(ctx, r2);\n}\npub fn instr16_0FBF_mem_jit(ctx: &mut JitContext, modrm_byte: ModrmByte, r: u32) {\n    codegen::gen_modrm_resolve_safe_read16(ctx, modrm_byte);\n    codegen::gen_set_reg16_unmasked(ctx, r);\n}\n\npub fn instr32_0FBF_reg_jit(ctx: &mut JitContext, r1: u32, r2: u32) {\n    codegen::gen_get_reg32(ctx, r1);\n    codegen::sign_extend_i16(ctx.builder);\n    codegen::gen_set_reg32(ctx, r2);\n}\npub fn instr32_0FBF_mem_jit(ctx: &mut JitContext, modrm_byte: ModrmByte, r: u32) {\n    codegen::gen_modrm_resolve_safe_read16(ctx, modrm_byte); // TODO: Could use sign-extended read\n    codegen::sign_extend_i16(ctx.builder);\n    codegen::gen_set_reg32(ctx, r);\n}\n\npub fn instr16_0FC1_mem_jit(ctx: &mut JitContext, modrm_byte: ModrmByte, r: u32) {\n    codegen::gen_modrm_resolve(ctx, modrm_byte);\n    let address_local = ctx.builder.set_new_local();\n    codegen::gen_safe_read_write(ctx, BitSize::WORD, &address_local, &|ref mut ctx| {\n        ctx.builder.const_i32(r as i32);\n        codegen::gen_move_registers_from_locals_to_memory(ctx);\n        ctx.builder.call_fn2_ret("xadd16");\n        codegen::gen_move_registers_from_memory_to_locals(ctx);\n    });\n    ctx.builder.free_local(address_local);\n}\npub fn instr16_0FC1_reg_jit(ctx: &mut JitContext, r1: u32, r2: u32) {\n    codegen::gen_get_reg16(ctx, r1);\n    ctx.builder.const_i32(r2 as i32);\n    codegen::gen_move_registers_from_locals_to_memory(ctx);\n    ctx.builder.call_fn2_ret("xadd16");\n    codegen::gen_move_registers_from_memory_to_locals(ctx);\n    codegen::gen_set_reg16(ctx, r1);\n}\n\npub fn instr32_0FC1_mem_jit(ctx: &mut JitContext, modrm_byte: ModrmByte, r: u32) {\n    codegen::gen_modrm_resolve(ctx, modrm_byte);\n    let address_local = ctx.builder.set_new_local();\n    codegen::gen_safe_read_write(ctx, BitSize::DWORD, &address_local, &|ref mut ctx| {\n        let dest_operand = ctx.builder.set_new_local();\n        gen_xadd32(ctx, &dest_operand, r);\n        ctx.builder.get_local(&dest_operand);\n        ctx.builder.free_local(dest_operand);\n    });\n    ctx.builder.free_local(address_local);\n}\npub fn instr32_0FC1_reg_jit(ctx: &mut JitContext, r1: u32, r2: u32) {\n    codegen::gen_get_reg32(ctx, r1);\n    let dest_operand = ctx.builder.set_new_local();\n    gen_xadd32(ctx, &dest_operand, r2);\n    ctx.builder.get_local(&dest_operand);\n    codegen::gen_set_reg32(ctx, r1);\n    ctx.builder.free_local(dest_operand);\n}\n\npub fn instr_0FC3_mem_jit(ctx: &mut JitContext, modrm_byte: ModrmByte, r: u32) {\n    codegen::gen_modrm_resolve(ctx, modrm_byte);\n    let address_local = ctx.builder.set_new_local();\n    codegen::gen_safe_write32(ctx, &address_local, &ctx.reg(r));\n    ctx.builder.free_local(address_local);\n}\npub fn instr_0FC3_reg_jit(ctx: &mut JitContext, _r1: u32, _r2: u32) { codegen::gen_trigger_ud(ctx) }\n\npub fn instr16_0FC7_1_mem_jit(ctx: &mut JitContext, modrm_byte: ModrmByte) {\n    // cmpxchg8b\n    codegen::gen_modrm_resolve(ctx, modrm_byte);\n    let address_local = ctx.builder.set_new_local();\n    codegen::gen_safe_read_write(ctx, BitSize::QWORD, &address_local, &|ref mut ctx| {\n        let dest_operand = ctx.builder.tee_new_local_i64();\n        codegen::gen_get_reg32(ctx, regs::EDX);\n        ctx.builder.extend_unsigned_i32_to_i64();\n        ctx.builder.const_i64(32);\n        ctx.builder.shl_i64();\n        codegen::gen_get_reg32(ctx, regs::EAX);\n        ctx.builder.extend_unsigned_i32_to_i64();\n        ctx.builder.or_i64();\n        ctx.builder.eq_i64();\n        ctx.builder.if_i64();\n        {\n            codegen::gen_set_flags_bits(ctx.builder, FLAG_ZERO);\n            codegen::gen_get_reg32(ctx, regs::ECX);\n            ctx.builder.extend_unsigned_i32_to_i64();\n            ctx.builder.const_i64(32);\n            ctx.builder.shl_i64();\n            codegen::gen_get_reg32(ctx, regs::EBX);\n            ctx.builder.extend_unsigned_i32_to_i64();\n            ctx.builder.or_i64();\n        }\n        ctx.builder.else_();\n        {\n            codegen::gen_clear_flags_bits(ctx.builder, FLAG_ZERO);\n            ctx.builder.get_local_i64(&dest_operand);\n            ctx.builder.wrap_i64_to_i32();\n            codegen::gen_set_reg32(ctx, regs::EAX);\n            ctx.builder.get_local_i64(&dest_operand);\n            ctx.builder.const_i64(32);\n            ctx.builder.shr_u_i64();\n            ctx.builder.wrap_i64_to_i32();\n            codegen::gen_set_reg32(ctx, regs::EDX);\n            ctx.builder.get_local_i64(&dest_operand);\n        }\n        ctx.builder.block_end();\n        codegen::gen_clear_flags_changed_bits(ctx.builder, FLAG_ZERO);\n        ctx.builder.free_local_i64(dest_operand);\n    });\n    ctx.builder.free_local(address_local);\n}\npub fn instr16_0FC7_1_reg_jit(ctx: &mut JitContext, _r: u32) { codegen::gen_trigger_ud(ctx); }\npub fn instr32_0FC7_1_mem_jit(ctx: &mut JitContext, modrm_byte: ModrmByte) {\n    instr16_0FC7_1_mem_jit(ctx, modrm_byte);\n}\npub fn instr32_0FC7_1_reg_jit(ctx: &mut JitContext, _r: u32) { codegen::gen_trigger_ud(ctx); }\n\npub fn instr_0FC2_reg_jit(ctx: &mut JitContext, r1: u32, r2: u32, imm8: u32) {\n    sse_read128_xmm_xmm_imm(ctx, "instr_0FC2", r1, r2, imm8)\n}\npub fn instr_0FC2_mem_jit(ctx: &mut JitContext, modrm_byte: ModrmByte, r: u32, imm8: u32) {\n    sse_read128_xmm_mem_imm(ctx, "instr_0FC2", modrm_byte, r, imm8)\n}\npub fn instr_660FC2_reg_jit(ctx: &mut JitContext, r1: u32, r2: u32, imm8: u32) {\n    sse_read128_xmm_xmm_imm(ctx, "instr_660FC2", r1, r2, imm8)\n}\npub fn instr_660FC2_mem_jit(ctx: &mut JitContext, modrm_byte: ModrmByte, r: u32, imm8: u32) {\n    sse_read128_xmm_mem_imm(ctx, "instr_660FC2", modrm_byte, r, imm8)\n}\npub fn instr_F20FC2_reg_jit(ctx: &mut JitContext, r1: u32, r2: u32, imm8: u32) {\n    ctx.builder\n        .const_i32(global_pointers::get_reg_xmm_offset(r1) as i32);\n    ctx.builder.load_aligned_i64(0);\n    ctx.builder.const_i32(r2 as i32);\n    ctx.builder.const_i32(imm8 as i32);\n    ctx.builder.call_fn3_i64_i32_i32("instr_F20FC2");\n}\npub fn instr_F20FC2_mem_jit(ctx: &mut JitContext, modrm_byte: ModrmByte, r: u32, imm8: u32) {\n    codegen::gen_modrm_resolve_safe_read64(ctx, modrm_byte);\n    ctx.builder.const_i32(r as i32);\n    ctx.builder.const_i32(imm8 as i32);\n    ctx.builder.call_fn3_i64_i32_i32("instr_F20FC2");\n}\npub fn instr_F30FC2_reg_jit(ctx: &mut JitContext, r1: u32, r2: u32, imm8: u32) {\n    ctx.builder\n        .const_i32(global_pointers::get_reg_xmm_offset(r1) as i32);\n    ctx.builder.load_aligned_i32(0);\n    ctx.builder.const_i32(r2 as i32);\n    ctx.builder.const_i32(imm8 as i32);\n    ctx.builder.call_fn3("instr_F30FC2");\n}\npub fn instr_F30FC2_mem_jit(ctx: &mut JitContext, modrm_byte: ModrmByte, r: u32, imm8: u32) {\n    codegen::gen_modrm_resolve_safe_read32(ctx, modrm_byte);\n    ctx.builder.const_i32(r as i32);\n    ctx.builder.const_i32(imm8 as i32);\n    ctx.builder.call_fn3("instr_F30FC2");\n}\n\npub fn instr_0FC6_reg_jit(ctx: &mut JitContext, r1: u32, r2: u32, imm8: u32) {\n    sse_read128_xmm_xmm_imm(ctx, "instr_0FC6", r1, r2, imm8)\n}\npub fn instr_0FC6_mem_jit(ctx: &mut JitContext, modrm_byte: ModrmByte, r: u32, imm8: u32) {\n    sse_read128_xmm_mem_imm(ctx, "instr_0FC6", modrm_byte, r, imm8)\n}\npub fn instr_660FC6_reg_jit(ctx: &mut JitContext, r1: u32, r2: u32, imm8: u32) {\n    sse_read128_xmm_xmm_imm(ctx, "instr_660FC6", r1, r2, imm8)\n}\npub fn instr_660FC6_mem_jit(ctx: &mut JitContext, modrm_byte: ModrmByte, r: u32, imm8: u32) {\n    sse_read128_xmm_mem_imm(ctx, "instr_660FC6", modrm_byte, r, imm8)\n}\n\npub fn instr_C6_0_reg_jit(ctx: &mut JitContext, r: u32, imm: u32) {\n    // reg8[r] = imm;\n    ctx.builder.const_i32(imm as i32);\n    codegen::gen_set_reg8_unmasked(ctx, r);\n}\n\npub fn instr_C6_0_mem_jit(ctx: &mut JitContext, modrm_byte: ModrmByte, imm: u32) {\n    codegen::gen_modrm_resolve_with_local(ctx, modrm_byte, &|ctx, addr| {\n        ctx.builder.const_i32(imm as i32);\n        let value_local = ctx.builder.set_new_local();\n        codegen::gen_safe_write8(ctx, &addr, &value_local);\n        ctx.builder.free_local(value_local);\n    });\n}\n\npub fn instr16_C7_0_reg_jit(ctx: &mut JitContext, r: u32, imm: u32) {\n    // reg16[r] = imm;\n    ctx.builder.const_i32(imm as i32);\n    codegen::gen_set_reg16_unmasked(ctx, r);\n}\n\npub fn instr16_C7_0_mem_jit(ctx: &mut JitContext, modrm_byte: ModrmByte, imm: u32) {\n    codegen::gen_modrm_resolve_with_local(ctx, modrm_byte, &|ctx, addr| {\n        ctx.builder.const_i32(imm as i32);\n        let value_local = ctx.builder.set_new_local();\n        codegen::gen_safe_write16(ctx, &addr, &value_local);\n        ctx.builder.free_local(value_local);\n    });\n}\n\npub fn instr32_C7_0_reg_jit(ctx: &mut JitContext, r: u32, imm: u32) {\n    // reg32[r] = imm;\n    ctx.builder.const_i32(imm as i32);\n    codegen::gen_set_reg32(ctx, r);\n}\n\npub fn instr32_C7_0_mem_jit(ctx: &mut JitContext, modrm_byte: ModrmByte, imm: u32) {\n    codegen::gen_modrm_resolve_with_local(ctx, modrm_byte, &|ctx, addr| {\n        ctx.builder.const_i32(imm as i32);\n        let value_local = ctx.builder.set_new_local();\n        codegen::gen_safe_write32(ctx, &addr, &value_local);\n        ctx.builder.free_local(value_local);\n    });\n}\n\npub fn instr_0FC8_jit(ctx: &mut JitContext) { gen_bswap(ctx, 0) }\npub fn instr_0FC9_jit(ctx: &mut JitContext) { gen_bswap(ctx, 1) }\npub fn instr_0FCA_jit(ctx: &mut JitContext) { gen_bswap(ctx, 2) }\npub fn instr_0FCB_jit(ctx: &mut JitContext) { gen_bswap(ctx, 3) }\npub fn instr_0FCC_jit(ctx: &mut JitContext) { gen_bswap(ctx, 4) }\npub fn instr_0FCD_jit(ctx: &mut JitContext) { gen_bswap(ctx, 5) }\npub fn instr_0FCE_jit(ctx: &mut JitContext) { gen_bswap(ctx, 6) }\npub fn instr_0FCF_jit(ctx: &mut JitContext) { gen_bswap(ctx, 7) }\n\ndefine_instruction_write_reg16!("imul_reg16", instr16_0FAF_mem_jit, instr16_0FAF_reg_jit);\ndefine_instruction_write_reg32!(gen_imul_reg32, instr32_0FAF_mem_jit, instr32_0FAF_reg_jit);\n\nmacro_rules! define_cmovcc16(\n    ($cond:expr, $name_mem:ident, $name_reg:ident) => (\n        pub fn $name_mem(ctx: &mut JitContext, modrm_byte: ModrmByte, r: u32) {\n            codegen::gen_modrm_resolve_safe_read16(ctx, modrm_byte);\n            let value = ctx.builder.set_new_local();\n            codegen::gen_condition_fn(ctx, $cond);\n            ctx.builder.if_void();\n            ctx.builder.get_local(&value);\n            codegen::gen_set_reg16(ctx, r);\n            ctx.builder.block_end();\n            ctx.builder.free_local(value);\n        }\n\n        pub fn $name_reg(ctx: &mut JitContext, r1: u32, r2: u32) {\n            codegen::gen_condition_fn(ctx, $cond);\n            ctx.builder.if_void();\n            codegen::gen_get_reg16(ctx, r1);\n            codegen::gen_set_reg16(ctx, r2);\n            ctx.builder.block_end();\n        }\n    );\n);\n\nmacro_rules! define_cmovcc32(\n    ($cond:expr, $name_mem:ident, $name_reg:ident) => (\n        pub fn $name_mem(ctx: &mut JitContext, modrm_byte: ModrmByte, r: u32) {\n            codegen::gen_modrm_resolve_safe_read32(ctx, modrm_byte);\n            let value = ctx.builder.set_new_local();\n            codegen::gen_condition_fn(ctx, $cond);\n            ctx.builder.if_void();\n            ctx.builder.get_local(&value);\n            codegen::gen_set_reg32(ctx, r);\n            ctx.builder.block_end();\n            ctx.builder.free_local(value);\n        }\n\n        pub fn $name_reg(ctx: &mut JitContext, r1: u32, r2: u32) {\n            codegen::gen_condition_fn(ctx, $cond);\n            ctx.builder.if_void();\n            codegen::gen_get_reg32(ctx, r1);\n            codegen::gen_set_reg32(ctx, r2);\n            ctx.builder.block_end();\n        }\n    );\n);\n\ndefine_cmovcc16!(0x0, instr16_0F40_mem_jit, instr16_0F40_reg_jit);\ndefine_cmovcc16!(0x1, instr16_0F41_mem_jit, instr16_0F41_reg_jit);\ndefine_cmovcc16!(0x2, instr16_0F42_mem_jit, instr16_0F42_reg_jit);\ndefine_cmovcc16!(0x3, instr16_0F43_mem_jit, instr16_0F43_reg_jit);\ndefine_cmovcc16!(0x4, instr16_0F44_mem_jit, instr16_0F44_reg_jit);\ndefine_cmovcc16!(0x5, instr16_0F45_mem_jit, instr16_0F45_reg_jit);\ndefine_cmovcc16!(0x6, instr16_0F46_mem_jit, instr16_0F46_reg_jit);\ndefine_cmovcc16!(0x7, instr16_0F47_mem_jit, instr16_0F47_reg_jit);\n\ndefine_cmovcc16!(0x8, instr16_0F48_mem_jit, instr16_0F48_reg_jit);\ndefine_cmovcc16!(0x9, instr16_0F49_mem_jit, instr16_0F49_reg_jit);\ndefine_cmovcc16!(0xA, instr16_0F4A_mem_jit, instr16_0F4A_reg_jit);\ndefine_cmovcc16!(0xB, instr16_0F4B_mem_jit, instr16_0F4B_reg_jit);\ndefine_cmovcc16!(0xC, instr16_0F4C_mem_jit, instr16_0F4C_reg_jit);\ndefine_cmovcc16!(0xD, instr16_0F4D_mem_jit, instr16_0F4D_reg_jit);\ndefine_cmovcc16!(0xE, instr16_0F4E_mem_jit, instr16_0F4E_reg_jit);\ndefine_cmovcc16!(0xF, instr16_0F4F_mem_jit, instr16_0F4F_reg_jit);\n\ndefine_cmovcc32!(0x0, instr32_0F40_mem_jit, instr32_0F40_reg_jit);\ndefine_cmovcc32!(0x1, instr32_0F41_mem_jit, instr32_0F41_reg_jit);\ndefine_cmovcc32!(0x2, instr32_0F42_mem_jit, instr32_0F42_reg_jit);\ndefine_cmovcc32!(0x3, instr32_0F43_mem_jit, instr32_0F43_reg_jit);\ndefine_cmovcc32!(0x4, instr32_0F44_mem_jit, instr32_0F44_reg_jit);\ndefine_cmovcc32!(0x5, instr32_0F45_mem_jit, instr32_0F45_reg_jit);\ndefine_cmovcc32!(0x6, instr32_0F46_mem_jit, instr32_0F46_reg_jit);\ndefine_cmovcc32!(0x7, instr32_0F47_mem_jit, instr32_0F47_reg_jit);\n\ndefine_cmovcc32!(0x8, instr32_0F48_mem_jit, instr32_0F48_reg_jit);\ndefine_cmovcc32!(0x9, instr32_0F49_mem_jit, instr32_0F49_reg_jit);\ndefine_cmovcc32!(0xA, instr32_0F4A_mem_jit, instr32_0F4A_reg_jit);\ndefine_cmovcc32!(0xB, instr32_0F4B_mem_jit, instr32_0F4B_reg_jit);\ndefine_cmovcc32!(0xC, instr32_0F4C_mem_jit, instr32_0F4C_reg_jit);\ndefine_cmovcc32!(0xD, instr32_0F4D_mem_jit, instr32_0F4D_reg_jit);\ndefine_cmovcc32!(0xE, instr32_0F4E_mem_jit, instr32_0F4E_reg_jit);\ndefine_cmovcc32!(0xF, instr32_0F4F_mem_jit, instr32_0F4F_reg_jit);\n\nmacro_rules! define_setcc(\n    ($cond:expr, $name_mem:ident, $name_reg:ident) => (\n        pub fn $name_mem(ctx: &mut JitContext, modrm_byte: ModrmByte, _r: u32) {\n            codegen::gen_modrm_resolve_with_local(ctx, modrm_byte, &|ctx, addr| {\n                codegen::gen_condition_fn(ctx, $cond);\n                ctx.builder.const_i32(0);\n                ctx.builder.ne_i32();\n                let value_local = ctx.builder.set_new_local();\n                codegen::gen_safe_write8(ctx, &addr, &value_local);\n                ctx.builder.free_local(value_local);\n            });\n        }\n\n        pub fn $name_reg(ctx: &mut JitContext, r1: u32, _r2: u32) {\n            codegen::gen_condition_fn(ctx, $cond);\n            ctx.builder.const_i32(0);\n            ctx.builder.ne_i32();\n            codegen::gen_set_reg8_unmasked(ctx, r1);\n        }\n    );\n);\n\ndefine_setcc!(0x0, instr_0F90_mem_jit, instr_0F90_reg_jit);\ndefine_setcc!(0x1, instr_0F91_mem_jit, instr_0F91_reg_jit);\ndefine_setcc!(0x2, instr_0F92_mem_jit, instr_0F92_reg_jit);\ndefine_setcc!(0x3, instr_0F93_mem_jit, instr_0F93_reg_jit);\ndefine_setcc!(0x4, instr_0F94_mem_jit, instr_0F94_reg_jit);\ndefine_setcc!(0x5, instr_0F95_mem_jit, instr_0F95_reg_jit);\ndefine_setcc!(0x6, instr_0F96_mem_jit, instr_0F96_reg_jit);\ndefine_setcc!(0x7, instr_0F97_mem_jit, instr_0F97_reg_jit);\n\ndefine_setcc!(0x8, instr_0F98_mem_jit, instr_0F98_reg_jit);\ndefine_setcc!(0x9, instr_0F99_mem_jit, instr_0F99_reg_jit);\ndefine_setcc!(0xA, instr_0F9A_mem_jit, instr_0F9A_reg_jit);\ndefine_setcc!(0xB, instr_0F9B_mem_jit, instr_0F9B_reg_jit);\ndefine_setcc!(0xC, instr_0F9C_mem_jit, instr_0F9C_reg_jit);\ndefine_setcc!(0xD, instr_0F9D_mem_jit, instr_0F9D_reg_jit);\ndefine_setcc!(0xE, instr_0F9E_mem_jit, instr_0F9E_reg_jit);\ndefine_setcc!(0xF, instr_0F9F_mem_jit, instr_0F9F_reg_jit);\n\npub fn instr_0F10_mem_jit(ctx: &mut JitContext, modrm_byte: ModrmByte, r: u32) {\n    let dest = global_pointers::get_reg_xmm_offset(r);\n    codegen::gen_modrm_resolve_safe_read128(ctx, modrm_byte, dest);\n}\npub fn instr_0F10_reg_jit(ctx: &mut JitContext, r1: u32, r2: u32) { sse_mov_xmm_xmm(ctx, r1, r2) }\npub fn instr_660F10_mem_jit(ctx: &mut JitContext, modrm_byte: ModrmByte, r: u32) {\n    let dest = global_pointers::get_reg_xmm_offset(r);\n    codegen::gen_modrm_resolve_safe_read128(ctx, modrm_byte, dest);\n}\npub fn instr_660F10_reg_jit(ctx: &mut JitContext, r1: u32, r2: u32) { sse_mov_xmm_xmm(ctx, r1, r2) }\npub fn instr_F20F10_mem_jit(ctx: &mut JitContext, modrm_byte: ModrmByte, r: u32) {\n    instr_F30F7E_mem_jit(ctx, modrm_byte, r)\n}\npub fn instr_F20F10_reg_jit(ctx: &mut JitContext, r1: u32, r2: u32) {\n    ctx.builder.const_i32(r1 as i32);\n    ctx.builder.const_i32(r2 as i32);\n    ctx.builder.call_fn2("instr_F20F10_reg");\n}\npub fn instr_F30F10_mem_jit(ctx: &mut JitContext, modrm_byte: ModrmByte, r: u32) {\n    instr_660F6E_mem_jit(ctx, modrm_byte, r)\n}\npub fn instr_F30F10_reg_jit(ctx: &mut JitContext, r1: u32, r2: u32) {\n    ctx.builder.const_i32(0);\n    ctx.builder\n        .load_fixed_i32(global_pointers::get_reg_xmm_offset(r1));\n    ctx.builder\n        .store_aligned_i32(global_pointers::get_reg_xmm_offset(r2));\n}\n\npub fn instr_0F11_mem_jit(ctx: &mut JitContext, modrm_byte: ModrmByte, r: u32) {\n    instr_0F29_mem_jit(ctx, modrm_byte, r)\n}\npub fn instr_0F11_reg_jit(ctx: &mut JitContext, r1: u32, r2: u32) { sse_mov_xmm_xmm(ctx, r2, r1) }\npub fn instr_660F11_mem_jit(ctx: &mut JitContext, modrm_byte: ModrmByte, r: u32) {\n    instr_660F29_mem_jit(ctx, modrm_byte, r)\n}\npub fn instr_660F11_reg_jit(ctx: &mut JitContext, r1: u32, r2: u32) { sse_mov_xmm_xmm(ctx, r2, r1) }\npub fn instr_F20F11_mem_jit(ctx: &mut JitContext, modrm_byte: ModrmByte, r: u32) {\n    instr_660FD6_mem_jit(ctx, modrm_byte, r)\n}\npub fn instr_F20F11_reg_jit(ctx: &mut JitContext, r1: u32, r2: u32) {\n    ctx.builder.const_i32(r1 as i32);\n    ctx.builder.const_i32(r2 as i32);\n    ctx.builder.call_fn2("instr_F20F11_reg");\n}\npub fn instr_F30F11_mem_jit(ctx: &mut JitContext, modrm_byte: ModrmByte, r: u32) {\n    instr_660F7E_mem_jit(ctx, modrm_byte, r)\n}\npub fn instr_F30F11_reg_jit(ctx: &mut JitContext, r1: u32, r2: u32) {\n    ctx.builder.const_i32(0);\n    ctx.builder\n        .load_fixed_i32(global_pointers::get_reg_xmm_offset(r2));\n    ctx.builder\n        .store_aligned_i32(global_pointers::get_reg_xmm_offset(r1));\n}\n\npub fn instr_0F12_mem_jit(ctx: &mut JitContext, modrm_byte: ModrmByte, r: u32) {\n    ctx.builder\n        .const_i32(global_pointers::get_reg_xmm_offset(r) as i32);\n    codegen::gen_modrm_resolve_safe_read64(ctx, modrm_byte);\n    ctx.builder.store_aligned_i64(0);\n}\npub fn instr_0F12_reg_jit(ctx: &mut JitContext, r1: u32, r2: u32) {\n    ctx.builder\n        .const_i32(global_pointers::get_reg_xmm_offset(r2) as i32);\n    ctx.builder\n        .const_i32(global_pointers::get_reg_xmm_offset(r1) as i32 + 8);\n    ctx.builder.load_aligned_i64(0);\n    ctx.builder.store_aligned_i64(0);\n}\npub fn instr_660F12_mem_jit(ctx: &mut JitContext, modrm_byte: ModrmByte, r: u32) {\n    ctx.builder\n        .const_i32(global_pointers::get_reg_xmm_offset(r) as i32);\n    codegen::gen_modrm_resolve_safe_read64(ctx, modrm_byte);\n    ctx.builder.store_aligned_i64(0);\n}\npub fn instr_660F12_reg_jit(ctx: &mut JitContext, _r1: u32, _r2: u32) {\n    codegen::gen_trigger_ud(ctx);\n}\n\npub fn instr_0F13_mem_jit(ctx: &mut JitContext, modrm_byte: ModrmByte, r: u32) {\n    instr_660FD6_mem_jit(ctx, modrm_byte, r)\n}\npub fn instr_0F13_reg_jit(ctx: &mut JitContext, _r1: u32, _r2: u32) {\n    codegen::gen_trigger_ud(ctx);\n}\npub fn instr_660F13_mem_jit(ctx: &mut JitContext, modrm_byte: ModrmByte, r: u32) {\n    instr_660FD6_mem_jit(ctx, modrm_byte, r)\n}\npub fn instr_660F13_reg_jit(ctx: &mut JitContext, _r1: u32, _r2: u32) {\n    codegen::gen_trigger_ud(ctx);\n}\n\npub fn instr_0F14_mem_jit(ctx: &mut JitContext, modrm_byte: ModrmByte, r: u32) {\n    sse_read64_xmm_mem(ctx, "instr_0F14", modrm_byte, r);\n}\npub fn instr_0F14_reg_jit(ctx: &mut JitContext, r1: u32, r2: u32) {\n    sse_read64_xmm_xmm(ctx, "instr_0F14", r1, r2);\n}\npub fn instr_660F14_mem_jit(ctx: &mut JitContext, modrm_byte: ModrmByte, r: u32) {\n    sse_read64_xmm_mem(ctx, "instr_660F14", modrm_byte, r);\n}\npub fn instr_660F14_reg_jit(ctx: &mut JitContext, r1: u32, r2: u32) {\n    sse_read64_xmm_xmm(ctx, "instr_660F14", r1, r2);\n}\n\npub fn instr_0F15_mem_jit(ctx: &mut JitContext, modrm_byte: ModrmByte, r: u32) {\n    sse_read128_xmm_mem(ctx, "instr_0F15", modrm_byte, r);\n}\npub fn instr_0F15_reg_jit(ctx: &mut JitContext, r1: u32, r2: u32) {\n    sse_read128_xmm_xmm(ctx, "instr_0F15", r1, r2);\n}\npub fn instr_660F15_mem_jit(ctx: &mut JitContext, modrm_byte: ModrmByte, r: u32) {\n    sse_read128_xmm_mem(ctx, "instr_660F15", modrm_byte, r);\n}\npub fn instr_660F15_reg_jit(ctx: &mut JitContext, r1: u32, r2: u32) {\n    sse_read128_xmm_xmm(ctx, "instr_660F15", r1, r2);\n}\n\npub fn instr_0F28_mem_jit(ctx: &mut JitContext, modrm_byte: ModrmByte, r: u32) {\n    let dest = global_pointers::get_reg_xmm_offset(r);\n    codegen::gen_modrm_resolve_safe_read128(ctx, modrm_byte, dest);\n}\npub fn instr_0F28_reg_jit(ctx: &mut JitContext, r1: u32, r2: u32) { sse_mov_xmm_xmm(ctx, r1, r2) }\npub fn instr_660F28_mem_jit(ctx: &mut JitContext, modrm_byte: ModrmByte, r: u32) {\n    let dest = global_pointers::get_reg_xmm_offset(r);\n    codegen::gen_modrm_resolve_safe_read128(ctx, modrm_byte, dest);\n}\npub fn instr_660F28_reg_jit(ctx: &mut JitContext, r1: u32, r2: u32) { sse_mov_xmm_xmm(ctx, r1, r2) }\n\npub fn instr_0F29_mem_jit(ctx: &mut JitContext, modrm_byte: ModrmByte, r: u32) {\n    // XXX: Aligned write or #gp\n    codegen::gen_modrm_resolve(ctx, modrm_byte);\n    let address_local = ctx.builder.set_new_local();\n    ctx.builder\n        .const_i32(global_pointers::get_reg_xmm_offset(r) as i32);\n    ctx.builder.load_aligned_i64(0);\n    let value_local_low = ctx.builder.set_new_local_i64();\n    ctx.builder\n        .const_i32(global_pointers::get_reg_xmm_offset(r) as i32 + 8);\n    ctx.builder.load_aligned_i64(0);\n    let value_local_high = ctx.builder.set_new_local_i64();\n    codegen::gen_safe_write128(ctx, &address_local, &value_local_low, &value_local_high);\n    ctx.builder.free_local(address_local);\n    ctx.builder.free_local_i64(value_local_low);\n    ctx.builder.free_local_i64(value_local_high);\n}\npub fn instr_0F29_reg_jit(ctx: &mut JitContext, r1: u32, r2: u32) { sse_mov_xmm_xmm(ctx, r2, r1) }\n\npub fn instr_660F29_mem_jit(ctx: &mut JitContext, modrm_byte: ModrmByte, r: u32) {\n    instr_0F29_mem_jit(ctx, modrm_byte, r);\n}\npub fn instr_660F29_reg_jit(ctx: &mut JitContext, r1: u32, r2: u32) { sse_mov_xmm_xmm(ctx, r2, r1) }\n\npub fn instr_0F2A_mem_jit(ctx: &mut JitContext, modrm_byte: ModrmByte, r: u32) {\n    mmx_read64_mm_mem(ctx, "instr_0F2A", modrm_byte, r);\n}\npub fn instr_0F2A_reg_jit(ctx: &mut JitContext, r1: u32, r2: u32) {\n    mmx_read64_mm_mm(ctx, "instr_0F2A", r1, r2);\n}\npub fn instr_660F2A_mem_jit(ctx: &mut JitContext, modrm_byte: ModrmByte, r: u32) {\n    mmx_read64_mm_mem(ctx, "instr_660F2A", modrm_byte, r);\n}\npub fn instr_660F2A_reg_jit(ctx: &mut JitContext, r1: u32, r2: u32) {\n    mmx_read64_mm_mm(ctx, "instr_660F2A", r1, r2);\n}\npub fn instr_F20F2A_mem_jit(ctx: &mut JitContext, modrm_byte: ModrmByte, r: u32) {\n    codegen::gen_modrm_resolve_safe_read32(ctx, modrm_byte);\n    ctx.builder.const_i32(r as i32);\n    ctx.builder.call_fn2("instr_F20F2A")\n}\npub fn instr_F20F2A_reg_jit(ctx: &mut JitContext, r1: u32, r2: u32) {\n    codegen::gen_get_reg32(ctx, r1);\n    ctx.builder.const_i32(r2 as i32);\n    ctx.builder.call_fn2("instr_F20F2A")\n}\npub fn instr_F30F2A_mem_jit(ctx: &mut JitContext, modrm_byte: ModrmByte, r: u32) {\n    codegen::gen_modrm_resolve_safe_read32(ctx, modrm_byte);\n    ctx.builder.const_i32(r as i32);\n    ctx.builder.call_fn2("instr_F30F2A")\n}\npub fn instr_F30F2A_reg_jit(ctx: &mut JitContext, r1: u32, r2: u32) {\n    codegen::gen_get_reg32(ctx, r1);\n    ctx.builder.const_i32(r2 as i32);\n    ctx.builder.call_fn2("instr_F30F2A")\n}\n\npub fn instr_0F2B_mem_jit(ctx: &mut JitContext, modrm_byte: ModrmByte, r: u32) {\n    instr_0F29_mem_jit(ctx, modrm_byte, r)\n}\npub fn instr_0F2B_reg_jit(ctx: &mut JitContext, _r1: u32, _r2: u32) {\n    codegen::gen_trigger_ud(ctx);\n}\npub fn instr_660F2B_mem_jit(ctx: &mut JitContext, modrm_byte: ModrmByte, r: u32) {\n    instr_0F29_mem_jit(ctx, modrm_byte, r)\n}\npub fn instr_660F2B_reg_jit(ctx: &mut JitContext, _r1: u32, _r2: u32) {\n    codegen::gen_trigger_ud(ctx);\n}\n\npub fn instr_F20F2C_mem_jit(ctx: &mut JitContext, modrm_byte: ModrmByte, r: u32) {\n    codegen::gen_modrm_resolve_safe_read64(ctx, modrm_byte);\n    ctx.builder.reinterpret_i64_as_f64();\n    ctx.builder\n        .call_fn1_f64_ret("sse_convert_with_truncation_f64_to_i32");\n    codegen::gen_set_reg32(ctx, r);\n}\npub fn instr_F20F2C_reg_jit(ctx: &mut JitContext, r1: u32, r2: u32) {\n    ctx.builder\n        .const_i32(global_pointers::get_reg_xmm_offset(r1) as i32);\n    ctx.builder.load_aligned_f64(0);\n    ctx.builder\n        .call_fn1_f64_ret("sse_convert_with_truncation_f64_to_i32");\n    codegen::gen_set_reg32(ctx, r2);\n}\npub fn instr_F30F2C_mem_jit(ctx: &mut JitContext, modrm_byte: ModrmByte, r: u32) {\n    codegen::gen_modrm_resolve_safe_read32(ctx, modrm_byte);\n    ctx.builder.reinterpret_i32_as_f32();\n    ctx.builder\n        .call_fn1_f32_ret("sse_convert_with_truncation_f32_to_i32");\n    codegen::gen_set_reg32(ctx, r);\n}\npub fn instr_F30F2C_reg_jit(ctx: &mut JitContext, r1: u32, r2: u32) {\n    ctx.builder\n        .const_i32(global_pointers::get_reg_xmm_offset(r1) as i32);\n    ctx.builder.load_aligned_f32(0);\n    ctx.builder\n        .call_fn1_f32_ret("sse_convert_with_truncation_f32_to_i32");\n    codegen::gen_set_reg32(ctx, r2);\n}\n\npub fn instr_F20F2D_mem_jit(ctx: &mut JitContext, modrm_byte: ModrmByte, r: u32) {\n    codegen::gen_modrm_resolve_safe_read64(ctx, modrm_byte);\n    ctx.builder.reinterpret_i64_as_f64();\n    ctx.builder.call_fn1_f64_ret("sse_convert_f64_to_i32");\n    codegen::gen_set_reg32(ctx, r);\n}\npub fn instr_F20F2D_reg_jit(ctx: &mut JitContext, r1: u32, r2: u32) {\n    ctx.builder\n        .const_i32(global_pointers::get_reg_xmm_offset(r1) as i32);\n    ctx.builder.load_aligned_f64(0);\n    ctx.builder.call_fn1_f64_ret("sse_convert_f64_to_i32");\n    codegen::gen_set_reg32(ctx, r2);\n}\npub fn instr_F30F2D_mem_jit(ctx: &mut JitContext, modrm_byte: ModrmByte, r: u32) {\n    codegen::gen_modrm_resolve_safe_read32(ctx, modrm_byte);\n    ctx.builder.reinterpret_i32_as_f32();\n    ctx.builder.call_fn1_f32_ret("sse_convert_f32_to_i32");\n    codegen::gen_set_reg32(ctx, r);\n}\npub fn instr_F30F2D_reg_jit(ctx: &mut JitContext, r1: u32, r2: u32) {\n    ctx.builder\n        .const_i32(global_pointers::get_reg_xmm_offset(r1) as i32);\n    ctx.builder.load_aligned_f32(0);\n    ctx.builder.call_fn1_f32_ret("sse_convert_f32_to_i32");\n    codegen::gen_set_reg32(ctx, r2);\n}\n\npub fn instr_0F2E_mem_jit(ctx: &mut JitContext, modrm_byte: ModrmByte, r: u32) {\n    sse_read_f32_xmm_mem(ctx, "instr_0F2E", modrm_byte, r);\n}\npub fn instr_0F2E_reg_jit(ctx: &mut JitContext, r1: u32, r2: u32) {\n    sse_read_f32_xmm_xmm(ctx, "instr_0F2E", r1, r2);\n}\npub fn instr_660F2E_mem_jit(ctx: &mut JitContext, modrm_byte: ModrmByte, r: u32) {\n    sse_read64_xmm_mem(ctx, "instr_660F2E", modrm_byte, r);\n}\npub fn instr_660F2E_reg_jit(ctx: &mut JitContext, r1: u32, r2: u32) {\n    sse_read64_xmm_xmm(ctx, "instr_660F2E", r1, r2);\n}\n\npub fn instr_0F2F_mem_jit(ctx: &mut JitContext, modrm_byte: ModrmByte, r: u32) {\n    sse_read_f32_xmm_mem(ctx, "instr_0F2F", modrm_byte, r);\n}\npub fn instr_0F2F_reg_jit(ctx: &mut JitContext, r1: u32, r2: u32) {\n    sse_read_f32_xmm_xmm(ctx, "instr_0F2F", r1, r2);\n}\npub fn instr_660F2F_mem_jit(ctx: &mut JitContext, modrm_byte: ModrmByte, r: u32) {\n    sse_read64_xmm_mem(ctx, "instr_660F2F", modrm_byte, r);\n}\npub fn instr_660F2F_reg_jit(ctx: &mut JitContext, r1: u32, r2: u32) {\n    sse_read64_xmm_xmm(ctx, "instr_660F2F", r1, r2);\n}\n\npub fn instr_0F51_mem_jit(ctx: &mut JitContext, modrm_byte: ModrmByte, r: u32) {\n    sse_read128_xmm_mem(ctx, "instr_0F51", modrm_byte, r);\n}\npub fn instr_0F51_reg_jit(ctx: &mut JitContext, r1: u32, r2: u32) {\n    sse_read128_xmm_xmm(ctx, "instr_0F51", r1, r2);\n}\npub fn instr_660F51_mem_jit(ctx: &mut JitContext, modrm_byte: ModrmByte, r: u32) {\n    sse_read128_xmm_mem(ctx, "instr_660F51", modrm_byte, r);\n}\npub fn instr_660F51_reg_jit(ctx: &mut JitContext, r1: u32, r2: u32) {\n    sse_read128_xmm_xmm(ctx, "instr_660F51", r1, r2);\n}\npub fn instr_F20F51_mem_jit(ctx: &mut JitContext, modrm_byte: ModrmByte, r: u32) {\n    sse_read64_xmm_mem(ctx, "instr_F20F51", modrm_byte, r);\n}\npub fn instr_F20F51_reg_jit(ctx: &mut JitContext, r1: u32, r2: u32) {\n    sse_read64_xmm_xmm(ctx, "instr_F20F51", r1, r2);\n}\npub fn instr_F30F51_mem_jit(ctx: &mut JitContext, modrm_byte: ModrmByte, r: u32) {\n    sse_read_f32_xmm_mem(ctx, "instr_F30F51", modrm_byte, r);\n}\npub fn instr_F30F51_reg_jit(ctx: &mut JitContext, r1: u32, r2: u32) {\n    sse_read_f32_xmm_xmm(ctx, "instr_F30F51", r1, r2);\n}\n\npub fn instr_0F52_mem_jit(ctx: &mut JitContext, modrm_byte: ModrmByte, r: u32) {\n    sse_read128_xmm_mem(ctx, "instr_0F52", modrm_byte, r);\n}\npub fn instr_0F52_reg_jit(ctx: &mut JitContext, r1: u32, r2: u32) {\n    sse_read128_xmm_xmm(ctx, "instr_0F52", r1, r2);\n}\npub fn instr_F30F52_mem_jit(ctx: &mut JitContext, modrm_byte: ModrmByte, r: u32) {\n    sse_read_f32_xmm_mem(ctx, "instr_F30F52", modrm_byte, r);\n}\npub fn instr_F30F52_reg_jit(ctx: &mut JitContext, r1: u32, r2: u32) {\n    sse_read_f32_xmm_xmm(ctx, "instr_F30F52", r1, r2);\n}\n\npub fn instr_0F53_mem_jit(ctx: &mut JitContext, modrm_byte: ModrmByte, r: u32) {\n    sse_read128_xmm_mem(ctx, "instr_0F53", modrm_byte, r);\n}\npub fn instr_0F53_reg_jit(ctx: &mut JitContext, r1: u32, r2: u32) {\n    sse_read128_xmm_xmm(ctx, "instr_0F53", r1, r2);\n}\npub fn instr_F30F53_mem_jit(ctx: &mut JitContext, modrm_byte: ModrmByte, r: u32) {\n    sse_read_f32_xmm_mem(ctx, "instr_F30F53", modrm_byte, r);\n}\npub fn instr_F30F53_reg_jit(ctx: &mut JitContext, r1: u32, r2: u32) {\n    sse_read_f32_xmm_xmm(ctx, "instr_F30F53", r1, r2);\n}\n\npub fn instr_0F54_mem_jit(ctx: &mut JitContext, modrm_byte: ModrmByte, r: u32) {\n    sse_read128_xmm_mem(ctx, "instr_0F54", modrm_byte, r);\n}\npub fn instr_0F54_reg_jit(ctx: &mut JitContext, r1: u32, r2: u32) {\n    sse_read128_xmm_xmm(ctx, "instr_0F54", r1, r2);\n}\npub fn instr_660F54_mem_jit(ctx: &mut JitContext, modrm_byte: ModrmByte, r: u32) {\n    sse_read128_xmm_mem(ctx, "instr_660F54", modrm_byte, r);\n}\npub fn instr_660F54_reg_jit(ctx: &mut JitContext, r1: u32, r2: u32) {\n    sse_read128_xmm_xmm(ctx, "instr_660F54", r1, r2);\n}\n\npub fn instr_0F55_mem_jit(ctx: &mut JitContext, modrm_byte: ModrmByte, r: u32) {\n    sse_read128_xmm_mem(ctx, "instr_0F55", modrm_byte, r);\n}\npub fn instr_0F55_reg_jit(ctx: &mut JitContext, r1: u32, r2: u32) {\n    sse_read128_xmm_xmm(ctx, "instr_0F55", r1, r2);\n}\npub fn instr_660F55_mem_jit(ctx: &mut JitContext, modrm_byte: ModrmByte, r: u32) {\n    sse_read128_xmm_mem(ctx, "instr_660F55", modrm_byte, r);\n}\npub fn instr_660F55_reg_jit(ctx: &mut JitContext, r1: u32, r2: u32) {\n    sse_read128_xmm_xmm(ctx, "instr_660F55", r1, r2);\n}\n\npub fn instr_0F56_mem_jit(ctx: &mut JitContext, modrm_byte: ModrmByte, r: u32) {\n    sse_read128_xmm_mem(ctx, "instr_0F56", modrm_byte, r);\n}\npub fn instr_0F56_reg_jit(ctx: &mut JitContext, r1: u32, r2: u32) {\n    sse_read128_xmm_xmm(ctx, "instr_0F56", r1, r2);\n}\npub fn instr_660F56_mem_jit(ctx: &mut JitContext, modrm_byte: ModrmByte, r: u32) {\n    sse_read128_xmm_mem(ctx, "instr_660F56", modrm_byte, r);\n}\npub fn instr_660F56_reg_jit(ctx: &mut JitContext, r1: u32, r2: u32) {\n    sse_read128_xmm_xmm(ctx, "instr_660F56", r1, r2);\n}\n\npub fn instr_0F57_mem_jit(ctx: &mut JitContext, modrm_byte: ModrmByte, r: u32) {\n    sse_read128_xmm_mem(ctx, "instr_0F57", modrm_byte, r);\n}\npub fn instr_0F57_reg_jit(ctx: &mut JitContext, r1: u32, r2: u32) {\n    sse_read128_xmm_xmm(ctx, "instr_0F57", r1, r2);\n}\npub fn instr_660F57_mem_jit(ctx: &mut JitContext, modrm_byte: ModrmByte, r: u32) {\n    sse_read128_xmm_mem(ctx, "instr_660F57", modrm_byte, r);\n}\npub fn instr_660F57_reg_jit(ctx: &mut JitContext, r1: u32, r2: u32) {\n    sse_read128_xmm_xmm(ctx, "instr_660F57", r1, r2);\n}\n\npub fn instr_0F58_mem_jit(ctx: &mut JitContext, modrm_byte: ModrmByte, r: u32) {\n    sse_read128_xmm_mem(ctx, "instr_0F58", modrm_byte, r);\n}\npub fn instr_0F58_reg_jit(ctx: &mut JitContext, r1: u32, r2: u32) {\n    sse_read128_xmm_xmm(ctx, "instr_0F58", r1, r2);\n}\npub fn instr_660F58_mem_jit(ctx: &mut JitContext, modrm_byte: ModrmByte, r: u32) {\n    sse_read128_xmm_mem(ctx, "instr_660F58", modrm_byte, r);\n}\npub fn instr_660F58_reg_jit(ctx: &mut JitContext, r1: u32, r2: u32) {\n    sse_read128_xmm_xmm(ctx, "instr_660F58", r1, r2);\n}\npub fn instr_F20F58_mem_jit(ctx: &mut JitContext, modrm_byte: ModrmByte, r: u32) {\n    sse_read64_xmm_mem(ctx, "instr_F20F58", modrm_byte, r);\n}\npub fn instr_F20F58_reg_jit(ctx: &mut JitContext, r1: u32, r2: u32) {\n    sse_read64_xmm_xmm(ctx, "instr_F20F58", r1, r2);\n}\npub fn instr_F30F58_mem_jit(ctx: &mut JitContext, modrm_byte: ModrmByte, r: u32) {\n    sse_read_f32_xmm_mem(ctx, "instr_F30F58", modrm_byte, r);\n}\npub fn instr_F30F58_reg_jit(ctx: &mut JitContext, r1: u32, r2: u32) {\n    sse_read_f32_xmm_xmm(ctx, "instr_F30F58", r1, r2);\n}\n\npub fn instr_0F59_mem_jit(ctx: &mut JitContext, modrm_byte: ModrmByte, r: u32) {\n    sse_read128_xmm_mem(ctx, "instr_0F59", modrm_byte, r);\n}\npub fn instr_0F59_reg_jit(ctx: &mut JitContext, r1: u32, r2: u32) {\n    sse_read128_xmm_xmm(ctx, "instr_0F59", r1, r2);\n}\npub fn instr_660F59_mem_jit(ctx: &mut JitContext, modrm_byte: ModrmByte, r: u32) {\n    sse_read128_xmm_mem(ctx, "instr_660F59", modrm_byte, r);\n}\npub fn instr_660F59_reg_jit(ctx: &mut JitContext, r1: u32, r2: u32) {\n    sse_read128_xmm_xmm(ctx, "instr_660F59", r1, r2);\n}\npub fn instr_F20F59_mem_jit(ctx: &mut JitContext, modrm_byte: ModrmByte, r: u32) {\n    sse_read64_xmm_mem(ctx, "instr_F20F59", modrm_byte, r);\n}\npub fn instr_F20F59_reg_jit(ctx: &mut JitContext, r1: u32, r2: u32) {\n    sse_read64_xmm_xmm(ctx, "instr_F20F59", r1, r2);\n}\npub fn instr_F30F59_mem_jit(ctx: &mut JitContext, modrm_byte: ModrmByte, r: u32) {\n    sse_read_f32_xmm_mem(ctx, "instr_F30F59", modrm_byte, r);\n}\npub fn instr_F30F59_reg_jit(ctx: &mut JitContext, r1: u32, r2: u32) {\n    sse_read_f32_xmm_xmm(ctx, "instr_F30F59", r1, r2);\n}\n\npub fn instr_0F5A_mem_jit(ctx: &mut JitContext, modrm_byte: ModrmByte, r: u32) {\n    sse_read64_xmm_mem(ctx, "instr_0F5A", modrm_byte, r);\n}\npub fn instr_0F5A_reg_jit(ctx: &mut JitContext, r1: u32, r2: u32) {\n    sse_read64_xmm_xmm(ctx, "instr_0F5A", r1, r2);\n}\npub fn instr_660F5A_mem_jit(ctx: &mut JitContext, modrm_byte: ModrmByte, r: u32) {\n    sse_read128_xmm_mem(ctx, "instr_660F5A", modrm_byte, r);\n}\npub fn instr_660F5A_reg_jit(ctx: &mut JitContext, r1: u32, r2: u32) {\n    sse_read128_xmm_xmm(ctx, "instr_660F5A", r1, r2);\n}\npub fn instr_F20F5A_mem_jit(ctx: &mut JitContext, modrm_byte: ModrmByte, r: u32) {\n    sse_read64_xmm_mem(ctx, "instr_F20F5A", modrm_byte, r);\n}\npub fn instr_F20F5A_reg_jit(ctx: &mut JitContext, r1: u32, r2: u32) {\n    sse_read64_xmm_xmm(ctx, "instr_F20F5A", r1, r2);\n}\npub fn instr_F30F5A_mem_jit(ctx: &mut JitContext, modrm_byte: ModrmByte, r: u32) {\n    sse_read_f32_xmm_mem(ctx, "instr_F30F5A", modrm_byte, r);\n}\npub fn instr_F30F5A_reg_jit(ctx: &mut JitContext, r1: u32, r2: u32) {\n    sse_read_f32_xmm_xmm(ctx, "instr_F30F5A", r1, r2);\n}\n\npub fn instr_0F5B_mem_jit(ctx: &mut JitContext, modrm_byte: ModrmByte, r: u32) {\n    sse_read128_xmm_mem(ctx, "instr_0F5B", modrm_byte, r);\n}\npub fn instr_0F5B_reg_jit(ctx: &mut JitContext, r1: u32, r2: u32) {\n    sse_read128_xmm_xmm(ctx, "instr_0F5B", r1, r2);\n}\npub fn instr_660F5B_mem_jit(ctx: &mut JitContext, modrm_byte: ModrmByte, r: u32) {\n    sse_read128_xmm_mem(ctx, "instr_660F5B", modrm_byte, r);\n}\npub fn instr_660F5B_reg_jit(ctx: &mut JitContext, r1: u32, r2: u32) {\n    sse_read128_xmm_xmm(ctx, "instr_660F5B", r1, r2);\n}\npub fn instr_F30F5B_mem_jit(ctx: &mut JitContext, modrm_byte: ModrmByte, r: u32) {\n    sse_read128_xmm_mem(ctx, "instr_F30F5B", modrm_byte, r);\n}\npub fn instr_F30F5B_reg_jit(ctx: &mut JitContext, r1: u32, r2: u32) {\n    sse_read128_xmm_xmm(ctx, "instr_F30F5B", r1, r2);\n}\n\npub fn instr_0F5C_mem_jit(ctx: &mut JitContext, modrm_byte: ModrmByte, r: u32) {\n    sse_read128_xmm_mem(ctx, "instr_0F5C", modrm_byte, r);\n}\npub fn instr_0F5C_reg_jit(ctx: &mut JitContext, r1: u32, r2: u32) {\n    sse_read128_xmm_xmm(ctx, "instr_0F5C", r1, r2);\n}\npub fn instr_660F5C_mem_jit(ctx: &mut JitContext, modrm_byte: ModrmByte, r: u32) {\n    sse_read128_xmm_mem(ctx, "instr_660F5C", modrm_byte, r);\n}\npub fn instr_660F5C_reg_jit(ctx: &mut JitContext, r1: u32, r2: u32) {\n    sse_read128_xmm_xmm(ctx, "instr_660F5C", r1, r2);\n}\npub fn instr_F20F5C_mem_jit(ctx: &mut JitContext, modrm_byte: ModrmByte, r: u32) {\n    sse_read64_xmm_mem(ctx, "instr_F20F5C", modrm_byte, r);\n}\npub fn instr_F20F5C_reg_jit(ctx: &mut JitContext, r1: u32, r2: u32) {\n    sse_read64_xmm_xmm(ctx, "instr_F20F5C", r1, r2);\n}\npub fn instr_F30F5C_mem_jit(ctx: &mut JitContext, modrm_byte: ModrmByte, r: u32) {\n    sse_read_f32_xmm_mem(ctx, "instr_F30F5C", modrm_byte, r);\n}\npub fn instr_F30F5C_reg_jit(ctx: &mut JitContext, r1: u32, r2: u32) {\n    sse_read_f32_xmm_xmm(ctx, "instr_F30F5C", r1, r2);\n}\n\npub fn instr_0F5D_mem_jit(ctx: &mut JitContext, modrm_byte: ModrmByte, r: u32) {\n    sse_read128_xmm_mem(ctx, "instr_0F5D", modrm_byte, r);\n}\npub fn instr_0F5D_reg_jit(ctx: &mut JitContext, r1: u32, r2: u32) {\n    sse_read128_xmm_xmm(ctx, "instr_0F5D", r1, r2);\n}\npub fn instr_660F5D_mem_jit(ctx: &mut JitContext, modrm_byte: ModrmByte, r: u32) {\n    sse_read128_xmm_mem(ctx, "instr_660F5D", modrm_byte, r);\n}\npub fn instr_660F5D_reg_jit(ctx: &mut JitContext, r1: u32, r2: u32) {\n    sse_read128_xmm_xmm(ctx, "instr_660F5D", r1, r2);\n}\npub fn instr_F20F5D_mem_jit(ctx: &mut JitContext, modrm_byte: ModrmByte, r: u32) {\n    sse_read64_xmm_mem(ctx, "instr_F20F5D", modrm_byte, r);\n}\npub fn instr_F20F5D_reg_jit(ctx: &mut JitContext, r1: u32, r2: u32) {\n    sse_read64_xmm_xmm(ctx, "instr_F20F5D", r1, r2);\n}\npub fn instr_F30F5D_mem_jit(ctx: &mut JitContext, modrm_byte: ModrmByte, r: u32) {\n    sse_read_f32_xmm_mem(ctx, "instr_F30F5D", modrm_byte, r);\n}\npub fn instr_F30F5D_reg_jit(ctx: &mut JitContext, r1: u32, r2: u32) {\n    sse_read_f32_xmm_xmm(ctx, "instr_F30F5D", r1, r2);\n}\n\npub fn instr_0F5E_mem_jit(ctx: &mut JitContext, modrm_byte: ModrmByte, r: u32) {\n    sse_read128_xmm_mem(ctx, "instr_0F5E", modrm_byte, r);\n}\npub fn instr_0F5E_reg_jit(ctx: &mut JitContext, r1: u32, r2: u32) {\n    sse_read128_xmm_xmm(ctx, "instr_0F5E", r1, r2);\n}\npub fn instr_660F5E_mem_jit(ctx: &mut JitContext, modrm_byte: ModrmByte, r: u32) {\n    sse_read128_xmm_mem(ctx, "instr_660F5E", modrm_byte, r);\n}\npub fn instr_660F5E_reg_jit(ctx: &mut JitContext, r1: u32, r2: u32) {\n    sse_read128_xmm_xmm(ctx, "instr_660F5E", r1, r2);\n}\npub fn instr_F20F5E_mem_jit(ctx: &mut JitContext, modrm_byte: ModrmByte, r: u32) {\n    sse_read64_xmm_mem(ctx, "instr_F20F5E", modrm_byte, r);\n}\npub fn instr_F20F5E_reg_jit(ctx: &mut JitContext, r1: u32, r2: u32) {\n    sse_read64_xmm_xmm(ctx, "instr_F20F5E", r1, r2);\n}\npub fn instr_F30F5E_mem_jit(ctx: &mut JitContext, modrm_byte: ModrmByte, r: u32) {\n    sse_read_f32_xmm_mem(ctx, "instr_F30F5E", modrm_byte, r);\n}\npub fn instr_F30F5E_reg_jit(ctx: &mut JitContext, r1: u32, r2: u32) {\n    sse_read_f32_xmm_xmm(ctx, "instr_F30F5E", r1, r2);\n}\n\npub fn instr_0F5F_mem_jit(ctx: &mut JitContext, modrm_byte: ModrmByte, r: u32) {\n    sse_read128_xmm_mem(ctx, "instr_0F5F", modrm_byte, r);\n}\npub fn instr_0F5F_reg_jit(ctx: &mut JitContext, r1: u32, r2: u32) {\n    sse_read128_xmm_xmm(ctx, "instr_0F5F", r1, r2);\n}\npub fn instr_660F5F_mem_jit(ctx: &mut JitContext, modrm_byte: ModrmByte, r: u32) {\n    sse_read128_xmm_mem(ctx, "instr_660F5F", modrm_byte, r);\n}\npub fn instr_660F5F_reg_jit(ctx: &mut JitContext, r1: u32, r2: u32) {\n    sse_read128_xmm_xmm(ctx, "instr_660F5F", r1, r2);\n}\npub fn instr_F20F5F_mem_jit(ctx: &mut JitContext, modrm_byte: ModrmByte, r: u32) {\n    sse_read64_xmm_mem(ctx, "instr_F20F5F", modrm_byte, r);\n}\npub fn instr_F20F5F_reg_jit(ctx: &mut JitContext, r1: u32, r2: u32) {\n    sse_read64_xmm_xmm(ctx, "instr_F20F5F", r1, r2);\n}\npub fn instr_F30F5F_mem_jit(ctx: &mut JitContext, modrm_byte: ModrmByte, r: u32) {\n    sse_read_f32_xmm_mem(ctx, "instr_F30F5F", modrm_byte, r);\n}\npub fn instr_F30F5F_reg_jit(ctx: &mut JitContext, r1: u32, r2: u32) {\n    sse_read_f32_xmm_xmm(ctx, "instr_F30F5F", r1, r2);\n}\n\npub fn instr_0F60_mem_jit(ctx: &mut JitContext, modrm_byte: ModrmByte, r: u32) {\n    mmx_read64_mm_mem32(ctx, "instr_0F60", modrm_byte, r);\n}\npub fn instr_0F60_reg_jit(ctx: &mut JitContext, r1: u32, r2: u32) {\n    mmx_read64_mm_mm32(ctx, "instr_0F60", r1, r2);\n}\npub fn instr_0F61_mem_jit(ctx: &mut JitContext, modrm_byte: ModrmByte, r: u32) {\n    mmx_read64_mm_mem32(ctx, "instr_0F61", modrm_byte, r);\n}\npub fn instr_0F61_reg_jit(ctx: &mut JitContext, r1: u32, r2: u32) {\n    mmx_read64_mm_mm32(ctx, "instr_0F61", r1, r2);\n}\npub fn instr_0F62_mem_jit(ctx: &mut JitContext, modrm_byte: ModrmByte, r: u32) {\n    mmx_read64_mm_mem32(ctx, "instr_0F62", modrm_byte, r);\n}\npub fn instr_0F62_reg_jit(ctx: &mut JitContext, r1: u32, r2: u32) {\n    mmx_read64_mm_mm32(ctx, "instr_0F62", r1, r2);\n}\n\npub fn instr_0F63_mem_jit(ctx: &mut JitContext, modrm_byte: ModrmByte, r: u32) {\n    mmx_read64_mm_mem(ctx, "instr_0F63", modrm_byte, r);\n}\npub fn instr_0F63_reg_jit(ctx: &mut JitContext, r1: u32, r2: u32) {\n    mmx_read64_mm_mm(ctx, "instr_0F63", r1, r2);\n}\npub fn instr_0F64_mem_jit(ctx: &mut JitContext, modrm_byte: ModrmByte, r: u32) {\n    mmx_read64_mm_mem(ctx, "instr_0F64", modrm_byte, r);\n}\npub fn instr_0F64_reg_jit(ctx: &mut JitContext, r1: u32, r2: u32) {\n    mmx_read64_mm_mm(ctx, "instr_0F64", r1, r2);\n}\npub fn instr_0F65_mem_jit(ctx: &mut JitContext, modrm_byte: ModrmByte, r: u32) {\n    mmx_read64_mm_mem(ctx, "instr_0F65", modrm_byte, r);\n}\npub fn instr_0F65_reg_jit(ctx: &mut JitContext, r1: u32, r2: u32) {\n    mmx_read64_mm_mm(ctx, "instr_0F65", r1, r2);\n}\npub fn instr_0F66_mem_jit(ctx: &mut JitContext, modrm_byte: ModrmByte, r: u32) {\n    mmx_read64_mm_mem(ctx, "instr_0F66", modrm_byte, r);\n}\npub fn instr_0F66_reg_jit(ctx: &mut JitContext, r1: u32, r2: u32) {\n    mmx_read64_mm_mm(ctx, "instr_0F66", r1, r2);\n}\npub fn instr_0F67_mem_jit(ctx: &mut JitContext, modrm_byte: ModrmByte, r: u32) {\n    mmx_read64_mm_mem(ctx, "instr_0F67", modrm_byte, r);\n}\npub fn instr_0F67_reg_jit(ctx: &mut JitContext, r1: u32, r2: u32) {\n    mmx_read64_mm_mm(ctx, "instr_0F67", r1, r2);\n}\npub fn instr_0F68_mem_jit(ctx: &mut JitContext, modrm_byte: ModrmByte, r: u32) {\n    mmx_read64_mm_mem(ctx, "instr_0F68", modrm_byte, r);\n}\npub fn instr_0F68_reg_jit(ctx: &mut JitContext, r1: u32, r2: u32) {\n    mmx_read64_mm_mm(ctx, "instr_0F68", r1, r2);\n}\npub fn instr_0F69_mem_jit(ctx: &mut JitContext, modrm_byte: ModrmByte, r: u32) {\n    mmx_read64_mm_mem(ctx, "instr_0F69", modrm_byte, r);\n}\npub fn instr_0F69_reg_jit(ctx: &mut JitContext, r1: u32, r2: u32) {\n    mmx_read64_mm_mm(ctx, "instr_0F69", r1, r2);\n}\npub fn instr_0F6A_mem_jit(ctx: &mut JitContext, modrm_byte: ModrmByte, r: u32) {\n    mmx_read64_mm_mem(ctx, "instr_0F6A", modrm_byte, r);\n}\npub fn instr_0F6A_reg_jit(ctx: &mut JitContext, r1: u32, r2: u32) {\n    mmx_read64_mm_mm(ctx, "instr_0F6A", r1, r2);\n}\npub fn instr_0F6B_mem_jit(ctx: &mut JitContext, modrm_byte: ModrmByte, r: u32) {\n    mmx_read64_mm_mem(ctx, "instr_0F6B", modrm_byte, r);\n}\npub fn instr_0F6B_reg_jit(ctx: &mut JitContext, r1: u32, r2: u32) {\n    mmx_read64_mm_mm(ctx, "instr_0F6B", r1, r2);\n}\n\npub fn instr_660F60_mem_jit(ctx: &mut JitContext, modrm_byte: ModrmByte, r: u32) {\n    // Note: Only requires 64-bit read, but is allowed to do 128-bit read\n    sse_read128_xmm_mem(ctx, "instr_660F60", modrm_byte, r);\n}\npub fn instr_660F60_reg_jit(ctx: &mut JitContext, r1: u32, r2: u32) {\n    sse_read128_xmm_xmm(ctx, "instr_660F60", r1, r2);\n}\npub fn instr_660F61_mem_jit(ctx: &mut JitContext, modrm_byte: ModrmByte, r: u32) {\n    // Note: Only requires 64-bit read, but is allowed to do 128-bit read\n    sse_read128_xmm_mem(ctx, "instr_660F61", modrm_byte, r);\n}\npub fn instr_660F61_reg_jit(ctx: &mut JitContext, r1: u32, r2: u32) {\n    sse_read128_xmm_xmm(ctx, "instr_660F61", r1, r2);\n}\npub fn instr_660F62_mem_jit(ctx: &mut JitContext, modrm_byte: ModrmByte, r: u32) {\n    sse_read128_xmm_mem(ctx, "instr_660F62", modrm_byte, r);\n}\npub fn instr_660F62_reg_jit(ctx: &mut JitContext, r1: u32, r2: u32) {\n    sse_read128_xmm_xmm(ctx, "instr_660F62", r1, r2);\n}\npub fn instr_660F63_mem_jit(ctx: &mut JitContext, modrm_byte: ModrmByte, r: u32) {\n    sse_read128_xmm_mem(ctx, "instr_660F63", modrm_byte, r);\n}\npub fn instr_660F63_reg_jit(ctx: &mut JitContext, r1: u32, r2: u32) {\n    sse_read128_xmm_xmm(ctx, "instr_660F63", r1, r2);\n}\npub fn instr_660F64_mem_jit(ctx: &mut JitContext, modrm_byte: ModrmByte, r: u32) {\n    sse_read128_xmm_mem(ctx, "instr_660F64", modrm_byte, r);\n}\npub fn instr_660F64_reg_jit(ctx: &mut JitContext, r1: u32, r2: u32) {\n    sse_read128_xmm_xmm(ctx, "instr_660F64", r1, r2);\n}\npub fn instr_660F65_mem_jit(ctx: &mut JitContext, modrm_byte: ModrmByte, r: u32) {\n    sse_read128_xmm_mem(ctx, "instr_660F65", modrm_byte, r);\n}\npub fn instr_660F65_reg_jit(ctx: &mut JitContext, r1: u32, r2: u32) {\n    sse_read128_xmm_xmm(ctx, "instr_660F65", r1, r2);\n}\npub fn instr_660F66_mem_jit(ctx: &mut JitContext, modrm_byte: ModrmByte, r: u32) {\n    sse_read128_xmm_mem(ctx, "instr_660F66", modrm_byte, r);\n}\npub fn instr_660F66_reg_jit(ctx: &mut JitContext, r1: u32, r2: u32) {\n    sse_read128_xmm_xmm(ctx, "instr_660F66", r1, r2);\n}\npub fn instr_660F67_mem_jit(ctx: &mut JitContext, modrm_byte: ModrmByte, r: u32) {\n    sse_read128_xmm_mem(ctx, "instr_660F67", modrm_byte, r);\n}\npub fn instr_660F67_reg_jit(ctx: &mut JitContext, r1: u32, r2: u32) {\n    sse_read128_xmm_xmm(ctx, "instr_660F67", r1, r2);\n}\npub fn instr_660F68_mem_jit(ctx: &mut JitContext, modrm_byte: ModrmByte, r: u32) {\n    sse_read128_xmm_mem(ctx, "instr_660F68", modrm_byte, r);\n}\npub fn instr_660F68_reg_jit(ctx: &mut JitContext, r1: u32, r2: u32) {\n    sse_read128_xmm_xmm(ctx, "instr_660F68", r1, r2);\n}\npub fn instr_660F69_mem_jit(ctx: &mut JitContext, modrm_byte: ModrmByte, r: u32) {\n    sse_read128_xmm_mem(ctx, "instr_660F69", modrm_byte, r);\n}\npub fn instr_660F69_reg_jit(ctx: &mut JitContext, r1: u32, r2: u32) {\n    sse_read128_xmm_xmm(ctx, "instr_660F69", r1, r2);\n}\npub fn instr_660F6A_mem_jit(ctx: &mut JitContext, modrm_byte: ModrmByte, r: u32) {\n    sse_read128_xmm_mem(ctx, "instr_660F6A", modrm_byte, r);\n}\npub fn instr_660F6A_reg_jit(ctx: &mut JitContext, r1: u32, r2: u32) {\n    sse_read128_xmm_xmm(ctx, "instr_660F6A", r1, r2);\n}\npub fn instr_660F6B_mem_jit(ctx: &mut JitContext, modrm_byte: ModrmByte, r: u32) {\n    sse_read128_xmm_mem(ctx, "instr_660F6B", modrm_byte, r);\n}\npub fn instr_660F6B_reg_jit(ctx: &mut JitContext, r1: u32, r2: u32) {\n    sse_read128_xmm_xmm(ctx, "instr_660F6B", r1, r2);\n}\npub fn instr_660F6C_mem_jit(ctx: &mut JitContext, modrm_byte: ModrmByte, r: u32) {\n    sse_read128_xmm_mem(ctx, "instr_660F6C", modrm_byte, r);\n}\npub fn instr_660F6C_reg_jit(ctx: &mut JitContext, r1: u32, r2: u32) {\n    sse_read128_xmm_xmm(ctx, "instr_660F6C", r1, r2);\n}\npub fn instr_660F6D_mem_jit(ctx: &mut JitContext, modrm_byte: ModrmByte, r: u32) {\n    sse_read128_xmm_mem(ctx, "instr_660F6D", modrm_byte, r);\n}\npub fn instr_660F6D_reg_jit(ctx: &mut JitContext, r1: u32, r2: u32) {\n    sse_read128_xmm_xmm(ctx, "instr_660F6D", r1, r2);\n}\n\npub fn instr_0F6E_mem_jit(ctx: &mut JitContext, modrm_byte: ModrmByte, r: u32) {\n    codegen::gen_modrm_resolve_safe_read32(ctx, modrm_byte);\n    ctx.builder.const_i32(r as i32);\n    ctx.builder.call_fn2("instr_0F6E")\n}\npub fn instr_0F6E_reg_jit(ctx: &mut JitContext, r1: u32, r2: u32) {\n    codegen::gen_get_reg32(ctx, r1);\n    ctx.builder.const_i32(r2 as i32);\n    ctx.builder.call_fn2("instr_0F6E")\n}\n\npub fn instr_660F6E_mem_jit(ctx: &mut JitContext, modrm_byte: ModrmByte, r: u32) {\n    codegen::gen_modrm_resolve_safe_read32(ctx, modrm_byte);\n    ctx.builder.const_i32(r as i32);\n    ctx.builder.call_fn2("instr_660F6E")\n}\npub fn instr_660F6E_reg_jit(ctx: &mut JitContext, r1: u32, r2: u32) {\n    codegen::gen_get_reg32(ctx, r1);\n    ctx.builder.const_i32(r2 as i32);\n    ctx.builder.call_fn2("instr_660F6E")\n}\n\npub fn instr_0F6F_mem_jit(ctx: &mut JitContext, modrm_byte: ModrmByte, r: u32) {\n    // XXX: Aligned read or #gp\n    codegen::gen_modrm_resolve_safe_read64(ctx, modrm_byte);\n    ctx.builder.const_i32(r as i32);\n    ctx.builder.call_fn2_i64_i32("instr_0F6F")\n}\npub fn instr_0F6F_reg_jit(ctx: &mut JitContext, r1: u32, r2: u32) {\n    ctx.builder.const_i32(r1 as i32);\n    ctx.builder.const_i32(r2 as i32);\n    ctx.builder.call_fn2("instr_0F6F_reg")\n}\n\npub fn instr_660F6F_mem_jit(ctx: &mut JitContext, modrm_byte: ModrmByte, r: u32) {\n    // XXX: Aligned read or #gp\n    let dest = global_pointers::get_reg_xmm_offset(r);\n    codegen::gen_modrm_resolve_safe_read128(ctx, modrm_byte, dest);\n}\npub fn instr_660F6F_reg_jit(ctx: &mut JitContext, r1: u32, r2: u32) { sse_mov_xmm_xmm(ctx, r1, r2) }\npub fn instr_F30F6F_mem_jit(ctx: &mut JitContext, modrm_byte: ModrmByte, r: u32) {\n    let dest = global_pointers::get_reg_xmm_offset(r);\n    codegen::gen_modrm_resolve_safe_read128(ctx, modrm_byte, dest);\n}\npub fn instr_F30F6F_reg_jit(ctx: &mut JitContext, r1: u32, r2: u32) { sse_mov_xmm_xmm(ctx, r1, r2) }\n\npub fn instr_0F70_mem_jit(ctx: &mut JitContext, modrm_byte: ModrmByte, r: u32, imm8: u32) {\n    codegen::gen_modrm_resolve_safe_read64(ctx, modrm_byte);\n    ctx.builder.const_i32(r as i32);\n    ctx.builder.const_i32(imm8 as i32);\n    ctx.builder.call_fn3_i64_i32_i32("instr_0F70");\n}\npub fn instr_0F70_reg_jit(ctx: &mut JitContext, r1: u32, r2: u32, imm8: u32) {\n    ctx.builder\n        .const_i32(global_pointers::get_reg_mmx_offset(r1) as i32);\n    ctx.builder.load_aligned_i64(0);\n    ctx.builder.const_i32(r2 as i32);\n    ctx.builder.const_i32(imm8 as i32);\n    ctx.builder.call_fn3_i64_i32_i32("instr_0F70");\n}\npub fn instr_660F70_mem_jit(ctx: &mut JitContext, modrm_byte: ModrmByte, r: u32, imm8: u32) {\n    sse_read128_xmm_mem_imm(ctx, "instr_660F70", modrm_byte, r, imm8)\n}\npub fn instr_660F70_reg_jit(ctx: &mut JitContext, r1: u32, r2: u32, imm8: u32) {\n    sse_read128_xmm_xmm_imm(ctx, "instr_660F70", r1, r2, imm8)\n}\npub fn instr_F20F70_mem_jit(ctx: &mut JitContext, modrm_byte: ModrmByte, r: u32, imm8: u32) {\n    sse_read128_xmm_mem_imm(ctx, "instr_F20F70", modrm_byte, r, imm8)\n}\npub fn instr_F20F70_reg_jit(ctx: &mut JitContext, r1: u32, r2: u32, imm8: u32) {\n    sse_read128_xmm_xmm_imm(ctx, "instr_F20F70", r1, r2, imm8)\n}\npub fn instr_F30F70_mem_jit(ctx: &mut JitContext, modrm_byte: ModrmByte, r: u32, imm8: u32) {\n    sse_read128_xmm_mem_imm(ctx, "instr_F30F70", modrm_byte, r, imm8)\n}\npub fn instr_F30F70_reg_jit(ctx: &mut JitContext, r1: u32, r2: u32, imm8: u32) {\n    sse_read128_xmm_xmm_imm(ctx, "instr_F30F70", r1, r2, imm8)\n}\n\npub fn instr_0F71_2_mem_jit(ctx: &mut JitContext, _modrm_byte: ModrmByte, _imm: u32) {\n    codegen::gen_trigger_ud(ctx);\n}\npub fn instr_0F71_2_reg_jit(ctx: &mut JitContext, r: u32, imm8: u32) {\n    ctx.builder.const_i32(r as i32);\n    ctx.builder.const_i32(imm8 as i32);\n    ctx.builder.call_fn2("instr_0F71_2_reg");\n}\npub fn instr_0F71_4_mem_jit(ctx: &mut JitContext, _modrm_byte: ModrmByte, _imm: u32) {\n    codegen::gen_trigger_ud(ctx);\n}\npub fn instr_0F71_4_reg_jit(ctx: &mut JitContext, r: u32, imm8: u32) {\n    ctx.builder.const_i32(r as i32);\n    ctx.builder.const_i32(imm8 as i32);\n    ctx.builder.call_fn2("instr_0F71_4_reg");\n}\npub fn instr_0F71_6_mem_jit(ctx: &mut JitContext, _modrm_byte: ModrmByte, _imm: u32) {\n    codegen::gen_trigger_ud(ctx);\n}\npub fn instr_0F71_6_reg_jit(ctx: &mut JitContext, r: u32, imm8: u32) {\n    ctx.builder.const_i32(r as i32);\n    ctx.builder.const_i32(imm8 as i32);\n    ctx.builder.call_fn2("instr_0F71_6_reg");\n}\n\npub fn instr_0F72_2_mem_jit(ctx: &mut JitContext, _modrm_byte: ModrmByte, _imm: u32) {\n    codegen::gen_trigger_ud(ctx);\n}\npub fn instr_0F72_2_reg_jit(ctx: &mut JitContext, r: u32, imm8: u32) {\n    ctx.builder.const_i32(r as i32);\n    ctx.builder.const_i32(imm8 as i32);\n    ctx.builder.call_fn2("instr_0F72_2_reg");\n}\npub fn instr_0F72_4_mem_jit(ctx: &mut JitContext, _modrm_byte: ModrmByte, _imm: u32) {\n    codegen::gen_trigger_ud(ctx);\n}\npub fn instr_0F72_4_reg_jit(ctx: &mut JitContext, r: u32, imm8: u32) {\n    ctx.builder.const_i32(r as i32);\n    ctx.builder.const_i32(imm8 as i32);\n    ctx.builder.call_fn2("instr_0F72_4_reg");\n}\npub fn instr_0F72_6_mem_jit(ctx: &mut JitContext, _modrm_byte: ModrmByte, _imm: u32) {\n    codegen::gen_trigger_ud(ctx);\n}\npub fn instr_0F72_6_reg_jit(ctx: &mut JitContext, r: u32, imm8: u32) {\n    ctx.builder.const_i32(r as i32);\n    ctx.builder.const_i32(imm8 as i32);\n    ctx.builder.call_fn2("instr_0F72_6_reg");\n}\n\npub fn instr_0F73_2_mem_jit(ctx: &mut JitContext, _modrm_byte: ModrmByte, _imm: u32) {\n    codegen::gen_trigger_ud(ctx);\n}\npub fn instr_0F73_2_reg_jit(ctx: &mut JitContext, r: u32, imm8: u32) {\n    ctx.builder.const_i32(r as i32);\n    ctx.builder.const_i32(imm8 as i32);\n    ctx.builder.call_fn2("instr_0F73_2_reg");\n}\npub fn instr_0F73_6_mem_jit(ctx: &mut JitContext, _modrm_byte: ModrmByte, _imm: u32) {\n    codegen::gen_trigger_ud(ctx);\n}\npub fn instr_0F73_6_reg_jit(ctx: &mut JitContext, r: u32, imm8: u32) {\n    ctx.builder.const_i32(r as i32);\n    ctx.builder.const_i32(imm8 as i32);\n    ctx.builder.call_fn2("instr_0F73_6_reg");\n}\n\npub fn instr_660F71_2_mem_jit(ctx: &mut JitContext, _modrm_byte: ModrmByte, _imm: u32) {\n    codegen::gen_trigger_ud(ctx);\n}\npub fn instr_660F71_2_reg_jit(ctx: &mut JitContext, r: u32, imm8: u32) {\n    ctx.builder.const_i32(r as i32);\n    ctx.builder.const_i32(imm8 as i32);\n    ctx.builder.call_fn2("instr_660F71_2_reg");\n}\npub fn instr_660F71_4_mem_jit(ctx: &mut JitContext, _modrm_byte: ModrmByte, _imm: u32) {\n    codegen::gen_trigger_ud(ctx);\n}\npub fn instr_660F71_4_reg_jit(ctx: &mut JitContext, r: u32, imm8: u32) {\n    ctx.builder.const_i32(r as i32);\n    ctx.builder.const_i32(imm8 as i32);\n    ctx.builder.call_fn2("instr_660F71_4_reg");\n}\npub fn instr_660F71_6_mem_jit(ctx: &mut JitContext, _modrm_byte: ModrmByte, _imm: u32) {\n    codegen::gen_trigger_ud(ctx);\n}\npub fn instr_660F71_6_reg_jit(ctx: &mut JitContext, r: u32, imm8: u32) {\n    ctx.builder.const_i32(r as i32);\n    ctx.builder.const_i32(imm8 as i32);\n    ctx.builder.call_fn2("instr_660F71_6_reg");\n}\n\npub fn instr_660F72_2_mem_jit(ctx: &mut JitContext, _modrm_byte: ModrmByte, _imm: u32) {\n    codegen::gen_trigger_ud(ctx);\n}\npub fn instr_660F72_2_reg_jit(ctx: &mut JitContext, r: u32, imm8: u32) {\n    ctx.builder.const_i32(r as i32);\n    ctx.builder.const_i32(imm8 as i32);\n    ctx.builder.call_fn2("instr_660F72_2_reg");\n}\npub fn instr_660F72_4_mem_jit(ctx: &mut JitContext, _modrm_byte: ModrmByte, _imm: u32) {\n    codegen::gen_trigger_ud(ctx);\n}\npub fn instr_660F72_4_reg_jit(ctx: &mut JitContext, r: u32, imm8: u32) {\n    ctx.builder.const_i32(r as i32);\n    ctx.builder.const_i32(imm8 as i32);\n    ctx.builder.call_fn2("instr_660F72_4_reg");\n}\npub fn instr_660F72_6_mem_jit(ctx: &mut JitContext, _modrm_byte: ModrmByte, _imm: u32) {\n    codegen::gen_trigger_ud(ctx);\n}\npub fn instr_660F72_6_reg_jit(ctx: &mut JitContext, r: u32, imm8: u32) {\n    ctx.builder.const_i32(r as i32);\n    ctx.builder.const_i32(imm8 as i32);\n    ctx.builder.call_fn2("instr_660F72_6_reg");\n}\n\npub fn instr_660F73_2_mem_jit(ctx: &mut JitContext, _modrm_byte: ModrmByte, _imm: u32) {\n    codegen::gen_trigger_ud(ctx);\n}\npub fn instr_660F73_2_reg_jit(ctx: &mut JitContext, r: u32, imm8: u32) {\n    ctx.builder.const_i32(r as i32);\n    ctx.builder.const_i32(imm8 as i32);\n    ctx.builder.call_fn2("instr_660F73_2_reg");\n}\npub fn instr_660F73_3_mem_jit(ctx: &mut JitContext, _modrm_byte: ModrmByte, _imm: u32) {\n    codegen::gen_trigger_ud(ctx);\n}\npub fn instr_660F73_3_reg_jit(ctx: &mut JitContext, r: u32, imm8: u32) {\n    ctx.builder.const_i32(r as i32);\n    ctx.builder.const_i32(imm8 as i32);\n    ctx.builder.call_fn2("instr_660F73_3_reg");\n}\npub fn instr_660F73_6_mem_jit(ctx: &mut JitContext, _modrm_byte: ModrmByte, _imm: u32) {\n    codegen::gen_trigger_ud(ctx);\n}\npub fn instr_660F73_6_reg_jit(ctx: &mut JitContext, r: u32, imm8: u32) {\n    ctx.builder.const_i32(r as i32);\n    ctx.builder.const_i32(imm8 as i32);\n    ctx.builder.call_fn2("instr_660F73_6_reg");\n}\npub fn instr_660F73_7_mem_jit(ctx: &mut JitContext, _modrm_byte: ModrmByte, _imm: u32) {\n    codegen::gen_trigger_ud(ctx);\n}\npub fn instr_660F73_7_reg_jit(ctx: &mut JitContext, r: u32, imm8: u32) {\n    ctx.builder.const_i32(r as i32);\n    ctx.builder.const_i32(imm8 as i32);\n    ctx.builder.call_fn2("instr_660F73_7_reg");\n}\n\npub fn instr_0F74_mem_jit(ctx: &mut JitContext, modrm_byte: ModrmByte, r: u32) {\n    mmx_read64_mm_mem(ctx, "instr_0F74", modrm_byte, r);\n}\npub fn instr_0F74_reg_jit(ctx: &mut JitContext, r1: u32, r2: u32) {\n    mmx_read64_mm_mm(ctx, "instr_0F74", r1, r2);\n}\npub fn instr_0F75_mem_jit(ctx: &mut JitContext, modrm_byte: ModrmByte, r: u32) {\n    mmx_read64_mm_mem(ctx, "instr_0F75", modrm_byte, r);\n}\npub fn instr_0F75_reg_jit(ctx: &mut JitContext, r1: u32, r2: u32) {\n    mmx_read64_mm_mm(ctx, "instr_0F75", r1, r2);\n}\npub fn instr_0F76_mem_jit(ctx: &mut JitContext, modrm_byte: ModrmByte, r: u32) {\n    mmx_read64_mm_mem(ctx, "instr_0F76", modrm_byte, r);\n}\npub fn instr_0F76_reg_jit(ctx: &mut JitContext, r1: u32, r2: u32) {\n    mmx_read64_mm_mm(ctx, "instr_0F76", r1, r2);\n}\n\npub fn instr_660F74_mem_jit(ctx: &mut JitContext, modrm_byte: ModrmByte, r: u32) {\n    sse_read128_xmm_mem(ctx, "instr_660F74", modrm_byte, r);\n}\npub fn instr_660F74_reg_jit(ctx: &mut JitContext, r1: u32, r2: u32) {\n    sse_read128_xmm_xmm(ctx, "instr_660F74", r1, r2);\n}\npub fn instr_660F75_mem_jit(ctx: &mut JitContext, modrm_byte: ModrmByte, r: u32) {\n    sse_read128_xmm_mem(ctx, "instr_660F75", modrm_byte, r);\n}\npub fn instr_660F75_reg_jit(ctx: &mut JitContext, r1: u32, r2: u32) {\n    sse_read128_xmm_xmm(ctx, "instr_660F75", r1, r2);\n}\npub fn instr_660F76_mem_jit(ctx: &mut JitContext, modrm_byte: ModrmByte, r: u32) {\n    sse_read128_xmm_mem(ctx, "instr_660F76", modrm_byte, r);\n}\npub fn instr_660F76_reg_jit(ctx: &mut JitContext, r1: u32, r2: u32) {\n    sse_read128_xmm_xmm(ctx, "instr_660F76", r1, r2);\n}\n\npub fn instr_0F7E_mem_jit(ctx: &mut JitContext, modrm_byte: ModrmByte, r: u32) {\n    codegen::gen_modrm_resolve(ctx, modrm_byte);\n    let address_local = ctx.builder.set_new_local();\n    ctx.builder.const_i32(r as i32);\n    ctx.builder.call_fn1_ret("instr_0F7E");\n    let value_local = ctx.builder.set_new_local();\n    codegen::gen_safe_write32(ctx, &address_local, &value_local);\n    ctx.builder.free_local(address_local);\n    ctx.builder.free_local(value_local);\n}\npub fn instr_0F7E_reg_jit(ctx: &mut JitContext, r1: u32, r2: u32) {\n    ctx.builder.const_i32(r2 as i32);\n    ctx.builder.call_fn1_ret("instr_0F7E");\n    codegen::gen_set_reg32(ctx, r1);\n}\n\npub fn instr_660F7E_mem_jit(ctx: &mut JitContext, modrm_byte: ModrmByte, r: u32) {\n    codegen::gen_modrm_resolve(ctx, modrm_byte);\n    let address_local = ctx.builder.set_new_local();\n    ctx.builder\n        .load_fixed_i32(global_pointers::get_reg_xmm_offset(r));\n    let value_local = ctx.builder.set_new_local();\n    codegen::gen_safe_write32(ctx, &address_local, &value_local);\n    ctx.builder.free_local(address_local);\n    ctx.builder.free_local(value_local);\n}\npub fn instr_660F7E_reg_jit(ctx: &mut JitContext, r1: u32, r2: u32) {\n    ctx.builder\n        .load_fixed_i32(global_pointers::get_reg_xmm_offset(r2));\n    codegen::gen_set_reg32(ctx, r1);\n}\n\npub fn instr_0F7F_mem_jit(ctx: &mut JitContext, modrm_byte: ModrmByte, r: u32) {\n    codegen::gen_modrm_resolve(ctx, modrm_byte);\n    let address_local = ctx.builder.set_new_local();\n    ctx.builder.const_i32(r as i32);\n    ctx.builder.call_fn1_ret_i64("instr_0F7F");\n    let value_local = ctx.builder.set_new_local_i64();\n    codegen::gen_safe_write64(ctx, &address_local, &value_local);\n    ctx.builder.free_local(address_local);\n    ctx.builder.free_local_i64(value_local);\n}\npub fn instr_0F7F_reg_jit(ctx: &mut JitContext, r1: u32, r2: u32) {\n    ctx.builder.const_i32(r1 as i32);\n    ctx.builder.const_i32(r2 as i32);\n    ctx.builder.call_fn2("instr_0F7F_reg")\n}\n\npub fn instr_F30F7E_mem_jit(ctx: &mut JitContext, modrm_byte: ModrmByte, r: u32) {\n    ctx.builder\n        .const_i32(global_pointers::get_reg_xmm_offset(r) as i32);\n    codegen::gen_modrm_resolve_safe_read64(ctx, modrm_byte);\n    ctx.builder.store_aligned_i64(0);\n\n    ctx.builder\n        .const_i32(global_pointers::get_reg_xmm_offset(r) as i32 + 8);\n    ctx.builder.const_i64(0);\n    ctx.builder.store_aligned_i64(0);\n}\npub fn instr_F30F7E_reg_jit(ctx: &mut JitContext, r1: u32, r2: u32) {\n    ctx.builder.const_i32(r1 as i32);\n    ctx.builder.const_i32(r2 as i32);\n    ctx.builder.call_fn2("instr_F30F7E_reg");\n}\n\npub fn instr_660F7F_mem_jit(ctx: &mut JitContext, modrm_byte: ModrmByte, r: u32) {\n    instr_0F29_mem_jit(ctx, modrm_byte, r);\n}\npub fn instr_660F7F_reg_jit(ctx: &mut JitContext, r1: u32, r2: u32) { sse_mov_xmm_xmm(ctx, r2, r1) }\npub fn instr_F30F7F_mem_jit(ctx: &mut JitContext, modrm_byte: ModrmByte, r: u32) {\n    instr_0F29_mem_jit(ctx, modrm_byte, r);\n}\npub fn instr_F30F7F_reg_jit(ctx: &mut JitContext, r1: u32, r2: u32) { sse_mov_xmm_xmm(ctx, r2, r1) }\n\npub fn instr16_0FA0_jit(ctx: &mut JitContext) {\n    codegen::gen_get_sreg(ctx, regs::FS);\n    let sreg = ctx.builder.set_new_local();\n    codegen::gen_push16(ctx, &sreg);\n    ctx.builder.free_local(sreg);\n}\npub fn instr32_0FA0_jit(ctx: &mut JitContext) {\n    codegen::gen_get_sreg(ctx, regs::FS);\n    let sreg = ctx.builder.set_new_local();\n    codegen::gen_push32(ctx, &sreg);\n    ctx.builder.free_local(sreg);\n}\npub fn instr16_0FA8_jit(ctx: &mut JitContext) {\n    codegen::gen_get_sreg(ctx, regs::GS);\n    let sreg = ctx.builder.set_new_local();\n    codegen::gen_push16(ctx, &sreg);\n    ctx.builder.free_local(sreg);\n}\npub fn instr32_0FA8_jit(ctx: &mut JitContext) {\n    codegen::gen_get_sreg(ctx, regs::GS);\n    let sreg = ctx.builder.set_new_local();\n    codegen::gen_push32(ctx, &sreg);\n    ctx.builder.free_local(sreg);\n}\n\npub fn instr16_0FA3_reg_jit(ctx: &mut JitContext, r1: u32, r2: u32) {\n    gen_bt(\n        &mut ctx.builder,\n        &ctx.register_locals[r1 as usize],\n        &LocalOrImmediate::WasmLocal(&ctx.register_locals[r2 as usize]),\n        15,\n    )\n}\npub fn instr16_0FA3_mem_jit(ctx: &mut JitContext, modrm_byte: ModrmByte, r: u32) {\n    codegen::gen_modrm_resolve(ctx, modrm_byte);\n    codegen::gen_get_reg16(ctx, r);\n    codegen::sign_extend_i16(ctx.builder);\n    ctx.builder.const_i32(3);\n    ctx.builder.shr_s_i32();\n    ctx.builder.add_i32();\n    let address_local = ctx.builder.set_new_local();\n    codegen::gen_safe_read8(ctx, &address_local);\n    ctx.builder.free_local(address_local);\n    let value = ctx.builder.set_new_local();\n    gen_bt(\n        &mut ctx.builder,\n        &value,\n        &LocalOrImmediate::WasmLocal(&ctx.register_locals[r as usize]),\n        7,\n    );\n    ctx.builder.free_local(value);\n}\npub fn instr32_0FA3_reg_jit(ctx: &mut JitContext, r1: u32, r2: u32) {\n    gen_bt(\n        &mut ctx.builder,\n        &ctx.register_locals[r1 as usize],\n        &LocalOrImmediate::WasmLocal(&ctx.register_locals[r2 as usize]),\n        31,\n    )\n}\npub fn instr32_0FA3_mem_jit(ctx: &mut JitContext, modrm_byte: ModrmByte, r: u32) {\n    codegen::gen_modrm_resolve(ctx, modrm_byte);\n    codegen::gen_get_reg32(ctx, r);\n    ctx.builder.const_i32(3);\n    ctx.builder.shr_s_i32();\n    ctx.builder.add_i32();\n    let address_local = ctx.builder.set_new_local();\n    codegen::gen_safe_read8(ctx, &address_local);\n    ctx.builder.free_local(address_local);\n    let value = ctx.builder.set_new_local();\n    gen_bt(\n        &mut ctx.builder,\n        &value,\n        &LocalOrImmediate::WasmLocal(&ctx.register_locals[r as usize]),\n        7,\n    );\n    ctx.builder.free_local(value);\n}\n\npub fn instr16_0FAB_reg_jit(ctx: &mut JitContext, r1: u32, r2: u32) {\n    gen_bts(\n        &mut ctx.builder,\n        &ctx.register_locals[r1 as usize],\n        &LocalOrImmediate::WasmLocal(&ctx.register_locals[r2 as usize]),\n        15,\n    )\n}\npub fn instr16_0FAB_mem_jit(ctx: &mut JitContext, modrm_byte: ModrmByte, r: u32) {\n    gen_bit_rmw(\n        ctx,\n        modrm_byte,\n        &gen_bts,\n        &LocalOrImmediate::WasmLocal(&ctx.reg(r)),\n        16,\n    );\n}\npub fn instr32_0FAB_reg_jit(ctx: &mut JitContext, r1: u32, r2: u32) {\n    gen_bts(\n        &mut ctx.builder,\n        &ctx.register_locals[r1 as usize],\n        &LocalOrImmediate::WasmLocal(&ctx.register_locals[r2 as usize]),\n        31,\n    )\n}\npub fn instr32_0FAB_mem_jit(ctx: &mut JitContext, modrm_byte: ModrmByte, r: u32) {\n    gen_bit_rmw(\n        ctx,\n        modrm_byte,\n        &gen_bts,\n        &LocalOrImmediate::WasmLocal(&ctx.reg(r)),\n        32,\n    );\n}\n\npub fn instr16_0FB3_reg_jit(ctx: &mut JitContext, r1: u32, r2: u32) {\n    gen_btr(\n        &mut ctx.builder,\n        &ctx.register_locals[r1 as usize],\n        &LocalOrImmediate::WasmLocal(&ctx.register_locals[r2 as usize]),\n        15,\n    )\n}\npub fn instr16_0FB3_mem_jit(ctx: &mut JitContext, modrm_byte: ModrmByte, r: u32) {\n    gen_bit_rmw(\n        ctx,\n        modrm_byte,\n        &gen_btr,\n        &LocalOrImmediate::WasmLocal(&ctx.reg(r)),\n        16,\n    );\n}\npub fn instr32_0FB3_reg_jit(ctx: &mut JitContext, r1: u32, r2: u32) {\n    gen_btr(\n        &mut ctx.builder,\n        &ctx.register_locals[r1 as usize],\n        &LocalOrImmediate::WasmLocal(&ctx.register_locals[r2 as usize]),\n        31,\n    )\n}\npub fn instr32_0FB3_mem_jit(ctx: &mut JitContext, modrm_byte: ModrmByte, r: u32) {\n    gen_bit_rmw(\n        ctx,\n        modrm_byte,\n        &gen_btr,\n        &LocalOrImmediate::WasmLocal(&ctx.reg(r)),\n        32,\n    );\n}\n\npub fn instr16_0FBB_reg_jit(ctx: &mut JitContext, r1: u32, r2: u32) {\n    gen_btc(\n        &mut ctx.builder,\n        &ctx.register_locals[r1 as usize],\n        &LocalOrImmediate::WasmLocal(&ctx.register_locals[r2 as usize]),\n        15,\n    )\n}\npub fn instr16_0FBB_mem_jit(ctx: &mut JitContext, modrm_byte: ModrmByte, r: u32) {\n    gen_bit_rmw(\n        ctx,\n        modrm_byte,\n        &gen_btc,\n        &LocalOrImmediate::WasmLocal(&ctx.reg(r)),\n        16,\n    );\n}\npub fn instr32_0FBB_reg_jit(ctx: &mut JitContext, r1: u32, r2: u32) {\n    gen_btc(\n        &mut ctx.builder,\n        &ctx.register_locals[r1 as usize],\n        &LocalOrImmediate::WasmLocal(&ctx.register_locals[r2 as usize]),\n        31,\n    )\n}\npub fn instr32_0FBB_mem_jit(ctx: &mut JitContext, modrm_byte: ModrmByte, r: u32) {\n    gen_bit_rmw(\n        ctx,\n        modrm_byte,\n        &gen_btc,\n        &LocalOrImmediate::WasmLocal(&ctx.reg(r)),\n        32,\n    );\n}\n\npub fn instr16_0FBA_4_reg_jit(ctx: &mut JitContext, r: u32, imm8: u32) {\n    gen_bt(\n        &mut ctx.builder,\n        &ctx.register_locals[r as usize],\n        &LocalOrImmediate::Immediate(imm8 as i32),\n        15,\n    )\n}\npub fn instr16_0FBA_4_mem_jit(ctx: &mut JitContext, modrm_byte: ModrmByte, imm8: u32) {\n    codegen::gen_modrm_resolve(ctx, modrm_byte);\n    let offset = (imm8 as i32 & 15) >> 3;\n    if offset != 0 {\n        ctx.builder.const_i32(offset);\n        ctx.builder.add_i32();\n    }\n    let address_local = ctx.builder.set_new_local();\n    codegen::gen_safe_read8(ctx, &address_local);\n    ctx.builder.free_local(address_local);\n    let value = ctx.builder.set_new_local();\n    gen_bt(\n        &mut ctx.builder,\n        &value,\n        &LocalOrImmediate::Immediate(imm8 as i32),\n        7,\n    );\n    ctx.builder.free_local(value);\n}\npub fn instr32_0FBA_4_reg_jit(ctx: &mut JitContext, r: u32, imm8: u32) {\n    gen_bt(\n        &mut ctx.builder,\n        &ctx.register_locals[r as usize],\n        &LocalOrImmediate::Immediate(imm8 as i32),\n        31,\n    )\n}\npub fn instr32_0FBA_4_mem_jit(ctx: &mut JitContext, modrm_byte: ModrmByte, imm8: u32) {\n    codegen::gen_modrm_resolve(ctx, modrm_byte);\n    let offset = (imm8 as i32 & 31) >> 3;\n    if offset != 0 {\n        ctx.builder.const_i32(offset);\n        ctx.builder.add_i32();\n    }\n    let address_local = ctx.builder.set_new_local();\n    codegen::gen_safe_read8(ctx, &address_local);\n    ctx.builder.free_local(address_local);\n    let value = ctx.builder.set_new_local();\n    gen_bt(\n        &mut ctx.builder,\n        &value,\n        &LocalOrImmediate::Immediate(imm8 as i32),\n        7,\n    );\n    ctx.builder.free_local(value);\n}\n\npub fn instr16_0FBA_5_reg_jit(ctx: &mut JitContext, r: u32, imm8: u32) {\n    gen_bts(\n        &mut ctx.builder,\n        &ctx.register_locals[r as usize],\n        &LocalOrImmediate::Immediate(imm8 as i32),\n        15,\n    )\n}\npub fn instr16_0FBA_5_mem_jit(ctx: &mut JitContext, modrm_byte: ModrmByte, imm8: u32) {\n    gen_bit_rmw(\n        ctx,\n        modrm_byte,\n        &gen_bts,\n        &LocalOrImmediate::Immediate(imm8 as i32),\n        16,\n    );\n}\npub fn instr32_0FBA_5_reg_jit(ctx: &mut JitContext, r: u32, imm8: u32) {\n    gen_bts(\n        &mut ctx.builder,\n        &ctx.register_locals[r as usize],\n        &LocalOrImmediate::Immediate(imm8 as i32),\n        31,\n    )\n}\npub fn instr32_0FBA_5_mem_jit(ctx: &mut JitContext, modrm_byte: ModrmByte, imm8: u32) {\n    gen_bit_rmw(\n        ctx,\n        modrm_byte,\n        &gen_bts,\n        &LocalOrImmediate::Immediate(imm8 as i32),\n        32,\n    );\n}\n\npub fn instr16_0FBA_6_reg_jit(ctx: &mut JitContext, r: u32, imm8: u32) {\n    gen_btr(\n        &mut ctx.builder,\n        &ctx.register_locals[r as usize],\n        &LocalOrImmediate::Immediate(imm8 as i32),\n        15,\n    )\n}\npub fn instr16_0FBA_6_mem_jit(ctx: &mut JitContext, modrm_byte: ModrmByte, imm8: u32) {\n    gen_bit_rmw(\n        ctx,\n        modrm_byte,\n        &gen_btr,\n        &LocalOrImmediate::Immediate(imm8 as i32),\n        16,\n    );\n}\npub fn instr32_0FBA_6_reg_jit(ctx: &mut JitContext, r: u32, imm8: u32) {\n    gen_btr(\n        &mut ctx.builder,\n        &ctx.register_locals[r as usize],\n        &LocalOrImmediate::Immediate(imm8 as i32),\n        31,\n    )\n}\npub fn instr32_0FBA_6_mem_jit(ctx: &mut JitContext, modrm_byte: ModrmByte, imm8: u32) {\n    gen_bit_rmw(\n        ctx,\n        modrm_byte,\n        &gen_btr,\n        &LocalOrImmediate::Immediate(imm8 as i32),\n        32,\n    );\n}\n\npub fn instr16_0FBA_7_reg_jit(ctx: &mut JitContext, r: u32, imm8: u32) {\n    gen_btc(\n        &mut ctx.builder,\n        &ctx.register_locals[r as usize],\n        &LocalOrImmediate::Immediate(imm8 as i32),\n        15,\n    )\n}\npub fn instr16_0FBA_7_mem_jit(ctx: &mut JitContext, modrm_byte: ModrmByte, imm8: u32) {\n    gen_bit_rmw(\n        ctx,\n        modrm_byte,\n        &gen_btc,\n        &LocalOrImmediate::Immediate(imm8 as i32),\n        16,\n    );\n}\npub fn instr32_0FBA_7_reg_jit(ctx: &mut JitContext, r: u32, imm8: u32) {\n    gen_btc(\n        &mut ctx.builder,\n        &ctx.register_locals[r as usize],\n        &LocalOrImmediate::Immediate(imm8 as i32),\n        31,\n    )\n}\npub fn instr32_0FBA_7_mem_jit(ctx: &mut JitContext, modrm_byte: ModrmByte, imm8: u32) {\n    gen_bit_rmw(\n        ctx,\n        modrm_byte,\n        &gen_btc,\n        &LocalOrImmediate::Immediate(imm8 as i32),\n        32,\n    );\n}\n\npub fn instr_0FAE_5_mem_jit(ctx: &mut JitContext, _modrm_byte: ModrmByte) {\n    dbg_log!("Generating #ud for unimplemented instruction: instr_0FAE_5_mem_jit");\n    codegen::gen_trigger_ud(ctx);\n}\npub fn instr_0FAE_5_reg_jit(_ctx: &mut JitContext, _r: u32) {\n    // For this instruction, the processor ignores the r/m field of the ModR/M byte.\n}\n\npub fn instr_0FD1_mem_jit(ctx: &mut JitContext, modrm_byte: ModrmByte, r: u32) {\n    mmx_read64_mm_mem(ctx, "instr_0FD1", modrm_byte, r);\n}\npub fn instr_0FD1_reg_jit(ctx: &mut JitContext, r1: u32, r2: u32) {\n    mmx_read64_mm_mm(ctx, "instr_0FD1", r1, r2);\n}\npub fn instr_0FD2_mem_jit(ctx: &mut JitContext, modrm_byte: ModrmByte, r: u32) {\n    mmx_read64_mm_mem(ctx, "instr_0FD2", modrm_byte, r);\n}\npub fn instr_0FD2_reg_jit(ctx: &mut JitContext, r1: u32, r2: u32) {\n    mmx_read64_mm_mm(ctx, "instr_0FD2", r1, r2);\n}\npub fn instr_0FD3_mem_jit(ctx: &mut JitContext, modrm_byte: ModrmByte, r: u32) {\n    mmx_read64_mm_mem(ctx, "instr_0FD3", modrm_byte, r);\n}\npub fn instr_0FD3_reg_jit(ctx: &mut JitContext, r1: u32, r2: u32) {\n    mmx_read64_mm_mm(ctx, "instr_0FD3", r1, r2);\n}\npub fn instr_0FD4_mem_jit(ctx: &mut JitContext, modrm_byte: ModrmByte, r: u32) {\n    mmx_read64_mm_mem(ctx, "instr_0FD4", modrm_byte, r);\n}\npub fn instr_0FD4_reg_jit(ctx: &mut JitContext, r1: u32, r2: u32) {\n    mmx_read64_mm_mm(ctx, "instr_0FD4", r1, r2);\n}\npub fn instr_0FD5_mem_jit(ctx: &mut JitContext, modrm_byte: ModrmByte, r: u32) {\n    mmx_read64_mm_mem(ctx, "instr_0FD5", modrm_byte, r);\n}\npub fn instr_0FD5_reg_jit(ctx: &mut JitContext, r1: u32, r2: u32) {\n    mmx_read64_mm_mm(ctx, "instr_0FD5", r1, r2);\n}\n\npub fn instr_0FD7_mem_jit(ctx: &mut JitContext, _modrm_byte: ModrmByte, _r: u32) {\n    codegen::gen_trigger_ud(ctx)\n}\npub fn instr_0FD7_reg_jit(ctx: &mut JitContext, r1: u32, r2: u32) {\n    ctx.builder.const_i32(r1 as i32);\n    ctx.builder.call_fn1_ret("instr_0FD7");\n    codegen::gen_set_reg32(ctx, r2);\n}\n\npub fn instr_0FD8_mem_jit(ctx: &mut JitContext, modrm_byte: ModrmByte, r: u32) {\n    mmx_read64_mm_mem(ctx, "instr_0FD8", modrm_byte, r);\n}\npub fn instr_0FD8_reg_jit(ctx: &mut JitContext, r1: u32, r2: u32) {\n    mmx_read64_mm_mm(ctx, "instr_0FD8", r1, r2);\n}\npub fn instr_0FD9_mem_jit(ctx: &mut JitContext, modrm_byte: ModrmByte, r: u32) {\n    mmx_read64_mm_mem(ctx, "instr_0FD9", modrm_byte, r);\n}\npub fn instr_0FD9_reg_jit(ctx: &mut JitContext, r1: u32, r2: u32) {\n    mmx_read64_mm_mm(ctx, "instr_0FD9", r1, r2);\n}\npub fn instr_0FDA_mem_jit(ctx: &mut JitContext, modrm_byte: ModrmByte, r: u32) {\n    mmx_read64_mm_mem(ctx, "instr_0FDA", modrm_byte, r);\n}\npub fn instr_0FDA_reg_jit(ctx: &mut JitContext, r1: u32, r2: u32) {\n    mmx_read64_mm_mm(ctx, "instr_0FDA", r1, r2);\n}\npub fn instr_0FDB_mem_jit(ctx: &mut JitContext, modrm_byte: ModrmByte, r: u32) {\n    mmx_read64_mm_mem(ctx, "instr_0FDB", modrm_byte, r);\n}\npub fn instr_0FDB_reg_jit(ctx: &mut JitContext, r1: u32, r2: u32) {\n    mmx_read64_mm_mm(ctx, "instr_0FDB", r1, r2);\n}\npub fn instr_0FDC_mem_jit(ctx: &mut JitContext, modrm_byte: ModrmByte, r: u32) {\n    mmx_read64_mm_mem(ctx, "instr_0FDC", modrm_byte, r);\n}\npub fn instr_0FDC_reg_jit(ctx: &mut JitContext, r1: u32, r2: u32) {\n    mmx_read64_mm_mm(ctx, "instr_0FDC", r1, r2);\n}\npub fn instr_0FDD_mem_jit(ctx: &mut JitContext, modrm_byte: ModrmByte, r: u32) {\n    mmx_read64_mm_mem(ctx, "instr_0FDD", modrm_byte, r);\n}\npub fn instr_0FDD_reg_jit(ctx: &mut JitContext, r1: u32, r2: u32) {\n    mmx_read64_mm_mm(ctx, "instr_0FDD", r1, r2);\n}\npub fn instr_0FDE_mem_jit(ctx: &mut JitContext, modrm_byte: ModrmByte, r: u32) {\n    mmx_read64_mm_mem(ctx, "instr_0FDE", modrm_byte, r);\n}\npub fn instr_0FDE_reg_jit(ctx: &mut JitContext, r1: u32, r2: u32) {\n    mmx_read64_mm_mm(ctx, "instr_0FDE", r1, r2);\n}\npub fn instr_0FDF_mem_jit(ctx: &mut JitContext, modrm_byte: ModrmByte, r: u32) {\n    mmx_read64_mm_mem(ctx, "instr_0FDF", modrm_byte, r);\n}\npub fn instr_0FDF_reg_jit(ctx: &mut JitContext, r1: u32, r2: u32) {\n    mmx_read64_mm_mm(ctx, "instr_0FDF", r1, r2);\n}\n\npub fn instr_660FD1_mem_jit(ctx: &mut JitContext, modrm_byte: ModrmByte, r: u32) {\n    sse_read128_xmm_mem(ctx, "instr_660FD1", modrm_byte, r);\n}\npub fn instr_660FD1_reg_jit(ctx: &mut JitContext, r1: u32, r2: u32) {\n    sse_read128_xmm_xmm(ctx, "instr_660FD1", r1, r2);\n}\npub fn instr_660FD2_mem_jit(ctx: &mut JitContext, modrm_byte: ModrmByte, r: u32) {\n    sse_read128_xmm_mem(ctx, "instr_660FD2", modrm_byte, r);\n}\npub fn instr_660FD2_reg_jit(ctx: &mut JitContext, r1: u32, r2: u32) {\n    sse_read128_xmm_xmm(ctx, "instr_660FD2", r1, r2);\n}\npub fn instr_660FD3_mem_jit(ctx: &mut JitContext, modrm_byte: ModrmByte, r: u32) {\n    sse_read128_xmm_mem(ctx, "instr_660FD3", modrm_byte, r);\n}\npub fn instr_660FD3_reg_jit(ctx: &mut JitContext, r1: u32, r2: u32) {\n    sse_read128_xmm_xmm(ctx, "instr_660FD3", r1, r2);\n}\npub fn instr_660FD4_mem_jit(ctx: &mut JitContext, modrm_byte: ModrmByte, r: u32) {\n    sse_read128_xmm_mem(ctx, "instr_660FD4", modrm_byte, r);\n}\npub fn instr_660FD4_reg_jit(ctx: &mut JitContext, r1: u32, r2: u32) {\n    sse_read128_xmm_xmm(ctx, "instr_660FD4", r1, r2);\n}\npub fn instr_660FD5_mem_jit(ctx: &mut JitContext, modrm_byte: ModrmByte, r: u32) {\n    sse_read128_xmm_mem(ctx, "instr_660FD5", modrm_byte, r);\n}\npub fn instr_660FD5_reg_jit(ctx: &mut JitContext, r1: u32, r2: u32) {\n    sse_read128_xmm_xmm(ctx, "instr_660FD5", r1, r2);\n}\n\npub fn instr_660FD6_mem_jit(ctx: &mut JitContext, modrm_byte: ModrmByte, r: u32) {\n    codegen::gen_modrm_resolve(ctx, modrm_byte);\n    let address_local = ctx.builder.set_new_local();\n\n    ctx.builder\n        .const_i32(global_pointers::get_reg_xmm_offset(r) as i32);\n    ctx.builder.load_aligned_i64(0);\n    let value_local = ctx.builder.set_new_local_i64();\n\n    codegen::gen_safe_write64(ctx, &address_local, &value_local);\n    ctx.builder.free_local(address_local);\n    ctx.builder.free_local_i64(value_local);\n}\npub fn instr_660FD6_reg_jit(ctx: &mut JitContext, r1: u32, r2: u32) {\n    ctx.builder.const_i32(r1 as i32);\n    ctx.builder.const_i32(r2 as i32);\n    ctx.builder.call_fn2("instr_660FD6_reg");\n}\n\npub fn instr_660FD7_mem_jit(ctx: &mut JitContext, _modrm_byte: ModrmByte, _r: u32) {\n    codegen::gen_trigger_ud(ctx)\n}\npub fn instr_660FD7_reg_jit(ctx: &mut JitContext, r1: u32, r2: u32) {\n    ctx.builder.const_i32(r1 as i32);\n    ctx.builder.call_fn1_ret("instr_660FD7");\n    codegen::gen_set_reg32(ctx, r2);\n}\n\npub fn instr_660FD8_mem_jit(ctx: &mut JitContext, modrm_byte: ModrmByte, r: u32) {\n    sse_read128_xmm_mem(ctx, "instr_660FD8", modrm_byte, r);\n}\npub fn instr_660FD8_reg_jit(ctx: &mut JitContext, r1: u32, r2: u32) {\n    sse_read128_xmm_xmm(ctx, "instr_660FD8", r1, r2);\n}\npub fn instr_660FD9_mem_jit(ctx: &mut JitContext, modrm_byte: ModrmByte, r: u32) {\n    sse_read128_xmm_mem(ctx, "instr_660FD9", modrm_byte, r);\n}\npub fn instr_660FD9_reg_jit(ctx: &mut JitContext, r1: u32, r2: u32) {\n    sse_read128_xmm_xmm(ctx, "instr_660FD9", r1, r2);\n}\npub fn instr_660FDA_mem_jit(ctx: &mut JitContext, modrm_byte: ModrmByte, r: u32) {\n    sse_read128_xmm_mem(ctx, "instr_660FDA", modrm_byte, r);\n}\npub fn instr_660FDA_reg_jit(ctx: &mut JitContext, r1: u32, r2: u32) {\n    sse_read128_xmm_xmm(ctx, "instr_660FDA", r1, r2);\n}\npub fn instr_660FDB_mem_jit(ctx: &mut JitContext, modrm_byte: ModrmByte, r: u32) {\n    sse_read128_xmm_mem(ctx, "instr_660FDB", modrm_byte, r);\n}\npub fn instr_660FDB_reg_jit(ctx: &mut JitContext, r1: u32, r2: u32) {\n    sse_read128_xmm_xmm(ctx, "instr_660FDB", r1, r2);\n}\npub fn instr_660FDC_mem_jit(ctx: &mut JitContext, modrm_byte: ModrmByte, r: u32) {\n    sse_read128_xmm_mem(ctx, "instr_660FDC", modrm_byte, r);\n}\npub fn instr_660FDC_reg_jit(ctx: &mut JitContext, r1: u32, r2: u32) {\n    sse_read128_xmm_xmm(ctx, "instr_660FDC", r1, r2);\n}\npub fn instr_660FDD_mem_jit(ctx: &mut JitContext, modrm_byte: ModrmByte, r: u32) {\n    sse_read128_xmm_mem(ctx, "instr_660FDD", modrm_byte, r);\n}\npub fn instr_660FDD_reg_jit(ctx: &mut JitContext, r1: u32, r2: u32) {\n    sse_read128_xmm_xmm(ctx, "instr_660FDD", r1, r2);\n}\npub fn instr_660FDE_mem_jit(ctx: &mut JitContext, modrm_byte: ModrmByte, r: u32) {\n    sse_read128_xmm_mem(ctx, "instr_660FDE", modrm_byte, r);\n}\npub fn instr_660FDE_reg_jit(ctx: &mut JitContext, r1: u32, r2: u32) {\n    sse_read128_xmm_xmm(ctx, "instr_660FDE", r1, r2);\n}\npub fn instr_660FDF_mem_jit(ctx: &mut JitContext, modrm_byte: ModrmByte, r: u32) {\n    sse_read128_xmm_mem(ctx, "instr_660FDF", modrm_byte, r);\n}\npub fn instr_660FDF_reg_jit(ctx: &mut JitContext, r1: u32, r2: u32) {\n    sse_read128_xmm_xmm(ctx, "instr_660FDF", r1, r2);\n}\n\npub fn instr_0FE0_mem_jit(ctx: &mut JitContext, modrm_byte: ModrmByte, r: u32) {\n    mmx_read64_mm_mem(ctx, "instr_0FE0", modrm_byte, r);\n}\npub fn instr_0FE0_reg_jit(ctx: &mut JitContext, r1: u32, r2: u32) {\n    mmx_read64_mm_mm(ctx, "instr_0FE0", r1, r2);\n}\npub fn instr_0FE1_mem_jit(ctx: &mut JitContext, modrm_byte: ModrmByte, r: u32) {\n    mmx_read64_mm_mem(ctx, "instr_0FE1", modrm_byte, r);\n}\npub fn instr_0FE1_reg_jit(ctx: &mut JitContext, r1: u32, r2: u32) {\n    mmx_read64_mm_mm(ctx, "instr_0FE1", r1, r2);\n}\npub fn instr_0FE2_mem_jit(ctx: &mut JitContext, modrm_byte: ModrmByte, r: u32) {\n    mmx_read64_mm_mem(ctx, "instr_0FE2", modrm_byte, r);\n}\npub fn instr_0FE2_reg_jit(ctx: &mut JitContext, r1: u32, r2: u32) {\n    mmx_read64_mm_mm(ctx, "instr_0FE2", r1, r2);\n}\npub fn instr_0FE3_mem_jit(ctx: &mut JitContext, modrm_byte: ModrmByte, r: u32) {\n    mmx_read64_mm_mem(ctx, "instr_0FE3", modrm_byte, r);\n}\npub fn instr_0FE3_reg_jit(ctx: &mut JitContext, r1: u32, r2: u32) {\n    mmx_read64_mm_mm(ctx, "instr_0FE3", r1, r2);\n}\npub fn instr_0FE4_mem_jit(ctx: &mut JitContext, modrm_byte: ModrmByte, r: u32) {\n    mmx_read64_mm_mem(ctx, "instr_0FE4", modrm_byte, r);\n}\npub fn instr_0FE4_reg_jit(ctx: &mut JitContext, r1: u32, r2: u32) {\n    mmx_read64_mm_mm(ctx, "instr_0FE4", r1, r2);\n}\npub fn instr_0FE5_mem_jit(ctx: &mut JitContext, modrm_byte: ModrmByte, r: u32) {\n    mmx_read64_mm_mem(ctx, "instr_0FE5", modrm_byte, r);\n}\npub fn instr_0FE5_reg_jit(ctx: &mut JitContext, r1: u32, r2: u32) {\n    mmx_read64_mm_mm(ctx, "instr_0FE5", r1, r2);\n}\n\npub fn instr_0FE8_mem_jit(ctx: &mut JitContext, modrm_byte: ModrmByte, r: u32) {\n    mmx_read64_mm_mem(ctx, "instr_0FE8", modrm_byte, r);\n}\npub fn instr_0FE8_reg_jit(ctx: &mut JitContext, r1: u32, r2: u32) {\n    mmx_read64_mm_mm(ctx, "instr_0FE8", r1, r2);\n}\npub fn instr_0FE9_mem_jit(ctx: &mut JitContext, modrm_byte: ModrmByte, r: u32) {\n    mmx_read64_mm_mem(ctx, "instr_0FE9", modrm_byte, r);\n}\npub fn instr_0FE9_reg_jit(ctx: &mut JitContext, r1: u32, r2: u32) {\n    mmx_read64_mm_mm(ctx, "instr_0FE9", r1, r2);\n}\npub fn instr_0FEA_mem_jit(ctx: &mut JitContext, modrm_byte: ModrmByte, r: u32) {\n    mmx_read64_mm_mem(ctx, "instr_0FEA", modrm_byte, r);\n}\npub fn instr_0FEA_reg_jit(ctx: &mut JitContext, r1: u32, r2: u32) {\n    mmx_read64_mm_mm(ctx, "instr_0FEA", r1, r2);\n}\npub fn instr_0FEB_mem_jit(ctx: &mut JitContext, modrm_byte: ModrmByte, r: u32) {\n    mmx_read64_mm_mem(ctx, "instr_0FEB", modrm_byte, r);\n}\npub fn instr_0FEB_reg_jit(ctx: &mut JitContext, r1: u32, r2: u32) {\n    mmx_read64_mm_mm(ctx, "instr_0FEB", r1, r2);\n}\npub fn instr_0FEC_mem_jit(ctx: &mut JitContext, modrm_byte: ModrmByte, r: u32) {\n    mmx_read64_mm_mem(ctx, "instr_0FEC", modrm_byte, r);\n}\npub fn instr_0FEC_reg_jit(ctx: &mut JitContext, r1: u32, r2: u32) {\n    mmx_read64_mm_mm(ctx, "instr_0FEC", r1, r2);\n}\npub fn instr_0FED_mem_jit(ctx: &mut JitContext, modrm_byte: ModrmByte, r: u32) {\n    mmx_read64_mm_mem(ctx, "instr_0FED", modrm_byte, r);\n}\npub fn instr_0FED_reg_jit(ctx: &mut JitContext, r1: u32, r2: u32) {\n    mmx_read64_mm_mm(ctx, "instr_0FED", r1, r2);\n}\npub fn instr_0FEE_mem_jit(ctx: &mut JitContext, modrm_byte: ModrmByte, r: u32) {\n    mmx_read64_mm_mem(ctx, "instr_0FEE", modrm_byte, r);\n}\npub fn instr_0FEE_reg_jit(ctx: &mut JitContext, r1: u32, r2: u32) {\n    mmx_read64_mm_mm(ctx, "instr_0FEE", r1, r2);\n}\npub fn instr_0FEF_mem_jit(ctx: &mut JitContext, modrm_byte: ModrmByte, r: u32) {\n    mmx_read64_mm_mem(ctx, "instr_0FEF", modrm_byte, r);\n}\npub fn instr_0FEF_reg_jit(ctx: &mut JitContext, r1: u32, r2: u32) {\n    mmx_read64_mm_mm(ctx, "instr_0FEF", r1, r2);\n}\n\npub fn instr_660FE0_mem_jit(ctx: &mut JitContext, modrm_byte: ModrmByte, r: u32) {\n    sse_read128_xmm_mem(ctx, "instr_660FE0", modrm_byte, r);\n}\npub fn instr_660FE0_reg_jit(ctx: &mut JitContext, r1: u32, r2: u32) {\n    sse_read128_xmm_xmm(ctx, "instr_660FE0", r1, r2);\n}\npub fn instr_660FE1_mem_jit(ctx: &mut JitContext, modrm_byte: ModrmByte, r: u32) {\n    sse_read128_xmm_mem(ctx, "instr_660FE1", modrm_byte, r);\n}\npub fn instr_660FE1_reg_jit(ctx: &mut JitContext, r1: u32, r2: u32) {\n    sse_read128_xmm_xmm(ctx, "instr_660FE1", r1, r2);\n}\npub fn instr_660FE2_mem_jit(ctx: &mut JitContext, modrm_byte: ModrmByte, r: u32) {\n    sse_read128_xmm_mem(ctx, "instr_660FE2", modrm_byte, r);\n}\npub fn instr_660FE2_reg_jit(ctx: &mut JitContext, r1: u32, r2: u32) {\n    sse_read128_xmm_xmm(ctx, "instr_660FE2", r1, r2);\n}\npub fn instr_660FE3_mem_jit(ctx: &mut JitContext, modrm_byte: ModrmByte, r: u32) {\n    sse_read128_xmm_mem(ctx, "instr_660FE3", modrm_byte, r);\n}\npub fn instr_660FE3_reg_jit(ctx: &mut JitContext, r1: u32, r2: u32) {\n    sse_read128_xmm_xmm(ctx, "instr_660FE3", r1, r2);\n}\npub fn instr_660FE4_mem_jit(ctx: &mut JitContext, modrm_byte: ModrmByte, r: u32) {\n    sse_read128_xmm_mem(ctx, "instr_660FE4", modrm_byte, r);\n}\npub fn instr_660FE4_reg_jit(ctx: &mut JitContext, r1: u32, r2: u32) {\n    sse_read128_xmm_xmm(ctx, "instr_660FE4", r1, r2);\n}\npub fn instr_660FE5_mem_jit(ctx: &mut JitContext, modrm_byte: ModrmByte, r: u32) {\n    sse_read128_xmm_mem(ctx, "instr_660FE5", modrm_byte, r);\n}\npub fn instr_660FE5_reg_jit(ctx: &mut JitContext, r1: u32, r2: u32) {\n    sse_read128_xmm_xmm(ctx, "instr_660FE5", r1, r2);\n}\n\npub fn instr_660FE6_mem_jit(ctx: &mut JitContext, modrm_byte: ModrmByte, r: u32) {\n    sse_read128_xmm_mem(ctx, "instr_660FE6", modrm_byte, r);\n}\npub fn instr_660FE6_reg_jit(ctx: &mut JitContext, r1: u32, r2: u32) {\n    sse_read128_xmm_xmm(ctx, "instr_660FE6", r1, r2);\n}\npub fn instr_F20FE6_mem_jit(ctx: &mut JitContext, modrm_byte: ModrmByte, r: u32) {\n    sse_read128_xmm_mem(ctx, "instr_F20FE6", modrm_byte, r);\n}\npub fn instr_F20FE6_reg_jit(ctx: &mut JitContext, r1: u32, r2: u32) {\n    sse_read128_xmm_xmm(ctx, "instr_F20FE6", r1, r2);\n}\npub fn instr_F30FE6_mem_jit(ctx: &mut JitContext, modrm_byte: ModrmByte, r: u32) {\n    sse_read64_xmm_mem(ctx, "instr_F30FE6", modrm_byte, r);\n}\npub fn instr_F30FE6_reg_jit(ctx: &mut JitContext, r1: u32, r2: u32) {\n    sse_read64_xmm_xmm(ctx, "instr_F30FE6", r1, r2);\n}\n\npub fn instr_660FE7_mem_jit(ctx: &mut JitContext, modrm_byte: ModrmByte, r: u32) {\n    instr_0F29_mem_jit(ctx, modrm_byte, r);\n}\npub fn instr_660FE7_reg_jit(ctx: &mut JitContext, _r1: u32, _r2: u32) {\n    codegen::gen_trigger_ud(ctx);\n}\n\npub fn instr_660FE8_mem_jit(ctx: &mut JitContext, modrm_byte: ModrmByte, r: u32) {\n    sse_read128_xmm_mem(ctx, "instr_660FE8", modrm_byte, r);\n}\npub fn instr_660FE8_reg_jit(ctx: &mut JitContext, r1: u32, r2: u32) {\n    sse_read128_xmm_xmm(ctx, "instr_660FE8", r1, r2);\n}\npub fn instr_660FE9_mem_jit(ctx: &mut JitContext, modrm_byte: ModrmByte, r: u32) {\n    sse_read128_xmm_mem(ctx, "instr_660FE9", modrm_byte, r);\n}\npub fn instr_660FE9_reg_jit(ctx: &mut JitContext, r1: u32, r2: u32) {\n    sse_read128_xmm_xmm(ctx, "instr_660FE9", r1, r2);\n}\npub fn instr_660FEA_mem_jit(ctx: &mut JitContext, modrm_byte: ModrmByte, r: u32) {\n    sse_read128_xmm_mem(ctx, "instr_660FEA", modrm_byte, r);\n}\npub fn instr_660FEA_reg_jit(ctx: &mut JitContext, r1: u32, r2: u32) {\n    sse_read128_xmm_xmm(ctx, "instr_660FEA", r1, r2);\n}\npub fn instr_660FEB_mem_jit(ctx: &mut JitContext, modrm_byte: ModrmByte, r: u32) {\n    sse_read128_xmm_mem(ctx, "instr_660FEB", modrm_byte, r);\n}\npub fn instr_660FEB_reg_jit(ctx: &mut JitContext, r1: u32, r2: u32) {\n    sse_read128_xmm_xmm(ctx, "instr_660FEB", r1, r2);\n}\npub fn instr_660FEC_mem_jit(ctx: &mut JitContext, modrm_byte: ModrmByte, r: u32) {\n    sse_read128_xmm_mem(ctx, "instr_660FEC", modrm_byte, r);\n}\npub fn instr_660FEC_reg_jit(ctx: &mut JitContext, r1: u32, r2: u32) {\n    sse_read128_xmm_xmm(ctx, "instr_660FEC", r1, r2);\n}\npub fn instr_660FED_mem_jit(ctx: &mut JitContext, modrm_byte: ModrmByte, r: u32) {\n    sse_read128_xmm_mem(ctx, "instr_660FED", modrm_byte, r);\n}\npub fn instr_660FED_reg_jit(ctx: &mut JitContext, r1: u32, r2: u32) {\n    sse_read128_xmm_xmm(ctx, "instr_660FED", r1, r2);\n}\npub fn instr_660FEE_mem_jit(ctx: &mut JitContext, modrm_byte: ModrmByte, r: u32) {\n    sse_read128_xmm_mem(ctx, "instr_660FEE", modrm_byte, r);\n}\npub fn instr_660FEE_reg_jit(ctx: &mut JitContext, r1: u32, r2: u32) {\n    sse_read128_xmm_xmm(ctx, "instr_660FEE", r1, r2);\n}\npub fn instr_660FEF_mem_jit(ctx: &mut JitContext, modrm_byte: ModrmByte, r: u32) {\n    sse_read128_xmm_mem(ctx, "instr_660FEF", modrm_byte, r);\n}\npub fn instr_660FEF_reg_jit(ctx: &mut JitContext, r1: u32, r2: u32) {\n    sse_read128_xmm_xmm(ctx, "instr_660FEF", r1, r2);\n}\n\npub fn instr_0FF1_mem_jit(ctx: &mut JitContext, modrm_byte: ModrmByte, r: u32) {\n    mmx_read64_mm_mem(ctx, "instr_0FF1", modrm_byte, r);\n}\npub fn instr_0FF1_reg_jit(ctx: &mut JitContext, r1: u32, r2: u32) {\n    mmx_read64_mm_mm(ctx, "instr_0FF1", r1, r2);\n}\npub fn instr_0FF2_mem_jit(ctx: &mut JitContext, modrm_byte: ModrmByte, r: u32) {\n    mmx_read64_mm_mem(ctx, "instr_0FF2", modrm_byte, r);\n}\npub fn instr_0FF2_reg_jit(ctx: &mut JitContext, r1: u32, r2: u32) {\n    mmx_read64_mm_mm(ctx, "instr_0FF2", r1, r2);\n}\npub fn instr_0FF3_mem_jit(ctx: &mut JitContext, modrm_byte: ModrmByte, r: u32) {\n    mmx_read64_mm_mem(ctx, "instr_0FF3", modrm_byte, r);\n}\npub fn instr_0FF3_reg_jit(ctx: &mut JitContext, r1: u32, r2: u32) {\n    mmx_read64_mm_mm(ctx, "instr_0FF3", r1, r2);\n}\npub fn instr_0FF4_mem_jit(ctx: &mut JitContext, modrm_byte: ModrmByte, r: u32) {\n    mmx_read64_mm_mem(ctx, "instr_0FF4", modrm_byte, r);\n}\npub fn instr_0FF4_reg_jit(ctx: &mut JitContext, r1: u32, r2: u32) {\n    mmx_read64_mm_mm(ctx, "instr_0FF4", r1, r2);\n}\npub fn instr_0FF5_mem_jit(ctx: &mut JitContext, modrm_byte: ModrmByte, r: u32) {\n    mmx_read64_mm_mem(ctx, "instr_0FF5", modrm_byte, r);\n}\npub fn instr_0FF5_reg_jit(ctx: &mut JitContext, r1: u32, r2: u32) {\n    mmx_read64_mm_mm(ctx, "instr_0FF5", r1, r2);\n}\npub fn instr_0FF6_mem_jit(ctx: &mut JitContext, modrm_byte: ModrmByte, r: u32) {\n    mmx_read64_mm_mem(ctx, "instr_0FF6", modrm_byte, r);\n}\npub fn instr_0FF6_reg_jit(ctx: &mut JitContext, r1: u32, r2: u32) {\n    mmx_read64_mm_mm(ctx, "instr_0FF6", r1, r2);\n}\n\npub fn instr_0FF7_mem_jit(ctx: &mut JitContext, _modrm_byte: ModrmByte, _r: u32) {\n    codegen::gen_trigger_ud(ctx)\n}\npub fn instr_0FF7_reg_jit(ctx: &mut JitContext, r1: u32, r2: u32) {\n    codegen::gen_set_previous_eip_offset_from_eip_with_low_bits(\n        ctx.builder,\n        ctx.start_of_current_instruction as i32 & 0xFFF,\n    );\n\n    codegen::gen_move_registers_from_locals_to_memory(ctx);\n    ctx.builder.const_i32(r1 as i32);\n    ctx.builder.const_i32(r2 as i32);\n    if ctx.cpu.asize_32() {\n        codegen::gen_get_reg32(ctx, regs::EDI);\n    }\n    else {\n        codegen::gen_get_reg16(ctx, regs::DI);\n    }\n    jit_add_seg_offset(ctx, regs::DS);\n    ctx.builder.call_fn3("maskmovq");\n    codegen::gen_move_registers_from_memory_to_locals(ctx);\n\n    codegen::gen_get_page_fault(ctx.builder);\n    ctx.builder.if_void();\n    codegen::gen_debug_track_jit_exit(ctx.builder, ctx.start_of_current_instruction);\n    ctx.builder.br(ctx.exit_label);\n    ctx.builder.block_end();\n}\n\npub fn instr_0FF8_mem_jit(ctx: &mut JitContext, modrm_byte: ModrmByte, r: u32) {\n    mmx_read64_mm_mem(ctx, "instr_0FF8", modrm_byte, r);\n}\npub fn instr_0FF8_reg_jit(ctx: &mut JitContext, r1: u32, r2: u32) {\n    mmx_read64_mm_mm(ctx, "instr_0FF8", r1, r2);\n}\npub fn instr_0FF9_mem_jit(ctx: &mut JitContext, modrm_byte: ModrmByte, r: u32) {\n    mmx_read64_mm_mem(ctx, "instr_0FF9", modrm_byte, r);\n}\npub fn instr_0FF9_reg_jit(ctx: &mut JitContext, r1: u32, r2: u32) {\n    mmx_read64_mm_mm(ctx, "instr_0FF9", r1, r2);\n}\npub fn instr_0FFA_mem_jit(ctx: &mut JitContext, modrm_byte: ModrmByte, r: u32) {\n    mmx_read64_mm_mem(ctx, "instr_0FFA", modrm_byte, r);\n}\npub fn instr_0FFA_reg_jit(ctx: &mut JitContext, r1: u32, r2: u32) {\n    mmx_read64_mm_mm(ctx, "instr_0FFA", r1, r2);\n}\npub fn instr_0FFB_mem_jit(ctx: &mut JitContext, modrm_byte: ModrmByte, r: u32) {\n    mmx_read64_mm_mem(ctx, "instr_0FFB", modrm_byte, r);\n}\npub fn instr_0FFB_reg_jit(ctx: &mut JitContext, r1: u32, r2: u32) {\n    mmx_read64_mm_mm(ctx, "instr_0FFB", r1, r2);\n}\npub fn instr_0FFC_mem_jit(ctx: &mut JitContext, modrm_byte: ModrmByte, r: u32) {\n    mmx_read64_mm_mem(ctx, "instr_0FFC", modrm_byte, r);\n}\npub fn instr_0FFC_reg_jit(ctx: &mut JitContext, r1: u32, r2: u32) {\n    mmx_read64_mm_mm(ctx, "instr_0FFC", r1, r2);\n}\npub fn instr_0FFD_mem_jit(ctx: &mut JitContext, modrm_byte: ModrmByte, r: u32) {\n    mmx_read64_mm_mem(ctx, "instr_0FFD", modrm_byte, r);\n}\npub fn instr_0FFD_reg_jit(ctx: &mut JitContext, r1: u32, r2: u32) {\n    mmx_read64_mm_mm(ctx, "instr_0FFD", r1, r2);\n}\npub fn instr_0FFE_mem_jit(ctx: &mut JitContext, modrm_byte: ModrmByte, r: u32) {\n    mmx_read64_mm_mem(ctx, "instr_0FFE", modrm_byte, r);\n}\npub fn instr_0FFE_reg_jit(ctx: &mut JitContext, r1: u32, r2: u32) {\n    mmx_read64_mm_mm(ctx, "instr_0FFE", r1, r2);\n}\n\npub fn instr_660FF1_mem_jit(ctx: &mut JitContext, modrm_byte: ModrmByte, r: u32) {\n    sse_read128_xmm_mem(ctx, "instr_660FF1", modrm_byte, r);\n}\npub fn instr_660FF1_reg_jit(ctx: &mut JitContext, r1: u32, r2: u32) {\n    sse_read128_xmm_xmm(ctx, "instr_660FF1", r1, r2);\n}\npub fn instr_660FF2_mem_jit(ctx: &mut JitContext, modrm_byte: ModrmByte, r: u32) {\n    sse_read128_xmm_mem(ctx, "instr_660FF2", modrm_byte, r);\n}\npub fn instr_660FF2_reg_jit(ctx: &mut JitContext, r1: u32, r2: u32) {\n    sse_read128_xmm_xmm(ctx, "instr_660FF2", r1, r2);\n}\npub fn instr_660FF3_mem_jit(ctx: &mut JitContext, modrm_byte: ModrmByte, r: u32) {\n    sse_read128_xmm_mem(ctx, "instr_660FF3", modrm_byte, r);\n}\npub fn instr_660FF3_reg_jit(ctx: &mut JitContext, r1: u32, r2: u32) {\n    sse_read128_xmm_xmm(ctx, "instr_660FF3", r1, r2);\n}\npub fn instr_660FF4_mem_jit(ctx: &mut JitContext, modrm_byte: ModrmByte, r: u32) {\n    sse_read128_xmm_mem(ctx, "instr_660FF4", modrm_byte, r);\n}\npub fn instr_660FF4_reg_jit(ctx: &mut JitContext, r1: u32, r2: u32) {\n    sse_read128_xmm_xmm(ctx, "instr_660FF4", r1, r2);\n}\npub fn instr_660FF5_mem_jit(ctx: &mut JitContext, modrm_byte: ModrmByte, r: u32) {\n    sse_read128_xmm_mem(ctx, "instr_660FF5", modrm_byte, r);\n}\npub fn instr_660FF5_reg_jit(ctx: &mut JitContext, r1: u32, r2: u32) {\n    sse_read128_xmm_xmm(ctx, "instr_660FF5", r1, r2);\n}\npub fn instr_660FF6_mem_jit(ctx: &mut JitContext, modrm_byte: ModrmByte, r: u32) {\n    sse_read128_xmm_mem(ctx, "instr_660FF6", modrm_byte, r);\n}\npub fn instr_660FF6_reg_jit(ctx: &mut JitContext, r1: u32, r2: u32) {\n    sse_read128_xmm_xmm(ctx, "instr_660FF6", r1, r2);\n}\n\npub fn instr_660FF7_mem_jit(ctx: &mut JitContext, _modrm_byte: ModrmByte, _r: u32) {\n    codegen::gen_trigger_ud(ctx)\n}\npub fn instr_660FF7_reg_jit(ctx: &mut JitContext, r1: u32, r2: u32) {\n    codegen::gen_set_previous_eip_offset_from_eip_with_low_bits(\n        ctx.builder,\n        ctx.start_of_current_instruction as i32 & 0xFFF,\n    );\n\n    codegen::gen_move_registers_from_locals_to_memory(ctx);\n    ctx.builder.const_i32(r1 as i32);\n    ctx.builder.const_i32(r2 as i32);\n    if ctx.cpu.asize_32() {\n        codegen::gen_get_reg32(ctx, regs::EDI);\n    }\n    else {\n        codegen::gen_get_reg16(ctx, regs::DI);\n    }\n    jit_add_seg_offset(ctx, regs::DS);\n    ctx.builder.call_fn3("maskmovdqu");\n    codegen::gen_move_registers_from_memory_to_locals(ctx);\n\n    codegen::gen_get_page_fault(ctx.builder);\n    ctx.builder.if_void();\n    codegen::gen_debug_track_jit_exit(ctx.builder, ctx.start_of_current_instruction);\n    ctx.builder.br(ctx.exit_label);\n    ctx.builder.block_end();\n}\n\npub fn instr_660FF8_mem_jit(ctx: &mut JitContext, modrm_byte: ModrmByte, r: u32) {\n    sse_read128_xmm_mem(ctx, "instr_660FF8", modrm_byte, r);\n}\npub fn instr_660FF8_reg_jit(ctx: &mut JitContext, r1: u32, r2: u32) {\n    sse_read128_xmm_xmm(ctx, "instr_660FF8", r1, r2);\n}\npub fn instr_660FF9_mem_jit(ctx: &mut JitContext, modrm_byte: ModrmByte, r: u32) {\n    sse_read128_xmm_mem(ctx, "instr_660FF9", modrm_byte, r);\n}\npub fn instr_660FF9_reg_jit(ctx: &mut JitContext, r1: u32, r2: u32) {\n    sse_read128_xmm_xmm(ctx, "instr_660FF9", r1, r2);\n}\npub fn instr_660FFA_mem_jit(ctx: &mut JitContext, modrm_byte: ModrmByte, r: u32) {\n    sse_read128_xmm_mem(ctx, "instr_660FFA", modrm_byte, r);\n}\npub fn instr_660FFA_reg_jit(ctx: &mut JitContext, r1: u32, r2: u32) {\n    sse_read128_xmm_xmm(ctx, "instr_660FFA", r1, r2);\n}\npub fn instr_660FFB_mem_jit(ctx: &mut JitContext, modrm_byte: ModrmByte, r: u32) {\n    sse_read128_xmm_mem(ctx, "instr_660FFB", modrm_byte, r);\n}\npub fn instr_660FFB_reg_jit(ctx: &mut JitContext, r1: u32, r2: u32) {\n    sse_read128_xmm_xmm(ctx, "instr_660FFB", r1, r2);\n}\npub fn instr_660FFC_mem_jit(ctx: &mut JitContext, modrm_byte: ModrmByte, r: u32) {\n    sse_read128_xmm_mem(ctx, "instr_660FFC", modrm_byte, r);\n}\npub fn instr_660FFC_reg_jit(ctx: &mut JitContext, r1: u32, r2: u32) {\n    sse_read128_xmm_xmm(ctx, "instr_660FFC", r1, r2);\n}\npub fn instr_660FFD_mem_jit(ctx: &mut JitContext, modrm_byte: ModrmByte, r: u32) {\n    sse_read128_xmm_mem(ctx, "instr_660FFD", modrm_byte, r);\n}\npub fn instr_660FFD_reg_jit(ctx: &mut JitContext, r1: u32, r2: u32) {\n    sse_read128_xmm_xmm(ctx, "instr_660FFD", r1, r2);\n}\npub fn instr_660FFE_mem_jit(ctx: &mut JitContext, modrm_byte: ModrmByte, r: u32) {\n    sse_read128_xmm_mem(ctx, "instr_660FFE", modrm_byte, r);\n}\npub fn instr_660FFE_reg_jit(ctx: &mut JitContext, r1: u32, r2: u32) {\n    sse_read128_xmm_xmm(ctx, "instr_660FFE", r1, r2);\n}\n', 'message': 'Fix fldm80/fstenv/fldenv: These instructions were generating and unconditional exit from jitted code but not updating eip. Changed to use the fallback mechanism for handling pagefaults\n', 'author_name': 'Fabian', 'lang': 'rs'}