binbun-x86 0.1.0

x86 and x86-64 instruction decoder generated from Intel XED's datafiles.
Documentation
// @generated by `cargo xtask codegen` from Intel XED's datafiles in
// third_party/xed. Do not edit; edit the generator in xtask/ instead.
//
// Derived from Intel XED, Copyright (c) 2026 Intel Corporation, licensed
// under the Apache License, Version 2.0 (third_party/xed/LICENSE).

//! Decoder state.

use core::ops::{Deref, DerefMut};
/// The fields of XED's operand storage that a decoded instruction
/// keeps. Every field is an integer and zero when unset (registers
/// as `Register as u16`), so fresh fields are all zeros.
#[derive(Debug, Clone, Default, PartialEq, Eq)]
pub struct Fields {
    /// Bytes the length decoder has consumed: the length, once
    /// decoded.
    pub pos: usize,
    /// XED `HINT`, 3 bits.
    pub hint: u8,
    /// XED `LOCK`, 1 bits.
    pub lock: u8,
    /// XED `DISP`, 64 bits.
    pub disp: i64,
    /// XED `DISP_WIDTH`, 8 bits.
    pub disp_width: u8,
    /// XED `BRDISP_WIDTH`, 8 bits.
    pub brdisp_width: u8,
    /// XED `REP`, 2 bits.
    pub rep: u8,
    /// XED `OSZ`, 1 bits.
    pub osz: u8,
    /// XED `ASZ`, 1 bits.
    pub asz: u8,
    /// XED `EOSZ`, 2 bits.
    pub eosz: u8,
    /// XED `EASZ`, 2 bits.
    pub easz: u8,
    /// XED `MOD`, 2 bits.
    pub mod_: u8,
    /// XED `RM`, 3 bits.
    pub rm: u8,
    /// XED `REALMODE`, 1 bits.
    pub realmode: u8,
    /// XED `MODE`, 2 bits.
    pub mode: u8,
    /// XED `SMODE`, 2 bits.
    pub smode: u8,
    /// XED `IMM0SIGNED`, 1 bits.
    pub imm0signed: u8,
    /// XED `UIMM0`, 64 bits.
    pub uimm0: u64,
    /// XED `UIMM1`, 8 bits.
    pub uimm1: u8,
    /// XED `IMM_WIDTH`, 8 bits.
    pub imm_width: u8,
    /// XED `USING_DEFAULT_SEGMENT0`, 1 bits.
    pub using_default_segment0: u8,
    /// XED `USING_DEFAULT_SEGMENT1`, 1 bits.
    pub using_default_segment1: u8,
    /// XED `SEG0`, 16 bits.
    pub seg0: u16,
    /// XED `BASE0`, 16 bits.
    pub base0: u16,
    /// XED `INDEX`, 16 bits.
    pub index: u16,
    /// XED `SCALE`, 4 bits.
    pub scale: u8,
    /// XED `SEG1`, 16 bits.
    pub seg1: u16,
    /// XED `BASE1`, 16 bits.
    pub base1: u16,
    /// XED `MEM0`, 1 bits.
    pub mem0: u8,
    /// XED `MEM1`, 1 bits.
    pub mem1: u8,
    /// XED `AGEN`, 1 bits.
    pub agen: u8,
    /// XED `ABSBR`, 1 bits.
    pub absbr: u8,
    /// XED `PTR`, 1 bits.
    pub ptr: u8,
    /// XED `REG0`, 16 bits.
    pub reg0: u16,
    /// XED `REG1`, 16 bits.
    pub reg1: u16,
    /// XED `REG2`, 16 bits.
    pub reg2: u16,
    /// XED `REG3`, 16 bits.
    pub reg3: u16,
    /// XED `REG4`, 16 bits.
    pub reg4: u16,
    /// XED `REG5`, 16 bits.
    pub reg5: u16,
    /// XED `REG6`, 16 bits.
    pub reg6: u16,
    /// XED `REG7`, 16 bits.
    pub reg7: u16,
    /// XED `REG8`, 16 bits.
    pub reg8: u16,
    /// XED `REG9`, 16 bits.
    pub reg9: u16,
    /// XED `NELEM`, 4 bits.
    pub nelem: u16,
    /// XED `ELEMENT_SIZE`, 9 bits.
    pub element_size: u16,
    /// XED `NOMINAL_OPCODE`, 8 bits.
    pub nominal_opcode: u8,
    /// XED `VEXVALID`, 3 bits.
    pub vexvalid: u8,
    /// XED `BCAST`, 5 bits.
    pub bcast: u8,
    /// XED `ZEROING`, 1 bits.
    pub zeroing: u8,
    /// XED `ROUNDC`, 3 bits.
    pub roundc: u8,
    /// XED `SAE`, 1 bits.
    pub sae: u8,
    /// XED `DFV`, 4 bits.
    pub dfv: u8,
}
/// Decoder state: XED's operand storage, the kept [`Fields`] (which
/// it dereferences to) and the rest. Every field is an integer and
/// zero when unset (errors as `DecodeError as u8`), so a fresh state
/// is all zeros.
#[derive(Debug, Clone, Default)]
pub struct State {
    /// The fields a decoded instruction keeps.
    pub fields: Fields,
    /// The instruction's bytes (at most 15), zero-padded (not an XED
    /// field: the length decoder's input).
    pub buf: [u8; 32],
    /// Bytes available in `buf`, at most 15.
    pub max: usize,
    /// XED `SEG_OVD`, 3 bits.
    pub seg_ovd: u8,
    /// XED `NEED_MEMDISP`, 6 bits.
    pub need_memdisp: u8,
    /// XED `REX`, 1 bits.
    pub rex: u8,
    /// XED `REXW`, 1 bits.
    pub rexw: u8,
    /// XED `REXR`, 1 bits.
    pub rexr: u8,
    /// XED `REXX`, 1 bits.
    pub rexx: u8,
    /// XED `REXB`, 1 bits.
    pub rexb: u8,
    /// XED `REX2`, 1 bits.
    pub rex2: u8,
    /// XED `REXB4`, 1 bits.
    pub rexb4: u8,
    /// XED `REXX4`, 1 bits.
    pub rexx4: u8,
    /// XED `REXR4`, 1 bits.
    pub rexr4: u8,
    /// XED `PREFIX66`, 1 bits.
    pub prefix66: u8,
    /// XED `REG`, 3 bits.
    pub reg: u8,
    /// XED `SRM`, 3 bits.
    pub srm: u8,
    /// XED `MODEP5`, 1 bits.
    pub modep5: u8,
    /// XED `P4`, 1 bits.
    pub p4: u8,
    /// XED `LZCNT`, 1 bits.
    pub lzcnt: u8,
    /// XED `TZCNT`, 1 bits.
    pub tzcnt: u8,
    /// XED `MODE_SHORT_UD0`, 1 bits.
    pub mode_short_ud0: u8,
    /// XED `PREFETCHIT`, 1 bits.
    pub prefetchit: u8,
    /// XED `PREFETCHRST`, 1 bits.
    pub prefetchrst: u8,
    /// XED `SIBSCALE`, 2 bits.
    pub sibscale: u8,
    /// XED `SIBBASE`, 3 bits.
    pub sibbase: u8,
    /// XED `SIBINDEX`, 3 bits.
    pub sibindex: u8,
    /// XED `ERROR`, 8 bits.
    pub error: u8,
    /// XED `MAP`, 4 bits.
    pub map: u8,
    /// XED `OUT_OF_BYTES`, 1 bits.
    pub out_of_bytes: u8,
    /// XED `FIRST_F2F3`, 2 bits.
    pub first_f2f3: u8,
    /// XED `LAST_F2F3`, 2 bits.
    pub last_f2f3: u8,
    /// XED `ILD_F2`, 1 bits.
    pub ild_f2: u8,
    /// XED `ILD_F3`, 1 bits.
    pub ild_f3: u8,
    /// XED `ILD_SEG`, 8 bits.
    pub ild_seg: u8,
    /// XED `NSEG_PREFIXES`, 8 bits.
    pub nseg_prefixes: u8,
    /// XED `NREXES`, 8 bits.
    pub nrexes: u8,
    /// XED `NPREFIXES`, 8 bits.
    pub nprefixes: u8,
    /// XED `HAS_SIB`, 1 bits.
    pub has_sib: u8,
    /// XED `IMM1_BYTES`, 8 bits.
    pub imm1_bytes: u8,
    /// XED `ESRC`, 4 bits.
    pub esrc: u8,
    /// XED `DUMMY`, 1 bits.
    pub dummy: u8,
    /// XED `NO_APX`, 1 bits.
    pub no_apx: u8,
    /// XED `CLDEMOTE`, 1 bits.
    pub cldemote: u8,
    /// XED `VEXDEST3`, 1 bits.
    pub vexdest3: u8,
    /// XED `VEXDEST210`, 3 bits.
    pub vexdest210: u8,
    /// XED `VL`, 2 bits.
    pub vl: u8,
    /// XED `VEX_PREFIX`, 2 bits.
    pub vex_prefix: u8,
    /// XED `AMD3DNOW`, 1 bits.
    pub amd3dnow: u8,
    /// XED `WBNOINVD`, 1 bits.
    pub wbnoinvd: u8,
    /// XED `MPXMODE`, 1 bits.
    pub mpxmode: u8,
    /// XED `LLRC`, 2 bits.
    pub llrc: u8,
    /// XED `BCRC`, 1 bits.
    pub bcrc: u8,
    /// XED `VEXDEST4`, 1 bits.
    pub vexdest4: u8,
    /// XED `MASK`, 3 bits.
    pub mask: u8,
    /// XED `UBIT`, 1 bits.
    pub ubit: u8,
    /// XED `CET`, 1 bits.
    pub cet: u8,
    /// XED `ND`, 1 bits.
    pub nd: u8,
    /// XED `NF`, 1 bits.
    pub nf: u8,
    /// XED `SCC`, 4 bits.
    pub scc: u8,
    /// XED `IBHF`, 1 bits.
    pub ibhf: u8,
}
impl Deref for State {
    type Target = Fields;
    #[inline]
    fn deref(&self) -> &Fields {
        &self.fields
    }
}
impl DerefMut for State {
    #[inline]
    fn deref_mut(&mut self) -> &mut Fields {
        &mut self.fields
    }
}