XL1200-EMU Symbolics XL1200 Emulator
Plans & Roadmap SpecsPARTIAL docs/platforms-and-ci-plan.md

Broader CPU/OS Portability, Acceleration Tiers & Release CI Plan

Status: Future / Proposed Design Plan (Tier 3) — Not yet implemented. Builds on the completed 3-tier Zen 4 AVX-512 & portable engine (docs/cpu-acceleration-plan.md, docs/emulator/core-and-acceleration.md). See docs/ROADMAP.md for overall sequencing.

Target Emulator: C11 XL1200 Emulator (emu/)
Priority Ordering Inside This Plan:

  1. Primary (Phase 1): Generic x86-64 fast assembly tier (for non-AVX-512 Intel/AMD CPUs) + automated Linux & Windows Release CI.
  2. Second Tier (Phase 2): ARM64 (aarch64 Linux) native builds, CI, and optional NEON/ARM64 assembly fast loop.
  3. Lowest Priority (Phase 3): macOS portability ideas & requirements (documented for future reference; Intel x86_64-darwin / 2019 MBP and Apple Silicon).

1. Executive Summary & Motivation

Currently, ISA_MODE=runtime selects between:

  • Tier 0 (portable): Pure C11/GNU C computed-goto engine (~65–73 MIPS on Zen 4; runs on every 64-bit little-endian CPU).
  • Tier 1 / Tier 2 (avx512_c / avx512): Zen 4 AVX-512 page decoder/PHT + OS-independent SysV/Win64 hot assembly loop (emu/src/cpu_zen4_loop.S, ~150 MIPS on AMD Zen 4).

However, most beta testers on Intel 12th–14th Gen (Alder/Raptor/Arrow Lake), AMD Zen 1–3, or laptops without AVX-512 fall straight back to Tier 0 (~65 MIPS) even though cpu_zen4_loop.S itself uses zero ZMM registers inside its hot threaded loop (only baseline x86-64 GPRs + BMI1/2 rorx/bzhi)!

This plan unlocks fast execution for the vast majority of desktop CPUs, automates Linux & Windows release bundles, charts a second-tier aarch64 path, and records concrete macOS requirements without over-investing prematurely.

flowchart LR
    CPUID["Stateless Runtime Dispatch<br/>ivory_host_select_tier()"]
    T0["Tier 0: portable64<br/>Pure C11/GNU C threaded<br/>(All 64-bit LE arches)"]
    TX["Tier 1B (NEW): x64_asm<br/>Baseline x86-64 / BMI2 ASM<br/>(Intel 12th-14th, Zen 1-3, MBP)"]
    TZ["Tier 2: avx512 (Existing)<br/>Zen 4 ASM + AVX-512 VBMI/PHT"]
    TA["Tier 2A (Second Tier): arm64_asm<br/>ARM64 31-GPR Loop + NEON Decode"]

    CPUID --> T0
    CPUID -->|"x86_64 (no AVX-512)"| TX
    CPUID -->|"x86_64 + AVX-512 VBMI"| TZ
    CPUID -->|"aarch64"| TA

2. Phase 1 (Primary): Generic x86-64 Fast Assembly Tier & Linux/Windows Release CI

2.1 Generic x86-64 Threaded Assembly Tier (TIER_X64_ASM)

  • Key Insight: emu/src/cpu_zen4_loop.S already pins all hot Ivory CPU state in universal SysV + Win64 callee-saved GPRs (%rbx, %rbp, %r12..%r15) and uses zero XMM/ZMM registers! The only AVX-512/Zen-4-specific dependency is:
    1. BMI2 instructions (rorx, bzhi, shrx) — easily gated or replaced with standard shr/and shifts in a baseline x86-64-v2 / x86-64 build variant (or shared .S macro #ifdef IVORY_ASM_BMI2), and
    2. Calling the scalar ivory_decode_page_scalar() / 15-op ivory_pht_hash() instead of cpu_zen4_avx512.c when AVX512_VBMI is absent.
  • Expected Result: ~120–140+ MIPS (~2× speedup over Tier 0) on Intel Core 12th–14th gen, AMD Zen 1–3, and Intel macOS machines with ~30 lines of macro gating in cpu_zen4_loop.S (renamed/aliased cleanly or compiled twice with -DIVORY_ASM_GENERIC_X64 into cpu_x64_loop.o), zero ABI changes, and zero new .data/.bss.
  • Runtime Override: Extend IVORY_ACCEL=auto|portable|x64_asm|avx512_c|avx512 for deterministic lockstep A/B testing on any x86-64 host.

2.2 Automated Linux & Windows Release CI

Build a reproducible CI pipeline (GitHub Actions / Nix flakes) running on every PR and tagged release:

JobRunner / EnvironmentSteps & Artifacts
linux-x86_64Nix (nix develop / nix build .#default)make -C emu clean all test (15/15 suites, ROM-optional exit 77 = SKIP); ELF hygiene (readelf -WS 0 .data/.bss, nm -D sole export ivory_core_get_api, GNU_STACK RW, SDL_DECOUPLED=OK); package ivory-xl1200-linux-x86_64.tar.gz (+ optional AppImage).
windows-x86_64Nix .#mingw (nix build .#windows)make -C emu TARGET_OS=windows -j all dist-win test-win under Wine 11 (15/15 .exe suites); verify PE exports (objdump -p libivory_core.dll) and zero stray DLL dependencies; package ivory-xl1200-windows-x86_64.zip from build-win/dist/.
portable-c11Nix (ISA_MODE=portable)make -C emu clean all test ISA_MODE=portable confirming pure C11 baseline builds with zero x86 intrinsics/assembly.
Lockstep Gatetest_cpu_core + test_snapshot_reloadVerify bit-exact parity across IVORY_ACCEL=portable, x64_asm, avx512_c, and avx512 (when host supports AVX-512).

3. Phase 2 (Second Tier): ARM64 (aarch64) Linux Support & Acceleration

ARM64 (aarch64) is an important second-tier target (ARM64 Linux servers, SBCs, and ARM64 laptops/VMs):

  1. Stage 2a — Native aarch64-linux Build & CI (ISA_MODE=portable / runtime):
    • Audit emu/Makefile so uname -m = aarch64 / arm64 cleanly skips x86-64 ASM/AVX-512 objects under ISA_MODE=runtime and compiles Tier 0 (portable64) with -std=c11 -Wall -Wextra -Werror.
    • Verify emu/include/ivory_hw.h (_Static_assert little-endian bitfields, sizeof(IvoryCpu) == 4096U, sizeof(IvoryMem) == 32768U, sizeof(MerlinBoard) == 278528U) and emu/include/emu_os.h atomics (__atomic_* acquire/release — critical on weakly ordered ARM64 memory models for vram_dirty, Xl1200SerialRing, and EmuRuntime.ctl_waiters!).
    • Add aarch64-linux cross-compile / QEMU-user or native ARM64 CI build check.
  2. Stage 2b — Optional ARM64 Threaded Assembly & NEON Decoder (cpu_arm64_loop.S, cpu_arm64_neon.c):
    • ARM64 has 31 general-purpose 64-bit registers (x19..x28 callee-saved = 10 pinned registers!), allowing cpu, ip, tos, sp, fp, lp, disp_table, rem_budget, stack_cache, and l0_icache to stay register-resident simultaneously without stack spills.
    • ubfx / bfi map 1-to-1 to Ivory OP_LDB / OP_DPB and 40-bit tag/pointer extraction (ubfx x0, x12, #32, #6), and NEON vqtbl4q_u8 accelerates 256-word page decoding cleanly.

4. Phase 3 (Lowest Priority): macOS Portability Ideas & Requirements

Documented for future reference (noting available test hardware is an Intel x86_64 2019 MacBook Pro; no Apple Silicon hardware is currently on hand):

  • Shared-Library Hot Reload (.dylib):
    • Update emu/Makefile for Darwin: emit libivory_core.dylib (-dynamiclib -install_name @rpath/libivory_core.dylib), use -Wl,-exported_symbol,_ivory_core_get_api for strict symbol visibility, and verify with otool -L / nm -gU instead of ldd / readelf.
    • emu/src/core_loader.c: default library filename libivory_core.dylib on __APPLE__.
  • Host Portability Audit:
    • emu_os.h / emu_io.h / emu_ipc.h: clock_gettime(CLOCK_MONOTONIC) and POSIX pread/pwrite/AF_UNIX work natively on macOS >= 10.12; guard Linux-only madvise(MADV_DONTNEED) semantics (MADV_FREE vs mmap re-map) and ensure eth_tap_linux.c compiles cleanly to stubs (already #ifdef __linux__).
    • x86-64 Mach-O Assembly: On Intel x86_64-darwin, C symbols carry a leading underscore (_ivory_cpu_run_zen4_asm) and ELF .type/.size/.note.GNU-stack directives are unsupported — extend emu/src/asm_abi.h with #ifdef __APPLE__ symbol prefix and Mach-O section macros so Tier 1B (x64_asm) runs natively on Intel Macs!
  • SDL3 & Packaging:
    • SDL3 Cocoa backend (SDL_ShowOpenFileDialog / SDL_ShowSaveFileDialog map to NSOpenPanel/NSSavePanel natively, strictly on the Main Thread — already satisfied by ui_workbench.c!).
    • Keymap note: macOS Command (⌘) / Option (⌥) ergonomics already have a dedicated mac-ext ([MAC]) profile in emu/src/keymap.c.
    • Packaging: flake.nix Darwin target or Homebrew formula + .app bundle wrapping ivory-xl1200 + libivory_core.dylib + SDL3.framework.

5. Verification & Acceptance Criteria

PhaseVerification Gate
Phase 1: Generic x86-64 ASM + CIIVORY_ACCEL=x64_asm passes 10M-step + 45M-step bit-exact lockstep vs portable on Linux & Wine; readelf -WS (0 .data/.bss) & GNU_STACK RW; GitHub Actions / Nix CI produces verified Linux .tar.gz and Windows .zip bundles cleanly.
Phase 2: ARM64 (aarch64)All 15 unit test suites pass on aarch64-linux (verifying acquire/release atomics on weak memory ordering); if Stage 2b lands, arm64_asm passes 10M-step lockstep vs portable.
Phase 3: macOS (Future)make -C emu all test passes on x86_64-darwin with libivory_core.dylib hot-reload (test_snapshot_reload), SDL_VIDEODRIVER=dummy (test_ui_workbench), and zero libSDL3 linkage in otool -L build/libivory_core.dylib.

6. File Impact Summary

FileActionPurpose
emu/src/cpu_zen4_loop.S, emu/src/asm_abi.h, emu/src/cpu_zen4_avx512.cEditMacro-gate BMI2 for generic x64_asm tier, extend IVORY_ACCEL runtime selection
emu/Makefile, flake.nixEditBuild x64_asm object, aarch64 runtime detection, optional Darwin .dylib rules
.github/workflows/ci.yml (or Nix CI script)NewAutomated Linux + Windows MinGW/Wine CI & release archive packaging
emu/src/cpu_arm64_loop.S, emu/src/cpu_arm64_neon.c (Phase 2b)NewSecond-tier ARM64 threaded loop & NEON 256-word page decoder