x86 & x86-64 (archsem-x86)

archsem-x86 defines the x86 architecture manifest (X86_MANIFEST), register map (regmap), semantic table (X86_SEMANTICS), Asem-generated programs (programs), and—when the optional iced feature is enabled—the iced-x86 decoder adapter, form identity catalog, and performance scenario model.

# Pure data only (no decoder dependency):
archsem-x86 = "0.1"

# With iced-x86 decoder, form catalog, and performance adapters:
archsem-x86 = { version = "0.1", features = ["iced"] }

CPU Modes & Segmentation

X86_MANIFEST declares three CpuModes sharing one unified semantic table:

ConstantBit WidthSegSemanticsDescription
LONG6464-bitSegSemantics::NoneLong / 64-bit mode (FS/GS linear bases modeled explicitly)
PROT3232-bitSegSemantics::Descriptor32-bit protected mode (with optional architectural segmentation checks)
REAL1616-bitSegSemantics::RealMode16-bit real-address mode

Address formation uses SegmentationModel::Flat by default. Selecting SegmentationModel::Architectural (via RtlEmitter::with_segmentation_model or CfgLiftConfig::segmentation_model) routes 16-bit real-mode, virtual-8086, and 32-bit protected accesses through hidden descriptor caches with guarded #GP/#SS limit and attribute checks, plus descriptor-table/gate/IRETQ semantics and Require modeled-domain preconditions.

Decoder Adapter (iced Feature)

Enabling features = ["iced"] unlocks archsem_x86::decode:

  • IcedX86Decoder: Stateless default Intel-personality Decoder<Insn = IcedInsn, State = NoDecodeState>.
  • IcedX86DecoderWithOptions(pub u32): Selects vendor/historical opcode personalities:
    • AMD — AMD decode differences (honours 66 operand-size prefix on near branches in 64-bit mode, UD0 without ModRM, LOCK MOV CR0 as MOV CR8, etc.)
    • KNC — Intel Knights Corner (MVEX and KNC VEX maps in 64-bit mode)
    • Legacy/vendor personalities: CYRIX, LOADALL286, LOADALL386, UMOV, XBTS, CYRIX_SMINT_0F7E, CYRIX_DMI, ALTINST, STOREALL, CL1INVMB, UDBG, POP_CS
  • #UD Handling: Complete invalid encodings (Code::INVALID) lift through the UD2 semantic row (#UD trap) rather than failing as truncated input.

Register Aliasing, Flags, and REP Loops

  • GPRs (cid 0..16): RAX–R15 use SubRegMap::X86Nested:
    • 8-bit low (AL) and high (AH, offset = 8) and 16-bit (AX) writes use RegisterWritePolicy::Preserve.
    • 32-bit (EAX) writes use RegisterWritePolicy::ZeroExtendParent into the 64-bit parent (RAX).
  • Status Flags (CarryPolarity::BorrowSet): CF, PF, AF, ZF, SF, OF, and DF are modeled as individual 1-bit RegisterRole::Flag registers (cid 1..7), while RFLAGS_CONTROL holds the remaining non-condition bits.
  • String Operations (REP/REPE/REPNE): Expand via ControlEffect::Rep into executable Root / RepeatBody / RepeatLatch InstructionExecutionGroups. REPE/REPNE CMPS/SCAS run each iteration in the latch and commit final flags on the terminating iteration, preserving pre-instruction EFLAGS beside committed RCX/RSI/RDI progress if a later iteration faults.
  • Atomic Routes: XCHG with a memory destination and LOCK-prefixed memory-destination RMW instructions select programs::atomic_program_for and emit AtomicEvents; illegal LOCK combinations fail closed before emission.

x87, MMX, SIMD, AVX-512, and MVEX

  • x87 FPU (x87_exact.asem, x87_projection.asem, x87_state_image.asem): Models the 80-bit ST(0)..ST(7) stack (IndexedRegisterBank), FPCW, FPSW (reconstructing live X87_TOP), FPTW, and state-image layouts (FXSAVE/FXRSTOR, FNSAVE/FRSTOR, FNSTENV/FLDENV).
  • MMX (mmx.asem): Decoded operands touching MM0..MM7 dispatch to dedicated x87-aliased routes rather than silently aliasing XMM vectors.
  • SSE / AVX / AVX-512 (VEC_BASE = 0x100, K_BASE = 0x90):
    • XMM/YMM/ZMM alias a single 512-bit parent (SubRegMap::VectorNested); legacy SSE writes preserve upper lanes while VEX/EVEX/XOP writes clear them.
    • EVEX write masking ({k1}/{z}), embedded rounding ({rn-sae}), SAE, {1toN} broadcast, and fault-suppressed masked memory loads (E## vs E##NF with probe_write) are modeled explicitly.
    • AVX-512 scatter programs declare TransactionModel::Progressive.
  • Crypto / Math Expansion: AES, SHA, SM3/SM4, and x87 transcendentals stay compact structured OpaqueIntrinsics by default unless IrEmitter::opaque_expansion() enables OpaqueExpansion::CRYPTO or MATH.

Architecture Profiles, Form & Performance Catalogs

  • Profiles (X86_ARCHITECTURE_PROFILES): X86_PROFILE_BASELINE, LEGACY_BASE, X87, LEGACY_MMX, SSE, AVX, AVX512, CRYPTO, MVEX, OTHER_EXTENSION.
  • Form Catalog (archsem_x86::form): Assigns stable, versioned X86FormId digests (architectura.x86.form.v1) from symbolic iced Code names and X86ExecutionModes (13,028 reviewed iced 1.21.0 forms), independent of unstable enum discriminants.
  • Performance Catalog (archsem_x86::performance): Models CPU tuning IDs (X86Microarchitecture), ResolvedX86Scenario, latency/throughput records (X86PerformanceDatabase), and macro/micro-fusion rules imported offline from uops.info via archsem-uops-info.